jiazx0107@163.com
2023-05-17 620eab6cca2bc9ef9ea6d3067a0a5ba1deadbd1c
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
package com.ld.igds.protocol.fzzy.analysis;
 
import com.alibaba.fastjson.JSONObject;
import com.ld.igds.common.CoreCommonService;
import com.ld.igds.common.CoreDeviceService;
import com.ld.igds.common.CoreSerService;
import com.ld.igds.constant.BizType;
import com.ld.igds.constant.Constant;
import com.ld.igds.io.notify.NotifyWebInvoker;
import com.ld.igds.io.constant.OrderRespEnum;
import com.ld.igds.models.Depot;
import com.ld.igds.models.DepotConf;
import com.ld.igds.models.Device;
import com.ld.igds.models.DeviceSer;
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.Request1004;
import com.ld.igds.protocol.fzzy.req.Request1006;
import com.ld.igds.protocol.fzzy.req.Request1007;
import com.ld.igds.protocol.fzzy.resp.Response1001;
import com.ld.igds.protocol.fzzy.resp.Response1003;
import com.ld.igds.protocol.fzzy.resp.Response1010;
import com.ld.igds.protocol.fzzy.builder.ObjectCommandBuilder;
import com.ld.igds.protocol.fzzy.builder.SimpleCommandBuilder;
import com.ld.igds.util.ContextUtil;
 
import lombok.extern.slf4j.Slf4j;
 
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.Date;
import java.util.List;
 
/**
 * 系统类协议解析
 */
@Slf4j
@Component(AnalysisSystem.BEAN_ID)
public class AnalysisSystem extends BaseRemoteImpl {
 
    public static final String BEAN_ID = "fzzy.analysisSystem";
 
    @Autowired
    private CoreSerService coreSerService;
    @Autowired
    private CoreCommonService coreCommonService;
    @Autowired
    private CoreDeviceService deviceService;
    @Autowired
    private NotifyWebInvoker notifyWebInvoker;
 
 
    public void analysis1001(ReMessage reMessage) {
        //返回当前系统时间
        Response1001 response = new Response1001();
        response.setTime(DateFormatUtils.format(new Date(), "yyyyMMddHHmmss"));
        ObjectCommandBuilder commandBuilder = ObjectCommandBuilder.getInstance();
        SendMessage message = commandBuilder.buildMessage(reMessage, ServerUtils.FUNCTION_1001, response);
        send(message);
 
        if (null == reMessage.getContent()) return;
 
        DeviceSer ser = coreSerService.getCacheSer(reMessage.getCompanyId(), reMessage.getIedId());
        if (null == ser) {
            log.warn("控制柜----->>>平台:组织编码={},分机ID={},系统没有获取到分机信息,报文无法进行解析", reMessage.getCompanyId(), reMessage.getIedId());
            return;
        }
 
        //更新分机上线信息
        ser.setIp(reMessage.getIp());
        ser.setPort(reMessage.getPort());
        ser.setStatus(Constant.YN_Y);
        coreSerService.updateByData(ser);
 
        // Request1001 resp = JSONObject.parseObject(reMessage.getContent(), Request1001.class);
 
        log.info("控制柜----->>>平台:控制柜上线更新完成-IP={}", reMessage.getIp());
    }
 
    public void analysis1003(ReMessage reMessage, DeviceSer ser) {
        List<Response1003> list = JSONObject.parseArray(reMessage.getContent(), Response1003.class);
 
        Device device;
        int index = 0;
        for (Response1003 response1003 : list) {
            device = new Device();
            device.setCompanyId(ser.getCompanyId());
            device.setDepotId(response1003.getHouseId());
            device.setSerId(ser.getId());
            device.setPassCode(Integer.valueOf(response1003.getDeviceId()));
            if (StringUtils.isNotEmpty(response1003.getFanId())) {
                device.setLink(response1003.getFanId());
            }
            device.setName(response1003.getName());
            device.setLocation(ServerUtils.analysisLocation(response1003.getPos(),response1003.getName()));
 
            device.setType(ServerUtils.analysisDeviceType(response1003.getType(), response1003.isFan()));
 
            index++;
 
            if (index == list.size()) {
                deviceService.updateDeviceNoId(device, true);
            } else {
                deviceService.updateDeviceNoId(device, false);
            }
        }
        notifyWebInvoker.notifyWeb(ser.getCompanyId(), OrderRespEnum.MSG_SUCCESS, BizType.SYS, ser.getName() + " 远程获取设备信息并解析完成!");
 
        log.info("控制柜----->>>平台:控制柜设备列表同步到平台完成-控制柜={}", ser.getName());
    }
 
    public void analysis1004(ReMessage reMessage, DeviceSer ser) {
        Request1004 request = JSONObject.parseObject(reMessage.getContent(), Request1004.class);
 
        log.info("控制柜----->>>平台:控制柜推送警告信息-控制柜={}", request.toString());
 
        //平台反馈
        SimpleCommandBuilder commandBuilder = SimpleCommandBuilder.getInstance();
        SendMessage message = commandBuilder.buildMessage(ser, ServerUtils.FUNCTION_1004);
        send(message);
    }
 
    public void analysis1005(ReMessage reMessage, DeviceSer ser) {
        //请求不处理
 
        //直接返回
        SimpleCommandBuilder commandBuilder = SimpleCommandBuilder.getInstance();
        SendMessage message = commandBuilder.buildMessage(ser, ServerUtils.FUNCTION_1005);
        send(message);
    }
 
    public void analysis1006(ReMessage reMessage, DeviceSer ser) {
 
        //返回
        Request1006 request = JSONObject.parseObject(reMessage.getContent(), Request1006.class);
 
        //TODO
    }
 
    public void analysis1007(ReMessage reMessage, DeviceSer ser) {
        //直接返回
        SimpleCommandBuilder commandBuilder = SimpleCommandBuilder.getInstance();
        SendMessage message = commandBuilder.buildMessage(ser, ServerUtils.FUNCTION_1007);
        send(message);
 
 
        //開始解析
        List<Request1007> requestList = JSONObject.parseArray(reMessage.getContent(), Request1007.class);
        //获取到仓库状态变更信息
        String status;
        for (Request1007 request : requestList) {
            status = ServerUtils.analysisDepotStatus(request.getStatus());
            if (null != status) coreCommonService.updateDepotStatus(ser.getCompanyId(), request.getHouseId(), status);
        }
 
        log.info("控制柜----->>>平台:控制柜仓库状态信息同步完成-控制柜={}", ser.getName());
 
    }
 
    public void analysis1008(ReMessage message, DeviceSer ser) {
 
        notifyWebInvoker.notifyWeb(ser.getCompanyId(), OrderRespEnum.MSG_SUCCESS, BizType.SYS, "仓库状态远程同步成功!");
    }
 
    public void analysis1009(ReMessage message, DeviceSer ser) {
 
        notifyWebInvoker.notifyWeb(ser.getCompanyId(), OrderRespEnum.MSG_SUCCESS, BizType.SYS, ser.getName() + " 远程授权成功!");
    }
 
    public void analysis1010(ReMessage reMessage, DeviceSer ser) {
        List<Response1010> list = JSONObject.parseArray(reMessage.getContent(), Response1010.class);
 
        Depot depot;
        DepotConf depotConf;
        for (Response1010 resp : list) {
            depot = new Depot();
            depot.setId(resp.getHouseId());
            depot.setName(resp.getName());
            depot.setDepotType(ServerUtils.analysisDepotType(resp.getHouseType()));
            depot.setCompanyId(ser.getCompanyId());
            //默认添加所属分库
            depot.setDeptId(ContextUtil.subDeptId(null));
 
            coreCommonService.updateDepot(depot);
 
            depotConf = new DepotConf();
            depotConf.setCompanyId(ser.getCompanyId());
            depotConf.setDepotId(resp.getHouseId());
            depotConf.setThConf(resp.getTempHumChn());
            depotConf.setCableRule(resp.getLay() + "-" + resp.getRow() + "-" + resp.getCol());
 
            depotConf.setCableStart(resp.getStartCol());
            depotConf.setCableEnd(resp.getEndCol());
 
            depotConf.setGasStart(resp.getStartNo());
            depotConf.setGasEnd(resp.getEndNo());
 
            depotConf.setPestStart(resp.getStartNo());
            depotConf.setPestEnd(resp.getEndNo());
            depotConf.setGrainSer(ser.getId());
 
            if (StringUtils.isNotEmpty(resp.getLayout())) {
                depotConf.setCableRule(resp.getLayout());
            }
            depotConf.setCableCir(resp.getLayerPerCircle());
 
            coreCommonService.updateDepotConf(depotConf);
 
        }
        notifyWebInvoker.notifyWeb(ser.getCompanyId(), OrderRespEnum.MSG_SUCCESS, BizType.SYS, ser.getName() + " 远程获取仓库信息并解析完成!");
 
        log.info("控制柜----->>>平台:控制柜仓库配置信息同步完成-控制柜={}", ser.getName());
    }
}