k94314517
2024-03-27 622b92bac0fe45067bcaab3358168561b0dfbadb
git ch
已添加2个文件
已修改22个文件
1786 ■■■■■ 文件已修改
server/company/src/main/java/com/doumee/api/business/ApplyChangeController.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/company/src/main/java/com/doumee/api/business/InsuranceApplyController.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/company/src/main/java/com/doumee/api/business/MemberController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/company/src/main/java/com/doumee/api/business/UnionApplyController.java 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/company/src/main/java/com/doumee/api/business/UnionChangeController.java 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/core/annotation/excel/ExcelExporter.java 134 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/core/utils/Constants.java 99 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/dao/business/dto/MemberQueryDTO.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/dao/business/dto/SaveUnionChangeDTO.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/dao/business/dto/UnionChangeBXDDTO.java 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/dao/business/model/ApplyChange.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/dao/business/model/InsuranceApply.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/dao/business/model/Solutions.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/dao/business/model/UnionChange.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/service/business/ApplyChangeService.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/service/business/InsuranceApplyService.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/service/business/MemberService.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/service/business/UnionApplyService.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/service/business/UnionChangeService.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/service/business/impl/ApplyChangeServiceImpl.java 100 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/service/business/impl/InsuranceApplyServiceImpl.java 524 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/service/business/impl/MemberServiceImpl.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/service/business/impl/UnionApplyServiceImpl.java 44 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/service/src/main/java/com/doumee/service/business/impl/UnionChangeServiceImpl.java 574 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/company/src/main/java/com/doumee/api/business/ApplyChangeController.java
@@ -133,4 +133,11 @@
        return ApiResponse.success("操作成功",applyChangeService.getChangeCountCyclePriceVO(applyChangeCyclePriceDTO));
    }
    @ApiOperation("投保确认书签章业务")
    @GetMapping("/getChangeMemberListOnlineSignLink/{id}")
    @RequiresPermissions("business:applychange:query")
    public ApiResponse<String> getChangeMemberListOnlineSignLink(@PathVariable Integer id) {
        return ApiResponse.success(applyChangeService.getChangeMemberListOnlineSignLink(id));
    }
}
server/company/src/main/java/com/doumee/api/business/InsuranceApplyController.java
@@ -150,4 +150,22 @@
        return ApiResponse.success(null);
    }
    @ApiOperation("投保确认书签章业务")
    @GetMapping("/getSignTBQRSLink/{id}")
    @RequiresPermissions("business:insuranceapply:query")
    public ApiResponse<String> getSignTBQRSLink(@PathVariable Integer id) {
        return ApiResponse.success(insuranceApplyService.getSignTBQRSLink(id));
    }
    @ApiOperation("人员名单签章")
    @GetMapping("/getMemberListOnlineSignLink/{id}")
    @RequiresPermissions("business:insuranceapply:query")
    public ApiResponse<String> getMemberListOnlineSignLink(@PathVariable Integer id) {
        return ApiResponse.success(insuranceApplyService.getMemberListOnlineSignLink(id));
    }
}
server/company/src/main/java/com/doumee/api/business/MemberController.java
@@ -96,7 +96,7 @@
    @GetMapping("/{id}")
    @RequiresPermissions("business:member:query")
    public ApiResponse findById(@PathVariable Integer id) {
        return ApiResponse.success(memberService.findById(id));
        return ApiResponse.success(memberService.findDetailById(id));
    }
server/company/src/main/java/com/doumee/api/business/UnionApplyController.java
@@ -6,6 +6,7 @@
import com.doumee.core.model.ApiResponse;
import com.doumee.core.model.PageWrap;
import com.doumee.core.model.PageData;
import com.doumee.dao.business.dto.*;
import com.doumee.dao.business.model.UnionApply;
import com.doumee.service.business.UnionApplyService;
import io.swagger.annotations.Api;
@@ -87,4 +88,49 @@
    public ApiResponse findById(@PathVariable Integer id) {
        return ApiResponse.success(unionApplyService.findById(id));
    }
    @PreventRepeat
    @ApiOperation("创建合并单")
    @PostMapping("/merge")
    @RequiresPermissions("business:unionapply:create")
    public ApiResponse merge(@RequestBody SaveUnionApplyDTO saveUnionApplyDTO) {
        return ApiResponse.success(unionApplyService.merge(saveUnionApplyDTO));
    }
    @ApiOperation("关闭合并单")
    @GetMapping("/close")
    @RequiresPermissions("business:unionapply:close")
    public ApiResponse close(@RequestParam Integer id) {
        unionApplyService.cancelMerge(id);
        return ApiResponse.success(null);
    }
    @PreventRepeat
    @ApiOperation("上传投保单")
    @PostMapping("/uploadToubaodan")
    @RequiresPermissions("business:unionapply:create")
    public ApiResponse uploadToubaodan(@RequestBody UploadMultifileDTO uploadMultifileDTO) {
        unionApplyService.uploadToubaodan(uploadMultifileDTO);
        return ApiResponse.success(null);
    }
    @ApiOperation("签署申请单")
    @GetMapping("/getSignLink")
    @RequiresPermissions("business:unionapply:query")
    public ApiResponse getSignLink(@RequestParam Integer id) {
        unionApplyService.getSignLink(id);
        return ApiResponse.success(null);
    }
    @ApiOperation("上传保险单")
    @PostMapping("/uploadBXD")
    @RequiresPermissions("business:unionchange:query")
    public ApiResponse uploadBXD(@RequestBody UnionApplyBXDDTO unionApplyBXDDTO) {
        unionApplyService.uploadBXD(unionApplyBXDDTO);
        return ApiResponse.success(null);
    }
}
server/company/src/main/java/com/doumee/api/business/UnionChangeController.java
@@ -6,6 +6,8 @@
import com.doumee.core.model.ApiResponse;
import com.doumee.core.model.PageWrap;
import com.doumee.core.model.PageData;
import com.doumee.dao.business.dto.SaveUnionChangeDTO;
import com.doumee.dao.business.dto.UnionChangeBXDDTO;
import com.doumee.dao.business.model.UnionChange;
import com.doumee.service.business.UnionChangeService;
import io.swagger.annotations.Api;
@@ -87,4 +89,41 @@
    public ApiResponse findById(@PathVariable Integer id) {
        return ApiResponse.success(unionChangeService.findById(id));
    }
    @PreventRepeat
    @ApiOperation("创建合并单")
    @PostMapping("/merge")
    @RequiresPermissions("business:unionchange:create")
    public ApiResponse merge(@RequestBody SaveUnionChangeDTO saveUnionChangeDTO) {
        return ApiResponse.success(unionChangeService.merge(saveUnionChangeDTO));
    }
    @ApiOperation("关闭合并单")
    @GetMapping("/close")
    @RequiresPermissions("business:unionchange:close")
    public ApiResponse close(@RequestParam Integer id) {
        unionChangeService.cancelMerge(id);
        return ApiResponse.success(null);
    }
    @ApiOperation("签署申请单")
    @GetMapping("/getSignLink")
    @RequiresPermissions("business:unionchange:query")
    public ApiResponse getSignLink(@RequestParam Integer id) {
        unionChangeService.getSignLink(id);
        return ApiResponse.success(null);
    }
    @ApiOperation("上传保险单")
    @PostMapping("/uploadBXD")
    @RequiresPermissions("business:unionchange:query")
    public ApiResponse uploadBXD(@RequestBody UnionChangeBXDDTO unionChangeBXDDTO) {
        unionChangeService.uploadBXD(unionChangeBXDDTO);
        return ApiResponse.success(null);
    }
}
server/service/src/main/java/com/doumee/core/annotation/excel/ExcelExporter.java
@@ -745,7 +745,7 @@
     * @param data æ•°æ®
     * @param sheetName Sheet名称
     */
    public String exportJiajianBaoExcelToPdf (ApplyChange data, String sheetName) {
    public String exportJiajianBaoExcelToPdf (ApplyChange data, String sheetName,String cellValue) {
        SXSSFWorkbook sxssfWorkbook;
        try {
            sxssfWorkbook = new SXSSFWorkbook();
@@ -762,7 +762,7 @@
                configTitleCell(sxssfWorkbook,title.getCell(i));
            }
            Row header1 = sheet.createRow(1);
            header1.createCell(0).setCellValue("投保企业");
            header1.createCell(0).setCellValue(cellValue);
            header1.createCell(3).setCellValue("保险方案");
            header1.createCell(4).setCellValue("保单号");
            header1.createCell(5).setCellValue("保险生效起期");
@@ -871,7 +871,7 @@
            sheet.addMergedRegion(new CellRangeAddress(rowIndex ,rowIndex,0,11));
            Row header7= sheet.createRow(rowIndex+1);
            header7.setHeight((short) 3000);
            header7.createCell(0).setCellValue("投保企业签章 ï¼š                            \n \n \n" +"日期:     å¹´     æœˆ     æ—¥    ");
            header7.createCell(0).setCellValue(cellValue+"签章 ï¼š                            \n \n \n" +"日期:     å¹´     æœˆ     æ—¥    ");
            for (int i =0; i < 12; i++) {
                if(i>0){
                    header7.createCell(i).setCellValue("");
@@ -1001,7 +1001,7 @@
     * @param data æ•°æ®
     * @param sheetName Sheet名称
     */
    public String exportChangeUnitExcelToPdf (ApplyChange data, String sheetName) {
    public String exportChangeUnitExcelToPdf (ApplyChange data, String sheetName,String cellValue) {
        SXSSFWorkbook sxssfWorkbook;
        try {
            sxssfWorkbook = new SXSSFWorkbook();
@@ -1023,7 +1023,7 @@
                configTitleCell(sxssfWorkbook,title.getCell(i));
            }
            Row header1 = sheet.createRow(1);
            header1.createCell(0).setCellValue("投保企业");
            header1.createCell(0).setCellValue(cellValue);
            header1.createCell(1).setCellValue("保险方案");
            header1.createCell(2).setCellValue("");
            header1.createCell(3).setCellValue("保单号");
@@ -1096,7 +1096,7 @@
            sheet.addMergedRegion(new CellRangeAddress(rowIndex ,rowIndex,0,7));
            Row header7= sheet.createRow(rowIndex+1);
            header7.setHeight((short) 3000);
            header7.createCell(0).setCellValue("投保企业签章 ï¼š                            \n \n \n" +"日期:     å¹´     æœˆ     æ—¥    ");
            header7.createCell(0).setCellValue(cellValue + "签章 ï¼š                            \n \n \n" +"日期:     å¹´     æœˆ     æ—¥    ");
            for (int i =0; i < 8; i++) {
                if(i>0){
                    header7.createCell(i).setCellValue("");
@@ -1125,6 +1125,128 @@
        return null;
    }
    /**
     * å¯¼å‡º æŠ•保申请详单
     * @param insuranceApply æ•°æ®
     * @param sheetName Sheet名称
     */
    public String exportApplyExcelToPdf(InsuranceApply insuranceApply, String sheetName) {
        SXSSFWorkbook sxssfWorkbook;
        try {
            sxssfWorkbook = new SXSSFWorkbook();
            Sheet sheet = sxssfWorkbook.createSheet(sheetName);
            for (int i = 0; i < 6; i++) {
                sheet.setColumnWidth(i, ((i==3|| i== 4|| i== 5 )?16:8) * 2 * 256);
            }
            sheet.createFreezePane(0, 1);
            sheet.addMergedRegion(new CellRangeAddress(0   ,0,0,6));
            Row title = sheet.createRow(0);
            title.setHeight((short) 2000);
            Cell c = title.createCell(0);
            c.setCellValue(sheetName);
            configFirstCell(sxssfWorkbook,c);
            for (int i = 0; i < 8; i++) {
                if(i>0){
                    title.createCell(i).setCellValue("");
                }
                configTitleCell(sxssfWorkbook,title.getCell(i));
            }
            Row header1 = sheet.createRow(1);
            header1.createCell(0).setCellValue("投保人");
            header1.createCell(1).setCellValue("报保险人");
            header1.createCell(2).setCellValue("投保人数");
            header1.createCell(3).setCellValue("保险方案");
            header1.createCell(4).setCellValue("保险生效起期");
            header1.createCell(5).setCellValue("保险生效止期");
            for (int i = 0; i < 6; i++) {
                configFirstCell(sxssfWorkbook,header1.getCell(i));
            }
            sheet.addMergedRegion(new CellRangeAddress(1  ,1,1,2));
            Row header2 = sheet.createRow(2);
            header2.createCell(0).setCellValue(insuranceApply.getShopName());
            header2.createCell(1).setCellValue(insuranceApply.getCompanyName());
            header2.createCell(2).setCellValue(insuranceApply.getInsureNum());
            header2.createCell(3).setCellValue(insuranceApply.getSolutionsName());
            header2.createCell(4).setCellValue(com.doumee.core.utils.DateUtil.getPlusTime2(insuranceApply.getStartTime()));
            header2.createCell(5).setCellValue(com.doumee.core.utils.DateUtil.getPlusTime2(insuranceApply.getEndTime()));
            sheet.addMergedRegion(new CellRangeAddress(2  ,2,1,2));
            for (int i = 0; i < 6; i++) {
                configDataCell(sxssfWorkbook,header2.getCell(i));
            }
            Row header4 = sheet.createRow(3);
            header4.createCell(0).setCellValue("序号");
            header4.createCell(1).setCellValue("员工姓名");
            header4.createCell(2).setCellValue("性别");
            header4.createCell(3).setCellValue("身份证号");
            header4.createCell(4).setCellValue("派遣单位");
            header4.createCell(5).setCellValue("所所属工种");
            for (int i = 0; i < 6; i++) {
                configFirstCell(sxssfWorkbook,header4.getCell(i));
            }
            // åˆ›å»ºæ•°æ®è®°å½•
            for (int rowIndex = 0; rowIndex <insuranceApply.getApplyDetailList().size(); rowIndex++) {
                ApplyDetail addModel = insuranceApply.getApplyDetailList().get(rowIndex);
                Row header5 = sheet.createRow(rowIndex + 4);
                header5.createCell(0).setCellValue(rowIndex+1);
                header5.createCell(1).setCellValue(StringUtils.defaultString(addModel.getMemberName(),""));
                header5.createCell(2).setCellValue(Constants.equalsInteger(addModel.getSex(),0)?"男":(Constants.equalsInteger(addModel.getSex(),1)?"女":"-"));
                header5.createCell(3).setCellValue(StringUtils.defaultString(addModel.getIdcardNo(),""));
                header5.createCell(6).setCellValue(StringUtils.defaultString(addModel.getDuName(),""));
                header5.createCell(7).setCellValue(StringUtils.defaultString(addModel.getWorkTypeName(),""));
                for (int i = 0; i < 6; i++) {
                    configDataCell(sxssfWorkbook,header5.getCell(i));
                }
            }
            int rowIndex = 4+insuranceApply.getApplyDetailList().size();
            Row header6= sheet.createRow(rowIndex);
            header6.createCell(0).setCellValue("投保企业申明:\n" +
                    "1、在申请书上填写的一切内容属实,否则本企业承担一切法律责任。\n" +
                    "2、由于变更受益人产生的法律纠纷本企业愿承担一切法律责任。\n" +
                    "3、本申请表的签章为本企业亲自签署,如由此产生的法律纠纷本企业愿承担一切法律责任。\n");
            for (int i = 1; i < 6; i++) {
                header6.createCell(i).setCellValue("");
            }
            for (int i =0; i < 6; i++) {
                if(i>0){
                    header6.createCell(i).setCellValue("");
                }
                configInfoCell(sxssfWorkbook,header6.getCell(i),HorizontalAlignment.LEFT);
            }
            header6.setHeight((short) 2000);
            sheet.addMergedRegion(new CellRangeAddress(rowIndex ,rowIndex,0,7));
            Row header7= sheet.createRow(rowIndex+1);
            header7.setHeight((short) 3000);
            header7.createCell(0).setCellValue("投保企业签章 ï¼š                            \n \n \n" +"日期:     å¹´     æœˆ     æ—¥    ");
            for (int i =0; i < 6; i++) {
                if(i>0){
                    header7.createCell(i).setCellValue("");
                }
                configInfoCell(sxssfWorkbook,header7.getCell(i),HorizontalAlignment.RIGHT);
            }
            sheet.addMergedRegion(new CellRangeAddress(rowIndex+1 ,rowIndex+1,0,7));
            //临时缓冲区
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            //创建临时文件
            sxssfWorkbook.write(out);
            byte [] bookByteAry = out.toByteArray();
            InputStream     in = new ByteArrayInputStream(bookByteAry);
            String tempExcel = saveIsToFile(in);
            String tempPdf =System.getProperty("java.io.tmpdir")+File.separator+UUID.randomUUID().toString()+".pdf";
//            ExcelToPdfTool.excelToPdf(in,tempPdf);//转PDF
            ExcelToPdfTool.excelToPdf(tempExcel,tempPdf);//转PDF
            File f = new File(tempPdf);
            if(f!=null && f.isFile() && f.length()>0){
                return tempPdf;
            }
        } catch (Exception e) {
            // throw new BusinessException(ResponseStatus.EXPORT_EXCEL_ERROR, e);
        }
        return null;
    }
    private String saveIsToFile(InputStream inputStream) {
            try {
                String fileName =System.getProperty("java.io.tmpdir")+File.separator+UUID.randomUUID().toString()+".xlsx";
server/service/src/main/java/com/doumee/core/utils/Constants.java
@@ -441,6 +441,10 @@
        HBD_BD_APPLY_PDF(15, "合并单-保单申请表PDF ", "合并单-保单申请表PDF "),
        HBD_BD_SIGNED_PDF(16, "合并单-签署后保单申请表PDF", "合并单-签署后保单申请表PDF"),
        COMPANY_TBD_SIGNED_PDF(17, "合并单-投保单-商户提交(企业签署)", "合并单-签署后保单申请表PDF"),
        SOLUTIONS_CONFIRMATION_LATTER(18, "委托保 - æŠ•保方案确认书", "委托保 - æ–¹æ¡ˆç¡®è®¤ä¹¦"),
        MEMBER_LIST_LATTER(19, "委托保 - æŠ•保人员名单", "委托保 - æ–¹æ¡ˆç¡®è®¤ä¹¦"),
        CHANGE_MEMBER_LIST_LATTER(20, "委托保 - åŠ å‡ä¿äººå‘˜åå•", "委托保 - æ–¹æ¡ˆç¡®è®¤ä¹¦"),
@@ -949,6 +953,98 @@
    public  enum UnionChangeStatus {
        MERGE(0, "待签署申请单","",0),
        UPLOAD_INSURANCE_POLICY(1, "待上传保单","",0),
        FINISH(2, "保障中","",0),
        CLOSE(3, "关闭","",0),
        ;
        // æˆå‘˜å˜é‡
        private String name;
        private String info;
        private int key;
        private int collectStatus;
        // æž„造方法
        UnionChangeStatus(int key, String name,String info,int collectStatus) {
            this.name = name;
            this.key = key;
            this.info = info;
            this.collectStatus = collectStatus;
        }
        // æ™®é€šæ–¹æ³•
        public static String getName(int index) {
            for (UnionChangeStatus c : UnionChangeStatus.values()) {
                if (c.getKey() == index) {
                    return c.name;
                }
            }
            return null;
        }
        public static List<Integer> getKesByStatus(Integer collectStatus) {
            List<Integer>  list = new ArrayList<>();
            if(collectStatus!=null){
                for (UnionChangeStatus c : UnionChangeStatus.values()) {
                    if (Constants.equalsInteger(c.getCollectStatus() ,collectStatus)) {
                        list.add(c.getKey());
                    }
                }
            }
            return list;
        }
        public static Integer getCollectStatus(Integer index) {
            for (UnionChangeStatus c : UnionChangeStatus.values()) {
                if (Constants.equalsInteger(c.getKey() , index)) {
                    return c.collectStatus;
                }
            }
            return null;
        }
        public static String getInfo(int index) {
            for (UnionChangeStatus c : UnionChangeStatus.values()) {
                if (c.getKey() == index) {
                    return c.info;
                }
            }
            return null;
        }
        // get set æ–¹æ³•
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public int getKey() {
            return key;
        }
        public void setKey(int key) {
            this.key = key;
        }
        public String getInfo() {
            return info;
        }
        public void setInfo(String info) {
            this.info = info;
        }
        public int getCollectStatus() {
            return collectStatus;
        }
        public void setCollectStatus(int collectStatus) {
            this.collectStatus = collectStatus;
        }
    }
    public  enum InsuranceApplyStatus {
        UPLOAD(0, "提交投保","",0),
        PLATFORM_RETURN(1, "审核不通过","提交意见:${param}",4),
@@ -962,6 +1058,8 @@
        CLOSE(9, "订单关闭","",6),
        PLATFORM_CHECK_PASS(10,"平台投保审核通过","提交意见:${param}",0),
        COMPANY_BACK_APPLY_PASS(11, "企业申请退回(平台投保审核通过)","提交意见:${param}",5),
        COMPANY_APPLY_SIGNATURE(12, "委托保-企业已签署投保确认书","提交意见:${param}",5),
        COMPANY_MEMBER_LIST_SIGNATURE(13, "委托保-企业已签署人员名单","提交意见:${param}",5),
        ;
        // æˆå‘˜å˜é‡
        private String name;
@@ -1254,6 +1352,7 @@
        CLOSE(6, "已关闭"),
        PALTFORM_CHECK_PASS(7, "审核通过"),
        PALTFORM_CHECK_PASS_NO(8, "审核不通过"),
        COMPANY_SIGN(9, "企业签署人员名单 - å§”托保"),
        ;
        // æˆå‘˜å˜é‡
        private String name;
server/service/src/main/java/com/doumee/dao/business/dto/MemberQueryDTO.java
@@ -9,8 +9,12 @@
@Data
public class MemberQueryDTO {
    @ApiModelProperty(value = "模糊查询 æ‰‹æœºå·+身份证号码")
    private String keywords;
    @ApiModelProperty(value = "员工名称")
    private String name;
    @ApiModelProperty(value = "派遣單位名称")
    private String duName;
server/service/src/main/java/com/doumee/dao/business/dto/SaveUnionChangeDTO.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,32 @@
package com.doumee.dao.business.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Rk
 * @create 2024/3/15 14:42
 */
@Data
public class SaveUnionChangeDTO {
    @ApiModelProperty(value = "投保合并单主键")
    private Integer unionApplyId;
    @ApiModelProperty(value = "加减保/换厂单据主键 å¤šä¸ªä»¥,分割")
    private List<Integer> applyIds;
    @ApiModelProperty(value = "批单日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date applyDate;
    @ApiModelProperty(value = "业务类型:0=加减保;1=换厂")
    private Integer businessType;
}
server/service/src/main/java/com/doumee/dao/business/dto/UnionChangeBXDDTO.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,35 @@
package com.doumee.dao.business.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Rk
 * @create 2024/3/20 16:52
 */
@Data
public class UnionChangeBXDDTO {
    @ApiModelProperty(value = "合并单主键")
    private Integer id;
    @ApiModelProperty(value = "保单号")
    private String code;
    @ApiModelProperty(value = "批单日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date applyDate;
    @ApiModelProperty(value = "保单文件地址")
    private String fileUrl;
    @ApiModelProperty(value = "保单文件名称")
    private String fileName;
}
server/service/src/main/java/com/doumee/dao/business/model/ApplyChange.java
@@ -113,6 +113,14 @@
    @ApiModelProperty(value = "变更金额")
    @ExcelColumn(name="变更金额")
    private BigDecimal fee;
    @ApiModelProperty(value = "合并单-投保单状态 0=未上传;1=已上传;2=已签署", example = "1")
    private Integer unionChangeTbdStatus;
    @ApiModelProperty(value = "人员名单签署合同号")
    @ExcelColumn(name="人员名单签署合同号")
    private String signMemberListNo;
    @ApiModelProperty(value = "保单号")
    @TableField(exist = false)
    private String applyCode;
@@ -152,9 +160,11 @@
    private String createDateE;
    @ApiModelProperty(value = "批单生效起期时间")
    @TableField(exist = false)
    private String applyStartS;
    @ApiModelProperty(value = "批单止效时间")
    @TableField(exist = false)
    private String applyStartE;
    @ApiModelProperty(value = "保险方案主键")
server/service/src/main/java/com/doumee/dao/business/model/InsuranceApply.java
@@ -108,6 +108,9 @@
    @ExcelColumn(name="合并单编码(关联union_apply)")
    private Integer unionApplyId;
    @ApiModelProperty(value = "合并单-投保单状态 0=未上传;1=已上传;2=已签署", example = "1")
    private Integer unionApplyTbdStatus;
    @ApiModelProperty(value = "单号")
    @ExcelColumn(name="单号")
    private String code;
@@ -126,6 +129,14 @@
    @ApiModelProperty(value = "总费用")
    @ExcelColumn(name="总费用")
    private BigDecimal fee;
    @ApiModelProperty(value = "在线确认书合同号")
    @ExcelColumn(name="在线确认书合同号")
    private String signQrsNo;
    @ApiModelProperty(value = "人员名单签署合同号")
    @ExcelColumn(name="人员名单签署合同号")
    private String signMemberListNo;
    @ApiModelProperty(value = "企业名称")
    @TableField(exist = false)
@@ -222,6 +233,13 @@
    @TableField(exist = false)
    private Integer newVersionSolutionId;
    @ApiModelProperty(value = "商户名称")
    @TableField(exist = false)
    private String shopName;
    public TaxesInvoicingVO toTaxesInvoicingVO(){
        TaxesInvoicingVO taxesInvoicingVO = new TaxesInvoicingVO();
        taxesInvoicingVO.setId(this.getId());
server/service/src/main/java/com/doumee/dao/business/model/Solutions.java
@@ -116,6 +116,7 @@
    @ApiModelProperty(value = "接收文件邮箱")
    @ExcelColumn(name="接收文件邮箱")
    private String email;
    @ApiModelProperty(value = "承包公司")
    @ExcelColumn(name="承包公司")
    private String companyName;
server/service/src/main/java/com/doumee/dao/business/model/UnionChange.java
@@ -70,7 +70,7 @@
    @ApiModelProperty(value = "状态 0待签署申请单 1待上传批单 2已上传批单 3退回")
    @ExcelColumn(name="状态 0待签署申请单 1待上传批单 2已上传批单 3退回")
    private String status;
    private Integer status;
    @ApiModelProperty(value = "期望保险生效起期")
    @ExcelColumn(name="期望保险生效起期")
@@ -89,4 +89,8 @@
    @ExcelColumn(name="在线签章合同号")
    private String signApplyNo;
    @ApiModelProperty(value = "合并保单主键")
    @ExcelColumn(name="合并保单主键")
    private Integer unionApplyId;
}
server/service/src/main/java/com/doumee/service/business/ApplyChangeService.java
@@ -121,4 +121,12 @@
    String getSignLinkChangeUnit(ApplyChange model);
    CountCyclePriceVO getChangeCountCyclePriceVO(ApplyChangeCyclePriceDTO applyChangeCyclePriceDTO);
    /**
     * å§”托保 äººå‘˜åå•签署
     * @param applyChangeId
     * @return
     */
    String getChangeMemberListOnlineSignLink(Integer applyChangeId);
}
server/service/src/main/java/com/doumee/service/business/InsuranceApplyService.java
@@ -134,4 +134,26 @@
    CountCyclePriceVO getCountCyclePriceVO(CountCyclePriceDTO countCyclePriceDTO);
    void generateNotice();
    /**
     * è¯¦æƒ…信息
     * @param applyId
     * @return
     */
    InsuranceApply  queryApplyDetail(Integer applyId);
    /**
     * å§”托保 æŠ•保确认书签章业务
     * @param applyId
     * @return
     */
    String getSignTBQRSLink(Integer applyId);
    /**
     * äººå‘˜åå•签章
     * @param applyId
     * @return
     */
    String getMemberListOnlineSignLink(Integer applyId);
}
server/service/src/main/java/com/doumee/service/business/MemberService.java
@@ -67,6 +67,8 @@
     */
    Member findById(Integer id);
    Member findDetailById(Integer id);
    /**
     * æ¡ä»¶æŸ¥è¯¢å•条记录
     *
server/service/src/main/java/com/doumee/service/business/UnionApplyService.java
@@ -102,7 +102,7 @@
     * ä¿å•合并
     * @param saveUnionApplyDTO
     */
    void merge(SaveUnionApplyDTO saveUnionApplyDTO);
    Integer merge(SaveUnionApplyDTO saveUnionApplyDTO);
    /**
     * å–消合并单
server/service/src/main/java/com/doumee/service/business/UnionChangeService.java
@@ -2,6 +2,8 @@
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.dao.business.dto.SaveUnionChangeDTO;
import com.doumee.dao.business.dto.UnionChangeBXDDTO;
import com.doumee.dao.business.model.UnionChange;
import java.util.List;
@@ -94,4 +96,34 @@
     * @return long
     */
    long count(UnionChange unionChange);
    /**
     * åˆ›å»ºåˆå¹¶å•(加减保/换厂单)
     * @param saveUnionChangeDTO
     * @return
     */
    Integer merge(SaveUnionChangeDTO saveUnionChangeDTO);
    /**
     * å…³é—­ åˆå¹¶å•(加减保/换厂单)
     * @param id
     */
    void cancelMerge(Integer id);
    /**
     * åˆå¹¶å•(加减保/换厂) - æŠ•保申请签署
     * @param id
     * @return
     */
    String getSignLink(Integer id);
    /**
     * åˆå¹¶å• ä¸Šä¼ ä¿é™©å•
     * @param unionChangeBXDDTO
     */
    void uploadBXD(UnionChangeBXDDTO unionChangeBXDDTO);
}
server/service/src/main/java/com/doumee/service/business/impl/ApplyChangeServiceImpl.java
@@ -664,7 +664,6 @@
            );
            update.setFee(totalFee);
        }
    }
@@ -1468,7 +1467,7 @@
                        Constants.ApplyChangeStatus.RETURN_APPLY_SIGNATURE.getKey())
//                .eq(!Objects.isNull(model.getCompanyId()),InsuranceApply::getCompanyId,model.getCompanyId())
//                .eq(!Objects.isNull(model.getSolutionsId()),ApplyChange::getSolutionsId,model.getSolutionsId())
                .eq(!Objects.isNull(model.getType()),Solutions::getType,model.getSolutionType())
                .eq(!Objects.isNull(model.getSolutionType()),Solutions::getType,model.getSolutionType())
                .eq(!Objects.isNull(model.getApplyId()),ApplyChange::getApplyId,model.getApplyId())
                .eq(!Objects.isNull(model.getBaseSolutionsId()),Solutions::getBaseId,model.getBaseSolutionsId())
                .ge(StringUtils.isNotBlank(model.getCreateDateS()),ApplyChange::getCreateDate, model.getCreateDateS()+" 00:00:00" )
@@ -1745,9 +1744,9 @@
        }
        String fileUrl = null;
        if(Constants.equalsObject(model.getType(), Constants.ONE)){
              fileUrl = ExcelExporter.build(ApplyChange.class).exportChangeUnitExcelToPdf(model,"换厂申请表");
              fileUrl = ExcelExporter.build(ApplyChange.class).exportChangeUnitExcelToPdf(model,"换厂申请表","投保企业");
        }else{
            fileUrl = ExcelExporter.build(ApplyChange.class).exportJiajianBaoExcelToPdf(model,"加减保申请表");
            fileUrl = ExcelExporter.build(ApplyChange.class).exportJiajianBaoExcelToPdf(model,"加减保申请表","投保企业");
        }
        String notifyUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.SIGN_DONE_NOTIFY_URL).getCode();
        notifyUrl = notifyUrl.replace("${type}","0").replace("${id}",model.getId().toString());
@@ -1765,8 +1764,6 @@
        update.setEditDate(new Date());
        update.setSignApplyNo(applyNo);
        applyChangeMapper.updateById(update);
        return  link;
    }
@@ -1924,4 +1921,95 @@
        return sumPrice.divide(new BigDecimal(sumDays),2, RoundingMode.HALF_UP).multiply(new BigDecimal(optDays));
    }
    public  ApplyChange  queryApplyChangeData(Integer applyChangeId){
        ApplyChange model = findDetail(applyChangeId);
        if(Objects.isNull(model) ||! Constants.equalsInteger(Constants.ZERO,model.getIsdeleted())){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        MPJLambdaWrapper<ApplyChagneDetail> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(ApplyChagneDetail.class);
        queryWrapper.select("t2.name",ApplyChagneDetail::getWorkTypeName);
        queryWrapper.select("t3.name",ApplyChagneDetail::getDuName);
        queryWrapper.select("t4.name",ApplyChagneDetail::getOldWorkTypeName);
        queryWrapper.select("t5.name",ApplyChagneDetail::getOldDuName);
        queryWrapper.selectAs(Member::getName,ApplyChagneDetail::getMemberName);
        queryWrapper.selectAs(Member::getSex,ApplyChagneDetail::getSex);
        queryWrapper.selectAs(Member::getIdcardNo,ApplyChagneDetail::getMemberIdcardNo);
        queryWrapper.leftJoin(Member.class,Member::getId,ApplyChagneDetail::getMemberId);
        queryWrapper.leftJoin(Worktype.class,Worktype::getId,ApplyChagneDetail::getWorktypeId);
        queryWrapper.leftJoin(DispatchUnit.class,DispatchUnit::getId,ApplyChagneDetail::getDuId);
        queryWrapper.leftJoin(Worktype.class,Worktype::getId,ApplyChagneDetail::getOldWorktypeId);
        queryWrapper.leftJoin(DispatchUnit.class,DispatchUnit::getId,ApplyChagneDetail::getOldDuId);
        queryWrapper.eq(ApplyChagneDetail::getApplyChangeId,applyChangeId);
        List<ApplyChagneDetail> list = applyChangeDetailJoinMapper.selectJoinList(ApplyChagneDetail.class, queryWrapper);
        for (ApplyChagneDetail applyChagneDetail:list) {
            applyChagneDetail.setAge(Constants.getAgeByIdCard(applyChagneDetail.getMemberIdcardNo()));
        }
        if(CollectionUtils.isNotEmpty(list)){
            model.setAddDetailList(list.stream().filter(m->m.getType().equals(Constants.ZERO)).collect(Collectors.toList()));
            model.setDelDetailList(list.stream().filter(m->m.getType().equals(Constants.ONE)).collect(Collectors.toList()));
            model.setChangeDetailList(list.stream().filter(m->m.getType().equals(Constants.TWO)).collect(Collectors.toList()));
        }
        return model;
    }
    /**
     * äººå‘˜åå•签章
     */
    @Override
    public String getChangeMemberListOnlineSignLink(Integer applyChangeId) {
        ApplyChange model = this.queryApplyChangeData(applyChangeId);
        if(Objects.isNull(model)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询加减保信息");
        }
        if(Objects.isNull(model) ||! Constants.equalsInteger(Constants.ZERO,model.getIsdeleted())){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        if(!Constants.equalsInteger(Constants.ZERO,model.getStatus())){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,该申请状态已流转,当前不支持签章操作!");
        }
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        Company company = user.getCompany();
        if(debugModel){
            company = companyMapper.selectById(model.getCompanyId());
        }
        if(company== null || StringUtils.isBlank( company.getEmail()) || !Constants.equalsInteger(company.getSignStatus(),Constants.THREE)){
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,企业尚未具备在线签章条件,请联系平台管理员确认~");
        }
        Solutions solutions = solutionsMapper.selectById(model.getSolutionsId());
        if(Objects.isNull(solutions)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询方案信息");
        }
        if(solutions.getType().equals(Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,非委托保方案保单,无法进行该操作!");
        }
        String fileUrl = null;
        if(Constants.equalsObject(model.getType(), Constants.ONE)){
            fileUrl = ExcelExporter.build(ApplyChange.class).exportChangeUnitExcelToPdf(model,"换厂申请表","被保险人");
        }else{
            fileUrl = ExcelExporter.build(ApplyChange.class).exportJiajianBaoExcelToPdf(model,"加减保申请表","被保险人");
        }
        String notifyUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.SIGN_DONE_NOTIFY_URL).getCode();
        notifyUrl = notifyUrl.replace("${type}","0").replace("${id}",model.getId().toString());
        String applyNo = signService.applySignLocalFile(company.getName(),company.getName(),fileUrl,company.getCode(),company.getEmail(),"人员名单签章",company.getSignId(),notifyUrl);
        if(StringUtils.isBlank(applyNo) ){
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,获取在线签章地址失败,请稍后重试!");
        }
        String link = signService.signLink(applyNo,company.getName(),company.getCode());
        if(StringUtils.isBlank(link) ){
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,获取在线签章地址失败,请稍后重试!");
        }
        ApplyChange update= new ApplyChange();
        update.setId(model.getId());
        update.setEditor(user.getId());
        update.setEditDate(new Date());
        update.setSignMemberListNo(applyNo);
        applyChangeMapper.updateById(update);
        return  link;
    }
}
server/service/src/main/java/com/doumee/service/business/impl/InsuranceApplyServiceImpl.java
@@ -2,6 +2,7 @@
import com.alibaba.fastjson.JSONObject;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.annotation.excel.ExcelExporter;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.LoginUserInfo;
@@ -98,6 +99,8 @@
    @Autowired
    private NoticesMapper noticesMapper;
    @Autowired
    private UnionApplyJoinMapper unionApplyJoinMapper;
    @Override
    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
@@ -375,6 +378,7 @@
    }
    @Override
    public  String getSignLink(Integer id) {
        if(id == null ){
@@ -434,9 +438,10 @@
        update.setEditDate(new Date());
        update.setSignApplyNo(applyNo);
        insuranceApplyMapper.updateById(update);
        return  link;
    }
    public String uploadSignFile(String link){
        try {
            String bucketName = systemDictDataBiz.queryByCode(Constants.OSS,Constants.BUCKETNAME).getCode();
@@ -496,8 +501,75 @@
        startSendEmail(f, model.getCompanyName(),model.getSolutionsName(),model.getSolutionEmail());
        return  f;
    }
    /**
     * å§”托保 æ–¹æ¡ˆç¡®è®¤ä¹¦ï¼ˆä¼ä¸šï¼‰
     * @param model
     * @param fileurl
     * @param fullUrl
     * @return
     */
    public Multifile   uploadFAQRSSignedFileDo(InsuranceApply model,String fileurl,String fullUrl) {
        InsuranceApply update = new InsuranceApply();
        update.setEditDate(new Date());
        update.setEditor(model.getCreator());
        update.setStatus(Constants.InsuranceApplyStatus.COMPANY_APPLY_SIGNATURE.getKey());
        update.setCheckDate(update.getEditDate());
        update.setCheckInfo("企业完成签署方案确认书");
        update.setCheckUserId(model.getCreator());
        update.setId(model.getId());
        insuranceApplyMapper.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.SOLUTIONS_CONFIRMATION_LATTER.getKey());
        f.setType(Constants.TWO);
        f.setFileurl(fileurl);
        f.setFileurlFull(fullUrl);
        f.setInfo("企业完成签署方案确认书");
        f.setName("方案确认书.pdf");
        multifileMapper.insert(f);
        return  f;
    }
    /**
     * å§”托保 ä¼ä¸šç­¾ç½² äººå‘˜åå•
     * @param model
     * @param fileurl
     * @param fullUrl
     * @return
     */
    public Multifile   uploadApplyMemberListSignedFileDo(InsuranceApply model,String fileurl,String fullUrl) {
        InsuranceApply update = new InsuranceApply();
        update.setEditDate(new Date());
        update.setEditor(model.getCreator());
        update.setStatus(Constants.InsuranceApplyStatus.COMPANY_MEMBER_LIST_SIGNATURE.getKey());
        update.setCheckDate(update.getEditDate());
        update.setCheckInfo("企业完成签署人员名单");
        update.setCheckUserId(model.getCreator());
        update.setId(model.getId());
        insuranceApplyMapper.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.MEMBER_LIST_LATTER.getKey());
        f.setType(Constants.TWO);
        f.setFileurl(fileurl);
        f.setFileurlFull(fullUrl);
        f.setInfo("企业完成签署人员名单");
        f.setName("人员名单.pdf");
        multifileMapper.insert(f);
        return  f;
    }
    public Multifile  uploadChangeSignedFileDo(ApplyChange model,String fileurl,String fullurl) {
        Integer companyId = model.getCompanyId();
        ApplyChange update = new ApplyChange();
@@ -542,7 +614,81 @@
        startSendEmail(f,model.getCompanyName(),model.getSolutionsName(),model.getSolutionEmail());
        return f;
    }
    public Multifile  uploadChangeMemberListSignedFileDo(ApplyChange model,String fileurl,String fullurl) {
        ApplyChange update = new ApplyChange();
        update.setEditDate(new Date());
        update.setEditor(model.getCreator());
        update.setStatus(Constants.ApplyChangeStatus.COMPANY_SIGN.getKey());
        update.setCheckDate(update.getEditDate());
        update.setCheckInfo("企业完成签署人员名单");
        update.setCheckUserId(model.getCreator());
        update.setId(model.getId());
        applyChangeMapper.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.CHANGE_MEMBER_LIST_LATTER.getKey());
        f.setType(Constants.TWO);
        f.setFileurl(fileurl);
        f.setFileurlFull(fullurl);
        f.setInfo("企业完成签署人员名单");
        f.setName("签章人员名单.pdf");
        multifileMapper.insert(f);
        return f;
    }
    /**
     * å•†æˆ·åˆå¹¶å• å•†æˆ·ç­¾ç½²æŠ•保申请单
     * @param model
     * @param fileurl
     * @param fullUrl
     * @return
     */
    public Multifile   uploadUnionApplySignedFileDo(UnionApply model,String fileurl,String fullUrl) {
        UnionApply update = new UnionApply();
        update.setEditDate(new Date());
        update.setEditor(model.getCreator());
        update.setStatus(Constants.UnionApplyStatus.UPLOAD_INSURANCE_POLICY.getKey());
        update.setCheckDate(update.getEditDate());
        update.setCheckInfo("商户完成签署");
        update.setCheckUserId(model.getCreator());
        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());
        f.setObjId(update.getId());
        f.setCreateDate(update.getEditDate());
        f.setObjType(Constants.MultiFile.HBD_BD_APPLY_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.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());
        return  f;
    }
    private void startSendEmail(Multifile f, String companyName, String solutionsName, String solutionEmail) {
@@ -567,6 +713,9 @@
    @Override
    public   void dealWaitSignedData(){
        String path = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+
                systemDictDataBiz.queryByCode(Constants.OSS,Constants.APPLY_FILE).getCode();
        //直保保单 ä¼ä¸šç­¾ç« æ•°æ®å¤„理
        List<InsuranceApply> applyList = insuranceApplyJoinMapper.selectJoinList(InsuranceApply.class,
                new MPJLambdaWrapper<InsuranceApply>()
                .selectAll(InsuranceApply.class)
@@ -576,9 +725,8 @@
                .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
                .leftJoin(Company.class,Company::getId,InsuranceApply::getCompanyId)
                .eq(InsuranceApply::getStatus,Constants.InsuranceApplyStatus.WAIT_SIGNATURE.getKey())
                .eq(Solutions::getType,Constants.ZERO)
                .isNotNull(InsuranceApply::getSignApplyNo));
        String path = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+
                systemDictDataBiz.queryByCode(Constants.OSS,Constants.APPLY_FILE).getCode();
        if(applyList !=null && applyList.size()>0 ){
            for(InsuranceApply model : applyList){
                String status = signService.linkFileStatus(model.getSignApplyNo());
@@ -595,6 +743,64 @@
                return;
            }
        }
        //委托保 ä¼ä¸šç­¾ç½²æŠ•保确认书
        applyList = insuranceApplyJoinMapper.selectJoinList(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(InsuranceApply::getStatus,Constants.InsuranceApplyStatus.UPLOAD.getKey())
                        .eq(Solutions::getType,Constants.ONE)
                        .isNotNull(InsuranceApply::getSignQrsNo));
        if(applyList !=null && applyList.size()>0 ){
            for(InsuranceApply model : applyList){
                String status = signService.linkFileStatus(model.getSignQrsNo());
                if(!StringUtils.equals(status,"3")){
                    continue;
                }
                String link = signService.linkFile(model.getSignQrsNo());
                String fileUrl = uploadSignFile(link);
                if(StringUtils.isBlank(fileUrl)){
                    //如果下载失败,清除合同,下次签章重新生成新合同
                    return;
                }
                uploadFAQRSSignedFileDo(model,fileUrl,path+fileUrl);
                return;
            }
        }
        //委托保 ä¼ä¸šç­¾ç½²äººå‘˜åå•
        applyList = insuranceApplyJoinMapper.selectJoinList(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(InsuranceApply::getStatus,Constants.InsuranceApplyStatus.COMPANY_APPLY_SIGNATURE.getKey())
                        .eq(Solutions::getType,Constants.ONE)
                        .isNotNull(InsuranceApply::getSignMemberListNo));
        if(applyList !=null && applyList.size()>0 ){
            for(InsuranceApply model : applyList){
                String status = signService.linkFileStatus(model.getSignMemberListNo());
                if(!StringUtils.equals(status,"3")){
                    continue;
                }
                String link = signService.linkFile(model.getSignMemberListNo());
                String fileUrl = uploadSignFile(link);
                if(StringUtils.isBlank(fileUrl)){
                    //如果下载失败,清除合同,下次签章重新生成新合同
                    return;
                }
                uploadApplyMemberListSignedFileDo(model,fileUrl,path+fileUrl);
                return;
            }
        }
        List<ApplyChange> chagneList = applyChangeMapper.selectJoinList(ApplyChange.class,
                new MPJLambdaWrapper<ApplyChange>()
                .selectAll(ApplyChange.class)
@@ -606,6 +812,7 @@
                .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
                .leftJoin(Company.class,Company::getId,InsuranceApply::getCompanyId)
                .eq(ApplyChange::getStatus,Constants.ApplyChangeStatus.UPLOAD.getKey())
                .eq(Solutions::getType,Constants.ZERO)
                .isNotNull(ApplyChange::getSignApplyNo));
        if(chagneList !=null && chagneList.size()>0 ){
            for(ApplyChange model : chagneList){
@@ -623,6 +830,64 @@
                return;
            }
        }
        chagneList = applyChangeMapper.selectJoinList(ApplyChange.class,
                new MPJLambdaWrapper<ApplyChange>()
                        .selectAll(ApplyChange.class)
                        .selectAs(Solutions::getName,InsuranceApply::getSolutionsName)
                        .selectAs(Solutions::getEmail,InsuranceApply::getSolutionEmail)
                        .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(ApplyChange::getStatus,Constants.ApplyChangeStatus.UPLOAD.getKey())
                        .eq(Solutions::getType,Constants.ONE)
                        .isNotNull(ApplyChange::getSignMemberListNo));
        if(chagneList !=null && chagneList.size()>0 ){
            for(ApplyChange model : chagneList){
                String status = signService.linkFileStatus(model.getSignMemberListNo());
                if(!StringUtils.equals(status,"3")){
                    continue;
                }
                String link = signService.linkFile(model.getSignMemberListNo());
                String fileUrl = uploadSignFile(link);
                if(StringUtils.isBlank(fileUrl)){
                    //如果下载失败,清除合同,下次签章重新生成新合同
                    return;
                }
                uploadChangeMemberListSignedFileDo(model,fileUrl,path+fileUrl);
                return;
            }
        }
        /**
         *合并投保单 ç­¾ç½²ä¸šåŠ¡
         */
        List<UnionApply> unionApplyList = unionApplyJoinMapper.selectJoinList(UnionApply.class,
                new MPJLambdaWrapper<UnionApply>()
                        .selectAll(UnionApply.class)
                        .eq(UnionApply::getStatus,Constants.UnionApplyStatus.WAIT_SIGNATURE.getKey())
                        .isNotNull(UnionApply::getSignApplyNo));
        if(unionApplyList !=null && unionApplyList.size()>0 ){
            for(UnionApply model : unionApplyList){
                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)){
                    //如果下载失败,清除合同,下次签章重新生成新合同
                    return;
                }
                uploadUnionApplySignedFileDo(model,fileUrl,path+fileUrl);
                return;
            }
        }
    }
    @Override
    public   void dealSignResult(NotifyDataReq data){
@@ -633,6 +898,7 @@
            //如果已保全,可下载签约附件
            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)
@@ -641,6 +907,7 @@
                            .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())){
@@ -654,6 +921,54 @@
                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.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.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;
            }
            //直保 åŠ å‡ä¿ä¼ä¸šç­¾ç½²
            ApplyChange applyChange = applyChangeMapper.selectJoinOne(ApplyChange.class,
                    new MPJLambdaWrapper<ApplyChange>()
                            .selectAll(ApplyChange.class)
@@ -664,6 +979,7 @@
                            .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());
@@ -674,18 +990,67 @@
                }
                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(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);
            }
        }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()));
        }
        }
    }
    @Override
    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
    public Integer uploadToubaodan(InsuranceApply insuranceApply) {
@@ -751,8 +1116,6 @@
        Notices notices = new Notices(noticeObjectType,Constants.ONE,model.getId(),solutions.getName(),
                model.getCompanyId(), Constants.NoticeType.ONE);
        noticesMapper.insert(notices);
        return  1;
@@ -1372,11 +1735,13 @@
                .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")
                .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
                .leftJoin(Company.class,Company::getId,InsuranceApply::getCompanyId)
                .leftJoin(Company.class,Company::getId,Solutions::getShopId)
                .eq(InsuranceApply::getId,id)
                .last("limit 1");
@@ -1686,5 +2051,148 @@
    }
    /**
     * å§”托宝 æŠ•保确认书
     * @param id
     * @return
     */
    @Override
    public  String getSignTBQRSLink(Integer id) {
        if(id == null ){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        MPJLambdaWrapper wrapper=  new MPJLambdaWrapper<InsuranceApply>()
                .selectAll(InsuranceApply.class)
                .selectAs(Solutions::getSignKeyword,InsuranceApply::getSignKeyword)
                .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
                .eq(InsuranceApply::getId,id)
                .last("limit 1");
        InsuranceApply model = insuranceApplyJoinMapper.selectJoinOne(InsuranceApply.class,wrapper);
        if(model == null ||!Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        Solutions solutions = solutionsMapper.selectById(model.getSolutionId());
        if(Objects.isNull(solutions)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询方案信息");
        }
        if(solutions.getType().equals(Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,非委托保方案保单!");
        }
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        Constants.ApplyLogType applyLogType = null;
        String info = "";
        //如果是驳回,只能可驳回已签章状态下的退回申请状态进行操作
        if(!Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.UPLOAD.getKey())){
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该申请状态已流转,当前不支持该操作~");
        }
        Company company = user.getCompany();
        if(debugModel){
            company = companyMapper.selectById(model.getCompanyId());
        }
        if(company== null || StringUtils.isBlank( company.getEmail()) || !Constants.equalsInteger(company.getSignStatus(),Constants.THREE)){
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,企业尚未具备在线签章条件,请联系平台管理员确认~");
        }
        Multifile f = multifileMapper.selectOne(new QueryWrapper<Multifile>().lambda()
                .eq(Multifile::getObjId,solutions.getId())
                .eq(Multifile::getObjType,Constants.MultiFile.SOLUTIONS_CONFIRMATION_LATTER.getKey())
                .eq(Multifile::getIsdeleted,Constants.ZERO).last("limit 1"));
        if(f == null || StringUtils.isBlank(f.getFileurl())){
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,获取确认书文件失败,请联系商户确认投保确认书是否正确!");
        }
        String url = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+systemDictDataBiz.queryByCode(Constants.OSS,Constants.APPLY_FILE).getCode()+f.getFileurl();
        String notifyUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.SIGN_DONE_NOTIFY_URL).getCode();
        notifyUrl = notifyUrl.replace("${type}","0").replace("${id}",model.getId().toString());
        String applyNo = signService.applySign(company.getName(),url,company.getName(),company.getCode(),company.getEmail(),model.getSignKeyword(),company.getSignId(),notifyUrl);
        if(StringUtils.isBlank(applyNo) ){
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,获取在线签章地址失败,请稍后重试!");
        }
        String link = signService.signLink(applyNo,company.getName(),company.getCode());
        if(StringUtils.isBlank(link) ){
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,获取在线签章地址失败,请稍后重试!");
        }
        InsuranceApply update= new InsuranceApply();
        update.setId(model.getId());
        update.setEditor(user.getId());
        update.setEditDate(new Date());
        update.setSignQrsNo(applyNo);
        insuranceApplyMapper.updateById(update);
        return  link;
    }
    @Override
    public  InsuranceApply  queryApplyDetail(Integer applyId){
        InsuranceApply model = findDetail(applyId);
        if(Objects.isNull(model) ||! Constants.equalsInteger(Constants.ZERO,model.getIsdeleted())){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        //查询保单明细信息
        List<ApplyDetail> applyDetailList = applyDetailJoinMapper.selectJoinList(ApplyDetail.class,new MPJLambdaWrapper<ApplyDetail>()
                .selectAll(ApplyDetail.class)
                .selectAs(Worktype::getName,ApplyDetail::getWorkTypeName)
                .selectAs(DispatchUnit::getName,ApplyDetail::getDuName)
                .leftJoin(Worktype.class,Worktype::getId,ApplyDetail::getWorktypeId)
                .leftJoin(DispatchUnit.class,DispatchUnit::getId,ApplyDetail::getDuId)
                .isNull(ApplyDetail::getFromId)
                .eq(ApplyDetail::getId,model.getId())
        );
        model.setApplyDetailList(applyDetailList);
        return model;
    }
    /**
     * äººå‘˜åå•签章
     */
    @Override
    public String getMemberListOnlineSignLink(Integer applyId) {
        InsuranceApply model = this.queryApplyDetail(applyId);
        if(Objects.isNull(model)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询保单信息");
        }
        if(Objects.isNull(model) ||! Constants.equalsInteger(Constants.ZERO,model.getIsdeleted())){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        if(!Constants.equalsInteger(Constants.ZERO,model.getStatus())){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,该申请状态已流转,当前不支持签章操作!");
        }
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        Company company = user.getCompany();
        if(debugModel){
            company = companyMapper.selectById(model.getCompanyId());
        }
        if(company== null || StringUtils.isBlank( company.getEmail()) || !Constants.equalsInteger(company.getSignStatus(),Constants.THREE)){
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,企业尚未具备在线签章条件,请联系平台管理员确认~");
        }
        Solutions solutions = solutionsMapper.selectById(model.getSolutionId());
        if(Objects.isNull(solutions)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询方案信息");
        }
        if(solutions.getType().equals(Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,非委托保方案保单,无法进行该操作!");
        }
        String fileUrl =  ExcelExporter.build(InsuranceApply.class).exportApplyExcelToPdf(model,"人员名单");
        String notifyUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.SIGN_DONE_NOTIFY_URL).getCode();
        notifyUrl = notifyUrl.replace("${type}","0").replace("${id}",model.getId().toString());
        String applyNo = signService.applySignLocalFile(company.getName(),company.getName(),fileUrl,company.getCode(),company.getEmail(),"投保名单签章",company.getSignId(),notifyUrl);
        if(StringUtils.isBlank(applyNo) ){
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,获取在线签章地址失败,请稍后重试!");
        }
        String link = signService.signLink(applyNo,company.getName(),company.getCode());
        if(StringUtils.isBlank(link) ){
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,获取在线签章地址失败,请稍后重试!");
        }
        InsuranceApply update= new InsuranceApply();
        update.setId(model.getId());
        update.setEditor(user.getId());
        update.setEditDate(new Date());
        update.setSignMemberListNo(applyNo);
        insuranceApplyMapper.updateById(update);
        return  link;
    }
}
server/service/src/main/java/com/doumee/service/business/impl/MemberServiceImpl.java
@@ -103,6 +103,29 @@
    }
    @Override
    public Member findDetailById(Integer id) {
        MPJLambdaWrapper<Member> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(Member.class)
                .selectAs(DispatchUnit::getName,Member::getDuName)
                .selectAs(Worktype::getName,Member::getWorkTypeName)
                .selectAs(Solutions::getName,Member::getSolutionName)
                .selectAs(Company::getName,Member::getCompanyName)
                .select(" case when  now() between t.start_time and t.end_time then 1  else 2 end solutionsStatus ")
                .leftJoin(InsuranceApply.class,InsuranceApply::getId,Member::getApplyId)
                .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
                .leftJoin(DispatchUnit.class,DispatchUnit::getId,Member::getDuId)
                .leftJoin(Worktype.class,Worktype::getId,Member::getWorktypeId)
                .leftJoin(Company.class,Company::getId,Member::getCompanyId)
                .eq(Member::getId,id)
                .eq(Member::getIsdeleted, Constants.ZERO)
                .last(" limit 1 ")
        ;
        return memberJoinMapper.selectJoinOne(Member.class,queryWrapper);
    }
    @Override
    public Member findOne(Member member) {
        QueryWrapper<Member> wrapper = new QueryWrapper<>(member);
        return memberMapper.selectOne(wrapper);
@@ -207,6 +230,10 @@
                .leftJoin(DispatchUnit.class,DispatchUnit::getId,Member::getDuId)
                .leftJoin(Worktype.class,Worktype::getId,Member::getWorktypeId)
                .leftJoin(Company.class,Company::getId,Member::getCompanyId)
                .and(StringUtils.isNotBlank(memberQueryDTO.getKeywords()),
                        i->i.like(Member::getName, memberQueryDTO.getKeywords()).or().like(
                                Member::getIdcardNo,memberQueryDTO.getKeywords()
                        ))
                .eq(Member::getIsdeleted, Constants.ZERO)
//                .eq(Member::getCompanyId, memberQueryDTO.getCompanyId())
                .like(StringUtils.isNotBlank(memberQueryDTO.getName()),Member::getName, memberQueryDTO.getName())
server/service/src/main/java/com/doumee/service/business/impl/UnionApplyServiceImpl.java
@@ -221,7 +221,7 @@
    @Override
    public void merge(SaveUnionApplyDTO saveUnionApplyDTO){
    public Integer merge(SaveUnionApplyDTO saveUnionApplyDTO){
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(user.getType().equals(Constants.TWO)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"非商户用户,无法进行该操作");
@@ -230,6 +230,7 @@
            || Objects.isNull(saveUnionApplyDTO.getApplyIds())
            || Objects.isNull(saveUnionApplyDTO.getStartDate())
            || Objects.isNull(saveUnionApplyDTO.getEndDate())
            || Objects.isNull(saveUnionApplyDTO.getBaseSolutionId())
        ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
@@ -239,7 +240,7 @@
                        .selectAs(InsuranceApply::getSolutionBaseId,Solutions::getBaseId)
                        .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
                        .eq(InsuranceApply::getIsdeleted, Constants.ZERO)
                        .eq(InsuranceApply::getStatus,Constants.InsuranceApplyStatus.PLATFORM_CHECK_PASS.getKey())
                        .eq(InsuranceApply::getStatus,Constants.InsuranceApplyStatus.COMPANY_MEMBER_LIST_SIGNATURE.getKey())
                        .eq(Solutions::getBaseId,saveUnionApplyDTO.getBaseSolutionId())
                        .in(InsuranceApply::getId,saveUnionApplyDTO.getApplyIds())
                        .isNull(InsuranceApply::getUnionApplyId)
@@ -263,7 +264,6 @@
        Integer maxDays = DateUtil.calculateBetween(saveUnionApplyDTO.getStartDate(),saveUnionApplyDTO.getEndDate(),0);
        List<ApplyDetail> applyDetailList = applyDetailJoinMapper.selectList(new QueryWrapper<ApplyDetail>().lambda().select(ApplyDetail::getPrice)
                .in(ApplyDetail::getApplyId,saveUnionApplyDTO.getApplyIds()));
        //unionApply.setFee(insuranceApplyList.stream().map(i->i.getFee()).reduce(BigDecimal.ZERO,BigDecimal::add));
        unionApply.setFee(applyDetailList.stream().map(i->i.getPrice().multiply(new BigDecimal(maxDays))).reduce(BigDecimal.ZERO,BigDecimal::add));
        unionApplyMapper.insert(unionApply);
@@ -276,6 +276,8 @@
        applyDetailJoinMapper.update(null,new UpdateWrapper<ApplyDetail>().lambda()
                .set(ApplyDetail::getUnionApplyId,unionApply.getId())
                .in(ApplyDetail::getApplyId,saveUnionApplyDTO.getApplyIds()));
        return unionApply.getId();
    }
@@ -301,6 +303,9 @@
        if(unionApply.getStatus().equals(Constants.UnionApplyStatus.FINISH.getKey())){
            throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"对不起,合并单业务已完结,您无法进行该操作!");
        }
        if(unionApply.getStatus().equals(Constants.UnionApplyStatus.CLOSE.getKey())){
            throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"对不起,合并单业务已关闭");
        }
        //合并单状态处于待投保
        if(unionApply.getStatus().equals(Constants.UnionApplyStatus.UPLOAD_INSURANCE_POLICY.getKey())
        || unionApply.getStatus().equals(Constants.UnionApplyStatus.WAIT_SIGNATURE.getKey())){
@@ -313,11 +318,9 @@
                .set(InsuranceApply::getCheckUserId,user.getId())
                .eq(InsuranceApply::getUnionApplyId,unionApply.getId()));
        applyDetailJoinMapper.update(null,new UpdateWrapper<ApplyDetail>().lambda()
                .set(ApplyDetail::getUnionApplyId,null)
                .eq(ApplyDetail::getUnionApplyId,unionApply.getId()));
        unionApplyMapper.update(null,new UpdateWrapper<UnionApply>().lambda()
                .set(UnionApply::getCheckDate,new Date())
@@ -497,6 +500,22 @@
            }else if(useDays>0){
                currentFee =  new BigDecimal(useDays).multiply(price);
            }
            //上传保单信息
            if(StringUtils.isNotBlank(unionApplyBXDDDetailTO.getFileUrl())){
                Multifile multifile = new Multifile();
                multifile.setIsdeleted(Constants.ZERO);
                multifile.setCreator(user.getId());
                multifile.setCreateDate(new Date());
                multifile.setObjId(insuranceApply.getId());
                multifile.setObjType(Constants.MultiFile.COMPANY_TBD_SIGNED_PDF.getKey());
                multifile.setType(Constants.TWO);
                multifile.setFileurl(unionApplyBXDDDetailTO.getFileUrl());
                multifile.setName(unionApplyBXDDDetailTO.getFileName());
                multifileMapper.insert(multifile);
                insuranceApply.setUnionApplyTbdStatus(Constants.ONE);
            }else{
                insuranceApply.setUnionApplyTbdStatus(Constants.ZERO);
            }
            //更新投保申请单
            insuranceApplyJoinMapper.update(null,new UpdateWrapper<InsuranceApply>().lambda()
                    .set(InsuranceApply::getFee,
@@ -508,6 +527,7 @@
                    .set(InsuranceApply::getCurrentFee,currentFee.multiply(new BigDecimal(applyDetails.size())))
                    .set(InsuranceApply::getStartTime,unionApplyBXDDTO.getStartTime())
                    .set(InsuranceApply::getEndTime,unionApplyBXDDTO.getEndTime())
                    .set(InsuranceApply::getUnionApplyTbdStatus,insuranceApply.getUnionApplyTbdStatus())
                    .set(InsuranceApply::getEditDate,new Date())
                    .set(InsuranceApply::getEditor,user.getId())
                    .eq(InsuranceApply::getId,insuranceApply.getId()));
@@ -522,19 +542,7 @@
                    .set(ApplyDetail::getEndTime,unionApplyBXDDTO.getEndTime())
                    .in(ApplyDetail::getId,applyDetails.stream().map(m->m.getId()).collect(Collectors.toList()))
            );
            //上传保单信息
            if(StringUtils.isNotBlank(unionApplyBXDDDetailTO.getFileUrl())){
                Multifile multifile = new Multifile();
                multifile.setIsdeleted(Constants.ZERO);
                multifile.setCreator(user.getId());
                multifile.setCreateDate(new Date());
                multifile.setObjId(insuranceApply.getId());
                multifile.setObjType(Constants.MultiFile.BD_APPLY_PDF.getKey());
                multifile.setType(Constants.TWO);
                multifile.setFileurl(unionApplyBXDDDetailTO.getFileUrl());
                multifile.setName(unionApplyBXDDDetailTO.getFileName());
                multifileMapper.insert(multifile);
            }
            sumFee = sumFee.add(price.multiply(new BigDecimal(applyDetails.size())).multiply(new BigDecimal(maxDays)));
            sumCurrFee = sumCurrFee.add(currentFee.multiply(new BigDecimal(applyDetails.size())));
        }
server/service/src/main/java/com/doumee/service/business/impl/UnionChangeServiceImpl.java
@@ -1,20 +1,44 @@
package com.doumee.service.business.impl;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.annotation.excel.ExcelExporter;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.DateUtil;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.UnionChangeMapper;
import com.doumee.dao.business.model.UnionChange;
import com.doumee.dao.business.*;
import com.doumee.dao.business.dto.SaveUnionApplyDTO;
import com.doumee.dao.business.dto.SaveUnionChangeDTO;
import com.doumee.dao.business.dto.UnionChangeBXDDTO;
import com.doumee.dao.business.join.ApplyChagneDetailJoinMapper;
import com.doumee.dao.business.join.ApplyChangeJoinMapper;
import com.doumee.dao.business.join.ApplyDetailJoinMapper;
import com.doumee.dao.business.join.MemberInsuranceJoinMapper;
import com.doumee.dao.business.model.*;
import com.doumee.dao.business.vo.CountCyclePriceVO;
import com.doumee.service.business.UnionChangeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.doumee.service.business.third.SignService;
import com.github.xiaoymin.knife4j.core.util.CollectionUtils;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
 * åŠ å‡ä¿æ¢åŽ‚åˆå¹¶å•ä¿¡æ¯è¡¨Service实现
@@ -26,6 +50,36 @@
    @Autowired
    private UnionChangeMapper unionChangeMapper;
    @Autowired
    private ApplyChangeJoinMapper applyChangeJoinMapper;
    @Autowired
    private ApplyChagneDetailJoinMapper applyChagneDetailJoinMapper;
    @Autowired
    private CompanyMapper companyMapper;
    @Autowired
    private SolutionsMapper solutionsMapper;
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
    @Autowired
    private SignService signService;
    @Autowired
    private MemberMapper memberMapper;
    @Autowired
    private ApplyDetailJoinMapper applyDetailJoinMapper;
    @Autowired
    private MemberInsuranceJoinMapper memberInsuranceJoinMapper;
    @Autowired
    private InsuranceApplyMapper insuranceApplyMapper;
    @Override
    public Integer create(UnionChange unionChange) {
@@ -156,4 +210,518 @@
        QueryWrapper<UnionChange> wrapper = new QueryWrapper<>(unionChange);
        return unionChangeMapper.selectCount(wrapper);
    }
    @Override
    public Integer merge(SaveUnionChangeDTO saveUnionChangeDTO){
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(user.getType().equals(Constants.TWO)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"非商户用户,无法进行该操作");
        }
        if(Objects.isNull(saveUnionChangeDTO)
                || Objects.isNull(saveUnionChangeDTO.getApplyIds())
                || Objects.isNull(saveUnionChangeDTO.getApplyDate())
                || Objects.isNull(saveUnionChangeDTO.getUnionApplyId())
                || Objects.isNull(saveUnionChangeDTO.getBusinessType())
        ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        List<ApplyChange> applyChangeList = applyChangeJoinMapper.selectJoinList(ApplyChange.class,
                new MPJLambdaWrapper<ApplyChange>()
                        .selectAll(ApplyChange.class)
                        .leftJoin(InsuranceApply.class,InsuranceApply::getId,ApplyChange::getApplyId)
                        .eq(ApplyChange::getIsdeleted, Constants.ZERO)
                        .eq(InsuranceApply::getUnionApplyId,saveUnionChangeDTO.getUnionApplyId())
                        .eq(ApplyChange::getStatus,Constants.ApplyChangeStatus.COMPANY_SIGN.getKey())
                        .eq(InsuranceApply::getStatus,Constants.InsuranceApplyStatus.UPLOAD_INSURANCE.getKey())
                        .eq(ApplyChange::getType,saveUnionChangeDTO.getBusinessType())
                        .in(ApplyChange::getId,saveUnionChangeDTO.getApplyIds())
                        .isNull(ApplyChange::getUnionChangeId)
        );
        //查询数据是否存在未处于审批通过的数据
        if(applyChangeList.size()!=saveUnionChangeDTO.getApplyIds().size()){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"存在数据已处理,请刷新重试");
        }
        UnionChange unionChange = new UnionChange();
        unionChange.setCreateDate(new Date());
        unionChange.setCreator(user.getId());
        unionChange.setShopId(user.getCompanyId());
        unionChange.setUnionApplyId(saveUnionChangeDTO.getUnionApplyId());
        unionChange.setApplyStartTime(saveUnionChangeDTO.getApplyDate());
        unionChange.setType(saveUnionChangeDTO.getBusinessType());
        unionChange.setStatus(Constants.UnionChangeStatus.MERGE.getKey());
        unionChangeMapper.insert(unionChange);
        applyChangeJoinMapper.update(null,new UpdateWrapper<ApplyChange>().lambda()
                .set(ApplyChange::getUnionChangeId,unionChange.getId())
                .set(ApplyChange::getCheckDate,new Date())
                .set(ApplyChange::getCheckUserId,user.getId())
                .in(ApplyChange::getId,saveUnionChangeDTO.getApplyIds())
        );
        applyChagneDetailJoinMapper.update(null,new UpdateWrapper<ApplyChagneDetail>().lambda()
                .set(ApplyChagneDetail::getUnionChangeId,unionChange.getId())
                .in(ApplyChagneDetail::getApplyId,saveUnionChangeDTO.getApplyIds()));
        return unionChange.getId();
    }
    /**
     * å–消保单合并
     * @param id
     */
    @Override
    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
    public void cancelMerge(Integer id){
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(user.getType().equals(Constants.TWO)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"非商户用户,无法进行该操作!");
        }
        UnionChange unionChange = unionChangeMapper.selectById(id);
        if(Objects.isNull(unionChange)||!Constants.equalsInteger(unionChange.getIsdeleted(),Constants.ZERO)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        if(!unionChange.getShopId().equals(user.getCompanyId())){
            throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"对不起非您的合并单,您无法进行操作!");
        }
        if(unionChange.getStatus().equals(Constants.UnionChangeStatus.FINISH.getKey())){
            throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"对不起,合并单业务已完结,您无法进行该操作!");
        }
        if(unionChange.getStatus().equals(Constants.UnionChangeStatus.CLOSE.getKey())){
            throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"对不起,合并单业务已关闭");
        }
        applyChangeJoinMapper.update(null,new UpdateWrapper<ApplyChange>().lambda()
                .set(ApplyChange::getUnionChangeId,null)
                .set(ApplyChange::getCheckDate,new Date())
                .set(ApplyChange::getCheckUserId,user.getId())
                .in(ApplyChange::getUnionChangeId,unionChange.getId())
        );
        applyChagneDetailJoinMapper.update(null,new UpdateWrapper<ApplyChagneDetail>().lambda()
                .set(ApplyChagneDetail::getUnionChangeId,null)
                .in(ApplyChagneDetail::getApplyId,unionChange.getId()));
        unionChangeMapper.update(null,new UpdateWrapper<UnionChange>().lambda()
                .set(UnionChange::getStatus,Constants.UnionApplyStatus.CLOSE.getKey())
                .eq(UnionChange::getId,unionChange.getId())
        );
    }
    /**
     * åˆå¹¶å•(加减保/换厂) - æŠ•保申请签署
     * @param id
     * @return
     */
    @Override
    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
    public  String getSignLink(Integer id) {
        if(id == null ){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        UnionChange unionChange = unionChangeMapper.selectById(id);
        if(Objects.isNull(unionChange)||!Constants.equalsInteger(unionChange.getIsdeleted(),Constants.ZERO)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        if(!unionChange.getShopId().equals(user.getCompanyId())){
            throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"对不起非您的合并单,您无法进行操作!");
        }
        if(unionChange.getStatus().equals(Constants.UnionChangeStatus.FINISH.getKey())){
            throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"对不起,合并单业务已完结,您无法进行该操作!");
        }
        if(unionChange.getStatus().equals(Constants.UnionChangeStatus.CLOSE.getKey())){
            throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"对不起,合并单业务已关闭");
        }
        if(unionChange.getStatus().equals(Constants.UnionChangeStatus.MERGE.getKey())){
            throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"对不起,合并单状态已流转");
        }
        Company company =  companyMapper.selectById(user.getCompanyId());
        if(company== null || StringUtils.isBlank( company.getEmail()) || !Constants.equalsInteger(company.getSignStatus(),Constants.THREE)){
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,企业尚未具备在线签章条件,请联系平台管理员确认~");
        }
        String fileUrl = null;
        if(Constants.equalsObject(unionChange.getType(), Constants.ONE)){
//            fileUrl = ExcelExporter.build(ApplyChange.class).exportChangeUnitExcelToPdf(model,"换厂申请表","被保险人");
        }else{
//            fileUrl = ExcelExporter.build(ApplyChange.class).exportJiajianBaoExcelToPdf(model,"加减保申请表","被保险人");
        }
        String notifyUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.SIGN_DONE_NOTIFY_URL).getCode();
        notifyUrl = notifyUrl.replace("${type}","0").replace("${id}",unionChange.getId().toString());
        String applyNo = signService.applySignLocalFile(company.getName(),company.getName(),fileUrl,company.getCode(),company.getEmail(),"合并单(加减保/换厂)申请签署",company.getSignId(),notifyUrl);
        if(StringUtils.isBlank(applyNo) ){
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,获取在线签章地址失败,请稍后重试!");
        }
        String link = signService.signLink(applyNo,company.getName(),company.getCode());
        if(StringUtils.isBlank(link) ){
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,获取在线签章地址失败,请稍后重试!");
        }
        UnionChange update= new UnionChange();
        update.setId(unionChange.getId());
        update.setEditor(user.getId());
        update.setEditDate(new Date());
        update.setSignApplyNo(applyNo);
        unionChangeMapper.updateById(update);
        return  link;
    }
    @Override
    @Transactional(rollbackFor = {BusinessException.class,Exception.class})
    public void uploadBXD(UnionChangeBXDDTO unionChangeBXDDTO){
        if(Objects.isNull(unionChangeBXDDTO)
            || Objects.isNull(unionChangeBXDDTO.getId())
                || Objects.isNull(unionChangeBXDDTO.getApplyDate())
                || StringUtils.isBlank(unionChangeBXDDTO.getFileName())
                || StringUtils.isBlank(unionChangeBXDDTO.getFileUrl())
                || StringUtils.isBlank(unionChangeBXDDTO.getCode())
        ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        UnionChange unionChange = unionChangeMapper.selectById(unionChangeBXDDTO.getId());
        if(Objects.isNull(unionChange)||!Constants.equalsInteger(unionChange.getIsdeleted(),Constants.ZERO)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        if(!unionChange.getShopId().equals(user.getCompanyId())){
            throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"对不起非您的合并单,您无法进行操作!");
        }
        if(unionChange.getStatus().equals(Constants.UnionChangeStatus.FINISH.getKey())){
            throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"对不起,合并单业务已完结,您无法进行该操作!");
        }
        if(unionChange.getStatus().equals(Constants.UnionChangeStatus.CLOSE.getKey())){
            throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"对不起,合并单业务已关闭");
        }
        if(unionChange.getStatus().equals(Constants.UnionChangeStatus.UPLOAD_INSURANCE_POLICY.getKey())){
            throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"对不起,合并单状态已流转");
        }
        List<ApplyChange> applyChangeList = applyChangeJoinMapper.selectJoinList(ApplyChange.class,
                new MPJLambdaWrapper<ApplyChange>()
                        .selectAll(ApplyChange.class)
                        .selectAs(InsuranceApply::getSolutionId,ApplyChange::getSolutionsId)
                        .selectAs(InsuranceApply::getCode,ApplyChange::getApplyCode)
                        .leftJoin(InsuranceApply.class,InsuranceApply::getId,ApplyChange::getApplyId)
                        .eq(ApplyChange::getUnionChangeId,unionChange.getId()));
        if(CollectionUtils.isNotEmpty(applyChangeList)){
            for (ApplyChange applyChange:applyChangeList) {
                applyChange.setApplyStartTime(unionChangeBXDDTO.getApplyDate());
                applyChange.setValidTime(unionChangeBXDDTO.getApplyDate());
                applyChange.setEditDate(new Date());
                applyChange.setEditor(user.getId());
                List<ApplyChagneDetail> allList = applyChagneDetailJoinMapper.selectList(new QueryWrapper<ApplyChagneDetail>().lambda().eq(ApplyChagneDetail::getApplyChangeId,applyChange.getId()));
                this.dealApplyChangeDetail(applyChange,allList);
            }
        }
        unionChangeMapper.update(null,new UpdateWrapper<UnionChange>().lambda()
                .set(UnionChange::getStatus,Constants.UnionChangeStatus.FINISH.getKey())
                .set(UnionChange::getEditDate,new Date())
                .set(UnionChange::getEditor,user.getId())
                .eq(UnionChange::getId,unionChangeBXDDTO.getId())
        );
    }
    public void dealApplyChangeDetail(ApplyChange applyChange,List<ApplyChagneDetail> applyChagneDetailList){
        BigDecimal totalFee = BigDecimal.ZERO;
        BigDecimal currentFee = BigDecimal.ZERO;
        //查询最后记录 èŽ·å–å¯¹åº”å•ä»·
        ApplyDetail applyDetail = applyDetailJoinMapper.selectOne(new QueryWrapper<ApplyDetail>().lambda().eq(ApplyDetail::getApplyId,applyChange.getApplyId()).last(" limit 1 "));
        if(Objects.isNull(applyDetail)){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"未查询到保单明细数据");
        }
        //获取单价
        BigDecimal price = applyDetail.getPrice();
        for (ApplyChagneDetail detail:applyChagneDetailList) {
            Member member = memberMapper.selectById(detail.getMemberId());
            if(Objects.isNull(member)){
                throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到员工数据");
            }
            if (Constants.equalsInteger(detail.getType(), Constants.ZERO)) {
               this.addChangeDetailData(applyChange,detail,price,currentFee,totalFee);
            }else if(Constants.equalsInteger(detail.getType(),Constants.ONE)){
                this.reduceChangeDetailData(applyChange,detail,applyDetail,price,currentFee,totalFee);
            }else{
                this.otherChangeDetailData(applyChange,detail,applyDetail,price);
            }
        }
        if (totalFee.compareTo(new BigDecimal(0)) != 0) {
            //如果保单金额发生编码,更新总保单金额
            insuranceApplyMapper.update(null, new UpdateWrapper<InsuranceApply>().lambda()
                    .setSql(" fee = ifnull(fee,0)+" + totalFee)
                    .setSql(" current_fee = ifnull(current_fee,0)+" + currentFee)
                    .set(InsuranceApply::getEditor, applyChange.getEditor())
                    .set(InsuranceApply::getEditDate, applyChange.getEditDate())
                    .eq(InsuranceApply::getId, applyChange.getApplyId())
            );
            applyChangeJoinMapper.update(null, new UpdateWrapper<ApplyChange>().lambda()
                    .set(ApplyChange::getFee,totalFee)
                    .set(ApplyChange::getEditor, applyChange.getEditor())
                    .set(ApplyChange::getEditDate, applyChange.getEditDate())
                    .eq(ApplyChange::getId, applyChange.getApplyId())
            );
        }
    }
    /**
     * åŠ ä¿æ•°æ®å¤„ç†
     * @param applyChange
     * @param detail
     * @param price
     * @param currentFee
     * @param totalFee
     */
    public void addChangeDetailData(ApplyChange applyChange,ApplyChagneDetail detail
            ,BigDecimal price,BigDecimal currentFee,BigDecimal totalFee){
        //查询加保人员是否存在 å†²çªçš„ ä¿å•明细数据
        if(applyDetailJoinMapper.selectCount(new QueryWrapper<ApplyDetail>()
                .lambda()
                .eq(ApplyDetail::getApplyId,applyChange.getApplyId())
                .eq(ApplyDetail::getIdcardNo,detail.getIdcardNo())
                .le(ApplyDetail::getStartTime,DateUtil.getMontageDate(applyChange.getApplyStartTime(),1))
                .ge(ApplyDetail::getEndTime,DateUtil.getMontageDate(detail.getEndTime(),2))
        )>Constants.ZERO){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "当前保单下,加保人员【" + detail.getMemberName() + "】存在日期冲突的数据");
        }
        //总天数
        Integer countDays = DateUtil.daysBetweenDates(DateUtil.getMontageDate(detail.getEndTime(), 2), applyChange.getApplyStartTime());
        //加保
        ApplyDetail add = new ApplyDetail();
        if(new Date().compareTo(DateUtil.getMontageDate(applyChange.getApplyStartTime(), 2))>=0){
            Integer days = DateUtil.daysBetweenDates(DateUtil.getMontageDate(new Date(), 2), applyChange.getApplyStartTime()) + 1;
            //如果已已产生费用,计算已已产生费用
            add.setCurrentFee(new BigDecimal(days).multiply(price));
        }else{
            add.setCurrentFee(BigDecimal.ZERO);
        }
        add.setApplyId(applyChange.getApplyId());
        add.setValidCode(applyChange.getValidCode());
        add.setFee(detail.getFee());
        add.setIsdeleted(Constants.ZERO);
        add.setCreator(applyChange.getEditor());
        add.setCreateDate(applyChange.getEditDate());
        add.setMemberId(detail.getMemberId());
        add.setMemberName(detail.getMemberName());
        add.setWorktypeId(detail.getWorktypeId());
        add.setIsdeleted(Constants.ZERO);
        add.setIdcardNo(detail.getIdcardNo());
        add.setSex(Constants.getSexByIdCard(detail.getIdcardNo()));
        add.setMemberName(detail.getMemberName());
        add.setDuId(detail.getDuId());
        add.setStartTime(applyChange.getApplyStartTime());
        add.setStartTime(DateUtil.getMontageDate(applyChange.getApplyStartTime(), 1));
        add.setEndTime(DateUtil.getMontageDate(detail.getEndTime(), 2));
        add.setFee(new BigDecimal(countDays).multiply(price));
        applyDetailJoinMapper.insert(add);
        detail.setFee(add.getFee());
        applyChagneDetailJoinMapper.update(null,new UpdateWrapper<ApplyChagneDetail>().lambda()
                .set(ApplyChagneDetail::getFee,add.getFee())
                .set(ApplyChagneDetail::getStartTime,DateUtil.getMontageDate(applyChange.getApplyStartTime(), 1))
                .eq(ApplyChagneDetail::getId,detail.getId())
        );
        totalFee = totalFee.add(add.getFee());
        currentFee = currentFee.add(add.getCurrentFee());
        MemberInsurance memberInsurance = new MemberInsurance(detail, applyChange, applyChange.getEditor(), add.getId(),applyChange.getSolutionsId());
        memberInsurance.setStartTime(add.getStartTime());
        memberInsurance.setEndTime(add.getEndTime());
        memberInsurance.setRelationType(Constants.ONE);
        memberInsuranceJoinMapper.insert(memberInsurance);
    }
    /**
     * å‡ä¿æ•°æ®å¤„理
     * @param applyChange
     * @param detail
     * @param applyDetail
     * @param price
     * @param currentFee
     * @param totalFee
     */
    public void reduceChangeDetailData(ApplyChange applyChange,ApplyChagneDetail detail,ApplyDetail applyDetail
            ,BigDecimal price,BigDecimal currentFee,BigDecimal totalFee){
        //查询员工是在主单下 æ˜¯å¦å­˜åœ¨ç”Ÿæ•ˆä¸­çš„æ•°æ®
        ApplyDetail oldModel = applyDetailJoinMapper.selectOne(new QueryWrapper<ApplyDetail>().lambda()
                .eq(ApplyDetail::getApplyId, applyChange.getApplyId())
                .eq(ApplyDetail::getMemberId, detail.getMemberId())
                .orderByDesc(ApplyDetail::getCreateDate)
                .last("limit 1"));
        if (oldModel == null || oldModel.getStartTime() == null || oldModel.getStartTime().getTime() > applyChange.getApplyStartTime().getTime()) {
            throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(), "对不起,用户【" + detail.getMemberName() + "】原保单信息有误,当前申请不支持减保处理!");
        }
        //计算已生效天数
        //当审批时间 å°äºŽ å½“前时间 è®¡ç®—实际减少金额 å› ä¸ºå·²æ‰£é‡‘额会大于 åº”扣金额
        BigDecimal pullFee = BigDecimal.ZERO;
        //减保减少的金额
        BigDecimal reduceFee = BigDecimal.ZERO;
        if (DateUtil.daysBetweenDates(DateUtil.getMontageDate(new Date(), 2),applyChange.getApplyStartTime()) > 0) {
            //计算多扣金额
            Integer days = DateUtil.daysBetweenDates(DateUtil.getMontageDate(new Date(), 2), applyChange.getApplyStartTime()) + 1;
            pullFee = new BigDecimal(days).multiply(price).multiply(new BigDecimal(-1));
        }
        //计算投保明细应减少的天数
        Integer reduceDays = DateUtil.daysBetweenDates(DateUtil.getMontageDate(applyDetail.getEndTime(), 2), applyChange.getApplyStartTime()) + 1;
        if(reduceDays>0){
            reduceFee = new BigDecimal(reduceDays).multiply(price).multiply(new BigDecimal(-1));
        }
        applyDetailJoinMapper.update(null, new UpdateWrapper<ApplyDetail>().lambda()
                .setSql(" fee = ifnull(fee,0)+" + reduceFee)
                .setSql(" current_fee = ifnull(current_fee,0)+" + pullFee)
                .set(oldModel.getStartTime().compareTo(applyChange.getApplyStartTime())!=0,ApplyDetail::getEndTime, DateUtil.getMontageDate(applyChange.getApplyStartTime(), 3))
                .set(oldModel.getStartTime().compareTo(applyChange.getApplyStartTime())==0,ApplyDetail::getEndTime, DateUtil.getMontageDate(applyChange.getApplyStartTime(), 2))
                .set(ApplyDetail::getEditor, applyChange.getEditor())
                .set(ApplyDetail::getEditDate, applyChange.getEditDate())
                .eq(ApplyDetail::getId, oldModel.getId())
        );
        totalFee = totalFee.add(reduceFee);
        currentFee = currentFee.add(pullFee);
        //修改 å‘˜å·¥æŠ•保明细记录 åŽ†å²æ•°æ®
        memberInsuranceJoinMapper.update(null, new UpdateWrapper<MemberInsurance>().lambda()
                .setSql(" fee = ifnull(fee,0)+" + reduceFee)
                .set(oldModel.getStartTime().compareTo(applyChange.getApplyStartTime())!=0,MemberInsurance::getEndTime,DateUtil.getMontageDate(applyChange.getApplyStartTime(), 3))
                .set(oldModel.getStartTime().compareTo(applyChange.getApplyStartTime())==0,MemberInsurance::getEndTime,DateUtil.getMontageDate(applyChange.getApplyStartTime(), 2))
                .eq(MemberInsurance::getRelationId, oldModel.getId())
        );
        //修改业务明细行数据实际批单日期
        applyChagneDetailJoinMapper.update(null,new UpdateWrapper<ApplyChagneDetail>().lambda()
                .setSql(" fee = ifnull(fee,0)+" + reduceFee)
                .set(ApplyChagneDetail::getEndTime,DateUtil.getMontageDate(applyChange.getApplyStartTime(), 3))
                .eq(ApplyChagneDetail::getId,detail.getId())
        );
    }
    public void otherChangeDetailData(ApplyChange applyChange,ApplyChagneDetail detail,ApplyDetail applyDetail,BigDecimal price){
        //实际批单生效日期
        Date applyStartTime = DateUtil.getMontageDate(applyChange.getApplyStartTime(),1);
        //查询减保人员是否存在 å†²çªçš„ ä¿å•明细数据
        if(applyDetailJoinMapper.selectCount(new QueryWrapper<ApplyDetail>()
                .lambda()
                .eq(ApplyDetail::getApplyId,applyChange.getApplyId())
                .eq(ApplyDetail::getIdcardNo,detail.getIdcardNo())
                .le(ApplyDetail::getStartTime,applyStartTime)
                .ge(ApplyDetail::getEndTime,applyStartTime)
        )<=Constants.ZERO){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "当前保单下,换厂人员【" + detail.getMemberName() + "】未查询到符合批单日期的数据");
        }
        //查询员工是在主单下 æ˜¯å¦å­˜åœ¨ç”Ÿæ•ˆä¸­çš„æ•°æ®
        ApplyDetail oldModel = applyDetailJoinMapper.selectOne(new QueryWrapper<ApplyDetail>().lambda()
                .eq(ApplyDetail::getApplyId, applyChange.getApplyId())
                .eq(ApplyDetail::getMemberId, detail.getMemberId())
                .le(ApplyDetail::getStartTime,applyStartTime)
                .ge(ApplyDetail::getEndTime,applyStartTime)
                .orderByDesc(ApplyDetail::getCreateDate)
                .last("limit 1"));
        if(oldModel == null  ){
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,用户【"+detail.getMemberName()+"】原保单信息有误,批单日期未在保单日期内!");
        }
        //如果实际批单日期 å’Œ åŽŸè®°å½•æ—¥æœŸç›¸ç­‰ åˆ™ç›´æŽ¥ä¿®æ”¹è®°å½•派遣单位与工种信息
        if(applyStartTime.compareTo(oldModel.getStartTime())!=Constants.ZERO){
            //当前日期大于批单日期 éœ€è¦å›žæ»šæ•°æ®å®žé™…数据
            Boolean flag = DateUtil.getMontageDate(new Date(),2).compareTo(DateUtil.getMontageDate(applyStartTime,2))>0;
            //换厂后历史记录的费用 fee
            Integer days = DateUtil.daysBetweenDates(DateUtil.getMontageDate(applyStartTime,3),DateUtil.getMontageDate(oldModel.getStartTime(),1))+1;
            BigDecimal oldFee = new BigDecimal(days).multiply(price);
            BigDecimal fee = oldModel.getFee();
            BigDecimal oldCurrentFee = oldModel.getCurrentFee();
            applyDetailJoinMapper.update(null, new UpdateWrapper<ApplyDetail>().lambda()
                    .set(ApplyDetail::getEditor,applyChange.getEditor())
                    .set(ApplyDetail::getEditDate,applyChange.getEditDate())
                    .set(ApplyDetail::getEndTime,DateUtil.getMontageDate(applyStartTime,3))
                    .set(ApplyDetail::getFee,oldFee)
                    .set(flag,ApplyDetail::getCurrentFee,oldFee)
                    .eq(ApplyDetail::getId,oldModel.getId())
            );
            //修改 å‘˜å·¥æŠ•保明细记录 åŽ†å²æ•°æ®
            memberInsuranceJoinMapper.update(null,new UpdateWrapper<MemberInsurance>().lambda()
                    .set(MemberInsurance::getEndTime,applyStartTime)
                    .set(MemberInsurance::getFee,oldFee)
                    .eq(MemberInsurance::getRelationId,oldModel.getId())
            );
            ApplyDetail add = new ApplyDetail();
            add.setApplyId(oldModel.getApplyId());
            add.setCreateDate(new Date());
            add.setCreator(applyChange.getEditor());
            add.setMemberId(oldModel.getMemberId());
            add.setIdcardNo(detail.getIdcardNo());
            add.setSex(Constants.getSexByIdCard(detail.getIdcardNo()));
            add.setMemberName(detail.getMemberName());
            add.setStartTime(DateUtil.getMontageDate(applyStartTime,1));
            add.setEndTime(oldModel.getEndTime());
            add.setDuId(detail.getDuId());
            add.setWorktypeId(detail.getWorktypeId());
            add.setIdcardNo(oldModel.getIdcardNo());
            add.setFee(fee.subtract(oldFee));
            add.setIsdeleted(Constants.ZERO);
            if(flag){
                add.setCurrentFee(oldCurrentFee.multiply(oldFee));
            }else{
                add.setCurrentFee(BigDecimal.ZERO);
            }
            add.setSex(oldModel.getSex());
            add.setMemberName(oldModel.getMemberName());
            add.setFromId(detail.getId());
            applyDetailJoinMapper.insert(add);
            MemberInsurance memberInsurance = new MemberInsurance(applyDetail,applyChange.getId());
            memberInsurance.setSolutionId(detail.getSolutionId());
            memberInsurance.setWorktypeName(detail.getWorkTypeName());
            memberInsurance.setDuName(detail.getDuName());
            memberInsurance.setApplyChangeId(detail.getApplyChangeId());
            memberInsurance.setSolutionName(detail.getSolutionsName());
            memberInsurance.setPdCode(applyChange.getValidCode());
            memberInsurance.setBdCode(applyChange.getApplyCode());
            memberInsurance.setRelationType(Constants.ONE);
            memberInsuranceJoinMapper.insert(memberInsurance);
        }else{
            applyDetailJoinMapper.update(null, new UpdateWrapper<ApplyDetail>().lambda()
                    .set(ApplyDetail::getEditor,applyChange.getEditor())
                    .set(ApplyDetail::getEditDate,applyChange.getEditDate())
                    .set(ApplyDetail::getDuId,detail.getDuId())
                    .set(ApplyDetail::getWorktypeId,detail.getWorktypeId())
                    .eq(ApplyDetail::getId,oldModel.getId())
            );
            //员工投保明细记录 åŽ†å²æ•°æ®
            memberInsuranceJoinMapper.update(null,new UpdateWrapper<MemberInsurance>().lambda()
                    .set(MemberInsurance::getDuId,detail.getDuId())
                    .set(MemberInsurance::getDuName,detail.getDuName())
                    .set(MemberInsurance::getWorktypeId,detail.getWorktypeId())
                    .set(MemberInsurance::getWorktypeName,detail.getWorkTypeName())
                    .eq(MemberInsurance::getRelationId,oldModel.getId())
            );
        }
    }
}