新增审计日志功能(支持spEL表达式)
This commit is contained in:
+7
-1
@@ -12,6 +12,8 @@ import com.central.common.annotation.LoginUser;
|
||||
import com.central.common.constant.CommonConstant;
|
||||
import com.central.common.model.*;
|
||||
import com.central.common.utils.ExcelUtil;
|
||||
//import com.central.log.annotation.AuditLog;
|
||||
import com.central.log.annotation.AuditLog;
|
||||
import com.central.search.client.service.IQueryService;
|
||||
import com.central.search.model.LogicDelDto;
|
||||
import com.central.search.model.SearchDto;
|
||||
@@ -118,7 +120,8 @@ public class SysUserController {
|
||||
* @param sysUser
|
||||
*/
|
||||
@PutMapping("/users")
|
||||
@CachePut(value = "user", key = "#sysUser.username")
|
||||
@CachePut(value = "user", key = "#sysUser.username", unless="#result == null")
|
||||
//@AuditLog(operation = "'更新用户:' + #sysUser")
|
||||
public void updateSysUser(@RequestBody SysUser sysUser) {
|
||||
appUserService.updateById(sysUser);
|
||||
}
|
||||
@@ -187,6 +190,7 @@ public class SysUserController {
|
||||
* @param id
|
||||
*/
|
||||
@PutMapping(value = "/users/{id}/password")
|
||||
//@AuditLog(operation = "'重置用户密码:' + #id")
|
||||
public Result resetPassword(@PathVariable Long id) {
|
||||
if (checkAdmin(id)) {
|
||||
return Result.failed(ADMIN_CHANGE_MSG);
|
||||
@@ -213,6 +217,7 @@ public class SysUserController {
|
||||
* @param id
|
||||
*/
|
||||
@DeleteMapping(value = "/users/{id}")
|
||||
//@AuditLog(operation = "'删除用户:' + #id")
|
||||
public Result delete(@PathVariable Long id) {
|
||||
if (checkAdmin(id)) {
|
||||
return Result.failed(ADMIN_CHANGE_MSG);
|
||||
@@ -230,6 +235,7 @@ public class SysUserController {
|
||||
*/
|
||||
@CacheEvict(value = "user", key = "#sysUser.username")
|
||||
@PostMapping("/users/saveOrUpdate")
|
||||
@AuditLog(operation = "'新增或更新用户:' + #sysUser.username")
|
||||
public Result saveOrUpdate(@RequestBody SysUser sysUser) {
|
||||
return appUserService.saveOrUpdateUser(sysUser);
|
||||
}
|
||||
|
||||
@@ -34,4 +34,7 @@ zlt:
|
||||
- sys_role_user
|
||||
- sys_role_menu
|
||||
ignoreSqls:
|
||||
- com.central.user.mapper.SysRoleMapper.findAll
|
||||
- com.central.user.mapper.SysRoleMapper.findAll
|
||||
#审计日志
|
||||
# audit-log:
|
||||
# enabled: true
|
||||
+31
@@ -2,6 +2,8 @@ package com.central.user.controller;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@@ -80,7 +82,36 @@ public class SysUserControllerTest {
|
||||
@Transactional
|
||||
public void whenDeleteSuccess() throws Exception {
|
||||
mockMvc.perform(delete("/users/1")
|
||||
.header("x-userid-header", 1)
|
||||
.header("x-user-header", "admin")
|
||||
.header("x-tenant-header", "webApp")
|
||||
.contentType(MediaType.APPLICATION_JSON_UTF8))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void whenSaveOrUpdateSuccess() throws Exception {
|
||||
String content = "{\"id\":1, \"username\":\"admin\", \"roleId\":\"1,2,3\"}";
|
||||
mockMvc.perform(post("/users/saveOrUpdate")
|
||||
.header("x-userid-header", 1)
|
||||
.header("x-user-header", "admin")
|
||||
.header("x-tenant-header", "webApp")
|
||||
.contentType(MediaType.APPLICATION_JSON_UTF8)
|
||||
.content(content))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void whenUpdateSuccess() throws Exception {
|
||||
String content = "{\"id\":1, \"username\":\"admin\", \"roleId\":\"1,2,3\"}";
|
||||
mockMvc.perform(put("/users")
|
||||
.header("x-userid-header", 1)
|
||||
.header("x-user-header", "admin")
|
||||
.header("x-tenant-header", "webApp")
|
||||
.contentType(MediaType.APPLICATION_JSON_UTF8)
|
||||
.content(content))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user