ezhizao_zx hai 4 meses
pai
achega
72bce33893

+ 1 - 0
src/main/java/cn/ezhizao/framework/config/SecurityConfig.java

@@ -106,6 +106,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
                 .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
                 // 过滤请求
                 .authorizeRequests()
+                .antMatchers("/wsExport/**").anonymous()
                 // 对于登录login 注册register 验证码captchaImage 允许匿名访问
                 .antMatchers("/login", "/register", "/captchaImage", "/sms/sendSms", "/business/app/getUpdate", "/snms/**", "/mini/**", "/test/**").permitAll()
                 // 静态资源,可匿名访问

+ 9 - 0
src/main/java/cn/ezhizao/project/business/controller/BizProcessInspecionController.java

@@ -69,6 +69,15 @@ public class BizProcessInspecionController extends BaseController
         List<BizProcessInspecion> list = bizProcessInspecionService.getList(bizProcessInspecion);
         return getDataTable(list);
     }
+    @GetMapping("/getExportCount")
+    @Log(title = "查询序检列表", businessType = BusinessType.SELECT)
+    public AjaxResult getExportCount(BizProcessInspecion bizProcessInspecion) throws NoSuchFieldException, IllegalAccessException
+    {
+        setTenantId(bizProcessInspecion);
+//        startPage();
+        Long count = bizProcessInspecionService.getCountForExport(bizProcessInspecion);
+        return success(count);
+    }
     @PostMapping("/save")
     @Log(title = "保存序检详情", businessType = BusinessType.SELECT)
     public AjaxResult save(@RequestBody BizProcessInspecion processInspecion) throws NoSuchFieldException, IllegalAccessException

+ 2 - 0
src/main/java/cn/ezhizao/project/business/service/IBizProcessInspecionService.java

@@ -32,4 +32,6 @@ public interface IBizProcessInspecionService extends IService<BizProcessInspecio
     public List<BizProcessInspecion> getAllList();
 
     List<BizProcessInspecion> getVerifyList(BizProcessInspecion bizProcessInspecion);
+
+    Long getCountForExport(BizProcessInspecion bizProcessInspecion);
 }

+ 5 - 0
src/main/java/cn/ezhizao/project/business/service/impl/BizProcessInspecionServiceImpl.java

@@ -61,6 +61,11 @@ public class BizProcessInspecionServiceImpl extends ServiceImpl<BizProcessInspec
         return bizProcessInspecionMapper.getVerifyList(bizProcessInspecion);
     }
 
+    @Override
+    public Long getCountForExport(BizProcessInspecion bizProcessInspecion) {
+        return bizProcessInspecionMapper.getCountForExport(bizProcessInspecion);
+    }
+
     ;
 
 }

+ 4 - 0
src/main/java/cn/ezhizao/project/websocket/WebSocketUser.java

@@ -1,6 +1,7 @@
 package cn.ezhizao.project.websocket;
 
 import cn.ezhizao.project.business.domain.BizProcessInspecion;
+import cn.ezhizao.project.websocket.service.TaskService;
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONObject;
 import org.apache.commons.lang3.StringUtils;
@@ -39,6 +40,8 @@ public class WebSocketUser {
      */
     private String userId = "";
     private String type = "";
+    @Resource
+    TaskService taskService;
 
 //
 //    private static DataInformationServiceImpl dataInformationService;
@@ -97,6 +100,7 @@ public class WebSocketUser {
 //                JSONObject jsonObject = JSON.parseObject(message);
                 JSONObject j = JSON.parseObject(message);
                 BizProcessInspecion i = j.toJavaObject(BizProcessInspecion.class);
+//                taskService.processTaskAsync(i);
                 // 导出excel
             } catch (Exception e) {
                 e.printStackTrace();

+ 43 - 0
src/main/java/cn/ezhizao/project/websocket/controller/AsyncExportController.java

@@ -0,0 +1,43 @@
+package cn.ezhizao.project.websocket.controller;
+
+import cn.ezhizao.common.utils.poi.ExcelUtil;
+import cn.ezhizao.framework.aspectj.lang.annotation.Log;
+import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;
+import cn.ezhizao.framework.web.controller.BaseController;
+import cn.ezhizao.framework.web.domain.AjaxResult;
+import cn.ezhizao.project.business.domain.BizApp;
+import cn.ezhizao.project.business.domain.BizProcessInspecion;
+import cn.ezhizao.project.websocket.WebSocketUser;
+import cn.ezhizao.project.websocket.service.TaskService;
+import com.alibaba.fastjson2.JSONObject;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+
+@RestController
+@RequestMapping("/business/asyncExport")
+public class AsyncExportController extends BaseController {
+    @Resource
+    private TaskService taskService;
+//    @Resource
+//    private WebSocketUser webSocketUser;
+
+//    @PreAuthorize("@ss.hasPermi('business:asyncExport:export')")
+    @Log(title = "外协审核导出", businessType = BusinessType.EXPORT)
+    @PostMapping("/processInspectionexport")
+    public AjaxResult export(HttpServletResponse response, @RequestBody BizProcessInspecion bizProcessInspecion) throws IOException {
+        taskService.processTaskAsync(bizProcessInspecion, getUserId());
+        JSONObject result = new JSONObject();
+        result.put("status", "start");
+//        WebSocketUser.sendInfo(result.toJSONString(), String.valueOf(getUserId()));
+        // 开始导出
+        return success();
+    }
+}

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

@@ -10,7 +10,7 @@ public class BizProcessInspectionExport {
     private String mnemonicCode;
     private Integer productNum;
     private Integer auditNum;
-    private String productionDescription;
+    private String productDescription;
     private String lotCode;
     private Integer materialLoss;
     private String processAlias;

+ 25 - 17
src/main/java/cn/ezhizao/project/websocket/service/TaskService.java

@@ -25,17 +25,20 @@ import java.util.concurrent.atomic.AtomicInteger;
 
 @Service
 public class TaskService {
-    @Resource
-    WebSocketUser webSocketUser;
+//    @Resource
+//    WebSocketUser webSocketUser;
     @Resource
     BizProcessInspecionMapper bizProcessInspecionMapper;
     @Value("${file.upload.path}")
     private String filePath;
+    @Value("${file.upload.url}")
+    private String uploadUrl;
+
     @Resource
     SnowflakeIdWorker snowflakeIdWorker;
     @Async
-    @Log(title = "导出外协审核列表", businessType = BusinessType.EXPORT)
-    public void processTaskAsync(BizProcessInspecion bizProcessInspecion) {
+//    @Log(title = "导出外协审核列表", businessType = BusinessType.EXPORT)
+    public void processTaskAsync(BizProcessInspecion bizProcessInspecion, Long userId) {
         try {
             // 获取所有整年的检查的数量
             Long count = bizProcessInspecionMapper.getCountForExport(bizProcessInspecion);
@@ -54,28 +57,33 @@ public class TaskService {
             // 分页
             // 循环
             // 存到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());
-            }
+//            while(rowIndex < 30000) {
+//                pageNum = 0;
+                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) rowIndex - 1).divide(BigDecimal.valueOf(count), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)));
+                    WebSocketUser.sendInfo(result.toJSONString(), String.valueOf(userId));
+                }
+//            }
             // excel输出到文件夹
             // 完成后保存到本地
-            FileOutputStream out = new FileOutputStream(file.getAbsolutePath() +"/" + snowflakeIdWorker.nextId() + ".xlsx");
+            String fileName = String.valueOf(snowflakeIdWorker.nextId());
+            FileOutputStream out = new FileOutputStream(file.getAbsolutePath() +"/" + fileName + ".xlsx");
             writer.flush(out);
             writer.close();
             result.put("progress", 100);
-            webSocketUser.sendMessage(result.toJSONString());
+            result.put("url", "/profile/upload" + "/excel/" + fileName + ".xlsx");
+            WebSocketUser.sendInfo(result.toJSONString(), String.valueOf(userId));
         } catch (Exception e) {
             // 处理错误
             JSONObject err = new JSONObject();
             err.put("err", "保存出错");
             try {
-                webSocketUser.sendMessage(err.toJSONString());
+                WebSocketUser.sendInfo(err.toJSONString(), String.valueOf(userId));
             } catch (IOException ex) {
                 throw new RuntimeException(ex);
             }
@@ -109,7 +117,7 @@ public class TaskService {
             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(2, rowIndex+  i.get(), l.getProductDescription());
                 writer.writeCellValue(3, rowIndex+  i.get(), l.getLotCode());
                 writer.writeCellValue(4, rowIndex+  i.get(), l.getProductNum());
                 writer.writeCellValue(5, rowIndex+  i.get(), l.getProductNum());

+ 11 - 11
src/main/resources/mybatis/business/BizProcessInspecionMapper.xml

@@ -65,16 +65,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         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_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
+        , (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 as outsourcedOrder_detail_form_code, bod.form_date as outsource_date, brr.form_code as return_receipt_detail_form_code, brr.form_date as return_receipt_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">
             recheck_date is null and is_outsourced_inspection = 1 and bpi.deleted = 0
-            <if test="lotCode != null  and lotCode != ''">AND t.lot_code like concat ('%',#{lotCode},'%')</if>
-            <if test="userId != null  ">AND t.user_id = #{userId}</if>
-            <if test="status != null ">AND t.status = #{status}</if>
-            <if test="startTime != null"> AND DATE(t.start_time) &gt;= #{startTime}</if>
-            <if test="endTime != null"> AND DATE(t.start_time) &lt;= #{endTime}</if>
+            <if test="lotCode != null  and lotCode != ''">AND bpi.lot_code like concat ('%',#{lotCode},'%')</if>
+            <if test="userId != null  ">AND bpi.user_id = #{userId}</if>
+            <if test="status != null ">AND bpi.status = #{status}</if>
+            <if test="startTime != null"> AND DATE(bpi.start_time) &gt;= #{startTime}</if>
+            <if test="endTime != null"> AND DATE(bpi.start_time) &lt;= #{endTime}</if>
             <!--            <if test="startTime != null"> AND t.date_format(t.start_time, '%Y-%m-%d') = date_format(#{startTime}, '%Y-%m-%d')</if>-->
             <if test="supplierName != null">AND exists (select supplier_name from biz_outsourced_order_detail o where o.id = bpi.outsource_order_detail_id and o.supplier_name like concat('%', #{supplierName}, '%'))</if>
             <if test="returnReceiptDetailFormCode != null ">AND rrd.form_code like concat('%', #{returnReceiptDetailFormCode}, '%') </if>
@@ -94,11 +94,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         left join biz_supplier bs on bs.id = bod.supplier_id
         <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
             recheck_date is null and is_outsourced_inspection = 1 and bpi.deleted = 0
-            <if test="lotCode != null  and lotCode != ''">AND t.lot_code like concat ('%',#{lotCode},'%')</if>
-            <if test="userId != null  ">AND t.user_id = #{userId}</if>
-            <if test="status != null ">AND t.status = #{status}</if>
-            <if test="startTime != null"> AND DATE(t.start_time) &gt;= #{startTime}</if>
-            <if test="endTime != null"> AND DATE(t.start_time) &lt;= #{endTime}</if>
+            <if test="lotCode != null  and lotCode != ''">AND bpi.lot_code like concat ('%',#{lotCode},'%')</if>
+            <if test="userId != null  ">AND bpi.user_id = #{userId}</if>
+            <if test="status != null ">AND bpi.status = #{status}</if>
+            <if test="startTime != null"> AND DATE(bpi.start_time) &gt;= #{startTime}</if>
+            <if test="endTime != null"> AND DATE(bpi.start_time) &lt;= #{endTime}</if>
             <!--            <if test="startTime != null"> AND t.date_format(t.start_time, '%Y-%m-%d') = date_format(#{startTime}, '%Y-%m-%d')</if>-->
             <if test="supplierName != null">AND exists (select supplier_name from biz_outsourced_order_detail o where o.id = bpi.outsource_order_detail_id and o.supplier_name like concat('%', #{supplierName}, '%'))</if>
             <if test="returnReceiptDetailFormCode != null ">AND rrd.form_code like concat('%', #{returnReceiptDetailFormCode}, '%') </if>