|
@@ -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();
|
|
|
+ }
|
|
|
+}
|