Browse Source

保存节点

zhuang 2 tuần trước cách đây
mục cha
commit
40fa4bdbbf

+ 2 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/dao/ZhcxItpTemplateNodesDao.java

@@ -23,4 +23,6 @@ public interface ZhcxItpTemplateNodesDao extends BaseMapper<ZhcxItpTemplateNodes
     @Select("select a.*,b.NODENAME AS \"pname\" from ZHCX_ITP_TEMPLATE_NODES a left join ZHCX_ITP_TEMPLATE_NODES b on a.PID=b.ID " +
             " where a.ITPID in (${itpids}) and a.DELETED='0'")
     List<ZhcxItpTemplateNodesVo> selectPnameByTmpIds(@Param("itpids") String itpids);
+
+    int batchInsertNodes(List<ZhcxItpTemplateNodesDo> toCopySaveNodes);
 }

+ 1 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/service/ZhcxItpTemplateNodesService.java

@@ -24,4 +24,5 @@ public interface ZhcxItpTemplateNodesService extends IService<ZhcxItpTemplateNod
 
     List<ZhcxItpTemplateNodesVo> selectPnameByTmpIds(List<String> itpidList);
 
+    void batchInsertNodes(List<ZhcxItpTemplateNodesDo> toCopySaveNodes);
 }

+ 17 - 0
business-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ZhcxItpTemplateNodesServiceImpl.java

@@ -18,6 +18,7 @@ import com.rongwei.commonservice.service.dao.CommonSqlDao;
 import com.rongwei.rwcommon.utils.SecurityUtil;
 import com.rongwei.rwcommon.utils.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -452,6 +453,22 @@ public class ZhcxItpTemplateNodesServiceImpl extends ServiceImpl<ZhcxItpTemplate
         return templateNodesVos;
     }
 
+    @Override
+    public void batchInsertNodes(List<ZhcxItpTemplateNodesDo> toCopySaveNodes) {
+        int size = toCopySaveNodes.size();
+        int count = 500;
+        if (size < count) {
+            zhcxItpTemplateNodesDao.batchInsertNodes(toCopySaveNodes);
+        }else{
+            List<List<ZhcxItpTemplateNodesDo>> batches = new java.util.ArrayList<>();
+            for (int i = 0; i < size; i += count) {
+                int end = Math.min(i + count, size);
+                batches.add(toCopySaveNodes.subList(i, end));
+            }
+            batches.parallelStream().forEach(batch -> zhcxItpTemplateNodesDao.batchInsertNodes(batch));
+        }
+    }
+
     /**
      * 返回最新数据
      * @param copyNodeVo

+ 16 - 4
business-common/src/main/java/com/rongwei/bscommon/sys/service/impl/ZhcxItpTemplateServiceImpl.java

@@ -1,6 +1,5 @@
 package com.rongwei.bscommon.sys.service.impl;
 
-import cn.hutool.core.collection.ListUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.rongwei.bscommon.sys.service.ZhcxItpTemplateNodesService;
 import com.rongwei.bsentity.domain.ZhcxItpTemplateDo;
@@ -14,12 +13,11 @@ import com.rongwei.commonservice.service.dao.CommonSqlDao;
 import com.rongwei.rwcommon.base.exception.CustomException;
 import com.rongwei.rwcommon.utils.SecurityUtil;
 import com.rongwei.rwcommon.utils.StringUtils;
-import org.apache.commons.collections.ListUtils;
+import org.apache.ibatis.session.SqlSessionFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.*;
-import java.util.logging.Handler;
 import java.util.stream.Collectors;
 
 /**
@@ -37,6 +35,10 @@ public class ZhcxItpTemplateServiceImpl extends ServiceImpl<ZhcxItpTemplateDao,
     private ZhcxItpTemplateNodesService zhcxItpTemplateNodesService;
     @Autowired
     private CommonSqlDao commonSqlDao;
+    @Autowired
+    private SqlSessionFactory sqlSessionFactory;
+
+
 
     /**
      * 复制新增的引用所有子节点
@@ -270,7 +272,17 @@ public class ZhcxItpTemplateServiceImpl extends ServiceImpl<ZhcxItpTemplateDao,
         // 保存数据
         if(toCopySaveNodes != null && toCopySaveNodes.size()>0){
             // 保存最终数据
-            zhcxItpTemplateNodesService.saveBatch(toCopySaveNodes);
+//            int count = 500;
+//            if (toCopySaveNodes.size() < count) {
+//                zhcxItpTemplateNodesService.batchInsertNodes(toCopySaveNodes);
+//            }else{
+//                for (int i = 0; i < toCopySaveNodes.size(); i += count) {
+//                    int end = Math.min(i + count, toCopySaveNodes.size());
+//                    List<ZhcxItpTemplateNodesDo> batchList = toCopySaveNodes.subList(i, end);
+//                    zhcxItpTemplateNodesService.batchInsertNodes(batchList);
+//                }
+//            }
+            zhcxItpTemplateNodesService.batchInsertNodes(toCopySaveNodes);
         }
     }
 

+ 29 - 0
business-common/src/main/resources/mybatis/business/ZhcxItpTemplateNodesDao.xml

@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.rongwei.bscommon.sys.dao.ZhcxItpTemplateNodesDao">
+
+    <insert id="batchInsertNodes" parameterType="java.util.List">
+        INSERT INTO ZHCX_ITP_TEMPLATE_NODES (
+        ID, ITPID, ITPNAME, PID, NODENAME, ENNAME, PNODENAME, PNODEENNAME, PNODEID,
+        PRENODE, PRENODEID, NODETYPE, SORTINDEX, LEVEL, ISOFFLINE, NEEDFILES, NOTICEFILE,
+        CHECKFILE, RELATEIDS, TENANTID, ROPTION, OUTNOTICEFILE, REFNODEID, REFTMPID,
+        ISNEEDOUT, PATH, INSPECTIONTYPE, TYPE1, TYPE2, ISSUPP, CHECKTMPID, CHECKROLE,
+        CHECKROLEID, ORGID, ORGNAME, ISNEEDINPUT
+        )
+        VALUES
+        <foreach collection="list" item="item" separator=",">
+            (
+            #{item.id}, #{item.itpid}, #{item.itpname}, #{item.pid}, #{item.nodename},
+            #{item.enname}, #{item.pnodename}, #{item.pnodeenname}, #{item.pnodeid},
+            #{item.prenode}, #{item.prenodeid}, #{item.nodetype}, #{item.sortindex},
+            #{item.level}, #{item.isoffline}, #{item.needfiles}, #{item.noticefile},
+            #{item.checkfile}, #{item.relateids}, #{item.tenantid}, #{item.roption},
+            #{item.outnoticefile}, #{item.refnodeid}, #{item.reftmpid}, #{item.isneedout},
+            #{item.path}, #{item.inspectiontype}, #{item.type1}, #{item.type2}, #{item.issupp},
+            #{item.checktmpid}, #{item.checkrole}, #{item.checkroleid}, #{item.orgid},
+            #{item.orgname}, #{item.isneedinput}
+            )
+        </foreach>
+    </insert>
+</mapper>