|
@@ -3,10 +3,10 @@ package com.huimv.datacollection.service.impl;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.huimv.common.exception.RRException;
|
|
|
import com.huimv.datacollection.constant.XtAppConstant;
|
|
|
+import com.huimv.datacollection.dao.ConsumeElectricDao;
|
|
|
+import com.huimv.datacollection.dao.ConsumeWarterDao;
|
|
|
import com.huimv.datacollection.dao.DeviceDataDao;
|
|
|
-import com.huimv.datacollection.entity.DeviceDataEntity;
|
|
|
-import com.huimv.datacollection.entity.DeviceEntity;
|
|
|
-import com.huimv.datacollection.entity.IndoorEnvironmentEntity;
|
|
|
+import com.huimv.datacollection.entity.*;
|
|
|
import com.huimv.datacollection.enums.CmdEnum;
|
|
|
import com.huimv.datacollection.feign.ManagementFeignService;
|
|
|
import com.huimv.datacollection.service.HandleDataPackageService;
|
|
@@ -38,6 +38,12 @@ public class ClientDataPacketServiceImpl implements IClientDataPacketService {
|
|
|
@Autowired
|
|
|
private HandleDataPackageService handleDataPackageService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ConsumeWarterDao consumeWarterDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ConsumeElectricDao consumeElectricDao;
|
|
|
+
|
|
|
@Override
|
|
|
public String handleClientSendPacket(String clientMessageTxt) {
|
|
|
|
|
@@ -51,7 +57,7 @@ public class ClientDataPacketServiceImpl implements IClientDataPacketService {
|
|
|
String cmd = result[2];
|
|
|
String jqid = result[1];
|
|
|
log.info("本次执行命令>>" + cmd);
|
|
|
- String rs = "";
|
|
|
+ String rs ="";
|
|
|
|
|
|
if (jqid.equals("0")) {
|
|
|
|
|
@@ -282,60 +288,8 @@ public class ClientDataPacketServiceImpl implements IClientDataPacketService {
|
|
|
|
|
|
|
|
|
|
|
|
- DeviceDataEntity deviceDataEntity = new DeviceDataEntity();
|
|
|
- deviceDataEntity.setCmdHeader(result[0]);
|
|
|
- String jqId = result[1];
|
|
|
- deviceDataEntity.setJqId(jqId);
|
|
|
- deviceDataEntity.setCmdType(Integer.parseInt(result[2]));
|
|
|
- deviceDataEntity.setSequence(Integer.parseInt(result[3]));
|
|
|
- Double value = null;
|
|
|
- if (CmdEnum.TEMPERATURE.getTypeNum().equals(cmd) || CmdEnum.HUMIDITY.getTypeNum().equals(cmd)) {
|
|
|
- value = new BigDecimal(result[4]).divide(new BigDecimal("10")).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
- } else if (CmdEnum.GAS.getTypeNum().equals(cmd)) {
|
|
|
- value = Double.parseDouble(result[4]);
|
|
|
- }
|
|
|
- if (value == null) {
|
|
|
- throw new RRException("传入数据包的数据字段为空,请检查!");
|
|
|
- }
|
|
|
- deviceDataEntity.setValue(value);
|
|
|
- deviceDataEntity.setTime(result[5]);
|
|
|
- deviceDataEntity.setVerify(Integer.parseInt(result[6]));
|
|
|
- deviceDataEntity.setCmdEnd(result[7]);
|
|
|
- deviceDataDao.insert(deviceDataEntity);
|
|
|
-
|
|
|
- //获取设备信息并校验
|
|
|
- String deviceJson = JSONObject.toJSONString(managementFeignService.deviceInfo(jqId).get("device"));
|
|
|
- DeviceEntity deviceEntity = JSONObject.parseObject(deviceJson, DeviceEntity.class);
|
|
|
- if (deviceEntity == null) {
|
|
|
- throw new RRException("没有获取到设备信息,请联系管理员!");
|
|
|
- }
|
|
|
- //保存室内环境数据
|
|
|
- IndoorEnvironmentEntity indoorEnvironmentEntity = new IndoorEnvironmentEntity();
|
|
|
- Integer farmId = deviceEntity.getFarmId();
|
|
|
- indoorEnvironmentEntity.setFarmId(farmId);
|
|
|
- Integer pigstyId = deviceEntity.getPigstyId();
|
|
|
- indoorEnvironmentEntity.setPigstyId(pigstyId);
|
|
|
- indoorEnvironmentEntity.setValue(value);
|
|
|
- indoorEnvironmentEntity.setCollectTime(new Date());
|
|
|
+ return rs;
|
|
|
|
|
|
- Map<String, Double> map = managementFeignService.selectByType((short) 1);
|
|
|
- switch (deviceDataEntity.getCmdType()) {
|
|
|
- case 7:
|
|
|
- indoorEnvironmentEntity.setType(1);
|
|
|
- handleDataPackageService.handleTemperature(indoorEnvironmentEntity, value, farmId, pigstyId, map);
|
|
|
- return "hm+7+0+7+end";
|
|
|
- case 8:
|
|
|
- indoorEnvironmentEntity.setType(2);
|
|
|
- handleDataPackageService.handleHumidity(indoorEnvironmentEntity, value, farmId, pigstyId, map);
|
|
|
- return "hm+8+0+8+end";
|
|
|
- case 9:
|
|
|
- indoorEnvironmentEntity.setType(3);
|
|
|
- handleDataPackageService.handleGas(indoorEnvironmentEntity, value, farmId, pigstyId, map);
|
|
|
- return "hm+9+0+8+end";
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
- return "";
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -546,12 +500,131 @@ public class ClientDataPacketServiceImpl implements IClientDataPacketService {
|
|
|
gz = XtAppConstant.SOCKET_SJSC_GZBZ_0;
|
|
|
//温度
|
|
|
if (cmd.equals(XtAppConstant.SOCKET_SJSC_CMD_7)) {
|
|
|
+ DeviceDataEntity deviceDataEntity = new DeviceDataEntity();
|
|
|
+ deviceDataEntity.setCmdHeader(result[0]);
|
|
|
+ String jqId = result[1];
|
|
|
+ deviceDataEntity.setJqId(jqId);
|
|
|
+ deviceDataEntity.setCmdType(Integer.parseInt(result[2]));
|
|
|
+ deviceDataEntity.setSequence(Integer.parseInt(result[3]));
|
|
|
+ Double value = null;
|
|
|
+ if (CmdEnum.TEMPERATURE.getTypeNum().equals(cmd) || CmdEnum.HUMIDITY.getTypeNum().equals(cmd)) {
|
|
|
+ value = new BigDecimal(result[4]).divide(new BigDecimal("10")).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
+ } else if (CmdEnum.GAS.getTypeNum().equals(cmd)) {
|
|
|
+ value = Double.parseDouble(result[4]);
|
|
|
+ }
|
|
|
+ if (value == null) {
|
|
|
+ throw new RRException("传入数据包的数据字段为空,请检查!");
|
|
|
+ }
|
|
|
+ deviceDataEntity.setValue(value);
|
|
|
+ deviceDataEntity.setTime(result[5]);
|
|
|
+ deviceDataEntity.setVerify(Integer.parseInt(result[6]));
|
|
|
+ deviceDataEntity.setCmdEnd(result[7]);
|
|
|
+ deviceDataDao.insert(deviceDataEntity);
|
|
|
+
|
|
|
+ //获取设备信息并校验
|
|
|
+ String deviceJson = JSONObject.toJSONString(managementFeignService.deviceInfo(jqId).get("device"));
|
|
|
+ DeviceEntity deviceEntity = JSONObject.parseObject(deviceJson, DeviceEntity.class);
|
|
|
+ if (deviceEntity == null) {
|
|
|
+ throw new RRException("没有获取到设备信息,请联系管理员!");
|
|
|
+ }
|
|
|
+ //保存室内环境数据
|
|
|
+ IndoorEnvironmentEntity indoorEnvironmentEntity = new IndoorEnvironmentEntity();
|
|
|
+ Integer farmId = deviceEntity.getFarmId();
|
|
|
+ indoorEnvironmentEntity.setFarmId(farmId);
|
|
|
+ Integer pigstyId = deviceEntity.getPigstyId();
|
|
|
+ indoorEnvironmentEntity.setPigstyId(pigstyId);
|
|
|
+ indoorEnvironmentEntity.setValue(value);
|
|
|
+ indoorEnvironmentEntity.setCollectTime(new Date());
|
|
|
+
|
|
|
+ Map<String, Double> map = managementFeignService.selectByType((short) 1);
|
|
|
+ indoorEnvironmentEntity.setType(1);
|
|
|
+ handleDataPackageService.handleTemperature(indoorEnvironmentEntity, value, farmId, pigstyId, map);
|
|
|
}
|
|
|
//湿度
|
|
|
if (cmd.equals(XtAppConstant.SOCKET_SJSC_CMD_8)) {
|
|
|
+
|
|
|
+ DeviceDataEntity deviceDataEntity = new DeviceDataEntity();
|
|
|
+ deviceDataEntity.setCmdHeader(result[0]);
|
|
|
+ String jqId = result[1];
|
|
|
+ deviceDataEntity.setJqId(jqId);
|
|
|
+ deviceDataEntity.setCmdType(Integer.parseInt(result[2]));
|
|
|
+ deviceDataEntity.setSequence(Integer.parseInt(result[3]));
|
|
|
+ Double value = null;
|
|
|
+ if (CmdEnum.TEMPERATURE.getTypeNum().equals(cmd) || CmdEnum.HUMIDITY.getTypeNum().equals(cmd)) {
|
|
|
+ value = new BigDecimal(result[4]).divide(new BigDecimal("10")).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
+ } else if (CmdEnum.GAS.getTypeNum().equals(cmd)) {
|
|
|
+ value = Double.parseDouble(result[4]);
|
|
|
+ }
|
|
|
+ if (value == null) {
|
|
|
+ throw new RRException("传入数据包的数据字段为空,请检查!");
|
|
|
+ }
|
|
|
+ deviceDataEntity.setValue(value);
|
|
|
+ deviceDataEntity.setTime(result[5]);
|
|
|
+ deviceDataEntity.setVerify(Integer.parseInt(result[6]));
|
|
|
+ deviceDataEntity.setCmdEnd(result[7]);
|
|
|
+ deviceDataDao.insert(deviceDataEntity);
|
|
|
+
|
|
|
+ //获取设备信息并校验
|
|
|
+ String deviceJson = JSONObject.toJSONString(managementFeignService.deviceInfo(jqId).get("device"));
|
|
|
+ DeviceEntity deviceEntity = JSONObject.parseObject(deviceJson, DeviceEntity.class);
|
|
|
+ if (deviceEntity == null) {
|
|
|
+ throw new RRException("没有获取到设备信息,请联系管理员!");
|
|
|
+ }
|
|
|
+ //保存室内环境数据
|
|
|
+ IndoorEnvironmentEntity indoorEnvironmentEntity = new IndoorEnvironmentEntity();
|
|
|
+ Integer farmId = deviceEntity.getFarmId();
|
|
|
+ indoorEnvironmentEntity.setFarmId(farmId);
|
|
|
+ Integer pigstyId = deviceEntity.getPigstyId();
|
|
|
+ indoorEnvironmentEntity.setPigstyId(pigstyId);
|
|
|
+ indoorEnvironmentEntity.setValue(value);
|
|
|
+ indoorEnvironmentEntity.setCollectTime(new Date());
|
|
|
+
|
|
|
+ Map<String, Double> map = managementFeignService.selectByType((short) 1);
|
|
|
+
|
|
|
+ indoorEnvironmentEntity.setType(2);
|
|
|
+ handleDataPackageService.handleHumidity(indoorEnvironmentEntity, value, farmId, pigstyId, map);
|
|
|
}
|
|
|
//氨气
|
|
|
if (cmd.equals(XtAppConstant.SOCKET_SJSC_CMD_9)) {
|
|
|
+ DeviceDataEntity deviceDataEntity = new DeviceDataEntity();
|
|
|
+ deviceDataEntity.setCmdHeader(result[0]);
|
|
|
+ String jqId = result[1];
|
|
|
+ deviceDataEntity.setJqId(jqId);
|
|
|
+ deviceDataEntity.setCmdType(Integer.parseInt(result[2]));
|
|
|
+ deviceDataEntity.setSequence(Integer.parseInt(result[3]));
|
|
|
+ Double value = null;
|
|
|
+ if (CmdEnum.TEMPERATURE.getTypeNum().equals(cmd) || CmdEnum.HUMIDITY.getTypeNum().equals(cmd)) {
|
|
|
+ value = new BigDecimal(result[4]).divide(new BigDecimal("10")).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
+ } else if (CmdEnum.GAS.getTypeNum().equals(cmd)) {
|
|
|
+ value = Double.parseDouble(result[4]);
|
|
|
+ }
|
|
|
+ if (value == null) {
|
|
|
+ throw new RRException("传入数据包的数据字段为空,请检查!");
|
|
|
+ }
|
|
|
+ deviceDataEntity.setValue(value);
|
|
|
+ deviceDataEntity.setTime(result[5]);
|
|
|
+ deviceDataEntity.setVerify(Integer.parseInt(result[6]));
|
|
|
+ deviceDataEntity.setCmdEnd(result[7]);
|
|
|
+ deviceDataDao.insert(deviceDataEntity);
|
|
|
+
|
|
|
+ //获取设备信息并校验
|
|
|
+ String deviceJson = JSONObject.toJSONString(managementFeignService.deviceInfo(jqId).get("device"));
|
|
|
+ DeviceEntity deviceEntity = JSONObject.parseObject(deviceJson, DeviceEntity.class);
|
|
|
+ if (deviceEntity == null) {
|
|
|
+ throw new RRException("没有获取到设备信息,请联系管理员!");
|
|
|
+ }
|
|
|
+ //保存室内环境数据
|
|
|
+ IndoorEnvironmentEntity indoorEnvironmentEntity = new IndoorEnvironmentEntity();
|
|
|
+ Integer farmId = deviceEntity.getFarmId();
|
|
|
+ indoorEnvironmentEntity.setFarmId(farmId);
|
|
|
+ Integer pigstyId = deviceEntity.getPigstyId();
|
|
|
+ indoorEnvironmentEntity.setPigstyId(pigstyId);
|
|
|
+ indoorEnvironmentEntity.setValue(value);
|
|
|
+ indoorEnvironmentEntity.setCollectTime(new Date());
|
|
|
+
|
|
|
+ Map<String, Double> map = managementFeignService.selectByType((short) 1);
|
|
|
+ indoorEnvironmentEntity.setType(3);
|
|
|
+ handleDataPackageService.handleGas(indoorEnvironmentEntity, value, farmId, pigstyId, map);
|
|
|
|
|
|
}
|
|
|
//氨气
|
|
@@ -591,9 +664,22 @@ public class ClientDataPacketServiceImpl implements IClientDataPacketService {
|
|
|
}
|
|
|
//耗水
|
|
|
if (cmd.equals(XtAppConstant.SOCKET_SJSC_CMD_61)) {
|
|
|
+ ConsumeWarterEntity consumeWarterEntity= new ConsumeWarterEntity();
|
|
|
+ consumeWarterEntity.setCollectTime(new Date());
|
|
|
+ consumeWarterEntity.setDeviceId(Integer.parseInt(jqid));
|
|
|
+ consumeWarterEntity.setConsumeWarter(Double.parseDouble(sj));
|
|
|
+ consumeWarterDao.insert(consumeWarterEntity);
|
|
|
+
|
|
|
}
|
|
|
//耗电
|
|
|
if (cmd.equals(XtAppConstant.SOCKET_SJSC_CMD_62)) {
|
|
|
+
|
|
|
+ ConsumeElectricEntity consumeElectricEntity= new ConsumeElectricEntity();
|
|
|
+ consumeElectricEntity.setCollectTime(new Date());
|
|
|
+ consumeElectricEntity.setDeviceId(Integer.parseInt(jqid));
|
|
|
+ consumeElectricEntity.setConsumeElectric(Double.parseDouble(sj));
|
|
|
+ consumeElectricDao.insert(consumeElectricEntity);
|
|
|
+
|
|
|
}
|
|
|
//液位数据上传
|
|
|
if (cmd.equals(XtAppConstant.SOCKET_SJSC_CMD_70)) {
|