|
|
@@ -3,6 +3,8 @@ package com.jjt.dye.service.impl;
|
|
|
import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import com.jjt.calc.domain.TwinCalcHourYhj;
|
|
|
+import com.jjt.calc.service.ITwinCalcHourYhjService;
|
|
|
import com.jjt.common.utils.DateUtils;
|
|
|
import com.jjt.dye.domain.DyeCalcHour;
|
|
|
import com.jjt.dye.domain.DyeDevice;
|
|
|
@@ -38,6 +40,8 @@ public class DyeHourLineServiceImpl implements IDyeHourLineService {
|
|
|
private IDyeCalcHourService calcHourService;
|
|
|
@Resource
|
|
|
private IDyeDeviceService deviceService;
|
|
|
+ @Resource
|
|
|
+ private ITwinCalcHourYhjService yhjService;
|
|
|
|
|
|
/**
|
|
|
* 查询产线小时统计数据
|
|
|
@@ -130,90 +134,134 @@ public class DyeHourLineServiceImpl implements IDyeHourLineService {
|
|
|
dyeHourLineMapper.deleteByHour(DateUtils.toDate(date), hour);
|
|
|
//1.先查询小时统计数据
|
|
|
List<DyeCalcHour> calcHours = calcHourService.selectByTime(date, hour);
|
|
|
+ List<TwinCalcHourYhj> yhjList = yhjService.selectByTime(date, hour);
|
|
|
+ Map<Integer, Integer> yhjLengthMap = yhjList.stream()
|
|
|
+ .collect(Collectors.groupingBy(TwinCalcHourYhj::getDeviceId,
|
|
|
+ Collectors.summingInt(yhj -> yhj.getLength())));
|
|
|
for (DyeCalcHour calcHour : calcHours) {
|
|
|
DyeDevice device = deviceMap.get(calcHour.getDeviceId());
|
|
|
calcHour.setCreatedBy(device.getLine());
|
|
|
+ switch (calcHour.getParaCode()) {
|
|
|
+ case "P_u9m9n9v1o900":
|
|
|
+ case "P_osu9096knpc0":
|
|
|
+ case "P_ocgfbdif79k0":
|
|
|
+ case "P_rj0t7h4eqpo0":
|
|
|
+ calcHour.setParaCode("P_dx_tmp");
|
|
|
+ break;
|
|
|
+ case "P_ubk8dkl0p1o0":
|
|
|
+ case "P_n4hg31666hs0":
|
|
|
+ calcHour.setParaCode("P_tg_tmp");
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
//按生产线分组统计
|
|
|
Map<String, List<DyeCalcHour>> lineMap = calcHours.stream()
|
|
|
.collect(Collectors.groupingBy(DyeCalcHour::getCreatedBy));
|
|
|
|
|
|
- for (Map.Entry<String, List<DyeCalcHour>> entry : lineMap.entrySet()) {
|
|
|
- String line = entry.getKey();
|
|
|
- List<DyeCalcHour> lineCalcHours = entry.getValue();
|
|
|
-
|
|
|
- // 计算能耗总和
|
|
|
- BigDecimal engEnergy = calculateParameterValue(lineCalcHours, "ENG_energy", BigDecimal::add);
|
|
|
- String combinedEnergyMValue = combineParaMValues(lineCalcHours, "ENG_energy");
|
|
|
-
|
|
|
- // 计算电流平均值
|
|
|
- BigDecimal engAmpA = calculateParameterValue(lineCalcHours, "ENG_amp_a", BigDecimal::add);
|
|
|
- String avgAmpAMValue = averageParaMValues(lineCalcHours, "ENG_amp_a");
|
|
|
- BigDecimal avgEngAmpA = lineCalcHours.isEmpty() ? BigDecimal.ZERO :
|
|
|
- engAmpA.divide(BigDecimal.valueOf(lineCalcHours.size()), 2, RoundingMode.HALF_UP);
|
|
|
-
|
|
|
- // 获取速度值和对应的分钟级数据
|
|
|
- BigDecimal speed = lineCalcHours.stream()
|
|
|
- .filter(item -> item.getParaCode().equals("P_tt051hr93980"))
|
|
|
- .findFirst()
|
|
|
- .map(DyeCalcHour::getParaValue)
|
|
|
- .orElse(BigDecimal.ZERO);
|
|
|
-
|
|
|
- String speedMValue = lineCalcHours.stream()
|
|
|
- .filter(item -> item.getParaCode().equals("P_tt051hr93980") && item.getParaMValue() != null)
|
|
|
- .findFirst()
|
|
|
- .map(DyeCalcHour::getParaMValue)
|
|
|
- .orElse(null);
|
|
|
-
|
|
|
+ for (int line = 1; line <= 8; line++) {
|
|
|
+ Integer length = yhjLengthMap.getOrDefault(line, 0);
|
|
|
// 创建产线小时统计数据对象
|
|
|
DyeHourLine dyeHourLine = new DyeHourLine();
|
|
|
- dyeHourLine.setLine(line);
|
|
|
+ dyeHourLine.setLine(line + "");
|
|
|
dyeHourLine.setDataDate(DateUtils.toDate(date));
|
|
|
dyeHourLine.setHour(hour);
|
|
|
- dyeHourLine.setSpeed(speed);
|
|
|
- dyeHourLine.setEnergy(engEnergy);
|
|
|
- dyeHourLine.setEnergyM(combinedEnergyMValue);
|
|
|
- dyeHourLine.setAmpM(avgAmpAMValue);
|
|
|
- dyeHourLine.setSpeedM(speedMValue);
|
|
|
- dyeHourLine.setAmp(avgEngAmpA);
|
|
|
+ dyeHourLine.setLength(BigDecimal.valueOf(length));
|
|
|
+ List<DyeCalcHour> lineCalcHours = lineMap.get(line + "");
|
|
|
+ if (lineCalcHours!=null&&!lineCalcHours.isEmpty()) {
|
|
|
+ // 计算能耗总和
|
|
|
+ BigDecimal engEnergy = calculateParameterValue(lineCalcHours, "ENG_energy", BigDecimal::add);
|
|
|
+ String combinedEnergyMValue = combineParaMValues(lineCalcHours, "ENG_energy");
|
|
|
+
|
|
|
+ // 计算电流平均值
|
|
|
+ List<DyeCalcHour> engAmpAList = lineCalcHours.stream()
|
|
|
+ .filter(item -> item.getParaCode().equals("ENG_amp_a"))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ BigDecimal engAmpA = calculateParameterValue(lineCalcHours, "ENG_amp_a", BigDecimal::add);
|
|
|
+ String avgAmpAMValue = averageParaMValues(lineCalcHours, "ENG_amp_a");
|
|
|
+ BigDecimal avgEngAmpA = engAmpAList.isEmpty() ? BigDecimal.ZERO :
|
|
|
+ engAmpA.divide(BigDecimal.valueOf(engAmpAList.size()), 2, RoundingMode.HALF_UP);
|
|
|
+
|
|
|
+ // 计算定型机平均温度
|
|
|
+ List<DyeCalcHour> dxTmpList = lineCalcHours.stream()
|
|
|
+ .filter(item -> item.getParaCode().equals("P_dx_tmp"))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ BigDecimal dxTmp = calculateParameterValue(lineCalcHours, "P_dx_tmp", BigDecimal::add);
|
|
|
+ String dxTmpMValue = averageParaMValues(lineCalcHours, "P_dx_tmp");
|
|
|
+ BigDecimal avgDxTmp = dxTmpList.isEmpty() ? BigDecimal.ZERO :
|
|
|
+ dxTmp.divide(BigDecimal.valueOf(dxTmpList.size()), 2, RoundingMode.HALF_UP);
|
|
|
+
|
|
|
+ // 计算烫光平均温度
|
|
|
+ List<DyeCalcHour> tgTmpList = lineCalcHours.stream()
|
|
|
+ .filter(item -> item.getParaCode().equals("P_tg_tmp"))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ BigDecimal tgTmp = calculateParameterValue(lineCalcHours, "P_tg_tmp", BigDecimal::add);
|
|
|
+ String tgTmpMValue = averageParaMValues(lineCalcHours, "P_tg_tmp");
|
|
|
+ BigDecimal avgTgTmp = tgTmpList.isEmpty() ? BigDecimal.ZERO :
|
|
|
+ tgTmp.divide(BigDecimal.valueOf(tgTmpList.size()), 2, RoundingMode.HALF_UP);
|
|
|
+ // 获取速度值和对应的分钟级数据
|
|
|
+ BigDecimal speed = lineCalcHours.stream()
|
|
|
+ .filter(item -> item.getParaCode().equals("P_tt051hr93980"))
|
|
|
+ .findFirst()
|
|
|
+ .map(DyeCalcHour::getParaValue)
|
|
|
+ .orElse(BigDecimal.ZERO);
|
|
|
+
|
|
|
+ String speedMValue = lineCalcHours.stream()
|
|
|
+ .filter(item -> item.getParaCode().equals("P_tt051hr93980") && item.getParaMValue() != null)
|
|
|
+ .findFirst()
|
|
|
+ .map(DyeCalcHour::getParaMValue)
|
|
|
+ .orElse(null);
|
|
|
+
|
|
|
+ dyeHourLine.setEnergy(engEnergy);
|
|
|
+ dyeHourLine.setEnergyM(combinedEnergyMValue);
|
|
|
+ dyeHourLine.setAmp(avgEngAmpA);
|
|
|
+ dyeHourLine.setAmpM(avgAmpAMValue);
|
|
|
+ dyeHourLine.setSpeed(speed);
|
|
|
+ dyeHourLine.setSpeedM(speedMValue);
|
|
|
+ dyeHourLine.setTmpDx(avgDxTmp);
|
|
|
+ dyeHourLine.setTmpDxM(dxTmpMValue);
|
|
|
+ dyeHourLine.setTmpTg(avgTgTmp);
|
|
|
+ dyeHourLine.setTmpTgM(tgTmpMValue);
|
|
|
+ }
|
|
|
// 保存产线小时统计数据
|
|
|
dyeHourLineMapper.insertDyeHourLine(dyeHourLine);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 计算指定参数的值
|
|
|
+ *
|
|
|
* @param lineCalcHours 数据列表
|
|
|
- * @param paraCode 参数代码
|
|
|
- * @param operator 计算操作符
|
|
|
+ * @param paraCode 参数代码
|
|
|
+ * @param operator 计算操作符
|
|
|
* @return 计算结果
|
|
|
*/
|
|
|
- private BigDecimal calculateParameterValue(List<DyeCalcHour> lineCalcHours, String paraCode,
|
|
|
- BinaryOperator<BigDecimal> operator) {
|
|
|
+ private BigDecimal calculateParameterValue(List<DyeCalcHour> lineCalcHours, String paraCode,
|
|
|
+ BinaryOperator<BigDecimal> operator) {
|
|
|
return lineCalcHours.stream()
|
|
|
.filter(item -> item.getParaCode().equals(paraCode))
|
|
|
.map(DyeCalcHour::getParaValue)
|
|
|
.reduce(BigDecimal.ZERO, operator);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 合并多个paraMValue字段中的JSON数据,保持原有格式
|
|
|
+ *
|
|
|
* @param lineCalcHours 数据列表
|
|
|
- * @param paraCode 参数代码
|
|
|
+ * @param paraCode 参数代码
|
|
|
* @return 合并后的JSON字符串
|
|
|
*/
|
|
|
private String combineParaMValues(List<DyeCalcHour> lineCalcHours, String paraCode) {
|
|
|
List<DyeCalcHour> items = lineCalcHours.stream()
|
|
|
.filter(item -> item.getParaCode().equals(paraCode) && item.getParaMValue() != null)
|
|
|
.collect(Collectors.toList());
|
|
|
-
|
|
|
+
|
|
|
if (items.isEmpty()) {
|
|
|
return null;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 创建一个Map来存储time-value对,key为time,value为value的累加值
|
|
|
Map<String, BigDecimal> combinedValues = new java.util.HashMap<>();
|
|
|
-
|
|
|
+
|
|
|
// 遍历所有items中的paraMValue
|
|
|
for (DyeCalcHour item : items) {
|
|
|
try {
|
|
|
@@ -222,7 +270,7 @@ public class DyeHourLineServiceImpl implements IDyeHourLineService {
|
|
|
JSONObject dataObj = dataArray.getJSONObject(i);
|
|
|
String time = dataObj.getStr("time");
|
|
|
BigDecimal value = dataObj.getBigDecimal("value", BigDecimal.ZERO);
|
|
|
-
|
|
|
+
|
|
|
// 累加相同time的value
|
|
|
combinedValues.merge(time, value, BigDecimal::add);
|
|
|
}
|
|
|
@@ -231,7 +279,7 @@ public class DyeHourLineServiceImpl implements IDyeHourLineService {
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
// 构建合并后的JSONArray,按数字顺序排序
|
|
|
JSONArray combinedArray = new JSONArray();
|
|
|
@@ -253,30 +301,31 @@ public class DyeHourLineServiceImpl implements IDyeHourLineService {
|
|
|
dataObj.set("value", entry.getValue());
|
|
|
combinedArray.add(dataObj);
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
return combinedArray.toString();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 对多个paraMValue字段中的JSON数据计算平均值,保持原有格式
|
|
|
+ *
|
|
|
* @param lineCalcHours 数据列表
|
|
|
- * @param paraCode 参数代码
|
|
|
+ * @param paraCode 参数代码
|
|
|
* @return 平均值后的JSON字符串
|
|
|
*/
|
|
|
private String averageParaMValues(List<DyeCalcHour> lineCalcHours, String paraCode) {
|
|
|
List<DyeCalcHour> items = lineCalcHours.stream()
|
|
|
.filter(item -> item.getParaCode().equals(paraCode) && item.getParaMValue() != null)
|
|
|
.collect(Collectors.toList());
|
|
|
-
|
|
|
+
|
|
|
if (items.isEmpty()) {
|
|
|
return null;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 创建一个Map来存储time-value对,key为time,value为value的累加值
|
|
|
Map<String, BigDecimal> combinedValues = new java.util.HashMap<>();
|
|
|
// 创建一个Map来存储time出现的次数,用于计算平均值
|
|
|
Map<String, Integer> timeCounts = new java.util.HashMap<>();
|
|
|
-
|
|
|
+
|
|
|
// 遍历所有items中的paraMValue
|
|
|
for (DyeCalcHour item : items) {
|
|
|
try {
|
|
|
@@ -285,7 +334,7 @@ public class DyeHourLineServiceImpl implements IDyeHourLineService {
|
|
|
JSONObject dataObj = dataArray.getJSONObject(i);
|
|
|
String time = dataObj.getStr("time");
|
|
|
BigDecimal value = dataObj.getBigDecimal("value", BigDecimal.ZERO);
|
|
|
-
|
|
|
+
|
|
|
// 累加相同time的value
|
|
|
combinedValues.merge(time, value, BigDecimal::add);
|
|
|
// 记录time出现的次数
|
|
|
@@ -296,7 +345,7 @@ public class DyeHourLineServiceImpl implements IDyeHourLineService {
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 构建平均值后的JSONArray,按数字顺序排序
|
|
|
JSONArray averagedArray = new JSONArray();
|
|
|
combinedValues.entrySet().stream()
|
|
|
@@ -315,7 +364,7 @@ public class DyeHourLineServiceImpl implements IDyeHourLineService {
|
|
|
String time = entry.getKey();
|
|
|
BigDecimal sum = entry.getValue();
|
|
|
int count = timeCounts.getOrDefault(time, 1);
|
|
|
-
|
|
|
+
|
|
|
JSONObject dataObj = new JSONObject();
|
|
|
dataObj.set("time", time);
|
|
|
// 计算平均值
|