Skip to content

Commit

Permalink
Merge pull request #105 from EWHA-LUX/fix/#100
Browse files Browse the repository at this point in the history
test: μž„μ‹œ μ—…λ°μ΄νŠΈ
  • Loading branch information
julia-heo authored Jun 17, 2024
2 parents 67f24d8 + c5becd3 commit 46a7a6a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ public void cheeringBenefitGoalAnnounce() throws CustomException {

int remainBenefit = Math.max(goalBenefitGoal - receivedBenefit, 0);
if (remainBenefit == 0){
// λͺ©ν‘œ λ‹¬μ„±ν•œ 경우 μ•Œλ¦Όμ„ 보내지 μ•ŠμŒ
content = currentDate + "μ›” λͺ©ν‘œλ₯Ό λ‹¬μ„±ν–ˆμ–΄μš”!";
moreInfo = "100";
continue;
} else {
content = currentDate + "μ›” λͺ©ν‘œ ν˜œνƒ λ‹¬μ„±κΉŒμ§€ " + String.format("%,d", remainBenefit) + "원 λ‚¨μ•˜μ–΄μš”.";
if(goalBenefitGoal==0) moreInfo="100";
Expand Down Expand Up @@ -90,6 +92,7 @@ public void cardPerformanceAnnounce() throws CustomException {
for (OwnedCard card : ownedCardList) {
// 싀적 μ—…λ°μ΄νŠΈ
Users users = card.getUsers();
if(users.getConnectedId()==null) continue;
HashMap<String,Object> performResult = codefapi.Performace(card.getCard().getCardCompany().getCode(),users.getConnectedId(),card.getCard().getName()); //?????
int performanceCondition = (int) performResult.get("performanceCondition");
int currentPerformance = (int) performResult.get("performanceCondition");
Expand All @@ -98,6 +101,10 @@ public void cardPerformanceAnnounce() throws CustomException {

ownedCardRepository.save(card);
String res = String.valueOf(Math.max(card.getPerformanceCondition()-card.getCurrentPerformance(),0));
if(res == "0"){
// 싀적 μ™„λ£Œν•œ 경우 μ•Œλ¦Όμ„ 보내지 μ•ŠμŒ
continue;
}
String content = "이번 달 "+card.getCard().getName()+" μ‹€μ κΉŒμ§€\n"+res+"원 λ‚¨μ•˜μ–΄μš”!";
String moreInfo = card.getCard().getImgUrl();

Expand All @@ -110,6 +117,7 @@ public void cardPerformanceAnnounce() throws CustomException {
.build();
announcementRepository.save(announcement);
List<FCMToken> fcmTokens = fcmTokenRepository.findAllByUsers(users);

for ( FCMToken fcmToken : fcmTokens){
String token = fcmToken.getToken();
firebaseCloudMessageService.sendNotification(new AnnouncementRequestDto(token,currentDate+"μ›” 싀적 μ•Œλ¦Ό",content,announcement.getId().toString()));
Expand Down
43 changes: 42 additions & 1 deletion src/main/java/ewha/lux/once/domain/home/service/HomeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,47 @@ public ChatDto getHomeChat(Users nowUser, String keyword, int paymentAmount) thr
} catch (JsonProcessingException e) {
throw new CustomException(ResponseCode.FAILED_TO_OPENAI_RECOMMEND);
}
if(discount==0){
List <OwnedCard> mainOwncardList = ownedCardRepository.findOwnedCardByUsersAndIsMain(nowUser, true);
if (mainOwncardList.size() == 0) {
List <OwnedCard> ownedCardList = ownedCardRepository.findOwnedCardByUsers(nowUser);

// 싀적 많이 남은 μΉ΄λ“œ μ°ΎκΈ°
OwnedCard maxDifferenceCard = null;
int maxDifference = Integer.MIN_VALUE;

for (OwnedCard ownedCard : ownedCardList) {
int difference = ownedCard.getPerformanceCondition() - ownedCard.getCurrentPerformance();
if (difference > maxDifference) {
maxDifference = difference;
maxDifferenceCard = ownedCard;
}
}

card = maxDifferenceCard.getCard();
benefit= keyword+"에 ν•΄λ‹Ήν•˜λŠ” ν˜œνƒμ΄ μ—†μ–΄μš”.\n싀적이 κ°€μž₯ 많이 남은 μΉ΄λ“œμ—μš”";

} else if(mainOwncardList.size() == 1) {
card = mainOwncardList.get(0).getCard();
benefit= keyword+"에 ν•΄λ‹Ήν•˜λŠ” ν˜œνƒμ΄ μ—†μ–΄μš”.\nμ£ΌμΉ΄λ“œλ‘œ κ²°μ œν•΄λ³΄μ„Έμš”.";
} else {
OwnedCard maxDifferenceCard = null;
int maxDifference = Integer.MIN_VALUE;

for (OwnedCard ownedCard : mainOwncardList) {
int difference = ownedCard.getPerformanceCondition() - ownedCard.getCurrentPerformance();
if (difference > maxDifference) {
maxDifference = difference;
maxDifferenceCard = ownedCard;
}
}

card = maxDifferenceCard.getCard();

benefit= keyword+"에 ν•΄λ‹Ήν•˜λŠ” ν˜œνƒμ΄ μ—†μ–΄μš”.\n싀적이 κ°€μž₯ 많이 남은 μ£ΌμΉ΄λ“œμ—μš”.";
}
}


// 챗봇 λŒ€ν™” 기둝
ChatHistory chat = ChatHistory.builder()
Expand All @@ -83,7 +124,7 @@ public ChatDto getHomeChat(Users nowUser, String keyword, int paymentAmount) thr
// Chat 객체 μ €μž₯
ChatHistory savedChat = chatHistoryRepository.save(chat);

OwnedCard ownedCard = ownedCardRepository.findOwnedCardByCardIdAndUsers(Long.valueOf(cardId),nowUser);
OwnedCard ownedCard = ownedCardRepository.findOwnedCardByCardIdAndUsers(card.getId(),nowUser);

// 챗봇 응닡
ChatDto chatDto = ChatDto.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public String cardRecommend(Users nowUser, String keyword, int paymentAmount) th
}

String result = response.getChoices().get(0).getMessage().getContent();

log.info(result);

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ public interface OwnedCardRepository extends JpaRepository<OwnedCard, Long> {
List<OwnedCard> findOwnedCardByIsMain(boolean isMain);

Optional<OwnedCard> findOwnedCardByUsersAndCard(Users users, Card card);

List<OwnedCard> findOwnedCardByUsersAndIsMain(Users nowUser, boolean isMain);
}

0 comments on commit 46a7a6a

Please sign in to comment.