From 0d2fa8406e1ed0e73d80523b9b428752c2318ac4 Mon Sep 17 00:00:00 2001 From: LHS-11 Date: Thu, 21 Dec 2023 21:30:22 +0900 Subject: [PATCH] =?UTF-8?q?refactor=20:=20Policy=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EC=97=90=EC=84=9C=20SupportPolicyType=20->=20Set=20?= =?UTF-8?q?=EC=9E=90=EB=A3=8C=ED=98=95=20=ED=95=84=EB=93=9C=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../policy/application/PolicyRecommender.java | 6 ++-- .../policy/application/PolicyService.java | 18 ++++++------ .../policy/dao/PolicyQueryRepository.java | 2 +- .../domain/policy/dao/PolicyRepository.java | 8 +++--- .../domain/policy/domain/Policy.java | 11 ++------ .../domain/enums/SupportPolicyType.java | 21 ++++++++++---- .../domain/user/application/UserService.java | 28 +++++++++---------- .../dto/ApplyPolicyListResponseDto.java | 12 +------- 8 files changed, 50 insertions(+), 56 deletions(-) diff --git a/src/main/java/com/cmc/zenefitserver/domain/policy/application/PolicyRecommender.java b/src/main/java/com/cmc/zenefitserver/domain/policy/application/PolicyRecommender.java index ddf6d02..f75369f 100644 --- a/src/main/java/com/cmc/zenefitserver/domain/policy/application/PolicyRecommender.java +++ b/src/main/java/com/cmc/zenefitserver/domain/policy/application/PolicyRecommender.java @@ -34,18 +34,18 @@ public Map recommendPolicy(User user) { Policy maxBenefitMoneyPolicy = recommendPolicy.stream() - .filter(p -> p.getSupportPolicyType().equals(SupportPolicyType.MONEY)) + .filter(p -> p.getSupportPolicyTypes().contains((SupportPolicyType.MONEY))) .max(Comparator.comparingInt(Policy::getBenefit)) .orElse(null); Policy maxBenefitLoansPolicy = recommendPolicy.stream() - .filter(p -> p.getSupportPolicyType().equals(SupportPolicyType.LOANS)) + .filter(p -> p.getSupportPolicyTypes().contains(SupportPolicyType.LOANS)) .max(Comparator.comparingInt(Policy::getBenefit)) .orElse(null); LocalDate now = LocalDate.now(); Policy mostImminentEndDateSocialServicePolicy = recommendPolicy.stream() - .filter(p -> p.getSupportPolicyType().equals(SupportPolicyType.SOCIAL_SERVICE)) + .filter(p -> p.getSupportPolicyTypes().contains(SupportPolicyType.SOCIAL_SERVICE)) .filter(p -> p.getApplyEndDate().isAfter(now)) .min(Comparator.comparing(p -> ChronoUnit.DAYS.between(now, p.getApplyEndDate()))) .orElse(null); diff --git a/src/main/java/com/cmc/zenefitserver/domain/policy/application/PolicyService.java b/src/main/java/com/cmc/zenefitserver/domain/policy/application/PolicyService.java index b3051b8..2c4c7f3 100644 --- a/src/main/java/com/cmc/zenefitserver/domain/policy/application/PolicyService.java +++ b/src/main/java/com/cmc/zenefitserver/domain/policy/application/PolicyService.java @@ -197,15 +197,15 @@ public PolicyCountResponseDto getRecommendCountAndNickname(User user) { } public RecommendPolicyInfoResponseDto getRecommendPolicyDummy() { - Policy loansPolicy = policyRepository.findAllBySupportPolicyType(SupportPolicyType.LOANS).get(0); - Policy moneyPolicy = policyRepository.findAllBySupportPolicyType(SupportPolicyType.MONEY).get(0); - Policy socialServicePolicy = policyRepository.findAllBySupportPolicyType(SupportPolicyType.SOCIAL_SERVICE).get(0); + Policy loansPolicy = policyRepository.findAllBySupportPolicyTypesContains(SupportPolicyType.LOANS).get(0); + Policy moneyPolicy = policyRepository.findAllBySupportPolicyTypesContains(SupportPolicyType.MONEY).get(0); + Policy socialServicePolicy = policyRepository.findAllBySupportPolicyTypesContains(SupportPolicyType.SOCIAL_SERVICE).get(0); List result = new ArrayList<>(); result.add( RecommendPolicyInfoResponseDto.recommendPolicyInfo.builder() - .supportTypeDescription(loansPolicy.getSupportPolicyType().getDescription()) - .supportType(loansPolicy.getSupportPolicyType()) + .supportTypeDescription(SupportPolicyType.LOANS.getDescription()) + .supportType(SupportPolicyType.LOANS) .policyId(loansPolicy.getId()) .policyName(loansPolicy.getPolicyName()) .policyLogo(loansPolicy.getPolicyLogo()) @@ -219,8 +219,8 @@ public RecommendPolicyInfoResponseDto getRecommendPolicyDummy() { ); result.add( RecommendPolicyInfoResponseDto.recommendPolicyInfo.builder() - .supportType(moneyPolicy.getSupportPolicyType()) - .supportTypeDescription(moneyPolicy.getSupportPolicyType().getDescription()) + .supportType(SupportPolicyType.MONEY) + .supportTypeDescription(SupportPolicyType.MONEY.getDescription()) .policyId(moneyPolicy.getId()) .policyName(moneyPolicy.getPolicyName()) .policyLogo(moneyPolicy.getPolicyLogo()) @@ -234,8 +234,8 @@ public RecommendPolicyInfoResponseDto getRecommendPolicyDummy() { ); result.add( RecommendPolicyInfoResponseDto.recommendPolicyInfo.builder() - .supportType(socialServicePolicy.getSupportPolicyType()) - .supportTypeDescription(socialServicePolicy.getSupportPolicyType().getDescription()) + .supportType(SupportPolicyType.SOCIAL_SERVICE) + .supportTypeDescription(SupportPolicyType.SOCIAL_SERVICE.getDescription()) .policyId(socialServicePolicy.getId()) .policyName(socialServicePolicy.getPolicyName()) .policyLogo(socialServicePolicy.getPolicyLogo()) diff --git a/src/main/java/com/cmc/zenefitserver/domain/policy/dao/PolicyQueryRepository.java b/src/main/java/com/cmc/zenefitserver/domain/policy/dao/PolicyQueryRepository.java index 0a91fc2..180fd2d 100644 --- a/src/main/java/com/cmc/zenefitserver/domain/policy/dao/PolicyQueryRepository.java +++ b/src/main/java/com/cmc/zenefitserver/domain/policy/dao/PolicyQueryRepository.java @@ -49,7 +49,7 @@ public Page searchByPaging(User user, SupportPolicyType s .where( // getPolicyId(lastPolicyId, pageable), // 조건 - policy.supportPolicyType.eq(supportPolicyType) + policy.supportPolicyTypes.contains(supportPolicyType) ); if (PolicyCode.NONE != policyCode) { diff --git a/src/main/java/com/cmc/zenefitserver/domain/policy/dao/PolicyRepository.java b/src/main/java/com/cmc/zenefitserver/domain/policy/dao/PolicyRepository.java index 40bd2a9..79dfb39 100644 --- a/src/main/java/com/cmc/zenefitserver/domain/policy/dao/PolicyRepository.java +++ b/src/main/java/com/cmc/zenefitserver/domain/policy/dao/PolicyRepository.java @@ -20,7 +20,7 @@ public interface PolicyRepository extends JpaRepository { // jpql @Query("SELECT p FROM Policy p " + - "WHERE p.supportPolicyType = :policyType " + + "WHERE p.supportPolicyTypes in (:policyType) " + "AND p.applyEndDate >= :currentDate " + "AND NOT EXISTS (SELECT up FROM UserPolicy up WHERE up.policy = p AND up.user.userId = :userId AND up.applyFlag=true) " + "ORDER BY p.applyEndDate ASC ") @@ -29,7 +29,7 @@ public interface PolicyRepository extends JpaRepository { // native query @Query(value = "SELECT p.* FROM policy p " + - "WHERE p.support_policy_type = :policyType " + + "WHERE p.support_policy_types in (:policyType) " + "AND p.apply_end_date >= :currentDate " + "AND NOT EXISTS (SELECT 1 FROM user_policy up WHERE up.policy_id = p.id AND up.user_id = :userId AND up.apply_flag = true) " + "ORDER BY p.apply_end_date ASC " + @@ -41,7 +41,7 @@ public interface PolicyRepository extends JpaRepository { List findAllByApplySttDate(LocalDate sttDate); - List findAllBySupportPolicyType(SupportPolicyType supportPolicyType); + List findAllBySupportPolicyTypesContains(SupportPolicyType supportPolicyType); @EntityGraph(attributePaths = {"jobTypes", "educationTypes", "policySplzTypes", "supportPolicyTypes"}) @Query(value = "SELECT p FROM Policy p " + @@ -49,7 +49,7 @@ public interface PolicyRepository extends JpaRepository { "AND :age between p.minAge and p.maxAge") List findByAreaCodeAndCityCodeAndAge(@Param("areaCode") AreaCode areaCode, @Param("central") AreaCode central, @Param("cityCode") CityCode cityCode, @Param("age") int age); - @Query("SELECT COUNT(p) FROM Policy p WHERE p.supportPolicyType = :supportPolicyType") + @Query("SELECT COUNT(p) FROM Policy p WHERE p.supportPolicyTypes in (:supportPolicyType)") int getPolicyCntBySupportPolicyType(@Param("supportPolicyType") SupportPolicyType supportPolicyType); @Query("SELECT P FROM Policy P LEFT JOIN P.userPolicies UP " + diff --git a/src/main/java/com/cmc/zenefitserver/domain/policy/domain/Policy.java b/src/main/java/com/cmc/zenefitserver/domain/policy/domain/Policy.java index e02fb14..1c5104c 100644 --- a/src/main/java/com/cmc/zenefitserver/domain/policy/domain/Policy.java +++ b/src/main/java/com/cmc/zenefitserver/domain/policy/domain/Policy.java @@ -110,9 +110,6 @@ public class Policy extends BaseEntity implements Serializable { @Enumerated(EnumType.STRING) private PolicyCode policyCode; // 정책 유형 - @Enumerated(EnumType.STRING) - private SupportPolicyType supportPolicyType; // 지원 정책 유형 - @Column(columnDefinition = "TEXT") private String policyLogo; // 정책 로고 @@ -166,8 +163,8 @@ public void updateLogo(String imageUrl) { this.policyLogo = imageUrl; } - public void updateSupportType(SupportPolicyType supportPolicyType) { - this.supportPolicyType = supportPolicyType; + public void updateSupportTypes(Set supportPolicyTypes) { + this.supportPolicyTypes.addAll(supportPolicyTypes); } public void updateRemark(String remark) { @@ -188,7 +185,7 @@ public void updateDateType(PolicyDateType policyDateType) { } @Builder - public Policy(String bizId, String policyName, String policyIntroduction, String operatingAgencyName, String applicationPeriodContent, String organizationType, String supportContent, String ageInfo, String employmentStatusContent, String specializedFieldContent, String educationalRequirementContent, String residentialAndIncomeRequirementContent, String additionalClauseContent, String eligibilityTargetContent, String duplicatePolicyCode, String applicationSiteAddress, String referenceSiteUrlAddress, String applicationProcedureContent, String submissionDocumentContent, int minAge, int maxAge, AreaCode areaCode, CityCode cityCode, Set jobTypes, Set educationTypes, Set policySplzTypes, PolicyCode policyCode, SupportPolicyType supportPolicyType, String policyLogo, String policyApplyDenialReason, String applyStatus, LocalDate applySttDate, LocalDate applyEndDate, Set userPolicies, int benefit, String remark, List applyPeriods, PolicyDateType policyDateType) { + public Policy(String bizId, String policyName, String policyIntroduction, String operatingAgencyName, String applicationPeriodContent, String organizationType, String supportContent, String ageInfo, String employmentStatusContent, String specializedFieldContent, String educationalRequirementContent, String residentialAndIncomeRequirementContent, String additionalClauseContent, String eligibilityTargetContent, String duplicatePolicyCode, String applicationSiteAddress, String referenceSiteUrlAddress, String applicationProcedureContent, String submissionDocumentContent, int minAge, int maxAge, AreaCode areaCode, CityCode cityCode, Set jobTypes, Set educationTypes, Set policySplzTypes, PolicyCode policyCode, String policyLogo, String policyApplyDenialReason, String applyStatus, LocalDate applySttDate, LocalDate applyEndDate, Set userPolicies, int benefit, String remark, List applyPeriods, PolicyDateType policyDateType) { this.bizId = bizId; this.policyName = policyName; this.policyIntroduction = policyIntroduction; @@ -213,7 +210,6 @@ public Policy(String bizId, String policyName, String policyIntroduction, String this.areaCode = areaCode; this.cityCode = cityCode; this.policyCode = policyCode; - this.supportPolicyType = supportPolicyType; this.policyLogo = policyLogo; this.policyApplyDenialReason = policyApplyDenialReason; this.applyStatus = applyStatus; @@ -226,5 +222,4 @@ public Policy(String bizId, String policyName, String policyIntroduction, String this.policyDateType = policyDateType; } - } diff --git a/src/main/java/com/cmc/zenefitserver/domain/policy/domain/enums/SupportPolicyType.java b/src/main/java/com/cmc/zenefitserver/domain/policy/domain/enums/SupportPolicyType.java index a2b2ac2..c58bb83 100644 --- a/src/main/java/com/cmc/zenefitserver/domain/policy/domain/enums/SupportPolicyType.java +++ b/src/main/java/com/cmc/zenefitserver/domain/policy/domain/enums/SupportPolicyType.java @@ -10,29 +10,38 @@ @Getter public enum SupportPolicyType { - MONEY("현금","money"), - LOANS("대출","loan"), - SOCIAL_SERVICE("사회복지","social service"); + MONEY("현금", "money", "1"), + LOANS("대출", "loan", "2"), + SOCIAL_SERVICE("사회복지", "social service", "3"); private String description; private String name; + private String order; - SupportPolicyType(String description, String name) { + SupportPolicyType(String description, String name, String order) { this.description = description; this.name = name; + this.order = order; } - public static SupportPolicyType fromString(String value){ + public static SupportPolicyType fromString(String value) { return Arrays.stream(SupportPolicyType.values()) .filter(s -> s.name().equals(value)) .findFirst() .orElseThrow(() -> new BusinessException(NOT_FOUND_SUPPORT_POLICY_TYPE_ENUM_VALUE)); } - public static SupportPolicyType findSupportPolicyTypeContains(String name){ + public static SupportPolicyType findSupportPolicyTypeContains(String name) { return Arrays.stream(SupportPolicyType.values()) .filter(s -> name.contains(s.getName())) .findFirst() .orElseThrow(() -> new BusinessException(NOT_FOUND_SUPPORT_POLICY_TYPE_ENUM_VALUE)); } + + public static SupportPolicyType findSupportPolicyTypeByOrder(String order) { + return Arrays.stream(SupportPolicyType.values()) + .filter(s -> s.order.equals(order)) + .findFirst() + .orElseThrow(() -> new BusinessException(NOT_FOUND_SUPPORT_POLICY_TYPE_ENUM_VALUE)); + } } diff --git a/src/main/java/com/cmc/zenefitserver/domain/user/application/UserService.java b/src/main/java/com/cmc/zenefitserver/domain/user/application/UserService.java index 6d41f13..637d267 100644 --- a/src/main/java/com/cmc/zenefitserver/domain/user/application/UserService.java +++ b/src/main/java/com/cmc/zenefitserver/domain/user/application/UserService.java @@ -160,8 +160,8 @@ public HomeInfoResponseDto getHomeInfo(User user) { .policyId(findPolicy.getId()) .policyName(findPolicy.getPolicyName()) .policyLogo(findPolicy.getPolicyLogo()) - .supportPolicyType(findPolicy.getSupportPolicyType()) - .supportPolicyTypeName(findPolicy.getSupportPolicyType().getDescription()) + .supportPolicyType(type) + .supportPolicyTypeName(type.getDescription()) .dueDate(ChronoUnit.DAYS.between(currentTime, findPolicy.getApplyEndDate())) .build(); return homePolicyInfo; @@ -221,7 +221,7 @@ public void delete(User user) { } @Transactional - public void addPolicyDummy(User user){ + public void addPolicyDummy(User user) { Policy policy = policyRepository.findById(1L).get(); Policy policy2 = policyRepository.findById(2L).get(); Policy policy3 = policyRepository.findById(3L).get(); @@ -244,8 +244,8 @@ public void addPolicyDummy(User user){ Policy policy19 = policyRepository.findById(19L).get(); Policy policy20 = policyRepository.findById(20L).get(); - List interestPolices = List.of(policy, policy2, policy3, policy4, policy5, policy6, policy7, policy8, policy9 , policy10); - List appliyPolices = List.of(policy11, policy12, policy13, policy14, policy15, policy16, policy17, policy18, policy19 , policy20); + List interestPolices = List.of(policy, policy2, policy3, policy4, policy5, policy6, policy7, policy8, policy9, policy10); + List appliyPolices = List.of(policy11, policy12, policy13, policy14, policy15, policy16, policy17, policy18, policy19, policy20); for (Policy interestPolicy : interestPolices) { UserPolicy userPolicy = UserPolicy.builder() @@ -270,24 +270,24 @@ public void addPolicyDummy(User user){ } public List getRecommendPolicyDummy() { - Policy loansPolicy = policyRepository.findAllBySupportPolicyType(SupportPolicyType.LOANS).get(0); - Policy moneyPolicy = policyRepository.findAllBySupportPolicyType(SupportPolicyType.MONEY).get(0); - Policy socialServicePolicy = policyRepository.findAllBySupportPolicyType(SupportPolicyType.SOCIAL_SERVICE).get(0); + Policy loansPolicy = policyRepository.findAllBySupportPolicyTypesContains(SupportPolicyType.LOANS).get(0); + Policy moneyPolicy = policyRepository.findAllBySupportPolicyTypesContains(SupportPolicyType.MONEY).get(0); + Policy socialServicePolicy = policyRepository.findAllBySupportPolicyTypesContains(SupportPolicyType.SOCIAL_SERVICE).get(0); List result = new ArrayList<>(); - result.add(get(loansPolicy)); - result.add(get(moneyPolicy)); - result.add(get(socialServicePolicy)); + result.add(get(loansPolicy, SupportPolicyType.LOANS)); + result.add(get(moneyPolicy, SupportPolicyType.MONEY)); + result.add(get(socialServicePolicy, SupportPolicyType.SOCIAL_SERVICE)); return result; } - public HomeInfoResponseDto.HomePolicyInfo get(Policy policy) { + public HomeInfoResponseDto.HomePolicyInfo get(Policy policy, SupportPolicyType supportPolicyType) { return HomeInfoResponseDto.HomePolicyInfo.builder() .policyId(policy.getId()) .policyName(policy.getPolicyName()) .policyLogo(policy.getPolicyLogo()) - .supportPolicyTypeName(policy.getSupportPolicyType().getDescription()) - .supportPolicyType(policy.getSupportPolicyType()) + .supportPolicyTypeName(supportPolicyType.getDescription()) + .supportPolicyType(supportPolicyType) .build(); } } diff --git a/src/main/java/com/cmc/zenefitserver/domain/userpolicy/dto/ApplyPolicyListResponseDto.java b/src/main/java/com/cmc/zenefitserver/domain/userpolicy/dto/ApplyPolicyListResponseDto.java index c625a1a..cc32cd2 100644 --- a/src/main/java/com/cmc/zenefitserver/domain/userpolicy/dto/ApplyPolicyListResponseDto.java +++ b/src/main/java/com/cmc/zenefitserver/domain/userpolicy/dto/ApplyPolicyListResponseDto.java @@ -31,21 +31,13 @@ public class ApplyPolicyListResponseDto { @ApiModelProperty(notes = "정책 수혜 금액", example = "1000000") private int benefit; - @ApiModelProperty(notes = "정책 지원 유형", example = "SOCAIL_SERVICE") - private SupportPolicyType supportPolicyType; - - @ApiModelProperty(notes = "정책 지원 유형 이름", example = "사회복지") - private String supportPolicyTypeDescription; - @Builder - public ApplyPolicyListResponseDto(Long policyId, String policyName, String policyIntroduction, String policyLogo, int benefit, SupportPolicyType supportPolicyType, String supportPolicyTypeDescription) { + public ApplyPolicyListResponseDto(Long policyId, String policyName, String policyIntroduction, String policyLogo, int benefit) { this.policyId = policyId; this.policyName = policyName; this.policyIntroduction = policyIntroduction; this.policyLogo = policyLogo; this.benefit = benefit; - this.supportPolicyType = supportPolicyType; - this.supportPolicyTypeDescription = supportPolicyTypeDescription; } public static ApplyPolicyListResponseDto of(Policy policy) { @@ -55,8 +47,6 @@ public static ApplyPolicyListResponseDto of(Policy policy) { .policyLogo(policy.getPolicyLogo()) .policyIntroduction(policy.getPolicyIntroduction()) .benefit(policy.getBenefit()) - .supportPolicyType(policy.getSupportPolicyType()) - .supportPolicyTypeDescription(policy.getSupportPolicyType().getDescription()) .build(); } }