|
@@ -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.service.impl.BrokenYarnExportServiceImpl;
|
|
|
import com.ruoyi.biz.tools.Tools;
|
|
|
import com.ruoyi.common.constant.Constants;
|
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
@@ -67,6 +68,8 @@ public class ApiController extends BaseController {
|
|
|
private ITwinPanHeadInfoService panHeadInfoService;
|
|
|
@Resource
|
|
|
private ISysConfigService configService;
|
|
|
+ @Resource
|
|
|
+ private BrokenYarnExportServiceImpl exportService;
|
|
|
@Value("${excel.total}")
|
|
|
private String totalExcelTemplate;
|
|
|
@Value("${excel.formula}")
|
|
@@ -489,208 +492,13 @@ public class ApiController extends BaseController {
|
|
|
@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);
|
|
|
+ try (FileInputStream inputStream = new FileInputStream(brokenYarnExcelTemplate); XSSFWorkbook wb = new XSSFWorkbook(inputStream); OutputStream outputStream = new BufferedOutputStream(response.getOutputStream())) {
|
|
|
+ //1.基本信息表
|
|
|
+ exportService.base(wb, localDate);
|
|
|
//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));
|
|
|
+ exportService.stop(wb, localDate);
|
|
|
//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++;
|
|
|
- }
|
|
|
- }
|
|
|
+ exportService.top(wb, localDate);
|
|
|
// 清空response
|
|
|
response.reset();
|
|
|
// 设置response的Header
|