jiangping
2024-06-20 09da100729793848bc01b51f7b05ca3f1e7ec64f
server/service/src/main/java/com/doumee/service/business/impl/InsuranceApplyServiceImpl.java
@@ -1174,218 +1174,350 @@
    }
    @Override
    public   void dealSignResult(NotifyDataReq data){
    public   String dealSignResult(NotifyDataReq data){
        if(data.getApplyNo() == null ){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        if(Constants.equalsInteger(data.getSignStatus(), Constants.THREE )){
        if(Constants.equalsInteger(data.getSignStatus(), Constants.THREE )
                || Constants.equalsInteger(data.getSignStatus(), Constants.TWO )){
            //如果已保全,可下载签约附件
            String path = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+
                    systemDictDataBiz.queryByCode(Constants.OSS,Constants.APPLY_FILE).getCode();
            //直保 投保申请
            InsuranceApply model = insuranceApplyJoinMapper.selectJoinOne(InsuranceApply.class,
                    new MPJLambdaWrapper<InsuranceApply>()
                            .selectAll(InsuranceApply.class)
                            .selectAs(Solutions::getName,InsuranceApply::getSolutionsName)
                            .selectAs(Solutions::getEmail,InsuranceApply::getSolutionEmail)
                            .selectAs(Company::getName,InsuranceApply::getCompanyName)
                            .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
                            .leftJoin(Company.class,Company::getId,InsuranceApply::getCompanyId)
                            .eq(Solutions::getType,Constants.ZERO)
                            .eq(InsuranceApply::getSignApplyNo,data.getApplyNo())
                            .last("limit 1" ));
            if(model != null && Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.WAIT_SIGNATURE.getKey())){
           String r = dealXBTBBiz(path,data,"直保-投保申请签署");
           if(StringUtils.isNotBlank(r)){
               return  r;
           }
            r = dealWTBQYQRSBiz(path,data,"委托保-企业方案确认书签署");
            if(StringUtils.isNotBlank(r)){
                return  r;
            }
            r = dealWTBQYRYMQDBiz(path,data,"委托保-企业人员名单签署");
            if(StringUtils.isNotBlank(r)){
                return  r;
            }
            r = dealWTBTBSQBiz(path,data,"委托保-投保申请书签署");
            if(StringUtils.isNotBlank(r)){
                return  r;
            }
            r = dealZBJJBQYBiz(path,data,"直保-加减保企业签署");
            if(StringUtils.isNotBlank(r)){
                return  r;
            }
            r = dealWTBJJBQYBiz(path,data,"委托保-加减保企业签署");
            if(StringUtils.isNotBlank(r)){
                return  r;
            }
            r = dealHBDSHBiz(path,data,"投保合并单-商户签署签署");
            if(StringUtils.isNotBlank(r)){
                return  r;
            }
            r = dealHBCHANGEQYBiz(path,data,"合并加减保/换厂签署");
            if(StringUtils.isNotBlank(r)){
                return  r;
            }
        }
        return "无处理数据";
    }
    private String dealHBCHANGEQYBiz(String path, NotifyDataReq data, String title) {
        UnionChange unionChange = unionChangeJoinMapper.selectOne(
                new MPJLambdaWrapper<UnionChange>()
                        .selectAll(UnionChange.class)
                        .eq(UnionChange::getSignApplyNo,data.getApplyNo())
                        .last(" limit 1 "));
        if(unionChange == null){
            return null;
        }
        if( Constants.equalsInteger(unionChange.getStatus(),Constants.UnionChangeStatus.MERGE.getKey())){
            if(Constants.equalsInteger(data.getSignStatus(), Constants.THREE )){
                //完成签署已完成操作
                String link = signService.linkFile(data.getApplyNo());
                String link = signService.linkFile(unionChange.getSignApplyNo());
                String fileUrl = uploadSignFile(link);
                if(StringUtils.isBlank(fileUrl)){
                    //如果下载失败,清除合同,下次签章重新生成新合同
                    return;
                }
                uploadSignedFileDo(model,fileUrl,path+fileUrl);
                return;
            }
            //委托保 企业方案确认书
            InsuranceApply modelTBQRS = insuranceApplyJoinMapper.selectJoinOne(InsuranceApply.class,
                    new MPJLambdaWrapper<InsuranceApply>()
                            .selectAll(InsuranceApply.class)
                            .selectAs(Solutions::getName,InsuranceApply::getSolutionsName)
                            .selectAs(Solutions::getEmail,InsuranceApply::getSolutionEmail)
                            .selectAs(Company::getName,InsuranceApply::getCompanyName)
                            .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
                            .leftJoin(Company.class,Company::getId,InsuranceApply::getCompanyId)
                            .eq(Solutions::getType,Constants.ONE)
                            .eq(InsuranceApply::getSignQrsNo,data.getApplyNo())
                            .last("limit 1" ));
            if(modelTBQRS != null && Constants.equalsInteger(modelTBQRS.getStatus(),Constants.InsuranceApplyStatus.WTB_UPLOAD.getKey())){
                //完成签署已完成操作
                String link = signService.linkFile(data.getApplyNo());
                String fileUrl = uploadSignFile(link);
                if(StringUtils.isBlank(fileUrl)){
                    //如果下载失败,清除合同,下次签章重新生成新合同
                    return;
                }
                uploadFAQRSSignedFileDo(modelTBQRS,fileUrl,path+fileUrl);
                return;
            }
            //委托保 企业签署人员名单
            InsuranceApply modelMemberList = insuranceApplyJoinMapper.selectJoinOne(InsuranceApply.class,
                    new MPJLambdaWrapper<InsuranceApply>()
                            .selectAll(InsuranceApply.class)
                            .selectAs(Solutions::getName,InsuranceApply::getSolutionsName)
                            .selectAs(Solutions::getEmail,InsuranceApply::getSolutionEmail)
                            .selectAs(Company::getName,InsuranceApply::getCompanyName)
                            .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
                            .leftJoin(Company.class,Company::getId,InsuranceApply::getCompanyId)
                            .eq(Solutions::getType,Constants.ONE)
                            .eq(InsuranceApply::getSignMemberListNo,data.getApplyNo())
                            .last("limit 1" ));
            if(modelMemberList != null && Constants.equalsInteger(modelMemberList.getStatus(),Constants.InsuranceApplyStatus.WTB_COMPANY_APPLY_SIGNATURE.getKey())){
                //完成签署已完成操作
                String link = signService.linkFile(data.getApplyNo());
                String fileUrl = uploadSignFile(link);
                if(StringUtils.isBlank(fileUrl)){
                    //如果下载失败,清除合同,下次签章重新生成新合同
                    return;
                }
                uploadApplyMemberListSignedFileDo(modelMemberList,fileUrl,path+fileUrl);
                return;
            }
            //委托保 投保申请书签署
            InsuranceApply modelTBQSQ = insuranceApplyJoinMapper.selectJoinOne(InsuranceApply.class,
                    new MPJLambdaWrapper<InsuranceApply>()
                            .selectAll(InsuranceApply.class)
                            .selectAs(Solutions::getName,InsuranceApply::getSolutionsName)
                            .selectAs(Solutions::getEmail,InsuranceApply::getSolutionEmail)
                            .selectAs(Company::getName,InsuranceApply::getCompanyName)
                            .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
                            .leftJoin(Company.class,Company::getId,InsuranceApply::getCompanyId)
                            .eq(Solutions::getType,Constants.ONE)
                            .eq(InsuranceApply::getApplyTbdNo,data.getApplyNo())
                            .last("limit 1" ));
            if(modelTBQRS != null && Constants.equalsInteger(modelTBQSQ.getUnionApplyTbdStatus(),Constants.ONE)){
                //完成签署已完成操作
                String link = signService.linkFile(data.getApplyNo());
                String fileUrl = uploadSignFile(link);
                if(StringUtils.isBlank(fileUrl)){
                    //如果下载失败,清除合同,下次签章重新生成新合同
                    return;
                }
                uploadTBSQSSignedFileDo(modelTBQSQ,fileUrl,path+fileUrl);
                return;
            }
            //直保 加减保企业签署
            ApplyChange applyChange = applyChangeMapper.selectJoinOne(ApplyChange.class,
                    new MPJLambdaWrapper<ApplyChange>()
                            .selectAll(ApplyChange.class)
                            .selectAs(Solutions::getName,InsuranceApply::getSolutionsName)
                            .selectAs(Solutions::getEmail,InsuranceApply::getSolutionEmail)
                            .selectAs(Solutions::getId,ApplyChange::getSolutionsId)
                            .selectAs(Company::getName,InsuranceApply::getCompanyName)
                            .selectAs(InsuranceApply::getCompanyId,ApplyChange::getCompanyId)
                            .leftJoin(InsuranceApply.class,InsuranceApply::getId,ApplyChange::getApplyId)
                            .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
                            .leftJoin(Company.class,Company::getId,InsuranceApply::getCompanyId)
                            .eq(Solutions::getType,Constants.ZERO)
                            .eq(ApplyChange::getSignApplyNo,data.getApplyNo()).last("limit 1" ));
            if(applyChange != null &&Constants.equalsInteger(applyChange.getStatus(),Constants.ApplyChangeStatus.UPLOAD.getKey())){
                String link = signService.linkFile(data.getApplyNo());
                String fileUrl = uploadSignFile(link);
                if(StringUtils.isBlank(fileUrl)){
                    //如果下载失败,清除合同,下次签章重新生成新合同
                    return;
                }
                uploadChangeSignedFileDo(applyChange,fileUrl,path+fileUrl);
            }
            //委托保 加减保企业签署
            ApplyChange applyChangeMemberList = applyChangeMapper.selectJoinOne(ApplyChange.class,
                    new MPJLambdaWrapper<ApplyChange>()
                            .selectAll(ApplyChange.class)
                            .selectAs(Solutions::getName,InsuranceApply::getSolutionsName)
                            .selectAs(Solutions::getEmail,InsuranceApply::getSolutionEmail)
                            .selectAs(Solutions::getId,ApplyChange::getSolutionsId)
                            .selectAs(Company::getName,InsuranceApply::getCompanyName)
                            .selectAs(InsuranceApply::getCompanyId,ApplyChange::getCompanyId)
                            .leftJoin(InsuranceApply.class,InsuranceApply::getId,ApplyChange::getApplyId)
                            .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
                            .leftJoin(Company.class,Company::getId,InsuranceApply::getCompanyId)
                            .eq(Solutions::getType,Constants.ONE)
                            .eq(ApplyChange::getSignMemberListNo,data.getApplyNo()).last("limit 1" ));
            if(applyChangeMemberList != null &&Constants.equalsInteger(applyChangeMemberList.getStatus(),Constants.ApplyChangeStatus.UPLOAD.getKey())){
                String link = signService.linkFile(data.getApplyNo());
                String fileUrl = uploadSignFile(link);
                if(StringUtils.isBlank(fileUrl)){
                    //如果下载失败,清除合同,下次签章重新生成新合同
                    return;
                }
                uploadChangeMemberListSignedFileDo(applyChangeMemberList,fileUrl,path+fileUrl);
            }
            //投保合并单 商户签署保单
            UnionApply unionApply = unionApplyJoinMapper.selectOne(new QueryWrapper<UnionApply>()
                    .lambda().eq(UnionApply::getSignApplyNo,data.getApplyNo()).last(" limit 1 "));
            if(unionApply != null &&Constants.equalsInteger(unionApply.getStatus(),Constants.UnionApplyStatus.WAIT_SIGNATURE.getKey())){
                String link = signService.linkFile(data.getApplyNo());
                String fileUrl = uploadSignFile(link);
                if(StringUtils.isBlank(fileUrl)){
                    //如果下载失败,清除合同,下次签章重新生成新合同
                    return;
                }
                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;
                    return title+"合同下载失败,等待下次推送处理";
                }
                uploadUnionChangeSignedFileDo(unionChange,fileUrl,path+fileUrl);
                return title+"状态处理成功";
            }else{
                //如果已拒签,清除合同,下次签章重新生成新合同
                unionChangeJoinMapper.update(null,new UpdateWrapper<UnionChange>().lambda()
                        .set(UnionChange::getSignApplyNo,null)
                        .eq(UnionChange::getSignApplyNo,data.getApplyNo()));
                return title+"合同拒签处理成功";
            }
        }
        return  title+"状态已流转,不做处理";
    }
    private String dealHBDSHBiz(String path, NotifyDataReq data, String title) {
        //投保合并单 商户签署保单
        UnionApply unionApply = unionApplyJoinMapper.selectOne(new QueryWrapper<UnionApply>()
                .lambda().eq(UnionApply::getSignApplyNo,data.getApplyNo()).last(" limit 1 "));
        if(unionApply == null){
            return null;
        }
        if( Constants.equalsInteger(unionApply.getStatus(),Constants.UnionApplyStatus.WAIT_SIGNATURE.getKey())){
            if(Constants.equalsInteger(data.getSignStatus(), Constants.THREE )){
                //完成签署已完成操作
                String link = signService.linkFile(data.getApplyNo());
                String fileUrl = uploadSignFile(link);
                if(StringUtils.isBlank(fileUrl)){
                    //如果下载失败,清除合同,下次签章重新生成新合同
                    return title+"合同下载失败,等待下次推送处理";
                }
                uploadUnionApplySignedFileDo(unionApply,fileUrl,path+fileUrl);
                return title+"状态处理成功";
            }else{
                //如果已拒签,清除合同,下次签章重新生成新合同
                unionApplyJoinMapper.update(null,new UpdateWrapper<UnionApply>().lambda()
                        .set(UnionApply::getSignApplyNo,null)
                        .eq(UnionApply::getSignApplyNo,data.getApplyNo()));
                return title+"合同拒签处理成功";
            }
        }
        return  title+"状态已流转,不做处理";
    }
    private String dealWTBJJBQYBiz(String path, NotifyDataReq data, String title) {
        //委托保 加减保企业签署
        ApplyChange applyChangeMemberList = applyChangeMapper.selectJoinOne(ApplyChange.class,
                new MPJLambdaWrapper<ApplyChange>()
                        .selectAll(ApplyChange.class)
                        .selectAs(Solutions::getName,InsuranceApply::getSolutionsName)
                        .selectAs(Solutions::getEmail,InsuranceApply::getSolutionEmail)
                        .selectAs(Solutions::getId,ApplyChange::getSolutionsId)
                        .selectAs(Company::getName,InsuranceApply::getCompanyName)
                        .selectAs(InsuranceApply::getCompanyId,ApplyChange::getCompanyId)
                        .leftJoin(InsuranceApply.class,InsuranceApply::getId,ApplyChange::getApplyId)
                        .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
                        .leftJoin(Company.class,Company::getId,InsuranceApply::getCompanyId)
                        .eq(Solutions::getType,Constants.ONE)
                        .eq(ApplyChange::getSignMemberListNo,data.getApplyNo()).last("limit 1" ));
        if(applyChangeMemberList == null){
            return null;
        }
        if( Constants.equalsInteger(applyChangeMemberList.getStatus(),Constants.ApplyChangeStatus.UPLOAD.getKey())){
            if(Constants.equalsInteger(data.getSignStatus(), Constants.THREE )){
                //完成签署已完成操作
                String link = signService.linkFile(data.getApplyNo());
                String fileUrl = uploadSignFile(link);
                if(StringUtils.isBlank(fileUrl)){
                    //如果下载失败,清除合同,下次签章重新生成新合同
                    return title+"合同下载失败,等待下次推送处理";
                }
                uploadChangeMemberListSignedFileDo(applyChangeMemberList,fileUrl,path+fileUrl);
                return title+"状态处理成功";
            }else{
                //如果已拒签,清除合同,下次签章重新生成新合同
                applyChangeMapper.update(null,new UpdateWrapper<ApplyChange>().lambda()
                        .set(ApplyChange::getSignMemberListNo,null)
                        .eq(ApplyChange::getSignMemberListNo,data.getApplyNo()));
                return title+"合同拒签处理成功";
            }
        }
        return  title+"状态已流转,不做处理";
    }
    private String dealZBJJBQYBiz(String path, NotifyDataReq data, String title) {
        //直保 加减保企业签署
        ApplyChange applyChange = applyChangeMapper.selectJoinOne(ApplyChange.class,
                new MPJLambdaWrapper<ApplyChange>()
                        .selectAll(ApplyChange.class)
                        .selectAs(Solutions::getName,InsuranceApply::getSolutionsName)
                        .selectAs(Solutions::getEmail,InsuranceApply::getSolutionEmail)
                        .selectAs(Solutions::getId,ApplyChange::getSolutionsId)
                        .selectAs(Company::getName,InsuranceApply::getCompanyName)
                        .selectAs(InsuranceApply::getCompanyId,ApplyChange::getCompanyId)
                        .leftJoin(InsuranceApply.class,InsuranceApply::getId,ApplyChange::getApplyId)
                        .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
                        .leftJoin(Company.class,Company::getId,InsuranceApply::getCompanyId)
                        .eq(Solutions::getType,Constants.ZERO)
                        .eq(ApplyChange::getSignApplyNo,data.getApplyNo()).last("limit 1" ));
        if(applyChange == null){
            return null;
        }
        if( Constants.equalsInteger(applyChange.getStatus(),Constants.ApplyChangeStatus.UPLOAD.getKey())){
            if(Constants.equalsInteger(data.getSignStatus(), Constants.THREE )){
                //完成签署已完成操作
                String link = signService.linkFile(data.getApplyNo());
                String fileUrl = uploadSignFile(link);
                if(StringUtils.isBlank(fileUrl)){
                    //如果下载失败,清除合同,下次签章重新生成新合同
                    return title+"合同下载失败,等待下次推送处理";
                }
                uploadChangeSignedFileDo(applyChange,fileUrl,path+fileUrl);
                return title+"状态处理成功";
            }else{
                //如果已拒签,清除合同,下次签章重新生成新合同
                applyChangeMapper.update(null,new UpdateWrapper<ApplyChange>().lambda()
                        .set(ApplyChange::getSignApplyNo,null)
                        .eq(ApplyChange::getSignApplyNo,data.getApplyNo()));
                return title+"合同拒签处理成功";
            }
        }
        return  title+"状态已流转,不做处理";
    }
    private String dealWTBTBSQBiz(String path, NotifyDataReq data, String title) {
        //委托保 投保申请书签署
        InsuranceApply modelTBQSQ = insuranceApplyJoinMapper.selectJoinOne(InsuranceApply.class,
                new MPJLambdaWrapper<InsuranceApply>()
                        .selectAll(InsuranceApply.class)
                        .selectAs(Solutions::getName,InsuranceApply::getSolutionsName)
                        .selectAs(Solutions::getEmail,InsuranceApply::getSolutionEmail)
                        .selectAs(Company::getName,InsuranceApply::getCompanyName)
                        .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
                        .leftJoin(Company.class,Company::getId,InsuranceApply::getCompanyId)
                        .eq(Solutions::getType,Constants.ONE)
                        .eq(InsuranceApply::getApplyTbdNo,data.getApplyNo())
                        .last("limit 1" ));
        if(modelTBQSQ == null){
            return null;
        }
        if( Constants.equalsInteger(modelTBQSQ.getUnionApplyTbdStatus(),Constants.ONE)){
            if(Constants.equalsInteger(data.getSignStatus(), Constants.THREE )){
                //完成签署已完成操作
                String link = signService.linkFile(data.getApplyNo());
                String fileUrl = uploadSignFile(link);
                if(StringUtils.isBlank(fileUrl)){
                    //如果下载失败,清除合同,下次签章重新生成新合同
                    return title+"合同下载失败,等待下次推送处理";
                }
                uploadTBSQSSignedFileDo(modelTBQSQ,fileUrl,path+fileUrl);
                return title+"状态处理成功";
            }else{
                //如果已拒签,清除合同,下次签章重新生成新合同
                insuranceApplyJoinMapper.update(null,new UpdateWrapper<InsuranceApply>().lambda()
                        .set(InsuranceApply::getApplyTbdNo,null)
                        .eq(InsuranceApply::getApplyTbdNo,data.getApplyNo()));
                return title+"合同拒签处理成功";
            }
        }
        return  title+"状态已流转,不做处理";
    }
    private String dealWTBQYRYMQDBiz(String path, NotifyDataReq data, String title) {
        //委托保 企业签署人员名单
        InsuranceApply modelMemberList = insuranceApplyJoinMapper.selectJoinOne(InsuranceApply.class,
                new MPJLambdaWrapper<InsuranceApply>()
                        .selectAll(InsuranceApply.class)
                        .selectAs(Solutions::getName,InsuranceApply::getSolutionsName)
                        .selectAs(Solutions::getEmail,InsuranceApply::getSolutionEmail)
                        .selectAs(Company::getName,InsuranceApply::getCompanyName)
                        .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
                        .leftJoin(Company.class,Company::getId,InsuranceApply::getCompanyId)
                        .eq(Solutions::getType,Constants.ONE)
                        .eq(InsuranceApply::getSignMemberListNo,data.getApplyNo())
                        .last("limit 1" ));
        if(modelMemberList == null){
            return null;
        }
        if( Constants.equalsInteger(modelMemberList.getStatus(),Constants.InsuranceApplyStatus.WTB_COMPANY_APPLY_SIGNATURE.getKey())){
            if(Constants.equalsInteger(data.getSignStatus(), Constants.THREE )){
                //完成签署已完成操作
                String link = signService.linkFile(data.getApplyNo());
                String fileUrl = uploadSignFile(link);
                if(StringUtils.isBlank(fileUrl)){
                    //如果下载失败,清除合同,下次签章重新生成新合同
                    return title+"合同下载失败,等待下次推送处理";
                }
                uploadApplyMemberListSignedFileDo(modelMemberList,fileUrl,path+fileUrl);
                return title+"状态处理成功";
            }else{
                //如果已拒签,清除合同,下次签章重新生成新合同
                insuranceApplyMapper.update(null,new UpdateWrapper<InsuranceApply>().lambda()
                        .set(InsuranceApply::getSignMemberListNo,null)
                        .eq(InsuranceApply::getSignMemberListNo,data.getApplyNo()));
                return title+"合同拒签处理成功";
            }
        }
        return  title+"状态已流转,不做处理";
    }
    private String dealWTBQYQRSBiz(String path, NotifyDataReq data, String title) {
        //委托保 企业方案确认书
        InsuranceApply modelTBQRS = insuranceApplyJoinMapper.selectJoinOne(InsuranceApply.class,
                new MPJLambdaWrapper<InsuranceApply>()
                        .selectAll(InsuranceApply.class)
                        .selectAs(Solutions::getName,InsuranceApply::getSolutionsName)
                        .selectAs(Solutions::getEmail,InsuranceApply::getSolutionEmail)
                        .selectAs(Company::getName,InsuranceApply::getCompanyName)
                        .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
                        .leftJoin(Company.class,Company::getId,InsuranceApply::getCompanyId)
                        .eq(Solutions::getType,Constants.ONE)
                        .eq(InsuranceApply::getSignQrsNo,data.getApplyNo())
                        .last("limit 1" ));
        if(modelTBQRS == null){
            return null;
        }
        if(  Constants.equalsInteger(modelTBQRS.getStatus(),Constants.InsuranceApplyStatus.WTB_UPLOAD.getKey())){
            if(Constants.equalsInteger(data.getSignStatus(), Constants.THREE )){
                //完成签署已完成操作
                String link = signService.linkFile(data.getApplyNo());
                String fileUrl = uploadSignFile(link);
                if(StringUtils.isBlank(fileUrl)){
                    //如果下载失败,清除合同,下次签章重新生成新合同
                    return title+"合同下载失败,等待下次推送处理";
                }
                uploadFAQRSSignedFileDo(modelTBQRS,fileUrl,path+fileUrl);
                return title+"状态处理成功";
            }else{
                //如果已拒签,清除合同,下次签章重新生成新合同
                insuranceApplyMapper.update(null,new UpdateWrapper<InsuranceApply>().lambda()
                        .set(InsuranceApply::getSignQrsNo,null)
                        .eq(InsuranceApply::getSignQrsNo,data.getApplyNo()));
                return title+"合同拒签处理成功";
            }
        }else if(Constants.equalsInteger(data.getSignStatus(), Constants.TWO )){
            //如果已拒签,清除合同,下次签章重新生成新合同
            insuranceApplyMapper.update(null,new UpdateWrapper<InsuranceApply>().lambda()
                    .set(InsuranceApply::getSignApplyNo,null)
                    .eq(InsuranceApply::getSignApplyNo,data.getApplyNo()));
            applyChangeMapper.update(null,new UpdateWrapper<ApplyChange>().lambda()
                    .set(ApplyChange::getSignApplyNo,null)
                    .eq(ApplyChange::getSignApplyNo,data.getApplyNo()));
            insuranceApplyMapper.update(null,new UpdateWrapper<InsuranceApply>().lambda()
                    .set(InsuranceApply::getSignQrsNo,null)
                    .eq(InsuranceApply::getSignQrsNo,data.getApplyNo()));
            insuranceApplyMapper.update(null,new UpdateWrapper<InsuranceApply>().lambda()
                    .set(InsuranceApply::getSignMemberListNo,null)
                    .eq(InsuranceApply::getSignMemberListNo,data.getApplyNo()));
            unionApplyJoinMapper.update(null,new UpdateWrapper<UnionApply>().lambda()
                    .set(UnionApply::getSignApplyNo,null)
                    .eq(UnionApply::getSignApplyNo,data.getApplyNo()));
            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()));
        }
        return  title+"状态已流转,不做处理";
    }
    /**
     * 投保直保申请签署
     * @param path
     * @param data
     * @return
     */
    private String dealXBTBBiz(String path, NotifyDataReq data,String title) {
        InsuranceApply model = insuranceApplyJoinMapper.selectJoinOne(InsuranceApply.class,
                new MPJLambdaWrapper<InsuranceApply>()
                        .selectAll(InsuranceApply.class)
                        .selectAs(Solutions::getName,InsuranceApply::getSolutionsName)
                        .selectAs(Solutions::getEmail,InsuranceApply::getSolutionEmail)
                        .selectAs(Company::getName,InsuranceApply::getCompanyName)
                        .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
                        .leftJoin(Company.class,Company::getId,InsuranceApply::getCompanyId)
                        .eq(Solutions::getType,Constants.ZERO)
                        .eq(InsuranceApply::getSignApplyNo,data.getApplyNo())
                        .last("limit 1" ));
        if(model == null){
            return null;
        }
        if(  Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.WAIT_SIGNATURE.getKey())){
            //完成签署已完成操作
            if(Constants.equalsInteger(data.getSignStatus(), Constants.THREE )){
                String link = signService.linkFile(data.getApplyNo());
                String fileUrl = uploadSignFile(link);
                if(StringUtils.isBlank(fileUrl)){
                    //如果下载失败,清除合同,下次签章重新生成新合同
                    return title + "合同下载失败,等待下次推送处理";
                }
                uploadSignedFileDo(model,fileUrl,path+fileUrl);
                return title +"状态处理成功";
            }else{
                //如果已拒签,清除合同,下次签章重新生成新合同
                insuranceApplyMapper.update(null,new UpdateWrapper<InsuranceApply>().lambda()
                        .set(InsuranceApply::getSignApplyNo,null)
                        .eq(InsuranceApply::getSignApplyNo,data.getApplyNo()));
                return title+"合同拒签处理成功";
            }
        }
        return  title+"状态已流转,不做处理";
    }
@@ -1763,7 +1895,7 @@
                .apply(" t1.BASE_ID in ( select du.id from dispatch_unit du where du.STATUS = 0 and du.ISDELETED = 0 ) ")
        );
        if(!CollectionUtils.isNotEmpty(duSolutionList)){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"数据异常:保险方案下未查询到派遣单位");
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,保险方案下未查询到派遣单位信息,请确保派遣单位和工作配置并审核通过!");
        }
        //查询所有派遣单位下的工种
        List<Integer> duSolutionIdList = duSolutionList.stream().map(i->i.getId()).collect(Collectors.toList());
@@ -1775,7 +1907,7 @@
                .eq(checkNewData,Worktype::getDataType,Constants.TWO)
                .in(DuWorktype::getDuSolutionId,duSolutionIdList));
        if(!CollectionUtils.isNotEmpty(duWorktypeList)){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"数据异常:保险方案下未查询到工种信息");
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,保险方案下未查询到工种信息,请确保派遣单位和工作配置并审核通过!");
        }
        if(CollectionUtils.isNotEmpty(applyDetailList)){
@@ -1802,7 +1934,7 @@
                    member.setCompanyId(insuranceApply.getCompanyId());
                    member.setSex(Constants.getSexByIdCard(applyDetail.getIdcardNo()));
                    if(!IdcardUtil.isValidCard(applyDetail.getIdcardNo())){
                        throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"投保员工信息身份证信息错误["+member.getName()+"]");
                        throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,投保员工【"+member.getName()+"】身份证信息【"+applyDetail.getIdcardNo()+"】错误");
                    }
                    member.setIdcardNo(applyDetail.getIdcardNo());
                    member.setApplyId(insuranceApply.getId());
@@ -1825,7 +1957,7 @@
                        ||Objects.isNull(applyDetail.getDuId())
                        ||Objects.isNull(applyDetail.getWorktypeId())
                ){
                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"投保员工信息数据缺失");
                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,投保员工信息数据缺失,请按照要求填写员工的有效信息!");
                }
                applyDetail.setCreateDate(new Date());
                applyDetail.setCreator(loginUserInfo.getId());
@@ -1879,18 +2011,18 @@
                //获取计算总天数
                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(),"投保信息异常:总天数与总金额错误");
                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"投保信息异常:投保总天数与总金额错误");
                }
                applyDetail.setPrice(
                        applyDetail.getFee().divide(new BigDecimal(maxDays),7,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()+"】员工派遣单位未查询到!");
                    throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"【"+applyDetail.getMemberName()+applyDetail.getIdcardNo()+"】员工派遣单位未查询到!");
                }
                if(duWorktypeList.stream().filter(d->d.getWorkTypeId().equals(applyDetail.getWorktypeId()))
                        .collect(Collectors.toList()).size()<=Constants.ZERO){
                    throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"【"+applyDetail.getMemberName()+"】员工工种信息未查询到!");
                    throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"【"+applyDetail.getMemberName()+applyDetail.getIdcardNo()+"】员工工种信息未查询到!");
                }
            }
            applyDetailJoinMapper.insertBatchSomeColumn(applyDetailList);
@@ -1991,7 +2123,8 @@
        queryWrapper.selectAs(Solutions::getPrice,InsuranceApply::getPrice);
        queryWrapper.selectAs(Solutions::getTimeUnit,InsuranceApply::getTimeUnit);
        queryWrapper.select(" DATEDIFF( t.END_TIME ,now()  ) AS loseEfficacyDays  ");
        queryWrapper.select(" ( select count(DISTINCT(ad.MEMBER_ID)) from apply_detail ad  where ad.apply_id = t.id ) as insureNum");
        queryWrapper.select(" ( select count(DISTINCT(ad.MEMBER_ID)) from apply_detail ad  where ad.apply_id = t.id   ) as insureNum");
        queryWrapper.select(" ( select count(DISTINCT(ad.MEMBER_ID)) from apply_detail ad  where ad.apply_id = t.id and ad.END_TIME > now() ) as guaranteeNum");
        if(!Objects.isNull(pageWrap.getModel())&&!Objects.isNull(pageWrap.getModel().getType())){
            queryWrapper.select(" ifnull(( select sum(td.fee) from taxes ts inner join tax_detial td on td.TAX_ID = ts.id  where ts.status != 2 and td.INSURANCE_APPLY_ID = t.id ),0) as taxesMoney");
            queryWrapper.select(" ( select td.CREATE_DATE from taxes ts inner join tax_detial td on td.TAX_ID = ts.id  where ts.status = 1 and td.INSURANCE_APPLY_ID = t.id order by td.CREATE_DATE desc limit 1 ) as taxesLast ");
@@ -2263,6 +2396,7 @@
                .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(" ( select count(DISTINCT(ad.MEMBER_ID)) from apply_detail ad  where ad.apply_id = t.id and ad.END_TIME > now() ) as guaranteeNum")
                .select(" t3.name as shopName")
                .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
                .leftJoin(Company.class,Company::getId,InsuranceApply::getCompanyId)
@@ -2386,6 +2520,7 @@
                .selectAs(Solutions::getName,InsuranceApply::getSolutionsName)
                .selectAs(Solutions::getType,InsuranceApply::getSolutionType)
                .selectAs(Company::getName,InsuranceApply::getCompanyName)
                .select(" ( select count(DISTINCT(ad.MEMBER_ID)) from apply_detail ad  where ad.apply_id = t.id and ad.END_TIME > now() ) as guaranteeNum")
                .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
                .leftJoin(Company.class,Company::getId,InsuranceApply::getCompanyId)
                .eq(InsuranceApply::getId,model.getId())
@@ -2402,6 +2537,7 @@
                .selectAs(DispatchUnit::getName,ApplyDetail::getDuName)
                .leftJoin(Worktype.class,Worktype::getId,ApplyDetail::getWorktypeId)
                .leftJoin(DispatchUnit.class,DispatchUnit::getId,ApplyDetail::getDuId)
                .ge(ApplyDetail::getEndTime,DateUtil.getPlusTime2(new Date()))
                .eq(ApplyDetail::getApplyId,model.getId());
        //查询明细
        List<ApplyDetail> detailList =applyDetailJoinMapper.selectJoinList(ApplyDetail.class,wrapper1);
@@ -2737,6 +2873,7 @@
                .leftJoin(DispatchUnit.class,DispatchUnit::getId,ApplyDetail::getDuId)
                .isNull(ApplyDetail::getFromId)
                .eq(ApplyDetail::getApplyId,model.getId())
                .orderByAsc(ApplyDetail::getId)
        );
        model.setApplyDetailList(applyDetailList);
        return model;