Bläddra i källkod

新增动态表格接口

xuezizhuo 1 år sedan
förälder
incheckning
c8f1fb4698

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

@@ -3,7 +3,9 @@ package com.ruoyi.web.controller.dragForm;
 import java.util.List;
 import javax.servlet.http.HttpServletResponse;
 
+import com.ruoyi.common.annotation.Anonymous;
 import com.ruoyi.system.entity.DragTable;
+import com.ruoyi.system.entity.vo.DragTableVo;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -28,7 +30,7 @@ import com.ruoyi.common.core.page.TableDataInfo;
  * @author xzz
  * @date 2023-07-31
  */
-
+@Anonymous
 @RestController
 @RequestMapping("/system/table")
 public class DragTableController extends BaseController {
@@ -90,4 +92,13 @@ public class DragTableController extends BaseController {
     public AjaxResult remove(@PathVariable Long[] tIds) {
         return toAjax(dragTableService.deleteDragTableByTIds(tIds));
     }
+
+    /**
+     * 新增动态表格
+     */
+    @PostMapping("/addDragTable")
+    public AjaxResult addDragTable(@RequestBody DragTableVo dragTableVo){
+        return toAjax(dragTableService.addDragTable(dragTableVo));
+    }
+
 }

+ 169 - 0
ruoyi-system/src/main/java/com/ruoyi/system/entity/vo/DragTableVo.java

@@ -0,0 +1,169 @@
+package com.ruoyi.system.entity.vo;
+
+import com.ruoyi.common.annotation.Excel;
+import com.ruoyi.common.core.domain.BaseEntity;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 动态格对象 drag_table
+ * 
+ * @author ruoyi
+ * @date 2023-07-31
+ */
+public class DragTableVo
+{
+    /** 表格主键 */
+    private Long tId;
+
+    /** 菜单名称 */
+    private String dtName;
+
+    /** 表格别名 */
+    private String dtNickname;
+
+    /** 路由信息 */
+    private String tableKey;
+
+    /** sql编号 */
+    private String sqlKey;
+
+    /** 绑定表名称 */
+    private String dtTableName;
+
+    /** 列字段标题名称(存储显示字段信息JSON) */
+    private Object dtColumnName;
+
+    /** 时间格式 */
+    private String timeFormat;
+
+    /** 是否显示列表复选框(0:显示;1;不显示) */
+    private String isSelection;
+
+    /** 搜索字段数组 */
+    private List<String> searchFieldList;
+
+    /** 表查询语句 */
+    private String tableSql;
+
+    /** 导出字段名以及列名JSON */
+    private Object tableExportField;
+
+
+    public Long gettId() {
+        return tId;
+    }
+
+    public void settId(Long tId) {
+        this.tId = tId;
+    }
+
+    public String getDtName() {
+        return dtName;
+    }
+
+    public void setDtName(String dtName) {
+        this.dtName = dtName;
+    }
+
+    public String getDtNickname() {
+        return dtNickname;
+    }
+
+    public void setDtNickname(String dtNickname) {
+        this.dtNickname = dtNickname;
+    }
+
+    public String getTableKey() {
+        return tableKey;
+    }
+
+    public void setTableKey(String tableKey) {
+        this.tableKey = tableKey;
+    }
+
+    public String getSqlKey() {
+        return sqlKey;
+    }
+
+    public void setSqlKey(String sqlKey) {
+        this.sqlKey = sqlKey;
+    }
+
+    public String getDtTableName() {
+        return dtTableName;
+    }
+
+    public void setDtTableName(String dtTableName) {
+        this.dtTableName = dtTableName;
+    }
+
+    public Object getDtColumnName() {
+        return dtColumnName;
+    }
+
+    public void setDtColumnName(Object dtColumnName) {
+        this.dtColumnName = dtColumnName;
+    }
+
+    public String getTimeFormat() {
+        return timeFormat;
+    }
+
+    public void setTimeFormat(String timeFormat) {
+        this.timeFormat = timeFormat;
+    }
+
+    public String getIsSelection() {
+        return isSelection;
+    }
+
+    public void setIsSelection(String isSelection) {
+        this.isSelection = isSelection;
+    }
+
+    public List<String> getSearchFieldList() {
+        return searchFieldList;
+    }
+
+    public void setSearchFieldList(List<String> searchFieldList) {
+        this.searchFieldList = searchFieldList;
+    }
+
+    public String getTableSql() {
+        return tableSql;
+    }
+
+    public void setTableSql(String tableSql) {
+        this.tableSql = tableSql;
+    }
+
+    public Object getTableExportField() {
+        return tableExportField;
+    }
+
+    public void setTableExportField(Object tableExportField) {
+        this.tableExportField = tableExportField;
+    }
+
+    @Override
+    public String toString() {
+        return "DragTableVo{" +
+                "tId=" + tId +
+                ", dtName='" + dtName + '\'' +
+                ", dtNickname='" + dtNickname + '\'' +
+                ", tableKey='" + tableKey + '\'' +
+                ", sqlKey='" + sqlKey + '\'' +
+                ", dtTableName='" + dtTableName + '\'' +
+                ", dtColumnName='" + dtColumnName + '\'' +
+                ", timeFormat='" + timeFormat + '\'' +
+                ", isSelection='" + isSelection + '\'' +
+                ", searchFieldList=" + searchFieldList +
+                ", tableSql='" + tableSql + '\'' +
+                ", tableExportField='" + tableExportField + '\'' +
+                '}';
+    }
+}

+ 6 - 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.DragTableVo;
 
 import java.util.List;
 
@@ -68,4 +69,9 @@ public interface IDragTableService
      * @return 动态格
      */
     CommonEntity dragTableInfo(String sqlKey);
+
+    /**
+     * 新增动态表格
+     */
+    int addDragTable(DragTableVo dragTableVo);
 }

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

@@ -3,19 +3,24 @@ package com.ruoyi.system.service.impl;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.uuid.IdUtils;
 import com.ruoyi.system.entity.CommonEntity;
 import com.ruoyi.system.entity.DragTable;
 import com.ruoyi.system.entity.DragTableCondition;
 import com.ruoyi.system.entity.TableSql;
+import com.ruoyi.system.entity.vo.DragTableVo;
 import com.ruoyi.system.mapper.CommonMapper;
 import com.ruoyi.system.mapper.DragTableConditionMapper;
 import com.ruoyi.system.mapper.TableSqlMapper;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.ruoyi.system.mapper.DragTableMapper;
 import com.ruoyi.system.service.IDragTableService;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 
@@ -136,4 +141,34 @@ public class DragTableServiceImpl implements IDragTableService
         commonEntity.setResultMap(resultMap);
         return commonEntity;
     }
+
+    @Transactional
+    @Override
+    public int addDragTable(DragTableVo dragTableVo) {
+
+        //生成dtNickname表格别名
+        String dtNickname = IdUtils.fastSimpleUUID();
+        //生成sqlKey唯一标识
+        String sqlKey = IdUtils.fastSimpleUUID();
+
+        //add drag_table
+        DragTable dragTable = new DragTable();
+        BeanUtils.copyProperties(dragTableVo,dragTable);
+        dragTable.setDtTableName(dtNickname);
+        dragTable.setSqlKey(sqlKey);
+        dragTable.setDtColumnName(dragTableVo.getDtColumnName().toString());
+
+        //add table_sql
+        TableSql tableSql = new TableSql();
+        tableSql.setTableSql(dragTableVo.getTableSql());
+        tableSql.setTableCondition(dragTableVo.getSearchFieldList().stream().collect(Collectors.joining(",")));
+        tableSql.setTableAlias(dragTableVo.getDtTableName());
+        tableSql.setSqlKey(sqlKey);
+        tableSql.setTableExportField(dragTableVo.getTableExportField().toString());
+        tableSqlMapper.insertTableSql(tableSql);
+
+        //add drag_table_condition
+
+        return dragTableMapper.insertDragTable(dragTable);
+    }
 }