CZT
2023-11-27 c206acfaedc69c390fb67daa81bc686f58a212ef
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
package com.ld.igds.n2.manager;
 
import com.ld.igds.common.CoreCommonService;
import com.ld.igds.common.CoreSerService;
import com.ld.igds.constant.BizType;
import com.ld.igds.constant.Constant;
import com.ld.igds.io.RemoteControlService;
import com.ld.igds.io.RemoteManager;
import com.ld.igds.io.constant.OrderRespEnum;
import com.ld.igds.io.request.DeviceAutoControlRequest;
import com.ld.igds.io.response.DeviceControlResponse;
import com.ld.igds.models.DepotConf;
import com.ld.igds.models.DeviceSer;
import com.ld.igds.models.N2IntelTask;
import com.ld.igds.n2.N2ModelTag;
import com.ld.igds.n2.N2Util;
import com.ld.igds.n2.dto.N2AutoData;
import com.ld.igds.n2.dto.N2Param;
import com.ld.igds.n2.dto.N2TaskParam;
import com.ld.igds.n2.service.HN2Service;
import com.ld.igds.util.ContextUtil;
 
import lombok.extern.slf4j.Slf4j;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.Date;
import java.util.List;
 
 
/**
 * @Desc: 智能气调业务逻辑管理页面,主要包括气密性检测流程,智能气调流程控制管理
 * @author: Andy
 * @update-time: 2022/12/27
 */
@Slf4j
@Component
public class N2IntelManager {
 
    @Autowired
    private CoreCommonService coreCommonService;
    @Autowired
    private RemoteManager remoteManager;
    @Autowired
    private CoreSerService coreSerService;
    @Autowired
    private HN2Service hn2Service;
 
 
//    /**
//     * 智能气调操作入口,实现逻辑
//     * 1,首先验证是否满足执行的标准,设备状态是否满足,当前是否有正在执行的智能任务,比如智能通风或者其他智能任务。
//     * 2.将新增的任务添加到任务队列中,有系统自动调用参数判断执行
//     *
//     * @param autoData
//     * @param param
//     * @param modeClose 是否执行关闭操作,针对流程来讲关闭操作的动作是停止运行,不去回复已经打开的设备状态
//     * @return
//     */
//    public DeviceControlResponse exeIntel(N2AutoData autoData, N2Param param, String modeClose) {
//        String result;
//        if (N2Util.EXE_MODE_02.equals(autoData.getExeMode())) {
//            result = exeIntelBySer(autoData, param, modeClose);
//        } else {
//            result = exeIntelBySys(autoData, param, modeClose);
//        }
//
//        if (null == result) {
//            return new DeviceControlResponse(
//                    OrderRespEnum.ORDER_SUCCESS.getCode(), "命令发送成功,待终端执行!");
//        }
//
//        return new DeviceControlResponse(OrderRespEnum.ORDER_ERROR.getCode(),
//                result);
//    }
//
//    /**
//     * 当前系统执行 智能化任务
//     *
//     * @param autoData
//     * @param param
//     * @param modeClose
//     * @return
//     */
//    private String exeIntelBySys(N2AutoData autoData, N2Param param, String modeClose) {
//
//        //如果执行关闭任务
//        if (Constant.YN_Y.equals(modeClose)) {
//            return exeStopIntel(autoData, param);
//        }
//
//        //正常开启任务,系统执行需要多验证设备状态是否满足开启任务条件
//        boolean checkTag = n2TaskCheck(param.getCompanyId(), param.getDepotId());
//        if (checkTag) {
//            return "当前仓库有气调任务执行中,请先关闭当前子任务!";
//        }
//        checkTag = airTaskCheck(param.getCompanyId(), param.getDepotId());
//        if (checkTag) {
//            return "当前仓库有通风任务执行中,请先关闭当前子任务!";
//        }
//
//        checkTag = airDeviceStatus(param.getCompanyId(), param.getDepotId());
//        if (checkTag) {
//            return "当前仓库设备通风状态有开启,不能执行当前操作!";
//        }
//
//
//        //创建任务,任务创建可能有多个,主任务 + 子任务
//        addN2TaskByAuto(autoData);
//
//        return null;
//    }
//
//
//    /**
//     * 智能控制柜执行智能化任务
//     *
//     * @param autoData
//     * @param param
//     * @param modeClose
//     * @return
//     */
//    private String exeIntelBySer(N2AutoData autoData, N2Param param, String modeClose) {
//
//        //如果执行关闭任务,先要发送通知给智能控制柜,然后关闭当前任务
//        if (Constant.YN_Y.equals(modeClose)) {
//            String msg = exeAutoActionBySer(autoData, param, modeClose);
//            if (null == msg) {
//                msg = exeStopIntel(autoData, param);
//            }
//            return msg;
//        }
//
//        //正常开启任务,控制柜执行不验证通风状态
//        boolean checkTag = n2TaskCheck(param.getCompanyId(), param.getDepotId());
//        if (checkTag) {
//            return "当前仓库有气调任务执行中,请先关闭当前子任务!";
//        }
//        checkTag = airTaskCheck(param.getCompanyId(), param.getDepotId());
//        if (checkTag) {
//            return "当前仓库有通风任务执行中,请先关闭当前子任务!";
//        }
//
//        //新增智能任务
//        addN2TaskByAuto(autoData);
//
//        return exeAutoActionBySer(autoData, param, modeClose);
//    }
//
//
//    public String exeAutoActionBySer(N2AutoData autoData, N2Param param, String modeClose) {
//
//        DepotConf depotConf = coreCommonService.getCacheDepotConf(param.getCompanyId(), param.getDepotId());
//
//        //获取粮情分机的主控信息
//        DeviceSer ser = coreSerService.getCacheSer(param.getCompanyId(), depotConf.getGrainSer());
//
//        if (null == ser || Constant.YN_N.equals(ser.getStatus())) {
//            return "当前仓库控制分机不存在或者已经掉线,系统无法执行,请联系管理员!";
//        }
//
//        DeviceAutoControlRequest request = new DeviceAutoControlRequest();
//        request.setDepotId(param.getDepotId());
//        request.setCompanyId(param.getCompanyId());
//        request.setBizType(BizType.AREATION.getCode());
//        request.setModeTag(autoData.getModeTag());
//        request.setSerId(ser.getId());
//        request.setSerName(ser.getName());
//        request.setModeClose(modeClose);
//        request.setIp(ser.getIp());
//        request.setPort(ser.getPort());
//        request.setDepotName(depotConf.getDepotName());
//
//        RemoteControlService remoteControlService = remoteManager.getRemoteControlService(ser.getProtocol());
//
//        if (null == remoteControlService) {
//            return "当前仓库控制分机协议没有实现,系统无法执行,请联系管理员!";
//        }
//
//        DeviceControlResponse response = remoteControlService.n2AutoControl(request);
//
//        if (OrderRespEnum.ORDER_SUCCESS.getCode().equals(response.getCode())) {
//            return null;
//        }
//
//        return "后台发送命令执行失败,原因:" + response.getMsg();
//    }
//
//    /**
//     * 执行关闭智能任务
//     *
//     * @param autoData
//     * @param param
//     * @return 执行异常信息,正常返回 null
//     */
//    private String exeStopIntel(N2AutoData autoData, N2Param param) {
//
//        // TODO 执行智能任务关闭操作
//
//
//        return null;
//    }
//
//
//    /**
//     * 核对气调任务,有返回true 没有返回false
//     *
//     * @param companyId
//     * @param depotId
//     * @return
//     */
//    public boolean n2TaskCheck(String companyId, String depotId) {
//        // TODO 暂时不做处理
//        N2TaskParam param = new N2TaskParam();
//        param.setCompanyId(companyId);
//        param.setDepotId(depotId);
//        param.setNotStatus(N2Util.TASK_STATUS_03);
//
//        List<N2IntelTask> list = null;//
//
//        if (null == list || list.isEmpty()) return false;
//
//        return true;
//    }
//
//
//    /**
//     * 核对通风任务,有返回true 没有返回false
//     *
//     * @param companyId
//     * @param depotId
//     * @return
//     */
//    public boolean airTaskCheck(String companyId, String depotId) {
//        // TODO 验证是否有通风任务正在执行,暂时不核对
//
//        log.warn("------------验证是否有通风任务正在执行,暂时不核对");
//
//        return false;
//    }
//
//    /**
//     * 核对通风设备状态,有开启返回 true,没有返回false
//     *
//     * @param companyId
//     * @param depotId
//     * @return
//     */
//    private boolean airDeviceStatus(String companyId, String depotId) {
//        // TODO 验证设备通风状态,暂时不核对
//
//        return false;
//    }
//
//    /**
//     * 新增智能任务,主任务,主任务创建需要自动创建至少一个子任务
//     *
//     * @param autoData
//     */
//    private void addN2TaskByAuto(N2AutoData autoData) {
//        N2IntelTask task = new N2IntelTask();
//        String parentId = ContextUtil.getUUID();
//        task.setId(parentId);
//        task.setCompanyId(autoData.getCompanyId());
//        task.setDepotId(autoData.getDepotId());
//        task.setDeptId(autoData.getDeptId());
//        task.setAutoName(autoData.getName());
//        task.setExeNum(1);
//        task.setStatus(N2Util.TASK_STATUS_01);
//        task.setStart(new Date());
//        task.setExeMode(autoData.getExeMode());
//        task.setModeTag(autoData.getModeTag());
//
//        //主任务
//        hn2Service.saveIntelTask(task);
//
//        //气密性检测-子任务
//        if (N2ModelTag.MODEL_30.getCode().equals(autoData.getModeTag())) {
//            // -添加气压检测任务
//            task.setParentId(parentId);
//            task.setId(ContextUtil.getUUID());
//            task.setModeTag(N2ModelTag.MODEL_42.getCode());
//            task.setAutoName(N2ModelTag.MODEL_42.getMsg());
//            hn2Service.saveIntelTask(task);
//
//            //-添加第一个动作抽负压
//            task.setParentId(parentId);
//            task.setId(ContextUtil.getUUID());
//            task.setModeTag(N2ModelTag.MODEL_01.getCode());
//            task.setAutoName(N2ModelTag.MODEL_01.getMsg());
//            hn2Service.saveIntelTask(task);
//        }
//
//
//        //智能气调-子任务
//        if (N2ModelTag.MODEL_31.getCode().equals(autoData.getModeTag())) {
//
//            // -添加气压检测任务
//            task.setParentId(parentId);
//            task.setId(ContextUtil.getUUID());
//            task.setModeTag(N2ModelTag.MODEL_42.getCode());
//            task.setAutoName(N2ModelTag.MODEL_42.getMsg());
//            hn2Service.saveIntelTask(task);
//
//            // -添加一个气体检测任务
//            task.setParentId(parentId);
//            task.setId(ContextUtil.getUUID());
//            task.setModeTag(N2ModelTag.MODEL_41.getCode());
//            task.setAutoName(N2ModelTag.MODEL_41.getMsg());
//            hn2Service.saveIntelTask(task);
//
//            //-添加第一个动作充氮
//            task.setParentId(parentId);
//            task.setId(ContextUtil.getUUID());
//            task.setModeTag(N2ModelTag.MODEL_03.getCode());
//            task.setAutoName(N2ModelTag.MODEL_03.getMsg());
//
//            hn2Service.saveIntelTask(task);
//        }
//
//    }
 
 
}