| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.UUID; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 保险方案信息表Service实现 |
| | |
| | | public class SolutionsServiceImpl implements SolutionsService { |
| | | |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | @Autowired |
| | | private MultifileMapper multifileMapper; |
| | | @Autowired |
| | | private SolutionsMapper solutionsMapper; |
| | | @Autowired |
| | | private SolutionsJoinMapper solutionsJoinMapper; |
| | |
| | | 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.setCanAdd(Constants.formatIntegerNum(solutions.getCanAdd())); |
| | | solutions.setCanReduce(Constants.formatIntegerNum(solutions.getCanReduce())); |
| | | solutions.setCanChangeUnit(Constants.formatIntegerNum(solutions.getCanChangeUnit())); |
| | | solutions.setAddValidDays(Constants.formatIntegerNum(solutions.getAddValidDays())); |
| | | solutions.setDelValidDays(Constants.formatIntegerNum(solutions.getDelValidDays())); |
| | | solutions.setIsdeleted(Constants.ZERO); |
| | | solutions.setCreator(user.getId()); |
| | | solutions.setCreateDate(new Date()); |
| | | solutions.setVersion(UUID.randomUUID().toString());//版本号 |
| | | solutions.setDataType(Constants.ZERO); |
| | | solutions.setStatus(Constants.ZERO); |
| | | //2024年6月17日15:56:18 仅支持替换模式下,批增日期 等于 批减日期 |
| | | if(Constants.equalsInteger(solutions.getDelOnlyReplace(),Constants.ONE)){ |
| | | solutions.setAddValidDays(solutions.getDelValidDays()); |
| | | } |
| | | solutionsMapper.insert(solutions);//基础版本 |
| | | |
| | | //如果有工种,则产生一个新的有效历史版本 ~ |
| | |
| | | solutionsMapper.insert(newModel); |
| | | |
| | | dealWorkType(solutions,newModel,solutions.getWorktypeIdList(),true); |
| | | if(Constants.equalsObject(solutions.getType(),Constants.ONE) ){ |
| | | if (solutions.getFanganFile()==null || StringUtils.isBlank(solutions.getFanganFile().getFileurl())){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"请上传方案确认书!"); |
| | | } |
| | | |
| | | Multifile file = solutions.getFanganFile(); |
| | | file.setIsdeleted(Constants.ZERO); |
| | | file.setCreateDate(new Date()); |
| | | file.setCreator(user.getId()); |
| | | file.setObjId(solutions.getId()); |
| | | file.setObjType(Constants.MultiFile.SOLUTIONS_CONFIRMATION_LATTER.getKey()); |
| | | file.setType(Constants.formatIntegerNum(file.getType())); |
| | | multifileMapper.insert(file); |
| | | file.setObjId(newModel.getId()); |
| | | multifileMapper.insert(file); |
| | | } |
| | | return solutions.getId(); |
| | | } |
| | | |
| | |
| | | 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()) |
| | |
| | | // ||Constants.formatIntegerNum(solutions.getPriceCycleUnit()) < 0 |
| | | ||Constants.formatIntegerNum(solutions.getInsureCycle()) < 0 |
| | | ||Constants.formatIntegerNum(solutions.getInsureCycleUnit()) < 0 |
| | | || solutions.getMinAge() >solutions.getMaxAge() |
| | | ||Constants.formatIntegerNum( solutions.getMinAge()) >Constants.formatIntegerNum(solutions.getMaxAge()) |
| | | || Constants.formatBigdecimal(solutions.getPrice()).compareTo(new BigDecimal(0)) !=1 |
| | | ){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | |
| | | if(!(Constants.equalsInteger(solutions.getInsureCycleUnit(),Constants.ZERO) |
| | | ||Constants.equalsInteger(solutions.getInsureCycleUnit(),solutions.getInsureCycleUnit()))){ |
| | | solutions.setDelOnlyReplace(Constants.ZERO); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) |
| | | public void updateById(Solutions solutions) { |
| | | LoginUserInfo user= (LoginUserInfo)SecurityUtils.getSubject().getPrincipal(); |
| | | Solutions model = findById(solutions.getId()); |
| | |
| | | } |
| | | //数据有效性校验 |
| | | initCreateParam(solutions); |
| | | |
| | | solutions.setType(null);//不支持修改投保方案 |
| | | 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()); |
| | | |
| | | //2024年6月17日15:56:18 仅支持替换模式下,批增日期 等于 批减日期 |
| | | if(Constants.equalsInteger(solutions.getDelOnlyReplace(),Constants.ONE)){ |
| | | solutions.setAddValidDays(solutions.getDelValidDays()); |
| | | } |
| | | 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(); |
| | |
| | | .lambda() |
| | | .eq(SolutionWorktype::getSolutionId,solutions.getId()) |
| | | ); |
| | | if(Constants.equalsObject(model.getType(),Constants.ONE) ){ |
| | | if (solutions.getFanganFile()!=null && StringUtils.isNotBlank(solutions.getFanganFile().getFileurl())){ |
| | | |
| | | multifileMapper.update(null,new UpdateWrapper<Multifile>().lambda() |
| | | .set(Multifile::getIsdeleted,Constants.ONE) |
| | | .set(Multifile::getEditDate,solutions.getEditDate()) |
| | | .set(Multifile::getEditor,solutions.getEditor()) |
| | | .eq(Multifile::getObjId,solutions.getId()) |
| | | .eq(Multifile::getIsdeleted,Constants.ZERO) |
| | | .eq(Multifile::getObjType,Constants.MultiFile.SOLUTIONS_CONFIRMATION_LATTER.getKey())); |
| | | |
| | | Multifile file = solutions.getFanganFile(); |
| | | file.setIsdeleted(Constants.ZERO); |
| | | file.setCreateDate(solutions.getEditDate()); |
| | | file.setCreator(solutions.getEditor()); |
| | | file.setObjId(solutions.getId()); |
| | | file.setObjType(Constants.MultiFile.SOLUTIONS_CONFIRMATION_LATTER.getKey()); |
| | | file.setType(Constants.formatIntegerNum(file.getType())); |
| | | multifileMapper.insert(file); |
| | | file.setObjId(newModel.getId()); |
| | | multifileMapper.insert(file); |
| | | } |
| | | } |
| | | |
| | | 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 |
| | |
| | | MPJLambdaWrapper<Solutions> queryWrapper = new MPJLambdaWrapper<>(); |
| | | queryWrapper.selectAll(Solutions.class); |
| | | queryWrapper.selectAs(Insurance::getName,Solutions::getInsuranceName); |
| | | queryWrapper.selectAs(Company::getName,Solutions::getShopName); |
| | | queryWrapper.leftJoin(Insurance.class,Insurance::getId,Solutions::getInsuranceId); |
| | | queryWrapper.leftJoin(Company.class,Company::getId,Solutions::getShopId); |
| | | queryWrapper.eq(Solutions::getId,id); |
| | | Solutions model = solutionsJoinMapper.selectJoinOne(Solutions.class,queryWrapper); |
| | | if(model == null || !Constants.equalsInteger(model.getIsdeleted(),Constants.ZERO)){ |
| | |
| | | wrapper.orderByAsc(SolutionWorktype::getSortnum); |
| | | List<SolutionWorktype> worktypeList = solutionWorktypeJoinMapper.selectJoinList(SolutionWorktype.class,wrapper); |
| | | model.setWorktypeList(worktypeList); |
| | | Multifile f = multifileMapper.selectOne(new QueryWrapper<Multifile>().lambda() |
| | | .eq(Multifile::getObjId,model.getId()) |
| | | .eq(Multifile::getObjType,Constants.MultiFile.SOLUTIONS_CONFIRMATION_LATTER.getKey()) |
| | | .eq(Multifile::getIsdeleted,Constants.ZERO) |
| | | .last("limit 1")); |
| | | if(f!=null && StringUtils.isNotBlank(f.getFileurl())){ |
| | | String url = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+systemDictDataBiz.queryByCode(Constants.OSS,Constants.APPLY_FILE).getCode()+f.getFileurl(); |
| | | f.setFileurlFull(url); |
| | | model.setFanganFile(f);//方案确认书 |
| | | } |
| | | return model; |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | public List<Solutions> findList(Solutions solutions) { |
| | | LoginUserInfo user = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal(); |
| | | 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); |
| | | if(Constants.equalsObject(user.getType(),Constants.TWO)){ |
| | | //如果是删除 |
| | | // wrapper.lambda().exists("select c.id from company_solution c left join solutions d on c.solution_id=d.id where c.isdeleted=0 and d.base_id=solutions.base_id and c.shop_id="+user.getCompanyId());//设置无效访问 |
| | | wrapper.apply("((solutions.type=0 and exists(select cs.id from company_solution cs left join solutions s on cs.solution_id=s.id where cs.isdeleted=0 and s.base_id=solutions.base_id and cs.shop_id="+user.getCompanyId()+")) or (" + |
| | | "solutions.type=1 and solutions.shop_id="+user.getCompanyId()+"))") ; |
| | | } |
| | | return solutionsMapper.selectList(wrapper); |
| | | } |
| | | |
| | |
| | | Utils.MP.blankToNull(pageWrap.getModel()); |
| | | queryWrapper.selectAll(Solutions.class); |
| | | queryWrapper.selectAs(Insurance::getName,Solutions::getInsuranceName); |
| | | queryWrapper.selectAs(Company::getName,Solutions::getShopName); |
| | | queryWrapper.leftJoin(Insurance.class,Insurance::getId,Solutions::getInsuranceId); |
| | | |
| | | queryWrapper.leftJoin(Company.class,Company::getId,Solutions::getShopId); |
| | | 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()); |
| | | } |
| | |
| | | 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()); |
| | | } |
| | |
| | | if (pageWrap.getModel().getBaseId() != null) { |
| | | queryWrapper.eq(Solutions::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.orderByDesc(Solutions::getCreateDate); |
| | | // for(PageWrap.SortData sortData: pageWrap.getSorts()) { |
| | | // if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { |
| | | // queryWrapper.orderByDesc(sortData.getProperty()); |
| | | // } else { |
| | | // queryWrapper.orderByAsc(sortData.getProperty()); |
| | | // } |
| | | // } |
| | | PageData<Solutions> pageData = PageData.from(solutionsJoinMapper.selectJoinPage(page,Solutions.class, queryWrapper)); |
| | | |
| | | return pageData; |
| | | } |
| | | @Override |
| | |
| | | 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) |
| | | .orderByDesc(Solutions::getCreateDate) |
| | | ); |
| | | 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); |
| | |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public BigDecimal testSolutionAddMoney(Integer id, BigDecimal fee, Date start,Date end,Date newDate,Date newEndTime){ |
| | | return Constants.addFee(solutionsMapper.selectById(id),fee,start,end,newDate,newEndTime); |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal testSolutionReduceMoney(Integer id, BigDecimal fee, Date start,Date end,Date reduceStartTime,Date reduceEndTime){ |
| | | return Constants.reduceFee(solutionsMapper.selectById(id),fee,start,end,reduceStartTime,reduceEndTime); |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal testSolutionProduceMoney(Integer id, BigDecimal fee, Date start,Date end,Date produceStart){ |
| | | return Constants.produceFee(solutionsMapper.selectById(id),fee,start,end,produceStart); |
| | | } |
| | | } |