|
|
|
1
|
+package com.zhonglai.luhui.device.protocol.wendubao.analysis;
|
|
|
|
2
|
+
|
|
|
|
3
|
+import com.google.gson.JsonObject;
|
|
|
|
4
|
+import com.ruoyi.common.utils.GsonConstructor;
|
|
|
|
5
|
+import com.zhonglai.luhui.device.analysis.comm.dao.BaseDao;
|
|
|
|
6
|
+import com.zhonglai.luhui.device.analysis.comm.dto.DeviceSensorData;
|
|
|
|
7
|
+import com.zhonglai.luhui.device.analysis.comm.dto.LogDeviceOperation;
|
|
|
|
8
|
+import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelItemBase;
|
|
|
|
9
|
+import com.zhonglai.luhui.device.protocol.factory.config.DeviceCach;
|
|
|
|
10
|
+import com.zhonglai.luhui.device.protocol.factory.dto.DeviceHost;
|
|
|
|
11
|
+import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto;
|
|
|
|
12
|
+import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto;
|
|
|
|
13
|
+import com.zhonglai.luhui.device.protocol.factory.sync.ProtocolSyncFactory;
|
|
|
|
14
|
+import com.zhonglai.luhui.device.protocol.wendubao.db.WdbDBFactoryImp;
|
|
|
|
15
|
+import com.zhonglai.luhui.device.protocol.wendubao.dto.WdbTerminal;
|
|
|
|
16
|
+import org.springframework.stereotype.Service;
|
|
|
|
17
|
+
|
|
|
|
18
|
+import java.math.BigDecimal;
|
|
|
|
19
|
+import java.util.List;
|
|
|
|
20
|
+
|
|
|
|
21
|
+@Service
|
|
|
|
22
|
+public class WenDuBaoProtocolSyncFactoryImpl implements ProtocolSyncFactory {
|
|
|
|
23
|
+ private BaseDao ly_baseDao = new BaseDao(new WdbDBFactoryImp());
|
|
|
|
24
|
+ @Override
|
|
|
|
25
|
+ public void updateParserDeviceHostDto(ParserDeviceHostDto parserDeviceHostDto) {
|
|
|
|
26
|
+ DeviceHost upDeviceHost = new DeviceHost();
|
|
|
|
27
|
+
|
|
|
|
28
|
+ if(null != parserDeviceHostDto.getData())
|
|
|
|
29
|
+ {
|
|
|
|
30
|
+ DeviceHost deviceHost = (DeviceHost) ly_baseDao.get(DeviceHost.class,parserDeviceHostDto.getId());
|
|
|
|
31
|
+ if(null == deviceHost)
|
|
|
|
32
|
+ {
|
|
|
|
33
|
+ return;
|
|
|
|
34
|
+ }
|
|
|
|
35
|
+ JsonObject jsonObject = null != deviceHost.getData()?GsonConstructor.get().fromJson(deviceHost.getData(),JsonObject.class):new JsonObject();
|
|
|
|
36
|
+ JsonObject hostData = parserDeviceHostDto.getData();
|
|
|
|
37
|
+ for (String key:hostData.keySet())
|
|
|
|
38
|
+ {
|
|
|
|
39
|
+ jsonObject.add(key,hostData.get(key).getAsJsonObject().get("value"));
|
|
|
|
40
|
+ }
|
|
|
|
41
|
+ upDeviceHost.setData(jsonObject.toString());
|
|
|
|
42
|
+
|
|
|
|
43
|
+ if(hostData.has("27"))
|
|
|
|
44
|
+ {
|
|
|
|
45
|
+ ThingsModelItemBase thingsModelItemBase = ThingsModelItemBase.newhingsModelItem(hostData.get("27").getAsJsonObject());
|
|
|
|
46
|
+
|
|
|
|
47
|
+ ParserDeviceHostDto oldParserDeviceHostDto = DeviceCach.getDeviceHost(parserDeviceHostDto.getId());
|
|
|
|
48
|
+ ThingsModelItemBase oldthingsModelItemBase = ThingsModelItemBase.newhingsModelItem(oldParserDeviceHostDto.getData().get("27").getAsJsonObject());
|
|
|
|
49
|
+ if(!thingsModelItemBase.getSaveView().equals(oldthingsModelItemBase.getSaveView()))
|
|
|
|
50
|
+ {
|
|
|
|
51
|
+ if(hostData.get("27").getAsJsonObject().get("value").getAsInt()==1)
|
|
|
|
52
|
+ {
|
|
|
|
53
|
+ upDeviceHost.setAlarmCode("00");
|
|
|
|
54
|
+ }else{
|
|
|
|
55
|
+ upDeviceHost.setAlarmCode("89");
|
|
|
|
56
|
+ }
|
|
|
|
57
|
+ }
|
|
|
|
58
|
+ }
|
|
|
|
59
|
+ }
|
|
|
|
60
|
+ upDeviceHost.setId(parserDeviceHostDto.getId());
|
|
|
|
61
|
+ upDeviceHost.setOnline("01");
|
|
|
|
62
|
+ upDeviceHost.setDataUpdateTime(parserDeviceHostDto.getUpdateTime());
|
|
|
|
63
|
+ ly_baseDao.update(upDeviceHost);
|
|
|
|
64
|
+ }
|
|
|
|
65
|
+
|
|
|
|
66
|
+ @Override
|
|
|
|
67
|
+ public void updateParserDeviceInfoDtoList(Integer productId, List<ParserDeviceInfoDto> parserDeviceInfoDtoList) {
|
|
|
|
68
|
+ if(null != parserDeviceInfoDtoList && parserDeviceInfoDtoList.size() != 0)
|
|
|
|
69
|
+ {
|
|
|
|
70
|
+ for (ParserDeviceInfoDto parserDeviceInfoDto:parserDeviceInfoDtoList)
|
|
|
|
71
|
+ {
|
|
|
|
72
|
+ JsonObject dataObject = parserDeviceInfoDto.getData();
|
|
|
|
73
|
+ if(null != dataObject && dataObject.size() != 0)
|
|
|
|
74
|
+ {
|
|
|
|
75
|
+ String deviceInfoId =dataObject.get("sn").getAsJsonObject().get("value").getAsString(); //25636548,//主机sn号 int 型
|
|
|
|
76
|
+ dataObject.remove("sn");
|
|
|
|
77
|
+
|
|
|
|
78
|
+ WdbTerminal wdbTerminal = (WdbTerminal) ly_baseDao.get(WdbTerminal.class,deviceInfoId);
|
|
|
|
79
|
+
|
|
|
|
80
|
+ if(null == wdbTerminal)
|
|
|
|
81
|
+ {
|
|
|
|
82
|
+ wdbTerminal = new WdbTerminal();
|
|
|
|
83
|
+ wdbTerminal.setId(deviceInfoId);
|
|
|
|
84
|
+ wdbTerminal.setCreateTime(parserDeviceInfoDto.getUpdateTime());
|
|
|
|
85
|
+ wdbTerminal.setBaseStationId(deviceInfoId);
|
|
|
|
86
|
+ wdbTerminal.setBaseStationName(deviceInfoId);
|
|
|
|
87
|
+ ly_baseDao.insert(wdbTerminal);
|
|
|
|
88
|
+ }
|
|
|
|
89
|
+
|
|
|
|
90
|
+ JsonObject jsonObject = new JsonObject();
|
|
|
|
91
|
+ JsonObject devcieData = parserDeviceInfoDto.getData();
|
|
|
|
92
|
+ for (String key:devcieData.keySet())
|
|
|
|
93
|
+ {
|
|
|
|
94
|
+ switch (key)
|
|
|
|
95
|
+ {
|
|
|
|
96
|
+ case "4": //气温float型
|
|
|
|
97
|
+ break;
|
|
|
|
98
|
+ case "21": //光照 int型
|
|
|
|
99
|
+ break;
|
|
|
|
100
|
+ case "wt": //水面 float型
|
|
|
|
101
|
+ if(null != wdbTerminal && null != wdbTerminal.getWaterSurfaceErrorConfig())
|
|
|
|
102
|
+ {
|
|
|
|
103
|
+ jsonObject.addProperty("55",new BigDecimal(devcieData.get(key).getAsJsonObject().get("value").getAsFloat()).add(new BigDecimal(wdbTerminal.getWaterSurfaceErrorConfig())).floatValue());
|
|
|
|
104
|
+ }
|
|
|
|
105
|
+ break;
|
|
|
|
106
|
+ case "wm": //水中 float型
|
|
|
|
107
|
+ if(null != wdbTerminal && null != wdbTerminal.getWaterSurfaceErrorConfig())
|
|
|
|
108
|
+ {
|
|
|
|
109
|
+ jsonObject.addProperty("23",new BigDecimal(devcieData.get(key).getAsJsonObject().get("value").getAsFloat()).add(new BigDecimal(wdbTerminal.getWaterErrorConfig())).floatValue());
|
|
|
|
110
|
+ }
|
|
|
|
111
|
+ break;
|
|
|
|
112
|
+ case "wb": //水底 float型
|
|
|
|
113
|
+ if(null != wdbTerminal && null != wdbTerminal.getWaterSurfaceErrorConfig())
|
|
|
|
114
|
+ {
|
|
|
|
115
|
+ jsonObject.addProperty("24",new BigDecimal(devcieData.get(key).getAsJsonObject().get("value").getAsFloat()).add(new BigDecimal(wdbTerminal.getBedErrorConfig())).floatValue());
|
|
|
|
116
|
+ }
|
|
|
|
117
|
+ break;
|
|
|
|
118
|
+ case "bat": //电池电量百分比0-100 int型
|
|
|
|
119
|
+ jsonObject.add("25",devcieData.get(key).getAsJsonObject().get("value"));
|
|
|
|
120
|
+ break;
|
|
|
|
121
|
+ case "mcu": //信噪比 int型
|
|
|
|
122
|
+ jsonObject.add("26",devcieData.get(key).getAsJsonObject().get("value"));
|
|
|
|
123
|
+ break;
|
|
|
|
124
|
+ case "rssi": //信号接收灵敏度 int型
|
|
|
|
125
|
+ jsonObject.add("28",devcieData.get(key).getAsJsonObject().get("value"));
|
|
|
|
126
|
+ break;
|
|
|
|
127
|
+ }
|
|
|
|
128
|
+ }
|
|
|
|
129
|
+ wdbTerminal.setDataUpdateTime(parserDeviceInfoDto.getUpdateTime());
|
|
|
|
130
|
+ wdbTerminal.setOnline("01");
|
|
|
|
131
|
+ wdbTerminal.setData(jsonObject.toString());
|
|
|
|
132
|
+ ly_baseDao.update(wdbTerminal,"id");
|
|
|
|
133
|
+
|
|
|
|
134
|
+ }
|
|
|
|
135
|
+ }
|
|
|
|
136
|
+ }
|
|
|
|
137
|
+ }
|
|
|
|
138
|
+
|
|
|
|
139
|
+ @Override
|
|
|
|
140
|
+ public void updateDeviceSensorDataList(List<DeviceSensorData> deviceSensorDataList) {
|
|
|
|
141
|
+
|
|
|
|
142
|
+ }
|
|
|
|
143
|
+
|
|
|
|
144
|
+ @Override
|
|
|
|
145
|
+ public void updateLogDeviceOperationList(List<LogDeviceOperation> logDeviceOperationList) {
|
|
|
|
146
|
+
|
|
|
|
147
|
+ }
|
|
|
|
148
|
+} |