Merge pull request #2997 from dataease/pr@dev@perf_log

perf(系统管理-日志管理): 增加角色组织绑定用户日志
This commit is contained in:
fit2cloud-chenyw 2022-08-30 18:25:08 +08:00 committed by GitHub
commit ce2a8f8d6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 51 additions and 2 deletions

View File

@ -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) {

View File

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

View File

@ -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);

View File

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

View File

@ -193,6 +193,7 @@ public class LogService {
List<FolderItem> 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<FolderItem> 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()));

View File

@ -145,6 +145,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

View File

@ -145,6 +145,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

View File

@ -145,6 +145,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