111
k94314517
2024-01-19 3de94f9fd2e4354eec6e53eb1a6e466b20c896a7
server/service/src/main/java/com/doumee/service/business/impl/InsuranceApplyServiceImpl.java
@@ -9,7 +9,9 @@
import com.doumee.core.utils.DateUtil;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.*;
import com.doumee.dao.business.dto.InsuranceApplyOptDTO;
import com.doumee.dao.business.dto.InsuranceApplyQueryDTO;
import com.doumee.dao.business.join.ApplyLogJoinMapper;
import com.doumee.dao.business.join.InsuranceApplyJoinMapper;
import com.doumee.dao.business.model.*;
import com.doumee.dao.system.model.SystemUser;
@@ -21,6 +23,7 @@
import com.github.xiaoymin.knife4j.core.util.CollectionUtils;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import io.swagger.models.auth.In;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -49,6 +52,9 @@
    @Autowired
    private ApplyLogMapper applyLogMapper;
    @Autowired
    private ApplyLogJoinMapper applyLogJoinMapper;
    @Autowired
    private SolutionsMapper solutionsMapper;
@@ -148,9 +154,26 @@
            }
            applyDetailMapper.insert(applyDetail);
        }
        //存储日志数据
        this.saveApplyLog(insuranceApply,insuranceApplyStatus,null);
        return insuranceApply.getId();
    }
    public void saveApplyLog(InsuranceApply insuranceApply,Constants.InsuranceApplyStatus insuranceApplyStatus,String content){
        LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        ApplyLog applyLog = new ApplyLog();
        applyLog.setCreateDate(new Date());
        applyLog.setCreator(loginUserInfo.getId());
        applyLog.setIsdeleted(Constants.ZERO);
        applyLog.setApplyId(insuranceApply.getId());
        applyLog.setTitle(insuranceApplyStatus.getName());
        applyLog.setContent(content);
        applyLog.setObjType(insuranceApplyStatus.getKey());
        applyLog.setObjId(Integer.toString(insuranceApply.getId()));
        applyLog.setStatus(insuranceApply.getStatus());
        applyLogMapper.insert(applyLog);
    }
    public BigDecimal countDetailFee(Solutions solutions ,Date startDate,Date endDate){
@@ -253,6 +276,13 @@
        if (pageWrap.getModel().getStartTimeE() != null) {
            queryWrapper.le(InsuranceApply::getStartTime, Utils.Date.getEnd(pageWrap.getModel().getStartTimeE()));
        }
        if (pageWrap.getModel().getCreateTimeS() != null) {
            queryWrapper.ge(InsuranceApply::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateTimeS()));
        }
        if (pageWrap.getModel().getCreateTimeE() != null) {
            queryWrapper.le(InsuranceApply::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateTimeE()));
        }
        if (pageWrap.getModel().getCode() != null) {
            queryWrapper.eq(InsuranceApply::getCode, pageWrap.getModel().getCode());
        }
@@ -277,4 +307,71 @@
        QueryWrapper<InsuranceApply> wrapper = new QueryWrapper<>(insuranceApply);
        return insuranceApplyMapper.selectCount(wrapper);
    }
    @Override
    public InsuranceApply findDetail(Integer id) {
        InsuranceApply insuranceApply = insuranceApplyMapper.selectById(id);
        if(Objects.isNull(insuranceApply)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        insuranceApply.setInsureNum(applyDetailMapper.selectCount(new QueryWrapper<ApplyDetail>().lambda().eq(ApplyDetail::getApplyId,insuranceApply.getId())
                .eq(ApplyDetail::getIsdeleted,Constants.ZERO)));
        //查询操作记录
        List<ApplyLog> applyLogList = applyLogJoinMapper.selectJoinList(ApplyLog.class,
                new MPJLambdaWrapper<ApplyLog>()
                        .selectAll(ApplyLog.class)
                        .selectAs(Member::getName,ApplyLog::getCreatorName)
                        .selectAs(Company::getName,ApplyLog::getCompanyName)
                        .leftJoin(Member.class,Member::getId,ApplyLog::getCreator)
                        .leftJoin(Company.class,Company::getId,Member::getCompanyId)
                        .eq(ApplyLog::getApplyId,insuranceApply.getId())
                        .orderByAsc(ApplyLog::getCreateDate)
        );
        insuranceApply.setApplyLogList(applyLogList);
        return insuranceApply;
    }
    @Override
    @Transactional(rollbackFor = {Exception.class,BusinessException.class})
    public void applyReturn(InsuranceApplyOptDTO insuranceApplyOptDTO){
        if(Objects.isNull(insuranceApplyOptDTO)
            ||Objects.isNull(insuranceApplyOptDTO.getApplyId())
            ||StringUtils.isBlank(insuranceApplyOptDTO.getOptIllustration())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(loginUserInfo.getType().equals(Constants.ZERO)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"非企业端用户无法进行该操作");
        }
        InsuranceApply insuranceApply = insuranceApplyMapper.selectById(insuranceApplyOptDTO.getApplyId());
        if(Objects.isNull(insuranceApply)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        if(insuranceApply.getIsdeleted().equals(Constants.ONE)){
            throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"数据已删除,无法进行该操作");
        }
        if(insuranceApply.getStatus().equals(Constants.InsuranceApplyStatus.COMPANY_APPLY_RETURN.getKey())){
            throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"退回申请中,请勿重复操作");
        }
        if(!(insuranceApply.getStatus().equals(Constants.InsuranceApplyStatus.UPLOAD.getKey())
            ||insuranceApply.getStatus().equals(Constants.InsuranceApplyStatus.WAIT_SIGNATURE.getKey())
            ||insuranceApply.getStatus().equals(Constants.InsuranceApplyStatus.SIGNATURE.getKey()))){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"数据状态非可申请退回!");
        }
        Constants.InsuranceApplyStatus insuranceApplyStatus = Constants.InsuranceApplyStatus.COMPANY_APPLY_RETURN;
        insuranceApply.setStatus(insuranceApplyStatus.getKey());
        insuranceApply.setCheckDate(new Date());
        insuranceApply.setCheckInfo(insuranceApplyOptDTO.getOptIllustration());
        insuranceApply.setCheckUserId(loginUserInfo.getId());
        insuranceApplyMapper.updateById(insuranceApply);
        //存储日志数据
        this.saveApplyLog(insuranceApply,insuranceApplyStatus,null);
    }
}