Просмотр исходного кода

添加api管理列表,添加,编辑

david 2 лет назад
Родитель
Сommit
782b43cb4a

BIN
out/artifacts/roma_api_jar/roma-api.jar


+ 33 - 4
src/main/java/com/roma/romaapi/controller/ApiController.java

@@ -86,7 +86,7 @@ public class ApiController {
         return CustomResponse.formatResponse(ret);
     }
 
-    // 权限管理-添加权限-获取所有页面,选择关联页面
+    // 权限管理-添加权限-获取所有页面,选择关联页面,无分页,且为options格式
     @RequestMapping("/api/pageList")
     public Map pageDetailsList(){
         Map<String, Object> ret = new HashMap<>();
@@ -145,7 +145,7 @@ public class ApiController {
         return CustomResponse.formatResponse(ret);
     }
 
-    // 权限管理-添加权限-获取所有页面,选择关联页面
+    // 权限管理-添加权限-获取所有页面,选择关联sql,无分页,且为options格式
     @RequestMapping("/api/sqlList")
     public Map sqlDetailsList(){
         Map<String, Object> ret = new HashMap<>();
@@ -155,7 +155,7 @@ public class ApiController {
         return CustomResponse.formatResponse(ret);
     }
 
-    // 权限管理-添加权限-获取所有页面,选择关联api
+    // 权限管理-添加权限-获取所有页面,选择关联api,无分页,且为options格式
     @RequestMapping("/api/apiList")
     public Map apiDetailsList(){
         Map<String, Object> ret = new HashMap<>();
@@ -165,7 +165,7 @@ public class ApiController {
         return CustomResponse.formatResponse(ret);
     }
 
-    // 权限管理-添加权限-获取所有页面,选择关联item
+    // 权限管理-添加权限-获取所有页面,选择关联item,无分页,且为options格式
     @RequestMapping("/api/itemList")
     public Map itemDetailsList(){
         Map<String, Object> ret = new HashMap<>();
@@ -204,6 +204,35 @@ public class ApiController {
         return CustomResponse.formatResponse(ret);
     }
 
+    // 返回带分页格式的数据-api列表管理页
+    @RequestMapping("/api/apiManageList")
+    public Map apiManageList(HttpServletRequest request, @RequestBody String data){
+        Map maps = commonUtil.analysisRequestParams(request, data); // 参数
+        Map<String, Object> ret = new HashMap<>();
+        ret = apiService.apiListHasPaging(maps);
+
+        return CustomResponse.formatResponse(ret);
+    }
+
+    // api管理-新增和编辑api
+    @RequestMapping("/api/apiSave")
+    public Map apiSave(HttpServletRequest request, @RequestBody String data, @RequestHeader("Authorization") String authorization) {
+        Map maps = commonUtil.analysisRequestParams(request, data); // 参数
+
+        Map ret = apiService.saveApi(maps, authorization);
+
+        return CustomResponse.formatResponse(ret);
+    }
+
+    // Api管理-获取api详情
+    @RequestMapping("/api/apiDetailed")
+    public Map apiDetailed(HttpServletRequest request, @RequestBody String data) {
+        Map maps = commonUtil.analysisRequestParams(request, data); // 参数
+        Map ret = apiService.apiDetailById(maps);
+
+        return CustomResponse.formatResponse(ret);
+    }
+
 
 
     // 用户管理-获取全部用户

+ 21 - 0
src/main/java/com/roma/romaapi/dao/ApiDao.java

@@ -174,6 +174,27 @@ public class ApiDao {
         }
     }
 
+    // 添加/编辑sql_details表数据
+    public Integer saveApiDetails(Map<String, Object> bindValue, String editId) {
+        String sql = "";
+        if (editId.length()==0) {
+            sql = " INSERT INTO `api_details` (`api_name`,`api_code`,`api_description`,`is_enable`,`created_at`) " +
+                    "VALUES (:apiName,:apiCode,:apiDesc,:isEnable,:createdAt)  ";
+            KeyHolder keyHolder = new GeneratedKeyHolder();
+            Integer row = namedParameterJdbcTemplate.update(sql, new MapSqlParameterSource(bindValue), keyHolder);
+            int k = keyHolder.getKey().intValue();
+
+            return k;
+        } else {
+            bindValue.put("id", editId);
+            sql = " UPDATE `api_details` SET `api_name`=:apiName,`api_code`=:apiCode,`api_description`=:apiDesc," +
+                    "`is_enable`=:isEnable WHERE id=:id";
+            Integer row = namedParameterJdbcTemplate.update(sql, bindValue);
+
+            return row;
+        }
+    }
+
     // Role角色管理-获取总数
     public Integer getAllRoleListHasPagingCount(Map bindValue) {
         // 获取总数

+ 21 - 0
src/main/java/com/roma/romaapi/dao/PageDao.java

@@ -115,6 +115,27 @@ public class PageDao {
         return resMap2;
     }
 
+    // Api页面管理-获取总数
+    public Integer getAllApiListHasPagingCount(Map bindValue) {
+        // 获取总数
+        String countInnerSql = " SELECT * FROM `api_details` WHERE 1=1 ";
+        String countSql = "SELECT COUNT(*) AS `totalData` FROM ( " + countInnerSql + " ) AS ROMA";
+        Integer count = namedParameterJdbcTemplate.queryForObject(countSql, bindValue, Integer.class);
+
+        return count;
+    }
+
+    // Api页面管理-获取带分页的列表数据
+    public List<Map<String, Object>> getAllApiListHasPaging(Map bindValue, String page, String perPage, Integer count) {
+        // 计算分页
+        String limitAfter = commonUtil.calcPagingString(count, page, perPage);
+        String listSql = "SELECT  *  FROM `api_details` WHERE 1=1 ORDER BY `id` DESC " + " LIMIT " + limitAfter;
+
+        List<Map<String, Object>> resMap2 = namedParameterJdbcTemplate.queryForList(listSql, bindValue);
+
+        return resMap2;
+    }
+
     // 获取全部的sql
     public List<Map<String, Object>> getAllSqlList() {
         Map<String, Object> paramMap = new HashMap<>();

+ 66 - 5
src/main/java/com/roma/romaapi/service/ApiService.java

@@ -150,7 +150,7 @@ public class ApiService {
         return info;
     }
 
-    // 获取全部page_details
+    // 获取全部page_details---配置权限关联page使用,无分页
     public List pageList() {
         Map<String, Object> map = new HashMap<>();
         List<Map<String, Object>> menuData = pageDao.getAllPageList(); // 获取全部page_details表数据
@@ -199,6 +199,26 @@ public class ApiService {
         return res;
     }
 
+    // api管理列表-获取带分页的page数据
+    public Map apiListHasPaging(Map<String, String> maps) {
+        String page = "1"; // 页数
+        String perPage = "15"; // 显示多少条
+        Map res = new HashMap<>();
+        Map bindData = commonUtil.filterApiBindParams(maps);
+        if(maps.containsKey("page")) {
+            page = maps.get("page");
+        }
+        if(maps.containsKey("perPage")) {
+            perPage = maps.get("perPage");
+        }
+        Integer count = pageDao.getAllApiListHasPagingCount(bindData);
+        List info = pageDao.getAllApiListHasPaging(bindData, page, perPage, count);
+        res.put("count", count);
+        res.put("rows", info);
+
+        return res;
+    }
+
     // 获取全部sql_details
     public List sqlList() {
         Map<String, Object> map = new HashMap<>();
@@ -208,7 +228,7 @@ public class ApiService {
         return menuData;
     }
 
-    // 获取全部api_details
+    // 获取全部api_details---配置权限关联api使用,无分页
     public List apiList() {
         Map<String, Object> map = new HashMap<>();
         List<Map<String, Object>> menuData = pageDao.getAllApiList(); // 获取全部page_details表数据
@@ -217,7 +237,7 @@ public class ApiService {
         return menuData;
     }
 
-    // 获取全部sql_details
+    // 获取全部sql_details---配置权限关联item使用,无分页
     public List itemList() {
         Map<String, Object> map = new HashMap<>();
         List<Map<String, Object>> menuData = pageDao.getAllItemList(); // 获取全部page_details表数据
@@ -226,8 +246,6 @@ public class ApiService {
         return menuData;
     }
 
-
-
     // 新建权限
     public void addPermissions(Map maps) {
         String objectType = maps.get("object_type").toString();
@@ -414,6 +432,49 @@ public class ApiService {
         return retInfo;
     }
 
+    // 添加/编辑api_details表数据
+    public Map saveApi(Map maps, String authorization) {
+        String apiDesc = "";
+        String isEnable = maps.get("is_enable").toString();
+        String apiCode = maps.get("api_code").toString();
+        String apiName = maps.get("api_name").toString();
+        if(maps.containsKey("api_description")) {
+            apiDesc = maps.get("api_description").toString();
+        }
+        // 通过是否存在id,判读是新增还是修改
+        String editId = "";
+        if (maps.containsKey("id")) {
+            editId = maps.get("id").toString();
+        }
+        String createdAt = commonUtil.getNowYYMMDDHHIISS();
+        Map<String, Object> addPagePamars = new HashMap<>();
+        addPagePamars.put("isEnable", isEnable);
+        addPagePamars.put("apiCode", apiCode);
+        addPagePamars.put("apiName", apiName);
+        addPagePamars.put("apiDesc", apiDesc);
+//        Map<String, Object> loginResult = this.userInfo(authorization);
+//        addPagePamars.put("actionUser", loginResult.get("userName")); // 获取当前用户信息
+        if (editId.length()==0) {
+            // 如果不存在说明是新增
+            addPagePamars.put("createdAt", createdAt);
+        }
+        // 添加/编辑
+        Integer pageId = apiDao.saveApiDetails(addPagePamars, editId);
+        Map retInfo = new HashMap<>();
+        if(pageId <= 0){
+            retInfo.put("sysErrorCode", "500");
+        }
+        return retInfo;
+    }
+
+    // 获取api详情
+    public Map apiDetailById(Map params) {
+        String id = params.get("id").toString();
+        Map info = apiDao.getDetailsInfoByIdAndType("api_details", id);
+
+        return info;
+    }
+
     // 转换tree结构数据
     private List<Map<String, Object>> treeMenu(List<Map<String, Object>> renderMenu){
         // 处理的数据存在