|
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.jeecg.common.util.DateUtils;
|
|
|
import org.jeecg.common.util.oConvertUtils;
|
|
|
import org.jeecg.modules.deviceLesm.entity.DeviceInformation;
|
|
@@ -512,7 +513,18 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
if (i == 2) {
|
|
|
modelDataResult.setKey("尖");
|
|
|
modelDataResult.setKey1("尖(%)");
|
|
|
- modelDataResult.setValue(modelReportFormResult.getTopsPower().divide(sum, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
|
|
|
+
|
|
|
+ // 检查 sum 是否为零,避免除以零
|
|
|
+ if (sum.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ // 如果 sum 为零,可以设置百分比为 0 或其他适当的值
|
|
|
+ modelDataResult.setValue(BigDecimal.ZERO);
|
|
|
+ } else {
|
|
|
+ // sum 不为零时,正常进行除法
|
|
|
+ modelDataResult.setValue(
|
|
|
+ modelReportFormResult.getTopsPower().divide(sum, 4, RoundingMode.HALF_UP)
|
|
|
+ .multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
if (i == 3) {
|
|
|
modelDataResult.setKey("峰");
|
|
@@ -522,7 +534,17 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
if (i == 4) {
|
|
|
modelDataResult.setKey("峰");
|
|
|
modelDataResult.setKey1("峰(%)");
|
|
|
- modelDataResult.setValue(modelReportFormResult.getPeaksPower().divide(sum, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ // 检查 sum 是否为零,避免除以零
|
|
|
+ if (sum.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ // 如果 sum 为零,可以设置百分比为 0 或其他适当的值
|
|
|
+ modelDataResult.setValue(BigDecimal.ZERO);
|
|
|
+ } else {
|
|
|
+ // sum 不为零时,正常进行除法
|
|
|
+ modelDataResult.setValue(
|
|
|
+ modelReportFormResult.getPeaksPower().divide(sum, 4, RoundingMode.HALF_UP)
|
|
|
+ .multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
if (i == 5) {
|
|
|
modelDataResult.setKey("平");
|
|
@@ -532,7 +554,17 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
if (i == 6) {
|
|
|
modelDataResult.setKey("平");
|
|
|
modelDataResult.setKey1("平(%)");
|
|
|
- modelDataResult.setValue(modelReportFormResult.getFlatPower().divide(sum, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ // 检查 sum 是否为零,避免除以零
|
|
|
+ if (sum.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ // 如果 sum 为零,可以设置百分比为 0 或其他适当的值
|
|
|
+ modelDataResult.setValue(BigDecimal.ZERO);
|
|
|
+ } else {
|
|
|
+ // sum 不为零时,正常进行除法
|
|
|
+ modelDataResult.setValue(
|
|
|
+ modelReportFormResult.getFlatPower().divide(sum, 4, RoundingMode.HALF_UP)
|
|
|
+ .multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
if (i == 7) {
|
|
|
modelDataResult.setKey("谷");
|
|
@@ -542,7 +574,262 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
if (i == 8) {
|
|
|
modelDataResult.setKey("谷");
|
|
|
modelDataResult.setKey1("谷(%)");
|
|
|
- modelDataResult.setValue(modelReportFormResult.getValleysPower().divide(sum, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ // 检查 sum 是否为零,避免除以零
|
|
|
+ if (sum.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ // 如果 sum 为零,可以设置百分比为 0 或其他适当的值
|
|
|
+ modelDataResult.setValue(BigDecimal.ZERO);
|
|
|
+ } else {
|
|
|
+ // sum 不为零时,正常进行除法
|
|
|
+ modelDataResult.setValue(
|
|
|
+ modelReportFormResult.getValleysPower().divide(sum, 4, RoundingMode.HALF_UP)
|
|
|
+ .multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ modelDataResult.setDeviceTitle(deviceTitle);
|
|
|
+ modelDataResult.setDeviceRegionId(deviceRegionId);
|
|
|
+ modelDataResult.setDeviceInformationId(deviceInformationId);
|
|
|
+ modelDataResult.setCreateTime(createTime);
|
|
|
+ modelDataResult.setRegionTitle(regionTitle);
|
|
|
+ modelDataResult.setDeviceTypeName(deviceTypeName);
|
|
|
+ modelDataResults.add(modelDataResult);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ jsonResult = JSON.parseArray(JSON.toJSONString(modelDataResults));
|
|
|
+
|
|
|
+ log.info("{}{}", "积木报表导出总数:", jsonResult.size());
|
|
|
+ result.put("data", jsonResult);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONObject operatingStatistic() {
|
|
|
+
|
|
|
+ JSONObject finalResult = new JSONObject();
|
|
|
+ Query query = new Query();
|
|
|
+ query.with(Sort.by(Sort.Direction.ASC, "createTime"));
|
|
|
+ List<DeviceStatiscsModelMongodb> fpgStatiscsModelDataList = mongoTemplate.find(query, DeviceStatiscsModelMongodb.class, "total_day_powerproportioncurrent");
|
|
|
+
|
|
|
+ if (oConvertUtils.listIsEmpty(fpgStatiscsModelDataList)) {
|
|
|
+ log.info("{}{}", "mongo数据查询为空,峰平谷报表导出失败!", "total_day_powerproportioncurrent");
|
|
|
+ finalResult.put("data", new JSONArray());
|
|
|
+ return finalResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> deviceInformationIds = fpgStatiscsModelDataList.stream()
|
|
|
+ .map(DeviceStatiscsModelMongodb::getDeviceInformationId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ LambdaQueryWrapper<DeviceInformation> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.in(DeviceInformation::getId, deviceInformationIds);
|
|
|
+ List<DeviceInformation> deviceInformationList = deviceInformationMapper.selectList(queryWrapper);
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, String> deviceInfoMap = deviceInformationList.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ DeviceInformation::getId,
|
|
|
+ DeviceInformation::getDeviceTitle
|
|
|
+ ));
|
|
|
+
|
|
|
+ // 遍历 fpgStatiscsModelDataList,匹配 deviceTitle
|
|
|
+ fpgStatiscsModelDataList.forEach(data -> {
|
|
|
+ String deviceTitle = deviceInfoMap.get(data.getDeviceInformationId());
|
|
|
+ data.setDeviceTitle(deviceTitle); // 赋值 deviceTitle
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ // 将listA转换为以(设备Id, 区域Id)为键的Map
|
|
|
+ Map<String, DeviceInformation> mapA = deviceInformationList.stream()
|
|
|
+ .collect(Collectors.toMap(a -> a.getId() + "_" + a.getDeviceRegionId(), a -> a));
|
|
|
+
|
|
|
+ // 遍历listB,根据相同的(设备Id, 区域Id)与mapA中的对象合并成新的ModelResult并添加到新列表
|
|
|
+ List<ModelReportFormResult> combinedList = fpgStatiscsModelDataList.stream()
|
|
|
+ .map(b -> {
|
|
|
+ String key = b.getDeviceInformationId() + "_" + b.getDeviceRegionId();
|
|
|
+ DeviceInformation a = mapA.get(key);
|
|
|
+ if (a != null) {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ String dateString = sdf.format(b.getCreateTime());
|
|
|
+ return new ModelReportFormResult(a.getDeviceTitle(), b.getDevicePointId(), b.getDeviceRegionId(), b.getDeviceInformationId(),
|
|
|
+ b.getIngTime(), b.getSelectricCurrent(), b.getPower(), b.getTopsPower(), b.getPeaksPower(), b.getFlatPower(), b.getValleysPower(),
|
|
|
+ b.getTopsIngTime(), b.getPeaksIngTime(), b.getFlatIngTime(), b.getValleysIngTime(),
|
|
|
+ b.getTopsSelectricCurrent(), b.getPeaksSelectricCurrent(), b.getFlatSelectricCurrent(), b.getValleysSelectricCurrent(),
|
|
|
+ b.getTopsProportion(), b.getPeaksProportion(), b.getFlatProportion(), b.getValleysProportion(), b.getProportion(), b.getDates(), dateString, b.getRegionTitle(), mapDeviceType(a.getDeviceType()));
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }).filter(x -> x != null).collect(Collectors.toList());
|
|
|
+ JSONArray jsonResult = new JSONArray();
|
|
|
+
|
|
|
+ // 创建一个 Map 来存储按 deviceRegionId 和 deviceInformationId 分组的数据
|
|
|
+ Map<String, OperatingStatisticResult> mergedDataMap = new HashMap<>();
|
|
|
+
|
|
|
+ // 遍历 combinedList,根据 deviceRegionId 和 deviceInformationId 进行合并
|
|
|
+ for (ModelReportFormResult reportFormResult : combinedList) {
|
|
|
+ // 创建合并的 key(使用 deviceRegionId 和 deviceInformationId)
|
|
|
+ String key = reportFormResult.getDeviceRegionId() + "_" + reportFormResult.getDeviceInformationId();
|
|
|
+
|
|
|
+ // 从 Map 中获取已有的数据,如果没有,则新建一个对象
|
|
|
+ OperatingStatisticResult result = mergedDataMap.getOrDefault(key, new OperatingStatisticResult());
|
|
|
+
|
|
|
+ // 先对各个字段进行累加
|
|
|
+ result.setTopsPower(result.getTopsPower() == null ? BigDecimal.ZERO : result.getTopsPower().add(reportFormResult.getTopsPower()));
|
|
|
+ result.setPeaksPower(result.getPeaksPower() == null ? BigDecimal.ZERO : result.getPeaksPower().add(reportFormResult.getPeaksPower()));
|
|
|
+ result.setFlatPower(result.getFlatPower() == null ? BigDecimal.ZERO : result.getFlatPower().add(reportFormResult.getFlatPower()));
|
|
|
+ result.setValleysPower(result.getValleysPower() == null ? BigDecimal.ZERO : result.getValleysPower().add(reportFormResult.getValleysPower()));
|
|
|
+
|
|
|
+ // 累加之后的 power = topsPower + peaksPower + flatPower + valleysPower
|
|
|
+ BigDecimal totalPower = result.getTopsPower().add(result.getPeaksPower()).add(result.getFlatPower()).add(result.getValleysPower());
|
|
|
+ result.setPower(totalPower); // 将累加后的结果赋值给 power
|
|
|
+
|
|
|
+ result.setDeviceInformationId(reportFormResult.getDeviceInformationId());
|
|
|
+ result.setDeviceRegionId(reportFormResult.getDeviceRegionId());
|
|
|
+ result.setDevicePointId(reportFormResult.getDevicePointId());
|
|
|
+ result.setDeviceTitle(reportFormResult.getDeviceTitle());
|
|
|
+
|
|
|
+ // 获取最新的日期,使用最新的时间
|
|
|
+ if (result.getDates() == null || reportFormResult.getDates().compareTo(result.getDates()) > 0) {
|
|
|
+ result.setDates(reportFormResult.getDates());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新新的对象到 Map 中
|
|
|
+ mergedDataMap.put(key, result);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 合并后的数据列表
|
|
|
+ List<OperatingStatisticResult> mergedResults = new ArrayList<>(mergedDataMap.values());
|
|
|
+
|
|
|
+ // 重新计算百分比
|
|
|
+ for (OperatingStatisticResult result : mergedResults) {
|
|
|
+ BigDecimal totalPower = result.getPower();
|
|
|
+
|
|
|
+ // 防止除以零
|
|
|
+ if (totalPower.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ // 重新计算各个百分比
|
|
|
+ result.setTopsProportion(result.getTopsPower().divide(totalPower, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ result.setPeaksProportion(result.getPeaksPower().divide(totalPower, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ result.setFlatProportion(result.getFlatPower().divide(totalPower, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ result.setValleysProportion(result.getValleysPower().divide(totalPower, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP));
|
|
|
+ } else {
|
|
|
+ // 如果 totalPower 为零,则占比为零
|
|
|
+ result.setTopsProportion(BigDecimal.ZERO);
|
|
|
+ result.setPeaksProportion(BigDecimal.ZERO);
|
|
|
+ result.setFlatProportion(BigDecimal.ZERO);
|
|
|
+ result.setValleysProportion(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 龙钢变各工序报表
|
|
|
+ List<ElectricityControlReport> modelDataResults = new ArrayList<>();
|
|
|
+ for (OperatingStatisticResult modelReportFormResult : mergedResults) {
|
|
|
+
|
|
|
+ BigDecimal sum = modelReportFormResult.getTopsPower().add(modelReportFormResult.getPeaksPower()).add(modelReportFormResult.getFlatPower()).add(modelReportFormResult.getValleysPower());
|
|
|
+
|
|
|
+ // 先获取公共属性值,避免在循环内多次重复获取
|
|
|
+ String deviceTitle = modelReportFormResult.getDeviceTitle();
|
|
|
+ String deviceRegionId = modelReportFormResult.getDeviceRegionId();
|
|
|
+ String deviceInformationId = modelReportFormResult.getDeviceInformationId();
|
|
|
+ String createTime = modelReportFormResult.getDates();
|
|
|
+ String regionTitle = modelReportFormResult.getRegionName();
|
|
|
+ String deviceTypeName = modelReportFormResult.getDeviceTypeName();
|
|
|
+ for (int i = 0; i < 9; i++) {
|
|
|
+
|
|
|
+ ElectricityControlReport modelDataResult = new ElectricityControlReport();
|
|
|
+
|
|
|
+ if (i == 0) {
|
|
|
+ modelDataResult.setKey("尖值电量");
|
|
|
+ modelDataResult.setKey1("尖值电量");
|
|
|
+ modelDataResult.setValue(modelReportFormResult.getTopsPower());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (i == 1) {
|
|
|
+ modelDataResult.setKey("峰值电量");
|
|
|
+ modelDataResult.setKey1("峰值电量");
|
|
|
+ modelDataResult.setValue(modelReportFormResult.getPeaksPower());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (i == 2) {
|
|
|
+ modelDataResult.setKey("平值电量");
|
|
|
+ modelDataResult.setKey1("平值电量");
|
|
|
+ modelDataResult.setValue(modelReportFormResult.getFlatPower());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (i == 3) {
|
|
|
+ modelDataResult.setKey("谷值电量");
|
|
|
+ modelDataResult.setKey1("谷值电量");
|
|
|
+ modelDataResult.setValue(modelReportFormResult.getValleysPower());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (i == 4) {
|
|
|
+ modelDataResult.setKey("总电量");
|
|
|
+ modelDataResult.setKey1("总电量");
|
|
|
+ modelDataResult.setValue(modelReportFormResult.getTopsPower().add(modelReportFormResult.getPeaksPower()).add(modelReportFormResult.getFlatPower()).add(modelReportFormResult.getValleysPower()));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (i == 5) {
|
|
|
+ modelDataResult.setKey("尖用电比例");
|
|
|
+ modelDataResult.setKey1("尖用电比例");
|
|
|
+
|
|
|
+ // 检查 sum 是否为零,避免除以零
|
|
|
+ if (sum.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ // 如果 sum 为零,可以设置百分比为 0 或其他适当的值
|
|
|
+ modelDataResult.setValue(BigDecimal.ZERO);
|
|
|
+ } else {
|
|
|
+ // sum 不为零时,正常进行除法
|
|
|
+ modelDataResult.setValue(
|
|
|
+ modelReportFormResult.getTopsPower().divide(sum, 4, RoundingMode.HALF_UP)
|
|
|
+ .multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (i == 6) {
|
|
|
+ modelDataResult.setKey("峰用电比例");
|
|
|
+ modelDataResult.setKey1("峰用电比例");
|
|
|
+ // 检查 sum 是否为零,避免除以零
|
|
|
+ if (sum.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ // 如果 sum 为零,可以设置百分比为 0 或其他适当的值
|
|
|
+ modelDataResult.setValue(BigDecimal.ZERO);
|
|
|
+ } else {
|
|
|
+ // sum 不为零时,正常进行除法
|
|
|
+ modelDataResult.setValue(
|
|
|
+ modelReportFormResult.getPeaksPower().divide(sum, 4, RoundingMode.HALF_UP)
|
|
|
+ .multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (i == 7) {
|
|
|
+ modelDataResult.setKey("平用电比例");
|
|
|
+ modelDataResult.setKey1("平用电比例");
|
|
|
+ // 检查 sum 是否为零,避免除以零
|
|
|
+ if (sum.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ // 如果 sum 为零,可以设置百分比为 0 或其他适当的值
|
|
|
+ modelDataResult.setValue(BigDecimal.ZERO);
|
|
|
+ } else {
|
|
|
+ // sum 不为零时,正常进行除法
|
|
|
+ modelDataResult.setValue(
|
|
|
+ modelReportFormResult.getFlatPower().divide(sum, 4, RoundingMode.HALF_UP)
|
|
|
+ .multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (i == 8) {
|
|
|
+ modelDataResult.setKey("谷用电比例");
|
|
|
+ modelDataResult.setKey1("谷用电比例");
|
|
|
+ // 检查 sum 是否为零,避免除以零
|
|
|
+ if (sum.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ // 如果 sum 为零,可以设置百分比为 0 或其他适当的值
|
|
|
+ modelDataResult.setValue(BigDecimal.ZERO);
|
|
|
+ } else {
|
|
|
+ // sum 不为零时,正常进行除法
|
|
|
+ modelDataResult.setValue(
|
|
|
+ modelReportFormResult.getValleysPower().divide(sum, 4, RoundingMode.HALF_UP)
|
|
|
+ .multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -555,8 +842,256 @@ public class FpgLeanModelServiceImpl extends ServiceImpl<FpgLeanModelMapper, Fpg
|
|
|
modelDataResults.add(modelDataResult);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ // 分组,按key字段分组
|
|
|
+ Map<String, BigDecimal> groupedData = modelDataResults.stream()
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ ElectricityControlReport::getKey,
|
|
|
+ Collectors.mapping(ElectricityControlReport::getValue, Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))
|
|
|
+ ));
|
|
|
+
|
|
|
+ // 创建 ElectricityControlReport 对象
|
|
|
+ ElectricityControlReport report = new ElectricityControlReport();
|
|
|
+
|
|
|
+ // 根据key的值将分组数据映射到相应的字段
|
|
|
+ for (Map.Entry<String, BigDecimal> entry : groupedData.entrySet()) {
|
|
|
+ String key = entry.getKey();
|
|
|
+ BigDecimal value = entry.getValue();
|
|
|
+
|
|
|
+ switch (key) {
|
|
|
+ case "总电量":
|
|
|
+ report.setPower(value);
|
|
|
+ break;
|
|
|
+ case "尖值电量":
|
|
|
+ report.setTopsPower(value);
|
|
|
+ break;
|
|
|
+ case "峰值电量":
|
|
|
+ report.setPeaksPower(value);
|
|
|
+ break;
|
|
|
+ case "平值电量":
|
|
|
+ report.setFlatPower(value);
|
|
|
+ break;
|
|
|
+ case "谷值电量":
|
|
|
+ report.setValleysPower(value);
|
|
|
+ break;
|
|
|
+ case "尖用电比例":
|
|
|
+ report.setTopsProportion(value);
|
|
|
+ break;
|
|
|
+ case "峰用电比例":
|
|
|
+ report.setPeaksProportion(value);
|
|
|
+ break;
|
|
|
+ case "平用电比例":
|
|
|
+ report.setFlatProportion(value);
|
|
|
+ break;
|
|
|
+ case "谷用电比例":
|
|
|
+ report.setValleysProportion(value);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算比例 (如果需要根据总电量计算比例)
|
|
|
+ BigDecimal totalPower = report.getPower();
|
|
|
+ if (totalPower.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ // 判空处理,确保计算时字段不为null
|
|
|
+ BigDecimal topsPower = report.getTopsPower() != null ? report.getTopsPower() : BigDecimal.ZERO;
|
|
|
+ BigDecimal peaksPower = report.getPeaksPower() != null ? report.getPeaksPower() : BigDecimal.ZERO;
|
|
|
+ BigDecimal flatPower = report.getFlatPower() != null ? report.getFlatPower() : BigDecimal.ZERO;
|
|
|
+ BigDecimal valleysPower = report.getValleysPower() != null ? report.getValleysPower() : BigDecimal.ZERO;
|
|
|
+
|
|
|
+ // 计算各自的比例
|
|
|
+ report.setTopsProportion(topsPower.divide(totalPower, 4, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)).stripTrailingZeros());
|
|
|
+ report.setPeaksProportion(peaksPower.divide(totalPower, 4, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)).stripTrailingZeros());
|
|
|
+ report.setFlatProportion(flatPower.divide(totalPower, 4, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)).stripTrailingZeros());
|
|
|
+ report.setValleysProportion(valleysPower.divide(totalPower, 4, BigDecimal.ROUND_HALF_UP).multiply(BigDecimal.valueOf(100)).stripTrailingZeros());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ modelDataResults.forEach(deviceinfo -> {
|
|
|
+
|
|
|
+ deviceinfo.setPower(report.getPower());
|
|
|
+ deviceinfo.setTopsPower(report.getTopsPower());
|
|
|
+ deviceinfo.setTopsProportion(report.getTopsProportion());
|
|
|
+ deviceinfo.setPeaksPower(report.getPeaksPower());
|
|
|
+ deviceinfo.setPeaksProportion(report.getPeaksProportion());
|
|
|
+ deviceinfo.setFlatPower(report.getFlatPower());
|
|
|
+ deviceinfo.setFlatProportion(report.getFlatProportion());
|
|
|
+ deviceinfo.setValleysPower(report.getValleysPower());
|
|
|
+ deviceinfo.setValleysProportion(report.getValleysProportion());
|
|
|
+ if ("尖值电量".equals(deviceinfo.getKey())) {
|
|
|
+
|
|
|
+ deviceinfo.setTotal(deviceinfo.getTopsPower());
|
|
|
+ deviceinfo.setOrderIndex(1);
|
|
|
+
|
|
|
+
|
|
|
+ } else if ("峰值电量".equals(deviceinfo.getKey())) {
|
|
|
+
|
|
|
+ deviceinfo.setTotal(deviceinfo.getPeaksPower());
|
|
|
+ deviceinfo.setOrderIndex(2);
|
|
|
+
|
|
|
+ } else if ("平值电量".equals(deviceinfo.getKey())) {
|
|
|
+
|
|
|
+ deviceinfo.setTotal(deviceinfo.getFlatPower());
|
|
|
+ deviceinfo.setOrderIndex(3);
|
|
|
+
|
|
|
+ } else if ("谷值电量".equals(deviceinfo.getKey())) {
|
|
|
+
|
|
|
+ deviceinfo.setTotal(deviceinfo.getValleysPower());
|
|
|
+ deviceinfo.setOrderIndex(4);
|
|
|
+
|
|
|
+ } else if ("总电量".equals(deviceinfo.getKey())) {
|
|
|
+
|
|
|
+ deviceinfo.setTotal(deviceinfo.getPower());
|
|
|
+ deviceinfo.setOrderIndex(5);
|
|
|
+
|
|
|
+ } else if ("尖用电比例".equals(deviceinfo.getKey())) {
|
|
|
+
|
|
|
+ deviceinfo.setTotal(deviceinfo.getTopsProportion());
|
|
|
+ deviceinfo.setOrderIndex(6);
|
|
|
+
|
|
|
+ } else if ("峰用电比例".equals(deviceinfo.getKey())) {
|
|
|
+
|
|
|
+ deviceinfo.setTotal(deviceinfo.getPeaksProportion());
|
|
|
+ deviceinfo.setOrderIndex(7);
|
|
|
+
|
|
|
+ } else if ("平用电比例".equals(deviceinfo.getKey())) {
|
|
|
+
|
|
|
+ deviceinfo.setTotal(deviceinfo.getFlatProportion());
|
|
|
+ deviceinfo.setOrderIndex(8);
|
|
|
+
|
|
|
+ } else if ("谷用电比例".equals(deviceinfo.getKey())) {
|
|
|
+
|
|
|
+ deviceinfo.setTotal(deviceinfo.getValleysProportion());
|
|
|
+ deviceinfo.setOrderIndex(9);
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
jsonResult = JSON.parseArray(JSON.toJSONString(modelDataResults));
|
|
|
|
|
|
+ log.info("{}{}", "积木报表导出总数:", jsonResult.size());
|
|
|
+ finalResult.put("data", jsonResult);
|
|
|
+ return finalResult;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONObject valleyPeakDifferenceStatistics() {
|
|
|
+
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ Query query = new Query();
|
|
|
+ query.with(Sort.by(Sort.Direction.ASC, "createTime"));
|
|
|
+
|
|
|
+ // 查询 MongoDB 中的数据
|
|
|
+ List<DeviceStatiscsModelMongodb> fpgStatiscsModelDataList =
|
|
|
+ mongoTemplate.find(query, DeviceStatiscsModelMongodb.class, "total_day_powerproportioncurrent");
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(fpgStatiscsModelDataList)) {
|
|
|
+ log.info("{}{}", "mongo数据查询为空,峰平谷报表导出失败!", "total_day_powerproportioncurrent");
|
|
|
+ result.put("data", new JSONArray());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取设备 ID 列表
|
|
|
+ List<String> deviceInformationIds = fpgStatiscsModelDataList.stream()
|
|
|
+ .map(DeviceStatiscsModelMongodb::getDeviceInformationId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 查询设备信息
|
|
|
+ LambdaQueryWrapper<DeviceInformation> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.in(DeviceInformation::getId, deviceInformationIds);
|
|
|
+ List<DeviceInformation> deviceInformationList = deviceInformationMapper.selectList(queryWrapper);
|
|
|
+
|
|
|
+ // 将设备信息转换为 Map,键为 (设备Id_区域Id)
|
|
|
+ Map<String, DeviceInformation> mapA = deviceInformationList.stream()
|
|
|
+ .collect(Collectors.toMap(a -> a.getId() + "_" + a.getDeviceRegionId(), a -> a));
|
|
|
+
|
|
|
+ // 生成合并列表
|
|
|
+ List<ModelReportFormResult> combinedList = fpgStatiscsModelDataList.stream()
|
|
|
+ .map(b -> {
|
|
|
+ String key = b.getDeviceInformationId() + "_" + b.getDeviceRegionId();
|
|
|
+ DeviceInformation a = mapA.get(key);
|
|
|
+ if (a != null) {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ String dateString = sdf.format(b.getCreateTime());
|
|
|
+ return new ModelReportFormResult(
|
|
|
+ a.getDeviceTitle(), b.getDevicePointId(), b.getDeviceRegionId(), b.getDeviceInformationId(),
|
|
|
+ b.getIngTime(), b.getSelectricCurrent(), b.getPower(), b.getTopsPower(), b.getPeaksPower(), b.getFlatPower(), b.getValleysPower(),
|
|
|
+ b.getTopsIngTime(), b.getPeaksIngTime(), b.getFlatIngTime(), b.getValleysIngTime(),
|
|
|
+ b.getTopsSelectricCurrent(), b.getPeaksSelectricCurrent(), b.getFlatSelectricCurrent(), b.getValleysSelectricCurrent(),
|
|
|
+ b.getTopsProportion(), b.getPeaksProportion(), b.getFlatProportion(), b.getValleysProportion(),
|
|
|
+ b.getProportion(), b.getDates(), dateString, null, null);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 获取所有设备和区域的组合
|
|
|
+ Set<String> uniqueKeys = combinedList.stream()
|
|
|
+ .map(b -> b.getDeviceInformationId() + "_" + b.getDeviceRegionId())
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ // 获取所有日期
|
|
|
+ Set<String> allDates = combinedList.stream()
|
|
|
+ .map(ModelReportFormResult::getDates)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ // 结果列表
|
|
|
+ List<ModelDataResult> modelDataResults = new ArrayList<>();
|
|
|
+
|
|
|
+ // 遍历每个设备-区域组合和日期
|
|
|
+ for (String key : uniqueKeys) {
|
|
|
+ String[] keyParts = key.split("_");
|
|
|
+ String deviceInformationId = keyParts[0];
|
|
|
+ String deviceRegionId = keyParts[1];
|
|
|
+
|
|
|
+ for (String date : allDates) {
|
|
|
+ // 查找是否有对应设备和日期的对象
|
|
|
+ Optional<ModelReportFormResult> match = combinedList.stream()
|
|
|
+ .filter(model -> model.getDeviceInformationId().equals(deviceInformationId)
|
|
|
+ && model.getDeviceRegionId().equals(deviceRegionId)
|
|
|
+ && model.getDates().equals(date))
|
|
|
+ .findFirst();
|
|
|
+
|
|
|
+ if (match.isPresent()) {
|
|
|
+ // 如果有匹配对象,则按原逻辑处理
|
|
|
+ ModelReportFormResult modelReportFormResult = match.get();
|
|
|
+
|
|
|
+ BigDecimal valleysPower = modelReportFormResult.getValleysPower();
|
|
|
+ BigDecimal peaksPower = modelReportFormResult.getPeaksPower();
|
|
|
+ BigDecimal topsPower = modelReportFormResult.getTopsPower();
|
|
|
+
|
|
|
+ // 计算差值
|
|
|
+ BigDecimal difference = valleysPower.subtract(peaksPower).subtract(topsPower);
|
|
|
+
|
|
|
+ ModelDataResult modelDataResult = new ModelDataResult();
|
|
|
+ modelDataResult.setDeviceTitle(modelReportFormResult.getDeviceTitle());
|
|
|
+ modelDataResult.setDeviceRegionId(deviceRegionId);
|
|
|
+ modelDataResult.setDeviceInformationId(deviceInformationId);
|
|
|
+ modelDataResult.setCreateTime(date);
|
|
|
+ modelDataResult.setValue(difference);
|
|
|
+
|
|
|
+ modelDataResults.add(modelDataResult);
|
|
|
+ } else {
|
|
|
+ // 如果没有匹配对象,则初始化一个新对象,value 设置为 0
|
|
|
+ ModelDataResult modelDataResult = new ModelDataResult();
|
|
|
+ DeviceInformation deviceInfo = mapA.get(deviceInformationId + "_" + deviceRegionId);
|
|
|
+
|
|
|
+ modelDataResult.setDeviceTitle(deviceInfo != null ? deviceInfo.getDeviceTitle() : "未知设备");
|
|
|
+ modelDataResult.setDeviceRegionId(deviceRegionId);
|
|
|
+ modelDataResult.setDeviceInformationId(deviceInformationId);
|
|
|
+ modelDataResult.setCreateTime(date);
|
|
|
+ modelDataResult.setValue(BigDecimal.ZERO);
|
|
|
+
|
|
|
+ modelDataResults.add(modelDataResult);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 转换为 JSON 格式
|
|
|
+ JSONArray jsonResult = JSON.parseArray(JSON.toJSONString(modelDataResults));
|
|
|
+
|
|
|
log.info("{}{}", "积木报表导出总数:", jsonResult.size());
|
|
|
result.put("data", jsonResult);
|
|
|
return result;
|