太阳能图标数据查询修复

This commit is contained in:
wyw 2024-08-13 20:39:19 +08:00
parent 8c91613468
commit d8a171692a
2 changed files with 36 additions and 28 deletions

View File

@ -1640,9 +1640,13 @@ public class DeviceServiceImpl implements IDeviceService {
List<DeviceLog> deviceLogs= logService.selectDataList(kvHashMap);
Map<String, List<DeviceLog>> collect = deviceLogs != null ? deviceLogs.stream().collect(Collectors.groupingBy(t -> t.getIdentity())): new HashMap();
for (ThingsModel modelDevice : thingsModels) {
if(modelDevice.getIsChart().equals(0)){
continue;
}
HashMap<String, Object> dataListMap = new HashMap<>();
List<DeviceLog> deviceLogs1 = collect.get(modelDevice.getIdentifier());
deviceLogs1.sort(Comparator.comparing(DeviceLog::getCreateTime));
dataListMap.put("name", modelDevice.getModelName());
if (StringUtils.isNotEmpty(modelDevice.getSpecs())) {
cn.hutool.json.JSONObject object = new cn.hutool.json.JSONObject(modelDevice.getSpecs());
@ -1652,7 +1656,7 @@ public class DeviceServiceImpl implements IDeviceService {
}
if (deviceLogs1 != null) {
System.out.println(deviceLogs1);
dataListMap.put("time",deviceLogs1.stream().map(t->t.getCreateTime()).collect(Collectors.toList()));
dataListMap.put("time",deviceLogs1.stream().map(t->DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,t.getCreateTime())).collect(Collectors.toList()));
dataListMap.put("data",deviceLogs1.stream().map(t->t.getLogValue()).collect(Collectors.toList()));
}else{
dataListMap.put("time",new ArrayList<>());

View File

@ -151,32 +151,36 @@ public class MySqlLogServiceImpl implements ILogService {
@Override
public List<DeviceLog> selectDataList(HashMap<String, Object> kvHashMap) {
if (kvHashMap.get("endTime") != null) {
DateTime endTime = DateUtil.parse(kvHashMap.get("endTime").toString());
String yyyyMM = endTime.toString("yyyyMM");
String yyyyMM2 = DateUtil.offsetMonth(endTime, -1).toString("yyyyMM");
if (tableMapper.getTableByName(tableName + yyyyMM) == null) {
deviceLogMapper.createTableByDate(tableName + yyyyMM);
}
if (tableMapper.getTableByName(tableName + yyyyMM2) == null) {
deviceLogMapper.createTableByDate(tableName + yyyyMM2);
}
kvHashMap.put("tableName", tableName + yyyyMM);
kvHashMap.put("tableName2", tableName + yyyyMM2);
}
if (kvHashMap.get("tableName") == null) {
Date date = new Date();
String ym = DateUtils.parseDateToStr(DateUtils.YYYYMM, date);
String ym2 = DateUtils.parseDateToStr(DateUtils.YYYYMM, DateUtil.offsetMonth(new Date(), -1));
if (tableMapper.getTableByName(tableName + ym) == null) {
deviceLogMapper.createTableByDate(tableName + ym);
}
if (tableMapper.getTableByName(tableName + ym2) == null) {
deviceLogMapper.createTableByDate(tableName + ym2);
}
kvHashMap.put("tableName", tableName + ym);
kvHashMap.put("tableName2", tableName + ym2);
}
return deviceLogMapper.selectDataList(kvHashMap);
DeviceLog deviceLog = new DeviceLog();
deviceLog.setBeginTime(kvHashMap.get("beginTime").toString());
deviceLog.setEndTime(kvHashMap.get("endTime").toString());
deviceLog.setSerialNumber((kvHashMap.get("serialNumber").toString()));
// if (kvHashMap.get("endTime") != null) {
// DateTime endTime = DateUtil.parse(kvHashMap.get("endTime").toString());
// String yyyyMM = endTime.toString("yyyyMM");
// String yyyyMM2 = DateUtil.offsetMonth(endTime, -1).toString("yyyyMM");
// if (tableMapper.getTableByName(tableName + yyyyMM) == null) {
// deviceLogMapper.createTableByDate(tableName + yyyyMM);
// }
// if (tableMapper.getTableByName(tableName + yyyyMM2) == null) {
// deviceLogMapper.createTableByDate(tableName + yyyyMM2);
// }
// kvHashMap.put("tableName", tableName + yyyyMM);
// kvHashMap.put("tableName2", tableName + yyyyMM2);
// }
// if (kvHashMap.get("tableName") == null) {
// Date date = new Date();
// String ym = DateUtils.parseDateToStr(DateUtils.YYYYMM, date);
// String ym2 = DateUtils.parseDateToStr(DateUtils.YYYYMM, DateUtil.offsetMonth(new Date(), -1));
// if (tableMapper.getTableByName(tableName + ym) == null) {
// deviceLogMapper.createTableByDate(tableName + ym);
// }
// if (tableMapper.getTableByName(tableName + ym2) == null) {
// deviceLogMapper.createTableByDate(tableName + ym2);
// }
// kvHashMap.put("tableName", tableName + ym);
// kvHashMap.put("tableName2", tableName + ym2);
// }
return deviceLogMapper.selectDeviceLogList(deviceLog);
}
}