Bläddra i källkod

停机明细导出

wukai 8 månader sedan
förälder
incheckning
0fa8356088

+ 151 - 0
ruoyi-admin/src/main/java/com/ruoyi/biz/controller/ApiController.java

@@ -5,11 +5,13 @@ 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.biz.vo.StopDetailVO;
 import com.ruoyi.common.constant.Constants;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.utils.CacheUtils;
 import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.StringUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
@@ -73,6 +75,8 @@ public class ApiController extends BaseController {
     private String stopsExcelTemplate;
     @Value("${excel.stopsType}")
     private String stopsTypeExcelTemplate;
+    @Value("${excel.stopDetail}")
+    private String stopDetailExcelTemplate;
     @Value("${excel.alarms}")
     private String alarmsExcelTemplate;
     @Value("${excel.yarn}")
@@ -700,6 +704,153 @@ public class ApiController extends BaseController {
         }
     }
 
+
+    private void combo(int i, int[] nums, String[] devices, long id) {
+        nums[i]++;
+        if (StringUtils.isNotEmpty(devices[i])) {
+            devices[i] += ",";
+        } else {
+            devices[i] = "";
+        }
+        devices[i] += id;
+    }
+
+    @ApiOperation("导出当前停机明细")
+    @GetMapping("/export/stop")
+    @CrossOrigin(origins = "*")
+    public void stopExport(HttpServletResponse response) throws ParseException {
+        String[] stopStr = {"", "停经片停机", "断纱停机", "人工停机", "断电停机", "设备故障停机", "落布米数达到停机", "叫料停机"};
+        TwinDevice searchDevice = new TwinDevice();
+        searchDevice.setOnline("1");
+        List<TwinDevice> deviceList = deviceService.selectTwinDeviceList(searchDevice);
+        Object d = CacheUtils.get(Constants.IOT_TOKEN, Constants.STOP_DETAIL);
+        if (d != null) {
+            List<StopDetailVO> stopList = (List<StopDetailVO>) d;
+            stopList.sort(Comparator.comparing(StopDetailVO::getDeviceId));
+            int[] nums = new int[10];
+            String[] devices = new String[10];
+            try (FileInputStream inputStream = new FileInputStream(stopDetailExcelTemplate); Workbook wb = new XSSFWorkbook(inputStream); OutputStream outputStream = new BufferedOutputStream(response.getOutputStream())) {
+                CellStyle p2 = wb.createCellStyle();
+                p2.setDataFormat(wb.createDataFormat().getFormat("0.00"));
+                Sheet sheet2 = wb.getSheetAt(1);
+                int rowNum = 2;
+                for (StopDetailVO vo : stopList) {
+                    if (!vo.getHasData()) {
+                        combo(6, nums, devices, vo.getDeviceId());
+                        continue;
+                    }
+                    if (vo.getSpeed() > 0) {
+                        combo(0, nums, devices, vo.getDeviceId());
+                        if (vo.getStop() != 0) {
+                            combo(8, nums, devices, vo.getDeviceId());
+                        }
+                    }
+
+                    switch (vo.getStop()) {
+                        case 0:
+                            combo(9, nums, devices, vo.getDeviceId());
+                            if (vo.getSpeed() == 0f) {
+                                combo(7, nums, devices, vo.getDeviceId());
+                            }
+                            break;
+                        case 1:
+                            combo(1, nums, devices, vo.getDeviceId());
+                            break;
+                        case 2:
+                            combo(2, nums, devices, vo.getDeviceId());
+                            break;
+                        case 6:
+                            combo(3, nums, devices, vo.getDeviceId());
+                            break;
+                        case 7:
+                            combo(4, nums, devices, vo.getDeviceId());
+                            break;
+                        default:
+                            combo(5, nums, devices, vo.getDeviceId());
+                    }
+
+
+                    Row row = sheet2.createRow(rowNum++);
+                    Cell[] cells = new Cell[4];
+                    for (int j = 0; j < cells.length; j++) {
+                        cells[j] = row.createCell(j);
+                    }
+                    cells[0].setCellValue(vo.getDeviceId());
+                    cells[1].setCellValue(vo.getSpeed());
+                    cells[1].setCellStyle(p2);
+                    cells[2].setCellValue(vo.getStop());
+                    cells[3].setCellValue(stopStr[vo.getStop()]);
+                }
+                Sheet sheet1 = wb.getSheetAt(0);
+                Cell cell = sheet1.getRow(2).getCell(2);
+                cell.setCellValue(deviceList.size());
+
+                cell = sheet1.getRow(3).getCell(2);
+                cell.setCellValue(nums[0]);
+                cell = sheet1.getRow(3).getCell(4);
+                cell.setCellValue(devices[0]);
+
+                cell = sheet1.getRow(4).getCell(2);
+                cell.setCellValue(nums[1]);
+                cell = sheet1.getRow(4).getCell(4);
+                cell.setCellValue(devices[1]);
+
+                cell = sheet1.getRow(5).getCell(2);
+                cell.setCellValue(nums[2]);
+                cell = sheet1.getRow(5).getCell(4);
+                cell.setCellValue(devices[2]);
+
+                cell = sheet1.getRow(6).getCell(2);
+                cell.setCellValue(nums[3]);
+                cell = sheet1.getRow(6).getCell(4);
+                cell.setCellValue(devices[3]);
+
+                cell = sheet1.getRow(7).getCell(2);
+                cell.setCellValue(nums[4]);
+                cell = sheet1.getRow(7).getCell(4);
+                cell.setCellValue(devices[4]);
+
+                cell = sheet1.getRow(8).getCell(2);
+                cell.setCellValue(nums[5]);
+                cell = sheet1.getRow(8).getCell(4);
+                cell.setCellValue(devices[5]);
+
+                cell = sheet1.getRow(9).getCell(2);
+                cell.setCellValue(nums[6]);
+                cell = sheet1.getRow(9).getCell(4);
+                cell.setCellValue(devices[6]);
+
+                cell = sheet1.getRow(14).getCell(2);
+                cell.setCellValue(nums[7]);
+                cell = sheet1.getRow(14).getCell(4);
+                cell.setCellValue(devices[7]);
+
+                cell = sheet1.getRow(15).getCell(2);
+                cell.setCellValue(nums[8]);
+                cell = sheet1.getRow(15).getCell(4);
+                cell.setCellValue(devices[8]);
+
+                cell = sheet1.getRow(16).getCell(2);
+                cell.setCellValue(nums[9]);
+                cell = sheet1.getRow(16).getCell(4);
+                cell.setCellValue(devices[9]);
+                // 清空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("停机明细" + DateUtils.dateTimeNow() + ".xlsx", "UTF-8"));
+                response.setContentType("application/octet-stream");
+                wb.write(outputStream);
+                outputStream.flush();
+            } catch (IOException ex) {
+                ex.printStackTrace();
+            }
+        }
+    }
+
     @ApiOperation("停机分类导出")
     @GetMapping("/export/stops/type/{type}")
     @CrossOrigin(origins = "*")

+ 16 - 9
ruoyi-admin/src/main/java/com/ruoyi/biz/service/impl/ApiServiceImpl.java

@@ -3,9 +3,9 @@ package com.ruoyi.biz.service.impl;
 import com.ruoyi.biz.domain.*;
 import com.ruoyi.biz.service.*;
 import com.ruoyi.biz.tools.Tools;
+import com.ruoyi.biz.vo.StopDetailVO;
 import com.ruoyi.common.constant.Constants;
 import com.ruoyi.common.utils.CacheUtils;
-import com.ruoyi.system.service.ISysConfigService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.core.env.Environment;
 import org.springframework.stereotype.Service;
@@ -34,12 +34,8 @@ public class ApiServiceImpl implements IApiService {
     @Resource
     private ITwinCalcDayService twinCalcDayService;
     @Resource
-    private ITwinCalc2hrService calc2hrService;
-    @Resource
     private ITwinPanHeadInfoService panHeadInfoService;
     @Resource
-    private ISysConfigService configService;
-    @Resource
     private ITwinDeviceService deviceService;
     @Resource
     private IIotService iotService;
@@ -134,18 +130,29 @@ public class ApiServiceImpl implements IApiService {
             futureList.add(asyncService.currData(twinDevice));
         }
         int onlineNum = 0;
+        //停机明细
+        List<StopDetailVO> stopList = new ArrayList<>();
         try {
             for (Future<Map<String, Object>> future : futureList) {
                 Map<String, Object> map = future.get();
                 TwinDevice device = (TwinDevice) map.get("device");
-
+                StopDetailVO sdVO = new StopDetailVO();
+                sdVO.setDeviceId(device.getDeviceId());
+                sdVO.setDeviceName(device.getDeviceName());
+                sdVO.setHasData(true);
                 int total = (int) map.get("total");
                 if (total == 0) {
                     //可能会出现接口返回无数据的情况,需要设置设备状态为离线
+                    sdVO.setHasData(false);
+                    stopList.add(sdVO);
                     continue;
                 }
                 float cd1 = (float) map.get("Capacity_data_1");
-                if (cd1 != 0f) {
+                int stopStatus = (int) map.get("Capacity_data_48");
+                sdVO.setStop(stopStatus);
+                sdVO.setSpeed(cd1);
+                stopList.add(sdVO);
+                if (cd1 != 0f && stopStatus == 0) {
                     //主轴运行转速(转/分钟) 为0时,表示未开机
                     onlineNum++;
                 }
@@ -167,7 +174,6 @@ 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) {
@@ -189,7 +195,7 @@ public class ApiServiceImpl implements IApiService {
                     alarmList.add(indexAlarm);
                 }
 
-                int stopStatus = (int) map.get("Capacity_data_48");
+
                 indexAlarm = new IndexAlarm();
                 indexAlarm.setCode(device.getDeviceCode());
                 indexAlarm.setName(device.getDeviceName());
@@ -288,6 +294,7 @@ public class ApiServiceImpl implements IApiService {
         CacheUtils.put(Constants.IOT_TOKEN, Constants.INDEX_WARP_RUN_IN, warpList);
         CacheUtils.put(Constants.IOT_TOKEN, Constants.INDEX_GRAM_MASS, gramMasses);
         CacheUtils.put(Constants.IOT_TOKEN, Constants.INDEX_GRAM_MASS_DETAIL, gramMassDetails);
+        CacheUtils.put(Constants.IOT_TOKEN, Constants.STOP_DETAIL, stopList);
     }
 
     @PostConstruct

+ 24 - 0
ruoyi-admin/src/main/java/com/ruoyi/biz/vo/StopDetailVO.java

@@ -0,0 +1,24 @@
+package com.ruoyi.biz.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+/**
+ * StopDetailVO$
+ *
+ * @author wukai
+ * @date 2024/11/16 23:37
+ */
+@Data
+public class StopDetailVO {
+    @ApiModelProperty(name = "设备编号")
+    private Long deviceId;
+    @ApiModelProperty(name = "设备名称")
+    private String deviceName;
+    @ApiModelProperty(name = "主轴运转速度")
+    private Float speed;
+    @ApiModelProperty(name = "停机状态")
+    private Integer stop;
+    @ApiModelProperty(name = "是否获取到数据")
+    private Boolean hasData;
+}

+ 1 - 0
ruoyi-admin/src/main/resources/application.yml

@@ -13,6 +13,7 @@ excel:
   gram: D:\SYSTEM\Desktop\temp\excel\gram.xlsx
   stops: D:\SYSTEM\Desktop\temp\excel\stops.xlsx
   stopsType: D:\SYSTEM\Desktop\temp\excel\stopsType.xlsx
+  stopDetail: D:\SYSTEM\Desktop\temp\excel\stopDetail.xlsx
   alarms: D:\SYSTEM\Desktop\temp\excel\alarms.xlsx
   yarn: D:\SYSTEM\Desktop\temp\excel\yarn.xlsx
   brokenYarn: D:\SYSTEM\Desktop\temp\excel\brokenYarn.xlsx

+ 6 - 5
ruoyi-admin/src/test/java/com/jjt/JlTest.java

@@ -49,21 +49,22 @@ public class JlTest {
         JSONObject jsonObject = iotService.query(sql);
         JSONObject data = jsonObject.getJSONObject("data");
         JSONArray values = data.getJSONArray("values");
-        int xxx=0;
-        int yyy=0;
+        int xxx = 0;
+        int yyy = 0;
         for (int i = 0; i < values.size(); i++) {
             JSONArray arr = values.getJSONArray(i);
             String name = arr.getStr(0);
             if (name.startsWith("root.tl.suxi.knittings")) {
                 xxx++;
                 Float value = arr.getFloat(1);
-                if (value == 7f) {
+                if (value > 0f) {
                     yyy++;
-                System.err.println(name + "\t" + value);
                 }
+                name = name.replace("root.tl.suxi.knittings", "").replace("_plc1.Capacity_data_48", "");
+                System.err.println(name + "\t" + value);
             }
         }
 
-        System.err.println(xxx+"\t"+yyy);
+        System.err.println(xxx + "\t" + yyy);
     }
 }

+ 1 - 0
ruoyi-admin/src/test/java/com/jjt/OnlineTest.java

@@ -60,6 +60,7 @@ public class OnlineTest {
                 if (value > 0f) {
                     yyy++;
                 }
+                name = name.replace("root.tl.suxi.knittings", "").replace("_plc1.Capacity_data_1", "");
                 System.err.println(name + "\t" + value);
             }
         }

+ 4 - 0
ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java

@@ -94,6 +94,10 @@ public class Constants {
      */
     public static final String INDEX_GRAM_MASS_DETAIL = "indexGramMassDetail";
     /**
+     * 停机明细
+     */
+    public static final String STOP_DETAIL = "stopDetail";
+    /**
      * 平方米克重
      */
     public static final String INDEX_GRAM_MASS = "indexGramMass";