shiyunteng
6 天以前 fc8c86e7a365d5c6bdc37c2b05b9f83115ac2bc3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
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.constant.CommonStatusContant;
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()==CommonStatusContant.INSPECTION_PLAN_FLAG_GEN_Y){
            InspectionTask task = BeanUtil.copyProperties(inspectionPlan, InspectionTask.class);
            task.setId(null);
            task.setTaskStatus(CommonStatusContant.INSPECTION_TASK_NO_STARTED);
            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()==CommonStatusContant.INSPECTION_PLAN_FLAG_GEN_Y){
            InspectionTask task = BeanUtil.copyProperties(inspectionPlan, InspectionTask.class);
            task.setId(null);
            task.setTaskStatus(CommonStatusContant.INSPECTION_TASK_NO_STARTED);
            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(CommonStatusContant.INSPECTION_TASK_NO_STARTED);
        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(CommonStatusContant.INSPECTION_PLAN_FLAG_GEN_Y);
        baseMapper.updateById(plan);
        return R.ok();
    }
}