|
@@ -0,0 +1,129 @@
|
|
|
+package org.jeecg.modules.wzOutboundOrderBNew.monitor;
|
|
|
+
|
|
|
+import com.alibaba.excel.context.AnalysisContext;
|
|
|
+import com.alibaba.excel.event.AnalysisEventListener;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.jeecg.modules.message.websocket.WebSocket;
|
|
|
+import org.jeecg.modules.projectChbSwf.entity.ProjectChbSwf;
|
|
|
+import org.jeecg.modules.projectImportList.service.impl.ProjectImportListServiceImpl;
|
|
|
+import org.jeecg.modules.wzOutboundOrderBNew.entity.WzOutboundOrderBNew;
|
|
|
+import org.jeecg.modules.wzOutboundOrderBNew.service.IWzOutboundOrderBNewService;
|
|
|
+import org.jeecg.modules.wzOutboundOrderBNew.service.impl.WzOutboundOrderBNewServiceImpl;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.concurrent.CopyOnWriteArrayList;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author dzc
|
|
|
+ * @date 2024/4/1 9:03
|
|
|
+ * @package org.jeecg.modules.wzOutboundOrderBNew.monitor
|
|
|
+ * @project yecai_server
|
|
|
+ * @des
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+public class WzOutboundOrderBNewListenerS extends AnalysisEventListener<WzOutboundOrderBNew> {
|
|
|
+
|
|
|
+ private static final List<WzOutboundOrderBNew> wzList = new CopyOnWriteArrayList<>(); // 存放物资数据的集合
|
|
|
+
|
|
|
+
|
|
|
+ private final IWzOutboundOrderBNewService wzOutboundOrderBNewService;
|
|
|
+
|
|
|
+
|
|
|
+ private static final int BIG_SIZE = 3000; // 批量添加最大数量
|
|
|
+
|
|
|
+ public WzOutboundOrderBNewListenerS(IWzOutboundOrderBNewService wzOutboundOrderBNewService) {
|
|
|
+ this.wzOutboundOrderBNewService = wzOutboundOrderBNewService;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void invoke(WzOutboundOrderBNew wzOutboundOrderBNew, AnalysisContext analysisContext) {
|
|
|
+ wzList.add(wzOutboundOrderBNew);
|
|
|
+ if (wzList.size() == BIG_SIZE){
|
|
|
+ saveInfoInKu(wzList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void doAfterAllAnalysed(AnalysisContext analysisContext) {
|
|
|
+ saveInfoInKu(wzList);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void saveInfoInKu(List<WzOutboundOrderBNew> wzList) {
|
|
|
+ ExecutorService threadPoolExecutors = Executors.newFixedThreadPool(8);
|
|
|
+ try {
|
|
|
+ log.info("{}条数据,开始存储数据库!", wzList.size());
|
|
|
+ int sonListSize = wzList.size() / 8; // 计算将wzList分成8份之后每个子集合的大小
|
|
|
+
|
|
|
+ List<List<WzOutboundOrderBNew>> sonList = new ArrayList<>(); // 用于存放 子集合 的list
|
|
|
+ for (int i = 0; i < 8; i++) {
|
|
|
+ int startIndex = i * sonListSize;
|
|
|
+ int endIndex = (i + 1) * sonListSize;
|
|
|
+ if (i == 7){ // 避免遗漏数据,最后一个集合取全部数据
|
|
|
+ endIndex = wzList.size();
|
|
|
+ }
|
|
|
+ // 根据起始索引、终止索引进行截取
|
|
|
+ List<WzOutboundOrderBNew> list = wzList.subList(startIndex, endIndex);
|
|
|
+ sonList.add(list);
|
|
|
+ }
|
|
|
+ // 八个线程同步保存数据
|
|
|
+ if (!sonList.isEmpty()){
|
|
|
+ if (!sonList.get(0).isEmpty()){
|
|
|
+ threadPoolExecutors.submit(() -> {
|
|
|
+ wzOutboundOrderBNewService.saveBatch(sonList.get(0));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (!sonList.get(1).isEmpty()){
|
|
|
+ threadPoolExecutors.submit(() -> {
|
|
|
+ wzOutboundOrderBNewService.saveBatch(sonList.get(1));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (!sonList.get(2).isEmpty()){
|
|
|
+ threadPoolExecutors.submit(() -> {
|
|
|
+ wzOutboundOrderBNewService.saveBatch(sonList.get(2));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (!sonList.get(3).isEmpty()){
|
|
|
+ threadPoolExecutors.submit(() -> {
|
|
|
+ wzOutboundOrderBNewService.saveBatch(sonList.get(3));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (!sonList.get(4).isEmpty()){
|
|
|
+ threadPoolExecutors.submit(() -> {
|
|
|
+ wzOutboundOrderBNewService.saveBatch(sonList.get(4));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (!sonList.get(5).isEmpty()){
|
|
|
+ threadPoolExecutors.submit(() -> {
|
|
|
+ wzOutboundOrderBNewService.saveBatch(sonList.get(5));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (!sonList.get(6).isEmpty()){
|
|
|
+ threadPoolExecutors.submit(() -> {
|
|
|
+ wzOutboundOrderBNewService.saveBatch(sonList.get(6));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (!sonList.get(7).isEmpty()){
|
|
|
+ threadPoolExecutors.submit(() -> {
|
|
|
+ wzOutboundOrderBNewService.saveBatch(sonList.get(7));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ threadPoolExecutors.shutdown();
|
|
|
+ boolean b = threadPoolExecutors.awaitTermination(5, TimeUnit.HOURS);
|
|
|
+ log.info("数据成功入库");
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ } finally {
|
|
|
+ threadPoolExecutors.shutdown();
|
|
|
+ wzList.clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|