Browse Source

成本额导出优化

丁治程 11 months ago
parent
commit
060b204c65

+ 7 - 1
module_kzks/src/main/java/org/jeecg/modules/Index/service/impl/IndexNewServiceImpl.java

@@ -168,6 +168,10 @@ public class IndexNewServiceImpl implements IndexNewServer {
 
     @Autowired
     @SuppressWarnings("all")
+    private IWzOutboundOrderBNewService orderBNewService;
+
+    @Autowired
+    @SuppressWarnings("all")
     private ProjectChbZyfMapper zyfMapper;
     @Autowired
     @SuppressWarnings("all")
@@ -944,7 +948,9 @@ public class IndexNewServiceImpl implements IndexNewServer {
         }
         if (depart == null) {
             depart = "Boss";
-            wzList = orderBNewMapper.getClfDetailIfBoss1(nowMonth);
+
+            wzList = orderBNewService.getClfDetailIfBoss1(nowMonth);
+            //wzList = orderBNewMapper.getClfDetailIfBoss1(nowMonth);
             zyfList = zyfMapper.getDetailIfBoss1(nowMonth);
             swfList = swfMapper.getDetailIfBoss1(nowMonth);
             wxfList = wxfMapper.getDetailIfBoss1(nowMonth);

+ 4 - 0
module_kzks/src/main/java/org/jeecg/modules/wzOutboundOrderBNew/mapper/WzOutboundOrderBNewMapper.java

@@ -44,4 +44,8 @@ public interface WzOutboundOrderBNewMapper extends BaseMapper<WzOutboundOrderBNe
     List<WzOutboundOrderBNewExport> getClfDetailIfBoss1(@Param("nowMonth") String nowMonth);
 
     List<WzOutboundOrderBNewExport> getClfDetail1(@Param("tasknoList") ArrayList<String> tasknoList, @Param("nowMonth") String nowMonth);
+
+    int getCountClfDetail(@Param("nowMonth") String nowMonth);
+
+    List<WzOutboundOrderBNewExport> getClfDetailIfBoss1ByOffset(@Param("nowMonth") String nowMonth,@Param("index") Integer index,@Param("size") Integer size);
 }

+ 8 - 0
module_kzks/src/main/java/org/jeecg/modules/wzOutboundOrderBNew/mapper/xml/WzOutboundOrderBNewMapper.xml

@@ -103,4 +103,12 @@
         </foreach>
         and yearmonth = #{nowMonth}
     </select>
+    <select id="getCountClfDetail" resultType="java.lang.Integer">
+        select count(*) from wz_outbound_order_b_new where yearmonth = #{nowMonth}
+    </select>
+
+    <select id="getClfDetailIfBoss1ByOffset" resultType="org.jeecg.modules.wzOutboundOrderBNew.entity.WzOutboundOrderBNewExport">
+        select * from wz_outbound_order_b_new where yearmonth = #{nowMonth}
+        limit #{index},#{size}
+    </select>
 </mapper>

+ 3 - 0
module_kzks/src/main/java/org/jeecg/modules/wzOutboundOrderBNew/service/IWzOutboundOrderBNewService.java

@@ -3,8 +3,10 @@ package org.jeecg.modules.wzOutboundOrderBNew.service;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.modules.wzOutboundOrderBNew.entity.WzOutboundOrderBNew;
 import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.modules.wzOutboundOrderBNew.entity.WzOutboundOrderBNewExport;
 
 import java.io.IOException;
+import java.util.List;
 import java.util.concurrent.ExecutionException;
 
 /**
@@ -18,4 +20,5 @@ public interface IWzOutboundOrderBNewService extends IService<WzOutboundOrderBNe
     Result<?> importExcel1(String strUrl, Class<WzOutboundOrderBNew> clazz) throws InterruptedException, ExecutionException, IOException;
     Result<?> importExcelNew(String strUrl, Class<WzOutboundOrderBNew> clazz) throws IOException;
 
+    List<WzOutboundOrderBNewExport> getClfDetailIfBoss1(String nowMonth);
 }

+ 105 - 0
module_kzks/src/main/java/org/jeecg/modules/wzOutboundOrderBNew/service/impl/WzOutboundOrderBNewServiceImpl.java

@@ -17,6 +17,7 @@ import org.jeecg.modules.message.websocket.WebSocket;
 import org.jeecg.modules.projectImportList.readListener.ProjectChbImportReadListener;
 import org.jeecg.modules.projectKmbh.entity.KzksProjectKmbh;
 import org.jeecg.modules.wzOutboundOrderBNew.entity.WzOutboundOrderBNew;
+import org.jeecg.modules.wzOutboundOrderBNew.entity.WzOutboundOrderBNewExport;
 import org.jeecg.modules.wzOutboundOrderBNew.mapper.WzOutboundOrderBNewMapper;
 import org.jeecg.modules.wzOutboundOrderBNew.monitor.WzOutboundOrderBNewListenerS;
 import org.jeecg.modules.wzOutboundOrderBNew.monitor.WzOutboundOrderBNewListerner;
@@ -31,7 +32,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import javax.annotation.Resource;
 import java.io.*;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.*;
 
 /**
@@ -81,4 +84,106 @@ public class WzOutboundOrderBNewServiceImpl extends ServiceImpl<WzOutboundOrderB
         return Result.ok("文件导入成功!");
     }
 
+    @Override
+    public List<WzOutboundOrderBNewExport> getClfDetailIfBoss1(String nowMonth) {
+        ArrayList<WzOutboundOrderBNewExport> resultList = new ArrayList<>();
+
+        ExecutorService threadPoolExecutors = Executors.newFixedThreadPool(8);
+
+        int wzSize = orderBNewMapper.getCountClfDetail(nowMonth);        // 当前月份一共有多少条物资数据
+        log.info("开始进行分片查询,共{}条数据",wzSize);
+        int threadCount = 8; // 开8个线程处理
+
+        int baseBatchSize = wzSize / threadCount;  // 每个线程处理的数量
+        int remaining = wzSize % threadCount; // 余数
+        int currentIndex = 0; // 起始索引
+
+        Map<String, String> map = new HashMap<>();
+
+        for (int i = 0; i < threadCount; i++) {
+            int batchSize = baseBatchSize;
+            if (remaining > 0){
+                batchSize += 1;
+                remaining -= 1;
+            }
+            map.put(String.valueOf(i), currentIndex + "-" + batchSize);
+            currentIndex += batchSize;
+        }
+
+        try {
+            if (!map.get("0").isEmpty()){
+                String[] split = map.get("0").split("-");
+                threadPoolExecutors.submit(() -> {
+                    List<WzOutboundOrderBNewExport> list = orderBNewMapper.getClfDetailIfBoss1ByOffset(nowMonth,Integer.parseInt(split[0]), Integer.parseInt(split[1]));
+                    resultList.addAll(list);
+                });
+            }
+
+            if (!map.get("1").isEmpty()){
+                String[] split = map.get("1").split("-");
+                threadPoolExecutors.submit(() -> {
+                    List<WzOutboundOrderBNewExport> list = orderBNewMapper.getClfDetailIfBoss1ByOffset(nowMonth,Integer.parseInt(split[0]), Integer.parseInt(split[1]));
+                    resultList.addAll(list);
+                });
+            }
+
+            if (!map.get("2").isEmpty()){
+                String[] split = map.get("2").split("-");
+                threadPoolExecutors.submit(() -> {
+                    List<WzOutboundOrderBNewExport> list = orderBNewMapper.getClfDetailIfBoss1ByOffset(nowMonth,Integer.parseInt(split[0]), Integer.parseInt(split[1]));
+                    resultList.addAll(list);
+                });
+            }
+
+            if (!map.get("3").isEmpty()){
+                String[] split = map.get("3").split("-");
+                threadPoolExecutors.submit(() -> {
+                    List<WzOutboundOrderBNewExport> list = orderBNewMapper.getClfDetailIfBoss1ByOffset(nowMonth,Integer.parseInt(split[0]), Integer.parseInt(split[1]));
+                    resultList.addAll(list);
+                });
+            }
+
+            if (!map.get("4").isEmpty()){
+                String[] split = map.get("4").split("-");
+                threadPoolExecutors.submit(() -> {
+                    List<WzOutboundOrderBNewExport> list = orderBNewMapper.getClfDetailIfBoss1ByOffset(nowMonth,Integer.parseInt(split[0]), Integer.parseInt(split[1]));
+                    resultList.addAll(list);
+                });
+            }
+
+            if (!map.get("5").isEmpty()){
+                String[] split = map.get("5").split("-");
+                threadPoolExecutors.submit(() -> {
+                    List<WzOutboundOrderBNewExport> list = orderBNewMapper.getClfDetailIfBoss1ByOffset(nowMonth,Integer.parseInt(split[0]), Integer.parseInt(split[1]));
+                    resultList.addAll(list);
+                });
+            }
+
+            if (!map.get("6").isEmpty()){
+                String[] split = map.get("6").split("-");
+                threadPoolExecutors.submit(() -> {
+                    List<WzOutboundOrderBNewExport> list = orderBNewMapper.getClfDetailIfBoss1ByOffset(nowMonth,Integer.parseInt(split[0]), Integer.parseInt(split[1]));
+                    resultList.addAll(list);
+                });
+            }
+
+            if (!map.get("7").isEmpty()){
+                String[] split = map.get("7").split("-");
+                threadPoolExecutors.submit(() -> {
+                    List<WzOutboundOrderBNewExport> list = orderBNewMapper.getClfDetailIfBoss1ByOffset(nowMonth,Integer.parseInt(split[0]), Integer.parseInt(split[1]));
+                    resultList.addAll(list);
+                });
+            }
+
+            threadPoolExecutors.shutdown();
+            boolean b = threadPoolExecutors.awaitTermination(5, TimeUnit.HOURS);
+            log.info("查询结束");
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            threadPoolExecutors.shutdown();
+        }
+
+        return resultList;
+    }
 }