RoleOptionLimit.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package restcontroller.webmanage.role;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.huaweicloud.sdk.meeting.v1.model.SearchQosHistoryMeetingsRequest;
  5. import common.BaseClass;
  6. import common.Controller;
  7. import common.YosException;
  8. import common.annotation.API;
  9. import common.data.*;
  10. import restcontroller.R;
  11. import java.util.ArrayList;
  12. /**
  13. * 用户角色选项权限-sys_role_optionlimit
  14. */
  15. public class RoleOptionLimit extends Controller {
  16. /**
  17. * 构造函数
  18. *
  19. * @param content
  20. */
  21. public RoleOptionLimit(JSONObject content) throws YosException {
  22. super(content);
  23. }
  24. @API(title = "角色选项权限-新增或更新", apiversion = R.ID20231201144302.v1.class)
  25. public String insertOrUpdate() throws YosException {
  26. Long optiontypeid = content.getLongValue("optiontypeid");
  27. Long roleid = content.getLongValue("roleid");
  28. JSONArray values = content.getJSONArray("values");
  29. if (optiontypeid <= 0) {
  30. return getErrReturnObject().setErrMsg("请选择分类项").toString();
  31. }
  32. if (roleid <= 0) {
  33. return getErrReturnObject().setErrMsg("请选择角色").toString();
  34. }
  35. ArrayList<String> sqlList = new ArrayList<>();
  36. for (Object obj : values) {
  37. String value = obj.toString();
  38. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_role_optionlimit");
  39. insertSQL.setUniqueid(createTableID("sys_role_optionlimit"));
  40. insertSQL.setValue("roleid", roleid);
  41. insertSQL.setValue("optiontypeid", optiontypeid);
  42. insertSQL.setValue("value", value);
  43. insertSQL.setWhere("not exists(select 1 from sys_role_optionlimit where roleid=" + roleid + " and optiontypeid=" + optiontypeid + " and value='" + value + "' )");
  44. sqlList.add(insertSQL.getSQL());
  45. }
  46. String deleteSql = "DELETE from sys_role_optionlimit WHERE roleid=" + roleid + " and optiontypeid=" + optiontypeid;
  47. if (values.size() > 0) {
  48. deleteSql = deleteSql + " and value not in " + values;
  49. }
  50. sqlList.add(deleteSql.replace("[", "(").replace("]", ")"));
  51. dbConnect.runSqlUpdate(sqlList);
  52. return detail();
  53. }
  54. @API(title = "角色选项权限-删除", apiversion = R.ID20231201145402.v1.class)
  55. public String delete() throws YosException {
  56. Long optiontypeid = content.getLongValue("optiontypeid");
  57. Long roleid = content.getLongValue("roleid");
  58. String deleteSql = "DELETE from sys_role_optionlimit WHERE optiontypeid = " + optiontypeid + " and roleid=" + roleid + "";
  59. dbConnect.runSqlUpdate(deleteSql);
  60. return getSucReturnObject().toString();
  61. }
  62. @API(title = "角色选项权限-列表", apiversion = R.ID20231201145502.v1.class)
  63. public String list() throws YosException {
  64. Long roleid = content.getLongValue("roleid");
  65. SQLFactory sqlFactory = new SQLFactory(this, "角色选项限制查询列表", pageSize, pageNumber, pageSorting);
  66. sqlFactory.addParameter("siteid", siteid);
  67. sqlFactory.addParameter("roleid", roleid);
  68. Rows rows = sqlFactory.runSqlQuery(dbConnect);
  69. RowsMap optiontypemxMap = new RowsMap();
  70. if (rows.isNotEmpty()) {
  71. String sql = "SELECT distinct optiontypeid,value from sys_optiontypemx WHERE optiontypeid in " + rows.toArrayList("optiontypeid");
  72. optiontypemxMap = dbConnect.runSqlQuery(sql.replace("[", "(").replace("]", ")")).toRowsMap("optiontypeid");
  73. }
  74. for (Row row : rows) {
  75. Rows optiontypemxRows = optiontypemxMap.getOrDefault(row.getString("optiontypeid"), new Rows());
  76. // for (Row optiontypemxRow : optiontypemxRows) {
  77. // optiontypemxRow.putIfAbsent("subvalues", new JSONArray());
  78. // }
  79. // row.put("optiontypemxall", optiontypemxRows);
  80. row.put("optiontypemx", optiontypemxRows.toArray("value"));
  81. Long optiontypeid = row.getLong("optiontypeid");
  82. Rows valuerows = dbConnect.runSqlQuery("SELECT `value` from sys_role_optionlimit WHERE roleid=" + roleid + " and optiontypeid=" + optiontypeid);
  83. row.put("values", valuerows.toArray("value"));
  84. }
  85. return getSucReturnObject().setData(rows).toString();
  86. }
  87. @API(title = "详细", apiversion = R.ID20231201153702.v1.class)
  88. public String detail() throws YosException {
  89. Long optiontypeid = content.getLongValue("optiontypeid");
  90. Long roleid = content.getLongValue("roleid");
  91. SQLFactory sqlFactory = new SQLFactory(this, "角色选项限制查询详情");
  92. sqlFactory.addParameter("siteid", siteid);
  93. sqlFactory.addParameter("optiontypeid", optiontypeid);
  94. sqlFactory.addParameter("roleid", roleid);
  95. Rows rows = sqlFactory.runSqlQuery(dbConnect);
  96. if (rows.isEmpty()) {
  97. return getSucReturnObject().setData(new Row()).toString();
  98. }
  99. String sql = "SELECT distinct optiontypeid,value from sys_optiontypemx WHERE optiontypeid in " + rows.toArrayList("optiontypeid");
  100. RowsMap optiontypemxMap = dbConnect.runSqlQuery(sql.replace("[", "(").replace("]", ")")).toRowsMap("optiontypeid");
  101. for (Row row : rows) {
  102. Rows optiontypemxRows = optiontypemxMap.getOrDefault(row.getString("optiontypeid"), new Rows());
  103. // for (Row optiontypemxRow : optiontypemxRows) {
  104. // optiontypemxRow.putIfAbsent("subvalues", new JSONArray());
  105. // }
  106. // row.put("optiontypemxall", optiontypemxRows);
  107. row.put("optiontypemx", optiontypemxRows.toArray("value"));
  108. Rows valuerows = dbConnect.runSqlQuery("SELECT `value` from sys_role_optionlimit WHERE roleid=" + roleid + " and optiontypeid=" + optiontypeid);
  109. row.put("values", valuerows.toArray("value"));
  110. }
  111. return getSucReturnObject().setData(rows.get(0)).toString();
  112. }
  113. }