更新 RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/outside/service/impl/OutSideServiceImpl.java

merge
This commit is contained in:
bieshande 2025-02-08 13:31:08 +08:00
parent 51a92e9796
commit 84b24e8f0a
1 changed files with 41 additions and 26 deletions

View File

@ -36,25 +36,27 @@ public class OutSideServiceImpl implements OutSideService {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode rootNode = objectMapper.readTree(jsonData);
for (JsonNode sensorNode : rootNode.get("sensorDatas")) {
sensorData.setSn(sn);
sensorData.setFlag(sensorNode.get("flag").asText());
sensorData.setDs(sensorNode.get("gas_value").asText());
sensorData.setJcjd(sensorNode.get("gas_dec").asInt());
// gas_status 转换为中文状态描述
int gasStatus = sensorNode.get("gas_status").asInt();
String statusDescription = getStatusDescription(gasStatus); // 调用转换方法
sensorData.setZt(statusDescription);
sensorData.setZl(sensorNode.get("gas_type").asText());
// gas_unit 转换为对应单位
int gasUnit = sensorNode.get("gas_unit").asInt();
String unitDescription = getUnitDescription(gasUnit); // 调用转换方法
sensorData.setDw(unitDescription); // 将中文单位设置到 dw 字段
sensorData.setDbz(sensorNode.get("alarml").asText());
sensorData.setGbz(sensorNode.get("alarmh").asText());
sensorData.setLc(sensorNode.get("gas_range").asText());
sensorData.setJcjd(sensorNode.get("gas_dec").asInt());//检测精度
sensorData.setReportTime(DateUtils.getTime());
outSideMapper.insertDevice(sensorData);
if (sensorNode.get("flag").asInt()==1) {
sensorData.setSn(sn);
sensorData.setFlag(sensorNode.get("flag").asText());
sensorData.setDs(sensorNode.get("gas_value").asText());
sensorData.setJcjd(sensorNode.get("gas_dec").asInt());
// gas_status 转换为中文状态描述
int gasStatus = sensorNode.get("gas_status").asInt();
String statusDescription = getStatusDescription(gasStatus); // 调用转换方法
sensorData.setZt(statusDescription);
sensorData.setZl(sensorNode.get("gas_type").asText());
// gas_unit 转换为对应单位
int gasUnit = sensorNode.get("gas_unit").asInt();
String unitDescription = getUnitDescription(gasUnit); // 调用转换方法
sensorData.setDw(unitDescription); // 将中文单位设置到 dw 字段
sensorData.setDbz(sensorNode.get("alarml").asText());
sensorData.setGbz(sensorNode.get("alarmh").asText());
sensorData.setLc(sensorNode.get("gas_range").asText());
sensorData.setJcjd(sensorNode.get("gas_dec").asInt());//检测精度
sensorData.setReportTime(DateUtils.getTime());
outSideMapper.insertDevice(sensorData);
}
}
return 1;
} catch (Exception e) {
@ -76,8 +78,12 @@ public class OutSideServiceImpl implements OutSideService {
String lastMonth = previousMonth.format(formatter);
List<SensorMonth> list = outSideMapper.queryMonth(lastMonth);
outSideMapper.insertMonth(list);
return 1;
if(list.size()>0){
outSideMapper.insertMonth(list);
return 1;
}else{
return 0;
}
}
@Override
@ -87,16 +93,25 @@ public class OutSideServiceImpl implements OutSideService {
// 判断是否是数组
if (rootNode.isArray()) {
for (JsonNode node : rootNode) {
SensorData sd = insertOldData(node);
outSideMapper.insertDevice(sd);
if (node.get("type").asInt()==5) {
SensorData sd = insertOldData(node);
outSideMapper.deleteSampleDevice(sd.getSn(),sd.getReportTime());
outSideMapper.insertDevice(sd);
}
}
} else {
SensorData sd = insertOldData(rootNode);
outSideMapper.insertDevice(sd);
}
// else {
// SensorData sd = insertOldData(rootNode);
// outSideMapper.insertDevice(sd);
// }
return 0;
}
@Override
public Integer updateData(String date) {
return outSideMapper.updateData(date);
}
private static SensorData insertOldData(JsonNode node) {
/**
* sn: equipmentUId