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.business.vo.dataBoard.DataListVO;
|
import com.doumee.dao.business.vo.dataBoard.InsuranceApplyDataVO;
|
import com.doumee.dao.business.vo.dataBoard.InsuranceApplyReportDataVO;
|
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 SolutionsJoinMapper 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;
|
@Autowired
|
private ApplyChangeDetailJoinMapper applyChangeDetailJoinMapper;
|
@Autowired
|
private SettleClaimsMapper settleClaimsMapper;
|
|
@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<Notices>().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<Multifile>().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<Notices>().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<Notices>().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<ApplyDetail>().lambda()
|
.set(ApplyDetail::getStartTime,insuranceApply.getStartTime())
|
.set(ApplyDetail::getEndTime,actEndTime)
|
.eq(ApplyDetail::getApplyId,model.getId()));
|
|
multifileMapper.update(null,new UpdateWrapper<Multifile>().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<Notices>().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<ApplyDetail> 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<ApplyDetail> applyDetailList = applyDetailJoinMapper.selectJoinList(ApplyDetail.class,queryWrapper);
|
|
if(CollectionUtils.isNotEmpty(applyDetailList)){
|
List<MemberInsurance> memberInsuranceList = new ArrayList<>();
|
List<String> idCodeList = new ArrayList<>();
|
for (ApplyDetail applyDetail:applyDetailList) {
|
idCodeList.add(applyDetail.getIdcardNo());
|
}
|
List<ApplyDetail> 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<Member>()
|
.lambda()
|
.set(Member::getStartTime,memberInsurance.getStartTime())
|
.set(Member::getEndTime,memberInsurance.getEndTime())
|
.set(Member::getDuId,memberInsurance.getDuId())
|
.set(Member::getWorktypeId,memberInsurance.getWorktypeId())
|
.eq(Member::getId, memberInsurance.getMemberId())
|
);
|
|
}
|
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<InsuranceApply> insuranceApplyList = insuranceApplyJoinMapper.selectJoinList(InsuranceApply.class,new MPJLambdaWrapper<InsuranceApply>()
|
.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<ApplyDetail> applyDetailList = applyDetailMapper
|
.selectList(new QueryWrapper<ApplyDetail>().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<ApplyDetail> getMemberSolutionList(Integer solutionParentId,List<String> idCodeList, Date startTime,Date endTime,Integer applyId){
|
List<ApplyDetail> applyDetailList = new ArrayList<ApplyDetail>();
|
try {
|
applyDetailList = applyDetailJoinMapper.selectJoinList(ApplyDetail.class,
|
new MPJLambdaWrapper<ApplyDetail>()
|
.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<ApplyDetail> allDetailList,String memberName){
|
List<ApplyDetail> 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<ApplyDetail> getMemberSolutionListByIdcode(String idCode, List<ApplyDetail> allDetailList) {
|
if(allDetailList == null || allDetailList.size()==0){
|
return new ArrayList<>();
|
}
|
List<ApplyDetail> list = new ArrayList<>();
|
for(ApplyDetail d : allDetailList){
|
if(StringUtils.equals(d.getIdcardNo(),idCode)){
|
list.add(d);
|
}
|
}
|
return list;
|
}
|
|
|
@Override
|
public InsuranceApplyDataVO getInsuranceApplyDataVO() {
|
InsuranceApplyDataVO insuranceApplyDataVO = new InsuranceApplyDataVO();
|
insuranceApplyDataVO.setInsuranceNum(Constants.ZERO);
|
insuranceApplyDataVO.setMonthAddInsuranceNum(Constants.ZERO);
|
insuranceApplyDataVO.setInsuranceCompanyNum(Constants.ZERO);
|
insuranceApplyDataVO.setMonthAddInsuranceCompanyNum(Constants.ZERO);
|
insuranceApplyDataVO.setMemberNum(Constants.ZERO);
|
insuranceApplyDataVO.setMonthAddMemberNum(Constants.ZERO);
|
insuranceApplyDataVO.setTotalFee(BigDecimal.ZERO);
|
insuranceApplyDataVO.setMonthAddTotalFee(BigDecimal.ZERO);
|
insuranceApplyDataVO.setUseCompanyNum(Constants.ZERO);
|
insuranceApplyDataVO.setUseInsuranceNum(Constants.ZERO);
|
insuranceApplyDataVO.setUseMemberNum(Constants.ZERO);
|
|
List<InsuranceApply> insuranceApplyList = insuranceApplyJoinMapper.selectJoinList(InsuranceApply.class,
|
new MPJLambdaWrapper<InsuranceApply>()
|
.selectAll(InsuranceApply.class)
|
.selectAs(Solutions::getType, InsuranceApply::getSolutionType)
|
.leftJoin(Solutions.class, Solutions::getId, InsuranceApply::getSolutionId)
|
.eq(InsuranceApply::getIsdeleted, Constants.ZERO)
|
.notIn(InsuranceApply::getStatus,
|
Constants.InsuranceApplyStatus.COMPANY_BACK_APPLY_PASS.getKey(),
|
Constants.InsuranceApplyStatus.CLOSE.getKey(),
|
Constants.InsuranceApplyStatus.WTB_RETURN.getKey(),
|
Constants.InsuranceApplyStatus.WTB_CLOSED.getKey()
|
)
|
);
|
|
String monthDate = DateUtil.getFomartDate(new Date(), "yyyy-MM");
|
|
if (CollectionUtils.isNotEmpty(insuranceApplyList)) {
|
//累计有效保单
|
insuranceApplyDataVO.setInsuranceNum(
|
insuranceApplyList.stream().filter(i -> Constants.equalsInteger(i.getStatus(), Constants.InsuranceApplyStatus.UPLOAD_INSURANCE.getKey())
|
|| Constants.equalsInteger(i.getStatus(), Constants.InsuranceApplyStatus.WTB_DONE.getKey())
|
).collect(Collectors.toList()).size()
|
);
|
//本月新增有效保单
|
insuranceApplyDataVO.setMonthAddInsuranceNum(
|
insuranceApplyList.stream().filter(i -> (Constants.equalsInteger(i.getStatus(), Constants.InsuranceApplyStatus.UPLOAD_INSURANCE.getKey())
|
|| Constants.equalsInteger(i.getStatus(), Constants.InsuranceApplyStatus.WTB_DONE.getKey()))
|
&& DateUtil.formatDate(i.getCreateDate(), "yyyy-MM").equals(monthDate)
|
).collect(Collectors.toList()).size()
|
);
|
//在保企业数量
|
List<Integer> useCompanyNum = insuranceApplyList.stream().filter(i -> (Constants.equalsInteger(i.getStatus(), Constants.InsuranceApplyStatus.UPLOAD_INSURANCE.getKey())
|
|| Constants.equalsInteger(i.getStatus(), Constants.InsuranceApplyStatus.WTB_DONE.getKey()))
|
&& i.getStartTime().getTime() <= System.currentTimeMillis() && i.getEndTime().getTime() >= System.currentTimeMillis()
|
).map(i -> i.getCompanyId()).collect(Collectors.toList());
|
insuranceApplyDataVO.setUseCompanyNum(new HashSet<>(useCompanyNum).size());
|
|
//在保保单数量
|
insuranceApplyDataVO.setUseInsuranceNum(
|
insuranceApplyList.stream().filter(i -> (Constants.equalsInteger(i.getStatus(), Constants.InsuranceApplyStatus.UPLOAD_INSURANCE.getKey())
|
|| Constants.equalsInteger(i.getStatus(), Constants.InsuranceApplyStatus.WTB_DONE.getKey()))
|
&& i.getStartTime().getTime() <= System.currentTimeMillis() && i.getEndTime().getTime() >= System.currentTimeMillis()
|
).collect(Collectors.toList()).size()
|
);
|
List<Integer> companyIds = insuranceApplyList.stream().map(i -> i.getCompanyId()).collect(Collectors.toList());
|
if (CollectionUtils.isNotEmpty(companyIds)) {
|
//累计投保企业数量
|
insuranceApplyDataVO.setInsuranceCompanyNum(new HashSet<>(companyIds).size());
|
}
|
Integer monthAddInsuranceCompanyNum = insuranceApplyJoinMapper.selectJoinCount(
|
new MPJLambdaWrapper<InsuranceApply>()
|
.eq(InsuranceApply::getIsdeleted, Constants.ZERO)
|
.notIn(InsuranceApply::getStatus,
|
Constants.InsuranceApplyStatus.COMPANY_BACK_APPLY_PASS.getKey(),
|
Constants.InsuranceApplyStatus.CLOSE.getKey(),
|
Constants.InsuranceApplyStatus.WTB_RETURN.getKey(),
|
Constants.InsuranceApplyStatus.WTB_CLOSED.getKey()
|
)
|
.apply(" company_id in ( select c.id from company c where c.ISDELETED = 0 and DATE_FORMAT(c.CREATE_DATE, '%Y-%m') = DATE_FORMAT(now(), '%Y-%m') ) ")
|
.groupBy(InsuranceApply::getCompanyId)
|
);
|
//本月新增投保企业
|
insuranceApplyDataVO.setMonthAddInsuranceCompanyNum(Objects.nonNull(monthAddInsuranceCompanyNum)?monthAddInsuranceCompanyNum:Constants.ZERO);
|
//直保保单数量
|
insuranceApplyDataVO.setZbInsuranceNum(insuranceApplyList.stream().filter(i -> Constants.equalsInteger(i.getSolutionType(), Constants.ZERO)).collect(Collectors.toList()).size());
|
//委托保保单数量
|
insuranceApplyDataVO.setWtbInsuranceNum(insuranceApplyList.stream().filter(i -> Constants.equalsInteger(i.getSolutionType(), Constants.ONE)).collect(Collectors.toList()).size());
|
}
|
|
//合计总费用
|
insuranceApplyDataVO.setTotalFee(new BigDecimal(applyDetailJoinMapper.selectJoinMap( new MPJLambdaWrapper<ApplyDetail>()
|
.select("ifnull(sum(t.fee),0) as fee")
|
.selectAs(InsuranceApply::getStatus, ApplyDetail::getApplyStatus)
|
.leftJoin(InsuranceApply.class, InsuranceApply::getId, ApplyDetail::getApplyId)
|
.eq(ApplyDetail::getIsdeleted, Constants.ZERO)
|
.eq(InsuranceApply::getIsdeleted, Constants.ZERO)
|
.notIn(InsuranceApply::getStatus,
|
Constants.InsuranceApplyStatus.COMPANY_BACK_APPLY_PASS.getKey(),
|
Constants.InsuranceApplyStatus.CLOSE.getKey(),
|
Constants.InsuranceApplyStatus.WTB_RETURN.getKey(),
|
Constants.InsuranceApplyStatus.WTB_CLOSED.getKey()
|
)
|
).get("fee").toString()));
|
//本月新增费用
|
insuranceApplyDataVO.setMonthAddTotalFee(
|
new BigDecimal(applyDetailJoinMapper.selectJoinMap( new MPJLambdaWrapper<ApplyDetail>()
|
.select("ifnull(sum(t.fee),0) as fee")
|
.leftJoin(InsuranceApply.class, InsuranceApply::getId, ApplyDetail::getApplyId)
|
.eq(ApplyDetail::getIsdeleted, Constants.ZERO)
|
.eq(InsuranceApply::getIsdeleted, Constants.ZERO)
|
.notIn(InsuranceApply::getStatus,
|
Constants.InsuranceApplyStatus.COMPANY_BACK_APPLY_PASS.getKey(),
|
Constants.InsuranceApplyStatus.CLOSE.getKey(),
|
Constants.InsuranceApplyStatus.WTB_RETURN.getKey(),
|
Constants.InsuranceApplyStatus.WTB_CLOSED.getKey()
|
)
|
.apply(" DATE_FORMAT(t.CREATE_DATE, '%Y-%m') = DATE_FORMAT(now(), '%Y-%m') ")
|
).get("fee").toString())
|
|
);
|
|
//累计投保人次
|
insuranceApplyDataVO.setMemberNum(
|
Integer.valueOf(applyDetailJoinMapper.selectJoinMap( new MPJLambdaWrapper<ApplyDetail>()
|
.select("count(distinct t.MEMBER_ID) as memberTimes")
|
.leftJoin(InsuranceApply.class, InsuranceApply::getId, ApplyDetail::getApplyId)
|
.eq(ApplyDetail::getIsdeleted, Constants.ZERO)
|
.eq(InsuranceApply::getIsdeleted, Constants.ZERO)
|
.notIn(InsuranceApply::getStatus,
|
Constants.InsuranceApplyStatus.COMPANY_BACK_APPLY_PASS.getKey(),
|
Constants.InsuranceApplyStatus.CLOSE.getKey(),
|
Constants.InsuranceApplyStatus.WTB_RETURN.getKey(),
|
Constants.InsuranceApplyStatus.WTB_CLOSED.getKey()
|
)
|
).get("memberTimes").toString())
|
);
|
//本月新增投保人次
|
insuranceApplyDataVO.setMonthAddMemberNum(
|
Integer.valueOf(applyDetailJoinMapper.selectJoinMap( new MPJLambdaWrapper<ApplyDetail>()
|
.select("count(distinct t.MEMBER_ID) as memberTimes")
|
.leftJoin(InsuranceApply.class, InsuranceApply::getId, ApplyDetail::getApplyId)
|
.eq(ApplyDetail::getIsdeleted, Constants.ZERO)
|
.eq(InsuranceApply::getIsdeleted, Constants.ZERO)
|
.notIn(InsuranceApply::getStatus,
|
Constants.InsuranceApplyStatus.COMPANY_BACK_APPLY_PASS.getKey(),
|
Constants.InsuranceApplyStatus.CLOSE.getKey(),
|
Constants.InsuranceApplyStatus.WTB_RETURN.getKey(),
|
Constants.InsuranceApplyStatus.WTB_CLOSED.getKey()
|
)
|
.apply(" DATE_FORMAT(t.CREATE_DATE, '%Y-%m') = DATE_FORMAT(now(), '%Y-%m') ")
|
).get("memberTimes").toString())
|
|
);
|
|
|
//当前保障人员
|
insuranceApplyDataVO.setUseMemberNum(
|
|
|
Integer.valueOf(applyDetailJoinMapper.selectJoinMap( new MPJLambdaWrapper<ApplyDetail>()
|
.select("count(distinct t.MEMBER_ID) as memberTimes")
|
.leftJoin(InsuranceApply.class, InsuranceApply::getId, ApplyDetail::getApplyId)
|
.eq(ApplyDetail::getIsdeleted, Constants.ZERO)
|
.eq(InsuranceApply::getIsdeleted, Constants.ZERO)
|
.notIn(InsuranceApply::getStatus,
|
Constants.InsuranceApplyStatus.COMPANY_BACK_APPLY_PASS.getKey(),
|
Constants.InsuranceApplyStatus.CLOSE.getKey(),
|
Constants.InsuranceApplyStatus.WTB_RETURN.getKey(),
|
Constants.InsuranceApplyStatus.WTB_CLOSED.getKey()
|
)
|
.apply(" t.start_time <= now() and t.end_time >= now() ")
|
).get("memberTimes").toString())
|
|
);
|
return insuranceApplyDataVO;
|
|
}
|
|
|
@Override
|
public InsuranceApplyReportDataVO getInsuranceApplyReportDataVO(){
|
InsuranceApplyReportDataVO insuranceApplyReportDataVO = new InsuranceApplyReportDataVO();
|
List<DataListVO> companyTopFeeList = applyDetailJoinMapper.selectJoinList(DataListVO.class, new MPJLambdaWrapper<ApplyDetail>()
|
.select(" t2.name as dataFirst, ROUND(ifnull(sum(t.fee),0),2) as dataSecond ")
|
.leftJoin(InsuranceApply.class, InsuranceApply::getId, ApplyDetail::getApplyId)
|
.leftJoin(Company.class,Company::getId,InsuranceApply::getCompanyId)
|
.eq(ApplyDetail::getIsdeleted, Constants.ZERO)
|
.eq(InsuranceApply::getIsdeleted, Constants.ZERO)
|
.notIn(InsuranceApply::getStatus,
|
Constants.InsuranceApplyStatus.COMPANY_BACK_APPLY_PASS.getKey(),
|
Constants.InsuranceApplyStatus.CLOSE.getKey(),
|
Constants.InsuranceApplyStatus.WTB_RETURN.getKey(),
|
Constants.InsuranceApplyStatus.WTB_CLOSED.getKey()
|
)
|
.groupBy(" t1.company_id,t2.name")
|
.orderByDesc(" sum(t.fee) ")
|
.last(" limit 10")
|
);
|
insuranceApplyReportDataVO.setCompanyTopFeeList(companyTopFeeList);
|
|
|
List<DataListVO> hotSolutionList = insuranceApplyJoinMapper.selectJoinList(DataListVO.class, new MPJLambdaWrapper<InsuranceApply>()
|
.select(" solution_id as dataFirst, count(1) as dataSecond ")
|
.eq(InsuranceApply::getIsdeleted, Constants.ZERO)
|
.notIn(InsuranceApply::getStatus,
|
Constants.InsuranceApplyStatus.COMPANY_BACK_APPLY_PASS.getKey(),
|
Constants.InsuranceApplyStatus.CLOSE.getKey(),
|
Constants.InsuranceApplyStatus.WTB_RETURN.getKey(),
|
Constants.InsuranceApplyStatus.WTB_CLOSED.getKey()
|
)
|
.groupBy(" t.solution_id")
|
.orderByDesc(" count(1) ")
|
.last(" limit 10")
|
);
|
|
if(CollectionUtils.isNotEmpty(hotSolutionList)){
|
List<Solutions> solutionsList = solutionsMapper.selectJoinList(Solutions.class,new MPJLambdaWrapper<Solutions>()
|
.select("t.id, t.NAME , t1.name as solutionBaseName ,t.PRICE,t.TIME_UNIT ")
|
.leftJoin(SolutionsBase.class,SolutionsBase::getId,Solutions::getParentId)
|
.in(Solutions::getId,hotSolutionList.stream().map(i->i.getDataFirst()).collect(Collectors.toList())));
|
if(CollectionUtils.isNotEmpty(solutionsList)){
|
for (DataListVO dataListVO:hotSolutionList) {
|
List<Solutions> solutions = solutionsList.stream().filter(i->Constants.equalsInteger(i.getId(),Integer.valueOf(dataListVO.getDataFirst()))).collect(Collectors.toList());
|
if(CollectionUtils.isNotEmpty(solutions)){
|
dataListVO.setSolutions(solutions.get(Constants.ZERO));
|
}
|
}
|
}
|
insuranceApplyReportDataVO.setHotSolutionList(hotSolutionList);
|
}
|
|
LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
insuranceApplyReportDataVO.setMonthAddReduceList(this.getAddReduceData(loginUserInfo));
|
return insuranceApplyReportDataVO;
|
}
|
|
|
|
@Override
|
public List<DataListVO> getAddReduceData(LoginUserInfo loginUserInfo){
|
List<DataListVO> monthAddReduceList = new ArrayList<>();
|
for (int i = -11; i <= 0 ; i++) {
|
String month = DateUtil.DateToStr(
|
DateUtil.afterDateByType(new Date(),1,i),"yyyy-MM");
|
DataListVO dataListVO = new DataListVO();
|
dataListVO.setDataFirst(month);
|
dataListVO.setDataSecond(
|
applyChangeDetailJoinMapper.selectJoinCount(new MPJLambdaWrapper<ApplyChagneDetail>()
|
.leftJoin(ApplyChange.class,ApplyChange::getId,ApplyChagneDetail::getApplyChangeId)
|
.leftJoin(InsuranceApply.class,InsuranceApply::getId,ApplyChange::getApplyId)
|
.eq(ApplyChagneDetail::getType,Constants.ZERO)
|
.eq(Objects.nonNull(loginUserInfo)&&Constants.equalsInteger(loginUserInfo.getType(),Constants.ONE),InsuranceApply::getCompanyId,loginUserInfo.getCompanyId())
|
.apply(" DATE_FORMAT(t.CREATE_DATE, '%Y-%m') = '"+month+"'")
|
) +""
|
);
|
dataListVO.setDataThird("-"+
|
applyChangeDetailJoinMapper.selectJoinCount(new MPJLambdaWrapper<ApplyChagneDetail>()
|
.leftJoin(ApplyChange.class,ApplyChange::getId,ApplyChagneDetail::getApplyChangeId)
|
.leftJoin(InsuranceApply.class,InsuranceApply::getId,ApplyChange::getApplyId)
|
.eq(ApplyChagneDetail::getType,Constants.ONE)
|
.eq(Objects.nonNull(loginUserInfo)&&Constants.equalsInteger(loginUserInfo.getType(),Constants.ONE)
|
,InsuranceApply::getCompanyId,loginUserInfo.getCompanyId())
|
.apply(" DATE_FORMAT(t.CREATE_DATE, '%Y-%m') = '"+month+"'")
|
)
|
);
|
monthAddReduceList.add(dataListVO);
|
}
|
return monthAddReduceList;
|
}
|
|
|
|
@Override
|
public InsuranceApplyDataVO getInsuranceNum(){
|
List<InsuranceApply> insuranceApplyList = insuranceApplyJoinMapper.selectJoinList(InsuranceApply.class,
|
new MPJLambdaWrapper<InsuranceApply>()
|
.selectAll(InsuranceApply.class)
|
.selectAs(Solutions::getType, InsuranceApply::getSolutionType)
|
.leftJoin(Solutions.class, Solutions::getId, InsuranceApply::getSolutionId)
|
.eq(InsuranceApply::getIsdeleted, Constants.ZERO)
|
.notIn(InsuranceApply::getStatus,
|
Constants.InsuranceApplyStatus.COMPANY_BACK_APPLY_PASS.getKey(),
|
Constants.InsuranceApplyStatus.CLOSE.getKey(),
|
Constants.InsuranceApplyStatus.WTB_RETURN.getKey(),
|
Constants.InsuranceApplyStatus.WTB_CLOSED.getKey()
|
)
|
);
|
InsuranceApplyDataVO insuranceApplyDataVO = new InsuranceApplyDataVO();
|
//直保保单数量
|
insuranceApplyDataVO.setZbInsuranceNum(insuranceApplyList.stream().filter(i -> Constants.equalsInteger(i.getSolutionType(), Constants.ZERO)).collect(Collectors.toList()).size());
|
//委托保保单数量
|
insuranceApplyDataVO.setWtbInsuranceNum(insuranceApplyList.stream().filter(i -> Constants.equalsInteger(i.getSolutionType(), Constants.ONE)).collect(Collectors.toList()).size());
|
return insuranceApplyDataVO;
|
|
}
|
|
|
@Override
|
public List<DataListVO> getSettleClaimsMoney(){
|
List<SettleClaims> settleClaimsList = settleClaimsMapper.selectList(new QueryWrapper<SettleClaims>().lambda()
|
.eq(SettleClaims::getStatus,Constants.SettleClaimsStatus.CLOSE_CASE.getKey())
|
.eq(SettleClaims::getIsdeleted,Constants.ZERO));
|
List<DataListVO> monthTotalMoneyDataList = new ArrayList<>();
|
for (int i = -11; i <= 0 ; i++) {
|
String month = DateUtil.DateToStr(
|
DateUtil.afterDateByType(new Date(),1,i),"yyyy-MM");
|
DataListVO dataListVO = new DataListVO();
|
dataListVO.setDataFirst(month);
|
if (CollectionUtils.isNotEmpty(settleClaimsList)) {
|
BigDecimal hpAccount = settleClaimsList.stream().filter(j->DateUtil.DateToStr(j.getCreateDate(),"yyyy-MM").equals(month))
|
.map(j->j.getHpAccount().add(j.getHpOtherAccount())).reduce(BigDecimal.ZERO,BigDecimal::add);
|
dataListVO.setDataSecond(hpAccount.compareTo(BigDecimal.ZERO)>Constants.ZERO?
|
hpAccount.divide(new BigDecimal("10000"),2,BigDecimal.ROUND_HALF_UP).toString():"0"
|
);
|
}else{
|
dataListVO.setDataSecond("0");
|
}
|
|
monthTotalMoneyDataList.add(dataListVO);
|
}
|
return monthTotalMoneyDataList;
|
}
|
|
@Override
|
public List<DataListVO> getInsuranceApplyStatusData(LoginUserInfo loginUserInfo){
|
List<DataListVO> dataListVOList = new ArrayList<>();
|
//待生效
|
DataListVO dataListVOA = new DataListVO();
|
dataListVOA.setDataFirst("待生效");
|
dataListVOA.setDataSecond(
|
insuranceApplyMapper.selectCount(new QueryWrapper<InsuranceApply>().lambda().eq(InsuranceApply::getIsdeleted,Constants.ZERO)
|
.in(InsuranceApply::getStatus,Constants.InsuranceApplyStatus.UPLOAD_INSURANCE.getKey(),Constants.InsuranceApplyStatus.WTB_DONE.getKey())
|
.eq(InsuranceApply::getCompanyId,loginUserInfo.getCompanyId())
|
.apply(" start_time > now() ")
|
).toString()
|
);
|
dataListVOList.add(dataListVOA);
|
|
//保障中
|
DataListVO dataListVOB = new DataListVO();
|
dataListVOB.setDataFirst("保障中");
|
dataListVOB.setDataSecond(
|
insuranceApplyMapper.selectCount(new QueryWrapper<InsuranceApply>().lambda().eq(InsuranceApply::getIsdeleted,Constants.ZERO)
|
.in(InsuranceApply::getStatus,Constants.InsuranceApplyStatus.UPLOAD_INSURANCE.getKey(),Constants.InsuranceApplyStatus.WTB_DONE.getKey())
|
.eq(InsuranceApply::getCompanyId,loginUserInfo.getCompanyId())
|
.apply(" start_time <= now() and end_time >= now()")
|
).toString()
|
);
|
|
dataListVOList.add(dataListVOB);
|
|
//已过期
|
DataListVO dataListVOC = new DataListVO();
|
dataListVOC.setDataFirst("已过期");
|
|
dataListVOC.setDataSecond(
|
insuranceApplyMapper.selectCount(new QueryWrapper<InsuranceApply>().lambda().eq(InsuranceApply::getIsdeleted,Constants.ZERO)
|
.in(InsuranceApply::getStatus,Constants.InsuranceApplyStatus.UPLOAD_INSURANCE.getKey(),Constants.InsuranceApplyStatus.WTB_DONE.getKey())
|
.eq(InsuranceApply::getCompanyId,loginUserInfo.getCompanyId())
|
.apply(" end_time < now()")
|
).toString()
|
);
|
dataListVOList.add(dataListVOC);
|
return dataListVOList;
|
}
|
|
|
|
|
@Override
|
public List<DataListVO> getInsuranceMemberData(LoginUserInfo loginUserInfo){
|
List<DataListVO> dataListVOList = new ArrayList<>();
|
//待生效
|
DataListVO dataListVOA = new DataListVO();
|
dataListVOA.setDataFirst("不在保");
|
dataListVOA.setDataSecond(
|
applyDetailJoinMapper.selectJoinCount( new MPJLambdaWrapper<ApplyDetail>()
|
.leftJoin(InsuranceApply.class, InsuranceApply::getId, ApplyDetail::getApplyId)
|
.eq(ApplyDetail::getIsdeleted, Constants.ZERO)
|
.eq(InsuranceApply::getIsdeleted, Constants.ZERO)
|
.in(InsuranceApply::getStatus,Constants.InsuranceApplyStatus.UPLOAD_INSURANCE.getKey(),Constants.InsuranceApplyStatus.WTB_DONE.getKey())
|
.eq(InsuranceApply::getCompanyId,loginUserInfo.getCompanyId())
|
.apply(" t.END_TIME < now() ")).toString()
|
|
);
|
dataListVOList.add(dataListVOA);
|
|
//保障中
|
DataListVO dataListVOB = new DataListVO();
|
dataListVOB.setDataFirst("保障中");
|
dataListVOB.setDataSecond(
|
applyDetailJoinMapper.selectJoinCount( new MPJLambdaWrapper<ApplyDetail>()
|
.leftJoin(InsuranceApply.class, InsuranceApply::getId, ApplyDetail::getApplyId)
|
.eq(ApplyDetail::getIsdeleted, Constants.ZERO)
|
.eq(InsuranceApply::getIsdeleted, Constants.ZERO)
|
.in(InsuranceApply::getStatus,Constants.InsuranceApplyStatus.UPLOAD_INSURANCE.getKey(),Constants.InsuranceApplyStatus.WTB_DONE.getKey())
|
.eq(InsuranceApply::getCompanyId,loginUserInfo.getCompanyId())
|
.apply(" t.END_TIME >= now() ")).toString()
|
);
|
|
dataListVOList.add(dataListVOB);
|
return dataListVOList;
|
}
|
|
|
}
|