|
@@ -1,8 +1,12 @@
|
|
|
package com.huimv.env.device.service.impl;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
-import com.huimv.env.common.entity.EnvDevice;
|
|
|
-import com.huimv.env.common.entity.EnvDeviceRecentlyData;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.json.JSON;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.huimv.env.common.entity.*;
|
|
|
import com.huimv.env.common.service.*;
|
|
|
import com.huimv.env.device.service.IDeviceService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -32,6 +36,14 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
|
|
|
@Autowired
|
|
|
private IEnvHumiService envHumiService;
|
|
|
+ @Autowired
|
|
|
+ private IEnvDeviceFanService envDeviceFanService;
|
|
|
+ @Autowired
|
|
|
+ private IEnvDeviceOtherService envDeviceOtherService;
|
|
|
+ @Autowired
|
|
|
+ private IEnvDayagePeizhiService envDayagePeizhiService;
|
|
|
+ @Autowired
|
|
|
+ private IEnvFengPeizhiService envFengPeizhiService;
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
@@ -41,23 +53,24 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
String originalTempValue = dataArray[4];
|
|
|
String status = dataArray[5];
|
|
|
String time = dataArray[6];
|
|
|
-
|
|
|
- BigDecimal tempValue = new BigDecimal(originalTempValue);
|
|
|
- BigDecimal tempValueHandle = new BigDecimal(0);
|
|
|
- if (tempValue.intValue() != 0){
|
|
|
- tempValueHandle = tempValue.divide(new BigDecimal(10),1,BigDecimal.ROUND_HALF_UP);
|
|
|
- }
|
|
|
String chipId = getChipId(deviceCode,4,ordeNumber);
|
|
|
- EnvDevice envDevice = envDeviceService.getByDeviceCode(deviceCode);
|
|
|
- EnvDeviceRecentlyData envDeviceRecentlyData = envDeviceRecentlyDataService.getbyChipId(chipId);
|
|
|
Date uploadDate = DateUtil.parse(time, "yyyyMMddHHmmss");
|
|
|
+ EnvDeviceRecentlyData envDeviceRecentlyData = envDeviceRecentlyDataService.getbyChipId(chipId);
|
|
|
+ EnvDevice envDevice = envDeviceService.getByDeviceCode(deviceCode);
|
|
|
//判断传感器 故障
|
|
|
- if ("1".equals(status)){
|
|
|
+ if ("1".equals(status) || "0".equals(originalTempValue) ){
|
|
|
log.info("传感器异常,未加入流水");
|
|
|
warningService.saveWarning(uploadDate,envDeviceRecentlyData,envDevice,chipId);
|
|
|
envDeviceRecentlyDataService.updateByChipId(uploadDate,envDeviceRecentlyData,null,2);
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
+ BigDecimal tempValue = new BigDecimal(originalTempValue);
|
|
|
+ BigDecimal tempValueHandle = new BigDecimal(0);
|
|
|
+ if (tempValue.intValue() != 0){
|
|
|
+ tempValueHandle = tempValue.divide(new BigDecimal(10),1,BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+
|
|
|
//更新实时表
|
|
|
envDeviceRecentlyDataService.updateByChipId(uploadDate,envDeviceRecentlyData,tempValueHandle,1);
|
|
|
//更新流水表
|
|
@@ -74,7 +87,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
String time = dataArray[6];
|
|
|
BigDecimal humiValue = new BigDecimal(originalHumiValue);
|
|
|
BigDecimal humiValueHandle = new BigDecimal(0);
|
|
|
- if (humiValue.intValue() != 0){
|
|
|
+ if (humiValue.intValue() != 0 ){
|
|
|
humiValueHandle = humiValue.divide(new BigDecimal(10),1,BigDecimal.ROUND_HALF_UP);
|
|
|
}
|
|
|
Integer order = (Integer.parseInt(ordeNumber) + 11);
|
|
@@ -84,7 +97,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
Date uploadDate = DateUtil.parse(time, "yyyyMMddHHmmss");
|
|
|
|
|
|
//判断传感器 故障
|
|
|
- if ("1".equals(status)){
|
|
|
+ if ("1".equals(status)|| "0".equals(originalHumiValue)){
|
|
|
log.info("传感器异常,未加入流水");
|
|
|
warningService.saveWarning(uploadDate,envDeviceRecentlyData,envDevice,chipId);
|
|
|
envDeviceRecentlyDataService.updateByChipId(uploadDate,envDeviceRecentlyData,null,2);
|
|
@@ -199,6 +212,160 @@ public class DeviceServiceImpl implements IDeviceService {
|
|
|
envDeviceRecentlyDataService.updateByChipId(uploadDate,envDeviceRecentlyData,tempValueHandle,1);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void saveFengStatus(String[] dataArray) {
|
|
|
+ String deviceCode = dataArray[1];
|
|
|
+ String originalTempValue = dataArray[3];
|
|
|
+ String time = dataArray[4];
|
|
|
+ long fanNum = envDeviceFanService.count(new QueryWrapper<EnvDeviceFan>().eq("device_code", deviceCode));
|
|
|
+ //hm+1001+61+16383+20230406135801+6+end
|
|
|
+ String s = Integer.toBinaryString(Integer.parseInt(originalTempValue));
|
|
|
+ String str = getStr(s,fanNum);
|
|
|
+ int orderId = 1;
|
|
|
+ for (int i = str.length() - 1; i >= 0; i--) {
|
|
|
+ //状态
|
|
|
+ char c = str.charAt(i);
|
|
|
+ String chipId = deviceCode+"11"+orderId;
|
|
|
+ orderId++;
|
|
|
+ EnvDeviceFan deviceFan = envDeviceFanService.getOne(new QueryWrapper<EnvDeviceFan>().eq("chip_code", chipId));
|
|
|
+ System.out.println(deviceFan.toString());
|
|
|
+ if (ObjectUtil.isNotEmpty(deviceFan)){
|
|
|
+ deviceFan.setDeviceCode(deviceFan.getDeviceCode());
|
|
|
+ deviceFan.setChipStatus(c == '1' ? 1 : 0);
|
|
|
+ envDeviceFanService.updateById(deviceFan);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getStr(String s,Long fanNum) {
|
|
|
+ int length = s.length();
|
|
|
+ StringBuilder sBuilder = new StringBuilder(s);
|
|
|
+ for (int i = length; i < fanNum; i++) {
|
|
|
+ sBuilder.insert(0, "0");
|
|
|
+ }
|
|
|
+ s = sBuilder.toString();
|
|
|
+ return s;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void saveShiLianStatus(String[] dataArray) {
|
|
|
+ //hm+1001+62+1+20230408175711+5+end
|
|
|
+ String deviceCode = dataArray[1];
|
|
|
+ //0关闭 1开启
|
|
|
+ String status = dataArray[3];
|
|
|
+ String time = dataArray[4];
|
|
|
+ String chipId = deviceCode+"133";
|
|
|
+ EnvDeviceOther envDeviceOther = envDeviceOtherService.getOne(new QueryWrapper<EnvDeviceOther>().eq("chip_code", chipId));
|
|
|
+ if (ObjectUtil.isNotEmpty(envDeviceOther)){
|
|
|
+ envDeviceOther.setChipStatus(Integer.parseInt(status));
|
|
|
+ Date uploadDate = DateUtil.parse(time, "yyyyMMddHHmmss");
|
|
|
+ envDeviceOther.setUpdateTime(uploadDate);
|
|
|
+ }else {
|
|
|
+ log.info("湿帘设备为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void savePenWuStatus(String[] dataArray) {
|
|
|
+ //hm+1001+62+1+20230408175711+5+end
|
|
|
+ String deviceCode = dataArray[1];
|
|
|
+ //0关闭 1开启
|
|
|
+ String status = dataArray[3];
|
|
|
+ String time = dataArray[4];
|
|
|
+ String chipId = deviceCode+"134";
|
|
|
+ EnvDeviceOther envDeviceOther = envDeviceOtherService.getOne(new QueryWrapper<EnvDeviceOther>().eq("chip_code", chipId));
|
|
|
+ if (ObjectUtil.isNotEmpty(envDeviceOther)){
|
|
|
+ envDeviceOther.setChipStatus(Integer.parseInt(status));
|
|
|
+ Date uploadDate = DateUtil.parse(time, "yyyyMMddHHmmss");
|
|
|
+ envDeviceOther.setUpdateTime(uploadDate);
|
|
|
+ }else {
|
|
|
+ log.info("喷雾设备为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void saveDayAgePeiZhi(String[] dataArray) {
|
|
|
+ //hm+0+81+value+20230408172352+3+end
|
|
|
+ //{ "days_temp_cfg": { "level": 1, "days": 5, "target_temp": 320 }}
|
|
|
+ String deviceCode = dataArray[1];
|
|
|
+ String originalValue = dataArray[3];
|
|
|
+ String time = dataArray[4];
|
|
|
+ EnvDayagePeizhi envDayagePeizhi = new EnvDayagePeizhi();
|
|
|
+ //解析
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(originalValue);
|
|
|
+ String days_temp_cfg = jsonObject.get("days_temp_cfg").toString();
|
|
|
+ JSONObject jsonObject1 = JSONUtil.parseObj(days_temp_cfg);
|
|
|
+ Integer level = (Integer)jsonObject1.get("level");
|
|
|
+ Integer days = (Integer)jsonObject1.get("days");
|
|
|
+ Integer targetTemp = (Integer)jsonObject1.get("target_temp");
|
|
|
+ //保存
|
|
|
+ envDayagePeizhi.setDays(days);
|
|
|
+ envDayagePeizhi.setDeviceCode(deviceCode);
|
|
|
+ envDayagePeizhi.setLevelDayage(level);
|
|
|
+ envDayagePeizhi.setDeployName(time);
|
|
|
+ //将引号转为 \"
|
|
|
+ envDayagePeizhi.setOriginalValue(days_temp_cfg.replaceAll("\"","\\\\\""));
|
|
|
+ BigDecimal bigDecimal = new BigDecimal(targetTemp);
|
|
|
+ BigDecimal tempValue = new BigDecimal(0);
|
|
|
+ if (bigDecimal.intValue() != 0){
|
|
|
+ tempValue =bigDecimal.divide(new BigDecimal(10),1,BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+ envDayagePeizhi.setTargetTemp(tempValue);
|
|
|
+ envDayagePeizhi.setTimeDayage(DateUtil.parse(time, "yyyyMMddHHmmss"));
|
|
|
+ envDayagePeizhiService.save(envDayagePeizhi);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void saveFengPeiZhi(String[] dataArray) {
|
|
|
+ //hm+0+81+value+20230408172352+3+end
|
|
|
+ //{ "air_fans_cfg": { "level": 8, "temp_diff": 0, "fan_enable": 255, "cycle_mode": 255, "run_gap": 65535, "stop_gap": 65535, "var_fan_enable": 255, "speed": 255, "fans_ctrl": 16383, "var_fans_ctrl": 1 }}
|
|
|
+ String deviceCode = dataArray[1];
|
|
|
+ String originalValue = dataArray[3];
|
|
|
+ String time = dataArray[4];
|
|
|
+ EnvFengPeizhi envDayagePeizhi = new EnvFengPeizhi();
|
|
|
+ //解析
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(originalValue);
|
|
|
+ String air_fans_cfg = jsonObject.get("air_fans_cfg").toString();
|
|
|
+ JSONObject jsonObject1 = JSONUtil.parseObj(air_fans_cfg);
|
|
|
+
|
|
|
+ Integer level = (Integer)jsonObject1.get("level");
|
|
|
+ Integer tempDiff = (Integer)jsonObject1.get("temp_diff");
|
|
|
+ Integer fanEnable = (Integer)jsonObject1.get("fan_enable");
|
|
|
+ Integer cycleMode = (Integer)jsonObject1.get("cycle_mode");
|
|
|
+ Integer runGap = (Integer)jsonObject1.get("run_gap");
|
|
|
+ Integer stopGap = (Integer)jsonObject1.get("stop_gap");
|
|
|
+ Integer varFanEnable = (Integer)jsonObject1.get("var_fan_enable");
|
|
|
+ Integer speed = (Integer)jsonObject1.get("speed");
|
|
|
+ Integer fansCtrl = (Integer)jsonObject1.get("fans_ctrl");
|
|
|
+ Integer varFansCtrl = (Integer)jsonObject1.get("var_fans_ctrl");
|
|
|
+ //保存
|
|
|
+ envDayagePeizhi.setLevelFeng(level);
|
|
|
+ envDayagePeizhi.setFanEnable(fanEnable);
|
|
|
+ envDayagePeizhi.setCycleMode(cycleMode);
|
|
|
+ envDayagePeizhi.setRunGap(runGap);
|
|
|
+ envDayagePeizhi.setStopGap(stopGap);
|
|
|
+ envDayagePeizhi.setVarFanEnable(varFanEnable);
|
|
|
+ envDayagePeizhi.setSpeed(speed);
|
|
|
+
|
|
|
+ String s =Integer.toBinaryString(fansCtrl);
|
|
|
+ long fanNum = envDeviceFanService.count(new QueryWrapper<EnvDeviceFan>().eq("device_code", deviceCode));
|
|
|
+ String str = getStr(s,fanNum);
|
|
|
+ envDayagePeizhi.setFansCtrl(str);
|
|
|
+ envDayagePeizhi.setVarFansCtrl(varFansCtrl);
|
|
|
+ BigDecimal bigDecimal = new BigDecimal(tempDiff);
|
|
|
+ BigDecimal tempValue = new BigDecimal(0);
|
|
|
+ if (bigDecimal.intValue() != 0){
|
|
|
+ tempValue =bigDecimal.divide(new BigDecimal(10),1,BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+ envDayagePeizhi.setTempDiff(tempValue);
|
|
|
+ envDayagePeizhi.setDeviceCode(deviceCode);
|
|
|
+ envDayagePeizhi.setDeployName(time);
|
|
|
+ envDayagePeizhi.setOriginalValue(air_fans_cfg.replaceAll("\"","\\\\\""));
|
|
|
+ envDayagePeizhi.setTimeFeng(DateUtil.parse(time, "yyyyMMddHHmmss"));
|
|
|
+ envFengPeizhiService.save(envDayagePeizhi);
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
private String getChipId(String deviceCode, int type, String ordeNumber) {
|
|
|
//温度
|