|
|
@@ -0,0 +1,280 @@
|
|
|
+package com.jzg.commons.entity.scheme.vo;
|
|
|
+
|
|
|
+import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
|
+import com.jzg.commons.constants.ProductsType;
|
|
|
+import com.jzg.commons.entity.po.PtlAgreementUndwrtRulesAttr;
|
|
|
+import com.jzg.commons.entity.po.PtlAgreementUndwrtRulesDictLabal;
|
|
|
+import com.jzg.commons.entity.scheme.po.*;
|
|
|
+import com.jzg.commons.entity.vo.AgreementRulesVo;
|
|
|
+import com.jzg.commons.exception.ValidateException;
|
|
|
+import com.jzg.commons.util.idgen.IdGenerate;
|
|
|
+import io.swagger.v3.oas.annotations.media.Schema;
|
|
|
+import jakarta.validation.constraints.Max;
|
|
|
+import jakarta.validation.constraints.NotBlank;
|
|
|
+import jakarta.validation.constraints.NotEmpty;
|
|
|
+import jakarta.validation.constraints.NotNull;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.Data;
|
|
|
+import lombok.NoArgsConstructor;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Data
|
|
|
+@AllArgsConstructor
|
|
|
+@NoArgsConstructor
|
|
|
+public class PtlSchemeSaveVo {
|
|
|
+
|
|
|
+ private String id;
|
|
|
+
|
|
|
+ @NotBlank(message = "保险公司id不能为空")
|
|
|
+ @Schema(description = "保险公司id")
|
|
|
+ private String companyId;
|
|
|
+ @NotBlank(message = "方案类型不能为空")
|
|
|
+ @Schema(description = "方案类型")
|
|
|
+ private String schemeType;
|
|
|
+
|
|
|
+ @NotBlank(message = "险种类型不能为空")
|
|
|
+ @Schema(description = "产品id")
|
|
|
+ private String productId;
|
|
|
+
|
|
|
+ @Schema(description = "方案列表")
|
|
|
+ private List<Scheme> schemeList = new ArrayList<>();
|
|
|
+
|
|
|
+ @Schema(description = "方案规则")
|
|
|
+ private List<PtlSchemeRulesAttrLink> linkList = new ArrayList<>();
|
|
|
+
|
|
|
+ @Schema(description = "回显的方案规则")
|
|
|
+ private List<PtlAgreementUndwrtRulesAttr> ruleAttrs = new ArrayList<>();
|
|
|
+
|
|
|
+ @Data
|
|
|
+ public static class Scheme{
|
|
|
+ private String id;
|
|
|
+
|
|
|
+// @NotBlank(message = "方案类型不能为空")
|
|
|
+ @Schema(description = "方案类型")
|
|
|
+ private String schemeType;
|
|
|
+
|
|
|
+ @NotBlank(message = "方案名称不能为空")
|
|
|
+ @Max(message = "方案名称不能超过50个字",value = 50)
|
|
|
+ @Schema(description = "方案名称")
|
|
|
+ private String schemeName;
|
|
|
+
|
|
|
+ @Max(message = "方案描述不能超过500个字",value = 500)
|
|
|
+ @Schema(description = "方案描述")
|
|
|
+ private String description;
|
|
|
+
|
|
|
+ @Schema(description = "险种列表")
|
|
|
+ private List<PtlSchemeInsuranceVo> schemeInsuranceList = new ArrayList<>();
|
|
|
+
|
|
|
+ @Schema(description = "驾意险列表")
|
|
|
+ private List<PtlSchemeInsuranceDrivingIntention> drivingIntentionList = new ArrayList<>();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public PtlSchemeSaveVo(PtlScheme ptlScheme,PtlSchemeInfo ptlSchemeInfo,
|
|
|
+ List<PtlSchemeInsuranceVo> insurances,List<PtlSchemeInsuranceDrivingIntention> drivingIntentionList,
|
|
|
+ List<PtlSchemeRulesAttrLink> rulesAttrLinks,List<PtlAgreementUndwrtRulesAttr> agreementRulesVo){
|
|
|
+ if(Objects.isNull(ptlScheme))
|
|
|
+ {
|
|
|
+ ptlScheme.setId(IdGenerate.nextId());
|
|
|
+ }
|
|
|
+ this.id = ptlScheme.getId();
|
|
|
+ this.companyId = ptlScheme.getCompanyId();
|
|
|
+ this.productId = ptlScheme.getProductId();
|
|
|
+ this.schemeList = new ArrayList<>();
|
|
|
+ Scheme scheme = new Scheme();
|
|
|
+ scheme.setId(ptlSchemeInfo.getId());
|
|
|
+ scheme.setSchemeType(ptlSchemeInfo.getSchemeType());
|
|
|
+ scheme.setSchemeName(ptlSchemeInfo.getSchemeName());
|
|
|
+ scheme.setDescription(ptlSchemeInfo.getDescription());
|
|
|
+ this.schemeList.add(scheme);
|
|
|
+ //处理商业险
|
|
|
+ insurances.stream().filter(insurance-> insurance.getSchemeInfoId().equals(ptlSchemeInfo.getId())).forEach(insurance -> {
|
|
|
+ scheme.schemeInsuranceList.add(insurance);
|
|
|
+ });
|
|
|
+ //处理驾意险
|
|
|
+ drivingIntentionList.stream().filter(drivingIntention -> drivingIntention.getSchemeInfoId().equals(ptlSchemeInfo.getId())).forEach(drivingIntention -> {
|
|
|
+ scheme.drivingIntentionList.add(drivingIntention);
|
|
|
+ });
|
|
|
+ //处理规则
|
|
|
+ rulesAttrLinks.stream().filter(link -> link.getSchemeId().equals(this.id)).forEach(link->{
|
|
|
+ this.linkList.add(link);
|
|
|
+ });
|
|
|
+ this.ruleAttrs = agreementRulesVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @JsonIgnore
|
|
|
+ public PtlScheme getPtlScheme(List<PtlAgreementUndwrtRulesAttr> undwrtRulesAttrList){
|
|
|
+ PtlScheme ptlScheme = new PtlScheme();
|
|
|
+ if(Objects.isNull(this.id) || this.id.isEmpty()){
|
|
|
+ this.id = IdGenerate.nextId();
|
|
|
+ }
|
|
|
+ ptlScheme.setId(id);
|
|
|
+ ptlScheme.setCompanyId(companyId);
|
|
|
+ ptlScheme.setProductId(productId);
|
|
|
+ ptlScheme.setProductName(ProductsType.getByCode(productId).getDesc());
|
|
|
+ List<PtlAgreementUndwrtRulesAttr> collect = ruleAttrs.stream().filter(x ->
|
|
|
+ x.getAttrCode().equals("NewEnergy") ||
|
|
|
+ x.getAttrCode().equals("CarClass") ||
|
|
|
+ x.getAttrCode().equals("NatureOfUse")).collect(Collectors.toList());
|
|
|
+ if(collect.size() != 3){
|
|
|
+ throw new ValidateException("方案规则不完整");
|
|
|
+ }
|
|
|
+ ptlScheme.setEnergyType(collect.stream().filter(x->x.getAttrCode().equals("NewEnergy")).findFirst().get().getMin());
|
|
|
+ ptlScheme.setCarnature(collect.stream().filter(x->x.getAttrCode().equals("CarClass")).findFirst().get().getMin());
|
|
|
+ ptlScheme.setVehicleType(collect.stream().filter(x->x.getAttrCode().equals("NatureOfUse")).findFirst().get().getMin());
|
|
|
+ ptlScheme.setRuleDesc(buildDesc(this.getRuleAttrs(), undwrtRulesAttrList));
|
|
|
+
|
|
|
+ return ptlScheme;
|
|
|
+ }
|
|
|
+
|
|
|
+ @JsonIgnore
|
|
|
+ public List<PtlSchemeInfo> getPtlSchemeInfoList(){
|
|
|
+ List<PtlSchemeInfo> ptlSchemeInfoList = new ArrayList<>();
|
|
|
+ for (Scheme scheme : schemeList) {
|
|
|
+ PtlSchemeInfo ptlSchemeInfo = new PtlSchemeInfo();
|
|
|
+ if(Objects.isNull(scheme.getId()) || scheme.getId().isEmpty()){
|
|
|
+ scheme.setId(IdGenerate.nextId());
|
|
|
+ }
|
|
|
+ ptlSchemeInfo.setId(scheme.getId());
|
|
|
+ ptlSchemeInfo.setSchemeId(this.id);
|
|
|
+ ptlSchemeInfo.setSchemeType(this.schemeType);
|
|
|
+ ptlSchemeInfo.setSchemeName(scheme.getSchemeName());
|
|
|
+ ptlSchemeInfo.setDescription(scheme.getDescription());
|
|
|
+ ptlSchemeInfoList.add(ptlSchemeInfo);
|
|
|
+ }
|
|
|
+ return ptlSchemeInfoList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String buildDesc(List<PtlAgreementUndwrtRulesAttr> linkList, List<PtlAgreementUndwrtRulesAttr> undwrtRulesAttrList) {
|
|
|
+ StringBuilder desc = new StringBuilder();
|
|
|
+ for (int i = 0; i < linkList.size(); i++) {
|
|
|
+ int finalI = i;
|
|
|
+ PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr = undwrtRulesAttrList.stream()
|
|
|
+ .filter(x -> x.getAttrCode().equals(linkList.get(finalI).getAttrCode()))
|
|
|
+ .findAny()
|
|
|
+ .get();
|
|
|
+ //数值范围判断
|
|
|
+
|
|
|
+ if ("inputNumber".equals(ptlAgreementUndwrtRulesAttr.getAttrType())) {
|
|
|
+ desc.append(inputNumberIdentifying(ptlAgreementUndwrtRulesAttr, linkList.get(i))).append("\n");
|
|
|
+ }
|
|
|
+ if ("radio".equals(ptlAgreementUndwrtRulesAttr.getAttrType())) {
|
|
|
+ desc.append(radioIdentifying(ptlAgreementUndwrtRulesAttr, linkList.get(i))).append("\n");
|
|
|
+ }
|
|
|
+ if ("checkbox".equals(ptlAgreementUndwrtRulesAttr.getAttrType()) || "select".equals(ptlAgreementUndwrtRulesAttr.getAttrType())) {
|
|
|
+ if(linkList.get(i).getMinArray() != null && linkList.get(i).getMinArray().length > 0){
|
|
|
+ desc.append(ptlAgreementUndwrtRulesAttr.getAttrName()).append("包含").append(String.join(",",Arrays.asList(linkList.get(i).getMinArray()))).append("\n");
|
|
|
+ }else{
|
|
|
+ desc.append(ptlAgreementUndwrtRulesAttr.getAttrName()).append("包含").append(linkList.get(i).getMin()).append("\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ("inputTag".equals(ptlAgreementUndwrtRulesAttr.getAttrType())) {
|
|
|
+ if (linkList.get(i).getOperator() != null && linkList.get(i).getOperator().equals("1")) {
|
|
|
+ desc.append(ptlAgreementUndwrtRulesAttr.getAttrName()).append("包含").append(linkList.get(i).getMin()).append("\n");
|
|
|
+ } else {
|
|
|
+ desc.append(ptlAgreementUndwrtRulesAttr.getAttrName()).append("不包含").append(linkList.get(i).getMin()).append("\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return desc.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private String radioIdentifying(PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr, PtlAgreementUndwrtRulesAttr ptlAgreementProductCostsAttrLink) {
|
|
|
+ PtlAgreementUndwrtRulesDictLabal ptlAgreementUndwrtRulesDictLabal = ptlAgreementUndwrtRulesAttr.getDictLabal().stream().filter(x -> x.getCode().equals(ptlAgreementProductCostsAttrLink.getMin())).findAny().get();
|
|
|
+ return ptlAgreementUndwrtRulesAttr.getAttrName() + "为" + ptlAgreementUndwrtRulesDictLabal.getName();
|
|
|
+ }
|
|
|
+
|
|
|
+ private String inputNumberIdentifying(PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr, PtlAgreementUndwrtRulesAttr ptlAgreementProductCostsAttrLink) {
|
|
|
+ if ("1".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
|
|
|
+ return ptlAgreementUndwrtRulesAttr.getAttrCode() + "范围值" + ptlAgreementProductCostsAttrLink.getMin() + "到" + ptlAgreementProductCostsAttrLink.getMax();
|
|
|
+ } else if ("2".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
|
|
|
+ return ptlAgreementUndwrtRulesAttr.getAttrName() + "小于" + ptlAgreementProductCostsAttrLink.getMin();
|
|
|
+ } else if ("3".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
|
|
|
+ return ptlAgreementUndwrtRulesAttr.getAttrName() + "小于等于" + ptlAgreementProductCostsAttrLink.getMin();
|
|
|
+ } else if ("4".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
|
|
|
+ return ptlAgreementUndwrtRulesAttr.getAttrName() + "大于" + ptlAgreementProductCostsAttrLink.getMax();
|
|
|
+ } else if ("5".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
|
|
|
+ return ptlAgreementUndwrtRulesAttr.getAttrName() + "大于等于" + ptlAgreementProductCostsAttrLink.getMax();
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ @JsonIgnore
|
|
|
+ public List<PtlSchemeInsurance> getPtlSchemeInsuranceList(){
|
|
|
+ List<PtlSchemeInsurance> ptlSchemeInsuranceList = new ArrayList<>();
|
|
|
+ for (Scheme scheme : schemeList) {
|
|
|
+ scheme.schemeInsuranceList.forEach(schemeInsurance -> {
|
|
|
+ schemeInsurance.getOptionId().forEach(optionId ->{
|
|
|
+ PtlSchemeInsurance ptlSchemeInsurance = new PtlSchemeInsurance();
|
|
|
+ if(Objects.isNull(scheme.getId()) || scheme.getId().isEmpty()) {
|
|
|
+ ptlSchemeInsurance.setId(IdGenerate.nextId());
|
|
|
+ }
|
|
|
+ ptlSchemeInsurance.setSchemeInfoId(scheme.getId());
|
|
|
+ ptlSchemeInsurance.setInsuranceId(schemeInsurance.getInsuranceId());
|
|
|
+ ptlSchemeInsurance.setOptionId(optionId);
|
|
|
+ ptlSchemeInsuranceList.add(ptlSchemeInsurance);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return ptlSchemeInsuranceList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @JsonIgnore
|
|
|
+ public List<PtlSchemeInsuranceDrivingIntention> getPtlSchemeInsuranceDrivingIntentionList(){
|
|
|
+ List<PtlSchemeInsuranceDrivingIntention> ptlSchemeInsuranceDrivingIntentionList = new ArrayList<>();
|
|
|
+ for (Scheme scheme : schemeList) {
|
|
|
+ scheme.drivingIntentionList.forEach(drivingIntention -> {
|
|
|
+ PtlSchemeInsuranceDrivingIntention ptlSchemeInsuranceDrivingIntention = new PtlSchemeInsuranceDrivingIntention();
|
|
|
+ ptlSchemeInsuranceDrivingIntention.setId(IdGenerate.nextId());
|
|
|
+ ptlSchemeInsuranceDrivingIntention.setSchemeInfoId(scheme.getId());
|
|
|
+ ptlSchemeInsuranceDrivingIntention.setSelectedStatus(drivingIntention.getSelectedStatus());
|
|
|
+ ptlSchemeInsuranceDrivingIntention.setDrivingIntentionId(drivingIntention.getDrivingIntentionId());
|
|
|
+ ptlSchemeInsuranceDrivingIntention.setQuantity(drivingIntention.getQuantity());
|
|
|
+ ptlSchemeInsuranceDrivingIntentionList.add(ptlSchemeInsuranceDrivingIntention);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return ptlSchemeInsuranceDrivingIntentionList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @JsonIgnore
|
|
|
+ public List<PtlSchemeRulesAttrLink> getPtlSchemeRulesAttrLinkList(){
|
|
|
+ this.linkList = this.convertAttrs(this.ruleAttrs);
|
|
|
+ List<PtlSchemeRulesAttrLink> links = this.linkList;
|
|
|
+ links.forEach(item->{
|
|
|
+ if(Objects.isNull(item.getId()) || item.getId().isEmpty()){
|
|
|
+ item.setId(IdGenerate.nextId());
|
|
|
+ }
|
|
|
+ if(Objects.isNull(item.getSchemeId()) || item.getSchemeId().isEmpty()){
|
|
|
+ item.setSchemeId(this.id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return links;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<PtlSchemeRulesAttrLink> convertAttrs(List<PtlAgreementUndwrtRulesAttr> attrs){
|
|
|
+ List<PtlSchemeRulesAttrLink> links = new ArrayList<>();
|
|
|
+ for (PtlAgreementUndwrtRulesAttr attr : attrs) {
|
|
|
+ PtlSchemeRulesAttrLink link = new PtlSchemeRulesAttrLink();
|
|
|
+ link.setId(IdGenerate.nextId());
|
|
|
+ link.setSchemeId(this.id);
|
|
|
+ link.setAttrCode(attr.getAttrCode());
|
|
|
+ if(Objects.nonNull(attr.getMinArray()) && attr.getMinArray().length > 0){
|
|
|
+ link.setMin(String.join(",",Arrays.asList(attr.getMinArray())));
|
|
|
+ }else{
|
|
|
+ link.setMin(attr.getMin());
|
|
|
+ }
|
|
|
+ link.setMax(attr.getMax());
|
|
|
+ link.setOperator(attr.getOperator());
|
|
|
+ links.add(link);
|
|
|
+ }
|
|
|
+ return links;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|