YYC
2023-11-04 3d8dfc3dd31f73dd7ba33d020193f9ab0764fa56
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
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
package com.ld.igds.inout.manager;
 
import com.ld.igds.camera.ApiCameraManager;
import com.ld.igds.camera.CameraUtil;
import com.ld.igds.camera.data.ApiCameraData;
import com.ld.igds.camera.data.ApiCameraResp;
import com.ld.igds.camera.data.ApiSnapReq;
import com.ld.igds.constant.BizType;
import com.ld.igds.data.SnapImgDto;
import com.ld.igds.file.CoreFileService;
import com.ld.igds.inout.ApiInoutManager;
import com.ld.igds.inout.ApiInoutService;
import com.ld.igds.inout.InoutApiConstant;
import com.ld.igds.inout.InoutConstant;
import com.ld.igds.inout.dto.*;
import com.ld.igds.inout.service.InoutService;
import com.ld.igds.io.constant.ProtocolEnum;
import com.ld.igds.m.service.InoutCommonService;
import com.ld.igds.models.InoutConf;
import com.ld.igds.models.SnapSer;
import com.ld.igds.util.ContextUtil;
import com.ld.igds.util.NumberUtil;
import com.ld.igds.view.service.SnapSerService;
import com.ld.igds.websocket.WebSocketPacket;
import com.ld.igds.websocket.WebSocketServer;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
 
 
/**
 * @Desc: 出入库过程中,针对流程相关的设备联动控制包括,地磅、扦样机、读卡器、闸机、LED对接等
 * <p>
 * 注意;当前类中事件类方法均使用异步方式实现
 * @author: Andy
 * @update-time: 2023/7/4 重新优化
 */
@Slf4j
@Component
public class InoutEventControlManager {
 
    @Resource
    private SnapSerService snapSerService;
    @Resource
    private InoutCommonService inoutCommonService;
    @Resource
    private InoutService inoutService;
    @Resource
    private CoreFileService fileService;
    @Resource
    private ApiInoutManager apiInoutManager;
    @Resource
    private ApiCameraManager apiCameraManager;
 
 
    /**
     * 页面获取车牌识别
     *
     * @param param
     * @return
     */
    public ApiInoutData getPlateNum(ApiInoutData param) {
 
        //如果使用的是地磅插件获取,则需要调整设备为地磅插件信息
        if (ProtocolEnum.TCP_FZZY_WEIGHT.getCode().equals(param.getProtocol())) {
            InoutConf conf = this.getInoutConf(param.getCompanyId(), param.getDeptId(), param.getSort(), InoutConstant.CONF_TYPE_70);
            if (null == conf) {
                param.setErrorMsg("没有获取到当前协议插件配置配置信息,获取失败");
                return param;
            }
            param.setIp(conf.getIp());
            param.setPort(conf.getPort());
            param.setProtocol(conf.getProtocol());
 
            return apiInoutManager.getApiService(param.getProtocol()).getPlateNum(param);
        }
 
        return apiInoutManager.getApiService(param.getProtocol()).getPlateNum(param);
    }
 
 
    /**
     * 获取智慧卡结果
     *
     * @param param
     * @return
     */
    public ApiInoutData getIcCardNum(ApiInoutData param) {
 
        //如果使用的是地磅插件获取,则需要调整设备为地磅插件信息
        if (ProtocolEnum.TCP_FZZY_WEIGHT.getCode().equals(param.getProtocol())) {
            InoutConf conf = this.getInoutConf(param.getCompanyId(), param.getDeptId(), param.getSort(), InoutConstant.CONF_TYPE_70);
            if (null == conf) {
                param.setErrorMsg("没有获取到当前协议插件配置配置信息,获取失败");
                return param;
            }
            param.setIp(conf.getIp());
            param.setPort(conf.getPort());
            param.setProtocol(conf.getProtocol());
 
            return apiInoutManager.getApiService(param.getProtocol()).getIcCardNum(param);
        }
 
        return apiInoutManager.getApiService(param.getProtocol()).getIcCardNum(param);
    }
 
 
    /**
     * 出入库登记初始化
     *
     * @param lpr 车牌识别配置信息
     */
    @Async
    public void initInoutRegister(InoutConf lpr) {
 
        if (null == lpr) return;
 
        ApiInoutData lprData = new ApiInoutData(lpr);
 
        apiInoutManager.getApiService(lpr.getProtocol()).initLpr(lprData);
    }
 
 
 
 
    /**
     * 出入库抓拍
     *
     * @param param
     * @return
     */
    public SnapImgDto snapImg(SnapImgDto param) {
        try {
            InoutConf conf;
            SnapSer ser = snapSerService.getCacheByDeptId(param.getDeptId());
            if (StringUtils.isNotEmpty(param.getId1())) {
                conf = inoutCommonService.getCacheInoutConf(param.getCompanyId(), param.getDeptId(), param.getId1());
                param.setFileName1(this.snapImgByConf(conf, param, ser));
                Thread.sleep(500);
            }
            if (StringUtils.isNotEmpty(param.getId2())) {
                conf = inoutCommonService.getCacheInoutConf(param.getCompanyId(), param.getDeptId(), param.getId2());
                param.setFileName2(this.snapImgByConf(conf, param, ser));
                Thread.sleep(500);
            }
            if (StringUtils.isNotEmpty(param.getId3())) {
                conf = inoutCommonService.getCacheInoutConf(param.getCompanyId(), param.getDeptId(), param.getId3());
                param.setFileName3(this.snapImgByConf(conf, param, ser));
            }
        } catch (Exception e) {
            log.error("---------------------出入库抓拍出现异常--------------------{}", e);
        }
 
        return param;
    }
 
    /**
     * 通知主控器-通知称重信息和称重完成信息
     *
     * @param snapImgDto
     */
//    private void noticeGatewayWeightInfo(SnapImgDto snapImgDto) {
//
//        log.debug("-------------用户确认称重----通知称重网关----{}", snapImgDto.getWeight());
//        InoutConf conf = this.getWeightGateway(snapImgDto.getCompanyId(), snapImgDto.getDeptId(), snapImgDto.getSort());
//
//        if (null == conf) {
//            log.info("-------------用户确认称重----通知称重网关---未配置网关----");
//            return;
//        }
//
//        ApiInoutData apiData = new ApiInoutData(conf);
//        apiData.setTime(new Date());
//        apiData.setRepeat(2);
//        apiData.setWeight(snapImgDto.getWeight());
//        apiData.setPlateNum(snapImgDto.getPlateNum());
//        //称重信息暂时取消播放
////        apiData.setMsg("当前称重:" + apiData.getWeight() + "千克");
//        apiData.setMsg("称重已完成");
//
////        apiInoutManager.getApiService(apiData.getProtocol()).noticeWeightDone(apiData);
//        //  apiInoutManager.getApiService(apiData.getProtocol()).noticeRadio(apiData);
//    }
 
    /**
     * 新增白名单给住控制器,需要注意的是,登记时候不确认使用哪个地磅系统,如果系统配置多个主控器,需要同步全部推送
     *
     * @param imgDto
     */
//    private void noticeGatewayAddWhitePlate(SnapImgDto imgDto) {
//
//        List<InoutConf> list = this.getWeightGateway(imgDto.getCompanyId(), imgDto.getDeptId());
//
//        if (null == list || list.isEmpty()) {
//            log.info("-------------称重网关增加白名单----没有获取到网关配置-----取消执行---");
//            return;
//        }
//
//        log.debug("-------------登记完成,增加车牌白名单-----------{}", imgDto.getPlateNum());
//
//        ApiInoutService inoutApiService = apiInoutManager.getApiService(list.get(0).getProtocol());
//
//        ApiInoutData apiData;
//        for (InoutConf conf : list) {
//            apiData = new ApiInoutData(conf);
//            apiData.setPlateNum(imgDto.getPlateNum());
//            // inoutApiService.addWhitePlate(apiData);
//        }
//    }
 
//    public void noticeProgressComplete(InoutData data) {
//        log.debug("-----------------通知称重主控--------流程结束删除白名单");
//        List<InoutConf> list = this.getWeightGateway(data.getCompanyId(), data.getDeptId());
//
//        if (null == list || list.isEmpty()) {
//            return;
//        }
//
//        ApiInoutService inoutApiService = apiInoutManager.getApiService(list.get(0).getProtocol());
//
//        ApiInoutData apiData;
//        for (InoutConf conf : list) {
//            apiData = new ApiInoutData(conf);
//            apiData.setPlateNum(data.getPlateNum());
//
//            // inoutApiService.delWhitePlate(apiData); TODO
//        }
//    }
 
    /**
     * 调用接口进行抓拍
     *
     * @param conf
     * @param param
     * @param snapSer
     * @return
     */
    private String snapImgByConf(InoutConf conf, SnapImgDto param, SnapSer snapSer) {
        if (null == conf) return null;
 
        if (null == conf.getSnapType()) {
            log.error("-----------抓拍执行失败:没有配置抓拍方式-----{}", conf.getName());
            return null;
        }
 
        ApiSnapReq req = new ApiSnapReq();
        req.setCompanyId(conf.getCompanyId());
        req.setDeptId(conf.getDeptId());
        req.setSn(conf.getSn());
        req.setSnapType(conf.getSnapType());
        req.setPlayType(conf.getPlayType());
        req.setSerSn(null == snapSer ? null : snapSer.getSn());
        req.setBizId(param.getBizId());
        //若为出入库称重抓拍,则不传递业务主键。在出入库业务提交时保存文件信息
        if(InoutConstant.PROGRESS_WEIGHT_TAG.equals(conf.getInoutProgress())){
            req.setBizId(null);
        }
        req.setCameraName(conf.getName());
 
        req.setMediaAddr(CameraUtil.updateMediaAddr(conf.getMediaAddr(), conf.getLoginId(),
                conf.getPwd(), conf.getIp(), conf.getPortCtrl(), conf.getChanNum()));
 
        String filePath = fileService.getInoutFilePath(new Date());
 
        req.setFilePath(filePath);
 
        //调整附件名称,避免出现中文
        String fileName = ContextUtil.getTimeId(100) + "_" + conf.getInoutProgress() + ".jpg";
        req.setFileName(fileName);
 
        //执行抓拍
        ApiCameraResp resp = apiCameraManager.getApiCameraService(conf.getPlayType()).snapImg(req);
 
        if (ApiCameraResp.CODE_ERROR.equals(resp.getCode())) {
            log.error("---------抓拍执行失败:{}-----{}", resp.getMsg(), conf.getName());
 
            return null;
        }
 
        return fileName;
    }
 
 
    /**
     * 出入库视频 -- 根据播放方式获取不同的播放地址
     *
     * @param param
     * @return
     */
    public InoutCameraDto inoutVideoPlay(InoutCameraDto param) {
 
        //没有配置播放方式
        if (StringUtils.isEmpty(param.getPlayType())) {
            param.setErrorMsg("没有配置播放方式,无法播放!");
            return param;
        }
 
        if (StringUtils.isEmpty(param.getCompanyId())) {
            param.setCompanyId(ContextUtil.getCompanyId());
        }
 
        //通过接口获取播放地址
        ApiCameraData apiCameraData = new ApiCameraData();
        apiCameraData.setCompanyId(param.getCompanyId());
        apiCameraData.setSn(param.getSn());
        apiCameraData.setCameraId(param.getId());
        apiCameraData.setPlayType(param.getPlayType());
        apiCameraData.setMediaAddr(CameraUtil.updateMediaAddr(param.getMediaAddr(),
                param.getLoginId(), param.getPwd(), param.getIp(), param.getPortCtrl(), param.getChanNum()));
 
        ApiCameraResp result = apiCameraManager.getApiCameraService(param.getPlayType()).getPlayAddr(apiCameraData);
 
        if (null == result) {
            return param;
        }
 
        if (ApiCameraResp.CODE_SUCCESS.equals(result.getCode())) {
            param.setPlayAddr(result.getPlayAddr());
        }
        if (ApiCameraResp.CODE_ERROR.equals(result.getCode())) {
            param.setErrorMsg(result.getMsg());
        }
        return param;
    }
 
    public String videoKeepLive(InoutCameraDto param) {
 
        ApiCameraData apiCameraData = new ApiCameraData();
        apiCameraData.setSn(param.getSn());
        apiCameraData.setCameraId(param.getId());
        apiCameraData.setPlayType(param.getPlayType());
 
        apiCameraManager.getApiCameraService(param.getPlayType()).keepAlive(apiCameraData);
 
        return null;
    }
 
 
    /**
     * 根据id获取出入库设备信息
     *
     * @param id
     * @return
     */
    public InoutConf getInoutConf(String id) {
        //没有配置播放方式
        if (StringUtils.isEmpty(id)) {
            return null;
        }
        return inoutCommonService.getCacheInoutConf(ContextUtil.getCompanyId(), ContextUtil.subDeptId(null), id);
    }
 
    /**
     * @Desc: 获取称重网关设备
     * @author: Andy
     * @update-time: 2022/11/26
     */
    public InoutConf getWeightGateway(String companyId, String deptId, String sort) {
        if (null == sort) sort = "1";
        List<InoutConf> list = inoutCommonService.getCacheInoutConf(companyId, deptId);
        if (null == list || list.isEmpty()) return null;
 
        for (InoutConf conf : list) {
            if (InoutConstant.CONF_TYPE_70.equals(conf.getType()) && sort.equals(conf.getSort())) {
                return conf;
            }
        }
        return null;
    }
 
 
    /**
     * 被动收到车牌识别结果,事件
     *
     * @param data
     */
    @Async
    public void onReceivePlateNum(ApiInoutData data) {
 
        InoutConf conf = this.getInoutConfBySn(data.getCompanyId(), data.getDeptId(), data.getSn());
        if (null == conf) {
            log.error("没有获取到出入库配置CONF:"+data.toString());
            return;
        }
        log.info(conf.toString());
        if (0 == conf.getInOrder()) return;
 
        data = new ApiInoutData(conf);
        log.info(data.toString());
        ApiInoutService inoutApiService = null;
        InoutConf gateconf = null;
        //获取车牌信息,开闸机
        if (InoutApiConstant.DEVICE_CODE_1002 == data.getDeviceCode()) {
            gateconf = this.getWeightGateway(data.getCompanyId(), data.getDeptId(), null);
            if (null == gateconf) {
                log.info("----------没有获取到称重控制器--------------");
            }
            data = new ApiInoutData(gateconf);
            //开入口处道闸
            inoutApiService = apiInoutManager.getApiService(gateconf.getProtocol());
            data.setDeviceCode(InoutApiConstant.DEVICE_CODE_2002);
            data.setActionCode(InoutApiConstant.ACTION_CODE_1);
            inoutApiService.gateControl(data);
        }
 
        if (InoutApiConstant.DEVICE_CODE_1003 == data.getDeviceCode()) {
            gateconf = this.getWeightGateway(data.getCompanyId(), data.getDeptId(), null);
            if (null == gateconf) {
                log.info("----------没有获取到称重控制器--------------");
            }
            //开入口处道闸
            data = new ApiInoutData(gateconf);
            inoutApiService = apiInoutManager.getApiService(gateconf.getProtocol());
            data.setDeviceCode(InoutApiConstant.DEVICE_CODE_2003);
            data.setActionCode(InoutApiConstant.ACTION_CODE_1);
            inoutApiService.gateControl(data);
        }
 
    }
 
    /**
     * 出入库称重页面初始化,如果有SDK车牌识别,需要进行初始化操作
     *
     * @param listInoutConf
     * @param sort
     */
    @Async
    public void initInoutWeight(List<InoutConf> listInoutConf, String sort) {
 
        //获取车牌配置信息
        if (null == listInoutConf) return;
 
        ApiInoutData apiInoutData;
        ApiInoutService inoutApiService;
        for (InoutConf conf : listInoutConf) {
            if (InoutConstant.PROGRESS_WEIGHT_TAG.equals(conf.getInoutProgress())&&InoutConstant.CONF_TYPE_10.equals(conf.getType()) && sort.equals(conf.getSort())) {
                apiInoutData = new ApiInoutData(conf);
                inoutApiService = apiInoutManager.getApiService(conf.getProtocol());
                inoutApiService.initLpr(apiInoutData);
            }
        }
    }
 
 
    /**
     * 出入库登记完成触发事件,默认为异步处理
     *
     * @param data
     */
    @Async
    public void onInoutRegister(InoutData data) {
 
        //DO Nothing
    }
 
 
    /**
     * 出入库称重完成,事件
     *
     * @param data
     * @param curProgress
     * @param nextProgress
     */
    @Async
    public void onInoutWeight(InoutData data, String curProgress, String nextProgress) {
        //获取地磅控制器
        InoutConf conf = this.getWeightGateway(data.getCompanyId(), data.getDeptId(), null);
        if (null == conf) {
            log.info("----------称重完成事件,没有获取到称重控制器--------------");
        }
 
        //1、通知称重显示屏,设备编号6001
        ApiInoutData apiData = new ApiInoutData(conf);
        apiData.setTime(new Date());
        apiData.setDeviceCode(InoutApiConstant.DEVICE_CODE_6001);
        ApiInoutService inoutApiService = apiInoutManager.getApiService(conf.getProtocol());
        inoutApiService.noticeLed(apiData, data);
 
        //2、语音通知
        apiData.setDeviceCode(InoutApiConstant.DEVICE_CODE_8001);
        inoutApiService.noticeRadio(apiData, data);
 
        //3、开闸机
        if (InoutConstant.TYPE_IN.equals(data.getType())) {
            //结算重量大于0表示二次称重
            if (data.getNetWeight() > 0) {
                apiData.setDeviceCode(InoutApiConstant.DEVICE_CODE_2002);
            } else {
                apiData.setDeviceCode(InoutApiConstant.DEVICE_CODE_2003);
            }
            apiData.setActionCode(InoutApiConstant.ACTION_CODE_1);
 
            inoutApiService.gateControl(apiData);
        } else {
            //结算重量大于0表示二次称重
            if (data.getNetWeight() > 0) {
                apiData.setDeviceCode(InoutApiConstant.DEVICE_CODE_2002);
            } else {
                apiData.setDeviceCode(InoutApiConstant.DEVICE_CODE_2003);
            }
            apiData.setActionCode(InoutApiConstant.ACTION_CODE_1);
            inoutApiService.gateControl(apiData);
        }
 
        //4、开红绿灯
        if (InoutConstant.TYPE_IN.equals(data.getType())) {
            //结算重量大于0表示二次称重
            if (data.getNetWeight() > 0) {
                apiData.setDeviceCode(InoutApiConstant.DEVICE_CODE_7001);
            } else {
                apiData.setDeviceCode(InoutApiConstant.DEVICE_CODE_7002);
            }
            apiData.setActionCode(InoutApiConstant.ACTION_CODE_1);
 
            inoutApiService.lightControl(apiData);
        } else {
            //结算重量大于0表示二次称重
            if (data.getNetWeight() > 0) {
                apiData.setDeviceCode(InoutApiConstant.DEVICE_CODE_7002);
            } else {
                apiData.setDeviceCode(InoutApiConstant.DEVICE_CODE_7001);
            }
            apiData.setActionCode(InoutApiConstant.ACTION_CODE_1);
            inoutApiService.lightControl(apiData);
        }
 
    }
 
 
    /**
     * 值仓完成,事件
     *
     * @param data
     * @param curProgress
     * @param nextProgress
     */
    @Async
    public void onInoutHandle(InoutData data, String curProgress, String nextProgress) {
 
        //DO Nothing
    }
 
 
    /**
     * 扦样完成,事件
     *
     * @param data
     */
    @Async
    public void onInSimple(InoutCheckData data) {
        //DO Nothing
    }
 
    /**
     * 质检完成,事件
     *
     * @param data
     * @param curProgress
     * @param nextProgress
     */
    @Async
    public void onInCheck(InoutCheckData data, String curProgress, String nextProgress) {
        //1、质检大屏显示
    }
 
    /**
     * 流程完成,事件
     *
     * @param data
     */
    @Async
    public void onInoutComplete(InoutData data) {
        //DO Nothing
    }
 
    /**
     * 初始化大屏
     *
     * @param companyId 组织编码
     * @param deptId    分库编码
     * @param progress  流程环节
     */
    @Async
    public void initInoutScreen(String companyId, String deptId, String progress) {
        if (null == WebSocketServer.contextOnLineMap.get(BizType.SCREEN
                .getCode())) {
            WebSocketServer.contextOnLineMap.put(BizType.SCREEN.getCode(),
                    false);
        }
        if (null == WebSocketServer.contextOnLineMap.get(BizType.SCREEN_INOUT
                .getCode())) {
            WebSocketServer.contextOnLineMap.put(
                    BizType.SCREEN_INOUT.getCode(), false);
        }
        if (null == WebSocketServer.contextOnLineMap.get(BizType.SCREEN_CHECK
                .getCode())) {
            WebSocketServer.contextOnLineMap.put(
                    BizType.SCREEN_CHECK.getCode(), false);
        }
 
        if (WebSocketServer.contextOnLineMap.get(BizType.SCREEN.getCode())
                || WebSocketServer.contextOnLineMap.get(BizType.SCREEN_INOUT
                .getCode())
                || WebSocketServer.contextOnLineMap.get(BizType.SCREEN_CHECK
                .getCode())) {
 
 
            // 推送到大屏
            List<InoutData> curList = inoutService.getListInoutCache(deptId);
 
            List<InoutData> completeList = inoutService.getCompleteListInoutCache(deptId);
 
            notifyInoutScreen(companyId, deptId, curList, completeList);
        }
    }
 
    private void notifyInoutScreen(String companyId, String deptId, List<InoutData> curList, List<InoutData> completeList) {
        InoutSumDto dto = new InoutSumDto();
        if (null != curList) {
            for (InoutData data : curList) {
                if (InoutConstant.TYPE_IN.equals(data.getType())) {
                    dto.setInSumNum(dto.getInSumNum() + 1);
                }
                if (InoutConstant.TYPE_OUT.equals(data.getType())) {
                    dto.setOutSumNum(dto.getOutSumNum() + 1);
                }
                dto.setCompanyId(companyId);
                dto.setDeptId(deptId);
            }
        }
 
        if (null != completeList) {
            for (InoutData data : completeList) {
                if (InoutConstant.TYPE_IN.equals(data.getType())) {
                    dto.setInSumNum(dto.getInSumNum() + 1);
                    dto.setInComplateNum(dto.getInComplateNum() + 1);
                }
                if (InoutConstant.TYPE_OUT.equals(data.getType())) {
                    dto.setOutSumNum(dto.getOutSumNum() + 1);
                    dto.setOutComplateNum(dto.getOutComplateNum() + 1);
                }
                dto.setCompanyId(data.getCompanyId());
                dto.setDeptId(data.getDeptId());
            }
        }
 
        // 调整封装
        if (dto.getInSumNum() > 0) {
            dto.setPerInComplate(dto.getInComplateNum() / Double.valueOf(dto.getInSumNum()));
            dto.setPerInComplate(NumberUtil.keepPrecision(
                    dto.getPerInComplate() * 100, 1));
        }
 
        if (dto.getOutSumNum() > 0) {
            dto.setPerOutComplate(dto.getOutComplateNum() / Double.valueOf(dto.getOutSumNum()));
            dto.setPerOutComplate(NumberUtil.keepPrecision(
                    dto.getPerOutComplate() * 100, 1));
        }
 
        if (null == dto.getCompanyId()) {
            dto.setCompanyId(ContextUtil.getDefaultCompanyId());
        }
 
        // 推送综合管理大屏
        WebSocketPacket packet = new WebSocketPacket();
        packet.setBizId("IN_OUT_SUMMARY");
        packet.setCompanyId(dto.getCompanyId());
        packet.setDeptId(dto.getDeptId());
        packet.setBizType(BizType.SCREEN.getCode());
        packet.setData(dto);
        WebSocketServer.sendByBizTag(packet);
 
        // 推送出入库大屏
        dto.setCurList(curList);
        dto.setComplateList(completeList);
        packet.setBizType(BizType.SCREEN.getCode());
        packet.setBizTag(WebSocketPacket.BIZ_TAG_SCREEN_INOUT);
        WebSocketServer.sendByBizTag(packet);
 
        // 推送化验大屏
        packet.setBizType(BizType.SCREEN.getCode());
        packet.setBizTag(WebSocketPacket.BIZ_TAG_SCREEN_CHECK);
        WebSocketServer.sendByBizTag(packet);
    }
 
    /**
     * 获取称重插件配置信息
     *
     * @param companyId
     * @param deptId
     * @param sort
     * @param type
     * @return
     */
    public InoutConf getInoutConf(String companyId, String deptId, String sort, String type) {
 
        // 获取出入库配置信息
        List<InoutConf> listInoutConf = inoutCommonService.getCacheInoutConf(companyId, deptId);
 
        if (null == listInoutConf) return null;
 
        InoutConf result = null;
 
        for (InoutConf conf : listInoutConf) {
            if (sort.equals(conf.getSort()) && type.equals(conf.getType())) {
                result = conf;
                break;
            }
        }
 
        if (null == result) return null;
 
        return result;
    }
 
    private InoutConf getInoutConfBySn(String companyId, String deptId, String sn) {
 
        if (null == sn) return null;
 
        // 获取出入库配置信息
        List<InoutConf> listInoutConf = inoutCommonService.getCacheInoutConf(companyId, deptId);
 
        if (null == listInoutConf) return null;
 
        for (InoutConf conf : listInoutConf) {
 
            if (null == conf.getSn()) continue;
 
            if (sn.equals(conf.getSn())) return conf;
        }
 
        return null;
    }
 
 
}