mirror of https://github.com/elunez/eladmin
[代码优化](v2.6):日志请求参数获取优化,日志优化
parent
53af24e1eb
commit
4a69bb4a52
|
@ -64,7 +64,8 @@ public class RedisConfig extends CachingConfigurerSupport {
|
|||
public RedisCacheConfiguration redisCacheConfiguration(){
|
||||
FastJsonRedisSerializer<Object> fastJsonRedisSerializer = new FastJsonRedisSerializer<>(Object.class);
|
||||
RedisCacheConfiguration configuration = RedisCacheConfiguration.defaultCacheConfig();
|
||||
configuration = configuration.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(fastJsonRedisSerializer)).entryTtl(Duration.ofHours(2));
|
||||
configuration = configuration.serializeValuesWith(RedisSerializationContext.
|
||||
SerializationPair.fromSerializer(fastJsonRedisSerializer)).entryTtl(Duration.ofHours(6));
|
||||
return configuration;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
*/
|
||||
package me.zhengjie.annotation;
|
||||
|
||||
import me.zhengjie.annotation.type.LogActionType;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
@ -30,13 +28,4 @@ import java.lang.annotation.Target;
|
|||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Log {
|
||||
String value() default "";
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
boolean enable() default true;
|
||||
|
||||
LogActionType type() default LogActionType.SELECT;
|
||||
}
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* Copyright 2019-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package me.zhengjie.annotation.type;
|
||||
|
||||
/**
|
||||
* @author: liaojinlong
|
||||
* @date: 2020/6/11 19:47
|
||||
* @apiNote: 日志类型
|
||||
*/
|
||||
|
||||
public enum LogActionType {
|
||||
/**
|
||||
* 增删改查
|
||||
*/
|
||||
ADD("新增"),
|
||||
SELECT("查询"),
|
||||
UPDATE("更新"),
|
||||
DELETE("删除");
|
||||
private String value;
|
||||
|
||||
LogActionType(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
|
@ -18,6 +18,7 @@ package me.zhengjie.service.impl;
|
|||
import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.zhengjie.domain.Log;
|
||||
import me.zhengjie.repository.LogRepository;
|
||||
|
@ -34,10 +35,13 @@ import org.springframework.data.domain.Page;
|
|||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
|
@ -84,13 +88,6 @@ public class LogServiceImpl implements LogService {
|
|||
// 方法路径
|
||||
String methodName = joinPoint.getTarget().getClass().getName() + "." + signature.getName() + "()";
|
||||
|
||||
StringBuilder params = new StringBuilder("{");
|
||||
//参数值
|
||||
List<Object> argValues = new ArrayList<>(Arrays.asList(joinPoint.getArgs()));
|
||||
//参数名称
|
||||
for (Object argValue : argValues) {
|
||||
params.append(argValue).append(" ");
|
||||
}
|
||||
// 描述
|
||||
if (log != null) {
|
||||
log.setDescription(aopLog.value());
|
||||
|
@ -98,22 +95,44 @@ public class LogServiceImpl implements LogService {
|
|||
assert log != null;
|
||||
log.setRequestIp(ip);
|
||||
|
||||
String loginPath = "login";
|
||||
if (loginPath.equals(signature.getName())) {
|
||||
try {
|
||||
username = new JSONObject(argValues.get(0)).get("username").toString();
|
||||
} catch (Exception e) {
|
||||
LogServiceImpl.log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
log.setAddress(StringUtils.getCityInfo(log.getRequestIp()));
|
||||
log.setMethod(methodName);
|
||||
log.setUsername(username);
|
||||
log.setParams(params.toString() + " }");
|
||||
log.setParams(getParameter(method, joinPoint.getArgs()));
|
||||
log.setBrowser(browser);
|
||||
logRepository.save(log);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据方法和传入的参数获取请求参数
|
||||
*/
|
||||
private String getParameter(Method method, Object[] args) {
|
||||
List<Object> argList = new ArrayList<>();
|
||||
Parameter[] parameters = method.getParameters();
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
//将RequestBody注解修饰的参数作为请求参数
|
||||
RequestBody requestBody = parameters[i].getAnnotation(RequestBody.class);
|
||||
if (requestBody != null) {
|
||||
argList.add(args[i]);
|
||||
}
|
||||
//将RequestParam注解修饰的参数作为请求参数
|
||||
RequestParam requestParam = parameters[i].getAnnotation(RequestParam.class);
|
||||
if (requestParam != null) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
String key = parameters[i].getName();
|
||||
if (!StringUtils.isEmpty(requestParam.value())) {
|
||||
key = requestParam.value();
|
||||
}
|
||||
map.put(key, args[i]);
|
||||
argList.add(map);
|
||||
}
|
||||
}
|
||||
if (argList.size() == 0) {
|
||||
return "";
|
||||
}
|
||||
return argList.size() == 1 ? JSONUtil.toJsonStr(argList.get(0)) : JSONUtil.toJsonStr(argList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object findByErrDetail(Long id) {
|
||||
Log log = logRepository.findById(id).orElseGet(Log::new);
|
||||
|
|
|
@ -44,7 +44,6 @@ public class AppController {
|
|||
|
||||
private final AppService appService;
|
||||
|
||||
@Log("导出应用数据")
|
||||
@ApiOperation("导出应用数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('app:list')")
|
||||
|
@ -52,7 +51,6 @@ public class AppController {
|
|||
appService.download(appService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@Log("查询应用")
|
||||
@ApiOperation(value = "查询应用")
|
||||
@GetMapping
|
||||
@PreAuthorize("@el.check('app:list')")
|
||||
|
|
|
@ -52,7 +52,6 @@ public class DatabaseController {
|
|||
private final String fileSavePath = FileUtil.getTmpDirPath()+"/";
|
||||
private final DatabaseService databaseService;
|
||||
|
||||
@Log("导出数据库数据")
|
||||
@ApiOperation("导出数据库数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('database:list')")
|
||||
|
@ -60,7 +59,6 @@ public class DatabaseController {
|
|||
databaseService.download(databaseService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@Log("查询数据库")
|
||||
@ApiOperation(value = "查询数据库")
|
||||
@GetMapping
|
||||
@PreAuthorize("@el.check('database:list')")
|
||||
|
|
|
@ -54,7 +54,6 @@ public class DeployController {
|
|||
private final DeployService deployService;
|
||||
|
||||
|
||||
@Log("导出部署数据")
|
||||
@ApiOperation("导出部署数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('database:list')")
|
||||
|
@ -62,7 +61,6 @@ public class DeployController {
|
|||
deployService.download(deployService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@Log("查询部署")
|
||||
@ApiOperation(value = "查询部署")
|
||||
@GetMapping
|
||||
@PreAuthorize("@el.check('deploy:list')")
|
||||
|
|
|
@ -42,7 +42,6 @@ public class DeployHistoryController {
|
|||
|
||||
private final DeployHistoryService deployhistoryService;
|
||||
|
||||
@Log("导出部署历史数据")
|
||||
@ApiOperation("导出部署历史数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('deployHistory:list')")
|
||||
|
@ -50,7 +49,6 @@ public class DeployHistoryController {
|
|||
deployhistoryService.download(deployhistoryService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@Log("查询部署历史")
|
||||
@ApiOperation(value = "查询部署历史")
|
||||
@GetMapping
|
||||
@PreAuthorize("@el.check('deployHistory:list')")
|
||||
|
|
|
@ -44,7 +44,6 @@ public class ServerDeployController {
|
|||
|
||||
private final ServerDeployService serverDeployService;
|
||||
|
||||
@Log("导出服务器数据")
|
||||
@ApiOperation("导出服务器数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('serverDeploy:list')")
|
||||
|
@ -52,7 +51,6 @@ public class ServerDeployController {
|
|||
serverDeployService.download(serverDeployService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@Log("查询服务器")
|
||||
@ApiOperation(value = "查询服务器")
|
||||
@GetMapping
|
||||
@PreAuthorize("@el.check('serverDeploy:list')")
|
||||
|
|
|
@ -48,7 +48,6 @@ public class QuartzJobController {
|
|||
private static final String ENTITY_NAME = "quartzJob";
|
||||
private final QuartzJobService quartzJobService;
|
||||
|
||||
@Log("查询定时任务")
|
||||
@ApiOperation("查询定时任务")
|
||||
@GetMapping
|
||||
@PreAuthorize("@el.check('timing:list')")
|
||||
|
@ -56,7 +55,6 @@ public class QuartzJobController {
|
|||
return new ResponseEntity<>(quartzJobService.queryAll(criteria,pageable), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("导出任务数据")
|
||||
@ApiOperation("导出任务数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('timing:list')")
|
||||
|
@ -64,7 +62,6 @@ public class QuartzJobController {
|
|||
quartzJobService.download(quartzJobService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@Log("导出日志数据")
|
||||
@ApiOperation("导出日志数据")
|
||||
@GetMapping(value = "/logs/download")
|
||||
@PreAuthorize("@el.check('timing:list')")
|
||||
|
|
|
@ -71,7 +71,6 @@ public class AuthorizationController {
|
|||
@Resource
|
||||
private LoginProperties loginProperties;
|
||||
|
||||
@Log("用户登录")
|
||||
@ApiOperation("登录授权")
|
||||
@AnonymousPostMapping(value = "/login")
|
||||
public ResponseEntity<Object> login(@Validated @RequestBody AuthUserDto authUser, HttpServletRequest request) throws Exception {
|
||||
|
|
|
@ -18,7 +18,6 @@ package me.zhengjie.modules.security.rest;
|
|||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.zhengjie.annotation.Log;
|
||||
import me.zhengjie.modules.security.service.OnlineUserService;
|
||||
import me.zhengjie.utils.EncryptUtils;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
@ -48,7 +47,6 @@ public class OnlineController {
|
|||
return new ResponseEntity<>(onlineUserService.getAll(filter, pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("导出数据")
|
||||
@ApiOperation("导出数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check()")
|
||||
|
|
|
@ -17,7 +17,6 @@ package me.zhengjie.modules.security.service.dto;
|
|||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
|
@ -37,9 +36,4 @@ public class AuthUserDto {
|
|||
private String code;
|
||||
|
||||
private String uuid = "";
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{username=" + username + ", password= ******}";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,6 @@ public class DeptController {
|
|||
private final DeptService deptService;
|
||||
private static final String ENTITY_NAME = "dept";
|
||||
|
||||
@Log("导出部门数据")
|
||||
@ApiOperation("导出部门数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('dept:list')")
|
||||
|
@ -56,7 +55,6 @@ public class DeptController {
|
|||
deptService.download(deptService.queryAll(criteria, false), response);
|
||||
}
|
||||
|
||||
@Log("查询部门")
|
||||
@ApiOperation("查询部门")
|
||||
@GetMapping
|
||||
@PreAuthorize("@el.check('user:list','dept:list')")
|
||||
|
@ -65,7 +63,6 @@ public class DeptController {
|
|||
return new ResponseEntity<>(PageUtil.toPage(deptDtos, deptDtos.size()),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("查询部门")
|
||||
@ApiOperation("查询部门:根据ID获取同级与上级数据")
|
||||
@PostMapping("/superior")
|
||||
@PreAuthorize("@el.check('user:list','dept:list')")
|
||||
|
|
|
@ -46,7 +46,6 @@ public class DictController {
|
|||
private final DictService dictService;
|
||||
private static final String ENTITY_NAME = "dict";
|
||||
|
||||
@Log("导出字典数据")
|
||||
@ApiOperation("导出字典数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('dict:list')")
|
||||
|
@ -54,7 +53,6 @@ public class DictController {
|
|||
dictService.download(dictService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@Log("查询字典")
|
||||
@ApiOperation("查询字典")
|
||||
@GetMapping(value = "/all")
|
||||
@PreAuthorize("@el.check('dict:list')")
|
||||
|
@ -62,7 +60,6 @@ public class DictController {
|
|||
return new ResponseEntity<>(dictService.queryAll(new DictQueryCriteria()),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("查询字典")
|
||||
@ApiOperation("查询字典")
|
||||
@GetMapping
|
||||
@PreAuthorize("@el.check('dict:list')")
|
||||
|
|
|
@ -50,7 +50,6 @@ public class DictDetailController {
|
|||
private final DictDetailService dictDetailService;
|
||||
private static final String ENTITY_NAME = "dictDetail";
|
||||
|
||||
@Log("查询字典详情")
|
||||
@ApiOperation("查询字典详情")
|
||||
@GetMapping
|
||||
public ResponseEntity<Object> query(DictDetailQueryCriteria criteria,
|
||||
|
@ -58,7 +57,6 @@ public class DictDetailController {
|
|||
return new ResponseEntity<>(dictDetailService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("查询多个字典详情")
|
||||
@ApiOperation("查询多个字典详情")
|
||||
@GetMapping(value = "/map")
|
||||
public ResponseEntity<Object> getDictDetailMaps(@RequestParam String dictName){
|
||||
|
|
|
@ -47,7 +47,6 @@ public class JobController {
|
|||
private final JobService jobService;
|
||||
private static final String ENTITY_NAME = "job";
|
||||
|
||||
@Log("导出岗位数据")
|
||||
@ApiOperation("导出岗位数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('job:list')")
|
||||
|
@ -55,7 +54,6 @@ public class JobController {
|
|||
jobService.download(jobService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@Log("查询岗位")
|
||||
@ApiOperation("查询岗位")
|
||||
@GetMapping
|
||||
@PreAuthorize("@el.check('job:list','user:list')")
|
||||
|
|
|
@ -51,7 +51,6 @@ public class MenuController {
|
|||
private final MenuMapper menuMapper;
|
||||
private static final String ENTITY_NAME = "menu";
|
||||
|
||||
@Log("导出菜单数据")
|
||||
@ApiOperation("导出菜单数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('menu:list')")
|
||||
|
@ -74,16 +73,14 @@ public class MenuController {
|
|||
return new ResponseEntity<>(menuService.getMenus(pid),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("查询菜单")
|
||||
@ApiOperation("查询菜单")
|
||||
@GetMapping
|
||||
@ApiOperation("查询菜单")
|
||||
@PreAuthorize("@el.check('menu:list')")
|
||||
public ResponseEntity<Object> query(MenuQueryCriteria criteria) throws Exception {
|
||||
List<MenuDto> menuDtoList = menuService.queryAll(criteria, true);
|
||||
return new ResponseEntity<>(PageUtil.toPage(menuDtoList, menuDtoList.size()),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("查询菜单")
|
||||
@ApiOperation("查询菜单:根据ID获取同级与上级数据")
|
||||
@PostMapping("/superior")
|
||||
@PreAuthorize("@el.check('menu:list')")
|
||||
|
|
|
@ -61,7 +61,6 @@ public class RoleController {
|
|||
return new ResponseEntity<>(roleService.findById(id), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("导出角色数据")
|
||||
@ApiOperation("导出角色数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('role:list')")
|
||||
|
@ -76,7 +75,6 @@ public class RoleController {
|
|||
return new ResponseEntity<>(roleService.queryAll(),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("查询角色")
|
||||
@ApiOperation("查询角色")
|
||||
@GetMapping
|
||||
@PreAuthorize("@el.check('roles:list')")
|
||||
|
|
|
@ -66,7 +66,6 @@ public class UserController {
|
|||
private final RoleService roleService;
|
||||
private final VerifyService verificationCodeService;
|
||||
|
||||
@Log("导出用户数据")
|
||||
@ApiOperation("导出用户数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('user:list')")
|
||||
|
@ -74,7 +73,6 @@ public class UserController {
|
|||
userService.download(userService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@Log("查询用户")
|
||||
@ApiOperation("查询用户")
|
||||
@GetMapping
|
||||
@PreAuthorize("@el.check('user:list')")
|
||||
|
|
|
@ -22,7 +22,6 @@ import me.zhengjie.exception.BadRequestException;
|
|||
import me.zhengjie.service.LocalStorageService;
|
||||
import me.zhengjie.service.dto.LocalStorageQueryCriteria;
|
||||
import me.zhengjie.utils.FileUtil;
|
||||
import me.zhengjie.utils.SecurityUtils;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -31,7 +30,6 @@ import org.springframework.validation.annotation.Validated;
|
|||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -54,7 +52,6 @@ public class LocalStorageController {
|
|||
return new ResponseEntity<>(localStorageService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("导出数据")
|
||||
@ApiOperation("导出数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('storage:list')")
|
||||
|
@ -70,7 +67,6 @@ public class LocalStorageController {
|
|||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@Log("上传图片")
|
||||
@PostMapping("/pictures")
|
||||
@ApiOperation("上传图片")
|
||||
public ResponseEntity<Object> upload(@RequestParam MultipartFile file){
|
||||
|
@ -83,6 +79,7 @@ public class LocalStorageController {
|
|||
return new ResponseEntity<>(localStorage, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("修改文件")
|
||||
@ApiOperation("修改文件")
|
||||
@PutMapping
|
||||
@PreAuthorize("@el.check('storage:edit')")
|
||||
|
@ -91,7 +88,7 @@ public class LocalStorageController {
|
|||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Log("多选删除")
|
||||
@Log("删除文件")
|
||||
@DeleteMapping
|
||||
@ApiOperation("多选删除")
|
||||
public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
|
||||
|
|
|
@ -63,14 +63,12 @@ public class QiniuController {
|
|||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("导出数据")
|
||||
@ApiOperation("导出数据")
|
||||
@GetMapping(value = "/download")
|
||||
public void download(HttpServletResponse response, QiniuQueryCriteria criteria) throws IOException {
|
||||
qiNiuService.downloadList(qiNiuService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@Log("查询文件")
|
||||
@ApiOperation("查询文件")
|
||||
@GetMapping
|
||||
public ResponseEntity<Object> query(QiniuQueryCriteria criteria, Pageable pageable){
|
||||
|
|
Loading…
Reference in New Issue