|
@@ -3,6 +3,7 @@ package com.ruoyi.biz.controller;
|
|
|
import com.ruoyi.biz.domain.*;
|
|
|
import com.ruoyi.biz.service.*;
|
|
|
import com.ruoyi.biz.service.impl.AsyncServiceImpl;
|
|
|
+import com.ruoyi.biz.tools.Tools;
|
|
|
import com.ruoyi.common.constant.Constants;
|
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
|
import com.ruoyi.common.core.domain.R;
|
|
@@ -80,6 +81,8 @@ public class ApiController extends BaseController {
|
|
|
private String alarmsExcelTemplate;
|
|
|
@Value("${excel.yarn}")
|
|
|
private String yarnExcelTemplate;
|
|
|
+ @Value("${excel.brokenYarn}")
|
|
|
+ private String brokenYarnExcelTemplate;
|
|
|
|
|
|
@ApiOperation("在线设备")
|
|
|
@GetMapping("/device/online")
|
|
@@ -481,6 +484,229 @@ public class ApiController extends BaseController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @ApiOperation("导出断纱分析")
|
|
|
+ @GetMapping("/export/broken-yarn")
|
|
|
+ @CrossOrigin(origins = "*")
|
|
|
+ public void brokenYarnExport(String date, HttpServletResponse response) throws ParseException {
|
|
|
+ LocalDate localDate = LocalDate.parse(date);
|
|
|
+ LocalDate st = localDate.minusDays(7);
|
|
|
+ Date sd = Date.from(st.atStartOfDay(ZoneOffset.of("+8")).toInstant());
|
|
|
+ Date ed = Date.from(localDate.atStartOfDay(ZoneOffset.of("+8")).toInstant());
|
|
|
+ //7天数据
|
|
|
+ List<TwinCalcDay> dayList = twinCalcDayService.selectTwinCalcDayListByTime(sd, ed);
|
|
|
+ Map<Date, List<TwinCalcDay>> dayGroup = dayList.stream().collect(Collectors.groupingBy(TwinCalcDay::getTime, LinkedHashMap::new, Collectors.toList()));
|
|
|
+ List<TwinCalcDay> jdl = new ArrayList<>();
|
|
|
+ for (Map.Entry<Date, List<TwinCalcDay>> entry : dayGroup.entrySet()) {
|
|
|
+ TwinCalcDay day = new TwinCalcDay(entry.getKey());
|
|
|
+ List<TwinCalcDay> days = entry.getValue();
|
|
|
+ day.calcDays(days);
|
|
|
+ jdl.add(day);
|
|
|
+ }
|
|
|
+ //当天数据
|
|
|
+ List<TwinCalcDay> curr = dayList.stream().filter(day -> day.getTime().equals(ed)).collect(Collectors.toList());
|
|
|
+ LocalDateTime sdt = LocalDateTime.of(localDate, LocalTime.of(7, 0));
|
|
|
+ LocalDateTime edt = LocalDateTime.of(localDate.plusDays(1), LocalTime.of(6, 59, 59));
|
|
|
+ Date sTime = Date.from(sdt.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+ Date eTime = Date.from(edt.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+ List<TwinCalcStop> stopList = stopService.selectTwinCalcStopListByDate(sTime, eTime);
|
|
|
+ Map<Integer, List<TwinCalcStop>> stopDeviceGroup = stopList.stream().collect(Collectors.groupingBy(TwinCalcStop::getStopType, LinkedHashMap::new, Collectors.toList()));
|
|
|
+
|
|
|
+ List<TwinCalcStop> yarnStopList = stopList.stream().filter(stop -> stop.getStopType().equals(2)).collect(Collectors.toList());
|
|
|
+ Map<Long, TwinDevice> deviceMap = deviceService.deviceMap();
|
|
|
+ //1停经片停机,2-CCD停机(相机号+断纱/故障),3-人工停机,4-断电停机,5-设备故障停机,6-落布米数达到停机,7-盘头剩余圈数达到停机
|
|
|
+ String[] stopStr = {"停经片停机", "CCD停机(相机号+断纱/故障)", "人工停机", "断电停机", "设备故障停机", "落布米数达到停机", "盘头剩余圈数达到停机"};
|
|
|
+ //停机次数
|
|
|
+ Integer[] stopNum = new Integer[7];
|
|
|
+ Integer totalNum = 0;
|
|
|
+ //停机时间
|
|
|
+ Long[] stopTime = new Long[7];
|
|
|
+ Arrays.fill(stopTime, 0L);
|
|
|
+ AtomicReference<Long> totalTime = new AtomicReference<>(0L);
|
|
|
+ for (Map.Entry<Integer, List<TwinCalcStop>> entry : stopDeviceGroup.entrySet()) {
|
|
|
+ Integer stopType = entry.getKey();
|
|
|
+ int pos = stopType - 1;
|
|
|
+ List<TwinCalcStop> stops = entry.getValue();
|
|
|
+ stopNum[pos] = stops.size();
|
|
|
+ totalNum += stops.size();
|
|
|
+ stops.forEach(stop -> {
|
|
|
+ Date stopEndTime = stop.getEndTime();
|
|
|
+ // 调整停机时间
|
|
|
+ if (stop.getEndTime().compareTo(eTime) > 0) {
|
|
|
+ stopEndTime = eTime;
|
|
|
+ }
|
|
|
+ Date stopStartTime = stop.getStartTime();
|
|
|
+ //调整开机时间
|
|
|
+ if (stop.getStartTime().compareTo(sTime) < 0) {
|
|
|
+ stopStartTime = sTime;
|
|
|
+ }
|
|
|
+ long t = (stopEndTime.getTime() - stopStartTime.getTime()) / 1000;
|
|
|
+ stopTime[pos] += t;
|
|
|
+ totalTime.updateAndGet(v -> v + t);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ try (FileInputStream inputStream = new FileInputStream(brokenYarnExcelTemplate); Workbook wb = new XSSFWorkbook(inputStream); OutputStream outputStream = new BufferedOutputStream(response.getOutputStream())) {
|
|
|
+ CreationHelper creationHelper = wb.getCreationHelper();
|
|
|
+ CellStyle percentStyle = wb.createCellStyle();
|
|
|
+ percentStyle.setDataFormat(creationHelper.createDataFormat().getFormat("0.00%"));
|
|
|
+ CellStyle p2 = wb.createCellStyle();
|
|
|
+ p2.setDataFormat(wb.createDataFormat().getFormat("0.00"));
|
|
|
+ CellStyle dateStyle = wb.createCellStyle();
|
|
|
+ dateStyle.setDataFormat(creationHelper.createDataFormat().getFormat(DateUtils.YYYY_MM_DD));
|
|
|
+ CellStyle timeStyle = wb.createCellStyle();
|
|
|
+ timeStyle.setDataFormat(creationHelper.createDataFormat().getFormat(DateUtils.YYYY_MM_DD_HH_MM_SS));
|
|
|
+ CellStyle rightStyle = wb.createCellStyle();
|
|
|
+ rightStyle.setAlignment(HorizontalAlignment.RIGHT);
|
|
|
+ //1.基本信息
|
|
|
+ Sheet sheet = wb.getSheetAt(0);
|
|
|
+ Cell cell = sheet.getRow(1).getCell(1);
|
|
|
+ cell.setCellValue(localDate);
|
|
|
+
|
|
|
+ //计算开机设备数量,A班开机时间+B班开机时间大于0的。
|
|
|
+ //按设备分组
|
|
|
+ Map<Long, List<TwinCalcDay>> deviceGr = curr.stream().collect(Collectors.groupingBy(TwinCalcDay::getDeviceId, LinkedHashMap::new, Collectors.toList()));
|
|
|
+ int openDevices = 0;
|
|
|
+ BigDecimal totOpenTimes = BigDecimal.ZERO;
|
|
|
+ for (Map.Entry<Long, List<TwinCalcDay>> entry1 : deviceGr.entrySet()) {
|
|
|
+ TwinCalcDay tempDay = new TwinCalcDay(ed);
|
|
|
+ tempDay.calcDays(entry1.getValue());
|
|
|
+ BigDecimal tot = tempDay.getOpenTimeA().add(tempDay.getOpenTimeB());
|
|
|
+ if (tot.intValue() > 0) {
|
|
|
+ openDevices++;
|
|
|
+ }
|
|
|
+ totOpenTimes = totOpenTimes.add(tot);
|
|
|
+ }
|
|
|
+
|
|
|
+ cell = sheet.getRow(2).getCell(1);
|
|
|
+ cell.setCellValue(openDevices);
|
|
|
+ BigDecimal avgOpenTimes = totOpenTimes.divide(BigDecimal.valueOf(openDevices), 0, RoundingMode.HALF_UP);
|
|
|
+
|
|
|
+ cell = sheet.getRow(3).getCell(1);
|
|
|
+ cell.setCellValue(Tools.convertHMS(totOpenTimes.longValue()));
|
|
|
+ cell = sheet.getRow(4).getCell(1);
|
|
|
+ cell.setCellValue(Tools.convertHMS(avgOpenTimes.longValue()));
|
|
|
+ cell = sheet.getRow(5).getCell(1);
|
|
|
+ cell.setCellValue(33);
|
|
|
+ //2.停机原因分析
|
|
|
+ sheet = wb.getSheetAt(1);
|
|
|
+ for (int i = 0; i < stopStr.length; i++) {
|
|
|
+ Row row = sheet.createRow(i + 2);
|
|
|
+ Cell[] cells = new Cell[5];
|
|
|
+ for (int j = 0; j < cells.length; j++) {
|
|
|
+ cells[j] = row.createCell(j);
|
|
|
+ }
|
|
|
+ cells[0].setCellValue(stopStr[i]);
|
|
|
+ cells[1].setCellValue(stopNum[i]);
|
|
|
+ cells[2].setCellValue(Tools.convertHMS(stopTime[i]));
|
|
|
+ cells[2].setCellStyle(rightStyle);
|
|
|
+ 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();
|
|
|
+ cells[3].setCellValue(percentNum);
|
|
|
+ cells[3].setCellStyle(percentStyle);
|
|
|
+ cells[4].setCellValue(percentTimes);
|
|
|
+ cells[4].setCellStyle(percentStyle);
|
|
|
+ }
|
|
|
+ //3.断纱分析
|
|
|
+ sheet = wb.getSheetAt(2);
|
|
|
+ int yst = yarnStopList.size();
|
|
|
+ cell = sheet.getRow(1).getCell(1);
|
|
|
+ cell.setCellValue(yst);
|
|
|
+ Map<Long, List<TwinCalcStop>> deviceGroup = yarnStopList.stream().collect(Collectors.groupingBy(TwinCalcStop::getDeviceId, LinkedHashMap::new, Collectors.toList()));
|
|
|
+ cell = sheet.getRow(2).getCell(1);
|
|
|
+ cell.setCellValue(deviceGroup.size());
|
|
|
+ float bl = 0f;
|
|
|
+ long aavg = 0;
|
|
|
+ if (yst > 0) {
|
|
|
+ bl = BigDecimal.valueOf(yst).divide(BigDecimal.valueOf(stopList.size()), 4, RoundingMode.HALF_UP).floatValue();
|
|
|
+ aavg = stopTime[1] / yst;
|
|
|
+ }
|
|
|
+ cell = sheet.getRow(3).getCell(1);
|
|
|
+ cell.setCellValue(bl);
|
|
|
+
|
|
|
+ cell = sheet.getRow(4).getCell(1);
|
|
|
+ cell.setCellValue(Tools.convertHMS(stopTime[1]));
|
|
|
+ cell = sheet.getRow(5).getCell(1);
|
|
|
+ cell.setCellValue(Tools.convertHMS(aavg));
|
|
|
+ //4.断纱停机TOP排名
|
|
|
+ sheet = wb.getSheetAt(3);
|
|
|
+ //5.并发断纱分析
|
|
|
+ sheet = wb.getSheetAt(4);
|
|
|
+ int rowNum = 1;
|
|
|
+ int rn = 2;
|
|
|
+ yarnStopList.sort(Comparator.comparing(TwinCalcStop::getDataDate).thenComparing(TwinCalcStop::getHour));
|
|
|
+ Map<Date, Map<Integer, List<TwinCalcStop>>> stopHourGroup = yarnStopList.stream().collect(
|
|
|
+ Collectors.groupingBy(TwinCalcStop::getDataDate, LinkedHashMap::new,
|
|
|
+ Collectors.groupingBy(TwinCalcStop::getHour, LinkedHashMap::new, Collectors.toList())));
|
|
|
+ for (Map.Entry<Date, Map<Integer, List<TwinCalcStop>>> entry : stopHourGroup.entrySet()) {
|
|
|
+ Map<Integer, List<TwinCalcStop>> map = entry.getValue();
|
|
|
+ for (Map.Entry<Integer, List<TwinCalcStop>> entry1 : map.entrySet()) {
|
|
|
+ List<TwinCalcStop> stops = entry1.getValue();
|
|
|
+ Row row = sheet.createRow(rowNum);
|
|
|
+ Cell[] cells = new Cell[7];
|
|
|
+ for (int j = 0; j < cells.length; j++) {
|
|
|
+ cells[j] = row.createCell(j);
|
|
|
+ }
|
|
|
+ cells[0].setCellValue(entry.getKey());
|
|
|
+ cells[0].setCellStyle(dateStyle);
|
|
|
+ cells[1].setCellValue(entry1.getKey());
|
|
|
+ Map<Long, List<TwinCalcStop>> yarnDeviceGroup = stops.stream().collect(Collectors.groupingBy(TwinCalcStop::getDeviceId, LinkedHashMap::new, Collectors.toList()));
|
|
|
+ cells[2].setCellValue(yarnDeviceGroup.size());
|
|
|
+ int num = stops.size();
|
|
|
+ cells[3].setCellValue(num);
|
|
|
+ //0.最小,1.最大,2.总时间
|
|
|
+ final long[] time = {999999L, 0, 0};
|
|
|
+ //6.设备断纱停机详情
|
|
|
+ Sheet sheet6 = wb.getSheetAt(5);
|
|
|
+ for (TwinCalcStop stop : stops) {
|
|
|
+ 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;
|
|
|
+
|
|
|
+ Row r1 = sheet6.createRow(rn);
|
|
|
+ Cell[] cs = new Cell[6];
|
|
|
+ for (int j = 0; j < cs.length; j++) {
|
|
|
+ cs[j] = r1.createCell(j);
|
|
|
+ }
|
|
|
+ cs[0].setCellValue(stop.getDataDate());
|
|
|
+ cs[0].setCellStyle(dateStyle);
|
|
|
+ cs[1].setCellValue(stop.getHour());
|
|
|
+ cs[2].setCellValue(deviceMap.get(stop.getDeviceId()).getDeviceName());
|
|
|
+ cs[3].setCellValue(stopStr[stop.getStopType() - 1]);
|
|
|
+ cs[4].setCellValue(stop.getStartTime());
|
|
|
+ cs[4].setCellStyle(timeStyle);
|
|
|
+ cs[5].setCellValue(stop.getEndTime());
|
|
|
+ cs[5].setCellStyle(timeStyle);
|
|
|
+ rn++;
|
|
|
+ }
|
|
|
+
|
|
|
+ cells[4].setCellValue(time[1]);
|
|
|
+ cells[5].setCellValue(time[0]);
|
|
|
+ float avg = BigDecimal.valueOf(time[2]).divide(BigDecimal.valueOf(num), 2, RoundingMode.HALF_UP).floatValue();
|
|
|
+ cells[6].setCellValue(avg);
|
|
|
+ cells[6].setCellStyle(p2);
|
|
|
+ rowNum++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 清空response
|
|
|
+ response.reset();
|
|
|
+ // 设置response的Header
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+ //Content-Disposition的作用:告知浏览器以何种方式显示响应返回的文件,用浏览器打开还是以附件的形式下载到本地保存
|
|
|
+ //attachment表示以附件方式下载 inline表示在线打开 "Content-Disposition: inline; filename=文件名.mp3"
|
|
|
+ // filename表示文件的默认名称,因为网络传输只支持URL编码的相关支付,因此需要将文件名URL编码后进行传输,前端收到后需要反编码才能获取到真正的名称
|
|
|
+ response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("断纱分析日报" + localDate + ".xlsx", "UTF-8"));
|
|
|
+ response.setContentType("application/octet-stream");
|
|
|
+ wb.write(outputStream);
|
|
|
+ outputStream.flush();
|
|
|
+ } catch (IOException ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@ApiOperation("导出停机数据")
|
|
|
@GetMapping("/export/stops")
|
|
|
@CrossOrigin(origins = "*")
|
|
@@ -539,12 +765,7 @@ public class ApiController extends BaseController {
|
|
|
}
|
|
|
cells[0].setCellValue(stopStr[i]);
|
|
|
cells[1].setCellValue(stopNum[i]);
|
|
|
- long minutes = stopTime[i] / 60;
|
|
|
- // 分钟差
|
|
|
- long seconds = stopTime[i] % 60;
|
|
|
- // 秒数差,不包括分钟的秒数
|
|
|
- String vv = minutes + "分" + (seconds > 10 ? seconds : "0" + seconds) + "秒";
|
|
|
- cells[2].setCellValue(vv);
|
|
|
+ cells[2].setCellValue(Tools.convertHMS(stopTime[i]));
|
|
|
cells[2].setCellStyle(rightStyle);
|
|
|
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();
|
|
@@ -570,10 +791,7 @@ public class ApiController extends BaseController {
|
|
|
cells[3].setCellValue(stop.getEndTime());
|
|
|
cells[3].setCellStyle(timeStyle);
|
|
|
Duration duration = Duration.between(stop.getStartTime().toInstant(), stop.getEndTime().toInstant());
|
|
|
- long minutes = duration.toMinutes(); // 分钟差
|
|
|
- long seconds = duration.getSeconds() % 60; // 秒数差,不包括分钟的秒数
|
|
|
- String vv = minutes + "分" + (seconds > 10 ? seconds : "0" + seconds) + "秒";
|
|
|
- cells[4].setCellValue(vv);
|
|
|
+ cells[4].setCellValue(Tools.convertHMS(duration.getSeconds()));
|
|
|
cells[4].setCellStyle(rightStyle);
|
|
|
rowNum.getAndIncrement();
|
|
|
});
|