| | |
| | | package com.gkhy.exam.system.service.impl; |
| | | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.gkhy.exam.common.api.CommonPage; |
| | | import com.gkhy.exam.common.api.CommonResult; |
| | |
| | | import com.gkhy.exam.system.domain.*; |
| | | import com.gkhy.exam.system.domain.req.QualityTargetReq; |
| | | import com.gkhy.exam.system.domain.vo.QualityTargetVo; |
| | | import com.gkhy.exam.system.mapper.QualityDecomposeMapper; |
| | | import com.gkhy.exam.system.mapper.QualityMapper; |
| | | import com.gkhy.exam.system.mapper.QualityTargetMapper; |
| | | import com.gkhy.exam.system.mapper.SysDeptMapper; |
| | | import com.gkhy.exam.system.mapper.*; |
| | | import com.gkhy.exam.system.service.QualityService; |
| | | import com.gkhy.exam.system.service.SysCompanyService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.sql.Wrapper; |
| | | import java.time.LocalDateTime; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class QualityServiceImpl extends ServiceImpl<QualityMapper, Quality> implements QualityService { |
| | |
| | | private SysCompanyService sysCompanyService; |
| | | @Autowired |
| | | private SysDeptMapper sysDeptMapper; |
| | | @Autowired |
| | | private QualityAccomplishMapper qualityAccomplishMapper; |
| | | |
| | | @Override |
| | | public CommonPage selectQualityList(Quality quality) { |
| | | boolean admin = SecurityUtils.isAdmin(SecurityUtils.getUserId()); |
| | | if (!admin){ |
| | | if (!SecurityUtils.adminUser()){ |
| | | if (quality.getCompanyId()==null){ |
| | | throw new RuntimeException("非管理员操作,查询条件不可为空"); |
| | | throw new ApiException("非管理员操作,查询条件不可为空"); |
| | | } |
| | | } |
| | | PageUtils.startPage(); |
| | | List<QualityTargetVo> qualityTargetVos = qualityMapper.selectQualityTarget(quality); |
| | | for (QualityTargetVo qualityTargetVo : qualityTargetVos) { |
| | | List<QualityTarget> qualityTargets = qualityTargetMapper.selectByQualityId(qualityTargetVo.getId()); |
| | | for (QualityTarget qualityTarget : qualityTargets) { |
| | | List<QualityTargetMess> qualityTargetMesses = qualityTargetMapper.selectBYQualityTargetId(qualityTarget.getId()); |
| | | qualityTarget.setQualityTargetMesses(qualityTargetMesses); |
| | | } |
| | | qualityTargetVo.setQualityTargets(qualityTargets); |
| | | } |
| | | return CommonPage.restPage(qualityTargetVos); |
| | |
| | | |
| | | @Override |
| | | public CommonResult updateQuality(QualityTargetReq qualityTargetReq) { |
| | | List<Quality> qualities = qualityMapper.selectQualityByType(qualityTargetReq); |
| | | if (qualities.size()>0){ |
| | | throw new ApiException("企业下已有相关数据,请删除后重试,或进行修改"); |
| | | } |
| | | LoginUserDetails loginUser = SecurityUtils.getLoginUser(); |
| | | List<QualityTarget> qualityTargets = qualityTargetReq.getQualityTargets(); |
| | | List<Integer> collect = qualityTargets.stream().map(QualityTarget::getQualityId).collect(Collectors.toList()); |
| | | // List<Integer> collect = qualityTargets.stream().map(QualityTarget::getQualityId).collect(Collectors.toList()); |
| | | Quality quality = new Quality(); |
| | | BeanUtils.copyProperties(qualityTargetReq,quality); |
| | | //获取对应企业 |
| | |
| | | quality.setUpdateBy(loginUser.getUsername()); |
| | | quality.setUpdateTime(LocalDateTime.now()); |
| | | int insert = qualityMapper.updateQualityById(quality); |
| | | qualityTargetMapper.deleteByQualityIds(collect); |
| | | qualityTargetMapper.deleteByQualityIds(qualityTargetReq.getId()); |
| | | for (QualityTarget qualityTarget : qualityTargets) { |
| | | qualityTarget.setQualityId(quality.getId()); |
| | | qualityTarget.setCompanyId(qualityTargetReq.getCompanyId()); |
| | |
| | | List<QualityTargetVo> qualityTargetVos = qualityMapper.selectQualityTarget(quality); |
| | | for (QualityTargetVo qualityTargetVo : qualityTargetVos) { |
| | | List<QualityTarget> qualityTargets = qualityTargetMapper.selectByQualityId(qualityTargetVo.getId()); |
| | | for (QualityTarget qualityTarget : qualityTargets) { |
| | | List<QualityTargetMess> qualityTargetMesses = qualityTargetMapper.selectBYQualityTargetId(qualityTarget.getId()); |
| | | qualityTarget.setQualityTargetMesses(qualityTargetMesses); |
| | | } |
| | | qualityTargetVo.setQualityTargets(qualityTargets); |
| | | } |
| | | return CommonResult.success(qualityTargetVos); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public CommonResult copyQuality(Long companyId, String sourceYear, String targetYear) { |
| | | if (companyId == null){ |
| | | companyId = SecurityUtils.getCompanyId(); |
| | | } |
| | | |
| | | LambdaQueryWrapper<Quality> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(Quality::getCompanyId,companyId) |
| | | .eq(Quality::getYear,targetYear).eq(Quality::getDelFlag,1); |
| | | List<Quality> qualitys = qualityMapper.selectList(queryWrapper); |
| | | if (ObjectUtil.isNotEmpty(qualitys)){ |
| | | for (Quality quality : qualitys) { |
| | | deletedQuality(quality.getId()); |
| | | LambdaQueryWrapper<QualityTarget> queryWrapper1 = new LambdaQueryWrapper<>(); |
| | | queryWrapper1.eq(QualityTarget::getQualityId,quality.getId()).eq(QualityTarget::getDelFlag,1); |
| | | List<QualityTarget> qualityTargets = qualityTargetMapper.selectList(queryWrapper1); |
| | | qualityTargetMapper.deleteByQualityIds(quality.getId()); |
| | | if (ObjectUtil.isNotEmpty(qualityTargets)){ |
| | | qualityTargetMapper.deletedByQualityTargetId(quality.getId()); |
| | | } |
| | | LambdaUpdateWrapper<QualityDecompose> updateWrapper = new LambdaUpdateWrapper<>(); |
| | | updateWrapper.eq(QualityDecompose::getQualityId,quality.getId()).eq(QualityDecompose::getDelFlag,1) |
| | | .set(QualityDecompose::getDelFlag,2).set(QualityDecompose::getUpdateTime,LocalDateTime.now()) |
| | | .set(QualityDecompose::getUpdateBy,SecurityUtils.getUsername()); |
| | | qualityDecomposeMapper.update(new QualityDecompose(),updateWrapper); |
| | | LambdaUpdateWrapper<QualityAccomplish> updateWrapper1 = new LambdaUpdateWrapper<>(); |
| | | updateWrapper1.eq(QualityAccomplish::getQualityId,quality.getId()).eq(QualityAccomplish::getDelFlag,1) |
| | | .set(QualityAccomplish::getDelFlag,2).set(QualityAccomplish::getUpdateTime,LocalDateTime.now()) |
| | | .set(QualityAccomplish::getUpdateBy,SecurityUtils.getUsername()); |
| | | qualityAccomplishMapper.update(new QualityAccomplish(),updateWrapper1); |
| | | } |
| | | } |
| | | LambdaQueryWrapper<Quality> queryWrapperSource = new LambdaQueryWrapper<>(); |
| | | queryWrapperSource.eq(Quality::getCompanyId,companyId) |
| | | .eq(Quality::getYear,sourceYear).eq(Quality::getDelFlag,1); |
| | | |
| | | List<Quality> qualitys1 = qualityMapper.selectList(queryWrapperSource); |
| | | if (ObjectUtil.isNotEmpty(qualitys1)){ |
| | | |
| | | for (Quality quality : qualitys1) { |
| | | Integer oldId = quality.getId(); |
| | | quality.setId( null); |
| | | quality.setYear(targetYear); |
| | | quality.setCreateBy(SecurityUtils.getUsername()); |
| | | quality.setCreateTime(LocalDateTime.now()); |
| | | quality.setUpdateBy(SecurityUtils.getUsername()); |
| | | quality.setUpdateTime(LocalDateTime.now()); |
| | | quality.setDelFlag(1); |
| | | quality.setCompilationTime(LocalDateTime.now()); |
| | | quality.setQualityTime(LocalDateTime.now()); |
| | | qualityMapper.insert(quality); |
| | | List<QualityTarget> qualityTargets = qualityTargetMapper.selectByQualityId(oldId); |
| | | if (ObjectUtil.isNotEmpty(qualityTargets)){ |
| | | for (QualityTarget qualityTarget : qualityTargets) { |
| | | List<QualityTargetMess> qualityTargetMesses = qualityTargetMapper.selectBYQualityTargetId(qualityTarget.getId()); |
| | | qualityTarget.setId(null); |
| | | qualityTarget.setQualityId(quality.getId()); |
| | | qualityTarget.setCreateBy(SecurityUtils.getUsername()); |
| | | qualityTarget.setCreateTime(LocalDateTime.now()); |
| | | qualityTarget.setUpdateBy(SecurityUtils.getUsername()); |
| | | qualityTarget.setUpdateTime(LocalDateTime.now()); |
| | | qualityTargetMapper.insert(qualityTarget); |
| | | |
| | | if (ObjectUtil.isNotEmpty(qualityTargetMesses)){ |
| | | for (QualityTargetMess qualityTargetMess : qualityTargetMesses) { |
| | | qualityTargetMess.setId(null); |
| | | qualityTargetMess.setQualityTargetId(qualityTarget.getId()); |
| | | } |
| | | qualityTargetMapper.insertQualityTargetMess(qualityTargetMesses); |
| | | } |
| | | } |
| | | } |
| | | |
| | | LambdaQueryWrapper<QualityDecompose> queryWrapper1 = new LambdaQueryWrapper<>(); |
| | | queryWrapper1.eq(QualityDecompose::getQualityId,oldId).eq(QualityDecompose::getDelFlag,1); |
| | | List<QualityDecompose> qualityDecomposes = qualityDecomposeMapper.selectList(queryWrapper1); |
| | | if (ObjectUtil.isNotEmpty(qualityDecomposes)){ |
| | | for (QualityDecompose qualityDecompose : qualityDecomposes) { |
| | | qualityDecompose.setId(null); |
| | | qualityDecompose.setQualityId(quality.getId()); |
| | | qualityDecompose.setCreateBy(SecurityUtils.getUsername()); |
| | | qualityDecompose.setCreateTime(LocalDateTime.now()); |
| | | qualityDecompose.setUpdateBy(SecurityUtils.getUsername()); |
| | | qualityDecompose.setUpdateTime(LocalDateTime.now()); |
| | | qualityDecompose.setDelFlag(1); |
| | | qualityDecompose.setCheckTime(LocalDateTime.now()); |
| | | qualityDecompose.setRatifyTime(LocalDateTime.now()); |
| | | qualityDecomposeMapper.insert(qualityDecompose); |
| | | } |
| | | } |
| | | |
| | | LambdaQueryWrapper<QualityAccomplish> queryWrapper2 = new LambdaQueryWrapper<>(); |
| | | queryWrapper2.eq(QualityAccomplish::getQualityId,oldId).eq(QualityAccomplish::getDelFlag,1); |
| | | List<QualityAccomplish> qualityAccomplishes = qualityAccomplishMapper.selectList(queryWrapper2); |
| | | if (ObjectUtil.isNotEmpty(qualityAccomplishes)){ |
| | | for (QualityAccomplish qualityAccomplish : qualityAccomplishes) { |
| | | qualityAccomplish.setId(null); |
| | | qualityAccomplish.setQualityId(quality.getId()); |
| | | qualityAccomplish.setCreateBy(SecurityUtils.getUsername()); |
| | | qualityAccomplish.setCreateTime(LocalDateTime.now()); |
| | | qualityAccomplish.setUpdateBy(SecurityUtils.getUsername()); |
| | | qualityAccomplish.setUpdateTime(LocalDateTime.now()); |
| | | qualityAccomplish.setDelFlag(1); |
| | | qualityAccomplish.setChargeTime(LocalDateTime.now()); |
| | | qualityAccomplishMapper.insert(qualityAccomplish); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | return CommonResult.success(); |
| | | } |
| | | } |