Selaa lähdekoodia

fix:表格联动修改

侯茂昌 1 vuosi sitten
vanhempi
säilyke
8eedcbcc46
19 muutettua tiedostoa jossa 362 lisäystä ja 225 poistoa
  1. 108 7
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/dragForm/CommonBtnController.java
  2. 1 6
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/dragForm/CommonController.java
  3. 4 5
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/dragForm/DragTableController.java
  4. 12 1
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/dragForm/DragTableGroupController.java
  5. 12 0
      ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java
  6. 13 0
      ruoyi-system/src/main/java/com/ruoyi/system/entity/DragTableBtn.java
  7. 0 2
      ruoyi-system/src/main/java/com/ruoyi/system/entity/vo/DragTableGroupVo.java
  8. 6 0
      ruoyi-system/src/main/java/com/ruoyi/system/mapper/DragTableGroupMapper.java
  9. 5 0
      ruoyi-system/src/main/java/com/ruoyi/system/mapper/DragTableMapper.java
  10. 9 0
      ruoyi-system/src/main/java/com/ruoyi/system/service/IDragTableGroupService.java
  11. 2 2
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CommonServiceImpl.java
  12. 107 12
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DragTableGroupServiceImpl.java
  13. 0 2
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DragTableServiceImpl.java
  14. 34 14
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DragTableStatisticServiceImpl.java
  15. 4 158
      ruoyi-system/src/main/java/com/ruoyi/system/test/ljj.java
  16. 18 15
      ruoyi-system/src/main/resources/mapper/common/TableSqlMapper.xml
  17. 2 1
      ruoyi-system/src/main/resources/mapper/dragmapper/DragTableBtnMapper.xml
  18. 6 0
      ruoyi-system/src/main/resources/mapper/dragmapper/DragTableGroupMapper.xml
  19. 19 0
      ruoyi-system/src/main/resources/mapper/dragmapper/DragTableMapper.xml

+ 108 - 7
ruoyi-admin/src/main/java/com/ruoyi/web/controller/dragForm/CommonBtnController.java

@@ -1,13 +1,24 @@
 package com.ruoyi.web.controller.dragForm;
 
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.ruoyi.common.constant.ButtonTypeConstants;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.utils.bean.BeanUtils;
 import com.ruoyi.common.utils.form.FromUtils;
 import com.ruoyi.system.entity.CommonEntity;
 import com.ruoyi.system.entity.DragForm;
 import com.ruoyi.system.entity.DragTableBtn;
+import com.ruoyi.system.entity.DragTableGroup;
+import com.ruoyi.system.entity.vo.DragTableGroupVo;
+import com.ruoyi.system.entity.vo.DragTableVo;
+import com.ruoyi.system.mapper.DragTableBtnMapper;
+import com.ruoyi.system.mapper.DragTableBtnRelevanceMapper;
+import com.ruoyi.system.mapper.DragTableGroupMapper;
+import com.ruoyi.system.mapper.DragTableMapper;
 import com.ruoyi.system.service.*;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -15,8 +26,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @author hanzihang
@@ -37,6 +48,21 @@ public class CommonBtnController extends BaseController {
     @Resource
     private FromUtils fromUtils;
 
+    @Resource
+    private DragTableMapper dragTableMapper;
+
+    @Resource
+    private   IDragTableGroupService dragTableGroupService;
+
+    @Resource
+    private DragTableGroupMapper dragTableGroupMapper;
+
+    @Resource
+    private DragTableBtnRelevanceMapper dragTableBtnRelevanceMapper;
+
+    @Resource
+    private DragTableBtnMapper dragTableBtnMapper;
+
     /**
      * 处理按钮通用接口(新增、修改、删除)
      */
@@ -108,19 +134,94 @@ public class CommonBtnController extends BaseController {
             }
             return toAjax(commonService.edit(commonEntity));
         } else if (commonEntity.getBasicMap().get("visible").toString().equals("false")) {
-            Map<String, Object> map = new HashMap<>();
-            //获取模板信息
+            //单纯是表格还是弹窗里有表格
+            return getAjaxResult(commonEntity);
+        } else {
+            return warn("暂不支持该操作!");
+        }
+    }
+
+    /**
+     * 判断是正常的表单渲染还是配置组三个的渲染
+     * @param commonEntity
+     * @return
+     * @throws JsonProcessingException
+     */
+    private AjaxResult getAjaxResult(CommonEntity commonEntity) throws JsonProcessingException {
+        Map<String, Object> map = new HashMap<>();
+        //先拿到btnKey
+        String btnKey = commonEntity.getBasicMap().get("btnKey").toString();
+        //查询按钮列表
+        DragTableBtn dragTableBtn = iDragTableBtnService.selectDragTableBtnByBtnKey(btnKey);
+        //判断是走原生的表单解析还是、走配置的表单解析
+        if (dragTableBtn.getBtnTableFormGroupKey()!=null&&dragTableBtn.getBtnTableFormGroupKey()!="") {
+            //查询组信息
+            DragTableGroup dragTableGroup = dragTableGroupMapper.selectDragTableGroupOneByGroupKey(dragTableBtn.getBtnTableFormGroupKey());
+            DragTableGroupVo dragTableGroupVo=new DragTableGroupVo();
+            //赋值给vo才好放表格
+            BeanUtils.copyProperties(dragTableGroup, dragTableGroupVo);
+
+            //把[{"tableKey":"a1","sort":0},{"tableKey":"a2","sort":1}]转换成Map对象
+            JSONArray jsonArray = JSON.parseArray( dragTableGroup.getGroupTableInfo());
+            //排序确保表格的顺序
+            JSONArray sortArray = jsonArray.stream().sorted(
+                    Comparator.comparingLong(
+                            // 根据对象中的ID进行排序
+                            e -> JSONObject.parseObject(e.toString()).getIntValue("sort")
+                    )
+            ).collect(Collectors.toCollection(JSONArray::new));
+            //用in查询
+            List<String> tableKeys = new ArrayList<>();
+            sortArray.stream().forEach(item->
+                    tableKeys.add(JSONObject.parseObject(item.toString()).get("tableKey").toString()));
+
+            //查询表格信息
+            List<DragTableVo> dragTableVos = dragTableMapper.selectDragTableTableKeysOrderby(tableKeys);
+            dragTableVos.forEach(item->{
+                // 动态表格按钮信息
+                //根据tableKey获取根节点信息
+                List<String> btnKeys = dragTableBtnRelevanceMapper.selectBtnKeyByTableKey(item.getTableKey());
+                //获取根节点数据
+                if(btnKeys.size() > 0){
+                    List<DragTableBtn> rootNodes = dragTableBtnMapper.selectDragTableBtnListByBtnKey(btnKeys);
+                    //查询子节点
+                    List<Long> ids = rootNodes.stream().map(m -> m.getId()).collect(Collectors.toList());
+                    if (ids.isEmpty()){
+                         item.setDragTableBtnList(rootNodes);
+                    }else {
+                        List<DragTableBtn> childNodes = dragTableBtnMapper.selectChildNodeById(ids);
+                        List<DragTableBtn> btnList = rootNodes.stream().peek(
+                                root -> root.setChildren(getChildrenList(root, childNodes))
+                        ).collect(Collectors.toList());
+                        item.setDragTableBtnList(btnList);
+                    }
+                }
+            });
+            //查询表格按钮
+            dragTableGroupVo.setDragTables(dragTableVos);
+            map.put("template", null);
+            //把groupKey放进去
+            map.put("result",dragTableGroupVo);
+        }else {
             String sqlKey = commonEntity.getBasicMap().get("sqlKey").toString();
             DragForm dragForm = dragFormService.selectDragFormBySqlKey(sqlKey);
             map.put("template", dragForm);
             //返回结果
             map.put("result", commonService.getInfoById(commonEntity));
-            return success(map);
-        } else {
-            return warn("暂不支持该操作!");
         }
+        return success(map);
     }
 
+    private List<DragTableBtn> getChildrenList(DragTableBtn root, List<DragTableBtn> childNodes) {
+        List<DragTableBtn> list = childNodes.stream().filter(dragTableBtn ->
+                //筛选出下一节点元素
+                Objects.equals(dragTableBtn.getBtnParentId(), root.getId())).map(dragTableBtn -> {
+            //递归set子节点
+            dragTableBtn.setChildren(this.getChildrenList(dragTableBtn, childNodes));
+            return dragTableBtn;
+        }).collect(Collectors.toList());
+        return list;
+    }
     // 删除类型按钮
     public AjaxResult deleteBtn(CommonEntity commonEntity) {
         return toAjax(commonService.batchDelete(commonEntity));

+ 1 - 6
ruoyi-admin/src/main/java/com/ruoyi/web/controller/dragForm/CommonController.java

@@ -84,7 +84,6 @@ public class CommonController extends BaseController {
     @GetMapping("/getTableList")
     public TableDataInfo queryTableList(CommonEntity commonEntity) throws TenantDataSource {
         TableSql tableSql = iTableSqlService.selectTableSqlByTSqlKey(commonEntity.getQueryMap().get("sqlkey").toString());
-        System.err.println(tableSql);
         startPage();  // 校验是否sqlserver 否执行 是执行另一种方式的分页
         return getDataTable(commonService.queryGroupTableList(commonEntity, tableSql));
     }
@@ -97,11 +96,6 @@ public class CommonController extends BaseController {
       return   AjaxResult.success(dragTableService.dragTableInfo(commonEntity.getQueryMap().get("tableKey").toString()));
     }
 
-    @GetMapping("/dragGroupTableInfo")
-    public AjaxResult dragGroupTableInfo(CommonEntity commonEntity) {
-        return   AjaxResult.success(dragTableGroupService.selectDragTableGroup(commonEntity.getQueryMap().get("groupKey").toString()));
-    }
-
     /**
      * 动态表单预览接口
      */
@@ -134,6 +128,7 @@ public class CommonController extends BaseController {
             return toAjax(commonService.edit(commonEntity));
         } else if (btnType == ButtonTypeConstants.UPDATE && visible.equals("false")) {
             Map<String,Object> map = new HashMap<>();
+
             //获取模板信息
             String sqlKey = commonEntity.getBasicMap().get("sqlKey").toString();
             DragForm dragForm = dragFormService.selectDragFormBySqlKey(sqlKey);

+ 4 - 5
ruoyi-admin/src/main/java/com/ruoyi/web/controller/dragForm/DragTableController.java

@@ -106,10 +106,10 @@ public class DragTableController extends BaseController {
         if(dragTableVo.getDragTableStyleList().size() > 0){
             dragTableStyleService.batchInsertDragTableStyle(dragTableVo);
         }
-        //新增动态表格数据统计信息
-//        if(dragTableVo.getDragTableStatisticList().size() > 0){
-//            dragTableStatisticService.batchInsertDragTableStatistic(dragTableVo);
-//        }
+        ////新增动态表格数据统计信息
+        //if(dragTableVo.getDragTableStatisticList().size() > 0){
+        //    dragTableStatisticService.batchInsertDragTableStatistic(dragTableVo);
+        //}
         //新增表格按钮关联表
         if(dragTableVo.getDragTableBtnRelevanceList().size() > 0){
             dragTableBtnRelevanceService.batchInsertDragTableBtnRelevance(dragTableVo.getDragTableBtnRelevanceList());
@@ -159,7 +159,6 @@ public class DragTableController extends BaseController {
         dragTableStyleService.deleteDragTableStyleByTableKeys(tableKeys);
         // 删除动态表格和按钮关联表
         dragTableBtnRelevanceService.deleteDragTableBtnRelevanceByTableKeys(tableKeys);
-
         return AjaxResult.success();
     }
 

+ 12 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/dragForm/DragTableGroupController.java

@@ -131,6 +131,18 @@ public class DragTableGroupController extends BaseController {
         return toAjax(dragTableGroupService.updateDragTableGroup(dragTableGroupVo));
     }
 
+    /**
+     * 修改拖拽配置表格组
+     */
+    @PreAuthorize("@ss.hasPermi('system:group:edit')")
+    @Log(title = "拖拽格组", businessType = BusinessType.UPDATE)
+    @PutMapping("/editConfigurationGroup")
+    @ApiOperation(value = "修改拖拽配置表格组")
+    public AjaxResult editConfigurationGroup(@RequestBody DragTableGroupVo dragTableGroupVo)
+    {
+        return toAjax(dragTableGroupService.editConfigurationGroup(dragTableGroupVo));
+    }
+
 
     /**
      * 批量删除拖拽格组
@@ -144,5 +156,4 @@ public class DragTableGroupController extends BaseController {
         //Boolean aBoolean = dragTableGroupService.selectDragTableGroupTableListSize(ids);
         return toAjax(dragTableGroupService.deleteDragTableGroupByIds(ids));
     }
-
 }

+ 12 - 0
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/AjaxResult.java

@@ -182,4 +182,16 @@ public class AjaxResult extends HashMap<String, Object>
         super.put(key, value);
         return this;
     }
+
+
+    /**
+     * 返回错误消息
+     * @param data 数据对象
+     * @return 错误消息
+     */
+    public static AjaxResult btnMessage( Object data)
+    {
+        return new AjaxResult(HttpStatus.ERROR, "成功", data);
+    }
+
 }

+ 13 - 0
ruoyi-system/src/main/java/com/ruoyi/system/entity/DragTableBtn.java

@@ -54,6 +54,9 @@ public class DragTableBtn extends BaseEntity
     /** 脚本唯一标识 */
     private String btnScriptKey;
 
+    /** 脚本唯一标识 */
+    private String btnTableFormGroupKey;
+
     /** 按钮显示条件 */
     private String btnShowCondition;
 
@@ -242,6 +245,15 @@ public class DragTableBtn extends BaseEntity
         this.btnIcon = btnIcon;
     }
 
+    public String getBtnTableFormGroupKey() {
+        return btnTableFormGroupKey;
+    }
+
+    public void setBtnTableFormGroupKey(String btnTableFormGroupKey) {
+        this.btnTableFormGroupKey = btnTableFormGroupKey;
+    }
+
+
     @Override
     public String toString() {
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
@@ -255,6 +267,7 @@ public class DragTableBtn extends BaseEntity
             .append("btnProcessKey", getBtnProcessKey())
             .append("btnTableKey", getBtnTableKey())
             .append("btnScriptKey", getBtnScriptKey())
+            .append("btnTableFormGroupKey", getBtnTableFormGroupKey())
             .append("btnShowCondition", getBtnShowCondition())
             .append("btnParams", getBtnParams())
             .append("btnHasPermi", getBtnHasPermi())

+ 0 - 2
ruoyi-system/src/main/java/com/ruoyi/system/entity/vo/DragTableGroupVo.java

@@ -31,8 +31,6 @@ public class DragTableGroupVo extends BaseEntity {
     @Excel(name = "表格组key")
     private String groupType;
 
-
-
     //动态表格实体类集合
     public List<DragTableVo> dragTables;
 

+ 6 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/DragTableGroupMapper.java

@@ -73,4 +73,10 @@ public interface DragTableGroupMapper {
      */
     public  List<DragTableGroup> selectDragTableGroupByIdIn(Long[] ids);
 
+    /**
+     * 通过GroupKey
+     * @return
+     */
+    public  DragTableGroup selectDragTableGroupOneByGroupKey(String groupKey);
+
 }

+ 5 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/DragTableMapper.java

@@ -84,6 +84,11 @@ public interface DragTableMapper
      */
     List<DragTableVo> selectDragTableTableKeys(List<String> tableKeys);
 
+    /**
+     * 根据tableKey批量获取动态表单详情
+     */
+    List<DragTableVo> selectDragTableTableKeysOrderby(List<String> tableKeys);
+
     /**
      * 根据tableKey批量删除动态表单详情
      */

+ 9 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/IDragTableGroupService.java

@@ -51,6 +51,15 @@ public interface IDragTableGroupService {
      */
     public int updateDragTableGroup(DragTableGroupVo dragTableGroupVo);
 
+    /**
+     * 修改配置组
+     *
+     * @param dragTableGroupVo 拖拽格组
+     * @return 结果
+     */
+    public int editConfigurationGroup(DragTableGroupVo dragTableGroupVo);
+
+
     /**
      * 批量删除拖拽格组
      *

+ 2 - 2
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CommonServiceImpl.java

@@ -128,6 +128,7 @@ public class CommonServiceImpl implements ICommonService {
                    }
                }
            });
+
            //证明条件不对应不能让他进行查询
            if(!isExist.get()){
                List<CommonEntity> commonEntityList = new ArrayList<>();
@@ -138,7 +139,7 @@ public class CommonServiceImpl implements ICommonService {
                commonEntityList.add(common);
                return  commonEntityList;
            }
-           Map<String, Object> conditions = JSONObject.parseObject(JSON.toJSONString(commonEntity.getQueryMap()));
+        Map<String, Object> conditions = JSONObject.parseObject(JSON.toJSONString(commonEntity.getQueryMap()));
 
         //正常的查询
         String queryCriteriaValue =
@@ -311,6 +312,5 @@ public class CommonServiceImpl implements ICommonService {
         }
         String sqlColumn = input.substring(startIndex + identifier.length() + 1, endIndex);
         return convertToCamelCase(sqlColumn);
-
     }
 }

+ 107 - 12
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DragTableGroupServiceImpl.java

@@ -14,6 +14,7 @@ import com.ruoyi.system.mapper.DragTableConditionMapper;
 import com.ruoyi.system.mapper.DragTableGroupMapper;
 import com.ruoyi.system.mapper.DragTableMapper;
 import com.ruoyi.system.mapper.TableSqlMapper;
+import com.ruoyi.system.service.IDragTableBtnRelevanceService;
 import com.ruoyi.system.service.IDragTableGroupService;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -48,6 +49,8 @@ public class DragTableGroupServiceImpl implements IDragTableGroupService {
     @Autowired
     private TableSqlMapper tableSqlMapper;
 
+    @Autowired
+    private IDragTableBtnRelevanceService dragTableBtnRelevanceService;
     /**
      * 查询拖拽格组
      *
@@ -148,6 +151,84 @@ public class DragTableGroupServiceImpl implements IDragTableGroupService {
         //删除表格数据
         //dragTableMapper.deleteDragTableByTableKeys(tableKeys);
 
+        //优化逻辑 1、表格组信息 2、表格信息、条件信息、sql信息
+        List<DragTableVo> dragTables = dragTableGroupVo.getDragTables();
+        if (dragTables.size()>0) {
+            dragTables.stream().forEach(dragTableVo->{
+                String SQL="";
+                //update drag_table
+                DragTable dragTable = new DragTable();
+                BeanUtils.copyProperties(dragTableVo, dragTable);
+                dragTable.setDtColumnName(dragTableVo.getDtColumnName().toString());
+                dragTable.setPrimaryKey(dragTableVo.getPrimaryKey());
+                dragTable.setMenuId(dragTableVo.getMenuId());
+                dragTable.setDtType("1");
+                dragTableMapper.updateDragTable(dragTable);
+                //update table_sql
+                TableSql tableSql = new TableSql();
+                //拼接sql查询条件
+                switch (SecurityUtils.getDatabaseType().toUpperCase()) {
+                    case "MYSQL":
+                        for (int i = 0; dragTableVo.getSearchFieldList().size() > i; i++) {
+                            SQL += " AND "+dragTableVo.getSearchFieldList().get(i)+"="+dragTableVo.getConditionDefaultValueMap().get(dragTableVo.getSearchFieldList().get(i));
+                        }
+                        break;
+                    case "DM":
+                    case "SQLSERVER":
+                        SQL += SQL_START;
+                        for (int i = 0; dragTableVo.getSearchFieldList().size() > i; i++) {
+                            SQL += SQL_DM_SERVER_MIDDLE.replace("#{VAL}", dragTableVo.getSearchFieldList().get(i));
+                            SQL += dragTableVo.getSearchFieldList().size() - 1 == i ? ",'')" : ",\n";
+                        }
+                        break;
+                    case "ORACLE":
+                        //SQL_START = "";
+                        for (int i = 0; dragTableVo.getSearchFieldList().size() > i; i++) {
+                            SQL += dragTableVo.getSearchFieldList().get(i);
+                            SQL += (dragTableVo.getSearchFieldList().size() - 1 == i ? " " : "||");
+                        }
+                        break;
+                }
+                String where = dragTableVo.getDtTableName() + ".del_flag = '0'";
+                tableSql.setTableCondition(where + SQL);
+                tableSql.setTableAlias(dragTableVo.getDtTableName());
+                tableSql.setOrderByColumn(dragTableVo.getOrderByColumn());
+                tableSql.setSortOrder(dragTableVo.getSortOrder());
+                tableSql.setSqlKey(dragTableVo.getSqlKey());
+                int i = tableSqlMapper.updateTableSqlBySqlKey(tableSql);
+                System.out.println(i);
+                //add drag_table_condition
+                if (dragTableVo.getSearchFieldList().size() > 0) {
+                    List<DragTableCondition> dragTableConditionList = new ArrayList<>();
+                    dragTableVo.getSearchFieldList().forEach(item -> {
+                        dragTableConditionList.add(new DragTableCondition(dragTable.gettId(), item,dragTableVo.getConditionDefaultValueMap().get(item).toString()));
+                    });
+                    dragTableConditionMapper.insertDragTableConditionByList(dragTableConditionList);
+                }
+            });
+        }
+        //修改表格组列表信息
+        DragTableGroup dragTableGroup = new DragTableGroup();
+        BeanUtils.copyProperties(dragTableGroupVo, dragTableGroup);
+        int i = dragTableGroupMapper.updateDragTableGroup(dragTableGroup);
+        return i;
+    }
+
+    @Override
+    public int editConfigurationGroup(DragTableGroupVo dragTableGroupVo) {
+        //根据id查询表格组信息
+        DragTableGroup dragTableGroupOne = dragTableGroupMapper.selectDragTableGroupById(dragTableGroupVo.getId());
+        //得到group_table_info
+        String groupTableInfo = dragTableGroupOne.getGroupTableInfo();
+        //把他转换成Map对象
+        JSONArray jsonArray = JSON.parseArray(groupTableInfo);
+        //收集tableKey
+        List<String> tableKeys = jsonArray.stream().map(item -> JSONObject.parseObject(item.toString()).get("tableKey").toString()
+        ).collect(Collectors.toList());
+        //删除条件数据
+        List<Long> dragTableIds = dragTableMapper.selectDragTableTableKeys(tableKeys)
+                .stream().map(item -> item.gettId()).collect(Collectors.toList());
+        dragTableConditionMapper.deleteDragTableConditionBytIds(dragTableIds);
         //优化逻辑 1、表格组信息 2、表格信息、条件信息、sql信息
         List<DragTableVo> dragTables = dragTableGroupVo.getDragTables();
         if (dragTables.size()>0) {
@@ -156,13 +237,13 @@ public class DragTableGroupServiceImpl implements IDragTableGroupService {
                 //add drag_table
                 DragTable dragTable = new DragTable();
                 BeanUtils.copyProperties(dragTableVo, dragTable);
-                dragTable.setDtColumnName(JSON.toJSONString(dragTableVo.getDtColumnName()));
+                dragTable.setDtColumnName(dragTableVo.getDtColumnName().toString());
                 dragTable.setPrimaryKey(dragTableVo.getPrimaryKey());
                 dragTable.setMenuId(dragTableVo.getMenuId());
                 dragTable.setDtType("1");
                 //add table_sql
                 TableSql tableSql = new TableSql();
-                tableSql.settId(dragTable.gettId());
+                tableSql.setSqlKey(dragTableVo.getSqlKey());
                 tableSql.setTableSql(dragTableVo.getTableSql());
                 dragTableMapper.updateDragTable(dragTable);
                 //拼接sql查询条件
@@ -191,7 +272,6 @@ public class DragTableGroupServiceImpl implements IDragTableGroupService {
                 String where = dragTableVo.getDtTableName() + ".del_flag = '0'";
                 tableSql.setTableCondition(where + SQL);
                 tableSql.setTableAlias(dragTableVo.getDtTableName());
-                tableSql.setTableExportField(JSON.toJSONString(dragTableVo.getTableExportField()));
                 tableSql.setSqlKey(dragTableVo.getSqlKey());
                 tableSql.setOrderByColumn(dragTableVo.getOrderByColumn());
                 tableSql.setSortOrder(dragTableVo.getSortOrder());
@@ -204,14 +284,14 @@ public class DragTableGroupServiceImpl implements IDragTableGroupService {
                     });
                     dragTableConditionMapper.insertDragTableConditionByList(dragTableConditionList);
                 }
+                //修改按钮信息
+                dragTableBtnRelevanceService.updateDragTableBtnRelevance(dragTableVo);
             });
         }
         //修改表格组列表信息
         DragTableGroup dragTableGroup = new DragTableGroup();
         BeanUtils.copyProperties(dragTableGroupVo, dragTableGroup);
         int i = dragTableGroupMapper.updateDragTableGroup(dragTableGroup);
-        //从新插入数据
-        //dragTableService.addDragTable(dragTableGroupVo);
         return i;
     }
 
@@ -274,15 +354,25 @@ public class DragTableGroupServiceImpl implements IDragTableGroupService {
         String groupTableInfo = dragTableGroupOne.getGroupTableInfo();
         //把他转换成Map对象
         JSONArray jsonArray = JSON.parseArray(groupTableInfo);
-        List<String> stringList=new ArrayList<>();
-        //收集下tableKey
-        jsonArray.forEach(e->{
+        //排序确保表格的顺序
+        JSONArray sortArray = jsonArray.stream().sorted(
+                Comparator.comparingLong(
+                        // 根据对象中的ID进行排序
+                        e -> JSONObject.parseObject(e.toString()).getIntValue("sort")
+                )
+        ).collect(Collectors.toCollection(JSONArray::new));
+        //把查询出来的动态表格数据放到一个集合里边
+        List<DragTableVo> dragTableList=new ArrayList<>();
+        sortArray.forEach(e->{
             JSONObject jsonObject = JSON.parseObject(e.toString());
             String str = jsonObject.get("tableKey").toString();
-            stringList.add(str);
+            DragTable dragTable = dragTableMapper.selectDragTableByTableKey(str);
+            DragTableVo dragTableVo=new DragTableVo();
+            BeanUtils.copyProperties(dragTable, dragTableVo);
+            dragTableList.add( dragTableVo);
         });
-        //根据tableKey批量查询表格数据
-        List<DragTableVo> dragTables = dragTableMapper.selectDragTableTableKeys(stringList).stream().map(item -> {
+        //查询这个动态表格的 1.条件 2.sql信息
+        dragTableList.stream().map(item -> {
             //拿到这个表格的所有条件数据
             List<DragTableCondition> dragTableConditions = dragTableConditionMapper.selectDragTableConditionByTid(item.gettId());
             //条件
@@ -297,11 +387,16 @@ public class DragTableGroupServiceImpl implements IDragTableGroupService {
                     item.setConditionDefaultValueMap(conditionDefaultValueMap);
                 }
             });
+            //排序字段
+            TableSql tableSql = tableSqlMapper.selectTableSqlByTSqlKey(item.getSqlKey());
+            if(tableSql!=null){
+                item.setOrderByColumn(tableSql.getOrderByColumn());
+            }
             return item;
         }).collect(Collectors.toList());
         DragTableGroupVo dragTableGroupVo=new DragTableGroupVo();
         BeanUtils.copyProperties(dragTableGroupOne, dragTableGroupVo);
-        dragTableGroupVo.setDragTables(dragTables);
+        dragTableGroupVo.setDragTables(dragTableList);
         //查询表格的关联数据
         return    dragTableGroupVo;
     }

+ 0 - 2
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DragTableServiceImpl.java

@@ -167,10 +167,8 @@ public class DragTableServiceImpl implements IDragTableService {
         //根据tableKey获取根节点信息
         List<String> btnKeys = dragTableBtnRelevanceMapper.selectBtnKeyByTableKey(dragTable.getTableKey());
         //获取根节点数据
-        System.err.println(btnKeys.toString());
         if(btnKeys.size() > 0){
             List<DragTableBtn> rootNodes = dragTableBtnMapper.selectDragTableBtnListByBtnKey(btnKeys);
-            System.err.println(rootNodes.toString());
             //查询子节点
             List<Long> ids = rootNodes.stream().map(m -> m.getId()).collect(Collectors.toList());
             if (ids.isEmpty()){

+ 34 - 14
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DragTableStatisticServiceImpl.java

@@ -1,6 +1,7 @@
 package com.ruoyi.system.service.impl;
 
 import java.util.*;
+import java.util.concurrent.atomic.AtomicReference;
 import java.util.stream.Collectors;
 
 import com.alibaba.fastjson2.JSON;
@@ -19,7 +20,6 @@ import com.ruoyi.system.mapper.DragTableStatisticMapper;
 import com.ruoyi.system.service.IDragTableStatisticService;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.StringUtils;
-import org.springframework.web.bind.annotation.RequestBody;
 
 import javax.annotation.Resource;
 
@@ -80,6 +80,10 @@ public class DragTableStatisticServiceImpl implements IDragTableStatisticService
                 for (int i = 0; vo.getSearchFieldList().size() > i; i++) {
                     SQL += SQL_MIDDLE.replace("#{VAL}", vo.getSearchFieldList().get(i));
                     SQL += vo.getSearchFieldList().size() - 1 == i ? ")" : ",\n";
+                    SQL +=SQL_END;
+                    if(vo.getConditionDefaultValueMap()!=null&&vo.getConditionDefaultValueMap().size()>0){
+                        SQL += " AND "+vo.getSearchFieldList().get(i)+"="+vo.getConditionDefaultValueMap().get(vo.getSearchFieldList().get(i));
+                    }
                 }
                 break;
             case "DM":
@@ -88,19 +92,19 @@ public class DragTableStatisticServiceImpl implements IDragTableStatisticService
                 for (int i = 0; vo.getSearchFieldList().size() > i; i++) {
                     SQL += SQL_DM_SERVER_MIDDLE.replace("#{VAL}", vo.getSearchFieldList().get(i));
                     SQL += vo.getSearchFieldList().size() - 1 == i ? ",'')" : ",\n";
+                    SQL +=SQL_END;
                 }
                 break;
             case "ORACLE":
-//                SQL_START = "";
                 for (int i = 0; vo.getSearchFieldList().size() > i; i++) {
                     SQL += vo.getSearchFieldList().get(i);
                     SQL += (vo.getSearchFieldList().size() - 1 == i ? " " : "||");
+                    SQL +=SQL_END;
                 }
                 break;
         }
-        String where = vo.getDtTableName() + ".del_flag = '0' AND "+ SQL + SQL_END;
+        String where = vo.getDtTableName() + ".del_flag = '0' AND "+ SQL;
         vo.getTableSqlList().stream().forEach(t -> t.setTableCondition(where));
-
         tableSqlMapper.batchInsertTableSql(vo.getTableSqlList());
         return dragTableStatisticMapper.batchInsertDragTableStatistic(vo.getDragTableStatisticList());
     }
@@ -117,6 +121,10 @@ public class DragTableStatisticServiceImpl implements IDragTableStatisticService
                 for (int i = 0; vo.getSearchFieldList().size() > i; i++) {
                     SQL += SQL_MIDDLE.replace("#{VAL}", vo.getSearchFieldList().get(i));
                     SQL += vo.getSearchFieldList().size() - 1 == i ? ")" : ",\n";
+                    SQL +=SQL_END;
+                    if(vo.getConditionDefaultValueMap()!=null&&vo.getConditionDefaultValueMap().size()>0){
+                        SQL += " AND "+vo.getSearchFieldList().get(i)+"="+vo.getConditionDefaultValueMap().get(vo.getSearchFieldList().get(i));
+                    }
                 }
                 break;
             case "DM":
@@ -125,17 +133,18 @@ public class DragTableStatisticServiceImpl implements IDragTableStatisticService
                 for (int i = 0; vo.getSearchFieldList().size() > i; i++) {
                     SQL += SQL_DM_SERVER_MIDDLE.replace("#{VAL}", vo.getSearchFieldList().get(i));
                     SQL += vo.getSearchFieldList().size() - 1 == i ? ",'')" : ",\n";
+                    SQL +=SQL_END;
                 }
                 break;
             case "ORACLE":
-//                SQL_START = "";
                 for (int i = 0; vo.getSearchFieldList().size() > i; i++) {
                     SQL += vo.getSearchFieldList().get(i);
                     SQL += (vo.getSearchFieldList().size() - 1 == i ? " " : "||");
+                    SQL +=SQL_END;
                 }
                 break;
         }
-        String sql = vo.getDtTableName() + ".del_flag = '0' AND "+ SQL + SQL_END;
+        String sql = vo.getDtTableName() + ".del_flag = '0' AND "+ SQL;
 
         LinkedList<DragTableStatistic> addList = new LinkedList<>();
         LinkedList<DragTableStatistic> editList = new LinkedList<>();
@@ -145,18 +154,18 @@ public class DragTableStatisticServiceImpl implements IDragTableStatisticService
                    s.setCreateById(SecurityUtils.getUserId());
                    s.setCreateBy(SecurityUtils.getUsername());
                    s.setCreateTime(DateUtils.getNowDate());
-                   addList.add(s);
+                   addList.add(s);//新添加的
                }else {
                    s.setUpdateById(SecurityUtils.getUserId());
                    s.setUpdateBy(SecurityUtils.getUsername());
                    s.setUpdateTime(DateUtils.getNowDate());
-                   editList.add(s);
+                   editList.add(s); //修改的
                }
                numList.add(s.getId());
-           });
+        });
         //select Statistic ids
         List<Long> allIds = dragTableStatisticMapper.selectIdsByTableKey(vo.getTableKey());
-        allIds.removeAll(numList);
+        allIds.removeAll(numList); //把所有的统计都给干掉
         //remove Statistic
         if(allIds.size() > 0){
             dragTableStatisticMapper.deleteDragTableStatisticByIds(allIds);
@@ -174,7 +183,8 @@ public class DragTableStatisticServiceImpl implements IDragTableStatisticService
 
         if(vo.getTableSqlList().size() > 0){
             vo.getTableSqlList().stream().forEach(t -> {
-                t.setCreateBy(SecurityUtils.getUserId().toString());
+                t.setCreateById(SecurityUtils.getUserId());
+                t.setCreateBy(SecurityUtils.getUsername());
                 t.setCreateTime(DateUtils.getNowDate());
                 t.setTableCondition(sql);
             });
@@ -204,6 +214,7 @@ public class DragTableStatisticServiceImpl implements IDragTableStatisticService
         dragTableStatisticMapper.deleteDragTableStatisticByTableKeys(tableKeys);
     }
 
+
     @Override
     public Map<String, Object> getInfoBySqlKey(String tableKey) {
         Map<String,Object> map = new HashMap<>();
@@ -228,7 +239,18 @@ public class DragTableStatisticServiceImpl implements IDragTableStatisticService
         return dragTableStatisticList.stream().map(d -> {
             TableSql tableSql = tableSqlMapper.selectTableSqlByTSqlKey(d.getSqlKey());
             // 得到需要执行的sql条件语句
-            String endSQL = tableSql.getTableCondition().replace("#{val}", queryCriteriaValue);
+            AtomicReference<String> endSQLAtomic = new AtomicReference<>(tableSql.getTableCondition());
+            //查询配置信息查询统计信息
+            if(commonEntity.getQueryMap()!=null||commonEntity.getQueryMap().size()>0){
+                commonEntity.getQueryMap().forEach((k,v)->{
+                    if(!k.equals("tableKey")){
+                        String replace = tableSql.getTableCondition().replace(k, v.toString());
+                        endSQLAtomic.set(replace);
+                    }
+
+                });
+            }
+            String endSQL = endSQLAtomic.get().replace("#{val}", queryCriteriaValue);
             String sql = "";
             if(StringUtils.hasLength(d.getStatisticObject())){
                 sql = tableSql.getTableSql() + " where " + endSQL + " and " + d.getStatisticField() + " like'"+d.getStatisticObject()+"'";
@@ -239,7 +261,5 @@ public class DragTableStatisticServiceImpl implements IDragTableStatisticService
             d.setResult(commonEntities.get(0) == null ? 0 : commonEntities.get(0).getResultMap().get("result") );
             return d;
         }).collect(Collectors.toList());
-
-
     }
 }

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 4 - 158
ruoyi-system/src/main/java/com/ruoyi/system/test/ljj.java


+ 18 - 15
ruoyi-system/src/main/resources/mapper/common/TableSqlMapper.xml

@@ -123,28 +123,16 @@
         where t_id = #{tId}
     </update>
 
-    <delete id="deleteTableSqlByTId" parameterType="Long">
-        delete
-        from table_sql
-        where t_id = #{tId}
-    </delete>
-
-    <delete id="deleteTableSqlByTIds" parameterType="String">
-        delete from table_sql where t_id in
-        <foreach item="tId" collection="array" open="(" separator="," close=")">
-            #{tId}
-        </foreach>
-    </delete>
-
-    <update id="updateTableSqlBySqlKey">
+    <update id="updateTableSqlBySqlKey" parameterType="com.ruoyi.system.entity.TableSql">
         update table_sql
         <trim prefix="SET" suffixOverrides=",">
             <if test="tableSql != null">table_sql = #{tableSql},</if>
             <if test="tableCondition != null">table_condition = #{tableCondition},</if>
             <if test="tableAlias != null">table_alias = #{tableAlias},</if>
+            <if test="sqlKey != null">sql_key = #{sqlKey},</if>
             <if test="tableExportField != null">table_export_field = #{tableExportField},</if>
-            <if test="createBy != null">create_by = #{createBy},</if>
             <if test="createById != null">create_by_id = #{createById},</if>
+            <if test="createBy != null">create_by = #{createBy},</if>
             <if test="createTime != null">create_time = #{createTime},</if>
             <if test="updateById != null">update_by_id = #{updateById},</if>
             <if test="updateBy != null">update_by = #{updateBy},</if>
@@ -156,6 +144,21 @@
         where sql_key = #{sqlKey}
     </update>
 
+    <delete id="deleteTableSqlByTId" parameterType="Long">
+        delete
+        from table_sql
+        where t_id = #{tId}
+    </delete>
+
+    <delete id="deleteTableSqlByTIds" parameterType="String">
+        delete from table_sql where t_id in
+        <foreach item="tId" collection="array" open="(" separator="," close=")">
+            #{tId}
+        </foreach>
+    </delete>
+
+
+
     <delete id="deleteTableSqlBySqlKeys" parameterType="String">
         delete from table_sql where sql_key in
         <foreach item="sqlKey" collection="list" open="(" separator="," close=")">

+ 2 - 1
ruoyi-system/src/main/resources/mapper/dragmapper/DragTableBtnMapper.xml

@@ -32,7 +32,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <sql id="selectDragTableBtnVo">
-        select id, btn_parent_id,ancestors_id, btn_key,btn_group_name, btn_name, btn_type,btn_icon, btn_form_key, btn_process_key, btn_table_key, btn_script_key, btn_show_condition, btn_params, btn_has_permi, btn_sort, del_flag, create_by, create_by_id, create_time, update_by, update_by_id, update_time, remark from drag_table_btn
+        select id, btn_parent_id,ancestors_id, btn_key,btn_group_name, btn_name, btn_type,btn_icon, btn_form_key, btn_process_key, btn_table_key, btn_script_key,btn_table_form_group_key,btn_show_condition, btn_params, btn_has_permi, btn_sort, del_flag, create_by, create_by_id, create_time, update_by, update_by_id, update_time, remark from drag_table_btn
     </sql>
 
     <select id="selectDragTableBtnList" parameterType="com.ruoyi.system.entity.DragTableBtn" resultMap="DragTableBtnResult">
@@ -45,6 +45,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="btnType != null  and btnType != ''"> and btn_type = #{btnType}</if>
             <if test="btnFormKey != null  and btnFormKey != ''"> and btn_form_key = #{btnFormKey}</if>
             <if test="btnProcessKey != null  and btnProcessKey != ''"> and btn_process_key = #{btnProcessKey}</if>
+            <if test="btnTableFormGroupKey !=null and btnTableFormGroupKey!=''">and btn_table_form_group_key=#{btnTableFormGroupKey}</if>
             <if test="btnTableKey != null  and btnTableKey != ''"> and btn_table_key = #{btnTableKey}</if>
             <if test="btnScriptKey != null  and btnScriptKey != ''"> and btn_script_key = #{btnScriptKey}</if>
             <if test="btnShowCondition != null  and btnShowCondition != ''"> and btn_show_condition = #{btnShowCondition}</if>

+ 6 - 0
ruoyi-system/src/main/resources/mapper/dragmapper/DragTableGroupMapper.xml

@@ -28,6 +28,7 @@
             <if test="groupName != null  and groupName != ''"> and group_name like concat('%', #{groupName}, '%')</if>
             <if test="groupDescription != null  and groupDescription != ''"> and group_description = #{groupDescription}</if>
             <if test="groupTableInfo != null  and groupTableInfo != ''"> and group_table_info = #{groupTableInfo}</if>
+            <if test="groupType !=null  and groupType!=''">and group_type = #{groupType}</if>
             <if test="createById != null   and createById != ''" > and create_by_id = #{createById}</if>
             <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
             <if test="updateById != null  and updateById != ''"> and update_by_id = #{updateById}</if>
@@ -53,6 +54,11 @@
         </foreach>
     </select>
 
+    <select id="selectDragTableGroupOneByGroupKey" resultType="com.ruoyi.system.entity.DragTableGroup" parameterType="string">
+        <include refid="selectDragTableGroupVo"/>
+        where  group_key=#{groupKey}
+    </select>
+
 
     <insert id="insertDragTableGroup" parameterType="com.ruoyi.system.entity.DragTableGroup">
         insert into drag_table_group

+ 19 - 0
ruoyi-system/src/main/resources/mapper/dragmapper/DragTableMapper.xml

@@ -201,4 +201,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{item}
         </foreach>
     </select>
+
+    <select id="selectDragTableTableKeysOrderby" parameterType="list" resultMap="DragTableVoResult">
+        SELECT
+        dt.*,
+        ts.table_sql,
+        ts.table_export_field,
+        ts.order_by_column
+        FROM drag_table dt
+        LEFT JOIN table_sql ts ON dt.sql_key = ts.sql_key
+        where  table_key in
+        <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
+            #{item}
+        </foreach>
+        order by field
+        (table_key,
+        <foreach collection="list" index="index" item="item" separator=","  close=")">
+            #{item}
+        </foreach>
+    </select>
 </mapper>

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä