|
|
|
package com.zhonglai.luhui.device.protocol.wendubao.analysis;
|
|
|
|
|
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
import com.ruoyi.common.utils.GsonConstructor;
|
|
|
|
import com.zhonglai.luhui.device.analysis.comm.dao.BaseDao;
|
|
|
|
import com.zhonglai.luhui.device.analysis.comm.dto.DeviceSensorData;
|
|
|
|
import com.zhonglai.luhui.device.analysis.comm.dto.LogDeviceOperation;
|
|
|
|
import com.zhonglai.luhui.device.analysis.comm.dto.thingsmodels.ThingsModelItemBase;
|
|
|
|
import com.zhonglai.luhui.device.protocol.factory.config.DeviceCach;
|
|
|
|
import com.zhonglai.luhui.device.protocol.factory.dto.DeviceHost;
|
|
|
|
import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceHostDto;
|
|
|
|
import com.zhonglai.luhui.device.protocol.factory.dto.ParserDeviceInfoDto;
|
|
|
|
import com.zhonglai.luhui.device.protocol.factory.sync.ProtocolSyncFactory;
|
|
|
|
import com.zhonglai.luhui.device.protocol.wendubao.db.WdbDBFactoryImp;
|
|
|
|
import com.zhonglai.luhui.device.protocol.wendubao.dto.WdbTerminal;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
@Service
|
|
|
|
public class WenDuBaoProtocolSyncFactoryImpl implements ProtocolSyncFactory {
|
|
|
|
private BaseDao ly_baseDao = new BaseDao(new WdbDBFactoryImp());
|
|
|
|
@Override
|
|
|
|
public void updateParserDeviceHostDto(ParserDeviceHostDto parserDeviceHostDto) {
|
|
|
|
DeviceHost upDeviceHost = new DeviceHost();
|
|
|
|
|
|
|
|
if(null != parserDeviceHostDto.getData())
|
|
|
|
{
|
|
|
|
DeviceHost deviceHost = (DeviceHost) ly_baseDao.get(DeviceHost.class,parserDeviceHostDto.getId());
|
|
|
|
if(null == deviceHost)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
JsonObject jsonObject = null != deviceHost.getData()?GsonConstructor.get().fromJson(deviceHost.getData(),JsonObject.class):new JsonObject();
|
|
|
|
JsonObject hostData = parserDeviceHostDto.getData();
|
|
|
|
for (String key:hostData.keySet())
|
|
|
|
{
|
|
|
|
jsonObject.add(key,hostData.get(key).getAsJsonObject().get("value"));
|
|
|
|
}
|
|
|
|
upDeviceHost.setData(jsonObject.toString());
|
|
|
|
|
|
|
|
if(hostData.has("27"))
|
|
|
|
{
|
|
|
|
ThingsModelItemBase thingsModelItemBase = ThingsModelItemBase.newhingsModelItem(hostData.get("27").getAsJsonObject());
|
|
|
|
|
|
|
|
ParserDeviceHostDto oldParserDeviceHostDto = DeviceCach.getDeviceHost(parserDeviceHostDto.getId());
|
|
|
|
ThingsModelItemBase oldthingsModelItemBase = ThingsModelItemBase.newhingsModelItem(oldParserDeviceHostDto.getData().get("27").getAsJsonObject());
|
|
|
|
if(!thingsModelItemBase.getSaveView().equals(oldthingsModelItemBase.getSaveView()))
|
|
|
|
{
|
|
|
|
if(hostData.get("27").getAsJsonObject().get("value").getAsInt()==1)
|
|
|
|
{
|
|
|
|
upDeviceHost.setAlarmCode("00");
|
|
|
|
}else{
|
|
|
|
upDeviceHost.setAlarmCode("89");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
upDeviceHost.setId(parserDeviceHostDto.getId());
|
|
|
|
upDeviceHost.setOnline("01");
|
|
|
|
upDeviceHost.setDataUpdateTime(parserDeviceHostDto.getUpdateTime());
|
|
|
|
ly_baseDao.update(upDeviceHost);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateParserDeviceInfoDtoList(Integer productId, List<ParserDeviceInfoDto> parserDeviceInfoDtoList) {
|
|
|
|
if(null != parserDeviceInfoDtoList && parserDeviceInfoDtoList.size() != 0)
|
|
|
|
{
|
|
|
|
for (ParserDeviceInfoDto parserDeviceInfoDto:parserDeviceInfoDtoList)
|
|
|
|
{
|
|
|
|
JsonObject dataObject = parserDeviceInfoDto.getData();
|
|
|
|
if(null != dataObject && dataObject.size() != 0)
|
|
|
|
{
|
|
|
|
String deviceInfoId =dataObject.get("sn").getAsJsonObject().get("value").getAsString(); //25636548,//主机sn号 int 型
|
|
|
|
dataObject.remove("sn");
|
|
|
|
|
|
|
|
WdbTerminal wdbTerminal = (WdbTerminal) ly_baseDao.get(WdbTerminal.class,deviceInfoId);
|
|
|
|
|
|
|
|
if(null == wdbTerminal)
|
|
|
|
{
|
|
|
|
wdbTerminal = new WdbTerminal();
|
|
|
|
wdbTerminal.setId(deviceInfoId);
|
|
|
|
wdbTerminal.setCreateTime(parserDeviceInfoDto.getUpdateTime());
|
|
|
|
wdbTerminal.setBaseStationId(deviceInfoId);
|
|
|
|
wdbTerminal.setBaseStationName(deviceInfoId);
|
|
|
|
ly_baseDao.insert(wdbTerminal);
|
|
|
|
}
|
|
|
|
|
|
|
|
JsonObject jsonObject = new JsonObject();
|
|
|
|
JsonObject devcieData = parserDeviceInfoDto.getData();
|
|
|
|
for (String key:devcieData.keySet())
|
|
|
|
{
|
|
|
|
switch (key)
|
|
|
|
{
|
|
|
|
case "4": //气温float型
|
|
|
|
break;
|
|
|
|
case "21": //光照 int型
|
|
|
|
break;
|
|
|
|
case "wt": //水面 float型
|
|
|
|
if(null != wdbTerminal && null != wdbTerminal.getWaterSurfaceErrorConfig())
|
|
|
|
{
|
|
|
|
jsonObject.addProperty("55",new BigDecimal(devcieData.get(key).getAsJsonObject().get("value").getAsFloat()).add(new BigDecimal(wdbTerminal.getWaterSurfaceErrorConfig())).floatValue());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "wm": //水中 float型
|
|
|
|
if(null != wdbTerminal && null != wdbTerminal.getWaterSurfaceErrorConfig())
|
|
|
|
{
|
|
|
|
jsonObject.addProperty("23",new BigDecimal(devcieData.get(key).getAsJsonObject().get("value").getAsFloat()).add(new BigDecimal(wdbTerminal.getWaterErrorConfig())).floatValue());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "wb": //水底 float型
|
|
|
|
if(null != wdbTerminal && null != wdbTerminal.getWaterSurfaceErrorConfig())
|
|
|
|
{
|
|
|
|
jsonObject.addProperty("24",new BigDecimal(devcieData.get(key).getAsJsonObject().get("value").getAsFloat()).add(new BigDecimal(wdbTerminal.getBedErrorConfig())).floatValue());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "bat": //电池电量百分比0-100 int型
|
|
|
|
jsonObject.add("25",devcieData.get(key).getAsJsonObject().get("value"));
|
|
|
|
break;
|
|
|
|
case "mcu": //信噪比 int型
|
|
|
|
jsonObject.add("26",devcieData.get(key).getAsJsonObject().get("value"));
|
|
|
|
break;
|
|
|
|
case "rssi": //信号接收灵敏度 int型
|
|
|
|
jsonObject.add("28",devcieData.get(key).getAsJsonObject().get("value"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wdbTerminal.setDataUpdateTime(parserDeviceInfoDto.getUpdateTime());
|
|
|
|
wdbTerminal.setOnline("01");
|
|
|
|
wdbTerminal.setData(jsonObject.toString());
|
|
|
|
ly_baseDao.update(wdbTerminal,"id");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateDeviceSensorDataList(List<DeviceSensorData> deviceSensorDataList) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateLogDeviceOperationList(List<LogDeviceOperation> logDeviceOperationList) {
|
|
|
|
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|