增加审计相关功能
This commit is contained in:
parent
0e4e320b94
commit
2eb38794c4
|
|
@ -25,6 +25,7 @@ import javax.annotation.Resource;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Date;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
|
|
@ -107,9 +108,11 @@ public class LoginInterceptor implements HandlerInterceptor {
|
|||
UserOperation userOperation = ((HandlerMethod) handler).getMethod().getAnnotation(UserOperation.class);
|
||||
String reqArgs = UserThreadLocal.getReqArgs();
|
||||
|
||||
UserLoginInfo user = Optional.of(UserThreadLocal.getUser()).orElse(new UserLoginInfo());
|
||||
|
||||
UserAccessLog userAccessLog = UserAccessLog.builder()
|
||||
.id(IdWorker.getSnowFlakeIdString())
|
||||
.userId(UserThreadLocal.getUserId())
|
||||
.userId(user.getUserId())
|
||||
.accessStartTime(DateUtil.date(accessStartTime))
|
||||
.accessEndTime(DateUtil.date(accessEndTime))
|
||||
.accessDuration(accessEndTime - accessStartTime)
|
||||
|
|
@ -122,9 +125,11 @@ public class LoginInterceptor implements HandlerInterceptor {
|
|||
.createTime(new Date())
|
||||
.operationModule(userOperation.modelName().key)
|
||||
.operationMsg(UserThreadLocal.getUser().getSuccessMsg())
|
||||
.dataId(user.getDataId())
|
||||
.parentId(user.getParentId())
|
||||
.build();
|
||||
|
||||
ElectromagneticResult<?> result = UserThreadLocal.getResult();
|
||||
ElectromagneticResult<?> result = user.getResult();
|
||||
if (result != null) {
|
||||
if (!result.getSuccess()) {
|
||||
userAccessLog.setAccessSuccess(false);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,39 @@
|
|||
package com.electromagnetic.industry.software.manage.controller;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import com.electromagnetic.industry.software.common.annotations.UserOperation;
|
||||
import com.electromagnetic.industry.software.common.enums.AdminTypeEnum;
|
||||
import com.electromagnetic.industry.software.common.enums.UserOperationModuleEnum;
|
||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.AccessLogQueryDTO;
|
||||
import com.electromagnetic.industry.software.manage.service.UserAccessLogService;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/data/ed/log/")
|
||||
public class AccessLogController {
|
||||
|
||||
@Resource
|
||||
private UserAccessLogService userAccessLogService;
|
||||
|
||||
@UserOperation(value = "查看操作记录", modelName = UserOperationModuleEnum.LOG)
|
||||
@RequestMapping("file")
|
||||
public ElectromagneticResult<?> file(@RequestBody AccessLogQueryDTO accessLogQueryDTO) {
|
||||
return userAccessLogService.info(accessLogQueryDTO, false);
|
||||
}
|
||||
|
||||
|
||||
@UserOperation(value = "查看审计", modelName = UserOperationModuleEnum.LOG)
|
||||
@RequestMapping("audit")
|
||||
public ElectromagneticResult<?> audit(@RequestBody AccessLogQueryDTO accessLogQueryDTO) {
|
||||
Assert.isTrue(UserThreadLocal.getAdminType().equals(AdminTypeEnum.AUDIT.getValue()), "当前用户没有查看审计的权限");
|
||||
return userAccessLogService.info(accessLogQueryDTO, true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -161,8 +161,4 @@ public class EdFileInfoController {
|
|||
return edFileInfoService.preview(id, response, DataOwnEnum.COMMON.code);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,12 +11,12 @@ import java.util.List;
|
|||
public class RespPageVO<T> implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private List<T> list;
|
||||
private List<T> records;
|
||||
|
||||
private long total;
|
||||
|
||||
public RespPageVO(long total, List<T> list) {
|
||||
this.list = list;
|
||||
public RespPageVO(long total, List<T> records) {
|
||||
this.records = records;
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1251,20 +1251,32 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
EdFileInfo fileInfo = this.baseMapper.selectById(id);
|
||||
Assert.isTrue(Objects.nonNull(fileInfo), "文件不存在");
|
||||
String fileSysPath = commonService.getFileSysPath(fileInfo.getFilePath(), dataOwnCode);
|
||||
EleCommonUtil.decryptFile(fileSysPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));
|
||||
String fileSaveTmpPath = tmpDir + File.separator + IdUtil.fastSimpleUUID() + "." + fileInfo.getFileType();
|
||||
FileUtil.copy(fileSysPath, fileSaveTmpPath, true);
|
||||
EleCommonUtil.decryptFile(fileSaveTmpPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));
|
||||
|
||||
if (Arrays.asList("doc", "docx").contains(fileInfo.getFileType())) {
|
||||
String pdfTmpPath = tmpDir + File.separator + fileInfo.getFileName() + "_" + IdUtil.fastSimpleUUID() + ".pdf";
|
||||
OfficeFileUtil.doc2pdf(fileSysPath, pdfTmpPath);
|
||||
fileSysPath = pdfTmpPath;
|
||||
OfficeFileUtil.doc2pdf(fileSaveTmpPath, pdfTmpPath);
|
||||
fileSaveTmpPath = pdfTmpPath;
|
||||
}
|
||||
FileSystemResource fileSystemResource = new FileSystemResource(fileSysPath);
|
||||
|
||||
String mimeType = Files.probeContentType(Paths.get(fileSaveTmpPath));
|
||||
if (mimeType == null) {
|
||||
// 如果无法探测到MIME类型,则使用默认值 application/octet-stream
|
||||
mimeType = "application/octet-stream";
|
||||
}
|
||||
|
||||
FileSystemResource fileSystemResource = new FileSystemResource(fileSaveTmpPath);
|
||||
String fileName = fileSystemResource.getFilename();
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
|
||||
headers.add("Pragma", "no-cache");
|
||||
headers.add("Expires", "0");
|
||||
|
||||
fileName = Base64.encode(fileName.substring(0, fileName.lastIndexOf(".")));
|
||||
response.setHeader("content-disposition", "attachment;filename=" + fileName);
|
||||
headers.add(HttpHeaders.CACHE_CONTROL, "no-cache, no-store, must-revalidate");
|
||||
headers.add(HttpHeaders.PRAGMA, "no-cache");
|
||||
headers.add(HttpHeaders.EXPIRES, "0");
|
||||
headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + fileName);
|
||||
headers.add(HttpHeaders.CONTENT_TYPE, mimeType);
|
||||
// 构建响应实体(可以返回<byte[]或Resource,返回类型取决body入参类型)
|
||||
UserThreadLocal.setSuccessInfo(fileInfo.getFileId(), "文件预览成功,文件名为 {}", fileInfo.getFileName() + "." + fileInfo.getFileType());
|
||||
return ResponseEntity
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.electromagnetic.industry.software.common.enums.UserOperationModuleEnum;
|
||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
||||
import com.electromagnetic.industry.software.manage.mapper.UserAccessLogMapper;
|
||||
|
|
@ -50,15 +51,20 @@ public class UserAccessLogServiceImpl extends ServiceImpl<UserAccessLogMapper, U
|
|||
Page<UserAccessLog> logs = this.baseMapper.selectPage(new Page<>(pars.getPageNum(), pars.getPageSize()), queryWrapper);
|
||||
List<UserAccessLog> records = logs.getRecords();
|
||||
List<AccessLogQueryVO> res = BeanUtil.copyToList(records, AccessLogQueryVO.class);
|
||||
setUserName(res);
|
||||
setOtherInfo(res);
|
||||
return ElectromagneticResultUtil.success(new RespPageVO<>(logs.getTotal(), res));
|
||||
}
|
||||
|
||||
private void setUserName(List<AccessLogQueryVO> res) {
|
||||
private void setOtherInfo(List<AccessLogQueryVO> res) {
|
||||
|
||||
List<String> userIds = res.stream().map(AccessLogQueryVO::getUserId).collect(Collectors.toList());
|
||||
LambdaQueryWrapper<User> wrapper = Wrappers.lambdaQuery(User.class).select(User::getUserId, User::getUserName).in(User::getUserId, userIds);
|
||||
Map<String, String> idNameMap = userMapper.selectList(wrapper).stream().collect(Collectors.toMap(User::getUserId, User::getUserName));
|
||||
res.forEach(e -> e.setUsername(idNameMap.get(e.getUserId())));
|
||||
|
||||
res.forEach(e -> {
|
||||
e.setUsername(idNameMap.get(e.getUserId()));
|
||||
e.setOperationModule(UserOperationModuleEnum.getDesc(e.getOperationModule()));
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package com.electromagnetic.industry.software.common.enums;
|
|||
|
||||
import lombok.AllArgsConstructor;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@AllArgsConstructor
|
||||
public enum UserOperationModuleEnum {
|
||||
|
||||
|
|
@ -11,9 +13,20 @@ public enum UserOperationModuleEnum {
|
|||
USER("user", "人员管理"),
|
||||
USER_PRJ("userPrj", "个人数据"),
|
||||
TAG("tag","标签管理"),
|
||||
LOG("log", "操作记录审计"),
|
||||
PERMISSION("permission", "权限管理");
|
||||
|
||||
public final String key;
|
||||
public final String desc;
|
||||
|
||||
|
||||
public static String getDesc(String key) {
|
||||
for (UserOperationModuleEnum e : UserOperationModuleEnum.values()) {
|
||||
if (Objects.equals(e.key, key)) {
|
||||
return e.desc;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue