fix: 日志入库
This commit is contained in:
parent
fb918e67fb
commit
0ab915a03e
@ -8,6 +8,7 @@ import org.springframework.data.domain.Pageable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
@ -53,6 +54,11 @@ public class Result<T> {
|
||||
return new Result<>(SUCCESS, MSG_SUCCESS, data);
|
||||
}
|
||||
|
||||
public Result<T> end(Runnable runnable) {
|
||||
runnable.run();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个元素,附带分页信息,分页数据写死
|
||||
*
|
||||
|
@ -17,8 +17,8 @@ import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.data.util.CastUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
@ -30,6 +30,9 @@ import java.util.Optional;
|
||||
@Slf4j
|
||||
public class LogManager {
|
||||
|
||||
@Resource
|
||||
private LogService logService;
|
||||
|
||||
/**
|
||||
* 尝试记录日志
|
||||
*
|
||||
@ -67,13 +70,10 @@ public class LogManager {
|
||||
log.setResponse(Optional.ofNullable(result).map(JSON::toJSONString).orElse(null));
|
||||
log.setOperator(UserContext.sharedContext().map(UserContext::currentUser).map(Domain::getName).orElse("未知"));
|
||||
log.setSignature(joinPoint.getSignature().getName());
|
||||
log.setUri(Optional.ofNullable(AnnotationUtils.findAnnotation(targetClass, RequestMapping.class))
|
||||
.map(mapping -> mapping.value())
|
||||
.filter(ArrayUtils::isNotEmpty)
|
||||
.map(array -> array[0])
|
||||
);
|
||||
// 先不拼接
|
||||
log.setUri(null);
|
||||
// 写入日志
|
||||
logService.create()
|
||||
logService.create(log);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +84,8 @@ public abstract class BaseController<T extends Domain, Q extends Qo<T>> implemen
|
||||
|
||||
@DeleteMapping("{id}")
|
||||
@Operation.Delete
|
||||
public Result<T> remove(@PathVariable String id) {
|
||||
public Result<T> remove(@PathVariable String id, @CurrentUser User user) {
|
||||
userContext.setUser(user);
|
||||
service.deleteById(id);
|
||||
return Result.ok();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user