111
k94314517
2024-03-12 f96ade1a353653871f6ecc38e2056f836f2dfe5e
server/service/src/main/java/com/doumee/service/business/impl/SolutionsServiceImpl.java
@@ -7,13 +7,11 @@
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.InsuranceMapper;
import com.doumee.dao.business.SolutionWorktypeMapper;
import com.doumee.dao.business.SolutionsMapper;
import com.doumee.dao.business.WorktypeMapper;
import com.doumee.dao.business.*;
import com.doumee.dao.business.join.SolutionWorktypeJoinMapper;
import com.doumee.dao.business.join.SolutionsJoinMapper;
import com.doumee.dao.business.model.*;
import com.doumee.service.business.CompanyService;
import com.doumee.service.business.SolutionsService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@@ -25,6 +23,7 @@
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
@@ -51,11 +50,25 @@
    private SolutionWorktypeJoinMapper solutionWorktypeJoinMapper;
    @Autowired
    private InsuranceMapper insuranceMapper;
    @Autowired
    private CompanySolutionMapper companySolutionMapper;
    @Autowired
    private DuSolutionMapper duSolutionMapper;
    @Override
    @Transactional(rollbackFor = {BusinessException.class,Exception.class})
    public Integer create(Solutions solutions) {
        LoginUserInfo user= (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
        initCreateParam(solutions);//工种数据有效性检验,去除空白行数据
        if(solutionsMapper.selectCount(new QueryWrapper<Solutions>().lambda()
                .eq(Solutions::getName,solutions.getName())
                .eq(Solutions::getIsdeleted,Constants.ZERO)
                .eq(Solutions::getDataType,Constants.ZERO)
        )>Constants.ZERO){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"保险方案名称已存在");
        }
        solutions.setIsdeleted(Constants.ZERO);
        solutions.setCreator(user.getId());
@@ -84,7 +97,7 @@
            throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,该保险公司信息不存在,请尝试刷新页面重试~" );
        }
        if( !Constants.equalsInteger(model.getStatus(),Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,该保险公司已被,请尝试刷新页面重试~" );
            throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,该保险公司已被禁用,请尝试刷新页面重试~" );
        }
        List<Worktype> worktypeList = worktypeMapper.selectList(new QueryWrapper<Worktype>().lambda()
                .eq(Worktype::getInsuranceId,solutions.getInsuranceId())
@@ -153,6 +166,7 @@
    }
    @Override
    @Transactional(rollbackFor = {BusinessException.class,Exception.class})
    public void updateById(Solutions solutions) {
        LoginUserInfo user= (LoginUserInfo)SecurityUtils.getSubject().getPrincipal();
        Solutions model = findById(solutions.getId());
@@ -162,11 +176,30 @@
        }
        //数据有效性校验
        initCreateParam(solutions);
        if(solutionsMapper.selectCount(new QueryWrapper<Solutions>().lambda()
                .eq(Solutions::getName,solutions.getName())
                .eq(Solutions::getIsdeleted,Constants.ZERO)
                .eq(Solutions::getDataType,Constants.ZERO)
                .ne(Solutions::getId,solutions.getId())
        )>Constants.ZERO){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"保险方案名称已存在");
        }
        solutions.setEditor(user.getId());
        solutions.setVersion(UUID.randomUUID().toString());
        solutions.setEditDate(new Date());
        solutionsMapper.updateById(solutions);
        Solutions oldVersion = solutionsMapper.selectOne(new QueryWrapper<Solutions>()
                .lambda()
                .eq(Solutions::getBaseId,solutions.getId())
                .eq(Solutions::getDataType,Constants.TWO)
                .last("limit 1")
        );
        if(Objects.isNull(oldVersion)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到历史版本数据");
        }
        //如果修改,则产生一个新的历史版本 ~
        Solutions newModel = new Solutions();
@@ -183,15 +216,35 @@
                .lambda()
                .eq(SolutionWorktype::getSolutionId,solutions.getId())
        );
        solutionsMapper.update(null,new UpdateWrapper<Solutions>()
                .lambda()
                .ne(Solutions::getId,newModel.getId())
                .eq(Solutions::getBaseId,solutions.getId())
                .eq(Solutions::getDataType,Constants.TWO)
                .set(Solutions::getDataType,Constants.ONE)
                .set(StringUtils.isNotBlank(solutions.getSignKeyword()),Solutions::getSignKeyword,solutions.getSignKeyword())
        );
        //处理工作信息,新增最新的,同时产生历史版本
        //处理工种信息,新增最新的,同时产生历史版本
        dealWorkType(solutions,newModel,solutions.getWorktypeIdList(),false);
        //更新company_solution 使用新版本的数据
        companySolutionMapper.update(null,
                new UpdateWrapper<CompanySolution>()
                        .lambda()
                        .eq(CompanySolution::getStatus,Constants.ZERO)
                        .set(CompanySolution::getSolutionId,newModel.getId())
                        .eq(CompanySolution::getSolutionBaseId,solutions.getId())
        );
        //更新 du_solution 使用新版本的数据
        duSolutionMapper.update(null,
                 new UpdateWrapper<DuSolution>()
                         .lambda()
                         .eq(DuSolution::getIsdeleted, Constants.ZERO)
                         .eq(DuSolution::getStatus, Constants.ONE)
                         .set(DuSolution::getSolutionId,newModel.getId())
                         .eq(DuSolution::getSolutionId,oldVersion.getId()));
    }
    @Override
@@ -260,7 +313,10 @@
    @Override
    public List<Solutions> findList(Solutions solutions) {
        solutions.setIsdeleted(Constants.ZERO);
        solutions.setDataType(Constants.TWO);
        solutions.setStatus(Constants.ZERO);
        if(solutions.getDataType() == null){
            solutions.setDataType(Constants.TWO);
        }
        QueryWrapper<Solutions> wrapper = new QueryWrapper<>(solutions);
        return solutionsMapper.selectList(wrapper);
    }
@@ -276,7 +332,10 @@
        queryWrapper.selectAll(Solutions.class);
        queryWrapper.selectAs(Insurance::getName,Solutions::getInsuranceName);
        queryWrapper.leftJoin(Insurance.class,Insurance::getId,Solutions::getInsuranceId);
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(user.getType().equals(Constants.ONE)){
            queryWrapper.exists(("select 1 from company_solution b where b.isdeleted=0 and b.company_id="+user.getCompanyId()+" and b.SOLUTION_BASE_ID = t.id"));
        }
        if (pageWrap.getModel().getId() != null) {
            queryWrapper.eq(Solutions::getId, pageWrap.getModel().getId());
        }
@@ -354,9 +413,7 @@
        if (pageWrap.getModel().getOrtherInfo() != null) {
            queryWrapper.eq(Solutions::getOrtherInfo, pageWrap.getModel().getOrtherInfo());
        }
        if (pageWrap.getModel().getSolutionBaseId() != null) {
            queryWrapper.eq(Solutions::getSolutionBaseId, pageWrap.getModel().getSolutionBaseId());
        }
        if (pageWrap.getModel().getVersion() != null) {
            queryWrapper.eq(Solutions::getVersion, pageWrap.getModel().getVersion());
        }
@@ -406,6 +463,56 @@
        return PageData.from(solutionsMapper.selectPage(page, queryWrapper));
    }
    @Override
    public List<Solutions> findListForCompany(Integer dataType) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        List<Solutions> solutionsList = solutionsJoinMapper.selectJoinList(Solutions.class,new MPJLambdaWrapper<Solutions>()
                        .selectAll(Solutions.class)
                .leftJoin(CompanySolution.class,CompanySolution::getSolutionId,Solutions::getId)
                .leftJoin(Company.class,Company::getId,CompanySolution::getCompanyId)
                .leftJoin(Insurance.class,Insurance::getId,Solutions::getInsuranceId)
                .eq(Solutions::getIsdeleted,Constants.ZERO)
                .eq(Solutions::getStatus,Constants.ZERO)
                .eq(Solutions::getDataType,dataType)
                .eq(CompanySolution::getIsdeleted,Constants.ZERO)
                .eq(CompanySolution::getCompanyId,user.getCompanyId())
                .eq(Company::getIsdeleted,Constants.ZERO)
                .eq(Company::getStatus,Constants.ZERO)
                .eq(Insurance::getIsdeleted,Constants.ZERO)
                .eq(Insurance::getStatus,Constants.ZERO)
                .orderByAsc(Solutions::getSortnum)
        );
        return solutionsList;
    }
    /**
     * 根据历史版本查询当前最新启用版本
     * @param solutionId
     * @return
     */
    @Override
    public Solutions getNewVersion(Integer solutionId){
        Solutions solutions = solutionsMapper.selectById(solutionId);
        if(Objects.isNull(solutions)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到历史方案信息");
        }
        if(solutions.getDataType().equals(Constants.TWO)){
            return solutions;
        }
        Solutions newVersion = solutionsMapper.selectOne(new QueryWrapper<Solutions>().lambda()
                .eq(Solutions::getIsdeleted,Constants.ZERO)
                .eq(Solutions::getDataType,Constants.TWO)
                .eq(Solutions::getBaseId,solutions.getBaseId())
                .last("limit 1")
        );
        if(Objects.isNull(newVersion)){
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到最新版本数据");
        }
        return newVersion;
    }
    @Override
    public long count(Solutions solutions) {
        QueryWrapper<Solutions> wrapper = new QueryWrapper<>(solutions);