Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
8512b34
#280 feat: 기본 수수료율 수정 및 적용
letskuku Jan 20, 2025
664920f
#280 feat: 경험치 엔티티 생성 및 적용
letskuku Feb 23, 2025
b691633
#280 feat: 경험치 엔티티에 수수료 추가 할인률 필드 추가
letskuku Feb 23, 2025
33ffcc7
#280 feat: 공개상담 질문 작성에 대한 경험치 가점 부여 로직 생성 및 적용
letskuku Feb 23, 2025
933d3a7
#280 feat: 공개상담 답변 작성에 대한 경험치 가점 부여 로직 생성 및 적용
letskuku Feb 23, 2025
c296ed7
#280 feat: 공개상담 답변을 채택한 질문자에 대한 경험치 가점 부여 로직 생성 및 적용
letskuku Feb 23, 2025
7cde1bd
#280 feat: 공개상담 답변이 채택된 답변자에 대한 경험치 가점 부여 로직 생성 및 적용
letskuku Feb 23, 2025
ae632ff
#280 feat: 공개상담 인기글 여부 확인하는 필드 생성
letskuku Feb 23, 2025
0e7a9fc
#280 feat: 공개상담 인기글 관련 경험치 가점 부여 로직 생성 및 적용
letskuku Feb 23, 2025
427d38e
#280 refactor: 경험치 엔티티명 수정 및 적용
letskuku Feb 23, 2025
617b1d8
#280 refactor: 경험치 엔티티 내 필드명 수정
letskuku Feb 23, 2025
8aa4610
#280 feat: 상담사 엔티티 생성 시 경험치 엔티티와 연결되도록 로직 생성 및 적용
letskuku Feb 23, 2025
4f219e3
#280 refactor: 상담사 경험치 엔티티 호출 로직 효율화
letskuku Feb 23, 2025
a67a691
#280 fix: 경험치 엔티티 관련 오류 해결
letskuku Feb 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.example.sharemind.counselor.domain.Counselor;
import com.example.sharemind.customer.application.CustomerService;
import com.example.sharemind.customer.domain.Customer;
import com.example.sharemind.customer.domain.Level;
import com.example.sharemind.post.application.PostService;
import com.example.sharemind.post.content.PostStatus;
import com.example.sharemind.post.domain.Post;
Expand Down Expand Up @@ -89,6 +90,11 @@ public void createComment(CommentCreateRequest commentCreateRequest, Long custom
commentRepository.save(commentCreateRequest.toEntity(post, counselor));
post.increaseTotalComment();
counselor.increaseTotalConsult();

if (post.getIsPublic()) {
Level counselorlevel = counselor.getLevel();
counselorlevel.increasePostAnswer();
}
}

@Override
Expand All @@ -110,6 +116,16 @@ public void updateCustomerChosenComment(Long postId, Long commentId, Long custom
comment.checkCommentIsForPost(post);

comment.updateIsChosen();
if (post.getIsPublic()) {
Level customerLevel = customer.getLevel();
customerLevel.increasePostChoose();

Level counselorLevel = comment.getCounselor().getLevel();
counselorLevel.increasePostChosen();
if (post.getIsPopular()) {
counselorLevel.increasePostPopularityChosen();
}
}

post.updatePostStatus(PostStatus.COMPLETED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static ConsultCreateResponse of(Consult consult, Counselor counselor) {
.collect(Collectors.toSet());

return new ConsultCreateResponse(consult.getConsultId(),
counselor.getNickname(), counselor.getLevel(), counselor.getRatingAverage(),
counselor.getNickname(), counselor.getLevel().getGrade(), counselor.getRatingAverage(),
counselor.getTotalReview(), consultCategories, counselor.getConsultStyle().getDisplayName(),
consult.getConsultType().getDisplayName(), consult.getCost());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.example.sharemind.counselor.content.ProfileStatus;
import com.example.sharemind.counselor.exception.CounselorErrorCode;
import com.example.sharemind.counselor.exception.CounselorException;
import com.example.sharemind.customer.domain.Level;
import com.example.sharemind.global.common.BaseEntity;
import com.example.sharemind.global.content.ConsultCategory;
import com.example.sharemind.counselor.content.ConsultStyle;
Expand All @@ -24,7 +25,6 @@
public class Counselor extends BaseEntity {

private static final Integer RETRY_EDUCATION_OFFSET = 1;
private static final Integer COUNSELOR_BASIC_LEVEL = 1;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down Expand Up @@ -90,10 +90,6 @@ public class Counselor extends BaseEntity {
@Column(columnDefinition = "TEXT")
private String introduction;

@PositiveOrZero(message = "상담사 레벨은 0 이상입니다.")
@Column(nullable = false)
private Integer level;

private String account;

private String bank;
Expand All @@ -119,11 +115,14 @@ public class Counselor extends BaseEntity {
@JoinColumn(name = "settlement_id", unique = true)
private Settlement settlement;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "level_id", unique = true)
private Level level;

@Builder
public Counselor(String nickname, String email) {
this.nickname = nickname;
this.email = email;
this.level = 0;
this.totalReview = 0L;
this.ratingAverage = 0.0;
this.profileStatus = ProfileStatus.NO_PROFILE;
Expand All @@ -132,6 +131,10 @@ public Counselor(String nickname, String email) {
this.settlement = Settlement.builder().build();
}

public void setLevel(Level level) {
this.level = level;
}

public Long getConsultCost(ConsultType consultType) {
return this.consultCosts.stream()
.filter(consultCost -> consultCost.getConsultType().equals(consultType))
Expand Down Expand Up @@ -172,8 +175,6 @@ public void updateIsEducated(Boolean isEducated) {

if (isEducated.equals(false)) {
this.retryEducation = LocalDateTime.now().plusDays(RETRY_EDUCATION_OFFSET);
} else {
this.level = COUNSELOR_BASIC_LEVEL;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public static CounselorGetBannerResponse of(Counselor counselor) {
return new CounselorGetBannerResponse(counselor.getCounselorId(), counselor.getNickname(),
CounselorUtil.convertConsultCategories(counselor), counselor.getConsultStyle().getDisplayName(),
counselor.getIntroduction(),
counselor.getLevel(), counselor.getTotalReview(), counselor.getRatingAverage());
counselor.getLevel().getGrade(), counselor.getTotalReview(), counselor.getRatingAverage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ public static CounselorGetForConsultResponse of(Counselor counselor, ConsultType
.map(ConsultCategory::getDisplayName)
.toList();

return new CounselorGetForConsultResponse(counselor.getCounselorId(), counselor.getNickname(),
counselor.getLevel(), counselor.getRatingAverage(), counselor.getTotalReview(), consultCategories,
return new CounselorGetForConsultResponse(counselor.getCounselorId(),
counselor.getNickname(), counselor.getLevel().getGrade(),
counselor.getRatingAverage(), counselor.getTotalReview(), consultCategories,
counselor.getConsultStyle().getDisplayName(), consultType.getDisplayName(),
counselor.getConsultCost(consultType), counselor.getTotalConsult());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ public static CounselorGetInfoResponse of(Counselor counselor) {
if (counselor.getConsultStyle() != null) {
consultStyle = counselor.getConsultStyle().getDisplayName();
}

return new CounselorGetInfoResponse(counselor.getNickname(), counselor.getLevel(), consultStyle, counselor.getIsEducated(),

return new CounselorGetInfoResponse(counselor.getNickname(),
counselor.getLevel().getGrade(), consultStyle, counselor.getIsEducated(),
counselor.getProfileStatus().name());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class CounselorGetListResponse extends CounselorGetBaseResponse {
protected CounselorGetListResponse(Counselor counselor, Boolean isWishList, Boolean isRealtime) {
super(counselor);
this.counselorId = counselor.getCounselorId();
this.level = counselor.getLevel();
this.level = counselor.getLevel().getGrade();
this.totalReview = counselor.getTotalReview();
this.ratingAverage = counselor.getRatingAverage();
this.isWishList = isWishList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static CounselorGetMinderProfileResponse of(Counselor counselor, Boolean
return CounselorGetMinderProfileResponse.builder()
.counselorId(counselor.getCounselorId())
.nickname(counselor.getNickname())
.level(counselor.getLevel())
.level(counselor.getLevel().getGrade())
.totalReview(counselor.getTotalReview())
.ratingAverage(counselor.getRatingAverage())
.consultCategories(CounselorUtil.convertConsultCategories(counselor))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private CounselorGetWishListResponse(Counselor counselor, WishList wishList, Boo
super(counselor);
this.wishlistId = wishList.getWishlistId();
this.counselorId = counselor.getCounselorId();
this.level = counselor.getLevel();
this.level = counselor.getLevel().getGrade();
this.totalReview = counselor.getTotalReview();
this.ratingAverage = counselor.getRatingAverage();
this.updatedAt = wishList.getUpdatedAt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ public interface CounselorRepository extends JpaRepository<Counselor, Long> {
+ "AND c.isActivated = true")
List<Counselor> findAllByNicknameOrEmail(String keyword);

@Query("SELECT c FROM Counselor c WHERE (c.nickname LIKE %:word% OR c.experience LIKE %:word% OR c.introduction LIKE %:word%) AND c.level >= 1 AND c.isActivated = true AND c.profileStatus = 'EVALUATION_COMPLETE'")
@Query("SELECT c FROM Counselor c WHERE (c.nickname LIKE %:word% OR c.experience LIKE %:word% OR c.introduction LIKE %:word%) AND c.level.grade >= 1 AND c.isActivated = true AND c.profileStatus = 'EVALUATION_COMPLETE'")
Page<Counselor> findByWordAndLevelAndStatus(String word, Pageable pageable);


@Query("SELECT c FROM Counselor c WHERE :category MEMBER OF c.consultCategories AND c.level >= 1 AND c.isActivated = true AND c.profileStatus = 'EVALUATION_COMPLETE'")
@Query("SELECT c FROM Counselor c WHERE :category MEMBER OF c.consultCategories AND c.level.grade >= 1 AND c.isActivated = true AND c.profileStatus = 'EVALUATION_COMPLETE'")
Page<Counselor> findByConsultCategoryAndLevelAndStatus(ConsultCategory category, Pageable pageable);

@Query("SELECT c FROM Counselor c WHERE c.level >= 1 AND c.isActivated = true AND c.profileStatus = 'EVALUATION_COMPLETE'")
@Query("SELECT c FROM Counselor c WHERE c.level.grade >= 1 AND c.isActivated = true AND c.profileStatus = 'EVALUATION_COMPLETE'")
Page<Counselor> findByLevelAndStatus(Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,17 @@ public class Customer extends BaseEntity {
@JoinColumn(name = "quit_id", unique = true)
private Quit quit;

@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinColumn(name = "level_id", unique = true)
private Level level;

@Builder
public Customer(String email, String password) {
this.nickname = "셰어" + new Random().nextInt(999999);
this.email = email;
this.password = password;
this.isBanned = false;
this.level = Level.builder().build();

this.roles = new ArrayList<>() {{
add(Role.ROLE_CUSTOMER);
Expand All @@ -67,6 +72,7 @@ public void updateIsBanned(Boolean isBanned) {

public void setCounselor(Counselor counselor) {
this.counselor = counselor;
this.counselor.setLevel(this.level);
}

public void setQuit(Quit quit) {
Expand Down
132 changes: 132 additions & 0 deletions src/main/java/com/example/sharemind/customer/domain/Level.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package com.example.sharemind.customer.domain;

import com.example.sharemind.global.common.BaseEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.Builder;
import lombok.Getter;

@Getter
@Entity
public class Level extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "level_id")
private Long levelId;

@Column(name = "post_create", nullable = false)
private Long postCreate;

@Column(name = "post_answer", nullable = false)
private Long postAnswer;

@Column(name = "post_choose", nullable = false)
private Long postChoose;

@Column(name = "post_chosen", nullable = false)
private Long postChosen;

@Column(name = "post_popularity_create", nullable = false)
private Long postPopularityCreate;

@Column(name = "post_popularity_answer", nullable = false)
private Long postPopularityAnswer;

@Column(name = "post_popularity_chosen", nullable = false)
private Long postPopularityChosen;

@Column(name = "grade", nullable = false)
private Integer grade;

@Column(name = "extra_discount", nullable = false)
private Double extraDiscount;

@Builder
public Level() {
this.postCreate = 0L;
this.postAnswer = 0L;
this.postChoose = 0L;
this.postChosen = 0L;
this.postPopularityCreate = 0L;
this.postPopularityAnswer = 0L;
this.postPopularityChosen = 0L;
this.grade = 1;
this.extraDiscount = 0.0;
}

public void increasePostCreate() {
this.postCreate++;
updateGradeAndExtraDiscount();
}

public void increasePostAnswer() {
this.postAnswer++;
updateGradeAndExtraDiscount();
}

public void increasePostChoose() {
this.postChoose++;
updateGradeAndExtraDiscount();
}

public void increasePostChosen() {
this.postChosen += 3;
updateGradeAndExtraDiscount();
}

public void increasePostPopularityCreate() {
this.postPopularityCreate += 3;
updateGradeAndExtraDiscount();
}

public void increasePostPopularityAnswer() {
this.postPopularityAnswer += 2;
updateGradeAndExtraDiscount();
}

public void increasePostPopularityChosen() {
this.postPopularityChosen += 3;
updateGradeAndExtraDiscount();
}

private void updateGradeAndExtraDiscount() {
long total = this.postCreate + this.postAnswer + this.postChoose + this.postChosen
+ this.postPopularityCreate + this.postPopularityAnswer + this.postPopularityChosen;

if (total == 0) {
this.grade = 1;
this.extraDiscount = 0.0;
} else if (total <= 7) {
this.grade = 2;
this.extraDiscount = 0.01;
} else if (total <= 15) {
this.grade = 3;
this.extraDiscount = 0.02;
} else if (total <= 25) {
this.grade = 4;
this.extraDiscount = 0.03;
} else if (total <= 100) {
this.grade = 5;
this.extraDiscount = 0.05;
} else if (total <= 500) {
this.grade = 6;
this.extraDiscount = 0.06;
} else if (total <= 1500) {
this.grade = 7;
this.extraDiscount = 0.07;
} else if (total <= 4000) {
this.grade = 8;
this.extraDiscount = 0.08;
} else if (total <= 10000) {
this.grade = 9;
this.extraDiscount = 0.09;
} else {
this.grade = 10;
this.extraDiscount = 0.1;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Constants {
public static final Boolean IS_CHAT = true;
public static final Boolean IS_LETTER = false;

public static final Double FEE = 0.2;
public static final Double BASE_FEE = 0.25;

public static final Long MAX_COMMENTS = 5L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import java.time.LocalDateTime;

import static com.example.sharemind.global.constants.Constants.FEE;
import static com.example.sharemind.global.constants.Constants.BASE_FEE;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
Expand Down Expand Up @@ -66,7 +66,8 @@ public class Payment extends BaseEntity {
public Payment(String customerPhoneNumber, Consult consult) {
this.customerPhoneNumber = customerPhoneNumber;
this.consult = consult;
this.fee = Math.round(consult.getCost() * FEE);
this.fee = Math.round(consult.getCost() * (BASE_FEE - consult.getCounselor().getLevel()
.getExtraDiscount()));
this.isPaid = false;
updateBothStatusNone();
}
Expand Down
Loading