Kaynağa Gözat

增加送经量导出,已经小BUG修改。

wukai 11 ay önce
ebeveyn
işleme
2c96c295fe

+ 82 - 13
ruoyi-admin/src/main/java/com/ruoyi/biz/controller/ApiController.java

@@ -13,10 +13,7 @@ import com.ruoyi.system.service.ISysConfigService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
@@ -30,6 +27,7 @@ import java.io.OutputStream;
 import java.net.URLEncoder;
 import java.text.ParseException;
 import java.time.LocalDate;
+import java.time.LocalDateTime;
 import java.time.ZoneOffset;
 import java.util.*;
 import java.util.concurrent.ExecutionException;
@@ -125,15 +123,29 @@ public class ApiController extends BaseController {
             throw new RuntimeException(e);
         }
         if (week != null) {
-//            List<TwinCalc2hr> list = calc2hrService.selectWeekData(info);
-//            List<Map<String, Object>> alarms = new ArrayList<>();
-//            list.forEach(calc2hr -> {
-//                Map<String, Object> temp = new HashMap<>(16);
-//                temp.put("time", DateUtils.parseDateToStr(calc2hr.getDataDate()));
-//                temp.put("value", calc2hr.getAlarm());
-//                alarms.add(temp);
-//            });
-//            result.put("alarms", alarms);
+            /*
+             *获取前面7天的数据
+             */
+            LocalDateTime ldt = LocalDateTime.now();
+            if (ldt.getHour() < 7) {
+                //7点前是属于前一生产天
+                ldt = ldt.minusDays(1);
+            }
+            LocalDate localDate = ldt.toLocalDate().minusDays(7);
+            Date date = Date.from(localDate.atStartOfDay(ZoneOffset.of("+8")).toInstant());
+            List<TwinCalcDay> list = twinCalcDayService.selectTwinCalcDayListByTime(date);
+            List<Map<String, Object>> alarms = new ArrayList<>();
+            Map<Date, List<TwinCalcDay>> stopDeviceGroup = list.stream().collect(Collectors.groupingBy(TwinCalcDay::getTime, LinkedHashMap::new, Collectors.toList()));
+            for (Map.Entry<Date, List<TwinCalcDay>> entry : stopDeviceGroup.entrySet()) {
+                Map<String, Object> temp = new HashMap<>(16);
+                TwinCalcDay day = new TwinCalcDay(entry.getKey());
+                List<TwinCalcDay> days = entry.getValue();
+                day.calcDays(days);
+                temp.put("time", DateUtils.parseDateToStr(entry.getKey()));
+                temp.put("value", day.getAlarm());
+                alarms.add(temp);
+            }
+            result.put("alarms", alarms);
         }
         return R.ok(result);
     }
@@ -151,6 +163,63 @@ public class ApiController extends BaseController {
         }
     }
 
+    @ApiOperation("送经量")
+    @GetMapping("/warp/run-in")
+    @CrossOrigin(origins = "*")
+    public void warpRunIn(HttpServletResponse response) {
+        Object d = CacheUtils.get(Constants.IOT_TOKEN, Constants.INDEX_WARP_RUN_IN);
+        if (d != null) {
+            List<WarpRunIn> list = (List<WarpRunIn>) d;
+            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("送经量明细导出" + System.currentTimeMillis() + ".xlsx", "UTF-8"));
+                response.setContentType("application/octet-stream");
+                wb.write(outputStream);
+                outputStream.flush();
+            } catch (IOException ex) {
+                ex.printStackTrace();
+            }
+        }
+    }
+
     @ApiOperation("配方详情")
     @GetMapping("/formula/detail/{height}")
     @CrossOrigin(origins = "*")

+ 1 - 1
ruoyi-admin/src/main/java/com/ruoyi/biz/domain/TwinCalcDay.java

@@ -320,7 +320,7 @@ public class TwinCalcDay extends BaseEntity {
         days.forEach(day -> {
             this.weight = weight.add(day.getWeight());
             this.weightA = weightA.add(day.getWeightA());
-            this.weightB = weightA.add(day.getWeightB());
+            this.weightB = weightB.add(day.getWeightB());
 
             this.kwh = kwh.add(day.getKwh());
             this.kwhA = kwhA.add(day.getKwh());

+ 61 - 0
ruoyi-admin/src/main/java/com/ruoyi/biz/domain/WarpRunIn.java

@@ -0,0 +1,61 @@
+package com.ruoyi.biz.domain;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
+
+import java.util.Map;
+
+/**
+ * 周曲线
+ *
+ * @author wukai
+ * @date 2024/5/8 15:50
+ */
+@ApiModel(value = "WarpRunIn", description = "送经量数据")
+@Data
+public class WarpRunIn {
+    @ApiModelProperty("设备信息")
+    private String device;
+    @ApiModelProperty("L1梳栉送经量")
+    private Integer l1;
+    @ApiModelProperty("L2梳栉送经量")
+    private Integer l2;
+    @ApiModelProperty("L3梳栉送经量")
+    private Integer l3;
+    @ApiModelProperty("L4梳栉送经量")
+    private Integer l4;
+    @ApiModelProperty("L5梳栉送经量")
+    private Integer l5;
+    @ApiModelProperty("牵拉密度")
+    private Float density;
+    @ApiModelProperty("卷曲张力系数")
+    private Float coefficient;
+
+    public WarpRunIn(Map<String, Object> map) {
+        TwinDevice twinDevice = (TwinDevice) map.get("device");
+        this.device = twinDevice.getDeviceName();
+        this.l1 = (int) map.get("Formula_data_19");
+        this.l2 = (int) map.get("Formula_data_20");
+        this.l3 = (int) map.get("Formula_data_21");
+        this.l4 = (int) map.get("Formula_data_22");
+        this.l5 = (int) map.get("Formula_data_23");
+        this.density = (float) map.get("Formula_data_24");
+        this.coefficient = (float) map.get("Formula_data_25");
+    }
+
+    public void setCells(Cell[] cells,CellStyle style) {
+        cells[0].setCellValue(device);
+        cells[1].setCellValue(l1);
+        cells[2].setCellValue(l2);
+        cells[3].setCellValue(l3);
+        cells[4].setCellValue(l4);
+        cells[5].setCellValue(l5);
+        cells[6].setCellValue(density);
+        cells[6].setCellStyle(style);
+        cells[7].setCellValue(coefficient);
+        cells[7].setCellStyle(style);
+    }
+}

+ 15 - 3
ruoyi-admin/src/main/java/com/ruoyi/biz/service/impl/ApiServiceImpl.java

@@ -14,6 +14,7 @@ import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.time.LocalDate;
+import java.time.LocalDateTime;
 import java.time.ZoneOffset;
 import java.util.*;
 import java.util.concurrent.ExecutionException;
@@ -70,14 +71,18 @@ public class ApiServiceImpl implements IApiService {
         efficiency.setTotalWeight(calcDay.getWeight().floatValue());
         efficiency.setAWeight(calcDay.getWeightA().floatValue());
         efficiency.setBWeight(calcDay.getWeightB().floatValue());
-        efficiency.setATime(calcDay.getOpenTimeA().add(calcDay.getCloseTimeA()).divide(BigDecimal.valueOf(3600), 2, BigDecimal.ROUND_HALF_UP).floatValue());
-        efficiency.setBTime(calcDay.getOpenTimeB().add(calcDay.getCloseTimeB()).divide(BigDecimal.valueOf(3600), 2, BigDecimal.ROUND_HALF_UP).floatValue());
+        efficiency.setATime(calcDay.getOpenTimeA().divide(BigDecimal.valueOf(3600), 2, BigDecimal.ROUND_HALF_UP).floatValue());
+        efficiency.setBTime(calcDay.getOpenTimeB().divide(BigDecimal.valueOf(3600), 2, BigDecimal.ROUND_HALF_UP).floatValue());
         indexData.setEfficiency(efficiency);
 
         /*
          *获取前面7天的数据
          */
-        LocalDate localDate = LocalDate.now().minusDays(7);
+        LocalDateTime ldt = LocalDateTime.now();
+        if (ldt.getHour() < 7) {
+            ldt = ldt.minusDays(1);
+        }
+        LocalDate localDate = ldt.toLocalDate().minusDays(7);
         Date date = Date.from(localDate.atStartOfDay(ZoneOffset.of("+8")).toInstant());
         List<TwinCalcDay> list = twinCalcDayService.selectTwinCalcDayListByTime(date);
         Map<Date, List<TwinCalcDay>> stopDeviceGroup = list.stream().collect(Collectors.groupingBy(TwinCalcDay::getTime, LinkedHashMap::new, Collectors.toList()));
@@ -103,6 +108,7 @@ public class ApiServiceImpl implements IApiService {
         List<IndexPan> panList = new ArrayList<>();
         //配方统计数据
         List<FormulaTotal> formulaTotal = new ArrayList<>();
+        List<WarpRunIn> warpList = new ArrayList<>();
         //配方明细数据
         List<FormulaDetail> formulaDetail = new ArrayList<>();
         int stop1 = 0, stop2 = 0, stop6 = 0, stop8 = 0;
@@ -134,6 +140,11 @@ public class ApiServiceImpl implements IApiService {
                 FormulaDetail detail = new FormulaDetail(map);
                 formulaDetail.add(detail);
 
+                //处理送经量数据
+                WarpRunIn warpRunIn = new WarpRunIn(map);
+                warpList.add(warpRunIn);
+
+
                 int data4 = (int) map.get("Capacity_data_4");
                 if (data4 == 0) {
                     //Capacity_data_4,如果设定落布米数为0,则证明当前数据无效
@@ -248,6 +259,7 @@ public class ApiServiceImpl implements IApiService {
 
         CacheUtils.put(Constants.IOT_TOKEN, Constants.INDEX_FORMULA_TOTAL, formulaTotal);
         CacheUtils.put(Constants.IOT_TOKEN, Constants.INDEX_FORMULA_DETAIL, formulaDetail);
+        CacheUtils.put(Constants.IOT_TOKEN, Constants.INDEX_WARP_RUN_IN, warpList);
     }
 
     @PostConstruct

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

@@ -86,6 +86,10 @@ public class Constants {
      */
     public static final String INDEX_ALARM = "indexAlarm";
     /**
+     * 送经量数据
+     */
+    public static final String INDEX_WARP_RUN_IN = "indexWarpRunIn";
+    /**
      * 首页配方明细缓存
      */
     public static final String INDEX_FORMULA_DETAIL = "indexFormulaDetail";