Răsfoiți Sursa

修改断纱报表

wukai 7 luni în urmă
părinte
comite
e98bcae2bb

+ 10 - 0
ruoyi-admin/src/main/java/com/ruoyi/biz/service/ITwinCalcStopService.java

@@ -78,4 +78,14 @@ public interface ITwinCalcStopService {
      * @return 查询列表
      */
     List<TwinCalcStop> selectTwinCalcStopListByDate(Date sTime, Date eTime);
+
+    /**
+     * 按开始和结束时间查询数据--停机类型)
+     *
+     * @param sTime 开始时间
+     * @param eTime 结束时间
+     * @param type  停机类型
+     * @return 查询列表
+     */
+    List<TwinCalcStop> selectTwinCalcStopListByDate(Date sTime, Date eTime, int type);
 }

+ 1 - 0
ruoyi-admin/src/main/java/com/ruoyi/biz/service/impl/ApiServiceImpl.java

@@ -161,6 +161,7 @@ public class ApiServiceImpl implements IApiService {
                     continue;
                 }
                 for (int i = 0; i < Tools.ALLOW_ALARM.length; i++) {
+
                     //允许的告警编号
                     boolean flag = (boolean) map.get("Alarm_unit_" + Tools.ALLOW_ALARM[i]);
                     if (flag) {

+ 73 - 12
ruoyi-admin/src/main/java/com/ruoyi/biz/service/impl/BrokenYarnExportServiceImpl.java

@@ -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行结束

+ 18 - 0
ruoyi-admin/src/main/java/com/ruoyi/biz/service/impl/TwinCalcStopServiceImpl.java

@@ -214,4 +214,22 @@ public class TwinCalcStopServiceImpl implements ITwinCalcStopService {
         stop.setParams(params);
         return selectTwinCalcStopList(stop);
     }
+
+    /**
+     * 按开始和结束时间查询数据(生产天)
+     *
+     * @param sTime 开始时间
+     * @param eTime 结束时间
+     * @return 查询列表
+     */
+    @Override
+    public List<TwinCalcStop> selectTwinCalcStopListByDate(Date sTime, Date eTime, int type) {
+        TwinCalcStop stop = new TwinCalcStop();
+        stop.setStopType(type);
+        Map<String, Object> params = new HashMap<>(16);
+        params.put("sTime", sTime);
+        params.put("eTime", eTime);
+        stop.setParams(params);
+        return selectTwinCalcStopList(stop);
+    }
 }

+ 1 - 1
ruoyi-admin/src/main/java/com/ruoyi/biz/tools/Tools.java

@@ -46,7 +46,7 @@ public class Tools {
      * Alarm_unit_26	BOOL	拍照自停
      * Alarm_unit_27	UINT	CCD位置报警信息显示
      */
-    public static final int[] ALLOW_ALARM = {8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 26, 27};
+    public static final int[] ALLOW_ALARM = {8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 26};
 
     /**
      * 查找编号是否允许告警

+ 4 - 1
ruoyi-admin/src/main/resources/mapper/biz/TwinCalcStopMapper.xml

@@ -49,7 +49,10 @@
             <if test="updatedTime != null ">and UPDATED_TIME = #{updatedTime}</if>
             <if test="remark != null  and remark != ''">and REMARK = #{remark}</if>
             <if test="params.sTime != null and params.eTime != null">
-                and (start_time&lt;=#{params.eTime} and end_time>=#{params.sTime})
+                and (DATE_ADD(data_date, INTERVAL hour HOUR)&lt;=#{params.eTime} and DATE_ADD(data_date, INTERVAL hour HOUR)>=#{params.sTime})
+            </if>
+            <if test="params.st != null and params.et != null">
+                and (data_date &lt;= #{params.eTime} and hour>=7) and (end_time>=#{params.sTime} and hour &lt; 7)
             </if>
         </where>
         order by START_TIME