jiangping
2024-01-30 a9ca0823ab8f33ca85abebcf6ec4a8da235adb49
server/service/src/main/java/com/doumee/service/business/impl/SettleClaimsServiceImpl.java
@@ -1,5 +1,8 @@
package com.doumee.service.business.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.api.R;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.LoginUserInfo;
@@ -22,13 +25,20 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.core.util.CollectionUtils;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.*;
import java.util.stream.Collectors;
/**
@@ -44,6 +54,8 @@
    @Autowired
    private SettleClaimsLogMapper settleClaimsLogMapper;
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
    @Autowired
    private MultifileMapper multifileMapper;
@@ -54,6 +66,247 @@
    @Autowired
    private SettleClaimsLogJoinMapper settleClaimsLogJoinMapper;
    /**
     * 退回申请
     * @param param
     * @return
     */
    @Override
    public      Integer back(SettleClaims  param){
        if(param.getId() == null
                ||StringUtils.isBlank( param.getCheckInfo()) ){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        SettleClaims model = settleClaimsMapper.selectById(param.getId());
        if(model == null ||!Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        if((Constants.equalsInteger(model.getStatus(),Constants.SettleClaimsStatus.FINISH_ACCEPTANCE.getKey())
                ||Constants.equalsInteger(model.getStatus(),Constants.SettleClaimsStatus.RETURN_ACCEPTANCE.getKey()))){
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该申请当前不支持该操作~");
        }
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        SettleClaims update = new SettleClaims();
        update.setEditDate(new Date());
        update.setEditor(user.getId());
        update.setCheckDate(update.getEditDate());
        update.setCheckInfo(param.getCheckInfo());
        update.setCheckUserId(user.getId());
        update.setId(model.getId());
        update.setStatus(Constants.SettleClaimsStatus.RETURN_ACCEPTANCE.getKey());
        settleClaimsMapper.updateById(update);
        Constants.SettleClaimsLogType applyLogType = Constants.SettleClaimsLogType.PLATFORM_RETURN;
        String info =applyLogType.getInfo();
        info = info.replace("${param}", update.getCheckInfo());
        SettleClaimsLog log = new SettleClaimsLog(update,applyLogType.getName(), info,update.getId(),applyLogType.getKey(), JSONObject.toJSONString(model), JSONObject.toJSONString(update));
        settleClaimsLogMapper.insert(log);
        return  1;
    }
    /**
     * 资料确认
     * @param param
     * @return
     */
    @Override
    public      Integer confirm(SettleClaims  param){
        if(param.getId() == null
                ||StringUtils.isBlank( param.getCheckInfo()) ){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        SettleClaims model = settleClaimsMapper.selectById(param.getId());
        if(model == null ||!Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        if((Constants.equalsInteger(model.getStatus(),Constants.SettleClaimsStatus.FINISH_ACCEPTANCE.getKey())
                ||Constants.equalsInteger(model.getStatus(),Constants.SettleClaimsStatus.RETURN_ACCEPTANCE.getKey()))){
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该申请当前不支持该操作~");
        }
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        SettleClaims update = new SettleClaims();
        update.setEditDate(new Date());
        update.setEditor(user.getId());
        update.setCheckDate(update.getEditDate());
        update.setCheckInfo(param.getCheckInfo());
        update.setCheckUserId(user.getId());
        update.setId(model.getId());
        update.setStatus(Constants.SettleClaimsStatus.CONFIRM_INFORMATION.getKey());
        settleClaimsMapper.updateById(update);
        Constants.SettleClaimsLogType applyLogType = Constants.SettleClaimsLogType.PLATFORM_CONFIRM_INFORMATION;
        String info =applyLogType.getInfo();
        info = info.replace("${param}", update.getCheckInfo());
        SettleClaimsLog log = new SettleClaimsLog(update,applyLogType.getName(), info,update.getId(),applyLogType.getKey(), JSONObject.toJSONString(model), JSONObject.toJSONString(update));
        settleClaimsLogMapper.insert(log);
        return  1;
    }
    /**
     * 理赔备注标签
     * @param param
     * @return
     */
    @Override
    public       Integer remark(SettleClaims param){
        if(param.getId() == null
                ||StringUtils.isBlank( param.getCheckInfo()) ){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        SettleClaims model = settleClaimsMapper.selectById(param.getId());
        if(model == null ||!Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        if((Constants.equalsInteger(model.getStatus(),Constants.SettleClaimsStatus.FINISH_ACCEPTANCE.getKey())
                ||Constants.equalsInteger(model.getStatus(),Constants.SettleClaimsStatus.RETURN_ACCEPTANCE.getKey()))){
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该申请当前不支持该操作~");
        }
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        SettleClaims update = new SettleClaims();
        update.setEditDate(new Date());
        update.setEditor(user.getId());
        update.setCheckDate(update.getEditDate());
        update.setCheckInfo(param.getCheckInfo());
        update.setCheckUserId(user.getId());
        update.setId(model.getId());
        settleClaimsMapper.updateById(update);
        Constants.SettleClaimsLogType applyLogType = Constants.SettleClaimsLogType.PLATFORM_REMARK;
        String info =applyLogType.getInfo();
        info = info.replace("${param}", update.getCheckInfo());
        SettleClaimsLog log = new SettleClaimsLog(update,applyLogType.getName(), info,update.getId(),applyLogType.getKey(), JSONObject.toJSONString(model), JSONObject.toJSONString(update));
        settleClaimsLogMapper.insert(log);
        return  1;
    }
    /**
     * 理赔结案提交
     * @param param
     * @return
     */
    @Override
    public    Integer doneCommit(SettleClaims param){
        if(param.getId() == null
                ||StringUtils.isBlank( param.getCheckInfo()) ){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        SettleClaims model = settleClaimsMapper.selectById(param.getId());
        if(model == null ||!Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        //受理中和已确认资料可以进行理赔处理
        if((Constants.equalsInteger(model.getStatus(),Constants.SettleClaimsStatus.FINISH_ACCEPTANCE.getKey())
              ||Constants.equalsInteger(model.getStatus(),Constants.SettleClaimsStatus.RETURN_ACCEPTANCE.getKey()))){
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该申请当前不支持该操作~");
        }
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        SettleClaims update = new SettleClaims();
        update.setEditDate(new Date());
        update.setEditor(user.getId());
        update.setCheckDate(update.getEditDate());
        update.setCheckInfo(param.getCheckInfo());
        update.setCheckUserId(user.getId());
        update.setStatus(Constants.SettleClaimsStatus.FINISH_ACCEPTANCE.getKey());
        update.setId(model.getId());
        update.setYlClaimAccount(Constants.formatBigdecimal(param.getYlClaimAccount()));
        update.setSwClaimAccount(Constants.formatBigdecimal(param.getSwClaimAccount()));
        update.setWgClaimAccount(Constants.formatBigdecimal(param.getWgClaimAccount()));
        update.setScClaimAccount(Constants.formatBigdecimal(param.getScClaimAccount()));
        update.setClaimAccount(update.getYlClaimAccount().add(update.getSwClaimAccount()).add(update.getScClaimAccount()).add(update.getWgClaimAccount()));
        settleClaimsMapper.updateById(update);
        Constants.SettleClaimsLogType applyLogType = Constants.SettleClaimsLogType.PLATFORM_FINISH;
        String info =applyLogType.getInfo();
        info = info.replace("${param}", update.getCheckInfo());
        SettleClaimsLog log = new SettleClaimsLog(update,applyLogType.getName(), info,update.getId(),applyLogType.getKey(), JSONObject.toJSONString(model), JSONObject.toJSONString(update));
        settleClaimsLogMapper.insert(log);
        return  1;
    }
    /**
     * 理赔处理
     * @param param
     * @return
     */
    @Override
    public Integer dealBiz(SettleClaims  param){
        if(param.getId() == null
                ||StringUtils.isBlank( param.getCheckInfo()) ){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        SettleClaims model = settleClaimsMapper.selectById(param.getId());
        if(model == null ||!Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        //受理中和已确认资料可以进行理赔处理
        if( Constants.equalsInteger(model.getStatus(),Constants.SettleClaimsStatus.RETURN_ACCEPTANCE.getKey())
              ||Constants.equalsInteger(model.getStatus(),Constants.SettleClaimsStatus.FINISH_ACCEPTANCE.getKey())){
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该申请当前不支持该操作~");
        }
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        SettleClaims update = new SettleClaims();
        update.setEditDate(new Date());
        update.setEditor(user.getId());
        update.setCheckDate(update.getEditDate());
        update.setCheckInfo(param.getCheckInfo());
        update.setCheckUserId(user.getId());
        update.setId(model.getId());
        settleClaimsMapper.updateById(update);
        Constants.SettleClaimsLogType applyLogType = Constants.SettleClaimsLogType.PLATFORM_LP_DEAL;
        String info =applyLogType.getInfo();
        info = info.replace("${param}", update.getCheckInfo());
        SettleClaimsLog log = new SettleClaimsLog(update,applyLogType.getName(), info,update.getId(),applyLogType.getKey(), JSONObject.toJSONString(model), JSONObject.toJSONString(update));
        settleClaimsLogMapper.insert(log);
        return  1;
    }
    /**
     * 添加备案号
     * @param param
     * @return
     */
    @Override
    public Integer addCode(SettleClaims param){
        if(param.getId() == null
                ||StringUtils.isBlank( param.getCode()) ){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        SettleClaims model = settleClaimsMapper.selectById(param.getId());
        if(model == null ||!Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        if(!Constants.equalsInteger(model.getStatus(),Constants.SettleClaimsStatus.WAIT_ACCEPTANCE.getKey())){
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该申请当前不支持该操作~");
        }
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        SettleClaims update = new SettleClaims();
        update.setEditDate(new Date());
        update.setEditor(user.getId());
        update.setCheckDate(update.getEditDate());
        update.setCheckInfo("添加备案号");
        update.setCheckUserId(user.getId());
        update.setId(model.getId());
        update.setStatus(Constants.SettleClaimsStatus.DEAL_ING.getKey());
        update.setCode(param.getCode());
        settleClaimsMapper.updateById(update);
        Constants.SettleClaimsLogType applyLogType = Constants.SettleClaimsLogType.PLATFORM_ADDCODE;
        SettleClaimsLog log = new SettleClaimsLog(update,applyLogType.getName(), null,update.getId(),applyLogType.getKey(), JSONObject.toJSONString(model), JSONObject.toJSONString(update));
        settleClaimsLogMapper.insert(log);
        return  1;
    }
    @Override
    public Integer create(SettleClaims settleClaims) {
        LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
@@ -113,6 +366,60 @@
        return settleClaims.getId();
    }
    @Override
    public  void exportFiles(Integer id, HttpServletResponse response) {
        try {
            SettleClaims model = settleClaimsMapper.selectById(id);
            if(model == null){
                throw  new BusinessException(ResponseStatus.DATA_EMPTY);
            }
            LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
            SettleClaims update = new SettleClaims();
            update.setEditDate(new Date());
            update.setEditor(loginUserInfo.getId());
            Constants.SettleClaimsLogType applyLogType = Constants.SettleClaimsLogType.PLATFORM_DOWNLOAD;
            String info =applyLogType.getInfo();
            SettleClaimsLog log = new SettleClaimsLog(update,applyLogType.getName(), info,update.getId(),applyLogType.getKey(), JSONObject.toJSONString(model), JSONObject.toJSONString(update));
            settleClaimsLogMapper.insert(log);
            List<File> fileList = new ArrayList<>();
            List<Multifile> multifileList = multifileMapper.selectList(new QueryWrapper<Multifile>().lambda()
                    .eq(Multifile::getObjId,id)
                    .isNotNull(Multifile::getFileurl)
                    .in(Multifile::getObjType, Arrays.asList(new Integer[]{
                            Constants.MultiFile.LP_YGGX_FILE.getKey(),
                            Constants.MultiFile.LP_MZCL_FILE.getKey(),
                            Constants.MultiFile.LP_ZYCL_FILE.getKey(),
                            Constants.MultiFile.LP_SCZL_FILE.getKey(),
                            Constants.MultiFile.LP_JACL_FILE.getKey(),
                    }))
            );
            if(multifileList== null || multifileList.size() == 0){
                throw  new BusinessException(ResponseStatus.DATA_EMPTY);
            }
            String path = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+systemDictDataBiz.queryByCode(Constants.OSS,Constants.SETTLE_FILE).getCode();
            for(Multifile l : multifileList){
                File f = Constants.getFileByNetFile(path + l.getFileurl(),StringUtils.defaultString(l.getName(),"未命名"));
                if(f !=null && f.isFile()){
                    fileList.add(f);
                }
            }
            if(fileList == null || fileList.size() == 0){
                throw  new BusinessException(ResponseStatus.DATA_EMPTY);
            }
            String fileName =  model.getInformantName() +"理赔资料下_"+System.currentTimeMillis()+".zip" ;
            String encodeFileName = URLEncoder.encode(fileName);
            response.setHeader("Content-Disposition","attachment;filename=" + encodeFileName);
            response.setContentType("application/octet-stream");
            response.setHeader("eva-opera-type", "download");
            response.setHeader("eva-download-filename", encodeFileName);
            Constants.packFilesToZip(fileList,response.getOutputStream());
        } catch (IOException e) {
            throw new BusinessException(ResponseStatus.EXPORT_EXCEL_ERROR, e);
        }
    }
    @Override
    public SettleClaims getSettleClaimsDetail(Integer id){