package com.doumee.service.business.impl; import cn.hutool.core.util.IdcardUtil; import com.alibaba.fastjson.JSONObject; 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.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.core.utils.aliyun.ALiYunUtil; import com.doumee.dao.business.*; import com.doumee.dao.business.dto.*; import com.doumee.dao.business.join.*; import com.doumee.dao.business.model.*; import com.doumee.dao.business.vo.ApplyPowerVO; import com.doumee.dao.business.vo.CountCyclePriceVO; import com.doumee.dao.system.SystemUserMapper; import com.doumee.dao.system.model.SystemUser; import com.doumee.service.business.InsuranceApplyOnService; import com.doumee.service.business.InsuranceApplyService; import com.doumee.service.business.SmsEmailService; import com.doumee.service.business.third.SignService; import com.github.xiaoymin.knife4j.core.util.CollectionUtils; import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.jzq.common.bean.sign.NotifyDataReq; import org.apache.commons.lang3.StringUtils; import org.apache.shiro.SecurityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.io.File; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.*; import java.util.stream.Collectors; /** * 投保申请信息表Service实现 * @author 江蹄蹄 * @date 2024/01/16 10:03 */ @Service public class InsuranceApplyOnServiceImpl implements InsuranceApplyOnService { @Value("${debug_model}") private boolean debugModel; @Autowired private InsuranceApplyMapper insuranceApplyMapper; @Autowired private SmsEmailService smsEmailService; @Autowired private ApplyChangeJoinMapper applyChangeMapper; @Autowired private SystemDictDataBiz systemDictDataBiz; @Autowired private InsuranceApplyJoinMapper insuranceApplyJoinMapper; @Autowired private CompanyMapper companyMapper; @Autowired private MemberInsuranceJoinMapper memberInsuranceJoinMapper; @Autowired private ApplyDetailMapper applyDetailMapper; @Autowired private ApplyDetailJoinMapper applyDetailJoinMapper; @Autowired private ApplyLogMapper applyLogMapper; @Autowired private SignService signService; @Autowired private MultifileMapper multifileMapper; @Autowired private ApplyLogJoinMapper applyLogJoinMapper; @Autowired private SolutionsMapper solutionsMapper; @Autowired private MemberMapper memberMapper; @Autowired private MemberJoinMapper memberJoinMapper; @Autowired private DuSolutionJoinMapper duSolutionJoinMapper; @Autowired private DuWorkTypeJoinMapper duWorkTypeJoinMapper; @Autowired private SolutionWorktypeJoinMapper solutionWorktypeJoinMapper; @Autowired private NoticesMapper noticesMapper; @Autowired private UnionApplyJoinMapper unionApplyJoinMapper; @Autowired private UnionChangeJoinMapper unionChangeJoinMapper; @Autowired private CompanySolutionMapper companySolutionMapper; @Autowired private ContractJoinMapper contractJoinMapper; @Autowired private SystemUserMapper systemUserMapper; @Autowired private CompanyDepartmentMapper companyDepartmentMapper; @Override @Transactional(rollbackFor = {Exception.class,BusinessException.class}) public Integer back(InsuranceApply insuranceApply) { if(insuranceApply.getId() == null ||StringUtils.isBlank(insuranceApply.getCheckInfo())){ throw new BusinessException(ResponseStatus.BAD_REQUEST); } InsuranceApply model = insuranceApplyMapper.selectById(insuranceApply.getId()); if(model == null ||!Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)){ throw new BusinessException(ResponseStatus.DATA_EMPTY); } Solutions solutions = solutionsMapper.selectById(model.getSolutionId()); if(Objects.isNull(solutions)){ throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询方案信息"); } LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); InsuranceApply update = new InsuranceApply(); if(Constants.equalsInteger(solutions.getType(),Constants.ZERO)){ if(Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.UPLOAD_INSURANCE.getKey())){ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该申请状态已流转,当前不支持该操作~"); } update.setStatus(Constants.InsuranceApplyStatus.FAIL_RETURN.getKey()); }else{ if( !(Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.WTB_COMPANY_MEMBER_LIST_SIGNATURE.getKey()) || Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.WTB_COMPANY_APPLY_SIGNATURE.getKey()) || Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.WTB_UPLOAD.getKey()))){ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该申请状态已流转,当前不支持该操作~"); } update.setStatus(Constants.InsuranceApplyStatus.WTB_RETURN.getKey()); } update.setEditDate(new Date()); update.setEditor(user.getId()); update.setCheckDate(update.getEditDate()); update.setCheckInfo(insuranceApply.getCheckInfo()); update.setCheckUserId(user.getId()); update.setId(model.getId()); insuranceApplyMapper.updateById(update); //存储待办信息 Constants.NoticeObjectType noticeObjectType = Constants.NoticeObjectType.INSURANCE_APPLY; //删除其他待办 noticesMapper.delete(new QueryWrapper().lambda().eq(Notices::getObjType,noticeObjectType.getKey()) .ne(Notices::getType,Constants.NoticeType.SIX.getStatus()) .eq(Notices::getObjId,insuranceApply.getId())); Notices notices = new Notices(noticeObjectType,Constants.ONE,insuranceApply.getId(),solutions.getName(), model.getCompanyId(), Constants.NoticeType.FOUR); noticesMapper.insert(notices); Constants.ApplyLogType applyLogType = Constants.ApplyLogType.PLATFORM_RETURN; String info =applyLogType.getInfo(); info = info.replace("${param}", update.getCheckInfo()); ApplyLog log = new ApplyLog(update,applyLogType.getName(),info,update.getId(),applyLogType.getKey(),JSONObject.toJSONString(model), JSONObject.toJSONString(update)); applyLogMapper.insert(log); return 1; } @Override @Transactional(rollbackFor = {Exception.class,BusinessException.class}) public Integer closeWtbForShop(InsuranceApply insuranceApply) { if(insuranceApply.getId() == null ||StringUtils.isBlank(insuranceApply.getCheckInfo())){ throw new BusinessException(ResponseStatus.BAD_REQUEST); } InsuranceApply model = insuranceApplyMapper.selectById(insuranceApply.getId()); if(model == null ||!Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)){ throw new BusinessException(ResponseStatus.DATA_EMPTY); } //只有审核通过的状态可关闭 if(!Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.WTB_BUSINESS_CHECK_PASS.getKey())){ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该申请状态已流转,当前不支持该操作~"); } LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); InsuranceApply update = new InsuranceApply(); update.setEditDate(new Date()); update.setEditor(user.getId()); update.setStatus(Constants.InsuranceApplyStatus.WTB_CLOSED.getKey()); update.setCheckDate(update.getEditDate()); update.setCheckInfo(insuranceApply.getCheckInfo()); update.setCheckUserId(user.getId()); update.setId(model.getId()); insuranceApplyMapper.updateById(update); Constants.ApplyLogType applyLogType = Constants.ApplyLogType.SHOP_CLOSE_WTB_APPLY; String info =applyLogType.getInfo(); info = info.replace("${param}", update.getCheckInfo()); ApplyLog log = new ApplyLog(update,applyLogType.getName(),info,update.getId(),applyLogType.getKey(),JSONObject.toJSONString(model), JSONObject.toJSONString(update)); applyLogMapper.insert(log); return 1; } @Override @Transactional(rollbackFor = {Exception.class,BusinessException.class}) public Integer uploadToubaodan(InsuranceApply insuranceApply) { if(insuranceApply.getId() == null || insuranceApply.getToubaodanFile() == null ||StringUtils.isBlank( insuranceApply.getToubaodanFile() .getFileurl()) ||StringUtils.isBlank( insuranceApply.getToubaodanFile() .getName())){ throw new BusinessException(ResponseStatus.BAD_REQUEST); } InsuranceApply model = insuranceApplyMapper.selectById(insuranceApply.getId()); if(model == null ||!Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)){ throw new BusinessException(ResponseStatus.DATA_EMPTY); } if(!(Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.UPLOAD.getKey()) || Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.WAIT_SIGNATURE.getKey()) || Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.PLATFORM_CHECK_PASS.getKey()))){ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该申请状态已流转,当前不支持该操作~"); } Solutions solutions = solutionsMapper.selectById(model.getSolutionId()); if(Objects.isNull(solutions)){ throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询方案信息"); } LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); InsuranceApply update = new InsuranceApply(); update.setEditDate(new Date()); update.setEditor(user.getId()); update.setStatus(Constants.InsuranceApplyStatus.WAIT_SIGNATURE.getKey()); update.setCheckDate(update.getEditDate()); update.setCheckInfo(insuranceApply.getCheckInfo()); update.setCheckUserId(user.getId()); update.setId(model.getId()); insuranceApplyMapper.updateById(update); multifileMapper.update(null,new UpdateWrapper().lambda() .eq(Multifile::getIsdeleted,Constants.ZERO) .eq(Multifile::getObjType,Constants.MultiFile.BD_APPLY_PDF.getKey()) .eq(Multifile::getObjId,update.getId()) .set(Multifile::getIsdeleted,Constants.ONE) .set(Multifile::getEditDate,update.getEditDate()) .set(Multifile::getEditor,update.getEditor()) ); insuranceApply.getToubaodanFile().setIsdeleted(Constants.ZERO); insuranceApply.getToubaodanFile().setCreator(user.getId()); insuranceApply.getToubaodanFile().setObjId(update.getId()); insuranceApply.getToubaodanFile().setCreateDate(update.getEditDate()); insuranceApply.getToubaodanFile().setObjType(Constants.MultiFile.BD_APPLY_PDF.getKey()); insuranceApply.getToubaodanFile().setType(Constants.TWO); multifileMapper.insert(insuranceApply.getToubaodanFile()); update.setToubaodanFile(insuranceApply.getToubaodanFile()); Constants.ApplyLogType applyLogType = Constants.ApplyLogType.WAIT_SIGNATURE; String info =applyLogType.getInfo(); // info = info.replace("${param}", update.getCheckInfo()); ApplyLog log = new ApplyLog(update,applyLogType.getName(),StringUtils.isNotBlank(update.getCheckInfo())?info:"",update.getId(),applyLogType.getKey(),JSONObject.toJSONString(model), JSONObject.toJSONString(update)); applyLogMapper.insert(log); //删除其他待办 Constants.NoticeObjectType noticeObjectType = Constants.NoticeObjectType.INSURANCE_APPLY; noticesMapper.delete(new QueryWrapper().lambda().eq(Notices::getObjType,noticeObjectType.getKey()).eq(Notices::getObjId,insuranceApply.getId())); Notices notices = new Notices(noticeObjectType,Constants.ONE,model.getId(),solutions.getName(), model.getCompanyId(), Constants.NoticeType.ONE); noticesMapper.insert(notices); return 1; } @Override @Transactional(rollbackFor = {Exception.class,BusinessException.class}) public Integer dealBackApply(InsuranceApply insuranceApply) { if(insuranceApply.getId() == null ||StringUtils.isBlank(insuranceApply.getCheckInfo())){ throw new BusinessException(ResponseStatus.BAD_REQUEST); } InsuranceApply model = insuranceApplyMapper.selectById(insuranceApply.getId()); if(model == null ||!Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)){ throw new BusinessException(ResponseStatus.DATA_EMPTY); } LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); Constants.ApplyLogType applyLogType = null; String info = ""; Constants.NoticeObjectType noticeObjectType = Constants.NoticeObjectType.INSURANCE_APPLY; //处理退回申请通知 noticesMapper.delete(new QueryWrapper().lambda().eq(Notices::getObjType,noticeObjectType.getKey()) .ne(Notices::getType,Constants.NoticeType.SIX.getStatus()) .eq(Notices::getObjId,insuranceApply.getId())); InsuranceApply update = new InsuranceApply(); if(insuranceApply.getDealBackApply() ==1){ //如果是驳回,只能可驳回已签章状态下的退回申请状态进行操作 if(!(Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.COMPANY_BACK_APPLY_SIGNATURE.getKey())|| Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.COMPANY_BACK_APPLY_WAIT_SIGNATURE.getKey())|| Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.COMPANY_BACK_APPLY_UPLOAD.getKey())|| Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.COMPANY_BACK_APPLY_PASS.getKey())) ){ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该申请状态已流转,当前不支持该操作~"); } applyLogType = Constants.ApplyLogType.PLATFORM_UN_AGREE_BACK; info = applyLogType.getInfo(); info = info.replace("${param}", insuranceApply.getCheckInfo()); if( Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.COMPANY_BACK_APPLY_SIGNATURE.getKey())){ update.setStatus(Constants.InsuranceApplyStatus.SIGNATURE.getKey()); }else if( Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.COMPANY_BACK_APPLY_WAIT_SIGNATURE.getKey())){ update.setStatus(Constants.InsuranceApplyStatus.WAIT_SIGNATURE.getKey()); }else if( Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.COMPANY_BACK_APPLY_UPLOAD.getKey())){ update.setStatus(Constants.InsuranceApplyStatus.UPLOAD.getKey()); }else if( Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.COMPANY_BACK_APPLY_PASS.getKey())){ update.setStatus(Constants.InsuranceApplyStatus.PLATFORM_CHECK_PASS.getKey()); } }else{ //如果是同意,两种申请退回状态都可操作 if(!(Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.COMPANY_BACK_APPLY_SIGNATURE.getKey()) ||Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.COMPANY_BACK_APPLY_WAIT_SIGNATURE.getKey()) ||Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.COMPANY_BACK_APPLY_UPLOAD.getKey()))){ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该申请状态已流转,当前不支持该操作~"); } applyLogType = Constants.ApplyLogType.PLATFORM_AGREE_BACK; update.setStatus(Constants.InsuranceApplyStatus.PLATFORM_RETURN.getKey()); //通知企业 已退回 Solutions solutions = solutionsMapper.selectById(model.getSolutionId()); if(Objects.nonNull(solutions)){ Notices notices = new Notices(noticeObjectType,Constants.ONE,insuranceApply.getId(),solutions.getName(), insuranceApply.getCompanyId(), Constants.NoticeType.FOUR); noticesMapper.insert(notices); } } update.setEditDate(new Date()); update.setEditor(user.getId()); update.setCheckDate(update.getEditDate()); update.setCheckInfo(insuranceApply.getCheckInfo()); update.setCheckUserId(user.getId()); update.setId(model.getId()); insuranceApplyMapper.updateById(update); ApplyLog log = new ApplyLog(update,applyLogType.getName(),info,update.getId(),applyLogType.getKey(),JSONObject.toJSONString(model), JSONObject.toJSONString(update)); applyLogMapper.insert(log); return 1; } @Override @Transactional(rollbackFor = {Exception.class,BusinessException.class}) public Integer uploadBaoxiandan(InsuranceApply insuranceApply) { if(insuranceApply.getId() == null || insuranceApply.getCode() == null || insuranceApply.getStartTime() == null || insuranceApply.getBaoxiandanFile() == null ||StringUtils.isBlank( insuranceApply.getBaoxiandanFile() .getFileurl()) ||StringUtils.isBlank( insuranceApply.getBaoxiandanFile() .getName())){ throw new BusinessException(ResponseStatus.BAD_REQUEST); } InsuranceApply model = insuranceApplyMapper.selectById(insuranceApply.getId()); if(model == null ||!Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)){ throw new BusinessException(ResponseStatus.DATA_EMPTY); } if(!Constants.equalsInteger(model.getStatus(),Constants.InsuranceApplyStatus.SIGNATURE.getKey())){ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该申请状态已流转,当前不支持该操作~"); } if(model.getApplyEndTime()== null || model.getStartTime().getTime()>model.getApplyEndTime().getTime() ){ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该申请生效周期时间不符合要求,请确认后修改重试~"); } Solutions solutions = solutionsMapper.selectById(model.getSolutionId()); if(Objects.isNull(solutions)){ throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询方案信息"); } //计算实际截止时间 Date actEndTime = new Date(model.getApplyEndTime().getTime() + (insuranceApply.getStartTime().getTime() - model.getApplyStartTime().getTime())); LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); InsuranceApply update = new InsuranceApply(); update.setEditDate(new Date()); update.setEditor(user.getId()); update.setStatus(Constants.InsuranceApplyStatus.UPLOAD_INSURANCE.getKey()); update.setCheckDate(update.getEditDate()); update.setCheckInfo(insuranceApply.getCheckInfo()); update.setCheckUserId(user.getId()); update.setId(model.getId()); update.setCode(insuranceApply.getCode()); update.setEndTime(actEndTime); update.setStartTime(insuranceApply.getStartTime()); CountCyclePriceDTO countCyclePriceDTO = new CountCyclePriceDTO(); countCyclePriceDTO.setSolutionsId(model.getSolutionId()); countCyclePriceDTO.setStartDate(insuranceApply.getStartTime()); update.setFinalEndTime(this.getCountCyclePriceVO(countCyclePriceDTO).getEndDate()); insuranceApplyMapper.updateById(update); //修改明细行的开始结束日期 applyDetailMapper.update(null,new UpdateWrapper().lambda() .set(ApplyDetail::getStartTime,insuranceApply.getStartTime()) .set(ApplyDetail::getEndTime,actEndTime) .eq(ApplyDetail::getApplyId,model.getId())); multifileMapper.update(null,new UpdateWrapper().lambda() .eq(Multifile::getIsdeleted,Constants.ZERO) .eq(Multifile::getObjType,Constants.MultiFile.BD_DONE_PDF.getKey()) .eq(Multifile::getObjId,update.getId()) .set(Multifile::getIsdeleted,Constants.ONE) .set(Multifile::getEditDate,update.getEditDate()) .set(Multifile::getEditor,update.getEditor()) ); insuranceApply.getBaoxiandanFile().setIsdeleted(Constants.ZERO); insuranceApply.getBaoxiandanFile().setCreator(user.getId()); insuranceApply.getBaoxiandanFile().setObjId(update.getId()); insuranceApply.getBaoxiandanFile().setCreateDate(update.getEditDate()); insuranceApply.getBaoxiandanFile().setObjType(Constants.MultiFile.BD_DONE_PDF.getKey()); insuranceApply.getBaoxiandanFile().setType(Constants.TWO); multifileMapper.insert(insuranceApply.getBaoxiandanFile()); update.setBaoxiandanFile(insuranceApply.getBaoxiandanFile()); noticesMapper.delete(new QueryWrapper().lambda().eq(Notices::getObjType,Constants.NoticeObjectType.INSURANCE_APPLY.getKey()) .ne(Notices::getType,Constants.NoticeType.SIX.getStatus()) .eq(Notices::getObjId,insuranceApply.getId())); Constants.ApplyLogType applyLogType = Constants.ApplyLogType.UPLOAD_INSURANCE; String info = ""; if(model.getApplyStartTime()!=null && model.getApplyStartTime().getTime()/1000!= insuranceApply.getStartTime().getTime()/1000){ info =applyLogType.getInfo(); info = info.replace("${param1}",DateUtil.getPlusTime2(model.getStartTime())); info = info.replace("${param2}",DateUtil.getPlusTime2(insuranceApply.getStartTime())); } ApplyLog log = new ApplyLog(update,applyLogType.getName(), info,update.getId(),applyLogType.getKey(),JSONObject.toJSONString(model), JSONObject.toJSONString(update)); applyLogMapper.insert(log); //存储员工信息投保记录 //查询单据明细记录 MPJLambdaWrapper queryWrapper = new MPJLambdaWrapper<>(); queryWrapper.selectAll(ApplyDetail.class); queryWrapper.selectAs(DispatchUnit::getName,ApplyDetail::getDuName); queryWrapper.selectAs(InsuranceApply::getCode,ApplyDetail::getApplyCode); queryWrapper.selectAs(Solutions::getId,ApplyDetail::getSolutionId); queryWrapper.selectAs(Solutions::getName,ApplyDetail::getSolutionName); queryWrapper.selectAs(Worktype::getName,ApplyDetail::getWorkTypeName); queryWrapper.selectAs(Member::getIdcardNo,ApplyDetail::getIdcardNo); queryWrapper.selectAs(Member::getName,ApplyDetail::getMemberName); queryWrapper.leftJoin(DispatchUnit.class,DispatchUnit::getId,ApplyDetail::getDuId); queryWrapper.leftJoin(Worktype.class,Worktype::getId,ApplyDetail::getWorktypeId); queryWrapper.leftJoin(Member.class,Member::getId,ApplyDetail::getMemberId); queryWrapper.leftJoin(InsuranceApply.class,InsuranceApply::getId,ApplyDetail::getApplyId); queryWrapper.leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId); queryWrapper.eq(ApplyDetail::getApplyId,insuranceApply.getId()); List applyDetailList = applyDetailJoinMapper.selectJoinList(ApplyDetail.class,queryWrapper); if(CollectionUtils.isNotEmpty(applyDetailList)){ List memberInsuranceList = new ArrayList<>(); List idCodeList = new ArrayList<>(); for (ApplyDetail applyDetail:applyDetailList) { idCodeList.add(applyDetail.getIdcardNo()); } List allDetailList = this.getMemberSolutionList(solutions.getParentId(),idCodeList, update.getStartTime() ,update.getEndTime(),insuranceApply.getId()); for (ApplyDetail applyDetail:applyDetailList) { //查询人员信息是否存在相同的方案下是否存在 冲突数据 this.checkMemberSolution( applyDetail.getIdcardNo(),allDetailList,applyDetail.getMemberName()); MemberInsurance memberInsurance = new MemberInsurance(applyDetail,user.getId()); memberInsurance.setRelationType(Constants.ZERO); memberInsuranceList.add(memberInsurance); memberMapper.update(null,new UpdateWrapper() .lambda() .set(Member::getStartTime,memberInsurance.getStartTime()) .set(Member::getEndTime,memberInsurance.getEndTime()) .set(Member::getDuId,memberInsurance.getDuId()) .set(Member::getWorktypeId,memberInsurance.getWorktypeId()) .eq(Member::getId, memberInsurance.getMemberId()) ); } memberInsuranceJoinMapper.insert(memberInsuranceList); } this.updateApplyCurrentFee(insuranceApply.getId(),null); return 1; } public CountCyclePriceVO getCountCyclePriceVO(CountCyclePriceDTO countCyclePriceDTO){ if(Objects.isNull(countCyclePriceDTO) || Objects.isNull(countCyclePriceDTO.getSolutionsId()) || Objects.isNull(countCyclePriceDTO.getStartDate()) ){ throw new BusinessException(ResponseStatus.BAD_REQUEST); } Solutions solutions = solutionsMapper.selectById(countCyclePriceDTO.getSolutionsId()); if(Objects.isNull(solutions)){ throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询方案信息"); } return Constants.countPriceVO(countCyclePriceDTO.getStartDate(),solutions); } /** * 更新保单实际金额 */ @Transactional(rollbackFor = {Exception.class,BusinessException.class}) public void updateApplyCurrentFee(Integer id,Integer unionId){ List insuranceApplyList = insuranceApplyJoinMapper.selectJoinList(InsuranceApply.class,new MPJLambdaWrapper() .selectAll(InsuranceApply.class) .eq(InsuranceApply::getIsdeleted,Constants.ZERO) .in(InsuranceApply::getStatus,Constants.InsuranceApplyStatus.UPLOAD_INSURANCE.getKey(),Constants.InsuranceApplyStatus.WTB_DONE.getKey()) .eq(!Objects.isNull(id),InsuranceApply::getId,id) .eq(!Objects.isNull(unionId),InsuranceApply::getUnionApplyId,unionId) .le(InsuranceApply::getStartTime,DateUtil.getDate(new Date(),"yyyy-MM-dd") + " 00:00:00") .ge(InsuranceApply::getEndTime,DateUtil.getDate(new Date(),"yyyy-MM-dd") + " 23:59:59") ); if(CollectionUtils.isNotEmpty(insuranceApplyList)){ for (InsuranceApply insuranceApply:insuranceApplyList) { Solutions solutions = solutionsMapper.selectById(insuranceApply.getSolutionId()); if(Objects.isNull(solutions)){ continue; } BigDecimal sumAmount = BigDecimal.ZERO; List applyDetailList = applyDetailMapper .selectList(new QueryWrapper().lambda() .ne(ApplyDetail::getChangeStatus,Constants.TWO) .eq(ApplyDetail::getApplyId,insuranceApply.getId())); if(CollectionUtils.isNotEmpty(applyDetailList)){ for (ApplyDetail applyDetail: applyDetailList) { BigDecimal fee = Objects.isNull(insuranceApply.getServerCost())? solutions.getPrice(): solutions.getPrice().add(insuranceApply.getServerCost()); //在开始结束日期之间 if(applyDetail.getStartTime().compareTo(new Date()) <= 0 && applyDetail.getEndTime().compareTo(new Date()) >= 0 ){ applyDetail.setCurrentFee(Constants.produceFee(solutions,fee,insuranceApply.getStartTime(),insuranceApply.getFinalEndTime(),applyDetail.getStartTime())); applyDetailMapper.updateById(applyDetail); }else if(applyDetail.getStartTime().compareTo(new Date()) <= 0&&applyDetail.getEndTime().compareTo(new Date()) <= 0){ //在结束日期之后 applyDetail.setCurrentFee(applyDetail.getFee()); applyDetailMapper.updateById(applyDetail); } if(Constants.equalsInteger(applyDetail.getChangeStatus(),Constants.ZERO) || applyDetail.getEndTime().getTime()>System.currentTimeMillis()){ sumAmount = sumAmount.add(applyDetail.getCurrentFee()); } } } insuranceApply.setCurrentFee(sumAmount); insuranceApplyMapper.updateById(insuranceApply); } } } public List getMemberSolutionList(Integer solutionParentId,List idCodeList, Date startTime,Date endTime,Integer applyId){ List applyDetailList = new ArrayList(); try { applyDetailList = applyDetailJoinMapper.selectJoinList(ApplyDetail.class, new MPJLambdaWrapper() .selectAll(ApplyDetail.class) .selectAs(InsuranceApply::getCode,ApplyDetail::getApplyCode) .selectAs(Company::getName,ApplyDetail::getCompanyName) .leftJoin(InsuranceApply.class,InsuranceApply::getId,ApplyDetail::getApplyId) .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId) .leftJoin(Company.class,Company::getId,InsuranceApply::getCompanyId) .in(ApplyDetail::getIdcardNo,idCodeList) .eq(ApplyDetail::getIsdeleted,Constants.ZERO) .eq(Solutions::getParentId,solutionParentId) .ne(Objects.nonNull(applyId),InsuranceApply::getId,applyId) .notIn(InsuranceApply::getStatus ,Constants.InsuranceApplyStatus.FAIL_RETURN.getKey() ,Constants.InsuranceApplyStatus.COMPANY_BACK_APPLY_PASS.getKey() ,Constants.InsuranceApplyStatus.CLOSE.getKey() ,Constants.InsuranceApplyStatus.WTB_RETURN.getKey() ,Constants.InsuranceApplyStatus.WTB_CLOSED.getKey() ) .apply(" ( " + " '"+DateUtil.getPlusTime(startTime)+"' <= t.start_time AND t.start_time < '"+DateUtil.getPlusTime(endTime)+"' " + " or " + " ( '"+DateUtil.getPlusTime(startTime)+"' < t.end_time AND t.end_time < '"+DateUtil.getPlusTime(endTime)+"' ) " + " or " + " ( '"+DateUtil.getPlusTime(startTime)+"' > t.start_time AND '"+DateUtil.getPlusTime(endTime)+"' < t.end_time )" + " ) " )); }catch (Exception e){ } return applyDetailList; } /** * 查询 会员信息在方案下是否存在冲突数据 */ public void checkMemberSolution(String idCode,List allDetailList,String memberName){ List applyDetailList = getMemberSolutionListByIdcode(idCode,allDetailList); if(applyDetailList.size() >Constants.ZERO){ String companyName = applyDetailList.get(Constants.ZERO).getCompanyName(); if(StringUtils.isNotBlank(companyName)){ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该员工【"+memberName+" "+idCode+"】已在【"+companyName+"】存在保险,请联系客服确认"); }else{ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"该员工【"+memberName+" "+idCode+"】在该保险方案下已存在投保记录,无法进行该操作"); } }; } private List getMemberSolutionListByIdcode(String idCode, List allDetailList) { if(allDetailList == null || allDetailList.size()==0){ return new ArrayList<>(); } List list = new ArrayList<>(); for(ApplyDetail d : allDetailList){ if(StringUtils.equals(d.getIdcardNo(),idCode)){ list.add(d); } } return list; } }