package com.by4cloud.platformx.device.service.impl;
|
|
import cn.hutool.core.bean.BeanUtil;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.by4cloud.platformx.common.core.util.R;
|
import com.by4cloud.platformx.device.dto.InspectionPlanQueryDTO;
|
import com.by4cloud.platformx.device.entity.*;
|
import com.by4cloud.platformx.device.mapper.*;
|
import com.by4cloud.platformx.device.service.InspectionPlanService;
|
import lombok.AllArgsConstructor;
|
import org.springframework.stereotype.Service;
|
|
import java.util.List;
|
|
/**
|
* 巡检计划
|
*
|
* @author syt
|
* @date 2025-04-22 09:06:43
|
*/
|
@Service
|
@AllArgsConstructor
|
public class InspectionPlanServiceImpl extends ServiceImpl<InspectionPlanMapper, InspectionPlan> implements InspectionPlanService {
|
|
private final InspectionPlanDeviceMapper planDeviceMapper;
|
private final InspectionPlanDeviceSerialMapper planDeviceSerialMapper;
|
private final InspectionPlanDeviceStandardMapper planDeviceStandardMapper;
|
private final InspectionTaskMapper taskMapper;
|
private final InspectionTaskItemMapper taskItemMapper;
|
|
@Override
|
public boolean saveDeep(InspectionPlan inspectionPlan) {
|
baseMapper.insert(inspectionPlan);
|
|
//计划与设备关联
|
if (inspectionPlan.getDeviceList()!=null&&inspectionPlan.getDeviceList().size()>0){
|
for (InspectionPlanDevice planDevice:inspectionPlan.getDeviceList()
|
) {
|
planDevice.setPlanId(inspectionPlan.getId());
|
planDeviceMapper.insert(planDevice);
|
//巡检计划设备具体序列号
|
if (planDevice.getSerialList()!=null&&planDevice.getSerialList().size()>0){
|
planDevice.getSerialList().stream().forEach(item->{
|
InspectionPlanDeviceSerial serial = new InspectionPlanDeviceSerial();
|
serial.setSerialNo(item);
|
serial.setPlanDeviceId(planDevice.getId());
|
planDeviceSerialMapper.insert(serial);
|
});
|
}
|
//巡检计划巡检标准
|
if (planDevice.getStandardsList()!=null&&planDevice.getStandardsList().size()>0){
|
planDevice.getStandardsList().stream().forEach(item->{
|
InspectionPlanDeviceStandards standards = new InspectionPlanDeviceStandards();
|
standards.setStandardId(item);
|
standards.setPlanDeviceId(planDevice.getId());
|
planDeviceStandardMapper.insert(standards);
|
});
|
}
|
}
|
}
|
|
//根据是否生成任务标识生成任务
|
if (inspectionPlan.getTaskFlag()==1){
|
InspectionTask task = BeanUtil.copyProperties(inspectionPlan, InspectionTask.class);
|
task.setId(null);
|
task.setTaskStatus(0);
|
task.setTaskName(inspectionPlan.getPlanName()+"的任务");
|
task.setPlanId(inspectionPlan.getId());
|
taskMapper.insert(task);
|
|
//任务明细
|
if (inspectionPlan.getDeviceList()!=null&&inspectionPlan.getDeviceList().size()>0){
|
for (InspectionPlanDevice planDevice:inspectionPlan.getDeviceList()
|
) {
|
//巡检计划设备具体序列号
|
if (planDevice.getSerialList()!=null&&planDevice.getSerialList().size()>0){
|
for (String serial:planDevice.getSerialList()
|
) {
|
//巡检计划巡检标准
|
if (planDevice.getStandardsList()!=null&&planDevice.getStandardsList().size()>0){
|
for (Long standardId:planDevice.getStandardsList()
|
) {
|
InspectionTaskItem item = new InspectionTaskItem();
|
item.setDeviceId(planDevice.getDeviceId());
|
item.setTaskId(task.getId());
|
item.setStandardId(standardId);
|
item.setSerialNo(serial);
|
taskItemMapper.insert(item);
|
}
|
}
|
}
|
|
}
|
|
}
|
}
|
}
|
return true;
|
}
|
|
@Override
|
public IPage pageNew(Page page, InspectionPlanQueryDTO queryDTO) {
|
return baseMapper.page(page,queryDTO);
|
}
|
|
@Override
|
public InspectionPlan getByIdNew(Long id) {
|
InspectionPlan plan = baseMapper.selectById(id);
|
QueryWrapper<InspectionPlanDevice> queryWrapper = new QueryWrapper<>();
|
queryWrapper.eq("plan_id",id);
|
List<InspectionPlanDevice> planDeviceList = planDeviceMapper.selectList(queryWrapper);
|
if (planDeviceList.size()>0){
|
planDeviceList.stream().forEach(device->{
|
List<String> serials = planDeviceSerialMapper.selectSerialList(device.getId());
|
if (serials.size()>0) {
|
device.setSerialList(serials);
|
}
|
List<Long> standardIdList = planDeviceStandardMapper.selectStandardIdList(device.getId());
|
if (standardIdList.size()>0) {
|
device.setStandardsList(standardIdList);
|
}
|
});
|
}
|
plan.setDeviceList(planDeviceList);
|
return plan;
|
}
|
|
@Override
|
public boolean updateByIdNew(InspectionPlan inspectionPlan) {
|
baseMapper.updateById(inspectionPlan);
|
|
//计划与设备关联
|
if (inspectionPlan.getDeviceList()!=null&&inspectionPlan.getDeviceList().size()>0){
|
for (InspectionPlanDevice planDevice:inspectionPlan.getDeviceList()
|
) {
|
planDevice.setPlanId(inspectionPlan.getId());
|
|
if (planDevice.getId()!=null){
|
planDeviceMapper.updateById(planDevice);
|
}else {
|
planDeviceMapper.insert(planDevice);
|
}
|
//巡检计划设备具体序列号
|
if (planDevice.getSerialList()!=null&&planDevice.getSerialList().size()>0){
|
QueryWrapper<InspectionPlanDeviceSerial> queryWrapper = new QueryWrapper<>();
|
queryWrapper.eq("plan_device_id",planDevice.getId());
|
planDeviceSerialMapper.delete(queryWrapper);
|
planDevice.getSerialList().stream().forEach(item->{
|
InspectionPlanDeviceSerial serial = new InspectionPlanDeviceSerial();
|
serial.setSerialNo(item);
|
serial.setPlanDeviceId(planDevice.getId());
|
planDeviceSerialMapper.insert(serial);
|
});
|
}
|
//巡检计划巡检标准
|
if (planDevice.getStandardsList()!=null&&planDevice.getStandardsList().size()>0){
|
QueryWrapper<InspectionPlanDeviceStandards> queryWrapper = new QueryWrapper<>();
|
queryWrapper.eq("plan_device_id",planDevice.getId());
|
planDeviceStandardMapper.delete(queryWrapper);
|
planDevice.getStandardsList().stream().forEach(item->{
|
InspectionPlanDeviceStandards standards = new InspectionPlanDeviceStandards();
|
standards.setStandardId(item);
|
standards.setPlanDeviceId(planDevice.getId());
|
planDeviceStandardMapper.insert(standards);
|
});
|
}
|
}
|
}
|
|
//根据是否生成任务标识生成任务
|
if (inspectionPlan.getTaskFlag()==1){
|
InspectionTask task = BeanUtil.copyProperties(inspectionPlan, InspectionTask.class);
|
task.setId(null);
|
task.setTaskStatus(0);
|
task.setTaskName(inspectionPlan.getPlanName()+"的任务");
|
task.setPlanId(inspectionPlan.getId());
|
taskMapper.insert(task);
|
|
//任务明细
|
if (inspectionPlan.getDeviceList()!=null&&inspectionPlan.getDeviceList().size()>0){
|
for (InspectionPlanDevice planDevice:inspectionPlan.getDeviceList()
|
) {
|
//巡检计划设备具体序列号
|
if (planDevice.getSerialList()!=null&&planDevice.getSerialList().size()>0){
|
for (String serial:planDevice.getSerialList()
|
) {
|
//巡检计划巡检标准
|
if (planDevice.getStandardsList()!=null&&planDevice.getStandardsList().size()>0){
|
for (Long standardId:planDevice.getStandardsList()
|
) {
|
InspectionTaskItem item = new InspectionTaskItem();
|
item.setDeviceId(planDevice.getDeviceId());
|
item.setTaskId(task.getId());
|
item.setStandardId(standardId);
|
item.setSerialNo(serial);
|
taskItemMapper.insert(item);
|
}
|
}
|
}
|
}
|
}
|
}
|
}
|
return true;
|
}
|
|
@Override
|
public R gentTask(Long id) {
|
InspectionPlan plan = getByIdNew(id);
|
InspectionTask task = BeanUtil.copyProperties(plan, InspectionTask.class);
|
task.setId(null);
|
task.setTaskStatus(0);
|
task.setTaskName(plan.getPlanName()+"的任务");
|
task.setPlanId(plan.getId());
|
taskMapper.insert(task);
|
|
//任务明细
|
if (plan.getDeviceList()!=null&&plan.getDeviceList().size()>0){
|
for (InspectionPlanDevice planDevice:plan.getDeviceList()
|
) {
|
//巡检计划设备具体序列号
|
if (planDevice.getSerialList()!=null&&planDevice.getSerialList().size()>0){
|
for (String serial:planDevice.getSerialList()
|
) {
|
//巡检计划巡检标准
|
if (planDevice.getStandardsList()!=null&&planDevice.getStandardsList().size()>0){
|
for (Long standardId:planDevice.getStandardsList()
|
) {
|
InspectionTaskItem item = new InspectionTaskItem();
|
item.setDeviceId(planDevice.getDeviceId());
|
item.setTaskId(task.getId());
|
item.setStandardId(standardId);
|
item.setSerialNo(serial);
|
taskItemMapper.insert(item);
|
}
|
}
|
}
|
|
}
|
|
}
|
}
|
|
//跟新计划标识
|
plan.setTaskFlag(1);
|
baseMapper.updateById(plan);
|
return R.ok();
|
}
|
}
|