CZT
2023-10-30 b5a5795a5a64d9a5b78b338de74909e240fe73c3
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
package com.ld.igds.view;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
import com.ld.igds.io.RemoteCommonService;
import com.ld.igds.io.RemoteManager;
import com.ld.igds.io.constant.OrderRespEnum;
import com.ld.igds.io.request.DepotStatusRequest;
import com.ld.igds.io.response.BaseResponse;
import com.ld.igds.models.*;
 
import lombok.extern.slf4j.Slf4j;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
 
import com.bstek.bdf2.core.business.IUser;
import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.annotation.DataResolver;
import com.bstek.dorado.annotation.Expose;
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.constant.DepotStatus;
import com.ld.igds.constant.DepotType;
import com.ld.igds.constant.FoodLevel;
import com.ld.igds.order.ExeOrderService;
import com.ld.igds.order.data.ExeRequest;
import com.ld.igds.util.ContextUtil;
import com.ld.igds.view.service.HDepotService;
 
/**
 * @author jiazx
 */
@Slf4j
@Component
public class DepotPR {
 
    @Autowired
    private HDepotService depotService;
    @Autowired
    private CoreCommonService coreCommonService;
    @Autowired
    private CoreSerService coreSerService;
    @Autowired
    private RemoteManager remoteManager;
    @Autowired
    private ExeOrderService exeOrderService;
 
 
    /**
     * 仓房类型-非国标定义
     * ${dorado.getDataProvider("depotPR#triggerDepotType").getResult()}
     *
     * @return
     */
    @DataProvider
    public List<DicTrigger> triggerDepotType() {
        List<DicTrigger> list = new ArrayList<DicTrigger>();
        list.add(new DicTrigger(DepotType.TYPE_01.getCode(), DepotType.TYPE_01.getMsg()));
        list.add(new DicTrigger(DepotType.TYPE_02.getCode(), DepotType.TYPE_02.getMsg()));
        list.add(new DicTrigger(DepotType.TYPE_03.getCode(), DepotType.TYPE_03.getMsg()));
        list.add(new DicTrigger(DepotType.TYPE_04.getCode(), DepotType.TYPE_04.getMsg()));
        list.add(new DicTrigger(DepotType.TYPE_99.getCode(), DepotType.TYPE_99.getMsg()));
        return list;
    }
 
    /**
     * 仓房状态
     * ${dorado.getDataProvider("depotPR#triggerDepotStatus").getResult()}
     *
     * @return
     */
    @DataProvider
    public List<DicTrigger> triggerDepotStatus() {
        List<DicTrigger> list = new ArrayList<DicTrigger>();
        list.add(new DicTrigger(DepotStatus.STATUS_1.getCode(), DepotStatus.STATUS_1.getMsg()));
        list.add(new DicTrigger(DepotStatus.STATUS_2.getCode(), DepotStatus.STATUS_2.getMsg()));
        list.add(new DicTrigger(DepotStatus.STATUS_3.getCode(), DepotStatus.STATUS_3.getMsg()));
        list.add(new DicTrigger(DepotStatus.STATUS_4.getCode(), DepotStatus.STATUS_4.getMsg()));
        list.add(new DicTrigger(DepotStatus.STATUS_31.getCode(), DepotStatus.STATUS_31.getMsg()));
        list.add(new DicTrigger(DepotStatus.STATUS_32.getCode(), DepotStatus.STATUS_32.getMsg()));
        list.add(new DicTrigger(DepotStatus.STATUS_33.getCode(), DepotStatus.STATUS_33.getMsg()));
        list.add(new DicTrigger(DepotStatus.STATUS_34.getCode(), DepotStatus.STATUS_34.getMsg()));
        list.add(new DicTrigger(DepotStatus.STATUS_9.getCode(), DepotStatus.STATUS_9.getMsg()));
        return list;
    }
 
    /**
     * 粮食等级
     * ${dorado.getDataProvider("depotPR#triggerFoodLevel").getResult()}
     *
     * @return
     */
    @DataProvider
    public List<DicTrigger> triggerFoodLevel() {
        List<DicTrigger> list = new ArrayList<DicTrigger>();
        list.add(new DicTrigger(FoodLevel.LEVEL_01.getCode(), FoodLevel.LEVEL_01.getMsg()));
        list.add(new DicTrigger(FoodLevel.LEVEL_02.getCode(), FoodLevel.LEVEL_02.getMsg()));
        list.add(new DicTrigger(FoodLevel.LEVEL_03.getCode(), FoodLevel.LEVEL_03.getMsg()));
        list.add(new DicTrigger(FoodLevel.LEVEL_04.getCode(), FoodLevel.LEVEL_04.getMsg()));
        list.add(new DicTrigger(FoodLevel.LEVEL_05.getCode(), FoodLevel.LEVEL_05.getMsg()));
        list.add(new DicTrigger(FoodLevel.LEVEL_06.getCode(), FoodLevel.LEVEL_06.getMsg()));
        return list;
    }
 
    /**
     * 储粮方式
     * ${dorado.getDataProvider("depotPR#triggerStoreType").getResult()}
     *
     * @return
     */
    @DataProvider
    public List<DicTrigger> triggerStoreType() {
        List<DicTrigger> list = new ArrayList<DicTrigger>();
        list.add(new DicTrigger("1", "散装储粮"));
        list.add(new DicTrigger("2", "包装储粮"));
        list.add(new DicTrigger("3", "围包存"));
        list.add(new DicTrigger("9", "其他"));
        return list;
    }
 
    /**
     * 管理方式
     * ${dorado.getDataProvider("depotPR#triggerManagerType").getResult()}
     *
     * @return
     */
    @DataProvider
    public List<DicTrigger> triggerManagerType() {
        List<DicTrigger> list = new ArrayList<DicTrigger>();
        list.add(new DicTrigger("01", "直储"));
        list.add(new DicTrigger("02", "代储"));
        list.add(new DicTrigger("03", "租仓"));
        list.add(new DicTrigger("04", "委托"));
        return list;
    }
 
    /**
     * 电缆起始方位
     * ${dorado.getDataProvider("depotPR#triggerStartOrientation").getResult()}
     *
     * @return
     */
    @DataProvider
    public List<DicTrigger> triggerStartOrientation() {
        List<DicTrigger> list = new ArrayList<DicTrigger>();
        list.add(new DicTrigger(Constant.GRAIN_START_ORIENTATION_RIGHT, "右边"));
        list.add(new DicTrigger(Constant.GRAIN_START_ORIENTATION_RIGHT_UP, "右上"));
        list.add(new DicTrigger(Constant.GRAIN_START_ORIENTATION_LEFT, "左边"));
        list.add(new DicTrigger(Constant.GRAIN_START_ORIENTATION_LEFT_UP, "左上"));
        return list;
    }
 
    /**
     * 电缆布线方向
     * ${dorado.getDataProvider("depotPR#triggerStartDirection").getResult()}
     *
     * @return
     */
    @DataProvider
    public List<DicTrigger> triggerStartDirection() {
        List<DicTrigger> list = new ArrayList<DicTrigger>();
        list.add(new DicTrigger(Constant.GRAIN_START_DIRECTION_PORTRAIT, "纵向"));
        list.add(new DicTrigger(Constant.GRAIN_START_DIRECTION_TRANSVERSE, "横向"));
 
        return list;
    }
 
    /**
     * 电缆起始点位
     * ${dorado.getDataProvider("depotPR#triggerStartPoint").getResult()}
     *
     * @return
     */
    @DataProvider
    public List<DicTrigger> triggerStartPoint() {
        List<DicTrigger> list = new ArrayList<DicTrigger>();
        list.add(new DicTrigger(Constant.GRAIN_START_POINT_TOP, "顶部"));
        list.add(new DicTrigger(Constant.GRAIN_START_POINT_BELOW, "底部"));
 
        return list;
    }
 
    /**
     * 层行转换
     * ${dorado.getDataProvider("depotPR#triggerStartConvert").getResult()}
     *
     * @return
     */
    @DataProvider
    public List<DicTrigger> triggerStartConvert() {
        List<DicTrigger> list = new ArrayList<DicTrigger>();
        list.add(new DicTrigger(Constant.GRAIN_CONVERT_DEFAULT, "默认"));
        list.add(new DicTrigger(Constant.GRAIN_CONVERT_CLOCKWISE, "顺时针"));
        list.add(new DicTrigger(Constant.GRAIN_CONVERT_ANTICLOCKWISE, "逆时针"));
 
        return list;
    }
 
    /**
     * 筒仓锥形
     * ${dorado.getDataProvider("depotPR#triggerCableCone").getResult()}
     *
     * @return
     */
    @DataProvider
    public List<DicTrigger> triggerCableCone() {
        List<DicTrigger> list = new ArrayList<DicTrigger>();
        list.add(new DicTrigger(Constant.CABLE_CONE_0, "无锥形"));
        list.add(new DicTrigger(Constant.CABLE_CONE_1, "上锥形"));
        list.add(new DicTrigger(Constant.CABLE_CONE_2, "下锥形"));
 
        return list;
    }
 
    // depotPR#getData
    @DataProvider
    public List<Depot> getData(Map<String, Object> param) throws Exception {
        return depotService.getData(param);
    }
 
    // ${dorado.getDataProvider("depotPR#getAllCache").getResult()}
    @DataProvider
    public List<Depot> getAllCache(String name) {
        return depotService.getAllCache(name, ContextUtil.getCompanyId());
    }
 
 
    // depotPR#ajaxGetAllCache
    @Expose
    public List<Depot> ajaxGetAllCache() {
        return depotService.getAllCache(null, null);
    }
 
    // depotPR#flushCache
    @Expose
    public void flushCache() {
        depotService.flushCache(ContextUtil.getCompanyId());
    }
 
    // depotPR#saveOrUpdate
    @DataResolver
    @Transactional
    public String saveOrUpdate(Depot depot) throws Exception {
        IUser user = ContextUtil.getLoginUser();
 
        if (null == depot.getDeptId()) {
            depot.setDeptId(ContextUtil.subDeptId(user));
        }
 
        String msg = null;
 
        if (null == depot.getCompanyId()) {
            depotService.saveDepot(depot);
        } else {
            depotService.updateDepot(depot);
        }
 
        flushCache();
 
        return msg;
    }
 
    // depotPR#deletedepot
    @Expose
    @Transactional
    public void deletedepot(Depot depot) throws Exception {
        depotService.deleteDepot(depot);
    }
 
    /**
     * depotPR#getDepot 获取仓库信息
     *
     * @param depotId
     * @return
     */
    @Expose
    public Depot getDepot(String depotId) {
        return depotService.getDepotById(ContextUtil.getCompanyId(), depotId);
    }
 
    // --------------- 以下为仓库参数配置页面-------------------//
 
    /**
     * 参数配置列表 depotPR#getConfList
     *
     * @return
     */
    @DataProvider
    public List<DepotConf> getConfList() {
        return depotService.getConfList(ContextUtil.getCompanyId());
    }
 
    /**
     * depotPR#saveConf 参数配置更新,包括新增和修改
     *
     * @param conf
     */
    @DataResolver
    public void saveConf(DepotConf conf) {
        depotService.saveConf(conf);
    }
 
    /**
     * depotPR#delDepotConf 删除参数配置
     *
     * @param conf
     * @throws Exception
     */
    @Expose
    public String delDepotConf(DepotConf conf) {
        return depotService.deleteDepotConf(conf);
    }
 
    /**
     * depotPR#flushConfCache 刷新配置缓存
     */
    @Expose
    public void flushConfCache() {
        depotService.flushConfCache(ContextUtil.getCompanyId());
    }
 
    /**
     * depotPR#updateFreq 更新所有粮库的粮情频率
     */
    @Expose
    public void updateFreq(String freq) {
        depotService.updateFreq(freq);
    }
 
    public void updateByStore(DepotStore data) throws Exception {
 
        Depot depot = depotService.getDepotById(data.getCompanyId(), data.getDepotId());
 
        if (null == depot) return;
 
        depot.setStorageReal(data.getStorageReal());
        depot.setDepotStatus(data.getDepotStatus());
        depot.setFoodLevel(data.getFoodLevel());
        depot.setFoodLocation(data.getFoodLocation());
        depot.setFoodVariety(data.getFoodVariety());
        depot.setFoodType(data.getFoodType());
        depot.setFoodYear(data.getFoodYear());
        if (null != data.getStoreDate()) {
            depot.setStoreDate(data.getStoreDate());
        }
 
 
        depotService.updateDepot(depot);
    }
 
    public String pullDepotStatus(String companyId, String depotId, String status) {
        // 执行推送
        DepotConf depotConf = coreCommonService.getCacheDepotConf(companyId, depotId);
 
 
        String msg = "未获取到关联控制柜协议,远程同步取消执行!";
 
 
        if (null == depotConf) {
            msg = "未获取到仓库配置信息,远程同步取消执行!";
 
            log.error("------远程同步仓库状态失败-----{}---{}", depotId, msg);
            return msg;
        }
 
 
        DeviceSer ser = coreSerService.getCacheSer(depotConf.getCompanyId(),
                depotConf.getGrainSer());
 
        if (null == ser) {
            msg = "未获取到关联控制柜,远程同步取消执行!";
            log.error("------远程同步仓库状态失败-----{}---{}", depotId, msg);
            return msg;
        }
        if (Constant.YN_N.equals(ser.getStatus())) {
            msg = "关联控制柜不在线,远程同步取消执行!";
            log.error("------远程同步仓库状态失败-----{}---{}", depotId, msg);
            return msg;
        }
 
        DepotStatusRequest request = new DepotStatusRequest();
        request.setIp(ser.getIp());
        request.setSerName(ser.getName());
        request.setPort(ser.getPort());
        request.setCompanyId(ser.getCompanyId());
        request.setBizType(BizType.SYS.getCode());
        request.setSerId(ser.getId());
        request.setStatus(status);
        request.setDepotId(depotConf.getDepotId());
        request.setDepotName(depotConf.getDepotName());
 
        RemoteCommonService remoteCommonService = remoteManager.getRemoteCommonService(ser.getProtocol());
 
        if (null == remoteCommonService) {
            msg = "未获取到关联控制柜协议,远程同步取消执行!";
            log.error("------远程同步仓库状态失败-----{}---{}", depotId, msg);
            return msg;
        }
 
        ExeRequest exeRequest = new ExeRequest(request);
        exeRequest.setAddLogTag(true);
        exeRequest.setRepeatTag(true);
        exeRequest.setMsg(msg);
 
        BaseResponse response = remoteCommonService.pullDepotStatus(request);
 
        if (OrderRespEnum.ORDER_SUCCESS.getCode().equals(response.getCode())) {
            exeOrderService.checkExecute(exeRequest);
            return null;
        }
 
        msg = "数据保存成功,远程同步状态失败:" + response.getMsg();
        log.error("------远程同步仓库状态失败-----{}---{}", depotId, msg);
        return msg;
    }
 
 
}