|
|
@@ -1,5 +1,6 @@
|
|
|
package restcontroller.sale.role;
|
|
|
|
|
|
+import beans.datacontrllog.DataContrlLog;
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import common.Controller;
|
|
|
@@ -397,4 +398,79 @@ public class role extends Controller {
|
|
|
logroleout(roleid);
|
|
|
return getSucReturnObject().toString();
|
|
|
}
|
|
|
+
|
|
|
+ @API(title = "角色权限复制", apiversion = R.ID2025111810004903.v1.class)
|
|
|
+ @CACHEING_CLEAN(apiClass = role.class)
|
|
|
+ public String copyRole() throws YosException {
|
|
|
+ Long roleid = content.getLongValue("roleid");
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
+ Long roleid_copy = createTableID("sys_role");
|
|
|
+ //查询用户角色
|
|
|
+ Rows rows = dbConnect.runSqlQuery("SELECT * from sys_role WHERE roleid=" + roleid + " and siteid='" + siteid + "'");
|
|
|
+ if (rows.isNotEmpty()) {
|
|
|
+ String rolename = rows.get(0).getString("rolename");
|
|
|
+ String remarks = rows.get(0).getString("remarks");
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "复制_用户角色");
|
|
|
+ sqlFactory.addParameter("roleid", roleid_copy);
|
|
|
+ sqlFactory.addParameter("sys_enterpriseid", rows.get(0).getString("sys_enterpriseid"));
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ sqlFactory.addParameter("rolename", rolename + "(复制)");
|
|
|
+ sqlFactory.addParameter("remarks", remarks);
|
|
|
+ sqlFactory.addParameter("usertype", rows.get(0).getString("usertype"));
|
|
|
+ sqlFactory.addParameter("createby", username);
|
|
|
+ sqlList.add(sqlFactory.getSQL());
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, "sys_role", roleid, "复制角色", "复制角色【" + rolename + "-" + remarks + "】").getSQL());
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, "sys_role", roleid_copy, "复制角色", "由角色【" + rolename + "-" + remarks + "】复制").getSQL());
|
|
|
+ }
|
|
|
+ //报表
|
|
|
+ rows = dbConnect.runSqlQuery("SELECT * from sys_rolereportauth WHERE roleid= " + roleid);
|
|
|
+ for (Row row : rows) {
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "复制_报表");
|
|
|
+ sqlFactory.addParameter("roleid", roleid_copy);
|
|
|
+ sqlFactory.addParameter("sys_rolereportauthid", createTableID("sys_rolereportauth"));
|
|
|
+ sqlFactory.addParameter("sys_reportid", row.getString("sys_reportid"));
|
|
|
+ sqlList.add(sqlFactory.getSQL());
|
|
|
+ }
|
|
|
+// //用户角色授权
|
|
|
+// rows = dbConnect.runSqlQuery("SELECT * from sys_userrole WHERE roleid=" + roleid + " and siteid='" + siteid + "'");
|
|
|
+// for (Row row : rows) {
|
|
|
+// SQLFactory sqlFactory = new SQLFactory(this, "复制_角色授权");
|
|
|
+// sqlFactory.addParameter("roleid", roleid_copy);
|
|
|
+// sqlFactory.addParameter("userroleid", createTableID("sys_userrole"));
|
|
|
+// sqlFactory.addParameter("siteid", siteid);
|
|
|
+// sqlFactory.addParameter("userid", row.getString("userid"));
|
|
|
+// sqlFactory.addParameter("username", username);
|
|
|
+// sqlFactory.addParameter("changeuserid", userid);
|
|
|
+// sqlList.add(sqlFactory.getSQL());
|
|
|
+// }
|
|
|
+ //数据过滤
|
|
|
+ rows = dbConnect.runSqlQuery("SELECT * from sys_role_datalimit WHERE roleid=" + roleid);
|
|
|
+ for (Row row : rows) {
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "复制_数据过滤");
|
|
|
+ sqlFactory.addParameter("roleid", roleid_copy);
|
|
|
+ sqlFactory.addParameter("sys_role_datalimitid", createTableID("sys_role_datalimit"));
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ sqlFactory.addParameter("userid", userid);
|
|
|
+ sqlFactory.addParameter("username", username);
|
|
|
+ sqlFactory.addParameter("table_name", row.getString("table_name"));
|
|
|
+ //去除特殊字符,防止sql注入
|
|
|
+ sqlFactory.addParameter("sqlstr", row.getString("sqlstr").replace("'", "\\'"));
|
|
|
+ sqlList.add(sqlFactory.getSQL());
|
|
|
+ }
|
|
|
+ //应用功能授
|
|
|
+ rows = dbConnect.runSqlQuery("SELECT * from sys_roleappoptionauth WHERE roleid=" + roleid);
|
|
|
+ for (Row row : rows) {
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "复制_应用功能授");
|
|
|
+ sqlFactory.addParameter("roleid", roleid_copy);
|
|
|
+ sqlFactory.addParameter("optionauthid", createTableID("sys_roleappoptionauth"));
|
|
|
+ sqlFactory.addParameter("systemappid", row.getString("systemappid"));
|
|
|
+ sqlFactory.addParameter("optionid", row.getString("optionid"));
|
|
|
+ sqlFactory.addParameter("changeuserid", userid);
|
|
|
+ sqlList.add(sqlFactory.getSQL());
|
|
|
+ }
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ object.put("roleid", roleid_copy);
|
|
|
+ return getSucReturnObject().setData(object).toString();
|
|
|
+ }
|
|
|
}
|