ezhizao_zx 4 mesiacov pred
rodič
commit
49d735c7ce

+ 4 - 0
src/main/java/cn/ezhizao/project/business/domain/BizProcessInspecion.java

@@ -220,6 +220,10 @@ public class BizProcessInspecion extends BaseEntity
     @TableField(exist = false)
     private String returnReceiptDetailFormCode;
     private Integer adoptStatus;
+    @TableField(exist = false)
+    private Integer start;
+    @TableField(exist = false)
+    private Integer pageSize;
 
     public BizProcessInspecion() {
     }

+ 1 - 0
src/main/java/cn/ezhizao/project/websocket/domain/BizProcessInspectionExport.java

@@ -11,6 +11,7 @@ public class BizProcessInspectionExport {
     private Integer productNum;
     private Integer auditNum;
     private String productionDescription;
+    private String lotCode;
     private Integer materialLoss;
     private String processAlias;
     private String auditStatus;

+ 107 - 0
src/main/java/cn/ezhizao/project/websocket/service/TaskService.java

@@ -1,25 +1,132 @@
 package cn.ezhizao.project.websocket.service;
 
+import cn.ezhizao.common.utils.uuid.SnowflakeIdWorker;
+import cn.ezhizao.framework.aspectj.lang.annotation.Log;
+import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
 import cn.ezhizao.project.business.domain.BizProcessInspecion;
+import cn.ezhizao.project.business.mapper.BizProcessInspecionMapper;
 import cn.ezhizao.project.websocket.WebSocketUser;
+import cn.ezhizao.project.websocket.domain.BizProcessInspectionExport;
+import cn.hutool.poi.excel.ExcelUtil;
+import cn.hutool.poi.excel.ExcelWriter;
+import com.alibaba.fastjson2.JSONObject;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
 
 @Service
 public class TaskService {
     @Resource
     WebSocketUser webSocketUser;
+    @Resource
+    BizProcessInspecionMapper bizProcessInspecionMapper;
+    @Value("${file.upload.path}")
+    private String filePath;
+    @Resource
+    SnowflakeIdWorker snowflakeIdWorker;
     @Async
+    @Log(title = "导出外协审核列表", businessType = BusinessType.EXPORT)
     public void processTaskAsync(BizProcessInspecion bizProcessInspecion) {
         try {
             // 获取所有整年的检查的数量
+            Long count = bizProcessInspecionMapper.getCountForExport(bizProcessInspecion);
+            // 判断行数
+            int pageSize = 1000;
+            int pageNum = 0;
+            int rowIndex = 0;
+            ExcelWriter writer = ExcelUtil.getWriter(true);
+            // 文件导出位置
+            File file = new File(filePath + "/excel");
+            JSONObject result = new JSONObject();
+            // 判断文件夹是否存在,假设不存在则创建
+            if(!file.exists() && !file.isDirectory()) {
+                file.mkdir();
+            }
             // 分页
             // 循环
             // 存到excel中
+            for(;pageNum < (count%1000 > 0 ? (count/1000 + 1) : count/1000); pageNum ++) {
+                bizProcessInspecion.setStart(pageNum * pageSize);
+                bizProcessInspecion.setPageSize(pageSize);
+                List<BizProcessInspectionExport> exportList = bizProcessInspecionMapper.getExportList(bizProcessInspecion);
+                rowIndex = insertToSheet(writer, rowIndex, exportList);
+                // 每页发送消息到前端告知完成状态
+                result.put("progress", BigDecimal.valueOf((long) pageSize * (pageNum + 1)).divide(BigDecimal.valueOf(count), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)));
+                webSocketUser.sendMessage(result.toJSONString());
+            }
+            // excel输出到文件夹
+            // 完成后保存到本地
+            FileOutputStream out = new FileOutputStream(file.getAbsolutePath() +"/" + snowflakeIdWorker.nextId() + ".xlsx");
+            writer.flush(out);
+            writer.close();
+            result.put("progress", 100);
+            webSocketUser.sendMessage(result.toJSONString());
         } catch (Exception e) {
             // 处理错误
+            JSONObject err = new JSONObject();
+            err.put("err", "保存出错");
+            try {
+                webSocketUser.sendMessage(err.toJSONString());
+            } catch (IOException ex) {
+                throw new RuntimeException(ex);
+            }
+            throw new RuntimeException("导出错误");
+        }
+    }
+
+    public Integer insertToSheet(ExcelWriter writer, Integer rowIndex, List<BizProcessInspectionExport> data) {
+        if (rowIndex == 0) {
+            // 输出第一行表头
+            writer.writeCellValue(0, rowIndex, "单位编码");
+            writer.writeCellValue(1, rowIndex, "单位简称");
+            writer.writeCellValue(2, rowIndex, "产品描述");
+            writer.writeCellValue(3, rowIndex, "批号");
+            writer.writeCellValue(4, rowIndex, "发出量");
+            writer.writeCellValue(5, rowIndex, "投入数量");
+            writer.writeCellValue(6, rowIndex, "收回量");
+            writer.writeCellValue(7, rowIndex, "料损数量");
+            writer.writeCellValue(8, rowIndex, "工序简称");
+            writer.writeCellValue(9, rowIndex, "发出日期");
+            writer.writeCellValue(10, rowIndex, "收回日期");
+            writer.writeCellValue(11, rowIndex, "审核日期");
+            writer.writeCellValue(12, rowIndex, "结算日期");
+            writer.writeCellValue(13, rowIndex, "发出单号");
+            writer.writeCellValue(14, rowIndex, "收回单号");
+            writer.writeCellValue(15, rowIndex, "箱数");
+            writer.writeCellValue(15, rowIndex, "审核状态");
+            return insertToSheet(writer, rowIndex + 1, data);
+        } else {
+            AtomicInteger i = new AtomicInteger();
+            data.forEach(l -> {
+                writer.writeCellValue(0,rowIndex +  i.get(), l.getMnemonicCode());
+                writer.writeCellValue(1, rowIndex+  i.get(), l.getSupplierName());
+                writer.writeCellValue(2, rowIndex+  i.get(), l.getProductionDescription());
+                writer.writeCellValue(3, rowIndex+  i.get(), l.getLotCode());
+                writer.writeCellValue(4, rowIndex+  i.get(), l.getProductNum());
+                writer.writeCellValue(5, rowIndex+  i.get(), l.getProductNum());
+                writer.writeCellValue(6, rowIndex+  i.get(), l.getAuditNum());
+                writer.writeCellValue(7, rowIndex+  i.get(), l.getMaterialLoss());
+                writer.writeCellValue(8, rowIndex+  i.get(), l.getProcessAlias());
+                writer.writeCellValue(9, rowIndex+  i.get(), l.getOutsourceDate());
+                writer.writeCellValue(10, rowIndex+  i.get(), l.getReturnReceiptDate());
+                writer.writeCellValue(11, rowIndex+  i.get(), l.getAuditDate());
+                writer.writeCellValue(12, rowIndex+  i.get(), l.getBalanceDate());
+                writer.writeCellValue(13, rowIndex+  i.get(), l.getOutsourcedOrderDetailFormCode());
+                writer.writeCellValue(14, rowIndex+  i.get(), l.getReturnReceiptDetailFormCode());
+                writer.writeCellValue(15, rowIndex+  i.get(), l.getCarrierNum());
+                writer.writeCellValue(15, rowIndex+  i.get(), l.getAuditStatus());
+                i.getAndIncrement();
+            });
+            return rowIndex + data.size();
         }
     }
 }

+ 5 - 2
src/main/resources/mybatis/business/BizProcessInspecionMapper.xml

@@ -62,10 +62,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         order by rrd.form_code,rrd.lot_code
     </select>
     <select id="getExportList" parameterType="BizProcessInspecion" resultMap="ExportResult">
-        select bs.code as mnemonic_code, bs.name as supplier_name, bod.product_num, brr.audit_num
+        select bs.code as mnemonic_code, bs.name as supplier_name, bod.product_num, brr.audit_num, bod.lot_code
         , (case when bod.product_num &lt; brr.audit_num then 0 else bod.product_num - brr.audit_num end) as material_loss
         , brr.process_alias
-        , (case when bpi.audit_status = 1 then '已审核' else '未审核' end) as audit_status, bpi.start_time, bpi.end_time, bpi.reject_num, bpi.lot_code, bpi.product_description, bod.form_code, bod.form_date, brr.form_code, brr.form_date, (case when bpi.audit_status = 1 then bpi.update_time else null end) as audit_time, (select boa.update_time from biz_outsource_balance_account boa where boa.status = 1 and boa.process_inspection_id = bpi.id order by update_time desc limit 1) from biz_process_inspecion bpi
+        , (case when bpi.audit_status = 1 then '已审核' else '未审核' end) as audit_status, bpi.start_time, bpi.end_time, bpi.reject_num, bpi.lot_code, bpi.product_description, bod.form_code, bod.form_date, brr.form_code, brr.form_date, (case when bpi.audit_status = 1 then bpi.update_time else null end) as audit_date, (select boa.update_time from biz_outsource_balance_account boa where boa.status = 1 and boa.process_inspection_id = bpi.id order by update_time desc limit 1) as balance_date from biz_process_inspecion bpi
         left join biz_outsourced_order_detail bod on bod.id = bpi.outsource_order_detail_id left join biz_return_receipt_detail brr on brr.id = bpi.return_receipt_detail_id
         left join biz_supplier bs on bs.id = bod.supplier_id
         <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
@@ -84,6 +84,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
                 LIKE CONCAT('%',#{keyword},'%') OR
                 bpi.product_description LIKE CONCAT('%',#{keyword},'%'))</if>
         </trim>
+        <if test="start != null and pageSize != null">
+            limit #{start}, #{pageSize}
+        </if>
     </select>
     <select id="getCountForExport" resultType="java.lang.Long" parameterType="BizProcessInspecion">
         select count(1) from biz_process_inspecion bpi