Bläddra i källkod

表格组 表格新增逻辑拆分

侯茂昌 1 år sedan
förälder
incheckning
e2795e1b00
20 ändrade filer med 375 tillägg och 90 borttagningar
  1. 1 1
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/dragForm/CommonController.java
  2. 35 29
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/dragForm/DragTableGroupController.java
  3. 1 0
      ruoyi-system/src/main/java/com/ruoyi/system/entity/CommonEntity.java
  4. 11 0
      ruoyi-system/src/main/java/com/ruoyi/system/entity/DragTable.java
  5. 5 0
      ruoyi-system/src/main/java/com/ruoyi/system/entity/DragTableCondition.java
  6. 14 0
      ruoyi-system/src/main/java/com/ruoyi/system/entity/DragTableGroup.java
  7. 0 2
      ruoyi-system/src/main/java/com/ruoyi/system/entity/vo/DragTableGroupVo.java
  8. 1 1
      ruoyi-system/src/main/java/com/ruoyi/system/mapper/DragTableConditionMapper.java
  9. 7 0
      ruoyi-system/src/main/java/com/ruoyi/system/mapper/DragTableGroupMapper.java
  10. 12 2
      ruoyi-system/src/main/java/com/ruoyi/system/mapper/DragTableMapper.java
  11. 2 0
      ruoyi-system/src/main/java/com/ruoyi/system/service/ICommonService.java
  12. 0 1
      ruoyi-system/src/main/java/com/ruoyi/system/service/IDataSourceService.java
  13. 14 10
      ruoyi-system/src/main/java/com/ruoyi/system/service/IDragTableGroupService.java
  14. 7 0
      ruoyi-system/src/main/java/com/ruoyi/system/service/IDragTableService.java
  15. 43 0
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CommonServiceImpl.java
  16. 102 31
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DragTableGroupServiceImpl.java
  17. 76 3
      ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DragTableServiceImpl.java
  18. 2 2
      ruoyi-system/src/main/resources/mapper/dragmapper/DragTableConditionMapper.xml
  19. 18 6
      ruoyi-system/src/main/resources/mapper/dragmapper/DragTableGroupMapper.xml
  20. 24 2
      ruoyi-system/src/main/resources/mapper/dragmapper/DragTableMapper.xml

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

@@ -79,7 +79,7 @@ public class CommonController extends BaseController {
     public TableDataInfo queryTableList(CommonEntity commonEntity) throws TenantDataSource {
         TableSql tableSql = iTableSqlService.selectTableSqlByTSqlKey(commonEntity.getQueryMap().get("sqlkey").toString());
         startPage();  // 校验是否sqlserver 否执行 是执行另一种方式的分页
-        return getDataTable(commonService.queryTableList(commonEntity, tableSql));
+        return getDataTable(commonService.queryTableList2(commonEntity, tableSql));
     }
 
     /**

+ 35 - 29
ruoyi-admin/src/main/java/com/ruoyi/web/controller/dragForm/DragTableGroupController.java

@@ -6,16 +6,15 @@ import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.page.TableDataInfo;
 import com.ruoyi.common.enums.BusinessType;
 import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.system.entity.CommonEntity;
 import com.ruoyi.system.entity.DragTableGroup;
 import com.ruoyi.system.entity.vo.DragTableGroupVo;
 import com.ruoyi.system.service.IDragTableGroupService;
-import com.ruoyi.system.service.impl.DragTableServiceImpl;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
-
 import javax.servlet.http.HttpServletResponse;
 import java.util.List;
 
@@ -32,12 +31,20 @@ public class DragTableGroupController extends BaseController {
     @Autowired
     private IDragTableGroupService dragTableGroupService;
 
-
+    /**
+     * 传groupKey获取当前组下的所有动态表格
+     * @param commonEntity
+     * @return
+     */
+    @GetMapping("/dragGroupTableInfo")
+    public AjaxResult dragGroupTableInfo(CommonEntity commonEntity) {
+        return   AjaxResult.success(dragTableGroupService.selectDragTableGroup(commonEntity.getQueryMap().get("groupKey").toString()));
+    }
 
     /**
      * 查询拖拽格组列表
+     * @PreAuthorize("@ss.hasPermi('system:group:list')")
      */
-    @PreAuthorize("@ss.hasPermi('system:group:list')")
     @GetMapping("/list")
     @ApiOperation(value = "查询拖拽格组列表")
     public TableDataInfo list(DragTableGroup dragTableGroup)
@@ -47,6 +54,20 @@ public class DragTableGroupController extends BaseController {
         return getDataTable(list);
     }
 
+    /**
+     * 查询拖拽表格组详细信息
+     * @param dragTableGroup
+     * @return
+     */
+    @GetMapping("/listDetail")
+    @ApiOperation(value = "查询拖拽格组列表")
+    public AjaxResult listDetail(DragTableGroup dragTableGroup)
+    {
+        DragTableGroupVo list = dragTableGroupService.selectDragTableGroupListDetail(dragTableGroup);
+        return AjaxResult.success(list);
+    }
+
+
     /**
      * 导出拖拽格组列表
      */
@@ -72,31 +93,10 @@ public class DragTableGroupController extends BaseController {
         return success(dragTableGroupService.selectDragTableGroupById(id));
     }
 
-    /**
-     * 获取拖拽格组详细信息
-     */
-    //@PreAuthorize("@ss.hasPermi('system:group:query')")
-    //@GetMapping(value = "/{id}")
-    //@ApiOperation(value = "获取拖拽格组详细信息")
-    //public AjaxResult getInfo(@PathVariable("groupKey") Long groupKey)
-    //{
-    //    return success(dragTableGroupService.selectDragTableGroupById(id));
-    //}
-
 
     /**
      * 新增拖拽格组
      */
-    //@PreAuthorize("@ss.hasPermi('system:group:add')")
-    //@Log(title = "拖拽格组", businessType = BusinessType.INSERT)
-    //@PostMapping
-    //@ApiOperation(value = "新增拖拽格组")
-    //public AjaxResult add(@RequestBody DragTableGroup dragTableGroup)
-    //{
-    //    return toAjax(dragTableGroupService.insertDragTableGroup(dragTableGroup));
-    //}
-
-    //@PreAuthorize("@ss.hasPermi('system:group:add')")
     @Log(title = "拖拽格组", businessType = BusinessType.INSERT)
     @PostMapping
     @ApiOperation(value = "新增拖拽格组")
@@ -112,20 +112,26 @@ public class DragTableGroupController extends BaseController {
     @Log(title = "拖拽格组", businessType = BusinessType.UPDATE)
     @PutMapping
     @ApiOperation(value = "修改拖拽格组")
-    public AjaxResult edit(@RequestBody DragTableGroup dragTableGroup)
+    public AjaxResult edit(@RequestBody DragTableGroupVo dragTableGroupVo)
     {
-        return toAjax(dragTableGroupService.updateDragTableGroup(dragTableGroup));
+        return toAjax(dragTableGroupService.updateDragTableGroup(dragTableGroupVo));
     }
 
+
     /**
-     * 删除拖拽格组
+     * 批量删除拖拽格组
      */
     @PreAuthorize("@ss.hasPermi('system:group:remove')")
     @Log(title = "拖拽格组", businessType = BusinessType.DELETE)
     @DeleteMapping("/{ids}")
     @ApiOperation(value = "删除拖拽格组")
-    public AjaxResult remove(@PathVariable Long[] ids)
+    public AjaxResult batchRemove(@PathVariable Long[] ids)
     {
+        Boolean aBoolean = dragTableGroupService.selectDragTableGroupTableListSize(ids);
+        if(!aBoolean){
+            return   AjaxResult.error("该表格组下存在表格信息不能删除");
+        }
         return toAjax(dragTableGroupService.deleteDragTableGroupByIds(ids));
     }
+
 }

+ 1 - 0
ruoyi-system/src/main/java/com/ruoyi/system/entity/CommonEntity.java

@@ -19,6 +19,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
  * @date 2023/7/19 4:05 PM
  */
 public class CommonEntity extends BaseEntity {
+
     private static final long serialVersionUID = 1L;
 
     /**

+ 11 - 0
ruoyi-system/src/main/java/com/ruoyi/system/entity/DragTable.java

@@ -25,6 +25,13 @@ public class DragTable extends BaseEntity {
     @Excel(name = "表格名称")
     private String dtName;
 
+    /**
+     * 表格类型
+     */
+    @Excel(name = "表格名称")
+    private String dtType;
+
+
     /**
      * 表格别名
      */
@@ -134,6 +141,10 @@ public class DragTable extends BaseEntity {
         this.tId = tId;
     }
 
+    public String getDtType() {return dtType;}
+
+    public void setDtType(String dtType) {this.dtType = dtType;}
+
     public String getDtName() {
         return dtName;
     }

+ 5 - 0
ruoyi-system/src/main/java/com/ruoyi/system/entity/DragTableCondition.java

@@ -125,6 +125,11 @@ public class DragTableCondition extends BaseEntity {
     public DragTableCondition() {
     }
 
+    public DragTableCondition(Long tId, String conditionField) {
+        this.tId = tId;
+        this.conditionField = conditionField;
+    }
+
     public DragTableCondition(Long tId, String conditionField, String conditionDefaultValue) {
         this.tId = tId;
         this.conditionField = conditionField;

+ 14 - 0
ruoyi-system/src/main/java/com/ruoyi/system/entity/DragTableGroup.java

@@ -35,6 +35,12 @@ public class DragTableGroup extends BaseEntity {
     private String groupTableInfo;
 
 
+
+    /**
+     * 逻辑删除
+     */
+    private String delFlag;
+
     public void setId(Long id)
     {
         this.id = id;
@@ -76,6 +82,14 @@ public class DragTableGroup extends BaseEntity {
         this.groupKey = groupKey;
     }
 
+    public String getDelFlag() {
+        return delFlag;
+    }
+
+    public void setDelFlag(String delFlag) {
+        this.delFlag = delFlag;
+    }
+
     @Override
     public String toString() {
         return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)

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

@@ -21,8 +21,6 @@ public class DragTableGroupVo extends BaseEntity {
     /** 存放表格联动信息 [{tablekey:kh123,顺序:1},{tablekey:kh123,顺序:2}] */
     private String groupTableInfo;
 
-
-
     /**
      * 动态表格key
      */

+ 1 - 1
ruoyi-system/src/main/java/com/ruoyi/system/mapper/DragTableConditionMapper.java

@@ -39,7 +39,7 @@ public interface DragTableConditionMapper
     /**
      * 批量删除动态表格条件
      * 
-     * @param tcIds 需要删除的数据主键集合
+     * @param conditions 需要删除的数据主键集合
      * @return 结果
      */
     int deleteDragTableConditionByTcIds(@Param("conditions") Map<String, Object> conditions);

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

@@ -66,4 +66,11 @@ public interface DragTableGroupMapper {
      * @return
      */
     public String selectDragTableGroupByGroupKey(String groupKey);
+
+    /**
+     * 通过In id查询出来组信息
+     * @return
+     */
+    public  List<DragTableGroup> selectDragTableGroupByIdIn(Long[] ids);
+
 }

+ 12 - 2
ruoyi-system/src/main/java/com/ruoyi/system/mapper/DragTableMapper.java

@@ -75,7 +75,17 @@ public interface DragTableMapper
     DragTableVo selectDragTableVoByTId(Long tId);
 
     /**
-     * 获取动态表单详情
+     * 根据tableKey获取动态表格详情
+     */
+    DragTable selectDragTableByTableKey(String tableKey);
+
+    /**
+     * 根据tableKey批量获取动态表单详情
+     */
+    List<DragTableVo> selectDragTableTableKeys(List<String> tableKeys);
+
+    /**
+     * 根据tableKey批量删除动态表单详情
      */
-    DragTable selectDragTableSqlKeyByTableKey(String tableKey);
+    int deleteDragTableByTableKeys(List<String> tableKeys);
 }

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

@@ -35,6 +35,8 @@ public interface ICommonService {
      */
     List<CommonEntity> queryTableList(CommonEntity commonEntity, TableSql tableSql);
 
+     List<CommonEntity> queryTableList2(CommonEntity commonEntity, TableSql tableSql);
+
     /**
      * 导出列表
      */

+ 0 - 1
ruoyi-system/src/main/java/com/ruoyi/system/service/IDataSourceService.java

@@ -4,7 +4,6 @@ package com.ruoyi.system.service;
 import com.ruoyi.common.config.datasource.utils.AjaxResult;
 import com.ruoyi.system.entity.DataSource;
 import com.ruoyi.system.entity.TableInfo;
-import  com.ruoyi.system.entity.vo.TableInfoVO;
 
 import java.util.List;
 import java.util.Map;

+ 14 - 10
ruoyi-system/src/main/java/com/ruoyi/system/service/IDragTableGroupService.java

@@ -39,10 +39,10 @@ public interface IDragTableGroupService {
     /**
      * 修改拖拽格组
      *
-     * @param dragTableGroup 拖拽格组
+     * @param dragTableGroupVo 拖拽格组
      * @return 结果
      */
-    public int updateDragTableGroup(DragTableGroup dragTableGroup);
+    public int updateDragTableGroup(DragTableGroupVo dragTableGroupVo);
 
     /**
      * 批量删除拖拽格组
@@ -52,18 +52,22 @@ public interface IDragTableGroupService {
      */
     public int deleteDragTableGroupByIds(Long[] ids);
 
-    /**
-     * 删除拖拽格组信息
-     *
-     * @param id 拖拽格组主键
-     * @return 结果
-     */
-    public int deleteDragTableGroupById(Long id);
-
     /**
      * 根据表格组key查询表格组信息
      * @param groupKey
      * @return
      */
     public String selectDragTableGroup(String groupKey);
+
+    /**
+     * 查询表格组包含的详细信息
+     * @param dragTableGroup
+     * @return
+     */
+    DragTableGroupVo selectDragTableGroupListDetail(DragTableGroup dragTableGroup);
+
+    /**
+     * 查询当前组下是否包含有表格信息
+     */
+    Boolean selectDragTableGroupTableListSize(Long[] ids);
 }

+ 7 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/IDragTableService.java

@@ -2,6 +2,7 @@ package com.ruoyi.system.service;
 
 import com.ruoyi.system.entity.CommonEntity;
 import com.ruoyi.system.entity.DragTable;
+import com.ruoyi.system.entity.vo.DragTableGroupVo;
 import com.ruoyi.system.entity.vo.DragTableVo;
 
 import java.util.List;
@@ -75,6 +76,12 @@ public interface IDragTableService
      */
     void addDragTable(DragTableVo dragTableVo);
 
+    /**
+     * 表格组新增动态表格
+     * @param dragTableGroupVo
+     */
+    void addDragTable(DragTableGroupVo dragTableGroupVo);
+
     /**
      * 获取动态表格详情详情
      */

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

@@ -21,6 +21,7 @@ import javax.annotation.Resource;
 import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletResponse;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicReference;
 
 import static com.ruoyi.common.utils.StringUtils.*;
 
@@ -111,8 +112,50 @@ public class CommonServiceImpl implements ICommonService {
         return commonMapper.batchDelete(tableName, conditions);
     }
 
+
+    public List<CommonEntity> queryTableList2(CommonEntity commonEntity, TableSql tableSql) {
+           //前端传递过来的参数
+           Map<String, Object> queryMap = commonEntity.getQueryMap();
+           //是否存在
+           AtomicReference<Boolean> isExist= new AtomicReference<>(true);
+           //循环前端传过来的参数 跳过 sqlkey
+           AtomicReference<String> replaceSql= new AtomicReference<>(tableSql.getTableCondition());
+           queryMap.forEach((k,v)->{
+               if(!k.equals("sqlkey")){
+                   int isExistIndex = tableSql.getTableCondition().indexOf(k);
+                   replaceSql.set(tableSql.getTableCondition().replace(k, v.toString()));
+                   if(isExistIndex<0){
+                       isExist.set(false);
+                   }
+               }
+           });
+           //证明条件不对应不能让他进行查询
+           if(!isExist.get()){
+               List<CommonEntity> commonEntityList = new ArrayList<>();
+               CommonEntity common = new CommonEntity();
+               HashMap<String, Object> hashMap=new HashMap();
+               hashMap.put("err","查询条件不匹配查询失败");
+               common.setResultMap(hashMap);
+               commonEntityList.add(common);
+               return  commonEntityList;
+           }
+           Map<String, Object> conditions = JSONObject.parseObject(JSON.toJSONString(commonEntity.getQueryMap()));
+           String queryCriteriaValue =
+                        conditions.containsKey("queryCriteriaValue") == true
+                                ? conditions.get("queryCriteriaValue").toString() : "";
+           String endSQL = replaceSql.get().replace("#{val}", queryCriteriaValue);
+           String sqlString=tableSql.getTableSql() + " where " + endSQL;
+           return commonMapper.queryTableList(sqlString);
+    }
+
+    //以前的逻辑传递sqlKey、查询到一条TableSql数据
+    //commonEntity没改动的情况下只有sqlKey
+    //queryCriteriaValue,这参数是前端传过来的的,存的是标准超级查询的数据
+    //直接是后台的tableSql进行的拼接
+    //把前端传过来的值给替换掉#{val}
     @Override
     public List<CommonEntity> queryTableList(CommonEntity commonEntity, TableSql tableSql) {
+
         // 根据sqlkey查询得到当前表单对应的sql
         Map<String, Object> conditions = JSONObject.parseObject(JSON.toJSONString(commonEntity.getQueryMap()));
         // 得到查询条件的值

+ 102 - 31
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DragTableGroupServiceImpl.java

@@ -1,20 +1,25 @@
 package com.ruoyi.system.service.impl;
 
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
-import com.ruoyi.common.utils.DateUtils;
-import com.ruoyi.system.entity.DragTable;
+import com.ruoyi.system.entity.DragTableCondition;
 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.DragTableConditionMapper;
 import com.ruoyi.system.mapper.DragTableGroupMapper;
 import com.ruoyi.system.mapper.DragTableMapper;
+import com.ruoyi.system.mapper.TableSqlMapper;
 import com.ruoyi.system.service.IDragTableGroupService;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.core.parameters.P;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @author hmc
@@ -34,6 +39,12 @@ public class DragTableGroupServiceImpl implements IDragTableGroupService {
     @Autowired
     private DragTableServiceImpl dragTableService;
 
+    @Autowired
+    private DragTableConditionMapper dragTableConditionMapper;
+
+    @Autowired
+    private TableSqlMapper tableSqlMapper;
+
     /**
      * 查询拖拽格组
      *
@@ -72,23 +83,43 @@ public class DragTableGroupServiceImpl implements IDragTableGroupService {
         DragTableGroup dragTableGroup=new DragTableGroup();
         BeanUtils.copyProperties(dragTableGroupVo,dragTableGroup);
         //添加动态表格列表
-        List<DragTableVo> dragTables = dragTableGroupVo.getDragTables();
-        dragTables.forEach(item->{
-            dragTableService.addDragTable(item);
-        });
+        dragTableService.addDragTable(dragTableGroupVo);
         return dragTableGroupMapper.insertDragTableGroup(dragTableGroup);
     }
     /**
      * 修改拖拽格组
      *
-     * @param dragTableGroup 拖拽格组
+     * @param dragTableGroupVo 拖拽格组
      * @return 结果
      */
     @Override
-    public int updateDragTableGroup(DragTableGroup dragTableGroup)
+    public int updateDragTableGroup(DragTableGroupVo dragTableGroupVo)
     {
-        dragTableGroup.setUpdateTime(DateUtils.getNowDate());
-        return dragTableGroupMapper.updateDragTableGroup(dragTableGroup);
+        //根据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());
+        //删除表格数据
+        dragTableMapper.deleteDragTableByTableKeys(tableKeys);
+        //删除条件数据
+        List<Long> dragTableIds = dragTableMapper.selectDragTableTableKeys(tableKeys)
+                .stream().map(item -> item.gettId()).collect(Collectors.toList());
+        dragTableConditionMapper.deleteDragTableConditionBytIds(dragTableIds);
+        //删除sql数据
+        Long[] dragTableIds1 = dragTableIds.toArray(new Long[0]);
+        tableSqlMapper.deleteTableSqlByTIds(dragTableIds1);
+        //修改表格组列表信息
+        DragTableGroup dragTableGroup=new DragTableGroup();
+        BeanUtils.copyProperties(dragTableGroupVo,dragTableGroup );
+        dragTableGroupMapper.updateDragTableGroup(dragTableGroup);
+        //从新插入数据
+        int insertRow = this.insertDragTableGroup(dragTableGroupVo);
+        return insertRow;
     }
 
     /**
@@ -103,17 +134,6 @@ public class DragTableGroupServiceImpl implements IDragTableGroupService {
         return dragTableGroupMapper.deleteDragTableGroupByIds(ids);
     }
 
-    /**
-     * 删除拖拽格组信息
-     *
-     * @param id 拖拽格组主键
-     * @return 结果
-     */
-    @Override
-    public int deleteDragTableGroupById(Long id)
-    {
-        return dragTableGroupMapper.deleteDragTableGroupById(id);
-    }
 
     /**
      * 根据表格组key查询表格组信息
@@ -123,16 +143,67 @@ public class DragTableGroupServiceImpl implements IDragTableGroupService {
     @Override
     public String selectDragTableGroup(String groupKey) {
         String groupTableInfo = dragTableGroupMapper.selectDragTableGroupByGroupKey(groupKey);
-        //HashMap hashMap = JSONObject.parseObject(groupTableInfo, HashMap.class);
-        ////向 hashMap 中添加键值对
-        //ArrayList<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String, Integer>>(hashMap.entrySet());
-        //Collections.sort(list, Comparator.comparing(Map.Entry::getValue));
-        //// 遍历排序后的 ArrayList
-        //HashMap<String,String> sortHashMap=new HashMap();
-        //for (Map.Entry<String, Integer> entry : list) {
-        //    System.out.println(entry.getKey() + ":" + entry.getValue());
-        //    sortHashMap.put(entry.getKey(),entry.getValue().toString());
-        //}
         return groupTableInfo;
     }
+
+    @Override
+    public DragTableGroupVo selectDragTableGroupListDetail(DragTableGroup dragTableGroup) {
+        //根据id查询表格组信息
+        DragTableGroup dragTableGroupOne = dragTableGroupMapper.selectDragTableGroupById(dragTableGroup.getId());
+        //得到group_table_info
+        String groupTableInfo = dragTableGroupOne.getGroupTableInfo();
+        //把他转换成Map对象
+        JSONArray jsonArray = JSON.parseArray(groupTableInfo);
+        List<String> stringList=new ArrayList<>();
+        //收集下tableKey
+        jsonArray.forEach(e->{
+            JSONObject jsonObject = JSON.parseObject(e.toString());
+            String str = jsonObject.get("tableKey").toString();
+            stringList.add(str);
+        });
+        //根据tableKey批量查询表格数据
+        List<DragTableVo> dragTables = dragTableMapper.selectDragTableTableKeys(stringList).stream().map(item -> {
+            //拿到这个表格的所有条件数据
+            List<DragTableCondition> dragTableConditions = dragTableConditionMapper.selectDragTableConditionByTid(item.gettId());
+            //条件
+            item.setSearchFieldList(dragTableConditions.stream().map(it->it.getConditionField()).collect(Collectors.toList()));
+            //绑定的默认值map
+            HashMap<String, Object> conditionDefaultValueMap = new HashMap<>();
+            //关联条件
+            dragTableConditions.forEach(condition -> {
+                if (condition.getConditionDefaultValue() != null && condition.getConditionDefaultValue() != "") {
+                    //条件字段:条件值
+                    conditionDefaultValueMap.put(condition.getConditionField(), condition.getConditionDefaultValue());
+                    item.setConditionDefaultValueMap(conditionDefaultValueMap);
+                }
+            });
+            return item;
+        }).collect(Collectors.toList());
+        DragTableGroupVo dragTableGroupVo=new DragTableGroupVo();
+        BeanUtils.copyProperties(dragTableGroupOne, dragTableGroupVo);
+        dragTableGroupVo.setDragTables(dragTables);
+        //查询表格的关联数据
+        return    dragTableGroupVo;
+    }
+
+    @Override
+    public Boolean selectDragTableGroupTableListSize(Long[] ids) {
+        List<DragTableGroup> dragTableGroups = dragTableGroupMapper.selectDragTableGroupByIdIn(ids);
+        List<String> tableKeys=new ArrayList<>();
+        //收集这个组下的所有tableKey
+        dragTableGroups.stream().forEach(item->{
+            JSONArray jsonArray = JSON.parseArray(item.getGroupTableInfo());
+            jsonArray.stream().forEach(
+                    it ->{
+                        tableKeys.add( JSONObject.parseObject(it.toString()).get("tableKey").toString());
+                    }
+            );
+        });
+        //判断tableKey在表格表中出现了吗
+        List<DragTableVo> dragTableVos = dragTableMapper.selectDragTableTableKeys(tableKeys);
+        if(dragTableVos.size()>0){
+            return  false;
+        }
+        return true;
+    }
 }

+ 76 - 3
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DragTableServiceImpl.java

@@ -12,6 +12,7 @@ import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.uuid.IdUtils;
 import com.ruoyi.system.entity.*;
+import com.ruoyi.system.entity.vo.DragTableGroupVo;
 import com.ruoyi.system.entity.vo.DragTableVo;
 import com.ruoyi.system.mapper.*;
 import org.apache.ibatis.jdbc.SQL;
@@ -128,10 +129,13 @@ public class DragTableServiceImpl implements IDragTableService {
     @Override
     public CommonEntity dragTableInfo(String tableKey) {
         //DragTable dragTable = dragTableMapper.selectDragTableBySqlKey(sqlKey);
-        DragTable dragTable = dragTableMapper.selectDragTableSqlKeyByTableKey(tableKey);
+        //根据tableKey查询动态表格结构数据
+        DragTable dragTable = dragTableMapper.selectDragTableByTableKey(tableKey);
+        //得到模板数据
         Map<String, Object> resultMap = new HashMap<>();
         resultMap.put("template", dragTable);
         //resultMap.put("where",dragTableConditionMapper.selectDragTableConditionByTid(dragTable.gettId()));
+        //根据表格id查询表格的条件
         List<DragTableCondition> dragTableConditions = dragTableConditionMapper.selectDragTableConditionByTid(dragTable.gettId());
         dragTableConditions.forEach(d -> {
             // 0 查询字典 1 查询表数据
@@ -178,6 +182,7 @@ public class DragTableServiceImpl implements IDragTableService {
         dragTable.setMenuId(dragTableVo.getMenuId());
         dragTable.setCreateTime(DateUtils.getNowDate());
         dragTable.setCreateById(SecurityUtils.getUserId());
+        dragTable.setDtType("1");//表格类型
         //add table_sql
         TableSql tableSql = new TableSql();
         tableSql.setTableSql(dragTableVo.getTableSql());
@@ -221,7 +226,8 @@ public class DragTableServiceImpl implements IDragTableService {
         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()));
+                //dragTableConditionList.add(new DragTableCondition(dragTable.gettId(), item,dragTableVo.getConditionDefaultValueMap().get(item).toString()));
+                dragTableConditionList.add(new DragTableCondition(dragTable.gettId(),item));
             });
             dragTableConditionList.forEach(e->{
                 e.setCreateById(SecurityUtils.getUserId());
@@ -230,6 +236,73 @@ public class DragTableServiceImpl implements IDragTableService {
         }
     }
 
+    @Transactional
+    @Override
+    public void addDragTable(DragTableGroupVo dragTableGroupVo) {
+
+        for (DragTableVo dragTableVo : dragTableGroupVo.getDragTables()) {
+            String SQL="";
+            //add drag_table
+            DragTable dragTable = new DragTable();
+            BeanUtils.copyProperties(dragTableVo, dragTable);
+            dragTable.setDtColumnName(JSON.toJSONString(dragTableVo.getDtColumnName()));
+            dragTable.setPrimaryKey(dragTableVo.getPrimaryKey());
+            dragTable.setMenuId(dragTableVo.getMenuId());
+            dragTable.setCreateTime(DateUtils.getNowDate());
+            dragTable.setCreateById(SecurityUtils.getUserId());
+            //add table_sql
+            TableSql tableSql = new TableSql();
+            tableSql.setTableSql(dragTableVo.getTableSql());
+            tableSql.setCreateTime(DateUtils.getNowDate());
+            tableSql.setCreateById(SecurityUtils.getUserId());
+            dragTableMapper.insertDragTable(dragTable);
+            //拼接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.setTableExportField(JSON.toJSONString(dragTableVo.getTableExportField()));
+            tableSql.setSqlKey(dragTableVo.getSqlKey());
+            tableSql.setOrderByColumn(dragTableVo.getOrderByColumn());
+            tableSql.setSortOrder(dragTableVo.getSortOrder());
+            tableSqlMapper.insertTableSql(tableSql);
+            //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()));
+                    });
+                    //赋值创建人
+                    dragTableConditionList.forEach(e->{
+                        e.setCreateById(SecurityUtils.getUserId());
+                    });
+                    dragTableConditionMapper.insertDragTableConditionByList(dragTableConditionList);
+            }
+        }
+    }
+
+
     @Override
     public DragTableVo selectDragTableVoByTId(Long tId) {
         DragTableVo vo = dragTableMapper.selectDragTableVoByTId(tId);
@@ -323,6 +396,6 @@ public class DragTableServiceImpl implements IDragTableService {
 
     @Override
     public DragTable selectSqlKeyByTableKey(String tableKey) {
-        return dragTableMapper.selectDragTableSqlKeyByTableKey(tableKey);
+        return dragTableMapper.selectDragTableByTableKey(tableKey);
     }
 }

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

@@ -64,10 +64,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <insert id="insertDragTableConditionByList"  parameterType="java.util.List">
         insert into drag_table_condition
-        (t_id,condition_field,create_by_id)
+        (t_id,condition_field,create_by_id,condition_default_value)
         values
         <foreach collection="list" item="item" index="index" separator=",">
-            (#{item.tId},#{item.conditionField},#{item.createById})
+            (#{item.tId},#{item.conditionField},#{item.createById},#{item.conditionDefaultValue})
         </foreach>
     </insert>
 

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

@@ -9,6 +9,7 @@
         <result property="groupName"    column="group_name"    />
         <result property="groupDescription"    column="group_description"    />
         <result property="groupTableInfo"    column="group_table_info"    />
+        <result property="groupKey"    column="group_key"    />
         <result property="createById"    column="create_by_id"    />
         <result property="createBy"    column="create_by"    />
         <result property="createTime"    column="create_time"    />
@@ -18,7 +19,7 @@
     </resultMap>
 
     <sql id="selectDragTableGroupVo">
-        select id, group_name, group_description, group_table_info, create_by_id, create_by, create_time, update_by_id, update_by, update_time from drag_table_group
+        select id, group_name, group_description,group_key, group_table_info,create_by_id, create_by, create_time, update_by_id, update_by, update_time from drag_table_group
     </sql>
 
     <select id="selectDragTableGroupList" parameterType="com.ruoyi.system.entity.DragTableGroup" resultMap="DragTableGroupResult">
@@ -27,21 +28,32 @@
             <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="createById != null  and createById != ''"> and create_by_id = #{createById}</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>
         </where>
     </select>
 
-    <select id="selectDragTableGroupById" parameterType="Long" resultMap="DragTableGroupResult">
-        <include refid="selectDragTableGroupVo"/>
-        where id = #{id}
-    </select>
 
     <select id="selectDragTableGroupByGroupKey" parameterType="String" resultType="string">
         select group_table_info from drag_table_group
         where group_key = #{groupKey}
     </select>
 
+    <select id="selectDragTableGroupById" resultType="com.ruoyi.system.entity.DragTableGroup" resultMap="DragTableGroupResult">
+        <include refid="selectDragTableGroupVo"/>
+        where  id=#{id}
+    </select>
+
+    <select id="selectDragTableGroupByIdIn" resultType="com.ruoyi.system.entity.DragTableGroup">
+        <include refid="selectDragTableGroupVo"/>
+        where  id in
+        <foreach item="id" collection="array" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </select>
+
+
     <insert id="insertDragTableGroup" parameterType="com.ruoyi.system.entity.DragTableGroup">
         insert into drag_table_group
         <trim prefix="(" suffix=")" suffixOverrides=",">

+ 24 - 2
ruoyi-system/src/main/resources/mapper/dragmapper/DragTableMapper.xml

@@ -28,7 +28,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <resultMap type="com.ruoyi.system.entity.vo.DragTableVo" id="DragTableVoResult">
-        <result property="tId"    column="t_id"    />
+        <result property="tId"    column="t_id"/>
         <result property="dtName"    column="dt_name"    />
         <result property="dtNickname"    column="dt_nickname"    />
         <result property="tableKey"    column="table_key"    />
@@ -39,6 +39,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="isSelection"   column="is_selection"/>
         <result property="tableSql" column="table_sql"/>
         <result property="tableExportFieldEcho" column="table_export_field"/>
+        <result property="orderByColumn" column="order_by_column"/>
         <result property="echoData"      column="echo_data"/>
         <result property="menuId" column="menu_id"/>
         <result property="primaryKey" column="primary_key"/>
@@ -156,6 +157,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </foreach>
     </delete>
 
+    <delete id="deleteDragTableByTableKeys" parameterType="list" >
+        delete from drag_table where table_key in
+        <foreach item="tableKey" collection="list" open="(" separator="," close=")">
+            #{tableKey}
+        </foreach>
+    </delete>
+
     <select id="selectDragTableBySqlKey" parameterType="String" resultMap="DragTableResult">
         <include refid="selectDragTableVo"/>
         where sql_key = #{sqlKey}
@@ -170,8 +178,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         WHERE
             dt.t_id = #{tId}
     </select>
-    <select id="selectDragTableSqlKeyByTableKey" parameterType="String" resultMap="DragTableResult">
+    <select id="selectDragTableByTableKey" parameterType="String" resultMap="DragTableResult">
         <include refid="selectDragTableVo"/>
         where table_key = #{tableKey}
     </select>
+
+    <select id="selectDragTableTableKeys" parameterType="list" resultMap="DragTableResult">
+        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>
+    </select>
 </mapper>