package com.gkhy.exam.system.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.gkhy.exam.common.api.CommonPage; import com.gkhy.exam.common.api.CommonResult; import com.gkhy.exam.common.constant.UserConstant; import com.gkhy.exam.common.utils.PageUtils; import com.gkhy.exam.common.utils.SecurityUtils; import com.gkhy.exam.system.domain.AnnualVerificationPlan; import com.gkhy.exam.system.domain.SixInspection; import com.gkhy.exam.system.domain.SixInspectionContent; import com.gkhy.exam.system.domain.SixInspectionProblem; import com.gkhy.exam.system.mapper.SixInspectionContentMapper; import com.gkhy.exam.system.mapper.SixInspectionMapper; import com.gkhy.exam.system.mapper.SixInspectionProblemMapper; import com.gkhy.exam.system.service.SixInspectionService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; import java.util.List; /** *

* 6s检查主表 服务实现类 *

* * @author hh * @since 2025-08-25 15:01:44 */ @Service public class SixInspectionServiceImpl extends ServiceImpl implements SixInspectionService { @Autowired private SixInspectionMapper sixInspectionMapper; @Autowired private SixInspectionProblemMapper sixInspectionProblemMapper; @Autowired private SixInspectionContentMapper sixInspectionContentMapper; @Override public CommonPage selectSixInspectionList(SixInspection sixInspection) { PageUtils.startPage(); List sixInspections = sixInspectionMapper.selectSixInspectionList(sixInspection); return CommonPage.restPage(sixInspections); } @Override @Transactional public CommonResult saveSixInspection(SixInspection sixInspection) { List sixInspectionContentList = sixInspection.getSixInspectionContentList(); if (ObjectUtils.isEmpty(sixInspectionContentList)) { return CommonResult.failed("保存参数不能为空"); } int i = 0; if (sixInspection.getId() == null) { sixInspection.setCreateBy(SecurityUtils.getUsername()); sixInspection.setCreateTime(LocalDateTime.now()); i = sixInspectionMapper.insert(sixInspection); } else { sixInspection.setUpdateBy(SecurityUtils.getUsername()); sixInspection.setUpdateTime(LocalDateTime.now()); i = sixInspectionMapper.updateById(sixInspection); } if (i > 0) { batchSave(sixInspection.getId(), sixInspectionContentList, sixInspection.getDelProblemIds(), sixInspection.getDelContentIds(), sixInspection.getSixInspectionProblemList()); } return i > 0 ? CommonResult.success() : CommonResult.failed(); } private void batchSave(Long id, List sixInspectionContentList, List delProblemIds, List delContentIds, List sixInspectionProblemList) { if (ObjectUtils.isNotEmpty(delProblemIds)) { int update = sixInspectionProblemMapper.update(new SixInspectionProblem(), new LambdaUpdateWrapper().set(SixInspectionProblem::getDelFlag, UserConstant.DISENABLE) .set(SixInspectionProblem::getUpdateTime, LocalDateTime.now()).set(SixInspectionProblem::getUpdateBy, SecurityUtils.getUsername()) .in(SixInspectionProblem::getId, delProblemIds) ); } if (ObjectUtils.isNotEmpty(delContentIds)) { int update = sixInspectionContentMapper.update(new SixInspectionContent(), new LambdaUpdateWrapper().set(SixInspectionContent::getDelFlag, UserConstant.DISENABLE) .set(SixInspectionContent::getUpdateTime, LocalDateTime.now()).set(SixInspectionContent::getUpdateBy, SecurityUtils.getUsername()) .in(SixInspectionContent::getId, delContentIds) ); } if (ObjectUtils.isNotEmpty(sixInspectionContentList)) { sixInspectionContentList.forEach(sixInspectionContent -> { if (sixInspectionContent.getId() == null) { sixInspectionContent.setSixInspectionId(id); sixInspectionContent.setCreateTime(LocalDateTime.now()); sixInspectionContent.setCreateBy(SecurityUtils.getUsername()); sixInspectionContentMapper.insert(sixInspectionContent); } else { sixInspectionContent.setUpdateTime(LocalDateTime.now()); sixInspectionContent.setUpdateBy(SecurityUtils.getUsername()); sixInspectionContentMapper.updateById(sixInspectionContent); } }); } if (ObjectUtils.isNotEmpty(sixInspectionProblemList)) { sixInspectionProblemList.forEach(sixInspectionProblem -> { if (sixInspectionProblem.getId() == null) { sixInspectionProblem.setSixInspectionId(id); sixInspectionProblem.setCreateTime(LocalDateTime.now()); sixInspectionProblem.setCreateBy(SecurityUtils.getUsername()); sixInspectionProblemMapper.insert(sixInspectionProblem); } else { sixInspectionProblem.setUpdateTime(LocalDateTime.now()); sixInspectionProblem.setUpdateBy(SecurityUtils.getUsername()); sixInspectionProblemMapper.updateById(sixInspectionProblem); } }); } } @Override public CommonResult getSixInspection(Long id) { SixInspection sixInspection = sixInspectionMapper.selectById(id); if (sixInspection != null) { List sixInspectionContentList = sixInspectionContentMapper.selectList(new LambdaQueryWrapper<>(SixInspectionContent.class).eq(SixInspectionContent::getSixInspectionId, id) .eq(SixInspectionContent::getDelFlag, UserConstant.ENABLE).orderByAsc(SixInspectionContent::getSort)); sixInspection.setSixInspectionContentList(sixInspectionContentList); List sixInspectionProblemList = sixInspectionProblemMapper.selectList( new LambdaQueryWrapper<>(SixInspectionProblem.class).eq(SixInspectionProblem::getSixInspectionId, id) .eq(SixInspectionProblem::getDelFlag, UserConstant.ENABLE).orderByAsc(SixInspectionProblem::getSort) ); sixInspection.setSixInspectionProblemList(sixInspectionProblemList); } return CommonResult.success(sixInspection); } @Override @Transactional public CommonResult deletedSixInspection(Long id) { int update = sixInspectionMapper.update(new SixInspection(), new LambdaUpdateWrapper().eq(SixInspection::getId, id) .set(SixInspection::getDelFlag, UserConstant.DISENABLE).set(SixInspection::getUpdateTime, LocalDateTime.now()) .set(SixInspection::getUpdateBy, SecurityUtils.getUsername())); if (update > 0) { sixInspectionContentMapper.update(new SixInspectionContent(), new LambdaUpdateWrapper().eq(SixInspectionContent::getSixInspectionId, id) .set(SixInspectionContent::getDelFlag, UserConstant.DISENABLE).set(SixInspectionContent::getUpdateTime, LocalDateTime.now()) .set(SixInspectionContent::getUpdateBy, SecurityUtils.getUsername()) ); sixInspectionProblemMapper.update(new SixInspectionProblem(), new LambdaUpdateWrapper().eq(SixInspectionProblem::getSixInspectionId, id) .set(SixInspectionProblem::getDelFlag, UserConstant.DISENABLE).set(SixInspectionProblem::getUpdateTime, LocalDateTime.now()) .set(SixInspectionProblem::getUpdateBy, SecurityUtils.getUsername()) ); } return update > 0 ? CommonResult.success() : CommonResult.failed(); } }