forked from github/dataease
feat: 操作日志
This commit is contained in:
parent
57961f6ca9
commit
f0f5813071
34
backend/src/main/java/io/dataease/auth/annotation/DeLog.java
Normal file
34
backend/src/main/java/io/dataease/auth/annotation/DeLog.java
Normal file
@ -0,0 +1,34 @@
|
||||
package io.dataease.auth.annotation;
|
||||
|
||||
import io.dataease.commons.constants.SysLogConstants.OPERATE_TYPE;
|
||||
import io.dataease.commons.constants.SysLogConstants.SOURCE_TYPE;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ ElementType.TYPE, ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface DeLog {
|
||||
|
||||
OPERATE_TYPE operatetype();
|
||||
|
||||
|
||||
SOURCE_TYPE sourcetype();
|
||||
|
||||
|
||||
int positionIndex() default -1;
|
||||
String positionKey() default "";
|
||||
|
||||
|
||||
int sourceIndex() default 0;
|
||||
String sourceKey() default "";
|
||||
|
||||
int targetIndex() default -1;
|
||||
String targetKey() default "";
|
||||
SOURCE_TYPE targetType() default SOURCE_TYPE.USER;
|
||||
|
||||
String value() default "";
|
||||
|
||||
}
|
@ -2,10 +2,10 @@ package io.dataease.auth.aop;
|
||||
|
||||
import io.dataease.auth.annotation.DeCleaner;
|
||||
import io.dataease.auth.api.dto.CurrentUserDto;
|
||||
import io.dataease.auth.util.ReflectUtil;
|
||||
import io.dataease.commons.constants.AuthConstants;
|
||||
import io.dataease.commons.constants.DePermissionType;
|
||||
import io.dataease.commons.model.AuthURD;
|
||||
import io.dataease.commons.utils.AopUtils;
|
||||
import io.dataease.commons.utils.AuthUtils;
|
||||
import io.dataease.commons.utils.LogUtil;
|
||||
import io.dataease.listener.util.CacheUtils;
|
||||
@ -19,11 +19,8 @@ import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Aspect
|
||||
@ -43,7 +40,7 @@ public class DeCleanerAnnotationHandler {
|
||||
if (ObjectUtils.isNotEmpty(key) && ArrayUtils.isNotEmpty(args)) {
|
||||
int pi = deCleaner.paramIndex();
|
||||
Object arg = point.getArgs()[pi];
|
||||
paramValue = getParamValue(arg, key, 0);
|
||||
paramValue = AopUtils.getParamValue(arg, key, 0);
|
||||
}
|
||||
|
||||
switch (type.name()) {
|
||||
@ -136,44 +133,5 @@ public class DeCleanerAnnotationHandler {
|
||||
});
|
||||
}
|
||||
|
||||
private Object getParamValue(Object arg, String key, int layer) throws Exception{
|
||||
if (ObjectUtils.isNotEmpty(arg)) return null;
|
||||
Class<?> parameterType = arg.getClass();
|
||||
if (parameterType.isPrimitive() || ReflectUtil.isWrapClass(parameterType) || ReflectUtil.isString(parameterType)) {
|
||||
return arg;
|
||||
} else if (ReflectUtil.isArray(parameterType)) {
|
||||
Object result;
|
||||
for (int i = 0; i < Array.getLength(arg); i++) {
|
||||
Object o = Array.get(arg, i);
|
||||
|
||||
if (ObjectUtils.isNotEmpty((result = getParamValue(o, key, layer)))) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} else if (ReflectUtil.isCollection(parameterType)) {
|
||||
Object[] array = ((Collection) arg).toArray();
|
||||
Object result;
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
Object o = array[i];
|
||||
if (ObjectUtils.isNotEmpty((result = getParamValue(o, key, layer)))) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} else if (ReflectUtil.isMap(parameterType)) {
|
||||
Map<String, Object> argMap = (Map) arg;
|
||||
String[] values = key.split("\\.");
|
||||
Object o = argMap.get(values[layer]);
|
||||
return getParamValue(o, key, ++layer);
|
||||
} else {
|
||||
// 当作自定义类处理
|
||||
String[] values = key.split("\\.");
|
||||
String fieldName = values[layer];
|
||||
|
||||
Object fieldValue = ReflectUtil.getFieldValue(arg, values[layer]);
|
||||
return getParamValue(fieldValue, key, ++layer);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,143 @@
|
||||
package io.dataease.auth.aop;
|
||||
|
||||
|
||||
import io.dataease.auth.annotation.DeLog;
|
||||
import io.dataease.commons.constants.SysLogConstants;
|
||||
import io.dataease.commons.utils.AopUtils;
|
||||
import io.dataease.controller.ResultHolder;
|
||||
import io.dataease.dto.SysLogDTO;
|
||||
import io.dataease.dto.log.FolderItem;
|
||||
import io.dataease.service.sys.log.LogManager;
|
||||
import io.dataease.service.sys.log.LogService;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
public class DeLogAnnotationHandler {
|
||||
|
||||
@Resource
|
||||
private LogManager logManager;
|
||||
|
||||
@Resource
|
||||
private LogService logService;
|
||||
|
||||
private static List<Integer> befores = new ArrayList<>();
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
befores.add(SysLogConstants.OPERATE_TYPE.DELETE.getValue());
|
||||
befores.add(SysLogConstants.OPERATE_TYPE.UNSHARE.getValue());
|
||||
befores.add(SysLogConstants.OPERATE_TYPE.UNAUTHORIZE.getValue());
|
||||
}
|
||||
|
||||
private SysLogDTO exec(JoinPoint point, DeLog deLog) throws Exception{
|
||||
|
||||
Object[] args = point.getArgs();
|
||||
if (ArrayUtils.isEmpty(args)) return null;
|
||||
|
||||
SysLogConstants.OPERATE_TYPE operatetype = deLog.operatetype();
|
||||
SysLogConstants.SOURCE_TYPE sourcetype = deLog.sourcetype();
|
||||
|
||||
String sourceKey = StringUtils.isNotBlank(deLog.sourceKey()) ? deLog.sourceKey() : deLog.value();
|
||||
int sourceIndex = deLog.sourceIndex();
|
||||
if (args.length <= sourceIndex) return null;
|
||||
Object arg = args[sourceIndex];
|
||||
Object sourceIdValue = AopUtils.getParamValue(arg, sourceKey, 0);
|
||||
if (ObjectUtils.isEmpty(sourceIdValue)) return null;
|
||||
|
||||
SysLogDTO sysLogDTO = new SysLogDTO();
|
||||
sysLogDTO.setOperateType(operatetype.getValue());
|
||||
sysLogDTO.setSourceType(sourcetype.getValue());
|
||||
sysLogDTO.setSourceId(sourceIdValue.toString());
|
||||
FolderItem sourceInfo = logManager.nameWithId(sourceIdValue.toString(), sourcetype.getValue());
|
||||
if (ObjectUtils.isEmpty(sourceInfo)) {
|
||||
return null;
|
||||
}
|
||||
sysLogDTO.setSourceName(sourceInfo.getName());
|
||||
|
||||
// 填充资源位置信息
|
||||
int positionIndex = deLog.positionIndex();
|
||||
if (positionIndex > -1 && args.length > positionIndex){
|
||||
String positionKey = deLog.positionKey();
|
||||
Object positionArg = args[positionIndex];
|
||||
Object bottomPositionValue = AopUtils.getParamValue(positionArg, positionKey, 0);
|
||||
if (ObjectUtils.isNotEmpty(bottomPositionValue)) {
|
||||
if (sourcetype == SysLogConstants.SOURCE_TYPE.DATASOURCE) {
|
||||
FolderItem folderItem = logManager.dsTypeInfo(bottomPositionValue.toString());
|
||||
List<FolderItem> items = new ArrayList<>();
|
||||
items.add(folderItem);
|
||||
sysLogDTO.setPositions(items);
|
||||
}else {
|
||||
List<FolderItem> parentsAndSelf = parents(bottomPositionValue.toString(), sourcetype);
|
||||
sysLogDTO.setPositions(parentsAndSelf);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// 填充资源目标位置信息
|
||||
int targetIndex = deLog.targetIndex();
|
||||
if (targetIndex > -1 && args.length > targetIndex){
|
||||
String targetKey = deLog.targetKey();
|
||||
Object targetArg = args[targetIndex];
|
||||
SysLogConstants.SOURCE_TYPE targetType = deLog.targetType();
|
||||
Object bottomTargetValue = AopUtils.getParamValue(targetArg, targetKey, 0);
|
||||
if (ObjectUtils.isNotEmpty(bottomTargetValue)) {
|
||||
List<FolderItem> parentsAndSelf = parents(bottomTargetValue.toString(), targetType);
|
||||
sysLogDTO.setRemarks(parentsAndSelf);
|
||||
}
|
||||
}
|
||||
return sysLogDTO;
|
||||
}
|
||||
|
||||
@Around(value = "@annotation(io.dataease.auth.annotation.DeLog)")
|
||||
public Object logAround(ProceedingJoinPoint point) throws Throwable {
|
||||
SysLogDTO logDTO = null;
|
||||
Object result = null;
|
||||
DeLog log = getLog(point);
|
||||
if(befores.contains(log.operatetype().getValue())) {
|
||||
// 前置处理 比如删除操作 需要在数据删除之前查询
|
||||
logDTO = exec(point, log);
|
||||
result = point.proceed(point.getArgs());
|
||||
}else {
|
||||
// 后置处理 比如保存操作 需要在保存之后才有主键
|
||||
result = point.proceed(point.getArgs());
|
||||
logDTO = exec(point, log);
|
||||
}
|
||||
|
||||
if (ObjectUtils.isNotEmpty(result) && result instanceof ResultHolder && !((ResultHolder) result).isSuccess()) {
|
||||
return result;
|
||||
}
|
||||
Optional.ofNullable(logDTO).ifPresent(logService::saveLog);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private DeLog getLog(JoinPoint point) {
|
||||
MethodSignature ms = (MethodSignature) point.getSignature();
|
||||
Method method = ms.getMethod();
|
||||
DeLog deLog = method.getAnnotation(DeLog.class);
|
||||
return deLog;
|
||||
}
|
||||
|
||||
public List<FolderItem> parents(String value, SysLogConstants.SOURCE_TYPE type) {
|
||||
return logManager.parentsAndSelf(value, type);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
package io.dataease.commons.constants;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
public class SysLogConstants {
|
||||
|
||||
public static String operateTypeName(Integer value) {
|
||||
Optional<OPERATE_TYPE> any = Arrays.stream(OPERATE_TYPE.class.getEnumConstants()).filter(e -> e.value == value).findAny();
|
||||
if (any.isPresent()) return any.get().name;
|
||||
return null;
|
||||
}
|
||||
|
||||
public enum OPERATE_TYPE {
|
||||
CREATE(1, "OPERATE_TYPE_CREATE"),
|
||||
MODIFY(2, "OPERATE_TYPE_MODIFY"),
|
||||
DELETE(3, "OPERATE_TYPE_DELETE"),
|
||||
SHARE(4, "OPERATE_TYPE_SHARE"),
|
||||
UNSHARE(5, "OPERATE_TYPE_UNSHARE"),
|
||||
AUTHORIZE(6, "OPERATE_TYPE_AUTHORIZE"),
|
||||
UNAUTHORIZE(7, "OPERATE_TYPE_UNAUTHORIZE"),
|
||||
CREATELINK(8, "OPERATE_TYPE_CREATELINK"),
|
||||
DELETELINK(9, "OPERATE_TYPE_DELETELINK"),
|
||||
MODIFYLINK(10, "OPERATE_TYPE_MODIFYLINK");
|
||||
private Integer value;
|
||||
private String name;
|
||||
OPERATE_TYPE(Integer value, String name) {
|
||||
this.value = value;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
public static String sourceTypeName(Integer value) {
|
||||
Optional<SOURCE_TYPE> any = Arrays.stream(SOURCE_TYPE.class.getEnumConstants()).filter(e -> e.value == value).findAny();
|
||||
if (any.isPresent()) return any.get().name;
|
||||
return null;
|
||||
}
|
||||
|
||||
public enum SOURCE_TYPE {
|
||||
DATASOURCE(1, "SOURCE_TYPE_DATASOURCE"),
|
||||
DATASET(2, "SOURCE_TYPE_DATASET"),
|
||||
PANEL(3, "SOURCE_TYPE_PANEL"),
|
||||
VIEW(4, "SOURCE_TYPE_VIEW"),
|
||||
/*LINK(5, "SOURCE_TYPE_LINK"),*/
|
||||
USER(6, "SOURCE_TYPE_USER"),
|
||||
DEPT(7, "SOURCE_TYPE_DEPT"),
|
||||
ROLE(8, "SOURCE_TYPE_ROLE");
|
||||
private Integer value;
|
||||
private String name;
|
||||
|
||||
SOURCE_TYPE(Integer value, String name) {
|
||||
this.value = value;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package io.dataease.commons.utils;
|
||||
|
||||
import io.dataease.auth.util.ReflectUtil;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
public class AopUtils {
|
||||
|
||||
public static Object getParamValue(Object arg, String key, int layer) throws Exception{
|
||||
if (ObjectUtils.isEmpty(arg)) return null;
|
||||
Class<?> parameterType = arg.getClass();
|
||||
if (parameterType.isPrimitive() || ReflectUtil.isWrapClass(parameterType) || ReflectUtil.isString(parameterType)) {
|
||||
return arg;
|
||||
} else if (ReflectUtil.isArray(parameterType)) {
|
||||
Object result;
|
||||
for (int i = 0; i < Array.getLength(arg); i++) {
|
||||
Object o = Array.get(arg, i);
|
||||
|
||||
if (ObjectUtils.isNotEmpty((result = getParamValue(o, key, layer)))) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} else if (ReflectUtil.isCollection(parameterType)) {
|
||||
Object[] array = ((Collection) arg).toArray();
|
||||
Object result;
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
Object o = array[i];
|
||||
if (ObjectUtils.isNotEmpty((result = getParamValue(o, key, layer)))) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} else if (ReflectUtil.isMap(parameterType)) {
|
||||
Map<String, Object> argMap = (Map) arg;
|
||||
String[] values = key.split("\\.");
|
||||
Object o = argMap.get(values[layer]);
|
||||
return getParamValue(o, key, ++layer);
|
||||
} else {
|
||||
// 当作自定义类处理
|
||||
String[] values = key.split("\\.");
|
||||
String fieldName = values[layer];
|
||||
|
||||
Object fieldValue = ReflectUtil.getFieldValue(arg, values[layer]);
|
||||
return getParamValue(fieldValue, key, ++layer);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,10 @@
|
||||
package io.dataease.controller.datasource;
|
||||
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
|
||||
import io.dataease.auth.annotation.DeLog;
|
||||
import io.dataease.auth.annotation.DePermission;
|
||||
import io.dataease.commons.constants.SysLogConstants;
|
||||
import io.dataease.controller.datasource.request.DeleteDsRequest;
|
||||
import io.dataease.plugins.common.base.domain.Datasource;
|
||||
import io.dataease.commons.constants.DePermissionType;
|
||||
import io.dataease.commons.constants.ResourceAuthLevel;
|
||||
@ -39,6 +42,12 @@ public class DatasourceController {
|
||||
@DePermission(type = DePermissionType.DATASOURCE, value = "id")
|
||||
@ApiOperation("新增数据源")
|
||||
@PostMapping("/add")
|
||||
@DeLog(
|
||||
operatetype = SysLogConstants.OPERATE_TYPE.CREATE,
|
||||
sourcetype = SysLogConstants.SOURCE_TYPE.DATASOURCE,
|
||||
positionIndex = 0,positionKey = "type",
|
||||
value = "id"
|
||||
)
|
||||
public Datasource addDatasource(@RequestBody Datasource datasource) throws Exception{
|
||||
return datasourceService.addDatasource(datasource);
|
||||
}
|
||||
@ -81,15 +90,27 @@ public class DatasourceController {
|
||||
@RequiresPermissions("datasource:read")
|
||||
@DePermission(type = DePermissionType.DATASOURCE, level = ResourceAuthLevel.DATASOURCE_LEVEL_MANAGE)
|
||||
@ApiOperation("删除数据源")
|
||||
@PostMapping("/delete/{datasourceID}")
|
||||
public ResultHolder deleteDatasource(@PathVariable(value = "datasourceID") String datasourceID) throws Exception {
|
||||
return datasourceService.deleteDatasource(datasourceID);
|
||||
@PostMapping("/delete")
|
||||
@DeLog(
|
||||
operatetype = SysLogConstants.OPERATE_TYPE.DELETE,
|
||||
sourcetype = SysLogConstants.SOURCE_TYPE.DATASOURCE,
|
||||
positionIndex = 0,positionKey = "type",
|
||||
value = "id"
|
||||
)
|
||||
public ResultHolder deleteDatasource(@RequestBody DeleteDsRequest request) throws Exception {
|
||||
return datasourceService.deleteDatasource(request.getId());
|
||||
}
|
||||
|
||||
@RequiresPermissions("datasource:read")
|
||||
@DePermission(type = DePermissionType.DATASOURCE, value = "id", level = ResourceAuthLevel.DATASOURCE_LEVEL_MANAGE)
|
||||
@ApiOperation("更新数据源")
|
||||
@PostMapping("/update")
|
||||
@DeLog(
|
||||
operatetype = SysLogConstants.OPERATE_TYPE.MODIFY,
|
||||
sourcetype = SysLogConstants.SOURCE_TYPE.DATASOURCE,
|
||||
positionIndex = 0,positionKey = "type",
|
||||
value = "id"
|
||||
)
|
||||
public void updateDatasource(@RequestBody UpdataDsRequest dsRequest) throws Exception{
|
||||
datasourceService.updateDatasource(dsRequest);
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
package io.dataease.controller.datasource.request;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class DeleteDsRequest implements Serializable {
|
||||
|
||||
@ApiModelProperty(value = "ID",required = true)
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(value = "类型", required = true)
|
||||
private String type;
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package io.dataease.controller.sys;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
|
||||
import io.dataease.commons.utils.PageUtils;
|
||||
import io.dataease.commons.utils.Pager;
|
||||
import io.dataease.controller.handler.annotation.I18n;
|
||||
import io.dataease.controller.sys.base.BaseGridRequest;
|
||||
import io.dataease.dto.SysLogGridDTO;
|
||||
import io.dataease.dto.log.FolderItem;
|
||||
import io.dataease.service.sys.log.LogService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@Api(tags = "系统:日志管理")
|
||||
@ApiSupport(order = 220)
|
||||
@RequestMapping("/api/log")
|
||||
public class SysLogController {
|
||||
|
||||
@Resource
|
||||
private LogService logService;
|
||||
|
||||
@I18n
|
||||
@ApiOperation("查询日志")
|
||||
@PostMapping("/logGrid/{goPage}/{pageSize}")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(paramType = "path", name = "goPage", value = "页码", required = true, dataType = "Integer"),
|
||||
@ApiImplicitParam(paramType = "path", name = "pageSize", value = "页容量", required = true, dataType = "Integer"),
|
||||
@ApiImplicitParam(name = "request", value = "查询条件", required = true)
|
||||
})
|
||||
public Pager<List<SysLogGridDTO>> logGrid(@PathVariable int goPage, @PathVariable int pageSize,
|
||||
@RequestBody BaseGridRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
return PageUtils.setPageInfo(page, logService.query(request));
|
||||
}
|
||||
|
||||
@ApiOperation("操作类型")
|
||||
@PostMapping("/opTypes")
|
||||
public List<FolderItem> types() {
|
||||
return logService.types();
|
||||
}
|
||||
|
||||
@ApiOperation("导出操作日志")
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response) throws Exception{
|
||||
logService.exportExcel(response);
|
||||
}
|
||||
}
|
@ -3,7 +3,9 @@ package io.dataease.controller.sys;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
|
||||
import io.dataease.auth.annotation.DeLog;
|
||||
import io.dataease.auth.api.dto.CurrentUserDto;
|
||||
import io.dataease.commons.constants.SysLogConstants;
|
||||
import io.dataease.exception.DataEaseException;
|
||||
import io.dataease.i18n.Translator;
|
||||
import io.dataease.plugins.common.base.domain.SysRole;
|
||||
@ -69,6 +71,11 @@ public class SysUserController {
|
||||
@ApiOperation("创建用户")
|
||||
@RequiresPermissions("user:add")
|
||||
@PostMapping("/create")
|
||||
@DeLog(
|
||||
operatetype = SysLogConstants.OPERATE_TYPE.CREATE,
|
||||
sourcetype = SysLogConstants.SOURCE_TYPE.USER,
|
||||
value = "userId"
|
||||
)
|
||||
public void create(@RequestBody SysUserCreateRequest request) {
|
||||
sysUserService.save(request);
|
||||
}
|
||||
@ -76,6 +83,11 @@ public class SysUserController {
|
||||
@ApiOperation("更新用户")
|
||||
@RequiresPermissions("user:edit")
|
||||
@PostMapping("/update")
|
||||
@DeLog(
|
||||
operatetype = SysLogConstants.OPERATE_TYPE.MODIFY,
|
||||
sourcetype = SysLogConstants.SOURCE_TYPE.USER,
|
||||
value = "userId"
|
||||
)
|
||||
public void update(@RequestBody SysUserCreateRequest request) {
|
||||
sysUserService.update(request);
|
||||
}
|
||||
@ -84,6 +96,10 @@ public class SysUserController {
|
||||
@RequiresPermissions("user:del")
|
||||
@PostMapping("/delete/{userId}")
|
||||
@ApiImplicitParam(paramType = "path", value = "用户ID", name = "userId", required = true, dataType = "Integer")
|
||||
@DeLog(
|
||||
operatetype = SysLogConstants.OPERATE_TYPE.DELETE,
|
||||
sourcetype = SysLogConstants.SOURCE_TYPE.USER
|
||||
)
|
||||
public void delete(@PathVariable("userId") Long userId) {
|
||||
sysUserService.delete(userId);
|
||||
}
|
||||
@ -92,6 +108,11 @@ public class SysUserController {
|
||||
@RequiresPermissions("user:edit")
|
||||
@RequiresRoles("1")
|
||||
@PostMapping("/updateStatus")
|
||||
@DeLog(
|
||||
operatetype = SysLogConstants.OPERATE_TYPE.MODIFY,
|
||||
sourcetype = SysLogConstants.SOURCE_TYPE.USER,
|
||||
value = "userId"
|
||||
)
|
||||
public void updateStatus(@RequestBody SysUserStateRequest request) {
|
||||
sysUserService.updateStatus(request);
|
||||
}
|
||||
|
24
backend/src/main/java/io/dataease/dto/SysLogDTO.java
Normal file
24
backend/src/main/java/io/dataease/dto/SysLogDTO.java
Normal file
@ -0,0 +1,24 @@
|
||||
package io.dataease.dto;
|
||||
|
||||
import io.dataease.dto.log.FolderItem;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class SysLogDTO implements Serializable {
|
||||
|
||||
private Integer sourceType;
|
||||
|
||||
private String sourceId;
|
||||
|
||||
private String sourceName;
|
||||
|
||||
private Integer operateType;
|
||||
|
||||
private List<FolderItem> positions;
|
||||
|
||||
private List<FolderItem> remarks;
|
||||
|
||||
}
|
25
backend/src/main/java/io/dataease/dto/SysLogGridDTO.java
Normal file
25
backend/src/main/java/io/dataease/dto/SysLogGridDTO.java
Normal file
@ -0,0 +1,25 @@
|
||||
package io.dataease.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class SysLogGridDTO implements Serializable {
|
||||
|
||||
@ApiModelProperty("操作类型")
|
||||
private String opType;
|
||||
|
||||
@ApiModelProperty("资源类型")
|
||||
private String sourceType;
|
||||
|
||||
@ApiModelProperty("详细信息")
|
||||
private String detail;
|
||||
|
||||
@ApiModelProperty("操作人")
|
||||
private String user;
|
||||
|
||||
@ApiModelProperty("操作时间")
|
||||
private Long time;
|
||||
}
|
16
backend/src/main/java/io/dataease/dto/log/FolderItem.java
Normal file
16
backend/src/main/java/io/dataease/dto/log/FolderItem.java
Normal file
@ -0,0 +1,16 @@
|
||||
package io.dataease.dto.log;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class FolderItem implements Serializable {
|
||||
|
||||
private String id;
|
||||
|
||||
private String name;
|
||||
|
||||
private Integer type;
|
||||
|
||||
}
|
15
backend/src/main/java/io/dataease/ext/ExtSysLogMapper.java
Normal file
15
backend/src/main/java/io/dataease/ext/ExtSysLogMapper.java
Normal file
@ -0,0 +1,15 @@
|
||||
package io.dataease.ext;
|
||||
|
||||
import io.dataease.dto.log.FolderItem;
|
||||
import io.dataease.ext.query.GridExample;
|
||||
import io.dataease.plugins.common.base.domain.SysLogWithBLOBs;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ExtSysLogMapper {
|
||||
|
||||
List<SysLogWithBLOBs> query(GridExample example);
|
||||
|
||||
List<FolderItem> idAndName(@Param("ids") List<String> ids, @Param("type") Integer type);
|
||||
}
|
118
backend/src/main/java/io/dataease/ext/ExtSysLogMapper.xml
Normal file
118
backend/src/main/java/io/dataease/ext/ExtSysLogMapper.xml
Normal file
@ -0,0 +1,118 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="io.dataease.ext.ExtSysLogMapper">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<select id="query" parameterType="io.dataease.ext.query.GridExample" resultMap="io.dataease.plugins.common.base.mapper.SysLogMapper.ResultMapWithBLOBs">
|
||||
select * from sys_log
|
||||
|
||||
<if test="_parameter != null">
|
||||
<include refid="io.dataease.ext.query.GridSql.gridCondition" />
|
||||
</if>
|
||||
<if test="orderByClause != null">
|
||||
order by ${orderByClause}
|
||||
</if>
|
||||
<if test="orderByClause == null">
|
||||
order by time desc
|
||||
</if>
|
||||
</select>
|
||||
|
||||
|
||||
<select id="idAndName" resultType="io.dataease.dto.log.FolderItem" >
|
||||
select
|
||||
<if test="type == 1">
|
||||
id, name
|
||||
from datasource
|
||||
<where>
|
||||
id in
|
||||
<foreach collection="ids" item="id" index="index" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</where>
|
||||
</if>
|
||||
|
||||
<if test="type == 2">
|
||||
id, name
|
||||
from dataset_group
|
||||
<where>
|
||||
id in
|
||||
<foreach collection="ids" item="id" index="index" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</where>
|
||||
</if>
|
||||
|
||||
<if test="type == 3">
|
||||
id, name
|
||||
from panel_group
|
||||
<where>
|
||||
id in
|
||||
<foreach collection="ids" item="id" index="index" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</where>
|
||||
</if>
|
||||
|
||||
<if test="type == 4">
|
||||
id, name
|
||||
from chart_view
|
||||
<where>
|
||||
id in
|
||||
<foreach collection="ids" item="id" index="index" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</where>
|
||||
</if>
|
||||
|
||||
<if test="type == 5">
|
||||
id, name
|
||||
from panel_group
|
||||
<where>
|
||||
id in
|
||||
<foreach collection="ids" item="id" index="index" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</where>
|
||||
</if>
|
||||
|
||||
<if test="type == 6">
|
||||
user_id as id, nick_name as name
|
||||
from sys_user
|
||||
<where>
|
||||
user_id in
|
||||
<foreach collection="ids" item="id" index="index" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</where>
|
||||
</if>
|
||||
|
||||
<if test="type == 7">
|
||||
dept_id as id, name
|
||||
from sys_dept
|
||||
<where>
|
||||
dept_id in
|
||||
<foreach collection="ids" item="id" index="index" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</where>
|
||||
</if>
|
||||
|
||||
<if test="type == 8">
|
||||
role_id as id, name
|
||||
from sys_role
|
||||
<where>
|
||||
role_id in
|
||||
<foreach collection="ids" item="id" index="index" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</where>
|
||||
</if>
|
||||
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
@ -1,7 +1,9 @@
|
||||
package io.dataease.plugins.server;
|
||||
|
||||
|
||||
import io.dataease.auth.annotation.DeLog;
|
||||
import io.dataease.auth.service.ExtAuthService;
|
||||
import io.dataease.commons.constants.SysLogConstants;
|
||||
import io.dataease.commons.utils.BeanUtils;
|
||||
import io.dataease.controller.sys.response.DeptNodeResponse;
|
||||
import io.dataease.plugins.common.entity.XpackGridRequest;
|
||||
@ -70,6 +72,12 @@ public class XDeptServer {
|
||||
@RequiresPermissions("dept:add")
|
||||
@ApiOperation("创建")
|
||||
@PostMapping("/create")
|
||||
@DeLog(
|
||||
operatetype = SysLogConstants.OPERATE_TYPE.CREATE,
|
||||
sourcetype = SysLogConstants.SOURCE_TYPE.DEPT,
|
||||
positionIndex = 0,positionKey = "pid",
|
||||
value = "deptId"
|
||||
)
|
||||
public int create(@RequestBody XpackCreateDept dept){
|
||||
DeptXpackService deptService = SpringContextUtil.getBean(DeptXpackService.class);
|
||||
return deptService.add(dept);
|
||||
@ -78,6 +86,12 @@ public class XDeptServer {
|
||||
@RequiresPermissions("dept:del")
|
||||
@ApiOperation("删除")
|
||||
@PostMapping("/delete")
|
||||
@DeLog(
|
||||
operatetype = SysLogConstants.OPERATE_TYPE.DELETE,
|
||||
sourcetype = SysLogConstants.SOURCE_TYPE.DEPT,
|
||||
positionIndex = 0,positionKey = "pid",
|
||||
value = "deptId"
|
||||
)
|
||||
public void delete(@RequestBody List<XpackDeleteDept> requests){
|
||||
DeptXpackService deptService = SpringContextUtil.getBean(DeptXpackService.class);
|
||||
requests.forEach(request -> {
|
||||
@ -89,6 +103,12 @@ public class XDeptServer {
|
||||
@RequiresPermissions("dept:edit")
|
||||
@ApiOperation("更新")
|
||||
@PostMapping("/update")
|
||||
@DeLog(
|
||||
operatetype = SysLogConstants.OPERATE_TYPE.MODIFY,
|
||||
sourcetype = SysLogConstants.SOURCE_TYPE.DEPT,
|
||||
positionIndex = 0,positionKey = "pid",
|
||||
value = "deptId"
|
||||
)
|
||||
public int update(@RequestBody XpackCreateDept dept){
|
||||
DeptXpackService deptService = SpringContextUtil.getBean(DeptXpackService.class);
|
||||
return deptService.update(dept);
|
||||
|
@ -3,7 +3,9 @@ package io.dataease.plugins.server;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.dataease.auth.annotation.DeLog;
|
||||
import io.dataease.auth.service.ExtAuthService;
|
||||
import io.dataease.commons.constants.SysLogConstants;
|
||||
import io.dataease.commons.utils.PageUtils;
|
||||
import io.dataease.commons.utils.Pager;
|
||||
import io.dataease.plugins.common.entity.XpackGridRequest;
|
||||
@ -30,6 +32,11 @@ public class XRoleServer {
|
||||
@RequiresPermissions("role:add")
|
||||
@ApiOperation("新增角色")
|
||||
@PostMapping("/create")
|
||||
@DeLog(
|
||||
operatetype = SysLogConstants.OPERATE_TYPE.CREATE,
|
||||
sourcetype = SysLogConstants.SOURCE_TYPE.ROLE,
|
||||
value = "roleId"
|
||||
)
|
||||
public void create(@RequestBody XpackRoleDto role){
|
||||
RoleXpackService roleXpackService = SpringContextUtil.getBean(RoleXpackService.class);
|
||||
roleXpackService.save(role);
|
||||
@ -39,6 +46,10 @@ public class XRoleServer {
|
||||
@RequiresPermissions("role:del")
|
||||
@ApiOperation("删除角色")
|
||||
@PostMapping("/delete/{roleId}")
|
||||
@DeLog(
|
||||
operatetype = SysLogConstants.OPERATE_TYPE.DELETE,
|
||||
sourcetype = SysLogConstants.SOURCE_TYPE.ROLE
|
||||
)
|
||||
public void delete(@PathVariable("roleId") Long roleId){
|
||||
RoleXpackService roleXpackService = SpringContextUtil.getBean(RoleXpackService.class);
|
||||
extAuthService.clearDeptResource(roleId);
|
||||
@ -49,6 +60,11 @@ public class XRoleServer {
|
||||
@RequiresPermissions("role:edit")
|
||||
@ApiOperation("更新角色")
|
||||
@PostMapping("/update")
|
||||
@DeLog(
|
||||
operatetype = SysLogConstants.OPERATE_TYPE.MODIFY,
|
||||
sourcetype = SysLogConstants.SOURCE_TYPE.ROLE,
|
||||
value = "roleId"
|
||||
)
|
||||
public void update(@RequestBody XpackRoleDto role){
|
||||
RoleXpackService roleXpackService = SpringContextUtil.getBean(RoleXpackService.class);
|
||||
roleXpackService.update(role);
|
||||
|
@ -94,6 +94,7 @@ public class SysUserService {
|
||||
}
|
||||
int insert = sysUserMapper.insert(user);
|
||||
SysUser dbUser = findOne(user);
|
||||
request.setUserId(dbUser.getUserId());
|
||||
saveUserRoles(dbUser.getUserId(), request.getRoleIds());//插入用户角色关联
|
||||
return insert;
|
||||
}
|
||||
|
@ -0,0 +1,133 @@
|
||||
package io.dataease.service.sys.log;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import io.dataease.commons.constants.SysLogConstants;
|
||||
import io.dataease.commons.utils.AuthUtils;
|
||||
import io.dataease.dto.log.FolderItem;
|
||||
import io.dataease.ext.ExtSysLogMapper;
|
||||
import io.dataease.i18n.Translator;
|
||||
import io.dataease.plugins.common.base.domain.SysLogWithBLOBs;
|
||||
import io.dataease.plugins.common.dto.datasource.DataSourceType;
|
||||
import io.dataease.service.datasource.DatasourceService;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class LogManager {
|
||||
|
||||
protected static final String contentFormat = "【%s】";
|
||||
|
||||
protected static final String positionFormat = "在【%s】";
|
||||
|
||||
protected static final String format = "给%s【%s】";
|
||||
|
||||
protected Gson gson = new Gson();
|
||||
|
||||
|
||||
protected Type type = new TypeToken<List<FolderItem>>() {}.getType();
|
||||
|
||||
|
||||
|
||||
@Resource
|
||||
private ExtSysLogMapper extSysLogMapper;
|
||||
|
||||
@Resource
|
||||
private DatasourceService datasourceService;
|
||||
|
||||
|
||||
public String detailInfo(SysLogWithBLOBs vo) {
|
||||
String sourceName = vo.getSourceName();
|
||||
String postion = null;
|
||||
String operateTypeName = SysLogConstants.operateTypeName(vo.getOperateType());
|
||||
operateTypeName = Translator.get(operateTypeName);
|
||||
String sourceTypeName = SysLogConstants.sourceTypeName(vo.getSourceType());
|
||||
sourceTypeName = Translator.get(sourceTypeName);
|
||||
String result = operateTypeName + sourceTypeName + String.format(contentFormat, sourceName) + remarkInfo(vo);
|
||||
|
||||
if ((postion = vo.getPosition()) != null) {
|
||||
List<FolderItem> folderItems = gson.fromJson(postion, type);
|
||||
String template = folderItems.stream().map(folderItem -> folderItem.getName()).collect(Collectors.joining("/"));
|
||||
String postionResult = String.format(positionFormat, template);
|
||||
return postionResult + result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String remarkInfo(SysLogWithBLOBs vo) {
|
||||
String remakrk = null;
|
||||
if ((remakrk = vo.getRemark()) != null) {
|
||||
List<FolderItem> targetInfos = gson.fromJson(remakrk, type);
|
||||
String target = targetInfos.stream().map(item -> {
|
||||
Integer targetType = item.getType();
|
||||
String targetTypeName = SysLogConstants.sourceTypeName(targetType);
|
||||
return String.format(format, targetTypeName, item.getName());
|
||||
}).collect(Collectors.joining("/"));
|
||||
return target;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public List<FolderItem> parentsAndSelf(String id, SysLogConstants.SOURCE_TYPE type) {
|
||||
Integer value = type.getValue();
|
||||
String typeValue = "";
|
||||
switch (value) {
|
||||
case 2:
|
||||
typeValue = "dataset";
|
||||
break;
|
||||
case 3:
|
||||
typeValue = "panel";
|
||||
break;
|
||||
case 7:
|
||||
typeValue = "dept";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
List<String> ids = new ArrayList<>();
|
||||
if (StringUtils.isNotBlank(typeValue)) {
|
||||
ids.addAll(AuthUtils.parentResources(id, typeValue));
|
||||
}else {
|
||||
ids.add(id);
|
||||
}
|
||||
List<FolderItem> folderItems = extSysLogMapper.idAndName(ids, value);
|
||||
folderItems.forEach(item -> item.setType(value));
|
||||
return folderItems;
|
||||
}
|
||||
|
||||
public FolderItem nameWithId(String id, Integer type) {
|
||||
List<String> ids = new ArrayList<>();
|
||||
ids.add(id);
|
||||
List<FolderItem> folderItems = extSysLogMapper.idAndName(ids, type);
|
||||
if (CollectionUtils.isNotEmpty(folderItems)) {
|
||||
return folderItems.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public FolderItem dsTypeInfo(String typeId) {
|
||||
ArrayList<DataSourceType> dataSourceTypes = new ArrayList<>(datasourceService.types());
|
||||
String name = null;
|
||||
for (int i = 0; i < dataSourceTypes.size(); i++) {
|
||||
if (dataSourceTypes.get(i).getType().equals(typeId)){
|
||||
name = dataSourceTypes.get(i).getName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
FolderItem folderItem = new FolderItem();
|
||||
folderItem.setId(typeId);
|
||||
folderItem.setName(StringUtils.isNotBlank(name) ? name : typeId);
|
||||
return folderItem;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
package io.dataease.service.sys.log;
|
||||
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.dataease.auth.api.dto.CurrentUserDto;
|
||||
import io.dataease.commons.constants.SysLogConstants;
|
||||
import io.dataease.commons.utils.AuthUtils;
|
||||
import io.dataease.commons.utils.BeanUtils;
|
||||
import io.dataease.controller.sys.base.BaseGridRequest;
|
||||
import io.dataease.dto.SysLogDTO;
|
||||
import io.dataease.dto.SysLogGridDTO;
|
||||
import io.dataease.dto.log.FolderItem;
|
||||
import io.dataease.ext.ExtSysLogMapper;
|
||||
import io.dataease.ext.query.GridExample;
|
||||
import io.dataease.i18n.Translator;
|
||||
import io.dataease.plugins.common.base.domain.SysLogWithBLOBs;
|
||||
import io.dataease.plugins.common.base.mapper.SysLogMapper;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class LogService {
|
||||
|
||||
private Gson gson = new Gson();
|
||||
|
||||
private static Integer[] unPanelOperates = {4, 5, 8, 9, 10};
|
||||
|
||||
@Resource
|
||||
private SysLogMapper sysLogMapper;
|
||||
|
||||
@Resource
|
||||
private ExtSysLogMapper extSysLogMapper;
|
||||
|
||||
@Resource
|
||||
private LogManager logManager;
|
||||
|
||||
|
||||
|
||||
public List<SysLogGridDTO> query(BaseGridRequest request) {
|
||||
GridExample gridExample = request.convertExample();
|
||||
List<SysLogWithBLOBs> voLogs = extSysLogMapper.query(gridExample);
|
||||
List<SysLogGridDTO> dtos = voLogs.stream().map(this::convertDTO).collect(Collectors.toList());
|
||||
return dtos;
|
||||
}
|
||||
|
||||
|
||||
public List<FolderItem> types() {
|
||||
List<Integer> integers = Arrays.stream(unPanelOperates).collect(Collectors.toList());
|
||||
List<FolderItem> results = new ArrayList<>();
|
||||
SysLogConstants.SOURCE_TYPE[] sourceTypes = SysLogConstants.SOURCE_TYPE.values();
|
||||
SysLogConstants.OPERATE_TYPE[] operateTypes = SysLogConstants.OPERATE_TYPE.values();
|
||||
for (int i = 0; i < sourceTypes.length; i++) {
|
||||
SysLogConstants.SOURCE_TYPE sourceType = sourceTypes[i];
|
||||
for (int j = 0; j < operateTypes.length; j++) {
|
||||
SysLogConstants.OPERATE_TYPE operateType = operateTypes[j];
|
||||
if (sourceType.getValue() > 3 && operateType.getValue() > 3){
|
||||
continue;
|
||||
}
|
||||
if (sourceType.getValue() != 3 && integers.contains(operateType.getValue())) {
|
||||
continue;
|
||||
}
|
||||
FolderItem folderItem = new FolderItem();
|
||||
folderItem.setId(operateType.getValue() + "-" + sourceType.getValue());
|
||||
String operateTypeName = operateType.getName();
|
||||
String sourceTypeName = sourceType.getName();
|
||||
folderItem.setName( Translator.get(operateTypeName) + Translator.get(sourceTypeName));
|
||||
results.add(folderItem);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public SysLogGridDTO convertDTO(SysLogWithBLOBs vo) {
|
||||
SysLogGridDTO sysLogGridDTO = new SysLogGridDTO();
|
||||
sysLogGridDTO.setOpType(SysLogConstants.operateTypeName(vo.getOperateType()));
|
||||
sysLogGridDTO.setSourceType(SysLogConstants.sourceTypeName(vo.getSourceType()));
|
||||
sysLogGridDTO.setTime(vo.getTime());
|
||||
sysLogGridDTO.setUser(vo.getNickName());
|
||||
sysLogGridDTO.setDetail(logManager.detailInfo(vo));
|
||||
return sysLogGridDTO;
|
||||
}
|
||||
|
||||
public void saveLog(SysLogDTO sysLogDTO) {
|
||||
// String ip = "";
|
||||
CurrentUserDto user = AuthUtils.getUser();
|
||||
SysLogWithBLOBs sysLogWithBLOBs = BeanUtils.copyBean(new SysLogWithBLOBs(), sysLogDTO);
|
||||
if (CollectionUtils.isNotEmpty(sysLogDTO.getPositions())) {
|
||||
sysLogWithBLOBs.setPosition(gson.toJson(sysLogDTO.getPositions()));
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(sysLogDTO.getRemarks())) {
|
||||
sysLogWithBLOBs.setRemark(gson.toJson(sysLogDTO.getRemarks()));
|
||||
}
|
||||
sysLogWithBLOBs.setTime(System.currentTimeMillis());
|
||||
sysLogWithBLOBs.setUserId(user.getUserId());
|
||||
sysLogWithBLOBs.setLoginName(user.getUsername());
|
||||
sysLogWithBLOBs.setNickName(user.getNickName());
|
||||
// sysLogWithBLOBs.setIp(ip);
|
||||
sysLogMapper.insert(sysLogWithBLOBs);
|
||||
}
|
||||
|
||||
public void exportExcel(HttpServletResponse response) throws Exception{
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -128,3 +128,23 @@ i18n_wrong_content=Wrong content
|
||||
i18n_wrong_tel=Wrong tel format
|
||||
i18n_wrong_email=Wrong email format
|
||||
i18n_wrong_name_format=Wrong name format
|
||||
|
||||
|
||||
OPERATE_TYPE_CREATE=Create
|
||||
OPERATE_TYPE_MODIFY=Modify
|
||||
OPERATE_TYPE_DELETE=Delete
|
||||
OPERATE_TYPE_SHARE=Share
|
||||
OPERATE_TYPE_UNSHARE=Unshare
|
||||
OPERATE_TYPE_AUTHORIZE=Authorize
|
||||
OPERATE_TYPE_UNAUTHORIZE=Unauthorize
|
||||
OPERATE_TYPE_CREATELINK=Create Link
|
||||
OPERATE_TYPE_DELETELINK=Delete Link
|
||||
OPERATE_TYPE_MODIFYLINK=Modify Link
|
||||
|
||||
SOURCE_TYPE_DATASOURCE=数据源
|
||||
SOURCE_TYPE_DATASET=数据集
|
||||
SOURCE_TYPE_PANEL=仪表板
|
||||
SOURCE_TYPE_VIEW=视图
|
||||
SOURCE_TYPE_USER=用户
|
||||
SOURCE_TYPE_DEPT=组织
|
||||
SOURCE_TYPE_ROLE=角色
|
||||
|
@ -128,3 +128,26 @@ i18n_wrong_tel=电话格式错误
|
||||
i18n_wrong_email=邮箱格式错误
|
||||
i18n_wrong_name_format=姓名格式错误
|
||||
|
||||
OPERATE_TYPE_CREATE=创建
|
||||
OPERATE_TYPE_MODIFY=修改
|
||||
OPERATE_TYPE_DELETE=删除
|
||||
OPERATE_TYPE_SHARE=分享
|
||||
OPERATE_TYPE_UNSHARE=取消分享
|
||||
OPERATE_TYPE_AUTHORIZE=授权
|
||||
OPERATE_TYPE_UNAUTHORIZE=取消授权
|
||||
OPERATE_TYPE_CREATELINK=创建公共链接
|
||||
OPERATE_TYPE_DELETELINK=删除公共链接
|
||||
OPERATE_TYPE_MODIFYLINK=修改公共链接
|
||||
|
||||
SOURCE_TYPE_DATASOURCE=数据源
|
||||
SOURCE_TYPE_DATASET=数据集
|
||||
SOURCE_TYPE_PANEL=仪表板
|
||||
SOURCE_TYPE_VIEW=视图
|
||||
SOURCE_TYPE_USER=用户
|
||||
SOURCE_TYPE_DEPT=组织
|
||||
SOURCE_TYPE_ROLE=角色
|
||||
|
||||
I18N_OPERATE_TYPE=操作类型
|
||||
I18N_DETAIL=操作详情
|
||||
I18N_USER=操作人
|
||||
I18N_TIME=操作时间
|
||||
|
@ -128,3 +128,22 @@ i18n_wrong_content=內容不合法
|
||||
i18n_wrong_tel=電話格式錯誤
|
||||
i18n_wrong_email=郵箱格式錯誤
|
||||
i18n_wrong_name_format=姓名格式錯誤
|
||||
|
||||
OPERATE_TYPE_CREATE=創建
|
||||
OPERATE_TYPE_MODIFY=修改
|
||||
OPERATE_TYPE_DELETE=刪除
|
||||
OPERATE_TYPE_SHARE=分享
|
||||
OPERATE_TYPE_UNSHARE=取消分享
|
||||
OPERATE_TYPE_AUTHORIZE=授權
|
||||
OPERATE_TYPE_UNAUTHORIZE=取消授權
|
||||
OPERATE_TYPE_CREATELINK=創建公共鏈接
|
||||
OPERATE_TYPE_DELETELINK=刪除公共鏈接
|
||||
OPERATE_TYPE_MODIFYLINK=修改公共鏈接
|
||||
|
||||
SOURCE_TYPE_DATASOURCE=數據源
|
||||
SOURCE_TYPE_DATASET=數據集
|
||||
SOURCE_TYPE_PANEL=儀表板
|
||||
SOURCE_TYPE_VIEW=視圖
|
||||
SOURCE_TYPE_USER=用戶
|
||||
SOURCE_TYPE_DEPT=組織
|
||||
SOURCE_TYPE_ROLE=角色
|
||||
|
@ -27,7 +27,7 @@
|
||||
"element-ui": "2.15.7",
|
||||
"file-save": "^0.2.0",
|
||||
"file-saver": "^2.0.5",
|
||||
"fit2cloud-ui": "1.5.4",
|
||||
"fit2cloud-ui": "^1.8.0",
|
||||
"flv.js": "^1.6.2",
|
||||
"html2canvasde": "^v1.1.4-de",
|
||||
"jquery": "^3.1.1",
|
||||
|
@ -47,11 +47,12 @@ export function editDs(data) {
|
||||
})
|
||||
}
|
||||
|
||||
export function delDs(id) {
|
||||
export function delDs(data) {
|
||||
return request({
|
||||
url: 'datasource/delete/' + id,
|
||||
url: 'datasource/delete',
|
||||
loading: true,
|
||||
method: 'post'
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
@ -81,7 +82,7 @@ export function getSchema(data) {
|
||||
})
|
||||
}
|
||||
|
||||
export function checkApiDatasource(data){
|
||||
export function checkApiDatasource(data) {
|
||||
return request({
|
||||
url: 'datasource/checkApiDatasource',
|
||||
method: 'post',
|
||||
|
26
frontend/src/api/system/log.js
Normal file
26
frontend/src/api/system/log.js
Normal file
@ -0,0 +1,26 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
export function logGrid(page, size, data) {
|
||||
return request({
|
||||
url: '/api/log/logGrid/' + page + '/' + size,
|
||||
method: 'post',
|
||||
data,
|
||||
loading: true
|
||||
})
|
||||
}
|
||||
|
||||
export function opTypes() {
|
||||
return request({
|
||||
url: '/api/log/opTypes',
|
||||
method: 'post',
|
||||
loading: true
|
||||
})
|
||||
}
|
||||
|
||||
export function exportExcel() {
|
||||
return request({
|
||||
url: '/api/log/export',
|
||||
method: 'post',
|
||||
loading: true
|
||||
})
|
||||
}
|
@ -2041,5 +2041,14 @@ export default {
|
||||
port: '端口',
|
||||
user: '用户名',
|
||||
passwd: '密码'
|
||||
},
|
||||
log: {
|
||||
title: '操作日志',
|
||||
optype: '操作类型',
|
||||
detail: '操作详情',
|
||||
user: '操作用户',
|
||||
time: '操作时间',
|
||||
export: '导出',
|
||||
search_by_key: '搜索详情'
|
||||
}
|
||||
}
|
||||
|
@ -827,3 +827,6 @@ div:focus {
|
||||
// position: relative !important;
|
||||
right: 0px;
|
||||
}
|
||||
.fu-operator-component__operator {
|
||||
display: none !important;
|
||||
}
|
@ -5,11 +5,16 @@
|
||||
<span class="title-text">
|
||||
{{ $t('commons.datasource') }}
|
||||
</span>
|
||||
<el-button icon="el-icon-plus" type="text" size="mini" style="float: right;"
|
||||
@click="addFolder"/>
|
||||
<el-button
|
||||
icon="el-icon-plus"
|
||||
type="text"
|
||||
size="mini"
|
||||
style="float: right;"
|
||||
@click="addFolder"
|
||||
/>
|
||||
|
||||
</el-row>
|
||||
<el-divider/>
|
||||
<el-divider />
|
||||
<el-row>
|
||||
<el-form>
|
||||
<el-form-item class="form-item">
|
||||
@ -39,35 +44,41 @@
|
||||
<span slot-scope="{ node, data }" class="custom-tree-node-list father">
|
||||
<span style="display: flex;flex: 1;width: 0;">
|
||||
<span v-if="data.type !== 'folder' && data.status !== 'Error' && data.status !== 'Warning'">
|
||||
<svg-icon icon-class="datasource" class="ds-icon-scene"/>
|
||||
<svg-icon icon-class="datasource" class="ds-icon-scene" />
|
||||
</span>
|
||||
<span v-if="data.status === 'Error'">
|
||||
<svg-icon icon-class="exclamationmark" class="ds-icon-scene"/>
|
||||
<svg-icon icon-class="exclamationmark" class="ds-icon-scene" />
|
||||
</span>
|
||||
<span v-if="data.status === 'Warning'">
|
||||
<svg-icon icon-class="exclamationmark2" class="ds-icon-scene"/>
|
||||
<svg-icon icon-class="exclamationmark2" class="ds-icon-scene" />
|
||||
</span>
|
||||
<span v-if="data.type === 'folder'">
|
||||
<i class="el-icon-folder"/>
|
||||
<i class="el-icon-folder" />
|
||||
</span>
|
||||
<span v-if=" data.status === 'Error'"
|
||||
style="margin-left: 6px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">
|
||||
<span
|
||||
v-if=" data.status === 'Error'"
|
||||
style="margin-left: 6px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;"
|
||||
>
|
||||
<el-tooltip effect="dark" :content="$t('datasource.in_valid')" placement="right">
|
||||
<span>
|
||||
{{ data.name }}
|
||||
</span>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<span v-if=" data.status === 'Warning'"
|
||||
style="margin-left: 6px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">
|
||||
<span
|
||||
v-if=" data.status === 'Warning'"
|
||||
style="margin-left: 6px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;"
|
||||
>
|
||||
<el-tooltip effect="dark" :content="$t('datasource.warning')" placement="right">
|
||||
<span>
|
||||
{{ data.name }}
|
||||
</span>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<span v-if="data.status !== 'Error' && data.status !== 'Warning'"
|
||||
style="margin-left: 6px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">
|
||||
<span
|
||||
v-if="data.status !== 'Error' && data.status !== 'Warning'"
|
||||
style="margin-left: 6px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;"
|
||||
>
|
||||
{{ data.name }}
|
||||
</span>
|
||||
|
||||
@ -103,7 +114,7 @@
|
||||
</el-col>
|
||||
</template>
|
||||
<script>
|
||||
import {listDatasource, listDatasourceByType, delDs, listDatasourceType} from '@/api/system/datasource'
|
||||
import { listDatasource, listDatasourceByType, delDs, listDatasourceType } from '@/api/system/datasource'
|
||||
|
||||
export default {
|
||||
name: 'DsTree',
|
||||
@ -162,14 +173,14 @@ export default {
|
||||
listDatasourceByType(datasource.type).then(res => {
|
||||
typeData = this.buildTree(res.data)
|
||||
if (typeData.length === 0) {
|
||||
let index = this.tData.findIndex(item => {
|
||||
const index = this.tData.findIndex(item => {
|
||||
if (item.id === datasource.type) {
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
})
|
||||
this.tData.splice(index, 1)
|
||||
} else {
|
||||
let find = false;
|
||||
let find = false
|
||||
for (let index = 0; index < this.tData.length; index++) {
|
||||
if (typeData[0].id === this.tData[index].id) {
|
||||
this.tData[index].children = typeData[0].children
|
||||
@ -212,7 +223,7 @@ export default {
|
||||
this.switchMain('DsForm', {}, this.tData, this.dsTypes)
|
||||
},
|
||||
addFolderWithType(data) {
|
||||
this.switchMain('DsForm', {type: data.id}, this.tData, this.dsTypes)
|
||||
this.switchMain('DsForm', { type: data.id }, this.tData, this.dsTypes)
|
||||
},
|
||||
nodeClick(node, data) {
|
||||
if (node.type === 'folder') return
|
||||
@ -220,7 +231,7 @@ export default {
|
||||
},
|
||||
|
||||
clickFileMore(param) {
|
||||
const {optType, data} = param
|
||||
const { optType, data } = param
|
||||
switch (optType) {
|
||||
case 'edit':
|
||||
this.edit(data)
|
||||
@ -233,13 +244,13 @@ export default {
|
||||
}
|
||||
},
|
||||
beforeClickFile(optType, data, node) {
|
||||
return {optType, data, node}
|
||||
return { optType, data, node }
|
||||
},
|
||||
edit(row) {
|
||||
this.switchMain('DsForm', row, this.tData, this.dsTypes)
|
||||
},
|
||||
showInfo(row) {
|
||||
const param = {...row.data, ...{showModel: 'show'}}
|
||||
const param = { ...row.data, ...{ showModel: 'show' }}
|
||||
this.switchMain('DsForm', param, this.tData, this.dsTypes)
|
||||
},
|
||||
_handleDelete(datasource) {
|
||||
@ -248,12 +259,13 @@ export default {
|
||||
cancelButtonText: this.$t('commons.cancel'),
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
delDs(datasource.id).then(res => {
|
||||
if(res.success){
|
||||
const parma = { type: datasource.type, id: datasource.id }
|
||||
delDs(parma).then(res => {
|
||||
if (res.success) {
|
||||
this.$success(this.$t('commons.delete_success'))
|
||||
this.switchMain('DataHome', {}, this.tData, this.dsTypes)
|
||||
this.refreshType(datasource)
|
||||
}else {
|
||||
} else {
|
||||
this.$message({
|
||||
type: 'error',
|
||||
message: res.message
|
||||
|
137
frontend/src/views/system/log/index.vue
Normal file
137
frontend/src/views/system/log/index.vue
Normal file
@ -0,0 +1,137 @@
|
||||
<template>
|
||||
<layout-content :header="$t('log.title')">
|
||||
<complex-table
|
||||
v-loading="$store.getters.loadingMap[$store.getters.currentPath]"
|
||||
:data="data"
|
||||
:columns="columns"
|
||||
local-key="logGrid"
|
||||
:search-config="searchConfig"
|
||||
:pagination-config="paginationConfig"
|
||||
@select="select"
|
||||
@search="search"
|
||||
@sort-change="sortChange"
|
||||
>
|
||||
<template #toolbar>
|
||||
<el-button v-permission="['log:export']" icon="el-icon-download" size="mini" @click="exportData">{{ $t('log.export') }}</el-button>
|
||||
</template>
|
||||
|
||||
<el-table-column prop="opType" :label="$t('log.optype')" width="120">
|
||||
<template v-slot:default="{row}">
|
||||
<span>{{ row.opType + row.sourceType }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :show-overflow-tooltip="true" prop="detail" :label="$t('log.detail')" />
|
||||
<el-table-column prop="user" :label="$t('log.user')" width="80" />
|
||||
<el-table-column :show-overflow-tooltip="true" prop="time" sortable="custom" :label="$t('log.time')" width="180">
|
||||
<template v-slot:default="scope">
|
||||
<span>{{ scope.row.time | timestampFormatDate }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</complex-table>
|
||||
</layout-content>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import LayoutContent from '@/components/business/LayoutContent'
|
||||
import ComplexTable from '@/components/business/complex-table'
|
||||
import { formatCondition, formatQuickCondition, addOrder, formatOrders } from '@/utils/index'
|
||||
import { logGrid, opTypes, exportExcel } from '@/api/system/log'
|
||||
export default {
|
||||
|
||||
components: { ComplexTable, LayoutContent },
|
||||
data() {
|
||||
return {
|
||||
columns: [],
|
||||
|
||||
searchConfig: {
|
||||
useQuickSearch: true,
|
||||
useComplexSearch: true,
|
||||
quickPlaceholder: this.$t('log.search_by_key'),
|
||||
components: [
|
||||
{
|
||||
field: 'optype',
|
||||
label: this.$t('log.optype'),
|
||||
component: 'FuComplexMixSelect',
|
||||
options: [],
|
||||
multiple: true,
|
||||
class: 'de-log-filter',
|
||||
defaultOperator: 'in'
|
||||
},
|
||||
{ field: 'nick_name', label: this.$t('log.user'), component: 'DeComplexInput', class: 'de-log-filter' },
|
||||
|
||||
{ field: 'time', label: this.$t('log.time'), component: 'FuComplexDateTime', defaultOperator: 'between', class: 'de-log-filter' }
|
||||
|
||||
]
|
||||
},
|
||||
|
||||
paginationConfig: {
|
||||
currentPage: 1,
|
||||
pageSize: 10,
|
||||
total: 0
|
||||
},
|
||||
data: [],
|
||||
types: [],
|
||||
|
||||
orderConditions: [],
|
||||
last_condition: null
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
created() {
|
||||
this.types = []
|
||||
opTypes().then(res => {
|
||||
const datas = res.data
|
||||
datas.forEach(item => {
|
||||
this.types.push({ 'label': item.name, 'value': item.id })
|
||||
})
|
||||
this.searchConfig.components[0].options = this.types
|
||||
})
|
||||
},
|
||||
mounted() {
|
||||
this.search()
|
||||
},
|
||||
|
||||
methods: {
|
||||
exportData() {
|
||||
console.log('exportting...')
|
||||
exportExcel().then(res => {
|
||||
|
||||
})
|
||||
},
|
||||
|
||||
sortChange({ column, prop, order }) {
|
||||
this.orderConditions = []
|
||||
if (!order) {
|
||||
this.search(this.last_condition)
|
||||
return
|
||||
}
|
||||
|
||||
this.orderConditions = []
|
||||
addOrder({ field: prop, value: order }, this.orderConditions)
|
||||
this.search(this.last_condition)
|
||||
},
|
||||
select(selection) {
|
||||
|
||||
},
|
||||
|
||||
search(condition) {
|
||||
this.last_condition = condition
|
||||
condition = formatQuickCondition(condition, 'key')
|
||||
const temp = formatCondition(condition)
|
||||
const param = temp || {}
|
||||
param['orders'] = formatOrders(this.orderConditions)
|
||||
const { currentPage, pageSize } = this.paginationConfig
|
||||
logGrid(currentPage, pageSize, param).then(response => {
|
||||
this.data = response.data.listObject
|
||||
this.paginationConfig.total = response.data.itemCount
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
Loading…
Reference in New Issue
Block a user