From 45a8fb5db1b0aa6d5cd39198ffc30dba5ec8b2d9 Mon Sep 17 00:00:00 2001
From: k94314517 <8417338+k94314517@user.noreply.gitee.com>
Date: 星期三, 10 四月 2024 18:24:15 +0800
Subject: [PATCH] git ch

---
 server/service/src/main/java/com/doumee/service/business/impl/UnionApplyServiceImpl.java |  117 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 101 insertions(+), 16 deletions(-)

diff --git a/server/service/src/main/java/com/doumee/service/business/impl/UnionApplyServiceImpl.java b/server/service/src/main/java/com/doumee/service/business/impl/UnionApplyServiceImpl.java
index 7f6ff0e..ba9b444 100644
--- a/server/service/src/main/java/com/doumee/service/business/impl/UnionApplyServiceImpl.java
+++ b/server/service/src/main/java/com/doumee/service/business/impl/UnionApplyServiceImpl.java
@@ -12,10 +12,7 @@
 import com.doumee.core.utils.Utils;
 import com.doumee.dao.business.*;
 import com.doumee.dao.business.dto.*;
-import com.doumee.dao.business.join.ApplyDetailJoinMapper;
-import com.doumee.dao.business.join.ApplyLogJoinMapper;
-import com.doumee.dao.business.join.InsuranceApplyJoinMapper;
-import com.doumee.dao.business.join.UnionApplyJoinMapper;
+import com.doumee.dao.business.join.*;
 import com.doumee.dao.business.model.*;
 import com.doumee.dao.system.model.SystemUser;
 import com.doumee.service.business.SmsEmailService;
@@ -35,6 +32,7 @@
 import com.github.xiaoymin.knife4j.core.util.CollectionUtils;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -80,6 +78,10 @@
     @Autowired
     private ApplyLogJoinMapper applyLogJoinMapper;
 
+    @Autowired
+    private MemberInsuranceJoinMapper memberInsuranceJoinMapper;
+    @Autowired
+    private MemberMapper memberMapper;
     @Value("${debug_model}")
     private boolean debugModel;
 
@@ -146,8 +148,22 @@
         MPJLambdaWrapper<UnionApply> queryWrapper = new MPJLambdaWrapper<>();
         Utils.MP.blankToNull(pageWrap.getModel());
         queryWrapper.selectAll(UnionApply.class);
-        queryWrapper.selectAs(Solutions::getName,UnionApply::getSolutionName);
+        queryWrapper.selectAs(Solutions::getName,UnionApply::getSolutionName)
+          .selectAs(Solutions::getMaxAge,UnionApply::getMaxAge)
+                .selectAs(Solutions::getMinAge,UnionApply::getMinAge)
+                .selectAs(Solutions::getPrice,UnionApply::getPrice)
+                .selectAs(Solutions::getTimeUnit,UnionApply::getTimeUnit)
+                .selectAs(Solutions::getOrtherInfo,UnionApply::getOrtherInfo)
+                .selectAs(Solutions::getSpecialAgreement,UnionApply::getSpecialAgreement)
+                .selectAs(Solutions::getSpecialInfo,UnionApply::getSpecialInfo);
         queryWrapper.select("(select count(b.id) from apply_detail b where b.isdeleted=0 and b.union_apply_id=t.id) as insureNum ");
+
+        queryWrapper.select("(select count(1) from apply_change a inner join insurance_apply b on a.apply_id = b.id  where b.union_apply_id=t.id " +
+                "and b.status = "+Constants.InsuranceApplyStatus.WTB_TOUBAOING.getKey()+" and a.type = 0  ) as addApplyNum ");
+
+        queryWrapper.select("(select count(1) from apply_change a inner join insurance_apply b on a.apply_id = b.id  where b.union_apply_id=t.id " +
+                "and b.status = "+Constants.InsuranceApplyStatus.WTB_TOUBAOING.getKey()+" and a.type = 1  ) as changeApplyNum ");
+
         queryWrapper.leftJoin(Solutions.class,Solutions::getId,UnionApply::getSolutionId);
         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
         if(Constants.equalsInteger(user.getType(),Constants.TWO)){
@@ -364,7 +380,6 @@
                 }
             }
         }
-
     }
 
 
@@ -409,7 +424,7 @@
         if(insuranceApplyList.size()!=saveUnionApplyDTO.getApplyIds().size()){
             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"瀛樺湪鏁版嵁宸插鐞嗭紝璇峰埛鏂伴噸璇�");
         }
-
+        saveUnionApplyDTO.setEndDate(DateUtil.getMontageDate(saveUnionApplyDTO.getEndDate(),2));
         UnionApply unionApply = new UnionApply();
         unionApply.setCreateDate(new Date());
         unionApply.setCreator(user.getId());
@@ -427,13 +442,22 @@
 
         Integer maxDays = DateUtil.calculateBetween(saveUnionApplyDTO.getStartDate(),saveUnionApplyDTO.getEndDate(),0);
 
-        List<ApplyDetail> applyDetailList = applyDetailJoinMapper.selectList(new QueryWrapper<ApplyDetail>().lambda().select(ApplyDetail::getId,ApplyDetail::getPrice)
+        List<ApplyDetail> applyDetailList = applyDetailJoinMapper.selectList(new QueryWrapper<ApplyDetail>().lambda()
+                .select(ApplyDetail::getId,ApplyDetail::getPrice,ApplyDetail::getStartTime,ApplyDetail::getEndTime,ApplyDetail::getFee)
                 .in(ApplyDetail::getApplyId,saveUnionApplyDTO.getApplyIds())
                 .eq(ApplyDetail::getIsdeleted,Constants.ZERO));
         if(applyDetailList.size()==0){
             throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"瀵逛笉璧凤紝瀛樺湪濮旀墭鎶曚繚鐢宠璁板綍淇℃伅鏈夎锛岃杩斿洖鏌ョ湅鐢宠浜哄憳鏄惁涓虹┖锛�");
         }
-        unionApply.setFee(applyDetailList.stream().map(i->Constants.formatBigdecimal(i.getPrice()).multiply(new BigDecimal(maxDays))).reduce(BigDecimal.ZERO,BigDecimal::add));
+        BigDecimal fee = BigDecimal.ZERO;
+        for (ApplyDetail applyDetail:applyDetailList) {
+            Integer oldDays = DateUtil.calculateBetween(applyDetail.getStartTime(),applyDetail.getEndTime(),0);
+            fee =fee.add(new BigDecimal(maxDays).multiply( applyDetail.getFee()).divide(new BigDecimal(oldDays),2,RoundingMode.HALF_UP));
+        }
+        unionApply.setFee(fee);
+
+//        unionApply.setFee(applyDetailList.stream()
+//                .map(i->Constants.formatBigdecimal(i.getPrice()).multiply(new BigDecimal(maxDays))).reduce(BigDecimal.ZERO,BigDecimal::add));
 
         unionApplyMapper.insert(unionApply);
 
@@ -612,6 +636,13 @@
         multifile.setFileurl(uploadMultifileDTO.getFileurl());
         multifile.setName(uploadMultifileDTO.getName());
         multifileMapper.insert(multifile);
+
+
+        Constants.ApplyLogType applyLogType = Constants.ApplyLogType.IA_HBD_UPLOAD_TBD;
+        ApplyLog log = new ApplyLog(unionApply,applyLogType.getName(), null
+                ,unionApply.getId(),applyLogType.getKey(),null, JSONObject.toJSONString(unionApply));
+        applyLogMapper.insert(log);
+
     }
 
 
@@ -714,8 +745,22 @@
         List<UnionApplyBXDDetailDTO> unionApplyBXDDetailDTOList = unionApplyBXDDTO.getUnionApplyBXDDDetailDTOList();
 
         //鎵�鏈夋姇淇濈敵璇蜂繚鍗曟槑缁嗚
-        List<ApplyDetail> applyDetailList = applyDetailJoinMapper.selectList(new QueryWrapper<ApplyDetail>().lambda().select(ApplyDetail::getPrice)
+        List<ApplyDetail> applyDetailList = applyDetailJoinMapper.selectJoinList(ApplyDetail.class,new MPJLambdaWrapper<ApplyDetail>()
+                        .selectAll(ApplyDetail.class)
+                .selectAs(DispatchUnit::getName,ApplyDetail::getDuName)
+                .selectAs(InsuranceApply::getCode,ApplyDetail::getApplyCode)
+                .selectAs(Solutions::getId,ApplyDetail::getSolutionId)
+                .selectAs(Solutions::getName,ApplyDetail::getSolutionName)
+                .selectAs(Worktype::getName,ApplyDetail::getWorkTypeName)
+                .selectAs(Member::getIdcardNo,ApplyDetail::getIdcardNo)
+                .selectAs(Member::getName,ApplyDetail::getMemberName)
+                .leftJoin(DispatchUnit.class,DispatchUnit::getId,ApplyDetail::getDuId)
+                .leftJoin(Worktype.class,Worktype::getId,ApplyDetail::getWorktypeId)
+                .leftJoin(Member.class,Member::getId,ApplyDetail::getMemberId)
+                .leftJoin(InsuranceApply.class,InsuranceApply::getId,ApplyDetail::getApplyId)
+                .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
                 .in(ApplyDetail::getUnionApplyId,unionApply.getId()));
+        unionApplyBXDDTO.setEndTime(DateUtil.getMontageDate(unionApplyBXDDTO.getEndTime(),2));
         //鎬诲ぉ鏁�
         Integer maxDays = DateUtil.calculateBetween(unionApplyBXDDTO.getStartTime(),unionApplyBXDDTO.getEndTime(),0);
         //瀹為檯宸茬粡浜х敓璐圭敤鐨勫ぉ鏁�
@@ -732,11 +777,22 @@
         List<InsuranceApply> insuranceApplyList = insuranceApplyJoinMapper.selectList(new QueryWrapper<InsuranceApply>()
                 .lambda().eq(InsuranceApply::getUnionApplyId,unionApply.getId()));
         for (InsuranceApply insuranceApply:insuranceApplyList) {
-            BigDecimal price = insuranceApply.getPrice();
-            Optional<UnionApplyBXDDetailDTO> unionApplyBXDDDetailTO= unionApplyBXDDetailDTOList.stream().filter(m->m.getApplyId().equals(insuranceApply.getId())).findFirst();
+            List<ApplyDetail> applyDetails = applyDetailList.stream()
+                    .filter(m->Constants.equalsInteger(m.getApplyId(),(insuranceApply.getId()))).collect(Collectors.toList());
+            if(CollectionUtils.isEmpty(applyDetails)){
+                continue;
+            }
+            BigDecimal price = Constants.formatBigdecimal(applyDetails.get(Constants.ZERO).getPrice());
+
+            Optional<UnionApplyBXDDetailDTO> unionApplyBXDDDetailTO= unionApplyBXDDetailDTOList.stream().filter(
+                    m->m.getApplyId().equals(insuranceApply.getId())).findFirst();
+            BigDecimal serverCost = BigDecimal.ZERO;
             if(unionApplyBXDDDetailTO.isPresent()){
                 UnionApplyBXDDetailDTO unionApplyBXDDetailDTO = unionApplyBXDDDetailTO.get();
-                price = price.add(unionApplyBXDDetailDTO.getServerMoney());
+                serverCost = unionApplyBXDDetailDTO.getServerMoney();
+                BigDecimal dayServerMoney = unionApplyBXDDetailDTO.getServerMoney().divide(new BigDecimal(maxDays),2, RoundingMode.HALF_UP);
+
+                price = Constants.formatBigdecimal(price).add(Constants.formatBigdecimal(dayServerMoney));
                 //涓婁紶淇濆崟淇℃伅
                 if(StringUtils.isNotBlank(unionApplyBXDDetailDTO.getFileUrl())){
                     Multifile multifile = new Multifile();
@@ -761,10 +817,36 @@
             }else if(useDays>0){
                 currentFee =  new BigDecimal(useDays).multiply(price);
             }
+            //鐢熸垚鎶曚繚璁板綍
+            if(CollectionUtils.isNotEmpty(applyDetailList)){
+                List<MemberInsurance> memberInsuranceList = new ArrayList<>();
+                for (ApplyDetail applyDetail:applyDetailList.stream()
+                        .filter(m->Constants.equalsInteger(m.getApplyId(),(insuranceApply.getId()))).collect(Collectors.toList())) {
+                    applyDetail.setPrice(price);
+                    applyDetail.setFee(price.multiply(new BigDecimal(maxDays)));
+                    applyDetail.setStartTime(unionApplyBXDDTO.getStartTime());
+                    applyDetail.setEndTime(unionApplyBXDDTO.getEndTime());
+                    MemberInsurance memberInsurance = new MemberInsurance(applyDetail,user.getId());
+                    memberInsurance.setBdCode(unionApplyBXDDTO.getCode());
+                    memberInsurance.setRelationType(Constants.ZERO);
+                    memberInsuranceList.add(memberInsurance);
+                    //鏇存柊鍛樺伐鎶曚繚鏃堕棿
+                    memberMapper.update(null,new UpdateWrapper<Member>()
+                            .lambda()
+                            .set(Member::getStartTime,memberInsurance.getStartTime())
+                            .set(Member::getEndTime,memberInsurance.getEndTime())
+                            .set(Member::getDuId,memberInsurance.getDuId())
+                            .set(Member::getWorktypeId,memberInsurance.getWorktypeId())
+                            .eq(Member::getId, memberInsurance.getMemberId())
+                    );
 
-            List<ApplyDetail> applyDetails = applyDetailList.stream().filter(m->m.getApplyId().equals(insuranceApply.getId())).collect(Collectors.toList());
+                }
+                memberInsuranceJoinMapper.insertBatchSomeColumn(memberInsuranceList);
+            }
+
             //鏇存柊鎶曚繚鐢宠鍗�
             insuranceApplyJoinMapper.update(null,new UpdateWrapper<InsuranceApply>().lambda()
+                    .set(InsuranceApply::getUnionApplyTbdStatus,Constants.THREE)
                     .set(InsuranceApply::getStatus,Constants.InsuranceApplyStatus.WTB_DONE.getKey())
                     .set(InsuranceApply::getFee,price.multiply(new BigDecimal(applyDetails.size())).multiply(new BigDecimal(maxDays)))
                     .set(InsuranceApply::getCurrentFee,currentFee.multiply(new BigDecimal(applyDetails.size())))
@@ -772,6 +854,8 @@
                     .set(InsuranceApply::getEndTime,unionApplyBXDDTO.getEndTime())
                     .set(InsuranceApply::getEditDate,new Date())
                     .set(InsuranceApply::getEditor,user.getId())
+                    .set(InsuranceApply::getServerCost,serverCost)
+                    .set(InsuranceApply::getCode,unionApplyBXDDTO.getCode())
                     .eq(InsuranceApply::getId,insuranceApply.getId()));
             //鏇存柊鎶曚繚鍗曟槑缁嗛噾棰�
             applyDetailJoinMapper.update(null,new UpdateWrapper<ApplyDetail>().lambda()
@@ -790,11 +874,12 @@
 
         unionApplyMapper.update(null,new UpdateWrapper<UnionApply>()
                 .lambda()
-                .set(UnionApply::getStatus,Constants.UnionApplyStatus.FINISH)
+                .set(UnionApply::getStatus,Constants.UnionApplyStatus.FINISH.getKey())
                 .set(UnionApply::getEditDate,new Date())
                 .set(UnionApply::getEditor,user.getId())
                 .set(UnionApply::getStartTime,unionApplyBXDDTO.getStartTime())
                 .set(UnionApply::getEndTime,unionApplyBXDDTO.getEndTime())
+                .set(UnionApply::getCode,unionApplyBXDDTO.getCode())
                 .set(UnionApply::getFee,sumFee)
                 .set(UnionApply::getCurrentFee,sumCurrFee)
                 .eq(UnionApply::getId,unionApply.getId())
@@ -813,7 +898,7 @@
             multifileMapper.insert(multifile);
         }
 
-        Constants.ApplyLogType applyLogType = Constants.ApplyLogType.IA_HBD_UPLOAD_TBD;
+        Constants.ApplyLogType applyLogType = Constants.ApplyLogType.IA_HBD_UPLOAD_BXD;
         String info = "";
         if(Objects.nonNull(unionApplyBXDDTO.getStartTime())&&Objects.nonNull(unionApplyBXDDTO.getEndTime())){
             info =applyLogType.getInfo();

--
Gitblit v1.9.3