Skip to content

Commit

Permalink
FEFAS 추천 전략 로직 수정 #138
Browse files Browse the repository at this point in the history
  • Loading branch information
bongsh0112 committed Feb 2, 2024
1 parent 619bacf commit f9336d7
Showing 1 changed file with 49 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.stream.Stream;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import tify.server.domain.domains.product.adaptor.ProductAdaptor;
Expand Down Expand Up @@ -42,6 +43,7 @@ public List<Product> recommendation(Long userId, String categoryName) {
fefasProducts.addAll(
productAdaptor.queryAllByCategoryNameAndCharacter(categoryName, "장갑"));
}
fefasProducts.addAll(productAdaptor.queryAllByCategoryNameAndCharacter(categoryName, "지갑"));

List<Product> products = new ArrayList<>();
products.addAll(hatStep(userId, fefasProducts));
Expand Down Expand Up @@ -71,6 +73,7 @@ private List<FavorRecommendationDTO> getInitRecommendationDTO(Long userId) {
// 장갑
initFavorAnswers.add(
favorAnswerAdaptor.searchByCategoryNameAndNumber(userId, CATEGORY_NAME, 7L));

return initFavorAnswers.stream().map(FavorRecommendationDTO::from).toList();
}

Expand All @@ -91,13 +94,29 @@ private List<Product> hatStep(Long userId, List<Product> products) {
products.stream()
.filter(product -> product.getCharacteristic().contains("모자"))
.toList();
String hatAnswer =
stringBuilder
.append(dto.get(0).getAnswer())
.append(", ")
.append(dto.get(1).getAnswer())
.toString();
return hatList.stream().filter(hat -> hat.getCharacteristic().contains(hatAnswer)).toList();

return hatList.stream()
.filter(
product -> {
String[] splitAnswer = dto.get(0).getAnswer().split(", ");
if (splitAnswer.length == 1) {
return product.getCharacteristic().contains(splitAnswer[0]);
} else {
return product.getCharacteristic().contains(splitAnswer[0])
|| product.getCharacteristic().contains(splitAnswer[1]);
}
})
.filter(
hat -> {
String[] splitAnswer = dto.get(1).getAnswer().split(", ");
if (splitAnswer.length == 1) {
return hat.getCharacteristic().contains(splitAnswer[0]);
} else {
return hat.getCharacteristic().contains(splitAnswer[0])
|| hat.getCharacteristic().contains(splitAnswer[1]);
}
})
.toList();
}

private List<Product> walletStep(Long userId, List<Product> products) {
Expand All @@ -110,38 +129,51 @@ private List<Product> walletStep(Long userId, List<Product> products) {
products.stream()
.filter(product -> product.getCharacteristic().contains("지갑"))
.toList();
return walletList.stream()
.filter(wallet -> wallet.getCharacteristic().contains(answerContent))
.toList();

return getProducts(answerContent, walletList);
}

private List<Product> mufflerStep(Long userId, List<Product> products) {

String answerContent =
favorAnswerAdaptor
.searchByCategoryNameAndNumber(userId, CATEGORY_NAME, 6L)
.getAnswerContent();

List<Product> mufflerList =
products.stream()
.filter(product -> product.getCharacteristic().contains("목도리"))
.toList();
return mufflerList.stream()
.filter(muffler -> muffler.getCharacteristic().contains(answerContent))
.toList();

return getProducts(answerContent, mufflerList);
}

private List<Product> gloveStep(Long userId, List<Product> products) {

String answerContent =
favorAnswerAdaptor
.searchByCategoryNameAndNumber(userId, CATEGORY_NAME, 8L)
.getAnswerContent();

List<Product> gloveList =
products.stream()
.filter(product -> product.getCharacteristic().contains("장갑"))
.toList();
return gloveList.stream()
.filter(glove -> glove.getCharacteristic().contains(answerContent))

return getProducts(answerContent, gloveList);
}

@NotNull
private List<Product> getProducts(String answerContent, List<Product> productList) {
return productList.stream()
.filter(
product -> {
String[] splitAnswer = answerContent.split(", ");
if (splitAnswer.length == 1) {
return product.getCharacteristic().contains(splitAnswer[0]);
} else {
return product.getCharacteristic().contains(splitAnswer[0])
|| product.getCharacteristic().contains(splitAnswer[1]);
}
})
.toList();
}
}

0 comments on commit f9336d7

Please sign in to comment.