Commit 150f4941 by 宋祥

1.角色权限复制功能

parent fa49d08c
...@@ -107,7 +107,7 @@ public class ServiceHGWD003B extends ServiceEPBase { ...@@ -107,7 +107,7 @@ public class ServiceHGWD003B extends ServiceEPBase {
// 已存在的授权用户信息 // 已存在的授权用户信息
List<HGWD003> dbWd003s = dbWd003Map == null ? null : dbWd003Map.get(fileId); List<HGWD003> dbWd003s = dbWd003Map == null ? null : dbWd003Map.get(fileId);
List<String> userIds = CollectionUtils.isEmpty(dbWd003s) ? new ArrayList<>() List<String> userIds = CollectionUtils.isEmpty(dbWd003s) ? new ArrayList<>()
: dbWd003Map.get(fileId).stream().map(HGWD003::getUserId).collect(Collectors.toList()); : dbWd003s.stream().map(HGWD003::getUserId).collect(Collectors.toList());
// 过滤出未授权的用户,并重新赋值FILE_ID // 过滤出未授权的用户,并重新赋值FILE_ID
List<HGWD003> filterWd003s = dbMainWd003s.stream() List<HGWD003> filterWd003s = dbMainWd003s.stream()
.filter(dbMainWd003 -> !userIds.contains(dbMainWd003.getUserId())) .filter(dbMainWd003 -> !userIds.contains(dbMainWd003.getUserId()))
......
package com.baosight.xservices.xs.service;
import com.baosight.hggp.aspect.annotation.OperationLogAnnotation;
import com.baosight.hggp.core.constant.CommonConstant;
import com.baosight.hggp.core.dao.DaoUtils;
import com.baosight.hggp.core.security.UserSessionUtils;
import com.baosight.hggp.hg.wd.domain.HGWD001;
import com.baosight.hggp.hg.wd.domain.HGWD003;
import com.baosight.hggp.hg.wd.tools.HGWDTools;
import com.baosight.hggp.util.AssertUtils;
import com.baosight.hggp.util.DateUtils;
import com.baosight.hggp.util.EiInfoUtils;
import com.baosight.hggp.util.LogUtils;
import com.baosight.hggp.util.MapUtils;
import com.baosight.hggp.util.ObjectUtils;
import com.baosight.iplat4j.core.ei.EiBlockMeta;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.service.impl.ServiceEPBase;
import com.baosight.xservices.xs.domain.XS02;
import com.baosight.xservices.xs.tools.XsTools;
import com.baosight.xservices.xs.util.LoginUserDetails;
import org.apache.commons.collections.CollectionUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 复制角色权限
*
* @author:songx
* @date:2024/5/9,11:04
*/
public class ServiceXS3201B extends ServiceEPBase {
/**
* 画面初始化
*
* @param inInfo
* @return
*/
@Override
@OperationLogAnnotation(operModul = "文档权限", operType = "查询", operDesc = "初始化")
public EiInfo initLoad(EiInfo inInfo) {
try {
} catch (Exception e) {
LogUtils.setDetailMsg(inInfo, e, "初始化失败");
}
return inInfo;
}
/**
* 查询
*
* @param inInfo
* @return
*/
public EiInfo query(EiInfo inInfo) {
try {
Map queryMap = EiInfoUtils.getFirstRow(inInfo);
// 非超级管理只能看到所属企业的信息 added by songx at 2024-01-16
if (!LoginUserDetails.isUserAdmin(UserSessionUtils.getLoginName())) {
queryMap.put("accountCode", UserSessionUtils.getAccountCode());
}
// 排除自身
queryMap.put("excludeEnames", new String[]{MapUtils.getString(queryMap, "mainGroupEname")});
inInfo = super.query(inInfo, "XS02.query", new XS02());
} catch (Exception e) {
LogUtils.setMsg(inInfo, e, "查询失败");
}
return inInfo;
}
/**
* 确认
*
* @param inInfo
* @return
*/
@OperationLogAnnotation(operModul = "文档权限", operType = "保存", operDesc = "操作")
public EiInfo confirm(EiInfo inInfo) {
try {
Map queryMap = EiInfoUtils.getFirstRow(inInfo);
// 获取Group_ID信息
String mainGroupEname = MapUtils.getString(queryMap, "mainGroupEname");
Map resultMap = XsTools.Xs02.getGroup(mainGroupEname);
AssertUtils.isEmpty(resultMap, String.format("【%s】角色不存在", mainGroupEname));
// 获取Group_ID授权信息
List<Map> dbMainAuths = XsTools.Xs07.listBySubject(MapUtils.getString(resultMap, "groupId"));
AssertUtils.isEmpty(dbMainAuths, String.format("【%s】角色还未进行授权,请授权后再进行复制", mainGroupEname));
// 复制授权信息
List<Map> fGroupMaps = inInfo.getBlock(EiConstant.resultBlock).getRows();
this.copyAuthUser(fGroupMaps, dbMainAuths);
inInfo.setStatus(EiConstant.STATUS_SUCCESS);
inInfo.setMsg("复制角色权限成功!");
} catch (Exception e) {
LogUtils.setDetailMsg(inInfo, e, "复制角色权限失败");
}
return inInfo;
}
/**
* 复制授权用户
*
* @param fGroupMaps
* @param dbMainAuths
*/
private void copyAuthUser(List<Map> fGroupMaps, List<Map> dbMainAuths) {
List<String> groupIds = ObjectUtils.listKey(fGroupMaps, "groupId");
// 已授权信息
Map<String, List<Map>> dbAuthMap = XsTools.Xs07.mapBySubject(groupIds);
for (String groupId : groupIds) {
// 已存在的授权用户信息
List<Map> dbAuths = dbAuthMap == null ? null : dbAuthMap.get(groupId);
List<String> objectIds = CollectionUtils.isEmpty(dbAuths) ? new ArrayList<>()
: dbAuths.stream().map(item -> item.get("objectId").toString()).collect(Collectors.toList());
// 过滤出未授权的用户,并重新赋值FILE_ID
List<Map> filterAuths = dbMainAuths.stream()
.filter(dbMainAuth -> !objectIds.contains(dbMainAuth.get("objectId")))
.map(dbMainAuth -> {
dbMainAuth.put("subjectId", groupId);
dbMainAuth.put("recCreator", UserSessionUtils.getLoginName());
dbMainAuth.put("recCreateTime", DateUtils.shortDateTime());
dbMainAuth.put("sortIndex", 0);
return dbMainAuth;
}).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(filterAuths)) {
DaoUtils.insertBatch("XS07.insert", filterAuths);
}
}
}
}
...@@ -104,22 +104,26 @@ ...@@ -104,22 +104,26 @@
t1.id = #groupId# t1.id = #groupId#
</isNotEmpty> </isNotEmpty>
<isNotEmpty prepend=" AND " property="groupEname"> <isNotEmpty prepend=" AND " property="groupEname">
t1.group_ename like ('%$groupEname$%') t1.group_ename like '%$groupEname$%'
</isNotEmpty> </isNotEmpty>
<isNotEmpty prepend=" AND " property="groupCname"> <isNotEmpty prepend=" AND " property="groupCname">
t1.group_cname like ('%$groupCname$%') t1.group_cname like '%$groupCname$%'
</isNotEmpty> </isNotEmpty>
<isNotEmpty prepend=" AND " property="groupType"> <isNotEmpty prepend=" AND " property="groupType">
t1.group_type = #groupType# t1.group_type = #groupType#
</isNotEmpty> </isNotEmpty>
<isNotEmpty prepend=" AND " property="manageGroupEname"> <isNotEmpty prepend=" AND " property="manageGroupEname">
t1.manage_group_ename like ('%$manageGroupEname$%') t1.manage_group_ename like '%$manageGroupEname$%'
</isNotEmpty> </isNotEmpty>
<isNotEmpty prepend=" AND " property="accountCode"> <isNotEmpty prepend=" AND " property="accountCode">
t1.account_code = #accountCode# t1.account_code = #accountCode#
</isNotEmpty> </isNotEmpty>
<isNotEmpty prepend=" AND " property="excludeEnames">
t1.group_ename not in <iterate close=")" open="(" conjunction="," property="excludeEnames">#excludeEnames[]#</iterate>
</isNotEmpty>
ORDER BY t1.SORT_INDEX,t1.ID ORDER BY t1.SORT_INDEX,t1.ID
</select> </select>
<select id="queryByManageGroupEname" resultClass="java.util.HashMap"> <select id="queryByManageGroupEname" resultClass="java.util.HashMap">
SELECT SELECT
t1.id as "groupId", t1.id as "groupId",
...@@ -273,6 +277,22 @@ ...@@ -273,6 +277,22 @@
</isNotEmpty> </isNotEmpty>
</select> </select>
<select id="getGroup" resultClass="java.util.HashMap">
SELECT
id as "groupId",
group_ename as "gEname",
group_cname as "gCname"
FROM ${platSchema}.XS_USER_GROUP
where 1=1
<isNotEmpty prepend=" AND " property="groupEname">
group_ename = #groupEname#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="groupCname">
group_cname like '%$groupCname$%'
</isNotEmpty>
ORDER BY SORT_INDEX, ID
</select>
<select id="queryGroup" resultClass="java.util.HashMap"> <select id="queryGroup" resultClass="java.util.HashMap">
SELECT SELECT
id as "groupId", id as "groupId",
......
...@@ -36,6 +36,9 @@ ...@@ -36,6 +36,9 @@
<isNotEmpty prepend=" AND " property="subjectId"> <isNotEmpty prepend=" AND " property="subjectId">
subject_id = #subjectId# subject_id = #subjectId#
</isNotEmpty> </isNotEmpty>
<isNotEmpty prepend=" AND " property="subjectIds">
subject_id in <iterate close=")" open="(" conjunction="," property="subjectIds">#subjectIds[]#</iterate>
</isNotEmpty>
<isNotEmpty prepend=" AND " property="objectId"> <isNotEmpty prepend=" AND " property="objectId">
object_id = #objectId# object_id = #objectId#
</isNotEmpty> </isNotEmpty>
...@@ -846,4 +849,24 @@ ...@@ -846,4 +849,24 @@
SELECT $valueColumn$ as "subjectId" FROM ${platSchema}.$table$ WHERE $conditionColumn$ = #subjectEname# SELECT $valueColumn$ as "subjectId" FROM ${platSchema}.$table$ WHERE $conditionColumn$ = #subjectEname#
</select> </select>
<select id="get" resultClass="java.util.HashMap">
SELECT
SUBJECT_ID AS "subjectId",
SUBJECT_TYPE AS "subjectType",
OBJECT_ID AS "objectId",
OBJECT_TYPE AS "objectType",
OPERATION_TYPE AS "operationType"
FROM ${platSchema}.XS_AUTHORIZATION
WHERE 1=1
<isNotEmpty prepend=" AND " property="subjectId">
subject_id = #subjectId#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="subjectIds">
subject_id in <iterate close=")" open="(" conjunction="," property="subjectIds">#subjectIds[]#</iterate>
</isNotEmpty>
<isNotEmpty prepend=" AND " property="objectId">
object_id = #objectId#
</isNotEmpty>
</select>
</sqlMap> </sqlMap>
package com.baosight.xservices.xs.tools;
import com.baosight.hggp.core.dao.DaoBase;
import com.baosight.hggp.hg.wd.domain.HGWD001;
import com.baosight.hggp.util.AssertUtils;
import org.apache.commons.collections.CollectionUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author:songx
* @date:2024/9/12,16:18
*/
public class XsTools {
/**
* 用户角色
*
* @author:songx
* @date:2024/9/12,16:19
*/
public static class Xs02 {
/**
* @param groupEname
* @return
*/
public static Map getGroup(String groupEname) {
AssertUtils.isEmpty(groupEname, "角色英文名不能为空");
Map queryMap = new HashMap();
queryMap.put("groupEname", groupEname);
List<Map> results = DaoBase.getInstance().query("XS02.getGroup", queryMap);
return CollectionUtils.isEmpty(results) ? null : results.get(0);
}
}
/**
* @author:songx
* @date:2024/9/12,16:28
*/
public static class Xs07 {
/**
* @param subjectId
* @return
*/
public static List<Map> listBySubject(String subjectId) {
AssertUtils.isEmpty(subjectId, "subjectId不能为空");
Map queryMap = new HashMap();
queryMap.put("subjectId", subjectId);
return DaoBase.getInstance().query("XS07.get", queryMap);
}
/**
* @param subjectIds
* @return
*/
public static List<Map> listBySubject(List<String> subjectIds) {
AssertUtils.isEmpty(subjectIds, "subjectId不能为空");
Map queryMap = new HashMap();
queryMap.put("subjectIds", subjectIds);
return DaoBase.getInstance().query("XS07.get", queryMap);
}
/**
* @param subjectIds
* @return
*/
public static Map<String, List<Map>> mapBySubject(List<String> subjectIds) {
List<Map> results = listBySubject(subjectIds);
if (CollectionUtils.isEmpty(results)) {
return null;
}
return results.stream().collect(Collectors.groupingBy(item -> item.get("subjectId").toString()));
}
}
}
...@@ -165,6 +165,8 @@ $(function () { ...@@ -165,6 +165,8 @@ $(function () {
// result4Grid.dataSource.page(1); // result4Grid.dataSource.page(1);
result5Grid.dataSource.page(1); result5Grid.dataSource.page(1);
}) })
// 打开复制权限页面
$("#COPY_3").on("click", copyAuth);
}, },
onSave: (e) => { onSave: (e) => {
if (resultGrid?.getCheckedRows()?.length === 1 && resultGrid?.getCheckedRows()[0].id !== lastUserGroupId) { if (resultGrid?.getCheckedRows()?.length === 1 && resultGrid?.getCheckedRows()[0].id !== lastUserGroupId) {
...@@ -402,6 +404,38 @@ const authImpl = (grid, operation = "ACCESS", objectType = "RESOURCE_GROUP") => ...@@ -402,6 +404,38 @@ const authImpl = (grid, operation = "ACCESS", objectType = "RESOURCE_GROUP") =>
$("#authWindow").data("kendoWindow").close(); $("#authWindow").data("kendoWindow").close();
} }
/**
* 复制角色权限
*/
const copyAuth = function () {
let checkRows = resultGrid.getCheckedRows();
if (checkRows.length < 1) {
IPLAT.alert("请在角色列表中勾选一行数据");
return;
}
let groupCname = checkRows[0].groupCname;
let params = {
"inqu_status-0-mainGroupEname": checkRows[0].groupEname
}
JSColorbox.open({
href: "XS3201B",
title: "<div style='text-align: center;'>正在复制:【" + groupCname + "】的菜单权限...</div>",
width: "70%",
height: "80%",
params: params,
callbackName: copyAuthCallback
});
}
/**
* 复制授权回调
*
* @param res
*/
const copyAuthCallback = function (res) {
}
let resultGridHeight; let resultGridHeight;
window.onload = () => { window.onload = () => {
const tab_Strip = $("#resourceTab").data("kendoTabStrip"); const tab_Strip = $("#resourceTab").data("kendoTabStrip");
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
<%-- </EF:EFRegion>--%> <%-- </EF:EFRegion>--%>
<%-- <EF:EFRegion id="userGroupTable" title="用户组信息" style="overflow-y:auto">--%> <%-- <EF:EFRegion id="userGroupTable" title="用户组信息" style="overflow-y:auto">--%>
<div style="margin-bottom: 0px"> <div style="margin-bottom: 0px">
<EF:EFGrid blockId="result" autoDraw="no" serviceName="XS02" personal="true" checkMode="single"> <EF:EFGrid blockId="result" autoDraw="no" serviceName="XS02" personal="true" checkMode="row,single">
<EF:EFColumn ename="groupId" cname="用户群组ID" readonly="false" hidden="true" <EF:EFColumn ename="groupId" cname="用户群组ID" readonly="false" hidden="true"
primaryKey="true"/> primaryKey="true"/>
<EF:EFColumn ename="groupEname" cname="角色英文名" style="text-align:left;" readonly="true" <EF:EFColumn ename="groupEname" cname="角色英文名" style="text-align:left;" readonly="true"
......
$(function () {
IPLATUI.EFGrid = {
"result": {
exportGrid: false, // 隐藏右侧自定义导出按钮
pageable: {
pageSize: 20,
pageSizes: [20, 50, 100, 150],
},
loadComplete: function (grid) {
}
}
}
// 查询
$("#QUERY").on("click", query);
// 确认
$("#CONFIRM").on("click", confirm);
});
/**
* 页面加载
*/
$(window).load(function () {
// 查询
query();
});
/**
* 查询
*/
let query = function () {
resultGrid.dataSource.page(1);
}
/**
* 确认
*/
let confirm = function () {
let rows = resultGrid.getCheckedRows();
if (rows.length < 1) {
message("请选择数据");
return;
}
JSUtils.confirm("确定对勾选中的[" + rows.length + "]条数据做\"复制\"操作? ", {
ok: function () {
JSUtils.submitGridsData("result", "XS3201B", "confirm",
false, function (res) {
message(res.msg);
if (res.status !== -1) {
parent.JSColorbox.setValueCallback(res);
}
}
);
}
});
}
<!DOCTYPE html>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="EF" tagdir="/WEB-INF/tags/EF" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<EF:EFPage title="复制角色授权">
<EF:EFRegion id="inqu" title="查询条件">
<EF:EFInput ename="mainGroupEname" cname="主角色英文名" blockId="inqu_status" row="0" type="hidden"/>
<div class="row">
<EF:EFInput ename="groupEname" cname="角色英文名" blockId="inqu_status" row="0" colWidth="4"/>
<EF:EFInput ename="groupCname" cname="角色中文名" blockId="inqu_status" row="0" colWidth="4"/>
</div>
</EF:EFRegion>
<EF:EFRegion id="result" title="记录集" fitHeight="true">
<EF:EFGrid blockId="result" autoDraw="override" checkMode="row" height="69vh">
<EF:EFColumn ename="groupId" cname="用户群组ID" hidden="true" primaryKey="true"/>
<EF:EFColumn ename="groupEname" cname="角色英文名" enable="false" width="120" align="left"/>
<EF:EFColumn ename="groupCname" cname="角色中文名" enable="false" width="120" align="left"/>
<EF:EFColumn ename="recCreateTime" cname="创建时间" enable="false" width="150" align="center"
editType="datetime" parseFormats="['yyyyMMddHHmmss','yyyy-MM-dd HH:mm:ss']"
dateFormat="yyyy-MM-dd HH:mm:ss" displayType="datetime"/>
</EF:EFGrid>
</EF:EFRegion>
</EF:EFPage>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment