|
@@ -1,8 +1,9 @@
|
|
|
package com.jjt.calc.controller;
|
|
|
|
|
|
-import com.jjt.biz.service.ITwinDeviceService;
|
|
|
import com.jjt.calc.domain.TwinCalcStop;
|
|
|
import com.jjt.calc.service.ITwinCalcStopService;
|
|
|
+import com.jjt.calc.vo.StopCalcVO;
|
|
|
+import com.jjt.calc.vo.TpsVO;
|
|
|
import com.jjt.common.annotation.Log;
|
|
|
import com.jjt.common.core.controller.BaseController;
|
|
|
import com.jjt.common.core.domain.AjaxResult;
|
|
@@ -36,8 +37,6 @@ import java.util.stream.Collectors;
|
|
|
public class TwinCalcStopController extends BaseController {
|
|
|
@Resource
|
|
|
private ITwinCalcStopService twinCalcStopService;
|
|
|
- @Resource
|
|
|
- private ITwinDeviceService deviceService;
|
|
|
|
|
|
/**
|
|
|
* 查询停机数据统计列表
|
|
@@ -61,12 +60,56 @@ public class TwinCalcStopController extends BaseController {
|
|
|
int totalNum = 0;
|
|
|
//停机时间
|
|
|
Long[] stopTime = new Long[stopSize];
|
|
|
+ //设备数量
|
|
|
+ Integer[] deviceNum = new Integer[stopSize];
|
|
|
Arrays.fill(stopTime, 0L);
|
|
|
AtomicReference<Long> totalTime = new AtomicReference<>(0L);
|
|
|
+ List<TpsVO> tpsVOS = new ArrayList<>();
|
|
|
for (Map.Entry<Integer, List<TwinCalcStop>> entry : stopDeviceGroup.entrySet()) {
|
|
|
Integer stopType = entry.getKey();
|
|
|
int pos = stopType - 1;
|
|
|
List<TwinCalcStop> stops = entry.getValue();
|
|
|
+ Map<Long, List<TwinCalcStop>> deviceGroup = stops.stream().collect(Collectors.groupingBy(TwinCalcStop::getDeviceId, LinkedHashMap::new, Collectors.toList()));
|
|
|
+ stops.sort(Comparator.comparing(TwinCalcStop::getDataDate).thenComparing(TwinCalcStop::getHour));
|
|
|
+ Map<Date, Map<Integer, List<TwinCalcStop>>> stopHourGroup = stops.stream().collect(
|
|
|
+ Collectors.groupingBy(TwinCalcStop::getDataDate, LinkedHashMap::new,
|
|
|
+ Collectors.groupingBy(TwinCalcStop::getHour, LinkedHashMap::new, Collectors.toList())));
|
|
|
+ for (Map.Entry<Date, Map<Integer, List<TwinCalcStop>>> entry2 : stopHourGroup.entrySet()) {
|
|
|
+ Map<Integer, List<TwinCalcStop>> map = entry2.getValue();
|
|
|
+ for (Map.Entry<Integer, List<TwinCalcStop>> entry1 : map.entrySet()) {
|
|
|
+ List<TwinCalcStop> stopList = entry1.getValue();
|
|
|
+ TpsVO tps = new TpsVO();
|
|
|
+ tps.setType(stopType);
|
|
|
+ tps.setDate(entry2.getKey());
|
|
|
+ tps.setHour(entry1.getKey());
|
|
|
+ Map<Long, List<TwinCalcStop>> yarnDeviceGroup = stopList.stream().collect(Collectors.groupingBy(TwinCalcStop::getDeviceId, LinkedHashMap::new, Collectors.toList()));
|
|
|
+ tps.setTps(yarnDeviceGroup.size());
|
|
|
+ int num = stopList.size();
|
|
|
+ tps.setNum(num);
|
|
|
+ //0.最小,1.最大,2.总时间
|
|
|
+ final long[] time = {999999L, 0, 0};
|
|
|
+ //6.设备断纱停机详情
|
|
|
+ for (TwinCalcStop stop : stopList) {
|
|
|
+ long t = (stop.getEndTime().getTime() - stop.getStartTime().getTime()) / 1000;
|
|
|
+ if (t < time[0]) {
|
|
|
+ time[0] = t;
|
|
|
+ }
|
|
|
+ if (t > time[1]) {
|
|
|
+ time[1] = t;
|
|
|
+ }
|
|
|
+ time[2] += t;
|
|
|
+ }
|
|
|
+
|
|
|
+ tps.setMax(time[1]);
|
|
|
+ tps.setMin(time[0]);
|
|
|
+ BigDecimal avg = BigDecimal.valueOf(time[2]).divide(BigDecimal.valueOf(num), 2, RoundingMode.HALF_UP);
|
|
|
+ tps.setAvg(avg);
|
|
|
+
|
|
|
+ tpsVOS.add(tps);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ deviceNum[pos] = deviceGroup.size();
|
|
|
stopNum[pos] = stops.size();
|
|
|
totalNum += stops.size();
|
|
|
stops.forEach(stop -> {
|
|
@@ -76,25 +119,28 @@ public class TwinCalcStopController extends BaseController {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- List<Map<String, Object>> calcList = new ArrayList<>();
|
|
|
+ List<StopCalcVO> calcList = new ArrayList<>();
|
|
|
for (int i = 0; i < stopNum.length; i++) {
|
|
|
if (stopNum[i] == null) {
|
|
|
continue;
|
|
|
}
|
|
|
- Map<String, Object> map = new HashMap<>(16);
|
|
|
- map.put("type", i + 1);
|
|
|
- map.put("num", stopNum[i]);
|
|
|
- map.put("time", Tools.convertHMS(stopTime[i]));
|
|
|
- float percentNum = BigDecimal.valueOf(stopNum[i]).divide(BigDecimal.valueOf(totalNum), 4, RoundingMode.HALF_UP).floatValue();
|
|
|
- float percentTimes = BigDecimal.valueOf(stopTime[i]).divide(BigDecimal.valueOf(totalTime.get()), 4, RoundingMode.HALF_UP).floatValue();
|
|
|
- map.put("percentNum", percentNum);
|
|
|
- map.put("percentTimes", percentTimes);
|
|
|
- calcList.add(map);
|
|
|
+ StopCalcVO vo = new StopCalcVO();
|
|
|
+ vo.setType(i + 1);
|
|
|
+ vo.setNum(stopNum[i]);
|
|
|
+ vo.setDevice(deviceNum[i]);
|
|
|
+ vo.setTime(Tools.convertHMS(stopTime[i]));
|
|
|
+ long avg = stopTime[i] / totalNum;
|
|
|
+ vo.setAvgTime(Tools.convertHMS(avg));
|
|
|
+ BigDecimal percentNum = BigDecimal.valueOf(stopNum[i]).divide(BigDecimal.valueOf(totalNum), 4, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal percentTimes = BigDecimal.valueOf(stopTime[i]).divide(BigDecimal.valueOf(totalTime.get()), 4, RoundingMode.HALF_UP);
|
|
|
+ vo.setPercentNum(percentNum);
|
|
|
+ vo.setPercentTimes(percentTimes);
|
|
|
+ calcList.add(vo);
|
|
|
}
|
|
|
|
|
|
- Map<String, Object> result = new HashMap<>();
|
|
|
-// result.put("list", list);
|
|
|
+ Map<String, Object> result = new HashMap<>(16);
|
|
|
result.put("calc", calcList);
|
|
|
+ result.put("tps", tpsVOS);
|
|
|
|
|
|
return R.success(result);
|
|
|
}
|