|  |  |  | 
|---|
|  |  |  | import org.apache.shiro.SecurityUtils; | 
|---|
|  |  |  | import org.springframework.beans.BeanUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.context.annotation.Bean; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.util.CollectionUtils; | 
|---|
|  |  |  | 
|---|
|  |  |  | private InsuranceApplyMapper insuranceApplyMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) | 
|---|
|  |  |  | public Integer create(SolutionsBase solutionsBase) { | 
|---|
|  |  |  | LoginUserInfo user= (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|---|
|  |  |  | initCreateParam(solutionsBase); | 
|---|
|  |  |  | 
|---|
|  |  |  | //历史版本的工种信息 | 
|---|
|  |  |  | SolutionWorktype newType = new SolutionWorktype(); | 
|---|
|  |  |  | BeanUtils.copyProperties(w, newType); | 
|---|
|  |  |  | newType.setId(null); | 
|---|
|  |  |  | newType.setSolutionId(newModel.getId()); | 
|---|
|  |  |  | solutionWorktypeJoinMapper.insert(newType); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | || Objects.isNull(solutionsBase.getAddValidDays()) | 
|---|
|  |  |  | || Objects.isNull(solutionsBase.getDelValidDays()) | 
|---|
|  |  |  | || Objects.isNull(solutionsBase.getInsuranceId()) | 
|---|
|  |  |  | //                || Objects.isNull(solutionsBase.getRiskDelayStatus()) | 
|---|
|  |  |  | //                || Objects.isNull(solutionsBase.getRiskDelayTime()) | 
|---|
|  |  |  | //                || Objects.isNull(solutionsBase.getRiskDelayUnit()) | 
|---|
|  |  |  | //                || Objects.isNull(solutionsBase.getRiskNewUserStatus()) | 
|---|
|  |  |  | //                || Objects.isNull(solutionsBase.getRiskNewUserTime()) | 
|---|
|  |  |  | //                || Objects.isNull(solutionsBase.getRiskNewUserUnit()) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ||solutionsBase.getInsuranceId()==null | 
|---|
|  |  |  | || Constants.formatIntegerNum(solutionsBase.getMaxAge()) < 0 | 
|---|
|  |  |  | ||Constants.formatIntegerNum(solutionsBase.getMinAge()) < 0 | 
|---|
|  |  |  | 
|---|
|  |  |  | if(Constants.equalsInteger(solutionsBase.getValidType(),Constants.ZERO) && Objects.isNull(solutionsBase.getValidTypeNum())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void saveSolutionsRisk(SolutionsBase solutionsBase){ | 
|---|
|  |  |  | if( Objects.isNull(solutionsBase) | 
|---|
|  |  |  | || Objects.isNull(solutionsBase.getId()) | 
|---|
|  |  |  | ||Objects.isNull(solutionsBase.getRiskDelayStatus()) | 
|---|
|  |  |  | || Objects.isNull(solutionsBase.getRiskDelayTime()) | 
|---|
|  |  |  | || Objects.isNull(solutionsBase.getRiskDelayUnit()) | 
|---|
|  |  |  | || Objects.isNull(solutionsBase.getRiskNewUserStatus()) | 
|---|
|  |  |  | || Objects.isNull(solutionsBase.getRiskNewUserTime()) | 
|---|
|  |  |  | || Objects.isNull(solutionsBase.getRiskNewUserUnit())){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | SolutionsBase model = solutionsBaseMapper.selectById(solutionsBase.getId()); | 
|---|
|  |  |  | if(Objects.isNull(model)){ | 
|---|
|  |  |  | throw new BusinessException(ResponseStatus.DATA_EMPTY); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | solutionsBaseMapper.update(new UpdateWrapper<SolutionsBase>().lambda() | 
|---|
|  |  |  | .set(SolutionsBase::getEditDate,new Date()) | 
|---|
|  |  |  | .set(SolutionsBase::getRiskDelayStatus,solutionsBase.getRiskDelayStatus()) | 
|---|
|  |  |  | .set(SolutionsBase::getRiskDelayTime,solutionsBase.getRiskDelayTime()) | 
|---|
|  |  |  | .set(SolutionsBase::getRiskDelayUnit,solutionsBase.getRiskDelayUnit()) | 
|---|
|  |  |  | .set(SolutionsBase::getRiskNewUserStatus,solutionsBase.getRiskNewUserStatus()) | 
|---|
|  |  |  | .set(SolutionsBase::getRiskNewUserTime,solutionsBase.getRiskNewUserTime()) | 
|---|
|  |  |  | .set(SolutionsBase::getRiskNewUserUnit,solutionsBase.getRiskNewUserUnit()) | 
|---|
|  |  |  | .eq(SolutionsBase::getId,solutionsBase.getId()) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | solutionsBaseMapper.deleteBatchIds(ids); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) | 
|---|
|  |  |  | public void updateById(SolutionsBase solutionsBase) { | 
|---|
|  |  |  | LoginUserInfo user= (LoginUserInfo)SecurityUtils.getSubject().getPrincipal(); | 
|---|
|  |  |  | SolutionsBase model = findById(solutionsBase.getId()); | 
|---|
|  |  |  | 
|---|
|  |  |  | solutionsBase.setAddValidDays(solutionsBase.getDelValidDays()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | solutionsBaseMapper.updateById(solutionsBase); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | SolutionsBase oldVersion = solutionsBaseMapper.selectOne(new QueryWrapper<SolutionsBase>() | 
|---|
|  |  |  | .lambda() | 
|---|
|  |  |  | .eq(SolutionsBase::getBaseId,solutionsBase.getId()) | 
|---|
|  |  |  | 
|---|
|  |  |  | .eq(SolutionWorktype::getType,Constants.ONE) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | //删除父方案下所有子方案的工种数据 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | solutionWorktypeJoinMapper.delete(new UpdateWrapper<SolutionWorktype>() | 
|---|
|  |  |  | .lambda() | 
|---|
|  |  |  | .eq(SolutionWorktype::getType,Constants.ZERO) | 
|---|
|  |  |  | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | dealWorkTypeInsurance(solutionsBase,newModel,solutionsBase.getWorktypeIdList()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | solutionsBaseMapper.update(null,new UpdateWrapper<SolutionsBase>() | 
|---|
|  |  |  | .lambda() | 
|---|
|  |  |  | 
|---|
|  |  |  | QueryWrapper<SolutionsBase> wrapper = new QueryWrapper<>(solutionsBase); | 
|---|
|  |  |  | return solutionsBaseMapper.selectCount(wrapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) | 
|---|
|  |  |  | public void createSolutionBase(Integer solutionId){ | 
|---|
|  |  |  | List<Solutions> solutionsList = solutionsMapper.selectList(new QueryWrapper<Solutions>().lambda() | 
|---|
|  |  |  | .eq(Objects.nonNull(solutionId),Solutions::getId,solutionId) | 
|---|
|  |  |  | .isNull(Solutions::getParentId).eq(Solutions::getDataType,Constants.ZERO).eq(Solutions::getIsdeleted,Constants.ZERO)); | 
|---|
|  |  |  | for (Solutions solutions: solutionsList) { | 
|---|
|  |  |  | SolutionsBase solutionsBase = new SolutionsBase(); | 
|---|
|  |  |  | solutionsBase.setCreator(solutions.getCreator()); | 
|---|
|  |  |  | solutionsBase.setCreateDate(new Date()); | 
|---|
|  |  |  | solutionsBase.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | solutionsBase.setName(solutions.getName()); | 
|---|
|  |  |  | solutionsBase.setStatus(solutions.getStatus()); | 
|---|
|  |  |  | solutionsBase.setSortnum(Constants.ZERO); | 
|---|
|  |  |  | solutionsBase.setInsuranceId(solutions.getInsuranceId()); | 
|---|
|  |  |  | solutionsBase.setValidType(solutions.getValidType()); | 
|---|
|  |  |  | solutionsBase.setMinAge(solutions.getMinAge()); | 
|---|
|  |  |  | solutionsBase.setMaxAge(solutions.getMaxAge()); | 
|---|
|  |  |  | solutionsBase.setSingleWorktype(solutions.getSingleWorktype()); | 
|---|
|  |  |  | solutionsBase.setSpecialInfo(solutions.getSpecialInfo()); | 
|---|
|  |  |  | solutionsBase.setSpecialAgreement(solutions.getSpecialAgreement()); | 
|---|
|  |  |  | solutionsBase.setOrtherInfo(solutions.getOrtherInfo()); | 
|---|
|  |  |  | solutionsBase.setDataType(Constants.ZERO); | 
|---|
|  |  |  | solutionsBase.setValidTypeNum(solutions.getValidTypeNum()); | 
|---|
|  |  |  | solutionsBase.setShopId(solutions.getShopId()); | 
|---|
|  |  |  | solutionsBase.setAddValidDays(solutions.getAddValidDays()); | 
|---|
|  |  |  | solutionsBase.setDelValidDays(solutions.getDelValidDays()); | 
|---|
|  |  |  | solutionsBase.setCanAdd(solutions.getCanAdd()); | 
|---|
|  |  |  | solutionsBase.setCanReduce(solutions.getCanReduce()); | 
|---|
|  |  |  | solutionsBase.setCanChangeUnit(solutions.getCanChangeUnit()); | 
|---|
|  |  |  | solutionsBase.setDelOnlyReplace(solutions.getDelOnlyReplace()); | 
|---|
|  |  |  | solutionsBase.setCompanyName(solutions.getCompanyName()); | 
|---|
|  |  |  | solutionsBase.setCompanyName(solutions.getCompanyName()); | 
|---|
|  |  |  | solutionsBase.setCorrectWarnTime("18:30"); | 
|---|
|  |  |  | solutionsBaseMapper.insert(solutionsBase); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //如果有工种,则产生一个新的有效历史版本 ~ | 
|---|
|  |  |  | SolutionsBase newModel = new SolutionsBase(); | 
|---|
|  |  |  | BeanUtils.copyProperties(solutionsBase,newModel); | 
|---|
|  |  |  | newModel.setId(null); | 
|---|
|  |  |  | newModel.setBaseId(solutionsBase.getId()); | 
|---|
|  |  |  | newModel.setDataType(Constants.TWO); | 
|---|
|  |  |  | solutionsBaseMapper.insert(newModel); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<SolutionWorktype> solutionWorktypeList = solutionWorktypeJoinMapper.selectList(new QueryWrapper<SolutionWorktype>().lambda().eq(SolutionWorktype::getType,Constants.ZERO).eq(SolutionWorktype::getSolutionId,solutions.getId())); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Integer num = 1; | 
|---|
|  |  |  | for(SolutionWorktype solutionWorktype : solutionWorktypeList) { | 
|---|
|  |  |  | //基础版本 | 
|---|
|  |  |  | SolutionWorktype w = new SolutionWorktype(); | 
|---|
|  |  |  | w.setSolutionId(solutionsBase.getId()); | 
|---|
|  |  |  | w.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | w.setCreator(newModel.getCreator()); | 
|---|
|  |  |  | w.setCreateDate(solutionsBase.getCreateDate()); | 
|---|
|  |  |  | w.setStatus(Constants.ZERO); | 
|---|
|  |  |  | w.setSortnum(num++); | 
|---|
|  |  |  | w.setWorktypeId(solutionWorktype.getWorktypeId()); | 
|---|
|  |  |  | w.setType(Constants.ONE); | 
|---|
|  |  |  | solutionWorktypeJoinMapper.insert(w); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //历史版本的工种信息 | 
|---|
|  |  |  | SolutionWorktype newType = new SolutionWorktype(); | 
|---|
|  |  |  | BeanUtils.copyProperties(w, newType); | 
|---|
|  |  |  | newType.setSolutionId(newModel.getId()); | 
|---|
|  |  |  | solutionWorktypeJoinMapper.insert(newType); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | solutionsMapper.update(null,new UpdateWrapper<Solutions>().lambda().set(Solutions::getParentId,solutionsBase.getId()) | 
|---|
|  |  |  | .and(i->i.eq(Solutions::getId,solutions.getId()).or().eq(Solutions::getBaseId,solutions.getId())) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|