From 11d327572b3fc007ef68c46b9c66a451a76e6430 Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: 星期五, 25 六月 2021 17:28:01 +0800
Subject: [PATCH] 升级pagehelper到最新版1.3.1
---
src/main/java/com/ruoyi/project/tool/gen/service/GenTableServiceImpl.java | 85 +++++++++++++++++++++++++++++++++++-------
1 files changed, 71 insertions(+), 14 deletions(-)
diff --git a/src/main/java/com/ruoyi/project/tool/gen/service/GenTableServiceImpl.java b/src/main/java/com/ruoyi/project/tool/gen/service/GenTableServiceImpl.java
index 91f0d09..311b306 100644
--- a/src/main/java/com/ruoyi/project/tool/gen/service/GenTableServiceImpl.java
+++ b/src/main/java/com/ruoyi/project/tool/gen/service/GenTableServiceImpl.java
@@ -10,6 +10,7 @@
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
+import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
@@ -27,7 +28,6 @@
import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.project.tool.gen.domain.GenTable;
import com.ruoyi.project.tool.gen.domain.GenTableColumn;
import com.ruoyi.project.tool.gen.mapper.GenTableColumnMapper;
@@ -100,6 +100,17 @@
public List<GenTable> selectDbTableListByNames(String[] tableNames)
{
return genTableMapper.selectDbTableListByNames(tableNames);
+ }
+
+ /**
+ * 鏌ヨ鎵�鏈夎〃淇℃伅
+ *
+ * @return 琛ㄤ俊鎭泦鍚�
+ */
+ @Override
+ public List<GenTable> selectGenTableAll()
+ {
+ return genTableMapper.selectGenTableAll();
}
/**
@@ -185,9 +196,10 @@
Map<String, String> dataMap = new LinkedHashMap<>();
// 鏌ヨ琛ㄤ俊鎭�
GenTable table = genTableMapper.selectGenTableById(tableId);
- // 鏌ヨ鍒椾俊鎭�
- List<GenTableColumn> columns = table.getColumns();
- setPkColumn(table, columns);
+ // 璁剧疆涓诲瓙琛ㄤ俊鎭�
+ setSubTable(table);
+ // 璁剧疆涓婚敭鍒椾俊鎭�
+ setPkColumn(table);
VelocityInitializer.initVelocity();
VelocityContext context = VelocityUtils.prepareContext(table);
@@ -231,9 +243,10 @@
{
// 鏌ヨ琛ㄤ俊鎭�
GenTable table = genTableMapper.selectGenTableByName(tableName);
- // 鏌ヨ鍒椾俊鎭�
- List<GenTableColumn> columns = table.getColumns();
- setPkColumn(table, columns);
+ // 璁剧疆涓诲瓙琛ㄤ俊鎭�
+ setSubTable(table);
+ // 璁剧疆涓婚敭鍒椾俊鎭�
+ setPkColumn(table);
VelocityInitializer.initVelocity();
@@ -276,6 +289,10 @@
List<String> tableColumnNames = tableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
+ if (StringUtils.isEmpty(dbTableColumns))
+ {
+ throw new CustomException("鍚屾鏁版嵁澶辫触锛屽師琛ㄧ粨鏋勪笉瀛樺湪");
+ }
List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
dbTableColumns.forEach(column -> {
@@ -319,9 +336,10 @@
{
// 鏌ヨ琛ㄤ俊鎭�
GenTable table = genTableMapper.selectGenTableByName(tableName);
- // 鏌ヨ鍒椾俊鎭�
- List<GenTableColumn> columns = table.getColumns();
- setPkColumn(table, columns);
+ // 璁剧疆涓诲瓙琛ㄤ俊鎭�
+ setSubTable(table);
+ // 璁剧疆涓婚敭鍒椾俊鎭�
+ setPkColumn(table);
VelocityInitializer.initVelocity();
@@ -376,17 +394,27 @@
throw new CustomException("鏍戝悕绉板瓧娈典笉鑳戒负绌�");
}
}
+ else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory()))
+ {
+ if (StringUtils.isEmpty(genTable.getSubTableName()))
+ {
+ throw new CustomException("鍏宠仈瀛愯〃鐨勮〃鍚嶄笉鑳戒负绌�");
+ }
+ else if (StringUtils.isEmpty(genTable.getSubTableFkName()))
+ {
+ throw new CustomException("瀛愯〃鍏宠仈鐨勫閿悕涓嶈兘涓虹┖");
+ }
+ }
}
/**
* 璁剧疆涓婚敭鍒椾俊鎭�
*
* @param table 涓氬姟琛ㄤ俊鎭�
- * @param columns 涓氬姟瀛楁鍒楄〃
*/
- public void setPkColumn(GenTable table, List<GenTableColumn> columns)
+ public void setPkColumn(GenTable table)
{
- for (GenTableColumn column : columns)
+ for (GenTableColumn column : table.getColumns())
{
if (column.isPk())
{
@@ -396,7 +424,36 @@
}
if (StringUtils.isNull(table.getPkColumn()))
{
- table.setPkColumn(columns.get(0));
+ table.setPkColumn(table.getColumns().get(0));
+ }
+ if (GenConstants.TPL_SUB.equals(table.getTplCategory()))
+ {
+ for (GenTableColumn column : table.getSubTable().getColumns())
+ {
+ if (column.isPk())
+ {
+ table.getSubTable().setPkColumn(column);
+ break;
+ }
+ }
+ if (StringUtils.isNull(table.getSubTable().getPkColumn()))
+ {
+ table.getSubTable().setPkColumn(table.getSubTable().getColumns().get(0));
+ }
+ }
+ }
+
+ /**
+ * 璁剧疆涓诲瓙琛ㄤ俊鎭�
+ *
+ * @param table 涓氬姟琛ㄤ俊鎭�
+ */
+ public void setSubTable(GenTable table)
+ {
+ String subTableName = table.getSubTableName();
+ if (StringUtils.isNotEmpty(subTableName))
+ {
+ table.setSubTable(genTableMapper.selectGenTableByName(subTableName));
}
}
--
Gitblit v1.9.3