Pārlūkot izejas kodu

送经量 平方米克重 配方详情导出功能

wukai 4 mēneši atpakaļ
vecāks
revīzija
7456d5439c

+ 46 - 2
jjt-biz/src/main/java/com/jjt/biz/controller/ApiController.java

@@ -2,7 +2,7 @@ package com.jjt.biz.controller;
 
 import com.jjt.biz.domain.TwinDevice;
 import com.jjt.biz.service.ITwinDeviceService;
-import com.jjt.biz.vo.IndexData;
+import com.jjt.biz.vo.*;
 import com.jjt.calc.domain.TwinCalcDay;
 import com.jjt.calc.service.ITwinCalcAlarmsService;
 import com.jjt.calc.service.ITwinCalcDayService;
@@ -16,7 +16,10 @@ import com.jjt.utils.AsyncService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
 import java.time.LocalDate;
@@ -112,4 +115,45 @@ public class ApiController extends BaseController {
         }
         return R.success(result);
     }
+
+
+    @ApiOperation("平方米克重")
+    @GetMapping("/api/gram-mass/total")
+    @CrossOrigin(origins = "*")
+    public R<List<GramMass>> gramMass() {
+        return R.success(redisCache.getCacheObject(CacheConstants.INDEX_GRAM_MASS));
+    }
+
+    @ApiOperation("平方米克重详情")
+    @GetMapping("/api/gram-mass/detail/{gramMass}")
+    @CrossOrigin(origins = "*")
+    public R<List<GramMassDetail>> gramMassDetail(@PathVariable Float gramMass) {
+        List<GramMassDetail> list = redisCache.getCacheObject(CacheConstants.INDEX_GRAM_MASS_DETAIL);
+        if (list != null) {
+            list = list.stream().filter(detail -> detail.getGramMass().equals(gramMass)).collect(Collectors.toList());
+            return R.success(list);
+        } else {
+            return R.fail();
+        }
+    }
+
+    @ApiOperation("配方统计")
+    @GetMapping("/api/formula/total")
+    @CrossOrigin(origins = "*")
+    public R<List<FormulaTotal>> formulaTotal() {
+        return R.success(redisCache.getCacheObject(CacheConstants.INDEX_FORMULA_TOTAL));
+    }
+
+    @ApiOperation("配方详情")
+    @GetMapping("/api/formula/detail/{height}")
+    @CrossOrigin(origins = "*")
+    public R<List<FormulaDetail>> formulaDetail(@PathVariable Float height) {
+        List<FormulaDetail> list = redisCache.getCacheObject(CacheConstants.INDEX_FORMULA_DETAIL);
+        if (list != null) {
+            list = list.stream().filter(detail -> detail.getFormula_data_15().equals(height)).collect(Collectors.toList());
+            return R.success(list);
+        } else {
+            return R.fail();
+        }
+    }
 }

+ 206 - 0
jjt-biz/src/main/java/com/jjt/biz/controller/ApiExportController.java

@@ -0,0 +1,206 @@
+package com.jjt.biz.controller;
+
+import com.jjt.biz.service.ITwinDeviceService;
+import com.jjt.biz.vo.FormulaDetail;
+import com.jjt.biz.vo.GramMass;
+import com.jjt.biz.vo.GramMassDetail;
+import com.jjt.biz.vo.WarpRunIn;
+import com.jjt.calc.service.ITwinCalcAlarmsService;
+import com.jjt.calc.service.ITwinCalcDayService;
+import com.jjt.calc.service.ITwinCalcStopService;
+import com.jjt.common.constant.CacheConstants;
+import com.jjt.common.core.controller.BaseController;
+import com.jjt.common.core.redis.RedisCache;
+import com.jjt.common.utils.DateUtils;
+import com.jjt.utils.AsyncService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+import java.io.BufferedOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URLEncoder;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
+
+/**
+ * Excel导出控制类
+ *
+ * @author ruoyi
+ */
+@Api("数据接口")
+@RestController
+@Slf4j
+public class ApiExportController extends BaseController {
+    @Resource
+    private ITwinCalcDayService twinCalcDayService;
+    @Resource
+    private ITwinCalcStopService stopService;
+    @Resource
+    private ITwinCalcAlarmsService alarmsService;
+    @Resource
+    private ITwinDeviceService deviceService;
+    @Resource
+    private AsyncService asyncService;
+    @Resource
+    private RedisCache redisCache;
+
+    @ApiOperation("送经量")
+    @GetMapping("/api/export/warp-run-in")
+    @CrossOrigin(origins = "*")
+    public void warpRunInExport(HttpServletResponse response) {
+        List<WarpRunIn> list = redisCache.getCacheObject(CacheConstants.INDEX_WARP_RUN_IN);
+        try (Workbook wb = new XSSFWorkbook(); OutputStream outputStream = new BufferedOutputStream(response.getOutputStream())) {
+            Sheet sheet = wb.createSheet("送经量明细");
+            sheet.setDefaultColumnWidth(15);
+            CellStyle style = wb.createCellStyle();
+            style.setDataFormat(wb.createDataFormat().getFormat("0.00"));
+            Row titleRow = sheet.createRow(0);
+            Cell titleCell = titleRow.createCell(0);
+            titleCell.setCellValue("设备名");
+            titleCell = titleRow.createCell(1);
+            titleCell.setCellValue("L1梳栉送经量");
+            titleCell = titleRow.createCell(2);
+            titleCell.setCellValue("L2梳栉送经量");
+            titleCell = titleRow.createCell(3);
+            titleCell.setCellValue("L3梳栉送经量");
+            titleCell = titleRow.createCell(4);
+            titleCell.setCellValue("L4梳栉送经量");
+            titleCell = titleRow.createCell(5);
+            titleCell.setCellValue("L5梳栉送经量");
+            titleCell = titleRow.createCell(6);
+            titleCell.setCellValue("牵拉密度");
+            titleCell = titleRow.createCell(7);
+            titleCell.setCellValue("卷曲张力系数");
+            AtomicInteger rowNum = new AtomicInteger(1);
+            list.forEach(warp -> {
+                Row row = sheet.createRow(rowNum.get());
+                Cell[] cells = new Cell[8];
+                for (int i = 0; i < cells.length; i++) {
+                    cells[i] = row.createCell(i);
+                }
+                warp.setCells(cells, style);
+                rowNum.getAndIncrement();
+            });
+
+            // 清空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("/api/export/gram-mass")
+    @CrossOrigin(origins = "*")
+    public void gramMassExport(HttpServletResponse response) {
+        List<GramMass> list = redisCache.getCacheObject(CacheConstants.INDEX_GRAM_MASS);
+        List<GramMassDetail> details = redisCache.getCacheObject(CacheConstants.INDEX_GRAM_MASS_DETAIL);
+        try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream("tpl/gram.xlsx"); Workbook wb = new XSSFWorkbook(inputStream); OutputStream outputStream = new BufferedOutputStream(response.getOutputStream())) {
+            Sheet sheet = wb.getSheetAt(0);
+
+            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"));
+            AtomicInteger rowNum = new AtomicInteger(1);
+            list.forEach(gram -> {
+                Row row = sheet.createRow(rowNum.get());
+                Cell[] cells = new Cell[3];
+                for (int i = 0; i < cells.length; i++) {
+                    cells[i] = row.createCell(i);
+                }
+                cells[0].setCellValue(gram.getGramMass());
+                cells[0].setCellStyle(p2);
+                cells[1].setCellValue(gram.getNum());
+                cells[2].setCellValue(gram.getPercent());
+                cells[2].setCellStyle(percentStyle);
+                rowNum.getAndIncrement();
+                Sheet ns = wb.cloneSheet(1);
+                wb.setSheetName(wb.getSheetIndex(ns), gram.getGramMass() + "克明细");
+                AtomicInteger detailRowNum = new AtomicInteger(2);
+                details.stream().filter(d -> d.getGramMass().equals(gram.getGramMass())).forEach(d -> {
+                    Row dRow = ns.createRow(detailRowNum.get());
+                    Cell[] dCells = new Cell[24];
+                    for (int i = 0; i < dCells.length; i++) {
+                        dCells[i] = dRow.createCell(i);
+                    }
+                    dCells[2].setCellStyle(p2);
+                    d.setCells(dCells);
+                    detailRowNum.getAndIncrement();
+                });
+            });
+            wb.removeSheetAt(1);
+            // 清空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("/api/formula/export/{height}")
+    @CrossOrigin(origins = "*")
+    public void formulaExport(@PathVariable Float height, HttpServletResponse response) {
+        List<FormulaDetail> list = redisCache.getCacheObject(CacheConstants.INDEX_FORMULA_DETAIL);
+        list = list.stream().filter(detail -> detail.getFormula_data_15().equals(height)).collect(Collectors.toList());
+        try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream("tpl/formula.xlsx"); Workbook wb = new XSSFWorkbook(inputStream); OutputStream outputStream = new BufferedOutputStream(response.getOutputStream())) {
+            Sheet sheet = wb.getSheetAt(0);
+            AtomicInteger rowNum = new AtomicInteger(2);
+
+            list.forEach(detail -> {
+                Row row = sheet.createRow(rowNum.get());
+                Cell[] cells = new Cell[26];
+                for (int i = 0; i < cells.length; i++) {
+                    cells[i] = row.createCell(i);
+                }
+                detail.setCells(cells);
+                rowNum.getAndIncrement();
+            });
+
+            // 清空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("毛高" + height + "设备明细导出" + DateUtils.dateTimeNow() + ".xlsx", "UTF-8"));
+            response.setContentType("application/octet-stream");
+            wb.write(outputStream);
+            outputStream.flush();
+        } catch (IOException ex) {
+            ex.printStackTrace();
+        }
+    }
+}

+ 2 - 0
jjt-biz/src/main/java/com/jjt/biz/vo/FormulaDetail.java

@@ -4,6 +4,7 @@ import com.jjt.biz.domain.TwinDevice;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
+import lombok.NoArgsConstructor;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellStyle;
 
@@ -17,6 +18,7 @@ import java.util.Map;
  */
 @ApiModel(value = "FormulaTotal", description = "配方-统计数据")
 @Data
+@NoArgsConstructor
 public class FormulaDetail {
     @ApiModelProperty("设备信息")
     private String device;

+ 2 - 0
jjt-biz/src/main/java/com/jjt/biz/vo/GramMassDetail.java

@@ -4,6 +4,7 @@ import com.jjt.biz.domain.TwinDevice;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
+import lombok.NoArgsConstructor;
 import org.apache.poi.ss.usermodel.Cell;
 
 import java.math.BigDecimal;
@@ -18,6 +19,7 @@ import java.util.Map;
  */
 @ApiModel(value = "GramMass", description = "平方米克重统计")
 @Data
+@NoArgsConstructor
 public class GramMassDetail {
     @ApiModelProperty("设备信息")
     private String device;

+ 3 - 1
jjt-biz/src/main/java/com/jjt/biz/vo/WarpRunIn.java

@@ -4,6 +4,7 @@ import com.jjt.biz.domain.TwinDevice;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
+import lombok.NoArgsConstructor;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellStyle;
 
@@ -17,6 +18,7 @@ import java.util.Map;
  */
 @ApiModel(value = "WarpRunIn", description = "送经量数据")
 @Data
+@NoArgsConstructor
 public class WarpRunIn {
     @ApiModelProperty("设备信息")
     private String device;
@@ -47,7 +49,7 @@ public class WarpRunIn {
         this.coefficient = (float) map.get("Formula_data_25");
     }
 
-    public void setCells(Cell[] cells,CellStyle style) {
+    public void setCells(Cell[] cells, CellStyle style) {
         cells[0].setCellValue(device);
         cells[1].setCellValue(l1);
         cells[2].setCellValue(l2);

BIN
jjt-biz/src/main/resources/tpl/alarms.xlsx


BIN
jjt-biz/src/main/resources/tpl/brokenYarn.xlsx


BIN
jjt-biz/src/main/resources/tpl/energy-day.xlsx


BIN
jjt-biz/src/main/resources/tpl/energy-month.xlsx


BIN
jjt-biz/src/main/resources/tpl/formula.xlsx


BIN
jjt-biz/src/main/resources/tpl/gram.xlsx


BIN
jjt-biz/src/main/resources/tpl/order.xlsx


BIN
jjt-biz/src/main/resources/tpl/productivity-day.xlsx


BIN
jjt-biz/src/main/resources/tpl/productivity-month.xlsx


BIN
jjt-biz/src/main/resources/tpl/stopDetail.xlsx


BIN
jjt-biz/src/main/resources/tpl/stops.xlsx


BIN
jjt-biz/src/main/resources/tpl/stopsType.xlsx


BIN
jjt-biz/src/main/resources/tpl/template.xlsx


BIN
jjt-biz/src/main/resources/tpl/tmp.xlsx


BIN
jjt-biz/src/main/resources/tpl/total.xlsx


BIN
jjt-biz/src/main/resources/tpl/yarn.xlsx