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.AnnualVerificationDevice;
|
import com.gkhy.exam.system.domain.AnnualVerificationPlan;
|
import com.gkhy.exam.system.domain.OutsourcedReview;
|
import com.gkhy.exam.system.domain.OutsourcedReviewSubsidiary;
|
import com.gkhy.exam.system.mapper.AnnualVerificationDeviceMapper;
|
import com.gkhy.exam.system.mapper.AnnualVerificationPlanMapper;
|
import com.gkhy.exam.system.service.AnnualVerificationPlanService;
|
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;
|
|
/**
|
* <p>
|
* 年度检定计划主表 服务实现类
|
* </p>
|
*
|
* @author hh
|
* @since 2025-08-25 15:01:44
|
*/
|
@Service
|
public class AnnualVerificationPlanServiceImpl extends ServiceImpl<AnnualVerificationPlanMapper, AnnualVerificationPlan> implements AnnualVerificationPlanService {
|
|
@Autowired
|
private AnnualVerificationPlanMapper annualVerificationPlanMapper;
|
|
@Autowired
|
private AnnualVerificationDeviceMapper annualVerificationDeviceMapper;
|
|
@Override
|
public CommonPage selectAnnualVerificationPlanList(AnnualVerificationPlan annualVerificationPlan) {
|
PageUtils.startPage();
|
List<AnnualVerificationPlan> annualVerificationPlans = annualVerificationPlanMapper.selectAnnualVerificationPlanList(annualVerificationPlan);
|
return CommonPage.restPage(annualVerificationPlans);
|
}
|
|
@Override
|
@Transactional
|
public CommonResult saveAnnualVerificationPlan(AnnualVerificationPlan annualVerificationPlan) {
|
|
List<AnnualVerificationDevice> annualVerificationDevices = annualVerificationPlan.getAnnualVerificationDevices();
|
if (ObjectUtils.isEmpty(annualVerificationDevices)){
|
return CommonResult.failed("保存参数不能为空");
|
}
|
int i = 0;
|
if (annualVerificationPlan.getId() == null){
|
annualVerificationPlan.setCreateBy(SecurityUtils.getUsername());
|
annualVerificationPlan.setCreateTime(LocalDateTime.now());
|
i = annualVerificationPlanMapper.insert(annualVerificationPlan);
|
}else {
|
annualVerificationPlan.setUpdateTime(LocalDateTime.now());
|
annualVerificationPlan.setUpdateBy(SecurityUtils.getUsername());
|
i = annualVerificationPlanMapper.updateById(annualVerificationPlan);
|
}
|
if (i > 0){
|
batchSave(annualVerificationPlan.getId(), annualVerificationDevices, annualVerificationPlan.getDelData());
|
}
|
return i > 0 ? CommonResult.success() : CommonResult.failed();
|
}
|
|
private void batchSave(Long id, List<AnnualVerificationDevice> annualVerificationDevices, List<Long> delData) {
|
if (ObjectUtils.isNotEmpty(delData)){
|
int update = annualVerificationDeviceMapper.update(new AnnualVerificationDevice(),
|
new LambdaUpdateWrapper<AnnualVerificationDevice>().set(AnnualVerificationDevice::getDelFlag, UserConstant.DISENABLE)
|
.set(AnnualVerificationDevice::getUpdateTime, LocalDateTime.now()).set(AnnualVerificationDevice::getUpdateBy, SecurityUtils.getUsername())
|
.in(AnnualVerificationDevice::getId, delData)
|
);
|
if (update >= 0){
|
throw new RuntimeException("操作失败");
|
}
|
}
|
annualVerificationDevices.forEach(annualVerificationDevice -> {
|
if (annualVerificationDevice.getId() == null){
|
annualVerificationDevice.setAnnualVerificationId(id);
|
annualVerificationDevice.setCreateTime(LocalDateTime.now());
|
annualVerificationDevice.setCreateBy(SecurityUtils.getUsername());
|
annualVerificationDeviceMapper.insert(annualVerificationDevice);
|
}else {
|
annualVerificationDevice.setUpdateTime(LocalDateTime.now());
|
annualVerificationDevice.setUpdateBy(SecurityUtils.getUsername());
|
annualVerificationDeviceMapper.updateById(annualVerificationDevice);
|
}
|
|
});
|
}
|
|
|
@Override
|
public CommonResult getAnnualVerificationPlan(Long id) {
|
AnnualVerificationPlan annualVerificationPlan = annualVerificationPlanMapper.selectById(id);
|
if (annualVerificationPlan != null){
|
|
List<AnnualVerificationDevice> annualVerificationDevices = annualVerificationDeviceMapper.selectList(new LambdaQueryWrapper<>(AnnualVerificationDevice.class).eq(AnnualVerificationDevice::getAnnualVerificationId, id)
|
.eq(AnnualVerificationDevice::getDelFlag, UserConstant.ENABLE).orderByDesc(AnnualVerificationDevice::getCreateTime));
|
annualVerificationPlan.setAnnualVerificationDevices(annualVerificationDevices);
|
}
|
return CommonResult.success(annualVerificationPlan);
|
}
|
|
@Override
|
@Transactional
|
public CommonResult deletedAnnualVerificationPlan(Long id) {
|
|
int i = annualVerificationPlanMapper.update(new AnnualVerificationPlan(),
|
new LambdaUpdateWrapper<AnnualVerificationPlan>().eq(AnnualVerificationPlan::getId, id).set(AnnualVerificationPlan::getDelFlag, UserConstant.DISENABLE)
|
.set(AnnualVerificationPlan::getUpdateTime, LocalDateTime.now()).set(AnnualVerificationPlan::getUpdateBy, SecurityUtils.getUsername())
|
);
|
if (i > 0) {
|
annualVerificationDeviceMapper.update(new AnnualVerificationDevice(),
|
new LambdaUpdateWrapper<AnnualVerificationDevice>().eq(AnnualVerificationDevice::getAnnualVerificationId, id)
|
.set(AnnualVerificationDevice::getDelFlag, UserConstant.DISENABLE)
|
.set(AnnualVerificationDevice::getUpdateTime, LocalDateTime.now())
|
.set(AnnualVerificationDevice::getUpdateBy, SecurityUtils.getUsername()));
|
}
|
|
return CommonResult.success();
|
}
|
}
|