Parcourir la source

协议复制的开发

dongxin il y a 1 an
Parent
commit
0d58e43ae5

+ 5 - 0
commons/src/main/java/com/jzg/commons/entity/dto/AgreementCopyParam.java

@@ -2,6 +2,7 @@ package com.jzg.commons.entity.dto;
 
 
 import io.swagger.v3.oas.annotations.media.Schema;
 import io.swagger.v3.oas.annotations.media.Schema;
 import jakarta.validation.constraints.NotEmpty;
 import jakarta.validation.constraints.NotEmpty;
+import jakarta.validation.constraints.NotNull;
 import lombok.Data;
 import lombok.Data;
 
 
 import java.util.List;
 import java.util.List;
@@ -10,6 +11,10 @@ import java.util.List;
 @Data
 @Data
 public class AgreementCopyParam {
 public class AgreementCopyParam {
 
 
+    @NotNull(message = "协议id不能为空")
+    @Schema(description = "协议id")
+    private String id;
+
     @NotEmpty(message = "费用id不能为空")
     @NotEmpty(message = "费用id不能为空")
     @Schema(description = "费用id数组")
     @Schema(description = "费用id数组")
     private List<String> costIds;
     private List<String> costIds;

+ 1 - 1
tenant/organization/src/main/java/com/jzg/organization/controller/AgreementController.java

@@ -179,6 +179,6 @@ public class AgreementController extends BaseController {
     @PostMapping("/agreementCopy")
     @PostMapping("/agreementCopy")
     public HttpResult agreementCopy(@Validated @RequestBody AgreementCopyParam param) {
     public HttpResult agreementCopy(@Validated @RequestBody AgreementCopyParam param) {
         agreementService.agreementCopy(param);
         agreementService.agreementCopy(param);
-        return HttpResult.ok("修改成功");
+        return HttpResult.ok("复制成功");
     }
     }
 }
 }

+ 12 - 0
tenant/organization/src/main/java/com/jzg/organization/service/PtlAgreementService.java

@@ -7,12 +7,14 @@ import com.jzg.commons.entity.dto.AgreementEditParam;
 import com.jzg.commons.entity.dto.AgreementParam;
 import com.jzg.commons.entity.dto.AgreementParam;
 import com.jzg.commons.entity.po.PtlAgreement;
 import com.jzg.commons.entity.po.PtlAgreement;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.jzg.commons.entity.po.PtlAgreementCost;
 import com.jzg.commons.entity.vo.AgreementInfoVo;
 import com.jzg.commons.entity.vo.AgreementInfoVo;
 import com.jzg.commons.entity.vo.AgreementUserVo;
 import com.jzg.commons.entity.vo.AgreementUserVo;
 import com.jzg.commons.entity.vo.AgreementVo;
 import com.jzg.commons.entity.vo.AgreementVo;
 import com.jzg.commons.entity.vo.UpAndDownVo;
 import com.jzg.commons.entity.vo.UpAndDownVo;
 
 
 import java.util.List;
 import java.util.List;
+import java.util.Map;
 
 
 /**
 /**
 * @author dongxin
 * @author dongxin
@@ -101,4 +103,14 @@ public interface PtlAgreementService extends IService<PtlAgreement> {
      * @param param
      * @param param
      */
      */
     void agreementCopy(AgreementCopyParam param);
     void agreementCopy(AgreementCopyParam param);
+
+    /**
+     * 复制承保规则和费用
+     * @param costGroup
+     * @param costIds
+     */
+    void copyRuleAndCost(Map<String, List<PtlAgreementCost>> costGroup,
+                         List<String> costIds,
+                         List<PtlAgreementCost> costList,
+                         PtlAgreement newAgreement);
 }
 }

+ 114 - 11
tenant/organization/src/main/java/com/jzg/organization/service/impl/PtlAgreementServiceImpl.java

@@ -2,8 +2,6 @@ package com.jzg.organization.service.impl;
 
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.convert.Convert;
 import cn.hutool.core.convert.Convert;
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -15,10 +13,7 @@ import com.jzg.commons.entity.dto.AgreementEditParam;
 import com.jzg.commons.entity.dto.AgreementParam;
 import com.jzg.commons.entity.dto.AgreementParam;
 import com.jzg.commons.entity.enums.YesNoEnum;
 import com.jzg.commons.entity.enums.YesNoEnum;
 import com.jzg.commons.entity.po.*;
 import com.jzg.commons.entity.po.*;
-import com.jzg.commons.entity.vo.AgreementInfoVo;
-import com.jzg.commons.entity.vo.AgreementUserVo;
-import com.jzg.commons.entity.vo.AgreementVo;
-import com.jzg.commons.entity.vo.UpAndDownVo;
+import com.jzg.commons.entity.vo.*;
 import com.jzg.commons.exception.SystemException;
 import com.jzg.commons.exception.SystemException;
 import com.jzg.commons.util.MinioUtils;
 import com.jzg.commons.util.MinioUtils;
 import com.jzg.commons.util.StringUtils;
 import com.jzg.commons.util.StringUtils;
@@ -35,9 +30,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 
 
 import java.time.LocalDateTime;
 import java.time.LocalDateTime;
-import java.util.List;
-import java.util.Objects;
-import java.util.Set;
+import java.util.*;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
 
 
 /**
 /**
@@ -71,6 +64,12 @@ public class PtlAgreementServiceImpl extends ServiceImpl<PtlAgreementMapper, Ptl
     @Autowired
     @Autowired
     private PtlAgreementCostService agreementCostService;
     private PtlAgreementCostService agreementCostService;
 
 
+    @Autowired
+    private PtlAgreementCostRuleService agreementCostRuleService;
+
+    @Autowired
+    private PtlAgreementCostTypeService agreementCostTypeService;
+
     @Autowired
     @Autowired
     private PtlAgreementUndwrtRulesAttrService agreementUndwrtRulesAttrService;
     private PtlAgreementUndwrtRulesAttrService agreementUndwrtRulesAttrService;
 
 
@@ -230,18 +229,122 @@ public class PtlAgreementServiceImpl extends ServiceImpl<PtlAgreementMapper, Ptl
     }
     }
 
 
     @Override
     @Override
+    @Transactional(rollbackFor = {Exception.class})
     public void agreementCopy(AgreementCopyParam param) {
     public void agreementCopy(AgreementCopyParam param) {
+        PtlAgreement agreement = getById(param.getId());
+        // 获取保险公司信息
+        HttpResult<EsmInsCompany> result = companyClient.findById(agreement.getCompanyId());
+        String companyCode = "";
+        if(result.getCode() == 200 && Objects.nonNull(result.getData())){
+            companyCode = result.getData().getCompanyCode();
+        }else{
+            throw new SystemException("无法获取到保险公司信息");
+        }
+        String sysCode = baseController.getUserSystemCode();
+        PtlAgreement newAgreement = new PtlAgreement();
+        BeanUtils.copyProperties(agreement,newAgreement);
+        newAgreement.setId(null);
+        newAgreement.setAgreementCode(sysCode + companyCode + +System.currentTimeMillis());
+        newAgreement.setAuditStatus(0);
+        save(newAgreement);
+
         List<String> costIds = param.getCostIds();
         List<String> costIds = param.getCostIds();
         List<PtlAgreementCost> costList = agreementCostService.listByIds(costIds);
         List<PtlAgreementCost> costList = agreementCostService.listByIds(costIds);
         if(CollUtil.isEmpty(costList)){
         if(CollUtil.isEmpty(costList)){
             return;
             return;
         }
         }
-        Set<String> agreementIds = costList.stream().map(PtlAgreementCost::getPtlAgreementId)
-                .collect(Collectors.toSet());
 
 
+        Map<String,List<PtlAgreementCost>> costGroup = new HashMap<>();
+        for (PtlAgreementCost ptlAgreementCost : costList) {
+            List<PtlAgreementCost> costGroupList = new ArrayList<>();
+            if(costGroup.containsKey(ptlAgreementCost.getCoverRuleId())){
+                costGroupList = costGroup.get(ptlAgreementCost.getCoverRuleId());
+                costGroupList.add(ptlAgreementCost);
+                costGroup.put(ptlAgreementCost.getCoverRuleId(), costGroupList);
+            }else{
+                costGroupList.add(ptlAgreementCost);
+                costGroup.put(ptlAgreementCost.getCoverRuleId(), costGroupList);
+            }
+        }
 
 
+        /** 复制承保规则和费用 **/
+        this.copyRuleAndCost(costGroup,costIds,costList,newAgreement);
 
 
+    }
+
+    public void copyRuleAndCost(Map<String, List<PtlAgreementCost>> costGroup,
+                                List<String> costIds,
+                                List<PtlAgreementCost> costList,
+                                PtlAgreement newAgreement) {
+
+        // 获取查询所有的旧承保规则
+        Set<String> rulesIds = costList.stream().map(PtlAgreementCost :: getCoverRuleId).collect(Collectors.toSet());
+        List<PtlAgreementUndwrtRules> rulesList = agreementRulesService.listByIds(rulesIds);
+        Map<String, PtlAgreementUndwrtRules> rulesMap = rulesList.stream().collect(
+                Collectors.toMap(PtlAgreementUndwrtRules::getId,rules -> rules));
+
+        // 查询所有承保规则明细
+        LambdaQueryWrapper<PtlAgreementUndwrtRulesAttrLink> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.in(PtlAgreementUndwrtRulesAttrLink::getId, rulesIds);
+        List<PtlAgreementUndwrtRulesAttrLink> linkList = agreementUndwrtRulesAttrLinkService.list(queryWrapper);
+        Map<String, List<PtlAgreementUndwrtRulesAttrLink>> linkMap = linkList.stream().collect(
+                Collectors.groupingBy(PtlAgreementUndwrtRulesAttrLink::getRulesId));
+
+        // 查询所有旧的费用规则
+        LambdaQueryWrapper<PtlAgreementCostRule> costRuleLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        costRuleLambdaQueryWrapper.in(PtlAgreementCostRule::getPtlAgreementCostId, costIds);
+        List<PtlAgreementCostRule> costRuleList = agreementCostRuleService.list(costRuleLambdaQueryWrapper);
+        Map<String, List<PtlAgreementCostRule>> costRulesMap = costRuleList.stream().collect(
+                Collectors.groupingBy(PtlAgreementCostRule::getPtlAgreementCostId));
+        // 查询所有旧的费用明细
+        LambdaQueryWrapper<PtlAgreementCostType> costTypeLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        costTypeLambdaQueryWrapper.in(PtlAgreementCostType::getPtlAgreementCostId, costIds);
+        List<PtlAgreementCostType> costTypeList = agreementCostTypeService.list(costTypeLambdaQueryWrapper);
+        Map<String, List<PtlAgreementCostType>> costTypeMap = costTypeList.stream().collect(
+                Collectors.groupingBy(PtlAgreementCostType::getPtlAgreementCostId));
+
+        costGroup.forEach((key, value) -> {
+
+            /** 1-承保规则复制 **/
+            PtlAgreementUndwrtRules agreementUndwrtRules = rulesMap.get(key);
+            PtlAgreementUndwrtRules newAgreementUndwrtRules = new PtlAgreementUndwrtRules();
+            BeanUtils.copyProperties(agreementUndwrtRules,newAgreementUndwrtRules);
+            newAgreementUndwrtRules.setId(null);
+            newAgreementUndwrtRules.setAgreementId(newAgreement.getId());
+            agreementRulesService.save(newAgreementUndwrtRules);
+
+            // 复制承保规则因子
+            List<PtlAgreementUndwrtRulesAttrLink> links = linkMap.get(agreementUndwrtRules.getId());
+            links.forEach(link -> {
+                link.setId(null);
+                link.setRulesId(newAgreementUndwrtRules.getId());
+            });
+            agreementUndwrtRulesAttrLinkService.saveBatch(links);
+
+            /** 2-费用复制 **/
+            List<PtlAgreementCost> agreementCostList = costGroup.get(key);
+            agreementCostList.forEach(agreementCost -> {
+                PtlAgreementCost newAgreementCost = new PtlAgreementCost();
+                BeanUtils.copyProperties(agreementCost,newAgreementCost);
+                newAgreementCost.setId(null);
+                newAgreementCost.setApproved(0);
+                newAgreementCost.setIsEnabled(Boolean.TRUE);
+                agreementCostService.save(newAgreementCost);
+                List<PtlAgreementCostRule> costRules = costRulesMap.get(agreementCost.getId());
+                costRules.forEach(costRule -> {
+                    costRule.setId(null);
+                    costRule.setPtlAgreementCostId(newAgreementCost.getId());
+                });
+                agreementCostRuleService.saveBatch(costRules);
+                List<PtlAgreementCostType> costTypes = costTypeMap.get(agreementCost.getId());
+                costTypes.forEach(costType -> {
+                    costType.setId(null);
+                    costType.setPtlAgreementCostId(newAgreementCost.getId());
+                });
+                agreementCostTypeService.saveBatch(costTypes);
 
 
+            });
+        });
     }
     }
 
 
 }
 }