Skip to content

Commit

Permalink
feat : 정책 페이지 클릭시 나오는 정책 추천 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
LHS-11 committed Nov 15, 2023
1 parent b27e51c commit 57f784c
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ public CommonResponse<List<CalendarPolicyListResponseDto>> getPolicesBySearchDat
return CommonResponse.success(result);
}

// @GetMapping("/recommend")
// @Operation(summary = "지원 정책 유형에 따른 추천 정책 API",description = "로그인(회원가입)하고, 유저에게 정책을 추천할 때 사용합니다.")
// public CommonResponse<RecommendPolicyInfoResponseDto> recommend(@AuthUser User user){
// RecommendPolicyInfoResponseDto result = policyService.recommendPolicy(user);
// return CommonResponse.success(result);
// }
@GetMapping("/recommend")
@Operation(summary = "지원 정책 유형에 따른 추천 정책 API",description = "로그인(회원가입)하고, 해당 유저에게 정책 카테고리를 클릭했을 때 정책 유형에 따른 정책을 추천합니다.")
public CommonResponse<RecommendPolicyInfoResponseDto> recommend(@AuthUser User user){
RecommendPolicyInfoResponseDto result = policyService.getRecommendPolicyDummy();
return CommonResponse.success(result);
}

@GetMapping("/recommend/count")
@Operation(summary = "지원할 수 있는 정책의 수 조회 API", description = "로그인시 해당 유저가 지원할 수 있는 정책의 수를 가져옵니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -143,6 +144,31 @@ public List<CalendarPolicyListResponseDto> getPolicyListBySearchDate(User user,
return result;
}

public RecommendPolicyInfoResponseDto recommend(User user) {

Map<SupportPolicyType, Policy> supportPolicyTypePolicyMap = policyRecommender.recommendPolicy(user);

List<RecommendPolicyInfoResponseDto.recommendPolicyInfo> recommendPolicyInfos = supportPolicyTypePolicyMap.keySet()
.stream()
.map(supportPolicyType -> {
Policy policy = supportPolicyTypePolicyMap.get(supportPolicyType);
RecommendPolicyInfoResponseDto.recommendPolicyInfo dto = RecommendPolicyInfoResponseDto.recommendPolicyInfo.builder()
.policyId(policy.getId())
.policyName(policy.getPolicyName())
.policyLogo(policy.getPolicyLogo())
.policyAreaCode(policy.getAreaCode().getName())
.policyCityCode(policy.getCityCode().getName())
.policyIntroduction(policy.getPolicyIntroduction())
.supportTypePolicyCnt(policyRepository.getPolicyCntBySupportPolicyType(supportPolicyType))
.benefit(10000000)
.policyDateType(policy.getPolicyDateType().getDescription())
.build();
return dto;
}).collect(Collectors.toList());

return RecommendPolicyInfoResponseDto.builder().policyInfos(recommendPolicyInfos).build();
}

public List<HomeInfoResponseDto.HomePolicyInfo> recommendPolicy(User user) {
Map<SupportPolicyType, Policy> supportPolicyTypePolicyMap = policyRecommender.recommendPolicy(user);

Expand All @@ -168,5 +194,59 @@ public PolicyCountResponseDto getRecommendCountAndNickname(User user) {
.policyCnt(policyRecommender.matchPolicy(user).size())
.build();
}

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);

List<RecommendPolicyInfoResponseDto.recommendPolicyInfo> result = new ArrayList<>();
result.add(
RecommendPolicyInfoResponseDto.recommendPolicyInfo.builder()
.supportTypeDescription(loansPolicy.getSupportPolicyType().getDescription())
.supportType(loansPolicy.getSupportPolicyType())
.policyId(loansPolicy.getId())
.policyName(loansPolicy.getPolicyName())
.policyLogo(loansPolicy.getPolicyLogo())
.policyAreaCode(loansPolicy.getAreaCode().getName())
.policyCityCode(loansPolicy.getCityCode().getName())
.policyIntroduction(loansPolicy.getPolicyIntroduction())
.supportTypePolicyCnt(policyRepository.getPolicyCntBySupportPolicyType(SupportPolicyType.LOANS))
.benefit(10000000)
.policyDateType("기간 신청")
.build()
);
result.add(
RecommendPolicyInfoResponseDto.recommendPolicyInfo.builder()
.supportType(moneyPolicy.getSupportPolicyType())
.supportTypeDescription(moneyPolicy.getSupportPolicyType().getDescription())
.policyId(moneyPolicy.getId())
.policyName(moneyPolicy.getPolicyName())
.policyLogo(moneyPolicy.getPolicyLogo())
.policyAreaCode(moneyPolicy.getAreaCode().getName())
.policyCityCode(moneyPolicy.getCityCode().getName())
.policyIntroduction(moneyPolicy.getPolicyIntroduction())
.supportTypePolicyCnt(policyRepository.getPolicyCntBySupportPolicyType(SupportPolicyType.MONEY))
.benefit(10000000)
.policyDateType("상시")
.build()
);
result.add(
RecommendPolicyInfoResponseDto.recommendPolicyInfo.builder()
.supportType(socialServicePolicy.getSupportPolicyType())
.supportTypeDescription(socialServicePolicy.getSupportPolicyType().getDescription())
.policyId(socialServicePolicy.getId())
.policyName(socialServicePolicy.getPolicyName())
.policyLogo(socialServicePolicy.getPolicyLogo())
.policyAreaCode(socialServicePolicy.getAreaCode().getName())
.policyCityCode(socialServicePolicy.getCityCode().getName())
.policyIntroduction(socialServicePolicy.getPolicyIntroduction())
.supportTypePolicyCnt(policyRepository.getPolicyCntBySupportPolicyType(SupportPolicyType.SOCIAL_SERVICE))
.benefit(10000000)
.policyDateType("미정")
.build()
);
return RecommendPolicyInfoResponseDto.builder().policyInfos(result).build();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ public interface PolicyRepository extends JpaRepository<Policy, Long> {
"AND :age between p.minAge and p.maxAge")
List<Policy> 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")
int getPolicyCntBySupportPolicyType(@Param("supportPolicyType") SupportPolicyType supportPolicyType);

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@ToString
Expand Down Expand Up @@ -104,7 +106,6 @@ public class Policy implements Serializable {
@Enumerated(EnumType.STRING)
private Set<SupportPolicyType> supportPolicyTypes = new HashSet<>(); // 특화 분야 유형


@Enumerated(EnumType.STRING)
private PolicyCode policyCode; // 정책 유형

Expand All @@ -122,12 +123,19 @@ public class Policy implements Serializable {

private LocalDate applyEndDate; // 신청 종료일

private String remark; // 비고

@Enumerated(EnumType.STRING)
private PolicyDateType policyDateType;

@OneToMany(mappedBy = "policy", fetch = FetchType.LAZY)
private Set<UserPolicy> userPolicies = new HashSet<>();

private int benefit; // 수혜 금액

@OneToMany(fetch = FetchType.LAZY)
private List<ApplyPeriod> applyPeriods = new ArrayList<>();

public void updateAgeInfo(int minAge, int maxAge) {
this.minAge = minAge;
this.maxAge = maxAge;
Expand Down Expand Up @@ -161,8 +169,25 @@ public void updateSupportType(SupportPolicyType supportPolicyType) {
this.supportPolicyType = supportPolicyType;
}

public void updateRemark(String remark) {
this.remark = remark;
}

public void updateApplySttDateAndApplyEndDate(LocalDate applySttDate, LocalDate applyEndDate) {
this.applySttDate = applySttDate;
this.applyEndDate = applyEndDate;
}

public void updateApplyPeriods(List<ApplyPeriod> applyPeriods) {
this.applyPeriods = applyPeriods;
}

public void updateDateType(PolicyDateType policyDateType) {
this.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<JobType> jobTypes, Set<EducationType> educationTypes, Set<PolicySplzType> policySplzTypes, PolicyCode policyCode, SupportPolicyType supportPolicyType, String policyLogo, String policyApplyDenialReason, String applyStatus, LocalDate applySttDate, LocalDate applyEndDate, Set<UserPolicy> userPolicies, int benefit) {
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<JobType> jobTypes, Set<EducationType> educationTypes, Set<PolicySplzType> policySplzTypes, PolicyCode policyCode, SupportPolicyType supportPolicyType, String policyLogo, String policyApplyDenialReason, String applyStatus, LocalDate applySttDate, LocalDate applyEndDate, Set<UserPolicy> userPolicies, int benefit, String remark, List<ApplyPeriod> applyPeriods, PolicyDateType policyDateType) {
this.bizId = bizId;
this.policyName = policyName;
this.policyIntroduction = policyIntroduction;
Expand Down Expand Up @@ -195,6 +220,9 @@ public Policy(String bizId, String policyName, String policyIntroduction, String
this.applyEndDate = applyEndDate;
this.userPolicies = userPolicies;
this.benefit = benefit;
this.remark = remark;
this.applyPeriods = applyPeriods;
this.policyDateType = policyDateType;
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.cmc.zenefitserver.domain.policy.dto;

import com.cmc.zenefitserver.domain.policy.domain.enums.PolicyDateType;
import com.cmc.zenefitserver.domain.policy.domain.enums.SupportPolicyType;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
Expand All @@ -15,64 +17,64 @@
@ApiModel(description = "추천 정책 정보 조회 API response")
public class RecommendPolicyInfoResponseDto {

@ApiModelProperty(notes = "유저에 맞는 정책의 총 수",example = "56")
private int policyCnt;

@ApiModelProperty(notes = "추천 정책 정보")
private List<recommendPolicyInfo> policyInfos;

@Builder
public RecommendPolicyInfoResponseDto(int policyCnt, List<recommendPolicyInfo> policyInfos) {
this.policyCnt = policyCnt;
public RecommendPolicyInfoResponseDto(List<recommendPolicyInfo> policyInfos) {
this.policyInfos = policyInfos;
}

@Getter
@NoArgsConstructor
public static class recommendPolicyInfo {

@ApiModelProperty(notes = "정책 지원 유형",example = "현금, 대출, 사회서비스")
private String supportType;
@ApiModelProperty(notes = "정책 지원 유형", example = "MONEY, LOANS, SOCIAL_SERVICE")
private SupportPolicyType supportType;

@ApiModelProperty(notes = "정책 지원 유형 이름", example = "현금, 대출, 사회서비스")
private String supportTypeDescription;

@ApiModelProperty(notes = "정책 ID",example = "24")
@ApiModelProperty(notes = "정책 ID", example = "24")
private Long policyId;

@ApiModelProperty(notes = "정책 이름",example = "청년도약계좌")
@ApiModelProperty(notes = "정책 이름", example = "청년도약계좌")
private String policyName;

@ApiModelProperty(notes = "정책 지역 로고",example = "24")
@ApiModelProperty(notes = "정책 지역 로고", example = "24")
private String policyLogo;

@ApiModelProperty(notes = "정책 시/도 이름",example = "서울")
@ApiModelProperty(notes = "정책 시/도 이름", example = "서울")
private String policyAreaCode;

@ApiModelProperty(notes = "정책 시/구 이름",example = "강서구")
@ApiModelProperty(notes = "정책 시/구 이름", example = "강서구")
private String policyCityCode;

@ApiModelProperty(notes = "정책 소개",example = "월 70만원을 5년 납입하면 약 5,000만원을 적립할 수 있는 청년도약계좌")
@ApiModelProperty(notes = "정책 소개", example = "월 70만원을 5년 납입하면 약 5,000만원을 적립할 수 있는 청년도약계좌")
private String policyIntroduction;

@ApiModelProperty(notes = "정책 신청 상태",example = "상시, 기간")
private String applyStatus;

@ApiModelProperty(notes = "지원 정책 별 정책 수",example = "24")
@ApiModelProperty(notes = "지원 정책 별 정책 수", example = "24")
private int supportTypePolicyCnt;

@ApiModelProperty(notes = "정책 수혜금액",example = "1560000")
private int benefit;
@ApiModelProperty(notes = "정책 수혜금액", example = "1560000")
private double benefit;

@ApiModelProperty(notes = "정책 기간 타입", example = "1560000")
private String policyDateType;

@Builder
public recommendPolicyInfo(String supportType, Long policyId, String policyName, String policyLogo, String policyAreaCode, String policyCityCode, String policyIntroduction, String applyStatus, int supportTypePolicyCnt, int benefit) {
public recommendPolicyInfo(SupportPolicyType supportType, String supportTypeDescription, Long policyId, String policyName, String policyLogo, String policyAreaCode, String policyCityCode, String policyIntroduction, int supportTypePolicyCnt, double benefit, String policyDateType) {
this.supportType = supportType;
this.supportTypeDescription = supportTypeDescription;
this.policyId = policyId;
this.policyName = policyName;
this.policyLogo = policyLogo;
this.policyAreaCode = policyAreaCode;
this.policyCityCode = policyCityCode;
this.policyIntroduction = policyIntroduction;
this.applyStatus = applyStatus;
this.supportTypePolicyCnt = supportTypePolicyCnt;
this.benefit = benefit;
this.policyDateType = policyDateType;
}

public void upgradeCityCode(String name) {
Expand Down

0 comments on commit 57f784c

Please sign in to comment.