|
@@ -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 = "*")
|