|
|
|
@ -6,6 +6,7 @@ import com.mh.common.core.domain.ColumnData; |
|
|
|
import com.mh.common.core.domain.ColumnFilter; |
|
|
|
import com.mh.common.core.domain.ColumnFilter; |
|
|
|
import com.mh.common.core.domain.dto.EnergyConsumptionDTO; |
|
|
|
import com.mh.common.core.domain.dto.EnergyConsumptionDTO; |
|
|
|
import com.mh.common.core.domain.entity.ConsumptionAnalyze; |
|
|
|
import com.mh.common.core.domain.entity.ConsumptionAnalyze; |
|
|
|
|
|
|
|
import com.mh.common.core.domain.entity.CpmSpaceRelation; |
|
|
|
import com.mh.common.core.domain.entity.DeviceTypeEnergy; |
|
|
|
import com.mh.common.core.domain.entity.DeviceTypeEnergy; |
|
|
|
import com.mh.common.core.domain.vo.EnergyConsumptionVO; |
|
|
|
import com.mh.common.core.domain.vo.EnergyConsumptionVO; |
|
|
|
import com.mh.common.core.domain.vo.EnergyQueryVO; |
|
|
|
import com.mh.common.core.domain.vo.EnergyQueryVO; |
|
|
|
@ -15,8 +16,10 @@ import com.mh.common.utils.StringUtils; |
|
|
|
import com.mh.common.utils.bean.BeanUtils; |
|
|
|
import com.mh.common.utils.bean.BeanUtils; |
|
|
|
import com.mh.system.mapper.energy.EnergyAnalyzeMapper; |
|
|
|
import com.mh.system.mapper.energy.EnergyAnalyzeMapper; |
|
|
|
import com.mh.system.mapper.energy.EnergyMapper; |
|
|
|
import com.mh.system.mapper.energy.EnergyMapper; |
|
|
|
|
|
|
|
import com.mh.system.mapper.space.CpmSpaceRelationMapper; |
|
|
|
import com.mh.system.service.ISysDictDataService; |
|
|
|
import com.mh.system.service.ISysDictDataService; |
|
|
|
import com.mh.system.service.energy.IEnergyService; |
|
|
|
import com.mh.system.service.energy.IEnergyService; |
|
|
|
|
|
|
|
import com.mh.system.service.space.ICpmSpaceRelationService; |
|
|
|
import jakarta.annotation.Resource; |
|
|
|
import jakarta.annotation.Resource; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
@ -51,6 +54,110 @@ public class EnergyServiceImpl implements IEnergyService { |
|
|
|
@Resource |
|
|
|
@Resource |
|
|
|
private ISysDictDataService iSysDictDataService; |
|
|
|
private ISysDictDataService iSysDictDataService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
|
|
private CpmSpaceRelationMapper cpmSpaceRelationMapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public AjaxResult deviceERS(EnergyConsumptionVO vo) { |
|
|
|
|
|
|
|
AtomicReference<String> lastTableName = new AtomicReference<>("data_" + vo.getTimeType()); |
|
|
|
|
|
|
|
AtomicReference<String> curTableName = new AtomicReference<>("data_" + vo.getTimeType()); |
|
|
|
|
|
|
|
String timeType = vo.getTimeType(); |
|
|
|
|
|
|
|
String houseId = vo.getHouseId(); |
|
|
|
|
|
|
|
// 根据houseId获取参数类型id值
|
|
|
|
|
|
|
|
List<CpmSpaceRelation> cpmSpaceRelationList = cpmSpaceRelationMapper.selectListByHouseId(houseId); |
|
|
|
|
|
|
|
if (cpmSpaceRelationList.isEmpty()) { |
|
|
|
|
|
|
|
return AjaxResult.error("未查到设备组合信息"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ThreadPoolExecutor executor = EnergyThreadPoolService.getInstance(); |
|
|
|
|
|
|
|
CountDownLatch latch = new CountDownLatch(2); |
|
|
|
|
|
|
|
List<Future<Map<String, Object>>> futures = new ArrayList<>(); |
|
|
|
|
|
|
|
futures.add(executor.submit(() -> { |
|
|
|
|
|
|
|
List<ConsumptionAnalyze> consumptionAnalyzeEntities; |
|
|
|
|
|
|
|
if ("month".equalsIgnoreCase(timeType) || "year".equalsIgnoreCase(timeType)) { |
|
|
|
|
|
|
|
// 单表
|
|
|
|
|
|
|
|
consumptionAnalyzeEntities = energyMapper.queryDeviceERSOneTable(vo.getStartTime(), vo.getEndTime(), lastTableName.get(), curTableName.get(), getTimeLen(vo.getTimeType()), cpmSpaceRelationList, vo.getSystemType()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// 多表
|
|
|
|
|
|
|
|
lastTableName.set(lastTableName + vo.getStartTime().substring(0, 4)); |
|
|
|
|
|
|
|
curTableName.set(curTableName + vo.getEndTime().substring(0, 4)); |
|
|
|
|
|
|
|
consumptionAnalyzeEntities = energyMapper.queryDeviceERSManyTable(vo.getStartTime(), vo.getEndTime(), lastTableName.get(), curTableName.get(), getTimeLen(vo.getTimeType()), cpmSpaceRelationList, vo.getSystemType()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (null == consumptionAnalyzeEntities || consumptionAnalyzeEntities.size() == 0) { |
|
|
|
|
|
|
|
latch.countDown(); |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 组装赋值
|
|
|
|
|
|
|
|
String[] timeStrArr = consumptionAnalyzeEntities.stream() |
|
|
|
|
|
|
|
.map(ConsumptionAnalyze::getTimeStr) |
|
|
|
|
|
|
|
.toArray(String[]::new); |
|
|
|
|
|
|
|
String[] meterArr = consumptionAnalyzeEntities.stream() |
|
|
|
|
|
|
|
.map(ConsumptionAnalyze::getCurValue) |
|
|
|
|
|
|
|
.toArray(String[]::new); |
|
|
|
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
|
|
|
|
map.put("timeStrArr", timeStrArr); |
|
|
|
|
|
|
|
map.put("meterArr", meterArr); |
|
|
|
|
|
|
|
latch.countDown(); |
|
|
|
|
|
|
|
return map; |
|
|
|
|
|
|
|
})); |
|
|
|
|
|
|
|
futures.add(executor.submit(() -> { |
|
|
|
|
|
|
|
// 折线图,都查询min表
|
|
|
|
|
|
|
|
// 多表
|
|
|
|
|
|
|
|
String lastTable = "data_min" + vo.getStartTime().substring(0, 4); |
|
|
|
|
|
|
|
String curTable = "data_min" + vo.getEndTime().substring(0, 4); |
|
|
|
|
|
|
|
List<ConsumptionAnalyze> consumptionAnalyzeEntities = energyMapper.queryDeviceERSLineManyTable(vo.getStartTime(), vo.getEndTime(), lastTable, curTable, cpmSpaceRelationList, vo.getSystemType()); |
|
|
|
|
|
|
|
if (null == consumptionAnalyzeEntities || consumptionAnalyzeEntities.size() == 0) { |
|
|
|
|
|
|
|
latch.countDown(); |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 组装赋值
|
|
|
|
|
|
|
|
String[] timeStrArr = consumptionAnalyzeEntities.stream() |
|
|
|
|
|
|
|
.map(ConsumptionAnalyze::getTimeStr) |
|
|
|
|
|
|
|
.toArray(String[]::new); |
|
|
|
|
|
|
|
String[] meterArr = consumptionAnalyzeEntities.stream() |
|
|
|
|
|
|
|
.map(ConsumptionAnalyze::getCurValue) |
|
|
|
|
|
|
|
.toArray(String[]::new); |
|
|
|
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
|
|
|
|
map.put("timeStrLineArr", timeStrArr); |
|
|
|
|
|
|
|
map.put("meterLineArr", meterArr); |
|
|
|
|
|
|
|
latch.countDown(); |
|
|
|
|
|
|
|
return map; |
|
|
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
latch.await(); |
|
|
|
|
|
|
|
} catch (InterruptedException e) { |
|
|
|
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> allData = new HashMap<>(); |
|
|
|
|
|
|
|
// 获取数据
|
|
|
|
|
|
|
|
for (Future<Map<String, Object>> future : futures) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
Map<String, Object> map = future.get(); |
|
|
|
|
|
|
|
if (null != map) { |
|
|
|
|
|
|
|
allData.putAll(map); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (InterruptedException | ExecutionException e) { |
|
|
|
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EnergyConsumptionDTO energyConsumptionDTO = new EnergyConsumptionDTO(); |
|
|
|
|
|
|
|
String[] titleArr = new String[]{"meter", "lineMeter"}; |
|
|
|
|
|
|
|
energyConsumptionDTO.setTitles(titleArr); |
|
|
|
|
|
|
|
energyConsumptionDTO.setTimes((String[]) allData.get("timeStrArr")); |
|
|
|
|
|
|
|
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")); |
|
|
|
|
|
|
|
listData.add(meter); |
|
|
|
|
|
|
|
Map<String, Object> lineMeter = new HashMap<>(); |
|
|
|
|
|
|
|
lineMeter.put("lineMeter", allData.get("meterLineArr")); |
|
|
|
|
|
|
|
listData.add(lineMeter); |
|
|
|
|
|
|
|
energyConsumptionDTO.setData(listData); |
|
|
|
|
|
|
|
return AjaxResult.success(energyConsumptionDTO); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static String[] getArrChillerLine(List<DeviceTypeEnergy> copLineData, String[] lineTimeStrArr) { |
|
|
|
private static String[] getArrChillerLine(List<DeviceTypeEnergy> copLineData, String[] lineTimeStrArr) { |
|
|
|
String[] lineCopArr = new String[lineTimeStrArr.length]; |
|
|
|
String[] lineCopArr = new String[lineTimeStrArr.length]; |
|
|
|
for (int i = 0; i < lineTimeStrArr.length; i++) { |
|
|
|
for (int i = 0; i < lineTimeStrArr.length; i++) { |
|
|
|
|