|
|
|
@ -125,7 +125,7 @@ public class EnergyServiceImpl implements IEnergyService {
|
|
|
|
|
int pageNum = Integer.parseInt(String.valueOf(vo.getPageNum())); |
|
|
|
|
int pageSize = Integer.parseInt(String.valueOf(vo.getPageSize())); |
|
|
|
|
if (pageNum != 0) { |
|
|
|
|
int startIndex = (pageNum-1)*pageSize; |
|
|
|
|
int startIndex = (pageNum - 1) * pageSize; |
|
|
|
|
int endIndex = Math.min(pageNum * pageSize, timeStr.size()); |
|
|
|
|
value = value.subList(startIndex, endIndex); |
|
|
|
|
column.setValue(getArrChillerLine(value, timeStr.subList(startIndex, endIndex).toArray(new String[0]))); |
|
|
|
@ -144,7 +144,7 @@ public class EnergyServiceImpl implements IEnergyService {
|
|
|
|
|
map.put("timeStr", timeStr); |
|
|
|
|
map.put("dataList", columnData); |
|
|
|
|
} else { |
|
|
|
|
int startIndex = (pageNum-1) * pageSize; |
|
|
|
|
int startIndex = (pageNum - 1) * pageSize; |
|
|
|
|
int endIndex = Math.min(pageNum * pageSize, timeStr.size()); |
|
|
|
|
if (startIndex > endIndex) { |
|
|
|
|
return AjaxResult.success(new ArrayList<>(map.entrySet())); |
|
|
|
@ -194,8 +194,8 @@ public class EnergyServiceImpl implements IEnergyService {
|
|
|
|
|
futures.add(executor.submit(() -> { |
|
|
|
|
// 折线图,都查询min表
|
|
|
|
|
// 多表
|
|
|
|
|
String lastTable = "data_min" + vo.getStartTime().substring(0,4); |
|
|
|
|
String curTable = "data_min" + vo.getEndTime().substring(0,4); |
|
|
|
|
String lastTable = "data_min" + vo.getStartTime().substring(0, 4); |
|
|
|
|
String curTable = "data_min" + vo.getEndTime().substring(0, 4); |
|
|
|
|
List<ConsumptionAnalyze> consumptionAnalyzeEntities = energyMapper.queryDeviceLineManyTable(vo.getStartTime(), vo.getEndTime(), lastTable, curTable, vo.getDeviceType(), vo.getSystemType()); |
|
|
|
|
if (null == consumptionAnalyzeEntities || consumptionAnalyzeEntities.size() == 0) { |
|
|
|
|
latch.countDown(); |
|
|
|
@ -241,10 +241,10 @@ public class EnergyServiceImpl implements IEnergyService {
|
|
|
|
|
energyConsumptionDTO.setLineTimes((String[]) allData.get("timeStrLineArr")); |
|
|
|
|
List<Map<String, Object>> listData = new ArrayList<>(); |
|
|
|
|
Map<String, Object> meter = new HashMap<>(); |
|
|
|
|
meter.put("meter",allData.get("meterArr")); |
|
|
|
|
meter.put("meter", allData.get("meterArr")); |
|
|
|
|
listData.add(meter); |
|
|
|
|
Map<String, Object> lineMeter = new HashMap<>(); |
|
|
|
|
lineMeter.put("lineMeter",allData.get("meterLineArr")); |
|
|
|
|
lineMeter.put("lineMeter", allData.get("meterLineArr")); |
|
|
|
|
listData.add(lineMeter); |
|
|
|
|
energyConsumptionDTO.setData(listData); |
|
|
|
|
return AjaxResult.success(energyConsumptionDTO); |
|
|
|
@ -312,10 +312,10 @@ public class EnergyServiceImpl implements IEnergyService {
|
|
|
|
|
try { |
|
|
|
|
double cold = Math.round(Double.parseDouble(coldArr[i]) * 100) / 100.0; |
|
|
|
|
double meter = Math.round(Double.parseDouble(meterArr[i]) * 100) / 100.0; |
|
|
|
|
double cop = Math.round((meter==0 ? 0.00 : cold/ meter) * 100) / 100.0; |
|
|
|
|
double cop = Math.round((meter == 0 ? 0.00 : cold / meter) * 100) / 100.0; |
|
|
|
|
copArr[i] = String.valueOf(cop); |
|
|
|
|
} catch (NumberFormatException e) { |
|
|
|
|
log.error("处理累计能耗异常==>",e); |
|
|
|
|
log.error("处理累计能耗异常==>", e); |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -375,10 +375,10 @@ public class EnergyServiceImpl implements IEnergyService {
|
|
|
|
|
try { |
|
|
|
|
double cold = Math.round(Double.parseDouble(lineEfrColdArr[i]) * 100) / 100.0; |
|
|
|
|
double meter = Math.round(Double.parseDouble(lineInstantaneousMeterArr[i]) * 100) / 100.0; |
|
|
|
|
double cop = Math.round((meter==0 ? 0.00 : cold/ meter) * 100) / 100.0; |
|
|
|
|
double cop = Math.round((meter == 0 ? 0.00 : cold / meter) * 100) / 100.0; |
|
|
|
|
lineCopArr[i] = String.valueOf(cop); |
|
|
|
|
} catch (NumberFormatException e) { |
|
|
|
|
log.error("处理累计能耗异常==>",e); |
|
|
|
|
log.error("处理累计能耗异常==>", e); |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -432,13 +432,13 @@ public class EnergyServiceImpl implements IEnergyService {
|
|
|
|
|
meterLine.put("lineMeter", allData.get("lineMeterArr")); |
|
|
|
|
listData.add(meterLine); |
|
|
|
|
Map<String, Object> copLine = new HashMap<>(); |
|
|
|
|
copLine.put("lineCop",allData.get("lineCopArr")); |
|
|
|
|
copLine.put("lineCop", allData.get("lineCopArr")); |
|
|
|
|
listData.add(copLine); |
|
|
|
|
Map<String, Object> instantaneousColdLine = new HashMap<>(); |
|
|
|
|
instantaneousColdLine.put("lineInstantaneousCold",allData.get("lineInstantaneousColdArr")); |
|
|
|
|
instantaneousColdLine.put("lineInstantaneousCold", allData.get("lineInstantaneousColdArr")); |
|
|
|
|
listData.add(instantaneousColdLine); |
|
|
|
|
Map<String, Object> instantaneousMeterLine = new HashMap<>(); |
|
|
|
|
instantaneousMeterLine.put("lineInstantaneousMeter",allData.get("lineInstantaneousMeterArr")); |
|
|
|
|
instantaneousMeterLine.put("lineInstantaneousMeter", allData.get("lineInstantaneousMeterArr")); |
|
|
|
|
listData.add(instantaneousMeterLine); |
|
|
|
|
energyConsumptionDTO.setData(listData); |
|
|
|
|
return AjaxResult.success(energyConsumptionDTO); |
|
|
|
@ -462,8 +462,8 @@ public class EnergyServiceImpl implements IEnergyService {
|
|
|
|
|
public AjaxResult yoy(EnergyConsumptionVO vo) { |
|
|
|
|
// 获取今年的值
|
|
|
|
|
List<ConsumptionAnalyze> consumptionAnalyzeEntities; |
|
|
|
|
String lastTableName = "data_"+vo.getTimeType(); |
|
|
|
|
String curTableName = "data_"+vo.getTimeType(); |
|
|
|
|
String lastTableName = "data_" + vo.getTimeType(); |
|
|
|
|
String curTableName = "data_" + vo.getTimeType(); |
|
|
|
|
String startTime = vo.getStartTime(); |
|
|
|
|
String endTime = vo.getEndTime(); |
|
|
|
|
String deviceType = vo.getParamType(); |
|
|
|
@ -478,8 +478,8 @@ public class EnergyServiceImpl implements IEnergyService {
|
|
|
|
|
// curTableName = "data_min_cop";
|
|
|
|
|
// deviceType = "system";
|
|
|
|
|
} else { |
|
|
|
|
lastTableName = lastTableName+startTime.substring(0,4); |
|
|
|
|
curTableName = curTableName+endTime.substring(0,4); |
|
|
|
|
lastTableName = lastTableName + startTime.substring(0, 4); |
|
|
|
|
curTableName = curTableName + endTime.substring(0, 4); |
|
|
|
|
} |
|
|
|
|
String timeType = vo.getTimeType(); |
|
|
|
|
if (!(lastTableName.equalsIgnoreCase(curTableName)) && ("hour".equalsIgnoreCase(timeType) || "day".equalsIgnoreCase(timeType))) { |
|
|
|
@ -487,11 +487,11 @@ public class EnergyServiceImpl implements IEnergyService {
|
|
|
|
|
// 获取上一期的时间
|
|
|
|
|
startTime = DateUtils.yoyDate(startTime); |
|
|
|
|
endTime = DateUtils.yoyDate(endTime); |
|
|
|
|
String yoyLastTableName = lastTableName.substring(0, lastTableName.length() - 4) + startTime.substring(0,4); |
|
|
|
|
String yoyCurTableName = curTableName.substring(0, lastTableName.length() - 4) + endTime.substring(0,4); |
|
|
|
|
String yoyLastTableName = lastTableName.substring(0, lastTableName.length() - 4) + startTime.substring(0, 4); |
|
|
|
|
String yoyCurTableName = curTableName.substring(0, lastTableName.length() - 4) + endTime.substring(0, 4); |
|
|
|
|
consumptionAnalyzeEntities = energyMapper.queryManyTableYoy(vo.getStartTime(), vo.getEndTime(), lastTableName, curTableName, |
|
|
|
|
startTime, endTime, yoyLastTableName, yoyCurTableName, getTimeLen(vo.getTimeType()), deviceType, vo.getTimeType(), vo.getSystemType()); |
|
|
|
|
} else { |
|
|
|
|
} else { |
|
|
|
|
// 单表
|
|
|
|
|
startTime = DateUtils.yoyDate(startTime); |
|
|
|
|
endTime = DateUtils.yoyDate(endTime); |
|
|
|
@ -523,7 +523,8 @@ public class EnergyServiceImpl implements IEnergyService {
|
|
|
|
|
// 获取电量读数
|
|
|
|
|
vo.setParamType("5"); |
|
|
|
|
AjaxResult meterData = yoy(vo); |
|
|
|
|
EnergyConsumptionDTO meterEnergyData = (EnergyConsumptionDTO) meterData.get("data");; |
|
|
|
|
EnergyConsumptionDTO meterEnergyData = (EnergyConsumptionDTO) meterData.get("data"); |
|
|
|
|
; |
|
|
|
|
if (meterEnergyData == null) { |
|
|
|
|
return AjaxResult.error(); |
|
|
|
|
} |
|
|
|
@ -584,28 +585,47 @@ public class EnergyServiceImpl implements IEnergyService {
|
|
|
|
|
List<String> meterCurDataList = new ArrayList<>(Arrays.asList(meterCurData)); |
|
|
|
|
List<String> meterLastDataList = new ArrayList<>(Arrays.asList(meterLastData)); |
|
|
|
|
|
|
|
|
|
if (timeAList.size() < timeBList.size()) { |
|
|
|
|
for (String time : timeBList) { |
|
|
|
|
if (!timeAList.contains(time)) { |
|
|
|
|
timeAList.add(time); |
|
|
|
|
cloudCurDataList.add("0"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 遍历 timeB,补齐 timeA 缺失的部分,并在 cloud 数据中插入 0
|
|
|
|
|
for (int i = 0; i < timeBList.size(); i++) { |
|
|
|
|
String time = timeBList.get(i); |
|
|
|
|
int indexInTimeA = timeAList.indexOf(time); |
|
|
|
|
|
|
|
|
|
if (indexInTimeA == -1) { |
|
|
|
|
// timeB[i] 在 timeA 中不存在,需要在 cloud 的 list 中插入 "0"
|
|
|
|
|
cloudCurDataList.add(i, "0"); |
|
|
|
|
cloudLastDataList.add(i, "0"); |
|
|
|
|
timeAList.add(i, time); // 同步更新时间列表
|
|
|
|
|
} else if (indexInTimeA != i) { |
|
|
|
|
// 如果顺序不同,同步调整 cloud 列表
|
|
|
|
|
// 这里可以考虑排序后统一处理,或者抛出异常提示时间顺序不一致
|
|
|
|
|
log.warn("时间顺序不一致,请确保输入时间已排序"); |
|
|
|
|
} |
|
|
|
|
meterEnergyData.setTimes(timeAList.toArray(new String[0])); |
|
|
|
|
cloudCurData = cloudCurDataList.toArray(new String[0]); |
|
|
|
|
cloudLastData = cloudLastDataList.toArray(new String[0]); |
|
|
|
|
} else if (timeBList.size() < timeAList.size()) { |
|
|
|
|
for (String time : timeAList) { |
|
|
|
|
if (!timeBList.contains(time)) { |
|
|
|
|
timeBList.add(time); |
|
|
|
|
meterCurDataList.add("0"); |
|
|
|
|
meterLastDataList.add("0"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 反向处理 timeA 多出的情况(可选)
|
|
|
|
|
for (int i = 0; i < timeAList.size(); i++) { |
|
|
|
|
String time = timeAList.get(i); |
|
|
|
|
int indexInTimeB = timeBList.indexOf(time); |
|
|
|
|
|
|
|
|
|
if (indexInTimeB == -1) { |
|
|
|
|
// timeA[i] 在 timeB 中不存在,删除或跳过
|
|
|
|
|
timeAList.remove(i); |
|
|
|
|
cloudCurDataList.remove(i); |
|
|
|
|
cloudLastDataList.remove(i); |
|
|
|
|
i--; // 回退索引
|
|
|
|
|
} |
|
|
|
|
meterEnergyData.setTimes(timeBList.toArray(new String[0])); |
|
|
|
|
meterCurData = meterCurDataList.toArray(new String[0]); |
|
|
|
|
meterLastData = meterLastDataList.toArray(new String[0]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 更新回原对象
|
|
|
|
|
cloudEnergyData.setTimes(timeAList.toArray(new String[0])); |
|
|
|
|
meterEnergyData.setTimes(timeAList.toArray(new String[0])); // 保持时间一致
|
|
|
|
|
|
|
|
|
|
cloudCurData = cloudCurDataList.toArray(new String[0]); |
|
|
|
|
cloudLastData = cloudLastDataList.toArray(new String[0]); |
|
|
|
|
meterCurData = meterCurDataList.toArray(new String[0]); |
|
|
|
|
meterLastData = meterLastDataList.toArray(new String[0]); |
|
|
|
|
|
|
|
|
|
energyConsumptionDTO.setTitles(meterEnergyData.getTitles()); |
|
|
|
|
energyConsumptionDTO.setTimes(meterEnergyData.getTimes()); |
|
|
|
|
energyConsumptionDTO.setLineTimes(meterEnergyData.getLineTimes()); |
|
|
|
@ -652,13 +672,13 @@ public class EnergyServiceImpl implements IEnergyService {
|
|
|
|
|
// ));
|
|
|
|
|
List<Map<String, Object>> listData = new ArrayList<>(); |
|
|
|
|
Map<String, Object> cur = new HashMap<>(); |
|
|
|
|
cur.put("curValue",copMap); |
|
|
|
|
cur.put("curValue", copMap); |
|
|
|
|
listData.add(cur); |
|
|
|
|
Map<String, Object> last = new HashMap<>(); |
|
|
|
|
last.put("lastValue",copLastMap); |
|
|
|
|
last.put("lastValue", copLastMap); |
|
|
|
|
listData.add(last); |
|
|
|
|
Map<String, Object> yoy = new HashMap<>(); |
|
|
|
|
yoy.put(type,yoyMap); |
|
|
|
|
yoy.put(type, yoyMap); |
|
|
|
|
listData.add(yoy); |
|
|
|
|
energyConsumptionDTO.setData(listData); |
|
|
|
|
} |
|
|
|
@ -674,12 +694,12 @@ public class EnergyServiceImpl implements IEnergyService {
|
|
|
|
|
String deviceType = vo.getParamType(); |
|
|
|
|
if ("meter".equals(deviceType)) { |
|
|
|
|
deviceType = "5"; |
|
|
|
|
} else if ("cloud".equals(deviceType)){ |
|
|
|
|
} else if ("cloud".equals(deviceType)) { |
|
|
|
|
deviceType = "6"; |
|
|
|
|
} |
|
|
|
|
// 判断查询时间类型是month,year
|
|
|
|
|
if ("month".equalsIgnoreCase(vo.getTimeType()) || "year".equalsIgnoreCase(vo.getTimeType())) { |
|
|
|
|
String tableName = "data_"+vo.getTimeType(); |
|
|
|
|
String tableName = "data_" + vo.getTimeType(); |
|
|
|
|
// 计算COP值(后期有一个表存储)
|
|
|
|
|
if (!StringUtils.isBlank(vo.getParamType()) && vo.getParamType().equalsIgnoreCase("cop")) { |
|
|
|
|
// tableName = "data_min_cop";
|
|
|
|
@ -689,8 +709,8 @@ public class EnergyServiceImpl implements IEnergyService {
|
|
|
|
|
consumptionAnalyzeEntities = energyMapper.queryMonthAndYearMom(vo.getStartTime(), vo.getEndTime(), startTime, endTime, tableName, getTimeLen(vo.getTimeType()), deviceType, vo.getTimeType(), vo.getSystemType()); |
|
|
|
|
} else { |
|
|
|
|
// 判斷是否需要進行連表查詢
|
|
|
|
|
String tableName1 = "data_"+vo.getTimeType()+startTime.substring(0, 4); |
|
|
|
|
String tableName2 = "data_"+vo.getTimeType()+vo.getEndTime().substring(0, 4); |
|
|
|
|
String tableName1 = "data_" + vo.getTimeType() + startTime.substring(0, 4); |
|
|
|
|
String tableName2 = "data_" + vo.getTimeType() + vo.getEndTime().substring(0, 4); |
|
|
|
|
// 计算COP值(后期有一个表存储)
|
|
|
|
|
if (!StringUtils.isBlank(vo.getParamType()) && vo.getParamType().equalsIgnoreCase("cop")) { |
|
|
|
|
// tableName1 = "data_min_cop";
|
|
|
|
@ -776,7 +796,7 @@ public class EnergyServiceImpl implements IEnergyService {
|
|
|
|
|
EnergyConsumptionDTO result = new EnergyConsumptionDTO(); |
|
|
|
|
EnergyConsumptionDTO yoyData = (EnergyConsumptionDTO) yoy.get("data"); |
|
|
|
|
EnergyConsumptionDTO momData = (EnergyConsumptionDTO) mom.get("data"); |
|
|
|
|
if (yoyData.getData()==null || momData.getData()==null) { |
|
|
|
|
if (yoyData.getData() == null || momData.getData() == null) { |
|
|
|
|
return AjaxResult.success(result); |
|
|
|
|
} |
|
|
|
|
result.setTitles(new String[]{"curValue", "lastValue", "yoy", "mom"}); |
|
|
|
@ -842,13 +862,13 @@ public class EnergyServiceImpl implements IEnergyService {
|
|
|
|
|
energyConsumptionDTO.setTimes(timeStrArr); |
|
|
|
|
List<Map<String, Object>> listData = new ArrayList<>(); |
|
|
|
|
Map<String, Object> cur = new HashMap<>(); |
|
|
|
|
cur.put("curValue",curValue); |
|
|
|
|
cur.put("curValue", curValue); |
|
|
|
|
listData.add(cur); |
|
|
|
|
Map<String, Object> last = new HashMap<>(); |
|
|
|
|
last.put("lastValue",lastValue); |
|
|
|
|
last.put("lastValue", lastValue); |
|
|
|
|
listData.add(last); |
|
|
|
|
Map<String, Object> yoy = new HashMap<>(); |
|
|
|
|
yoy.put(compareType,yoyValue); |
|
|
|
|
yoy.put(compareType, yoyValue); |
|
|
|
|
listData.add(yoy); |
|
|
|
|
energyConsumptionDTO.setData(listData); |
|
|
|
|
return AjaxResult.success(energyConsumptionDTO); |
|
|
|
|