更新 RuoYi-Vue-Oracle/src/main/java/com/ruoyi/project/outside/service/impl/OutSideServiceImpl.java
日期格式修复
This commit is contained in:
parent
feba70636d
commit
51a92e9796
|
@ -11,9 +11,14 @@ import com.ruoyi.project.outside.service.OutSideService;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.YearMonth;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@Service
|
||||
public class OutSideServiceImpl implements OutSideService {
|
||||
|
@ -31,27 +36,25 @@ public class OutSideServiceImpl implements OutSideService {
|
|||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
JsonNode rootNode = objectMapper.readTree(jsonData);
|
||||
for (JsonNode sensorNode : rootNode.get("sensorDatas")) {
|
||||
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);
|
||||
}
|
||||
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) {
|
||||
|
@ -73,13 +76,8 @@ public class OutSideServiceImpl implements OutSideService {
|
|||
String lastMonth = previousMonth.format(formatter);
|
||||
|
||||
List<SensorMonth> list = outSideMapper.queryMonth(lastMonth);
|
||||
if(list.size()>0){
|
||||
outSideMapper.insertMonth(list);
|
||||
return 1;
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
|
||||
outSideMapper.insertMonth(list);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -89,42 +87,44 @@ public class OutSideServiceImpl implements OutSideService {
|
|||
// 判断是否是数组
|
||||
if (rootNode.isArray()) {
|
||||
for (JsonNode node : rootNode) {
|
||||
if (node.get("type").asInt()==5) {
|
||||
SensorData sd = insertOldData(node);
|
||||
outSideMapper.deleteSampleDevice(sd.getSn(),sd.getReportTime());
|
||||
outSideMapper.insertDevice(sd);
|
||||
}
|
||||
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
|
||||
* ds: vocRtd
|
||||
* report_time: vocTime
|
||||
* zt: vocRtd > 4 ? '一级报警' : '正常'
|
||||
* zt: vocRtd > 5 ? '一级报警' : '正常'
|
||||
*/
|
||||
|
||||
SensorData sensorData = new SensorData();
|
||||
sensorData.setSn(node.get("equipmentUId").asText());
|
||||
sensorData.setDs(node.get("vocRtd").asText());
|
||||
sensorData.setDw("mg/m3");
|
||||
sensorData.setDw(getUnitDescription(5));
|
||||
// "vocTime":"2024-10-30T07:19:20.000+0000" 转为 yyyy-MM-dd HH:mm:ss
|
||||
String reportTime = node.get("vocTime").asText().replace("T", " ").substring(0, 19);
|
||||
sensorData.setReportTime(reportTime);
|
||||
//String reportTime = node.get("vocTime").asText().replace("T", " ").substring(0, 19);
|
||||
|
||||
sensorData.setZt(node.get("vocRtd").asInt() > 4 ? "一级报警" : "正常");
|
||||
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSSZ");
|
||||
String reportTime = "";
|
||||
try {
|
||||
Date result = df.parse(node.get("vocTime").asText());
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
sdf.setTimeZone(TimeZone.getDefault());
|
||||
reportTime = sdf.format(result);
|
||||
sensorData.setReportTime(reportTime);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
sensorData.setZt(node.get("vocRtd").asInt() > 5 ? "一级报警" : "正常");
|
||||
return sensorData;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue