|
@@ -158,10 +158,10 @@ public class BrokenYarnExportServiceImpl {
|
|
|
int[] pos = {0, 10, 5, 30};
|
|
|
int[] data = {2, 8, 3, 3};
|
|
|
int[] xdata = {2, 8, 0, 0};
|
|
|
- drawBar(sheet, "停机次数占比","停机原因", pos, xdata, data);
|
|
|
+ drawBar(sheet, "停机次数占比", "停机原因", pos, xdata, data);
|
|
|
int[] pos1 = {6, 10, 16, 30};
|
|
|
int[] data1 = {2, 8, 4, 4};
|
|
|
- drawBar(sheet, "停机时长占比","停机原因", pos1, xdata, data1);
|
|
|
+ drawBar(sheet, "停机时长占比", "停机原因", pos1, xdata, data1);
|
|
|
|
|
|
brokenYarn(wb, yarnStopList, stopTime[1], stopList.size());
|
|
|
yarn(wb, yarnStopList, dateStyle, timeStyle, p2);
|
|
@@ -169,13 +169,20 @@ public class BrokenYarnExportServiceImpl {
|
|
|
}
|
|
|
|
|
|
public void top(XSSFWorkbook wb, LocalDate localDate) {
|
|
|
- LocalDateTime sdt = LocalDateTime.of(localDate.minusDays(7), LocalTime.of(7, 0));
|
|
|
+ LocalDateTime sdt = LocalDateTime.of(localDate.minusDays(6), 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);
|
|
|
+ List<TwinCalcStop> yarnStopList = stopService.selectTwinCalcStopListByDate(sTime, eTime, 2);
|
|
|
|
|
|
- List<TwinCalcStop> yarnStopList = stopList.stream().filter(stop -> stop.getStopType().equals(2)).collect(Collectors.toList());
|
|
|
+ yarnStopList.forEach(stop -> {
|
|
|
+ if (stop.getHour() < 7) {
|
|
|
+ Date d = stop.getDataDate();
|
|
|
+ stop.setDataDate(DateUtils.addDays(d, -1));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ Map<Long, Map<Date, Long>> weekData = yarnStopList.stream().collect(Collectors.groupingBy(TwinCalcStop::getDeviceId, Collectors.groupingBy(TwinCalcStop::getDataDate, Collectors.counting())));
|
|
|
+ List<Date> dateList = yarnStopList.stream().map(TwinCalcStop::getDataDate).distinct().sorted().collect(Collectors.toList());
|
|
|
Map<Long, Long> collect = yarnStopList.parallelStream().collect(Collectors.groupingBy(TwinCalcStop::getDeviceId, Collectors.counting()));
|
|
|
Map<Long, Long> sortedMap = collect.entrySet()
|
|
|
.stream()
|
|
@@ -188,23 +195,77 @@ public class BrokenYarnExportServiceImpl {
|
|
|
Map<Long, TwinDevice> deviceMap = deviceService.deviceMap();
|
|
|
XSSFSheet sheet = wb.getSheetAt(3);
|
|
|
Cell cell = sheet.getRow(0).getCell(0);
|
|
|
+ for (int i = 0; i < dateList.size(); i++) {
|
|
|
+ Cell dateCell = sheet.getRow(1).getCell(i + 2);
|
|
|
+ dateCell.setCellValue(dateList.get(i));
|
|
|
+ }
|
|
|
+
|
|
|
String title = "断纱停机周TOP排名\n(" + DateUtils.parseTimeToStr(sdt) + "至" + DateUtils.parseTimeToStr(edt) + ")";
|
|
|
cell.setCellValue(title);
|
|
|
int rn = 2;
|
|
|
for (Map.Entry<Long, Long> entry : sortedMap.entrySet()) {
|
|
|
Long deviceId = entry.getKey();
|
|
|
Row r1 = sheet.createRow(rn);
|
|
|
- Cell cell1 = r1.createCell(0);
|
|
|
- Cell cell2 = r1.createCell(1);
|
|
|
- cell1.setCellValue(deviceMap.get(deviceId).getDeviceName());
|
|
|
- cell2.setCellValue(entry.getValue());
|
|
|
+ Cell[] cells = new Cell[9];
|
|
|
+ for (int j = 0; j < cells.length; j++) {
|
|
|
+ cells[j] = r1.createCell(j);
|
|
|
+ }
|
|
|
+ cells[0].setCellValue(deviceMap.get(deviceId).getDeviceName());
|
|
|
+ cells[1].setCellValue(entry.getValue());
|
|
|
+ Map<Date, Long> xx = weekData.get(deviceId);
|
|
|
+ for (int i = 0; i < dateList.size(); i++) {
|
|
|
+ Long v = xx.get(dateList.get(i));
|
|
|
+ if (v == null) {
|
|
|
+ v = 0L;
|
|
|
+ }
|
|
|
+ cells[i + 2].setCellValue(v);
|
|
|
+ }
|
|
|
rn++;
|
|
|
}
|
|
|
|
|
|
- int[] pos = {4, 2, 10, rn};
|
|
|
+ int[] pos = {10, 2, 16, rn};
|
|
|
int[] data = {2, rn, 1, 1};
|
|
|
int[] xdata = {2, rn, 0, 0};
|
|
|
- drawBar(sheet, "断纱停机周TOP","设备名称", pos, xdata, data);
|
|
|
+ drawBar(sheet, "断纱停机周TOP", "设备名称", pos, xdata, data);
|
|
|
+ drawTopLine(sheet, rn);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void drawTopLine(XSSFSheet sheet, int endRn) {
|
|
|
+ XSSFDrawing drawing = sheet.createDrawingPatriarch();
|
|
|
+ // 2 左侧距离单元格个数, 4 顶部距离单元格个数, 7 左侧距离单元格个数, 26 顶部距离单元格个数
|
|
|
+ XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, endRn+1, 15, endRn+26);
|
|
|
+ XSSFChart chart = drawing.createChart(anchor);
|
|
|
+ // 图表标题
|
|
|
+ chart.setTitleText("断纱停机趋势");
|
|
|
+ // 图例是否覆盖标题
|
|
|
+ chart.setTitleOverlay(false);
|
|
|
+ XDDFChartLegend legend = chart.getOrAddLegend();
|
|
|
+ // 图例位置:上下左右
|
|
|
+ legend.setPosition(LegendPosition.BOTTOM);
|
|
|
+ // 创建x轴
|
|
|
+ XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.LEFT);
|
|
|
+ // X轴标题
|
|
|
+ bottomAxis.setTitle("日期");
|
|
|
+ // y轴标题
|
|
|
+ XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
|
|
|
+ leftAxis.setTitle("单位:次");
|
|
|
+ // y轴数据
|
|
|
+ // 分类轴标(X轴)数据,单元格范围位置[0, 0]到[0, 6]
|
|
|
+ XDDFDataSource<String> xData = XDDFDataSourcesFactory.fromStringCellRange(sheet, new CellRangeAddress(1, 1, 2, 8));
|
|
|
+ // 创建y轴
|
|
|
+ XDDFLineChartData data = (XDDFLineChartData) chart.createData(ChartTypes.LINE, bottomAxis, leftAxis);
|
|
|
+ for (int i = 2; i < endRn; i++) {
|
|
|
+ // 创建y轴
|
|
|
+ XDDFNumericalDataSource<Double> yData = XDDFDataSourcesFactory.fromNumericCellRange(sheet, new CellRangeAddress(i, i, 2, 8));
|
|
|
+ XDDFLineChartData.Series series = (XDDFLineChartData.Series) data.addSeries(xData, yData);
|
|
|
+ // 图例标题
|
|
|
+ series.setTitle(sheet.getRow(i).getCell(0).getStringCellValue(), null);
|
|
|
+ // 线条样式:true平滑曲线,false折线
|
|
|
+ series.setSmooth(true);
|
|
|
+ // 点的样式
|
|
|
+// series.setMarkerStyle(MarkerStyle.CIRCLE);
|
|
|
+ }
|
|
|
+ chart.plot(data);
|
|
|
}
|
|
|
|
|
|
private void drawLine(XSSFSheet sheet, List<TwinCalcDay> dayList) {
|
|
@@ -271,7 +332,7 @@ public class BrokenYarnExportServiceImpl {
|
|
|
chart.plot(data);
|
|
|
}
|
|
|
|
|
|
- private void drawBar(XSSFSheet sheet, String title,String xTitle, int[] pos, int[] xdata, int[] data) {
|
|
|
+ private void drawBar(XSSFSheet sheet, String title, String xTitle, int[] pos, int[] xdata, int[] data) {
|
|
|
// 创建一个画布
|
|
|
XSSFDrawing drawing = sheet.createDrawingPatriarch();
|
|
|
// 前四个默认0,[0,5]:从0列5行开始;[7,26]:到7列26行结束
|