k94314517
2024-11-23 b693c55ed17cc94efb45ea595341d443bfd4259d
server/service/src/main/java/com/doumee/service/business/impl/InsuranceServiceImpl.java
@@ -1,5 +1,6 @@
package com.doumee.service.business.impl;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.LoginUserInfo;
@@ -10,6 +11,7 @@
import com.doumee.dao.business.InsuranceMapper;
import com.doumee.dao.business.WorktypeMapper;
import com.doumee.dao.business.model.Insurance;
import com.doumee.dao.business.model.Solutions;
import com.doumee.dao.business.model.Worktype;
import com.doumee.dao.system.model.SystemUser;
import com.doumee.service.business.InsuranceService;
@@ -25,10 +27,8 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;
/**
 * 保险公司信息表Service实现
@@ -42,6 +42,8 @@
    private InsuranceMapper insuranceMapper;
    @Autowired
    private WorktypeMapper worktypeMapper;
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
    @Override
    @Transactional
@@ -49,6 +51,13 @@
        LoginUserInfo user= (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
        initCreateParam(insurance);//工种数据有效性检验,去除空白行数据
        if(insuranceMapper.selectCount(new QueryWrapper<Insurance>().lambda().eq(Insurance::getName,insurance.getName())
                .eq(Insurance::getIsdeleted,Constants.ZERO)
                .eq(Insurance::getDataType,Constants.ZERO)
        )>Constants.ZERO){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"保险公司名称已存在");
        }
        insurance.setIsdeleted(Constants.ZERO);
        insurance.setCreator(user.getId());
@@ -71,7 +80,23 @@
        return insurance.getId();
    }
    private void dealWorkTypeData(Insurance insurance, Insurance newModel, List<Worktype> worktypeList,boolean isNew) {
       int num=0;
        List<String> workTypeName = worktypeList.stream().map(m->m.getName()).collect(Collectors.toList());
        Set<String> set = new HashSet<>(workTypeName);
        if(workTypeName.size() != set.size()){
            throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"对不起,工种录入数据存在相同数据!");
        }
        for(Worktype w : worktypeList) {
            if(!isNew){
                //查询保险公司下是否已存在该工种
                if(worktypeMapper.selectCount(new QueryWrapper<Worktype>().lambda().eq(Worktype::getInsuranceId,insurance.getId())
                        .eq(Worktype::getIsdeleted,Constants.ZERO)
                        .eq(Worktype::getDataType,Constants.ZERO)
                        .eq(Worktype::getName,w.getName())
                )>Constants.ZERO){
                    throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"当前保险公司下存在【"+w.getName()+"】该工种信息");
                }
            }
            //基础版本
            w.setInsuranceId(insurance.getId());
            w.setIsdeleted(Constants.ZERO);
@@ -80,15 +105,18 @@
            w.setDataType(insurance.getDataType());
            w.setStatus(Constants.ZERO);
            w.setVersion(insurance.getVersion());
            w.setSortnum(num++);
            worktypeMapper.insert(w);
            //历史版本的工种信息
            Worktype newType = new Worktype();
            BeanUtils.copyProperties(w, newType);
            newType.setInsuranceId(newModel.getId());
            newType.setBaseId(w.getId());
            newType.setDataType(Constants.ONE);
            newType.setDataType(Constants.TWO);
            newType.setVersion(newModel.getVersion());
            w.setSortnum(num++);
            worktypeMapper.insert(newType);
        }
    }
@@ -107,6 +135,15 @@
        }
        if(worktypeList.size()==0){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,工种不能为空!");
        }
        if(StringUtils.isNotBlank(insurance.getEnglishName()) && insurance.getEnglishName().length()>100){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,英文名超长!");
        }
        if(StringUtils.isNotBlank(insurance.getLinkName()) && insurance.getLinkName().length()>10){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,联系人名称超长!");
        }
        if(StringUtils.isNotBlank(insurance.getLinkPhone()) && insurance.getLinkPhone().length()!=11){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,请输入正确的手机号!");
        }
        insurance.setWorktypeList(worktypeList);
    }
@@ -159,7 +196,6 @@
    @Override
    public void updateById(Insurance insurance) {
        LoginUserInfo user= (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
        Insurance model = findById(insurance.getId());
        if(model == null  || !Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)
                || !Constants.equalsInteger(model.getDataType(),Constants.ZERO)){
@@ -167,7 +203,15 @@
        }
        //数据有效性校验
        initCreateParam(insurance);
        if(insuranceMapper.selectCount(new QueryWrapper<Insurance>().lambda().eq(Insurance::getName,insurance.getName())
                .eq(Insurance::getIsdeleted,Constants.ZERO)
                .eq(Insurance::getDataType,Constants.ZERO)
                .ne(Insurance::getId,insurance.getId())
        )>Constants.ZERO){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"保险公司名称已存在");
        }
        LoginUserInfo user= (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
        Insurance updateModel = new Insurance();
        updateModel.setEditor(user.getId());
        updateModel.setName(insurance.getName());
@@ -176,6 +220,13 @@
        updateModel.setEditDate(new Date());
        updateModel.setRemark(insurance.getRemark());
        updateModel.setSortnum(insurance.getSortnum());
        updateModel.setLogo(insurance.getLogo());
        updateModel.setEnglishName(insurance.getEnglishName());
        updateModel.setLinkName(insurance.getLinkName());
        updateModel.setLinkPhone(insurance.getLinkPhone());
        updateModel.setPolicy(insurance.getPolicy());
        updateModel.setAgreement(insurance.getAgreement());
        updateModel.setClaimsInformation(insurance.getClaimsInformation());
        insuranceMapper.updateById(updateModel);
        //如果修改,则产生一个新的历史版本 ~
@@ -184,8 +235,16 @@
        newModel.setId(null);
        newModel.setVersion(updateModel.getVersion());
        newModel.setCreateDate(new Date());
        newModel.setName(updateModel.getName());
        newModel.setBaseId(insurance.getId());
        newModel.setDataType(Constants.TWO);
        newModel.setLogo(insurance.getLogo());
        newModel.setEnglishName(insurance.getEnglishName());
        newModel.setLinkName(insurance.getLinkName());
        newModel.setLinkPhone(insurance.getLinkPhone());
        newModel.setPolicy(insurance.getPolicy());
        newModel.setAgreement(insurance.getAgreement());
        newModel.setClaimsInformation(insurance.getClaimsInformation());
        insuranceMapper.insert(newModel);
        //删除所有工种数据
@@ -197,8 +256,16 @@
                .lambda()
                .eq(Insurance::getBaseId,insurance.getId())
                .eq(Insurance::getDataType,Constants.TWO)
                .ne(Insurance::getId,newModel.getId())
                .set(Insurance::getDataType,Constants.ONE)
        );
        worktypeMapper.update(null,new UpdateWrapper<Worktype>()
                .lambda()
                .eq(Worktype::getBaseId,insurance.getId())
                .eq(Worktype::getDataType,Constants.TWO)
                .set(Worktype::getDataType,Constants.ONE)
        );
        //处理工作信息,新增最新的,同时产生历史版本
        dealWorkTypeData(updateModel,newModel,insurance.getWorktypeList(),false);
    }
@@ -241,7 +308,16 @@
    @Override
    public Insurance findById(Integer id) {
        return insuranceMapper.selectById(id);
        Insurance model = insuranceMapper.selectById(id);
        if(model == null  || !Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY );
        }
        List<Worktype> worktypeList = worktypeMapper.selectList(new QueryWrapper<Worktype>().lambda()
                .eq(Worktype::getInsuranceId,id)
                .eq(Worktype::getIsdeleted,Constants.ZERO)
                .orderByAsc(Worktype::getSortnum));
        model.setWorktypeList(worktypeList);
        return model;
    }
    @Override
@@ -285,7 +361,7 @@
            queryWrapper.lambda().eq(Insurance::getIsdeleted, pageWrap.getModel().getIsdeleted());
        }
        if (pageWrap.getModel().getName() != null) {
            queryWrapper.lambda().eq(Insurance::getName, pageWrap.getModel().getName());
            queryWrapper.lambda().like(Insurance::getName, pageWrap.getModel().getName());
        }
        if (pageWrap.getModel().getRemark() != null) {
            queryWrapper.lambda().eq(Insurance::getRemark, pageWrap.getModel().getRemark());
@@ -305,16 +381,19 @@
        if (pageWrap.getModel().getBaseId() != null) {
            queryWrapper.lambda().eq(Insurance::getBaseId, pageWrap.getModel().getBaseId());
        }
 /*       for(PageWrap.SortData sortData: pageWrap.getSorts()) {
            if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
                queryWrapper.orderByDesc(sortData.getProperty());
            } else {
                queryWrapper.orderByAsc(sortData.getProperty());
            }
        }*/
        queryWrapper.lambda().orderByAsc(Insurance::getSortnum);
        return PageData.from(insuranceMapper.selectPage(page, queryWrapper));
        PageData<Insurance> pageData = PageData.from(insuranceMapper.selectPage(page, queryWrapper));
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(pageData.getRecords())){
            String path = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()
                    +systemDictDataBiz.queryByCode(Constants.OSS,Constants.INSURANCE).getCode();
            for (Insurance insurance:pageData.getRecords()) {
                if (StringUtils.isNotBlank(insurance.getLogo())) {
                    insurance.setLogoFullUrl(path + insurance.getLogo() );
                }
            }
        }
        return pageData;
    }
    @Override