소스 검색

用户角色选项权限

eganwu 1 년 전
부모
커밋
a92161cbc5

BIN
out/artifacts/yos/yos.war


+ 16 - 0
src/custom/restcontroller/R.java

@@ -5354,6 +5354,22 @@ public class R {
         public static class v1 {
         }
     }
+    public static class ID20231201144302 {
+        public static class v1 {
+        }
+    }
+    public static class ID20231201145402 {
+        public static class v1 {
+        }
+    }
+    public static class ID20231201145502 {
+        public static class v1 {
+        }
+    }
+    public static class ID20231201153702 {
+        public static class v1 {
+        }
+    }
 
 }
 

+ 141 - 0
src/custom/restcontroller/webmanage/role/RoleOptionLimit.java

@@ -0,0 +1,141 @@
+package restcontroller.webmanage.role;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import common.Controller;
+import common.YosException;
+import common.annotation.API;
+import common.data.*;
+import restcontroller.R;
+
+import java.util.ArrayList;
+
+/**
+ * 用户角色选项权限-sys_role_optionlimit
+ */
+public class RoleOptionLimit extends Controller {
+    /**
+     * 构造函数
+     *
+     * @param content
+     */
+    public RoleOptionLimit(JSONObject content) throws YosException {
+        super(content);
+    }
+
+    @API(title = "角色选项权限-新增或更新", apiversion = R.ID20231201144302.v1.class)
+    public String insertOrUpdate() throws YosException {
+
+        Long optiontypeid = content.getLongValue("optiontypeid");
+        Long roleid = content.getLongValue("roleid");
+        JSONArray values = content.getJSONArray("values");
+
+        if (optiontypeid <= 0) {
+            return getErrReturnObject().setErrMsg("请选择分类项").toString();
+        }
+        if (roleid <= 0) {
+            return getErrReturnObject().setErrMsg("请选择角色").toString();
+        }
+
+        ArrayList<String> sqlList = new ArrayList<>();
+
+        for (Object obj : values) {
+            String value = obj.toString();
+            InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_role_optionlimit");
+            insertSQL.setUniqueid(createTableID("sys_role_optionlimit"));
+            insertSQL.setValue("roleid", roleid);
+            insertSQL.setValue("optiontypeid", optiontypeid);
+            insertSQL.setValue("value", value);
+            insertSQL.setWhere("not exists(select 1 from  sys_role_optionlimit where roleid=" + roleid + " and optiontypeid=" + optiontypeid + " and value='" + value + "' )");
+            sqlList.add(insertSQL.getSQL());
+        }
+        String deleteSql = "DELETE from sys_role_optionlimit WHERE roleid=" + roleid + " and optiontypeid=" + optiontypeid;
+        if (values.size() > 0) {
+            deleteSql = deleteSql + " and value not in " + values;
+        }
+        sqlList.add(deleteSql.replace("[", "(").replace("]", ")"));
+
+        dbConnect.runSqlUpdate(sqlList);
+
+
+        return detail();
+    }
+
+    @API(title = "角色选项权限-删除", apiversion = R.ID20231201145402.v1.class)
+    public String delete() throws YosException {
+
+        Long optiontypeid = content.getLongValue("optiontypeid");
+        Long roleid = content.getLongValue("roleid");
+        String deleteSql = "DELETE from sys_role_optionlimit WHERE optiontypeid = " + optiontypeid + " and roleid=" + roleid + "";
+        dbConnect.runSqlUpdate(deleteSql);
+
+
+        return getSucReturnObject().toString();
+    }
+
+    @API(title = "角色选项权限-列表", apiversion = R.ID20231201145502.v1.class)
+    public String list() throws YosException {
+        Long roleid = content.getLongValue("roleid");
+
+        SQLFactory sqlFactory = new SQLFactory(this, "角色选项限制查询列表", pageSize, pageNumber, pageSorting);
+        sqlFactory.addParameter("siteid", siteid);
+        sqlFactory.addParameter("roleid", roleid);
+        Rows rows = sqlFactory.runSqlQuery(dbConnect);
+
+        RowsMap optiontypemxMap = new RowsMap();
+
+        if (rows.isNotEmpty()) {
+            String sql = "SELECT distinct optiontypeid,value from sys_optiontypemx WHERE optiontypeid in " + rows.toArrayList("optiontypeid");
+            optiontypemxMap = dbConnect.runSqlQuery(sql.replace("[", "(").replace("]", ")")).toRowsMap("optiontypeid");
+        }
+
+        for (Row row : rows) {
+            Rows optiontypemxRows = optiontypemxMap.getOrDefault(row.getString("optiontypeid"), new Rows());
+//            for (Row optiontypemxRow : optiontypemxRows) {
+//                optiontypemxRow.putIfAbsent("subvalues", new JSONArray());
+//            }
+
+//            row.put("optiontypemxall", optiontypemxRows);
+            row.put("optiontypemx", optiontypemxRows.toArray("value"));
+            Long optiontypeid = row.getLong("optiontypeid");
+            Rows valuerows = dbConnect.runSqlQuery("SELECT `value` from sys_role_optionlimit WHERE roleid=" + roleid + " and optiontypeid=" + optiontypeid);
+            row.put("values", valuerows.toArray("value"));
+        }
+
+
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+    @API(title = "详细", apiversion = R.ID20231201153702.v1.class)
+    public String detail() throws YosException {
+        Long optiontypeid = content.getLongValue("optiontypeid");
+        Long roleid = content.getLongValue("roleid");
+
+        SQLFactory sqlFactory = new SQLFactory(this, "角色选项限制查询详情");
+        sqlFactory.addParameter("siteid", siteid);
+        sqlFactory.addParameter("optiontypeid", optiontypeid);
+        sqlFactory.addParameter("roleid", roleid);
+        Rows rows = sqlFactory.runSqlQuery(dbConnect);
+        if (rows.isEmpty()) {
+            return getSucReturnObject().setData(new Row()).toString();
+        }
+
+        String sql = "SELECT distinct optiontypeid,value from sys_optiontypemx WHERE optiontypeid in " + rows.toArrayList("optiontypeid");
+        RowsMap optiontypemxMap = dbConnect.runSqlQuery(sql.replace("[", "(").replace("]", ")")).toRowsMap("optiontypeid");
+
+        for (Row row : rows) {
+            Rows optiontypemxRows = optiontypemxMap.getOrDefault(row.getString("optiontypeid"), new Rows());
+//            for (Row optiontypemxRow : optiontypemxRows) {
+//                optiontypemxRow.putIfAbsent("subvalues", new JSONArray());
+//            }
+//            row.put("optiontypemxall", optiontypemxRows);
+            row.put("optiontypemx", optiontypemxRows.toArray("value"));
+
+            Rows valuerows = dbConnect.runSqlQuery("SELECT `value` from sys_role_optionlimit WHERE roleid=" + roleid + " and optiontypeid=" + optiontypeid);
+            row.put("values", valuerows.toArray("value"));
+        }
+
+
+        return getSucReturnObject().setData(rows.get(0)).toString();
+    }
+}

+ 9 - 0
src/custom/restcontroller/webmanage/role/SQL/角色选项限制查询列表.sql

@@ -0,0 +1,9 @@
+SELECT t1.*
+from (
+         SELECT DISTINCT t1.roleid, t1.optiontypeid, t2.remarks optionttypename, t3.rolename
+         from sys_role_optionlimit t1
+                  LEFT JOIN sys_optiontype t2 ON t2.optiontypeid = t1.optiontypeid
+                  LEFT JOIN sys_role t3 ON t3.roleid = t1.roleid
+         where t3.siteid = $siteid$
+           and t1.roleid = $roleid$
+     ) t1

+ 7 - 0
src/custom/restcontroller/webmanage/role/SQL/角色选项限制查询详情.sql

@@ -0,0 +1,7 @@
+SELECT DISTINCT t1.roleid, t1.optiontypeid, t2.remarks optionttypename, t3.rolename
+from sys_role_optionlimit t1
+         LEFT JOIN sys_optiontype t2 ON t2.optiontypeid = t1.optiontypeid
+         LEFT JOIN sys_role t3 ON t3.roleid = t1.roleid
+where t3.siteid = $siteid$
+  and t1.roleid = $roleid$
+  and t1.optiontypeid = $optiontypeid$