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
package com.ld.igds.protocol.fzzy.analysis;
 
import com.alibaba.fastjson.JSONObject;
import com.ld.igds.common.CoreCommonService;
import com.ld.igds.constant.BizType;
import com.ld.igds.gas.dto.GasProgressData;
import com.ld.igds.io.notify.NotifyWebInvoker;
import com.ld.igds.io.constant.OrderRespEnum;
import com.ld.igds.models.DepotConf;
import com.ld.igds.models.DeviceSer;
import com.ld.igds.models.Pest;
import com.ld.igds.models.PestInfo;
import com.ld.igds.order.ExeOrderService;
import com.ld.igds.pest.CorePestService;
import com.ld.igds.protocol.fzzy.ServerUtils;
import com.ld.igds.protocol.fzzy.command.BaseRemoteImpl;
import com.ld.igds.protocol.fzzy.dto.ReMessage;
import com.ld.igds.protocol.fzzy.dto.SendMessage;
import com.ld.igds.protocol.fzzy.req.Request2202;
import com.ld.igds.protocol.fzzy.req.Request2203;
import com.ld.igds.protocol.fzzy.req.RequestBody2203;
import com.ld.igds.protocol.fzzy.builder.SimpleCommandBuilder;
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.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * 气体解析
 *
 * @author vince
 */
@Slf4j
@Component(AnalysisPest.BEAN_ID)
public class AnalysisPest extends BaseRemoteImpl {
 
    public static final String BEAN_ID = "fzzy.analysisPest";
 
    @Autowired
    private CorePestService pestService;
    @Autowired
    private CoreCommonService commonService;
    @Autowired
    private ExeOrderService exeOrderService;
 
    @Autowired
    private NotifyWebInvoker notifyInvoker;
 
 
    public void analysis2201(ReMessage reMessage, DeviceSer ser) {
        //DO NOTHING
    }
 
    public void analysis2202(ReMessage reMessage, DeviceSer ser) {
        //平台不反馈
 
        //终端请求-返回的进度信息
        Request2202 request2202 = JSONObject.parseObject(reMessage.getContent().replaceAll(" ", ""), Request2202.class);
 
        GasProgressData gasProgress = new GasProgressData();
        gasProgress.setCompanyId(ser.getCompanyId());
        gasProgress.setCheckPoint(request2202.getPoint());
        gasProgress.setSerId(ser.getId());
        gasProgress.setDepotId(request2202.getHouseId());
        gasProgress.setSumCheckNum(0);
 
        DepotConf depotConf = commonService.getCacheDepotConf(
                ser.getCompanyId(), request2202.getHouseId());
 
 
        gasProgress.setMsg("虫害检测进度:仓库=" + depotConf.getDepotName() + " 当前:"
                + gasProgress.getCheckPoint());
 
        notifyInvoker.notifyGasProgress(gasProgress);
    }
 
    //检测结果
    public void analysis2203(ReMessage reMessage, DeviceSer ser) {
 
        //平台反馈
        SimpleCommandBuilder commandBuilder = SimpleCommandBuilder.getInstance();
        SendMessage message = commandBuilder.buildMessage(ser, ServerUtils.FUNCTION_2203);
        send(message);
 
 
        // 清除采集锁
      //  exeOrderService.removeCache(ser.getCompanyId(), ser.getId(), BizType.PEST.getCode());
 
        //解析结果
        Request2203 request2203 = JSONObject.parseObject(reMessage.getContent().replaceAll(" ", ""), Request2203.class);
 
 
        DepotConf depotConf = commonService.getCacheDepotConf(ser.getCompanyId(), request2203.getHouseId());
 
 
        //主体信息
        Pest pest = new Pest();
        pest.setBatchId(request2203.getTime().substring(0, 12));
        pest.setCheckNum(request2203.getPoints().size());
        pest.setCompanyId(ser.getCompanyId());
        pest.setDepotId(request2203.getHouseId());
        pest.setPestEnd(depotConf.getPestEnd());
        pest.setPestStart(depotConf.getPestStart());
        pest.setReceiveDate(new Date());
        pest.setPestMax(0);
 
        StringBuffer points = new StringBuffer();
        List<PestInfo> items = new ArrayList<>();
        PestInfo info;
 
        for (RequestBody2203 point : request2203.getPoints()) {
            if (point.getNum() > pest.getPestMax()) {
                pest.setPestMax(point.getNum());
            }
 
            info = new PestInfo();
            info.setId(ContextUtil.buildInfoId(pest.getCompanyId(), pest.getDepotId(), pest.getBatchId()));
            info.setPassCode(point.getPoint());
            info.setPestNum(point.getNum());
            info.setPestType(point.getType());
            items.add(info);
 
            points.append(info.getPassCode() + ",");
            points.append(info.getPestNum() + ";");
        }
        pest.setPoints(points.toString());
 
 
        pestService.saveInfoPest(items);
        pestService.saveOrUpdateData(pest);
 
        // 调用通知前端
        notifyInvoker.notifyWeb(pest.getCompanyId(), OrderRespEnum.MSG_SUCCESS,
                BizType.PEST, depotConf.getDepotName() + " 虫害检测:结果返回成功.");
 
 
        log.info("控制柜----->>>平台:虫害解析完成-仓库={},批次={}", depotConf.getDepotName(), pest.getBatchId());
    }
 
    public void analysis2204(ReMessage reMessage, DeviceSer ser) {
        //DO NOTHING
    }
}