Преглед изворни кода

修改获取子表信息接口

Administrator пре 4 година
родитељ
комит
80f1b31d1d

+ 31 - 14
boman-modules/boman-gen/src/main/java/com/boman/gen/controller/MyController.java

@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
@@ -70,22 +71,36 @@ public class MyController extends BaseController {
     /**
      * 功能描述: 把主表关联的附表的信息和附表的字段信息存进redis
      *
-     * @param tableList    tableList
-     * @param relationList 主表和附表的关联信息
+     * @param tableList    tableList 所有表对象信息
+     * @param relationList 所有主表和附表的关联关系
+     * @param tableColumns 所有表字段
      */
     private void packRelationAndInsertToRedis(List<GenTable> tableList, List<GenTableRelation> relationList
             , List<GenTableColumn> tableColumns) {
         for (GenTable table : tableList) {
             List<GenTable> tableListTemp = new ArrayList<>(16);
+            //对关联关系表进行排序
+            relationList = relationList.stream().sorted(Comparator.comparing(GenTableRelation::getRelationParentId).thenComparing(GenTableRelation::getSort)).collect(Collectors.toList());
+
             for (GenTableRelation relation : relationList) {
                 if (relation.getRelationParentId().equals(table.getTableId())) {
+                    //关联主表PK gen_table_column的id
                     Long childId = relation.getRelationChildId();
-                    // 存了附表的建表信息和表的所有字段信息
-                    // todo
-                    List<GenTable> collect = tableList.stream()
-                            .filter(genTable -> genTable.getTableId().equals(childId))
-                            .collect(Collectors.toList());
-                    tableListTemp.add(collect.get(0));
+                    //根据gen_table_column的id查询出表id
+                    GenTableColumn genTableColumn = genTableColumnService.selectGenTableColumnListByColumnId(childId);
+                    // TODO: 2021/4/8
+                    //从tableList中去取出对应表的对象
+                    if (genTableColumn != null) {
+                        List<GenTable> collect = tableList.stream()
+                                .filter(genTable -> genTable.getTableId().equals(genTableColumn.getTableId()))
+                                .collect(Collectors.toList());
+                        GenTable genTable = collect.get(0);
+                        List<GenTableColumn> collectColumn = tableColumns.stream()
+                                .filter(genTableColumns -> genTableColumns.getTableId().equals(genTableColumn.getTableId()))
+                                .collect(Collectors.toList());
+                        genTable.setColumns(collectColumn);
+                        tableListTemp.add(genTable);
+                    }
                 }
             }
             table.setRelationList(tableListTemp);
@@ -114,12 +129,14 @@ public class MyController extends BaseController {
     }
 
 
-    /**手动更新redis缓存表数据
-    * @Description
-    * @author tjf
-    * @Date 2021/3/29
-    */
-    public AjaxResult updateRedisTable(){
+    /**
+     * 手动更新redis缓存表数据
+     *
+     * @Description
+     * @author tjf
+     * @Date 2021/3/29
+     */
+    public AjaxResult updateRedisTable() {
         //获取所有的表和表字段,更新到redis中
         List<GenTable> tableList = genTableService.selectGenTableList(new GenTable());
         if (null == tableList || tableList.isEmpty()) {

+ 16 - 1
boman-modules/boman-gen/src/main/java/com/boman/gen/domain/GenTableRelation.java

@@ -35,10 +35,23 @@ public class GenTableRelation extends BaseEntity {
     private Long relationType;
 
     /**
-     * 是否删除(1是)
+     * 排序
+     */
+    private Long sort;
+
+    /**
+     * 是否删除(Y是)
      */
     private String isDel;
 
+    public Long getSort() {
+        return sort;
+    }
+
+    public void setSort(Long sort) {
+        this.sort = sort;
+    }
+
     public Long getId() {
         return id;
     }
@@ -87,6 +100,7 @@ public class GenTableRelation extends BaseEntity {
         this.isDel = isDel;
     }
 
+
     @Override
     public String toString() {
         return "GenTableRelation{" +
@@ -95,6 +109,7 @@ public class GenTableRelation extends BaseEntity {
                 ", relationParentId=" + relationParentId +
                 ", relationChildId=" + relationChildId +
                 ", relationType=" + relationType +
+                ", sort=" + sort +
                 ", isDel='" + isDel + '\'' +
                 '}';
     }

+ 7 - 0
boman-modules/boman-gen/src/main/java/com/boman/gen/mapper/GenTableColumnMapper.java

@@ -27,6 +27,13 @@ public interface GenTableColumnMapper
      */
     public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId);
 
+    /**
+     * 根据gen_table_column的id查询字段对象
+     * @param columnId
+     * @return
+     */
+    public GenTableColumn selectGenTableColumnListByColumnId(Long columnId);
+
     /**
      * 查询业务字段列表
      *

+ 10 - 0
boman-modules/boman-gen/src/main/java/com/boman/gen/service/GenTableColumnServiceImpl.java

@@ -32,6 +32,16 @@ public class GenTableColumnServiceImpl implements IGenTableColumnService {
         return genTableColumnMapper.selectGenTableColumnListByTableId(tableId);
     }
 
+    /**
+     * 根据gen_table_column的id查询字段对象
+     * @param columnId
+     * @return
+     */
+    @Override
+    public GenTableColumn selectGenTableColumnListByColumnId(Long columnId) {
+        return   genTableColumnMapper.selectGenTableColumnListByColumnId(columnId);
+    }
+
     /**
      * 查询业务字段列表
      *

+ 7 - 0
boman-modules/boman-gen/src/main/java/com/boman/gen/service/IGenTableColumnService.java

@@ -18,6 +18,13 @@ public interface IGenTableColumnService
      */
     public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId);
 
+    /**
+     * 根据gen_table_column的id查询字段对象
+     * @param columnId
+     * @return
+     */
+    public GenTableColumn selectGenTableColumnListByColumnId(Long columnId);
+
     /**
      * 查询业务字段列表
      *

+ 6 - 0
boman-modules/boman-gen/src/main/resources/mapper/generator/GenTableColumnMapper.xml

@@ -40,6 +40,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         order by sort
     </select>
 
+    <select id="selectGenTableColumnListByColumnId" parameterType="GenTableColumn" resultMap="GenTableColumnResult">
+        <include refid="selectGenTableColumnVo"/>
+        where column_id = #{columnId}
+       limit 1
+    </select>
+
     <select id="listByTableIdList" parameterType="GenTableColumn" resultMap="GenTableColumnResult">
         <include refid="selectGenTableColumnVo"/>
         where table_id in

+ 5 - 1
boman-modules/boman-gen/src/main/resources/mapper/generator/GenTableRelationMapper.xml

@@ -10,6 +10,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<result property="relationParentId"     column="relation_parent_id"      />
 		<result property="relationChildId"     column="relation_child_id"      />
 		<result property="relationType"     column="relation_type"      />
+		<result property="sort"     column="sort"      />
 		<result property="createBy"     column="create_by"      />
 		<result property="createTime"     column="create_time"      />
 		<result property="updateBy"     column="update_by"      />
@@ -18,7 +19,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	</resultMap>
 
 	<sql id="selectGenTableRelationVo">
-        select id, description, relation_parent_id, relation_child_id, relation_type, create_by, create_time, update_by, update_time, is_del
+        select id, description, relation_parent_id, relation_child_id, relation_type, sort, create_by, create_time, update_by, update_time, is_del
 		from gen_table_relation
     </sql>
 
@@ -58,6 +59,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<if test="relationParentId != null">relation_parent_id,</if>
 		<if test="relationChildId != null">relation_child_id,</if>
 		<if test="relationType != null">relation_type,</if>
+		<if test="sort != null">sort,</if>
 		<if test="createBy != null and createBy != ''">create_by,</if>
 		<if test="updateBy != null and updateBy != ''">update_by,</if>
 		<if test="updateTime != null and updateTime != ''">update_time,</if>
@@ -67,6 +69,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<if test="relationParentId != null">#{relationParentId},</if>
 		<if test="relationChildId != null">#{relationChildId},</if>
 		<if test="relationType != null">#{relationType},</if>
+		<if test="sort != null">#{sort},</if>
 		<if test="createBy != null and createBy != ''">#{createBy},</if>
 		<if test="updateBy != null and updateBy != ''">#{updateBy},</if>
 		<if test="updateTime != null and updateTime != ''">#{updateTime},</if>
@@ -81,6 +84,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 			<if test="relationParentId != null">relation_parent_id = #{relationParentId},</if>
 			<if test="relationChildId != null">relation_child_id = #{relationChildId},</if>
 			<if test="relationType != null">relation_type = #{relationType},</if>
+			<if test="sort != null">sort = #{sort},</if>
 			<if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
 			<if test="create_time != null">create_time = #{createTime},</if>
 			<if test="updateBy != null and updateBy != null">update_by = #{updateBy},</if>

+ 4 - 0
boman-web-core/src/main/java/com/boman/web/core/constant/FormDataConstant.java

@@ -88,6 +88,10 @@ public class FormDataConstant {
 
     /**  根据表名查询表单时,返回给前台列表展示的列*/
     public static final String TABLE_HEAD_LIST = "tableHeadList";
+    /**
+     * 查询主表的子表对象的头
+     */
+    public static final String REF = "ref";
 
     /**  分页  总条数*/
     public static final String PAGE_TOTAL = "total";

+ 16 - 0
boman-web-core/src/main/java/com/boman/web/core/domain/BaseTableSaveDTO.java

@@ -158,6 +158,22 @@ public class BaseTableSaveDTO implements Serializable {
     public void setStatus(String status) {
         this.status = status;
     }
+
+    public Integer getPageNo() {
+        return pageNo;
+    }
+
+    public void setPageNo(Integer pageNo) {
+        this.pageNo = pageNo;
+    }
+
+    public Integer getPageSize() {
+        return pageSize;
+    }
+
+    public void setPageSize(Integer pageSize) {
+        this.pageSize = pageSize;
+    }
 }
 
 

+ 21 - 19
boman-web-core/src/main/java/com/boman/web/core/service/TableServiceCmdService.java

@@ -330,12 +330,22 @@ public class TableServiceCmdService {
         // genTable.getMenuRole() 暂时数据库没有数据,
         jsonObject.put(FormDataConstant.BUTTON_LIST, Strings.nullToEmpty(genTable.getMenuRole()));
 
+        jsonObject.put(FormDataConstant.TABLE_HEAD_LIST, getTableHeadList(genTable));
+        return AjaxResult.success(jsonObject);
+    }
+
+
+    /**
+     * 根据表对象获取要显示的表头信息
+     * @param genTable
+     * @return
+     */
+    public List<GenTableColumn> getTableHeadList(GenTable genTable){
+        List<GenTableColumn> columns = genTable.getColumns();
         // 表头
-        List<GenTableColumn> tableHeadList = columns.stream()
+        return columns.stream()
                 .filter(genTableColumn -> GenTableColumn.IS_LIST.equals(genTableColumn.getIsList()))
                 .collect(Collectors.toList());
-        jsonObject.put(FormDataConstant.TABLE_HEAD_LIST, tableHeadList);
-        return AjaxResult.success(jsonObject);
     }
 
     /**
@@ -345,24 +355,16 @@ public class TableServiceCmdService {
      * @return com.boman.common.core.web.domain.AjaxResult
      */
     public AjaxResult objectTab(BaseTableSaveDTO condition) {
+        //获取到主表对象
         GenTable genTable = getTableFromRedisByTableName(RedisKey.RELATION, condition.getTable());
-
+        //从主表对象的relationList中获取出所有子表表对象
         List<GenTable> childTableList = genTable.getRelationList();
-        // 此表没有关联子表,查啥查
-        requireNonNull(childTableList);
-        // todo
-        for (GenTable childTable : childTableList) {
-            String childTableName = childTable.getTableName();
-            Long childTableTableId = childTable.getTableId();
-            List<GenTableColumn> childColumns = childTable.getColumns();
-            //  column_name = 先根据tableName查到id,再用id到relation中查到relation_child_id, 在用这个值去到tableColumn中查到column_name
-            // select * from childTableName where column_name = objId
-
-
-        }
-
-
-        return AjaxResult.success();
+        // 表头
+        List<GenTableColumn> tableHeadList = getTableHeadList(genTable);
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put(FormDataConstant.REF, childTableList);
+        jsonObject.put(FormDataConstant.TABLE_HEAD_LIST, tableHeadList);
+        return AjaxResult.success(jsonObject);
     }
 
     public String getChildColumnNameByParentTableName(GenTable parentGenTable, Long childTableTableId){