|
@@ -2,10 +2,13 @@ package com.boman.gen.controller;
|
|
|
|
|
|
import com.boman.common.core.web.controller.BaseController;
|
|
|
import com.boman.common.core.web.domain.AjaxResult;
|
|
|
+import com.boman.common.redis.RedisKey;
|
|
|
import com.boman.common.redis.service.RedisService;
|
|
|
import com.boman.gen.domain.GenTable;
|
|
|
import com.boman.gen.domain.GenTableColumn;
|
|
|
+import com.boman.gen.domain.GenTableRelation;
|
|
|
import com.boman.gen.service.IGenTableColumnService;
|
|
|
+import com.boman.gen.service.IGenTableRelationService;
|
|
|
import com.boman.gen.service.IGenTableService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
@@ -17,6 +20,9 @@ import java.util.List;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static com.boman.common.core.utils.obj.ObjectUtils.requireNonNull;
|
|
|
+import static com.boman.common.core.utils.obj.ObjectUtils.requiredNonNull;
|
|
|
+
|
|
|
/**
|
|
|
* @author shiqian
|
|
|
* @description 获取gen_table
|
|
@@ -32,6 +38,8 @@ public class MyController extends BaseController {
|
|
|
private IGenTableColumnService genTableColumnService;
|
|
|
@Autowired
|
|
|
private RedisService redisService;
|
|
|
+ @Autowired
|
|
|
+ private IGenTableRelationService genTableRelationService;
|
|
|
|
|
|
/**
|
|
|
* 功能描述: 查询代码生成列表,table中封装columnList
|
|
@@ -40,22 +48,48 @@ public class MyController extends BaseController {
|
|
|
* @return AjaxResult
|
|
|
*/
|
|
|
@GetMapping("/loadTable")
|
|
|
- public AjaxResult loadTable(GenTable genTable) throws ClassNotFoundException {
|
|
|
+ public AjaxResult loadTable(GenTable genTable) {
|
|
|
List<GenTable> tableList = genTableService.selectGenTableList(genTable);
|
|
|
- if (null == tableList || tableList.isEmpty()) {
|
|
|
- return AjaxResult.success();
|
|
|
- }
|
|
|
+ requiredNonNull(tableList);
|
|
|
|
|
|
+ // load table and tableColumn
|
|
|
List<Long> tableIdList = tableList.stream().map(GenTable::getTableId).collect(Collectors.toList());
|
|
|
List<GenTableColumn> genTableColumns = genTableColumnService.listByTableIdList(tableIdList);
|
|
|
- if (null == genTableColumns || genTableColumns.isEmpty()) {
|
|
|
- return AjaxResult.success();
|
|
|
- }
|
|
|
-
|
|
|
+ requiredNonNull(genTableColumns);
|
|
|
packTableAndInsertToRedis(tableList, genTableColumns);
|
|
|
+
|
|
|
+ // load tableRelation
|
|
|
+ List<GenTableRelation> relationList = genTableRelationService.selectGenTableRelationList(new GenTableRelation());
|
|
|
+ requiredNonNull(relationList);
|
|
|
+ packRelationAndInsertToRedis(tableList, relationList);
|
|
|
+
|
|
|
return AjaxResult.success(tableList);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 功能描述: 把主表关联的附表的信息和附表的字段信息存进redis
|
|
|
+ *
|
|
|
+ * @param tableList tableList
|
|
|
+ * @param relationList 主表和附表的关联信息
|
|
|
+ */
|
|
|
+ private void packRelationAndInsertToRedis(List<GenTable> tableList, List<GenTableRelation> relationList) {
|
|
|
+ for (GenTable table : tableList) {
|
|
|
+ List<GenTable> tableListTemp = new ArrayList<>(16);
|
|
|
+ for (GenTableRelation relation : relationList) {
|
|
|
+ if (relation.getRelationParentId().equals(table.getTableId())) {
|
|
|
+ Long childId = relation.getRelationChildId();
|
|
|
+ // 存了附表的建表信息和表的所有字段信息
|
|
|
+ List<GenTable> collect = tableList.stream()
|
|
|
+ .filter(genTable -> genTable.getTableId().equals(childId))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ tableListTemp.add(requireNonNull(collect).get(0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ table.setRelationList(tableListTemp);
|
|
|
+ redisService.setCacheObject(RedisKey.RELATION + table.getTableName(), table, 12L, TimeUnit.DAYS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 功能描述: 把table中塞入对应的column, 同时把所有的信息塞到redis中
|
|
|
*
|
|
@@ -72,7 +106,7 @@ public class MyController extends BaseController {
|
|
|
}
|
|
|
|
|
|
table.setColumns(columnList);
|
|
|
- redisService.setCacheObject("table:" + table.getTableName(), table, 12L, TimeUnit.DAYS);
|
|
|
+ redisService.setCacheObject(RedisKey.TABLE_INFO + table.getTableName(), table, 12L, TimeUnit.DAYS);
|
|
|
}
|
|
|
}
|
|
|
|