k94314517
2024-04-01 0c1ac49f859a0570a19f267d6def82100cb39860
server/service/src/main/java/com/doumee/service/business/impl/InsuranceApplyServiceImpl.java
@@ -42,6 +42,7 @@
import java.io.File;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
@@ -102,6 +103,8 @@
    private NoticesMapper noticesMapper;
    @Autowired
    private UnionApplyJoinMapper unionApplyJoinMapper;
    @Autowired
    private UnionChangeJoinMapper unionChangeJoinMapper;
    @Override
    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
@@ -152,6 +155,39 @@
        applyLogMapper.insert(log);
        return  1;
    }
    @Override
    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
    public Integer closeWtbForShop(InsuranceApply insuranceApply) {
        if(insuranceApply.getId() == null ||StringUtils.isBlank(insuranceApply.getCheckInfo())){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        InsuranceApply model = insuranceApplyMapper.selectById(insuranceApply.getId());
        if(model == null ||!Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        //只有审核通过的状态可关闭
        if(!Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.WTB_BUSINESS_CHECK_PASS.getKey())){
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该申请状态已流转,当前不支持该操作~");
        }
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        InsuranceApply update = new InsuranceApply();
        update.setEditDate(new Date());
        update.setEditor(user.getId());
        update.setStatus(Constants.InsuranceApplyStatus.WTB_CLOSED.getKey());
        update.setCheckDate(update.getEditDate());
        update.setCheckInfo(insuranceApply.getCheckInfo());
        update.setCheckUserId(user.getId());
        update.setId(model.getId());
        insuranceApplyMapper.updateById(update);
        Constants.ApplyLogType applyLogType = Constants.ApplyLogType.SHOP_CLOSE_WTB_APPLY;
        String info =applyLogType.getInfo();
        info = info.replace("${param}", update.getCheckInfo());
        ApplyLog log = new ApplyLog(update,applyLogType.getName(),info,update.getId(),applyLogType.getKey(),JSONObject.toJSONString(model), JSONObject.toJSONString(update));
        applyLogMapper.insert(log);
        return  1;
    }
    @Override
@@ -717,15 +753,6 @@
        update.setId(model.getId());
        unionApplyJoinMapper.updateById(update);
        //存储待办信息
//        Constants.NoticeObjectType noticeObjectType = Constants.NoticeObjectType.INSURANCE_APPLY;
//        //删除其他待办
//        noticesMapper.delete(new QueryWrapper<Notices>().lambda().eq(Notices::getObjType,noticeObjectType.getKey())
//                .ne(Notices::getType,Constants.NoticeType.SIX.getStatus())
//                .eq(Notices::getObjId,model.getId()));
//        Notices notices = new Notices(noticeObjectType,Constants.ZERO,model.getId(),model.getSolutionsName(),model.getCompanyId(),Constants.NoticeType.TWO);
//        noticesMapper.insert(notices);
        Multifile f = new Multifile();
        f.setIsdeleted(Constants.ZERO);
        f.setCreator(model.getCreator());
@@ -738,11 +765,49 @@
        f.setInfo("商户签署投保单");
        f.setName("商户签署投保单.pdf");
        multifileMapper.insert(f);
//        Constants.ApplyLogType applyLogType = Constants.ApplyLogType.SIGNATURE;
//        ApplyLog log = new ApplyLog(update,applyLogType.getName(), null,update.getId(),applyLogType.getKey(),JSONObject.toJSONString(model), JSONObject.toJSONString(update));
//        applyLogMapper.insert(log);
//
//        startSendEmail(f, model.getCompanyName(),model.getSolutionsName(),model.getSolutionEmail());
        Constants.ApplyLogType applyLogType = Constants.ApplyLogType.IA_HBD_SIGNATURE_TBD;
        ApplyLog log = new ApplyLog(model,applyLogType.getName(), null
                ,model.getId(),applyLogType.getKey(),null, JSONObject.toJSONString(model));
        applyLogMapper.insert(log);
        return  f;
    }
    /**
     * 商户合并单(加减保/换厂) 商户签署投保申请单
     * @param model
     * @param fileurl
     * @param fullUrl
     * @return
     */
    public Multifile   uploadUnionChangeSignedFileDo(UnionChange model,String fileurl,String fullUrl) {
        UnionChange update = new UnionChange();
        update.setEditDate(new Date());
        update.setEditor(model.getCreator());
        update.setStatus(Constants.UnionChangeStatus.UPLOAD_INSURANCE_POLICY.getKey());
        update.setId(model.getId());
        unionChangeJoinMapper.updateById(update);
        Multifile f = new Multifile();
        f.setIsdeleted(Constants.ZERO);
        f.setCreator(model.getCreator());
        f.setObjId(update.getId());
        f.setCreateDate(update.getEditDate());
        f.setObjType(Constants.MultiFile.WTB_CA_TBD_PDF.getKey());
        f.setType(Constants.TWO);
        f.setFileurl(fileurl);
        f.setFileurlFull(fullUrl);
        f.setInfo("委托加减保/换厂业务 -投保单");
        f.setName("委托加减保/换厂业务 -投保单.pdf");
        multifileMapper.insert(f);
        Constants.ApplyLogType applyLogType = Constants.ApplyLogType.CA_HBD_SIGNATURE_TBD;
        ApplyLog log = new ApplyLog(model,applyLogType.getName(), null
                ,model.getId(),applyLogType.getKey(),null, JSONObject.toJSONString(model));
        applyLogMapper.insert(log);
        return  f;
    }
@@ -971,11 +1036,32 @@
                    continue;
                }
                uploadUnionApplySignedFileDo(model,fileUrl,path+fileUrl);
//                return;
            }
        }
        /**
         *合并加减保换厂 签署业务
         */
        List<UnionChange> unionChangeList = unionChangeJoinMapper.selectJoinList(UnionChange.class,
                new MPJLambdaWrapper<UnionChange>()
                        .selectAll(UnionChange.class)
                        .eq(UnionChange::getStatus,Constants.UnionChangeStatus.MERGE.getKey())
                        .isNotNull(UnionChange::getSignApplyNo));
        if(unionChangeList !=null && unionChangeList.size()>0 ){
            for(UnionChange model : unionChangeList){
                String status = signService.linkFileStatus(model.getSignApplyNo());
                if(!StringUtils.equals(status,"3")){
                    continue;
                }
                String link = signService.linkFile(model.getSignApplyNo());
                String fileUrl = uploadSignFile(link);
                if(StringUtils.isBlank(fileUrl)){
                    //如果下载失败,清除合同,下次签章重新生成新合同
                    continue;
                }
                uploadUnionChangeSignedFileDo(model,fileUrl,path+fileUrl);
            }
        }
@@ -1146,6 +1232,27 @@
                }
                uploadUnionApplySignedFileDo(unionApply,fileUrl,path+fileUrl);
            }
            /**
             *合并加减保换厂 签署业务
             */
            UnionChange unionChange = unionChangeJoinMapper.selectOne(
                    new MPJLambdaWrapper<UnionChange>()
                            .selectAll(UnionChange.class)
                            .eq(UnionChange::getSignApplyNo,data.getApplyNo())
                            .last(" limit 1 "));
            if(unionChange != null &&Constants.equalsInteger(unionChange.getStatus(),Constants.UnionChangeStatus.MERGE.getKey())){
                String link = signService.linkFile(model.getSignApplyNo());
                String fileUrl = uploadSignFile(link);
                if(StringUtils.isBlank(fileUrl)){
                    //如果下载失败,清除合同,下次签章重新生成新合同
                    return;
                }
                uploadUnionChangeSignedFileDo(unionChange,fileUrl,path+fileUrl);
            }
        }else if(Constants.equalsInteger(data.getSignStatus(), Constants.TWO )){
            //如果已拒签,清除合同,下次签章重新生成新合同
            insuranceApplyMapper.update(null,new UpdateWrapper<InsuranceApply>().lambda()
@@ -1166,6 +1273,9 @@
            applyChangeMapper.update(null,new UpdateWrapper<ApplyChange>().lambda()
                    .set(ApplyChange::getSignMemberListNo,null)
                    .eq(ApplyChange::getSignMemberListNo,data.getApplyNo()));
            unionChangeJoinMapper.update(null,new UpdateWrapper<UnionChange>().lambda()
                    .set(UnionChange::getSignApplyNo,null)
                    .eq(UnionChange::getSignApplyNo,data.getApplyNo()));
        }
    }
@@ -1261,15 +1371,19 @@
        if(Objects.isNull(solutions)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询方案信息");
        }
        if(solutions.getType().equals(Constants.ZERO)){
        if(Constants.equalsObject(solutions.getType(),Constants.ZERO)){
            if(!Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.UPLOAD.getKey())){
                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该申请状态已流转,当前不支持该操作~");
            }
        }else{
            if(!user.getType().equals(Constants.TWO)){
            if(!Constants.equalsObject(user.getType(),Constants.TWO)){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"非商户端无法进行该操作");
            }
            if(!Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.WTB_RETURN.getKey())){
            //委托保待签署、待审核可进行退回操作
            if(!(Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.WTB_UPLOAD.getKey())
                    ||Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.WTB_COMPANY_APPLY_SIGNATURE.getKey())
                    ||Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.WTB_COMPANY_MEMBER_LIST_SIGNATURE.getKey())
                    )){
                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该申请状态已流转,当前不支持该操作~");
            }
        }
@@ -1286,9 +1400,14 @@
            //如果是不通过
            applyLogType = Constants.ApplyLogType.PLATFORM_RETURN ;
            update.setStatus(Constants.InsuranceApplyStatus.PLATFORM_RETURN.getKey());
            if(Constants.equalsObject(solutions.getType(),Constants.ONE)){
                update.setStatus(Constants.InsuranceApplyStatus.WTB_RETURN.getKey());
            }
        }else{
            applyLogType = Constants.ApplyLogType.PLATFORM_CHECK_PASS;
            update.setStatus(Constants.InsuranceApplyStatus.PLATFORM_CHECK_PASS.getKey());
            if(Constants.equalsObject(solutions.getType(),Constants.ONE)){
                update.setStatus(Constants.InsuranceApplyStatus.WTB_BUSINESS_CHECK_PASS.getKey());
            }
        }
        insuranceApplyMapper.updateById(update);
@@ -1380,9 +1499,7 @@
        applyLogMapper.insert(log);
        //发送待办业务
        //存储待办信息
        Constants.NoticeObjectType noticeObjectType = Constants.NoticeObjectType.INSURANCE_APPLY;
        //删除其他待办
@@ -1582,6 +1699,14 @@
                applyDetail.setSex(member.getSex());
                applyDetail.setFee(countCyclePriceVO.getCyclePrice());
                applyDetail.setCurrentFee(BigDecimal.ZERO);
                //获取计算总天数
                Integer maxDays = DateUtil.calculateBetween(applyDetail.getStartTime(),applyDetail.getEndTime(),0);
                if(Constants.equalsInteger(maxDays,0)||Objects.isNull(applyDetail.getFee())){
                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"投保信息异常:总天数与总金额错误");
                }
                applyDetail.setPrice(
                        applyDetail.getFee().divide(new BigDecimal(maxDays),2,RoundingMode.HALF_UP)
                );
                //验证派遣单位信息是否存在
                if(duSolutionList.stream().filter(d->d.getDispatchUnitId().equals(applyDetail.getDuId())).collect(Collectors.toList()).size()<=Constants.ZERO){
                    throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"【"+applyDetail.getMemberName()+"】员工派遣单位未查询到!");
@@ -1883,10 +2008,10 @@
                .selectAs(Solutions::getTimeUnit,InsuranceApply::getTimeUnit)
                .selectAs(Solutions::getType,InsuranceApply::getSolutionType)
                .selectAs(Solutions::getName,InsuranceApply::getSolutionsName)
                .selectAs(Solutions::getName,InsuranceApply::getShopName)
                .selectAs(Company::getName,InsuranceApply::getCompanyName)
                .select(" ( select max(ac.APPLY_START_TIME) from apply_change ac  where ac.apply_id = t.id and ac.status = 2 ) as lastChangeDate")
                .select(" ( select count(DISTINCT(ad.MEMBER_ID)) from apply_detail ad  where ad.apply_id = t.id ) as insureNum")
                .select(" t3.name as shopName")
                .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
                .leftJoin(Company.class,Company::getId,InsuranceApply::getCompanyId)
                .leftJoin(Company.class,Company::getId,Solutions::getShopId)
@@ -1954,11 +2079,14 @@
    private void initImgData(InsuranceApply model) {
        List<Multifile> multifiles = multifileMapper.selectList(new QueryWrapper<Multifile>().lambda()
                .eq(Multifile::getObjId,Constants.equalsInteger(model.getSolutionType(),Constants.ZERO)? model.getId():model.getUnionApplyId())
                .eq(Multifile::getObjId, model.getId())
                .in(Multifile::getObjType,Arrays.asList(new Integer[]{Constants.MultiFile.BD_APPLY_PDF.getKey()
                        ,Constants.MultiFile.BD_SIGNED_PDF.getKey()
                        ,Constants.MultiFile.WTB_CONFIRMATION_LATTER.getKey()
                        ,Constants.MultiFile.MEMBER_LIST_LATTER.getKey()
                        ,Constants.MultiFile.BD_DONE_PDF.getKey()}))
                .eq(Multifile::getIsdeleted,Constants.ZERO));
                .eq(Multifile::getIsdeleted,Constants.ZERO)
                .orderByAsc(Multifile::getId));
        if(multifiles!=null){
            String path = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()
                    +systemDictDataBiz.queryByCode(Constants.OSS,Constants.APPLY_FILE).getCode();
@@ -1976,6 +2104,12 @@
                }else if(Constants.equalsInteger(f.getObjType(),Constants.MultiFile.BD_DONE_PDF.getKey())){
                    //最終保险单
                    model.setBaoxiandanFile(f);
                }else if(Constants.equalsInteger(f.getObjType(),Constants.MultiFile.MEMBER_LIST_LATTER.getKey())){
                    //申请单
                    model.setShenqingdanFile(f);
                }else if(Constants.equalsInteger(f.getObjType(),Constants.MultiFile.WTB_CONFIRMATION_LATTER.getKey())){
                    //签署后确认书
                    model.setFanganFile(f);
                }
//                if(model.getStatus().equals(Constants.InsuranceApplyStatus.UPLOAD_INSURANCE.getKey())){
@@ -2107,6 +2241,30 @@
        ApplyLog log = new ApplyLog(insuranceApply,applyLogType.getName(),info,insuranceApply.getId(),applyLogType.getKey(),JSONObject.toJSONString(insuranceApply), JSONObject.toJSONString(insuranceApply));
        applyLogMapper.insert(log);
    }
    /**
     * 企业保障中人数
     * @return
     */
    @Override
    public Integer guaranteeNum() {
        LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(loginUserInfo.getType().equals(Constants.ZERO)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"非企业端用户无法进行该操作");
        }
        MPJLambdaWrapper<ApplyDetail> lambdaWrapper = new MPJLambdaWrapper<ApplyDetail>();
        lambdaWrapper.select(ApplyDetail::getId)
                .leftJoin(InsuranceApply.class,InsuranceApply::getId,ApplyDetail::getApplyId)
                .and(i->i.eq(InsuranceApply::getStatus,Constants.InsuranceApplyStatus.UPLOAD_INSURANCE.getKey()).or().eq(InsuranceApply::getStatus,Constants.InsuranceApplyStatus.WTB_DONE.getKey()))
                .eq(InsuranceApply::getCompanyId,loginUserInfo.getCompanyId())
                .apply(" now() between t.START_TIME and t.END_TIME ");
         Integer count = applyDetailJoinMapper.selectJoinCount(lambdaWrapper);
        return count;
    }
    /**
@@ -2289,7 +2447,7 @@
                .leftJoin(Worktype.class,Worktype::getId,ApplyDetail::getWorktypeId)
                .leftJoin(DispatchUnit.class,DispatchUnit::getId,ApplyDetail::getDuId)
                .isNull(ApplyDetail::getFromId)
                .eq(ApplyDetail::getId,model.getId())
                .eq(ApplyDetail::getApplyId,model.getId())
        );
        model.setApplyDetailList(applyDetailList);
        return model;