From 3aaf4e2384867c7900293063ed81450b0c965499 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期一, 19 七月 2021 14:18:38 +0800
Subject: [PATCH] fix 回滚代码生成器 批处理优化(字段内容不一致, 不适合批处理)

---
 ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java     |   12 ++----------
 ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/ServicePlusImpl.java |   14 ++++++--------
 ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/BaseMapperPlus.java  |    4 ++++
 ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/methods/InsertAll.java    |    2 +-
 ruoyi-demo/src/main/java/com/ruoyi/demo/controller/TestBatchController.java            |    2 +-
 5 files changed, 14 insertions(+), 20 deletions(-)

diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/BaseMapperPlus.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/BaseMapperPlus.java
index cf51c90..ee779a5 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/BaseMapperPlus.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/BaseMapperPlus.java
@@ -13,6 +13,10 @@
  */
 public interface BaseMapperPlus<T> extends BaseMapper<T> {
 
+	/**
+	 * 鍗晄ql鎵归噺鎻掑叆( 鍏ㄩ噺濉厖 鏃犺鏁版嵁搴撻粯璁ゅ�� )
+	 * 閫傜敤浜庢棤鑴戞彃鍏�
+	 */
 	int insertAll(@Param("list") Collection<T> batchList);
 
 }
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/ServicePlusImpl.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/ServicePlusImpl.java
index 77b9c28..fb0998b 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/ServicePlusImpl.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/core/ServicePlusImpl.java
@@ -51,11 +51,8 @@
 	}
 
 	/**
-	 * 鍗曟潯鎵ц鎬ц兘宸�
-	 *
-	 * {@link #saveAll(Collection)}
+	 * 鍗曟潯鎵ц鎬ц兘宸� 閫傜敤浜庡垪琛ㄥ璞″唴瀹逛笉纭畾
 	 */
-	@Deprecated
 	@Override
 	public boolean saveBatch(Collection<T> entityList, int batchSize) {
 		return super.saveBatch(entityList, batchSize);
@@ -67,11 +64,8 @@
 	}
 
 	/**
-	 * 鍗曟潯鎵ц鎬ц兘宸�
-	 *
-	 * {@link #saveAll(Collection)}
+	 * 鍗曟潯鎵ц鎬ц兘宸� 閫傜敤浜庡垪琛ㄥ璞″唴瀹逛笉纭畾
 	 */
-	@Deprecated
 	@Override
 	public boolean saveOrUpdateBatch(Collection<T> entityList, int batchSize) {
 		return super.saveOrUpdateBatch(entityList, batchSize);
@@ -82,6 +76,10 @@
 		return super.updateBatchById(entityList, batchSize);
 	}
 
+	/**
+	 * 鍗晄ql鎵归噺鎻掑叆( 鍏ㄩ噺濉厖 鏃犺鏁版嵁搴撻粯璁ゅ�� )
+	 * 閫傜敤浜庢棤鑴戞彃鍏�
+	 */
 	@Override
 	public boolean saveAll(Collection<T> entityList) {
 		return baseMapper.insertAll(entityList) == entityList.size();
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/methods/InsertAll.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/methods/InsertAll.java
index ec57621..66cf34c 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/methods/InsertAll.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/mybatisplus/methods/InsertAll.java
@@ -13,7 +13,7 @@
 import org.apache.ibatis.mapping.SqlSource;
 
 /**
- * 鍗晄ql鎵归噺鎻掑叆
+ * 鍗晄ql鎵归噺鎻掑叆( 鍏ㄩ噺濉厖 鏃犺鏁版嵁搴撻粯璁ゅ�� )
  *
  * @author Lion Li
  */
diff --git a/ruoyi-demo/src/main/java/com/ruoyi/demo/controller/TestBatchController.java b/ruoyi-demo/src/main/java/com/ruoyi/demo/controller/TestBatchController.java
index 499a5ad..334f004 100644
--- a/ruoyi-demo/src/main/java/com/ruoyi/demo/controller/TestBatchController.java
+++ b/ruoyi-demo/src/main/java/com/ruoyi/demo/controller/TestBatchController.java
@@ -29,7 +29,7 @@
     private final ITestDemoService iTestDemoService;
 
     /**
-     * 鏂板鎵归噺鏂规硶
+     * 鏂板鎵归噺鏂规硶 ( 鍏ㄩ噺瑕嗙洊濉厖 )
      */
     @PostMapping()
     public AjaxResult<Void> add() {
diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java
index 741919b..9eceadf 100644
--- a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java
+++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java
@@ -179,14 +179,10 @@
                 if (row > 0) {
                     // 淇濆瓨鍒椾俊鎭�
                     List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
-					List<GenTableColumn> saveColumns = new ArrayList<>();
                     for (GenTableColumn column : genTableColumns) {
                         GenUtils.initColumnField(column, table);
-						saveColumns.add(column);
+						genTableColumnMapper.insert(column);
                     }
-                    if (CollUtil.isNotEmpty(saveColumns)) {
-						genTableColumnMapper.insertAll(saveColumns);
-					}
 				}
             }
         } catch (Exception e) {
@@ -290,16 +286,12 @@
         }
         List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
 
-		List<GenTableColumn> saveColumns = new ArrayList<>();
         dbTableColumns.forEach(column -> {
             if (!tableColumnNames.contains(column.getColumnName())) {
                 GenUtils.initColumnField(column, table);
-				saveColumns.add(column);
+				genTableColumnMapper.insert(column);
 			}
 		});
-		if (CollUtil.isNotEmpty(saveColumns)) {
-			genTableColumnMapper.insertAll(saveColumns);
-		}
 
         List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList());
         if (CollUtil.isNotEmpty(delColumns)) {

--
Gitblit v1.9.3