From 9cc9dff1a5f81ce7db0c39d9f0637571c8c20253 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Tue, 30 Aug 2022 18:24:10 +0800 Subject: [PATCH] =?UTF-8?q?perf(=E7=B3=BB=E7=BB=9F=E7=AE=A1=E7=90=86-?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E7=AE=A1=E7=90=86):=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=A7=92=E8=89=B2=E7=BB=84=E7=BB=87=E7=BB=91=E5=AE=9A=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commons/constants/SysLogConstants.java | 6 +++++- .../io/dataease/commons/utils/DeLogUtils.java | 18 ++++++++++++++++++ .../dataease/plugins/server/XDeptServer.java | 6 ++++++ .../dataease/plugins/server/XRoleServer.java | 10 +++++++++- .../dataease/service/sys/log/LogService.java | 7 +++++++ .../resources/i18n/messages_en_US.properties | 2 ++ .../resources/i18n/messages_zh_CN.properties | 2 ++ .../resources/i18n/messages_zh_TW.properties | 2 ++ 8 files changed, 51 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/io/dataease/commons/constants/SysLogConstants.java b/backend/src/main/java/io/dataease/commons/constants/SysLogConstants.java index dd1508ef07..9a6489ddc8 100644 --- a/backend/src/main/java/io/dataease/commons/constants/SysLogConstants.java +++ b/backend/src/main/java/io/dataease/commons/constants/SysLogConstants.java @@ -30,7 +30,11 @@ public class SysLogConstants { MB_VIEW(14, "OPERATE_TYPE_MB_VIEW"), - EXPORT(15, "OPERATE_TYPE_EXPORT"); + EXPORT(15, "OPERATE_TYPE_EXPORT"), + + BIND(16, "OPERATE_TYPE_BIND"), + + UNBIND(17, "OPERATE_TYPE_UNBIND"); private Integer value; private String name; OPERATE_TYPE(Integer value, String name) { diff --git a/backend/src/main/java/io/dataease/commons/utils/DeLogUtils.java b/backend/src/main/java/io/dataease/commons/utils/DeLogUtils.java index 2ae2dc8fb4..d996a2d7f4 100644 --- a/backend/src/main/java/io/dataease/commons/utils/DeLogUtils.java +++ b/backend/src/main/java/io/dataease/commons/utils/DeLogUtils.java @@ -48,6 +48,24 @@ public class DeLogUtils { return sysLogDTO; } + + public static SysLogDTO buildBindRoleUserLog(Long positionId, Long userId, OPERATE_TYPE operatetype, SOURCE_TYPE positionType) { + SysLogDTO sysLogDTO = new SysLogDTO(); + sysLogDTO.setOperateType(operatetype.getValue()); + sysLogDTO.setSourceType(SOURCE_TYPE.USER.getValue()); + sysLogDTO.setSourceId(userId.toString()); + FolderItem sourceInfo = logManager.nameWithId(userId.toString(), SOURCE_TYPE.USER.getValue()); + if (ObjectUtils.isEmpty(sourceInfo)) { + return null; + } + sysLogDTO.setSourceName(sourceInfo.getName()); + + List parentsAndSelf = logManager.parentsAndSelf(positionId.toString(), positionType); + sysLogDTO.setPositions(parentsAndSelf); + + return sysLogDTO; + } + public static SysLogDTO buildLog(OPERATE_TYPE operatetype, SOURCE_TYPE sourcetype, Object sourceIdValue, Object positionId, Object targetId, SOURCE_TYPE target_type ) { SysLogDTO sysLogDTO = new SysLogDTO(); sysLogDTO.setOperateType(operatetype.getValue()); diff --git a/backend/src/main/java/io/dataease/plugins/server/XDeptServer.java b/backend/src/main/java/io/dataease/plugins/server/XDeptServer.java index 5fcb242b89..54e0282fa8 100644 --- a/backend/src/main/java/io/dataease/plugins/server/XDeptServer.java +++ b/backend/src/main/java/io/dataease/plugins/server/XDeptServer.java @@ -10,9 +10,11 @@ import io.dataease.commons.constants.AuthConstants; import io.dataease.commons.constants.SysLogConstants; import io.dataease.commons.exception.DEException; import io.dataease.commons.utils.BeanUtils; +import io.dataease.commons.utils.DeLogUtils; import io.dataease.commons.utils.PageUtils; import io.dataease.commons.utils.Pager; import io.dataease.controller.sys.response.DeptNodeResponse; +import io.dataease.dto.SysLogDTO; import io.dataease.listener.util.CacheUtils; import io.dataease.plugins.common.entity.XpackGridRequest; import io.dataease.plugins.config.SpringContextUtil; @@ -163,6 +165,8 @@ public class XDeptServer { public void bindUser(@RequestBody XpackDeptBindRequest request) { DeptXpackService deptService = SpringContextUtil.getBean(DeptXpackService.class); request.getUserIds().forEach(userId -> { + SysLogDTO sysLogDTO = DeLogUtils.buildBindRoleUserLog(request.getDeptId(), userId, SysLogConstants.OPERATE_TYPE.BIND, SysLogConstants.SOURCE_TYPE.DEPT); + DeLogUtils.save(sysLogDTO); CacheUtils.remove( AuthConstants.USER_CACHE_NAME, "user" + userId); }); deptService.bindUser(request); @@ -176,6 +180,8 @@ public class XDeptServer { DEException.throwException("userIds can not be empty"); } request.getUserIds().forEach(userId -> { + SysLogDTO sysLogDTO = DeLogUtils.buildBindRoleUserLog(request.getDeptId(), userId, SysLogConstants.OPERATE_TYPE.UNBIND, SysLogConstants.SOURCE_TYPE.DEPT); + DeLogUtils.save(sysLogDTO); CacheUtils.remove( AuthConstants.USER_CACHE_NAME, "user" + userId); }); deptService.unBindUsers(request); diff --git a/backend/src/main/java/io/dataease/plugins/server/XRoleServer.java b/backend/src/main/java/io/dataease/plugins/server/XRoleServer.java index 4cf3741a96..c9ed08f3a5 100644 --- a/backend/src/main/java/io/dataease/plugins/server/XRoleServer.java +++ b/backend/src/main/java/io/dataease/plugins/server/XRoleServer.java @@ -7,8 +7,10 @@ import io.dataease.auth.annotation.DeLog; import io.dataease.auth.service.ExtAuthService; import io.dataease.commons.constants.AuthConstants; import io.dataease.commons.constants.SysLogConstants; +import io.dataease.commons.utils.DeLogUtils; import io.dataease.commons.utils.PageUtils; import io.dataease.commons.utils.Pager; +import io.dataease.dto.SysLogDTO; import io.dataease.listener.util.CacheUtils; import io.dataease.plugins.common.entity.XpackGridRequest; import io.dataease.plugins.config.SpringContextUtil; @@ -25,7 +27,8 @@ import io.swagger.annotations.ApiOperation; import org.apache.commons.collections4.CollectionUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cache.annotation.CacheEvict; +import static io.dataease.commons.constants.SysLogConstants.OPERATE_TYPE; +import static io.dataease.commons.constants.SysLogConstants.SOURCE_TYPE; import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; @@ -124,10 +127,13 @@ public class XRoleServer { RoleXpackService roleXpackService = SpringContextUtil.getBean(RoleXpackService.class); if (CollectionUtils.isNotEmpty(request.getUserIds())) { request.getUserIds().forEach(userId -> { + SysLogDTO sysLogDTO = DeLogUtils.buildBindRoleUserLog(request.getRoleId(), userId, OPERATE_TYPE.BIND, SOURCE_TYPE.ROLE); + DeLogUtils.save(sysLogDTO); CacheUtils.remove( AuthConstants.USER_CACHE_NAME, "user" + userId); }); } roleXpackService.addUser(request); + } @RequiresPermissions({"role:edit", "user:edit"}) @@ -137,6 +143,8 @@ public class XRoleServer { RoleXpackService roleXpackService = SpringContextUtil.getBean(RoleXpackService.class); if (CollectionUtils.isNotEmpty(request.getUserIds())) { request.getUserIds().forEach(userId -> { + SysLogDTO sysLogDTO = DeLogUtils.buildBindRoleUserLog(request.getRoleId(), userId, OPERATE_TYPE.UNBIND, SOURCE_TYPE.ROLE); + DeLogUtils.save(sysLogDTO); CacheUtils.remove( AuthConstants.USER_CACHE_NAME, "user" + userId); }); } diff --git a/backend/src/main/java/io/dataease/service/sys/log/LogService.java b/backend/src/main/java/io/dataease/service/sys/log/LogService.java index 4a92767f15..6e8d0bb4ca 100644 --- a/backend/src/main/java/io/dataease/service/sys/log/LogService.java +++ b/backend/src/main/java/io/dataease/service/sys/log/LogService.java @@ -193,6 +193,7 @@ public class LogService { List folderItems = viewPanelTypes(); results.addAll(folderItems); results.addAll(viewRelativeTypes()); + results.addAll(bindUserTypes()); return results; } @@ -227,6 +228,12 @@ public class LogService { return typesByArr(opTypes, sourceTypes); } + private List bindUserTypes() { + Integer[] opTypes = new Integer[]{16, 17}; + Integer[] sourceTypes = new Integer[]{6}; + return typesByArr(opTypes, sourceTypes); + } + public SysLogGridDTO convertDTO(SysLogWithBLOBs vo) { SysLogGridDTO sysLogGridDTO = new SysLogGridDTO(); sysLogGridDTO.setOpType(SysLogConstants.operateTypeName(vo.getOperateType())); diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index 965bd17c7c..7c0b0aa244 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -144,6 +144,8 @@ OPERATE_TYPE_LOGIN=Login OPERATE_TYPE_PC_VIEW=View with pc OPERATE_TYPE_MB_VIEW=View with mobile device OPERATE_TYPE_EXPORT=Export +OPERATE_TYPE_BIND=Bind +OPERATE_TYPE_UNBIND=Unbind I18N_USER_TEMPLATE_ERROR=Template file error SOURCE_TYPE_DATASOURCE=DATASOURCE SOURCE_TYPE_DATASET=DATASET diff --git a/backend/src/main/resources/i18n/messages_zh_CN.properties b/backend/src/main/resources/i18n/messages_zh_CN.properties index 49316a7434..905da1a1db 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -144,6 +144,8 @@ OPERATE_TYPE_LOGIN=\u767B\u5F55 OPERATE_TYPE_PC_VIEW=\u4F7F\u7528PC\u67E5\u770B OPERATE_TYPE_MB_VIEW=\u4F7F\u7528\u79FB\u52A8\u7AEF\u67E5\u770B OPERATE_TYPE_EXPORT=\u5BFC\u51FA +OPERATE_TYPE_BIND=\u7ED1\u5B9A +OPERATE_TYPE_UNBIND=\u89E3\u7ED1 I18N_USER_TEMPLATE_ERROR=\u7528\u6237\u6A21\u7248\u9519\u8BEF SOURCE_TYPE_DATASOURCE=\u6570\u636E\u6E90 SOURCE_TYPE_DATASET=\u6570\u636E\u96C6 diff --git a/backend/src/main/resources/i18n/messages_zh_TW.properties b/backend/src/main/resources/i18n/messages_zh_TW.properties index c08d222579..24144d33ba 100644 --- a/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -144,6 +144,8 @@ OPERATE_TYPE_LOGIN=\u767B\u9304 OPERATE_TYPE_PC_VIEW=\u4F7F\u7528PC\u67E5\u770B OPERATE_TYPE_MB_VIEW=\u4F7F\u7528\u79FB\u52D5\u7AEF\u67E5\u770B OPERATE_TYPE_EXPORT=\u5C0E\u51FA +OPERATE_TYPE_BIND=\u7D81\u5B9A +OPERATE_TYPE_UNBIND=\u89E3\u7D81 I18N_USER_TEMPLATE_ERROR=\u7528\u6236\u6A21\u7248\u932F\u8AA4 SOURCE_TYPE_DATASOURCE=\u6578\u64DA\u6E90 SOURCE_TYPE_DATASET=\u6578\u64DA\u96C6