Compare commits
No commits in common. "26954302dee5146c55266e2ec72fea7e04ec4675" and "c389f408481e5eaf532024f7486a7770521ca26d" have entirely different histories.
26954302de
...
c389f40848
|
|
@ -25,7 +25,6 @@ import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
|
@ -108,11 +107,9 @@ public class LoginInterceptor implements HandlerInterceptor {
|
||||||
UserOperation userOperation = ((HandlerMethod) handler).getMethod().getAnnotation(UserOperation.class);
|
UserOperation userOperation = ((HandlerMethod) handler).getMethod().getAnnotation(UserOperation.class);
|
||||||
String reqArgs = UserThreadLocal.getReqArgs();
|
String reqArgs = UserThreadLocal.getReqArgs();
|
||||||
|
|
||||||
UserLoginInfo user = Optional.of(UserThreadLocal.getUser()).orElse(new UserLoginInfo());
|
|
||||||
|
|
||||||
UserAccessLog userAccessLog = UserAccessLog.builder()
|
UserAccessLog userAccessLog = UserAccessLog.builder()
|
||||||
.id(IdWorker.getSnowFlakeIdString())
|
.id(IdWorker.getSnowFlakeIdString())
|
||||||
.userId(user.getUserId())
|
.userId(UserThreadLocal.getUserId())
|
||||||
.accessStartTime(DateUtil.date(accessStartTime))
|
.accessStartTime(DateUtil.date(accessStartTime))
|
||||||
.accessEndTime(DateUtil.date(accessEndTime))
|
.accessEndTime(DateUtil.date(accessEndTime))
|
||||||
.accessDuration(accessEndTime - accessStartTime)
|
.accessDuration(accessEndTime - accessStartTime)
|
||||||
|
|
@ -125,11 +122,9 @@ public class LoginInterceptor implements HandlerInterceptor {
|
||||||
.createTime(new Date())
|
.createTime(new Date())
|
||||||
.operationModule(userOperation.modelName().key)
|
.operationModule(userOperation.modelName().key)
|
||||||
.operationMsg(UserThreadLocal.getUser().getSuccessMsg())
|
.operationMsg(UserThreadLocal.getUser().getSuccessMsg())
|
||||||
.dataId(user.getDataId())
|
|
||||||
.parentId(user.getParentId())
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
ElectromagneticResult<?> result = user.getResult();
|
ElectromagneticResult<?> result = UserThreadLocal.getResult();
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
if (!result.getSuccess()) {
|
if (!result.getSuccess()) {
|
||||||
userAccessLog.setAccessSuccess(false);
|
userAccessLog.setAccessSuccess(false);
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,11 @@
|
||||||
package com.electromagnetic.industry.software.manage.controller;
|
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 org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/data/ed/log/")
|
|
||||||
public class AccessLogController {
|
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,4 +161,8 @@ public class EdFileInfoController {
|
||||||
return edFileInfoService.preview(id, response, DataOwnEnum.COMMON.code);
|
return edFileInfoService.preview(id, response, DataOwnEnum.COMMON.code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,12 @@ import java.util.List;
|
||||||
public class RespPageVO<T> implements Serializable {
|
public class RespPageVO<T> implements Serializable {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private List<T> records;
|
private List<T> list;
|
||||||
|
|
||||||
private long total;
|
private long total;
|
||||||
|
|
||||||
public RespPageVO(long total, List<T> records) {
|
public RespPageVO(long total, List<T> list) {
|
||||||
this.records = records;
|
this.list = list;
|
||||||
this.total = total;
|
this.total = total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1251,32 +1251,20 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
||||||
EdFileInfo fileInfo = this.baseMapper.selectById(id);
|
EdFileInfo fileInfo = this.baseMapper.selectById(id);
|
||||||
Assert.isTrue(Objects.nonNull(fileInfo), "文件不存在");
|
Assert.isTrue(Objects.nonNull(fileInfo), "文件不存在");
|
||||||
String fileSysPath = commonService.getFileSysPath(fileInfo.getFilePath(), dataOwnCode);
|
String fileSysPath = commonService.getFileSysPath(fileInfo.getFilePath(), dataOwnCode);
|
||||||
String fileSaveTmpPath = tmpDir + File.separator + IdUtil.fastSimpleUUID() + "." + fileInfo.getFileType();
|
EleCommonUtil.decryptFile(fileSysPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));
|
||||||
FileUtil.copy(fileSysPath, fileSaveTmpPath, true);
|
|
||||||
EleCommonUtil.decryptFile(fileSaveTmpPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));
|
|
||||||
|
|
||||||
if (Arrays.asList("doc", "docx").contains(fileInfo.getFileType())) {
|
if (Arrays.asList("doc", "docx").contains(fileInfo.getFileType())) {
|
||||||
String pdfTmpPath = tmpDir + File.separator + fileInfo.getFileName() + "_" + IdUtil.fastSimpleUUID() + ".pdf";
|
String pdfTmpPath = tmpDir + File.separator + fileInfo.getFileName() + "_" + IdUtil.fastSimpleUUID() + ".pdf";
|
||||||
OfficeFileUtil.doc2pdf(fileSaveTmpPath, pdfTmpPath);
|
OfficeFileUtil.doc2pdf(fileSysPath, pdfTmpPath);
|
||||||
fileSaveTmpPath = pdfTmpPath;
|
fileSysPath = 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();
|
String fileName = fileSystemResource.getFilename();
|
||||||
HttpHeaders headers = new HttpHeaders();
|
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(".")));
|
fileName = Base64.encode(fileName.substring(0, fileName.lastIndexOf(".")));
|
||||||
headers.add(HttpHeaders.CACHE_CONTROL, "no-cache, no-store, must-revalidate");
|
response.setHeader("content-disposition", "attachment;filename=" + fileName);
|
||||||
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入参类型)
|
// 构建响应实体(可以返回<byte[]或Resource,返回类型取决body入参类型)
|
||||||
UserThreadLocal.setSuccessInfo(fileInfo.getFileId(), "文件预览成功,文件名为 {}", fileInfo.getFileName() + "." + fileInfo.getFileType());
|
UserThreadLocal.setSuccessInfo(fileInfo.getFileId(), "文件预览成功,文件名为 {}", fileInfo.getFileName() + "." + fileInfo.getFileType());
|
||||||
return ResponseEntity
|
return ResponseEntity
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
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.resp.ElectromagneticResult;
|
||||||
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
||||||
import com.electromagnetic.industry.software.manage.mapper.UserAccessLogMapper;
|
import com.electromagnetic.industry.software.manage.mapper.UserAccessLogMapper;
|
||||||
|
|
@ -51,20 +50,15 @@ public class UserAccessLogServiceImpl extends ServiceImpl<UserAccessLogMapper, U
|
||||||
Page<UserAccessLog> logs = this.baseMapper.selectPage(new Page<>(pars.getPageNum(), pars.getPageSize()), queryWrapper);
|
Page<UserAccessLog> logs = this.baseMapper.selectPage(new Page<>(pars.getPageNum(), pars.getPageSize()), queryWrapper);
|
||||||
List<UserAccessLog> records = logs.getRecords();
|
List<UserAccessLog> records = logs.getRecords();
|
||||||
List<AccessLogQueryVO> res = BeanUtil.copyToList(records, AccessLogQueryVO.class);
|
List<AccessLogQueryVO> res = BeanUtil.copyToList(records, AccessLogQueryVO.class);
|
||||||
setOtherInfo(res);
|
setUserName(res);
|
||||||
return ElectromagneticResultUtil.success(new RespPageVO<>(logs.getTotal(), res));
|
return ElectromagneticResultUtil.success(new RespPageVO<>(logs.getTotal(), res));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setOtherInfo(List<AccessLogQueryVO> res) {
|
private void setUserName(List<AccessLogQueryVO> res) {
|
||||||
|
|
||||||
List<String> userIds = res.stream().map(AccessLogQueryVO::getUserId).collect(Collectors.toList());
|
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);
|
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));
|
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,8 +2,6 @@ package com.electromagnetic.industry.software.common.enums;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum UserOperationModuleEnum {
|
public enum UserOperationModuleEnum {
|
||||||
|
|
||||||
|
|
@ -13,20 +11,9 @@ public enum UserOperationModuleEnum {
|
||||||
USER("user", "人员管理"),
|
USER("user", "人员管理"),
|
||||||
USER_PRJ("userPrj", "个人数据"),
|
USER_PRJ("userPrj", "个人数据"),
|
||||||
TAG("tag","标签管理"),
|
TAG("tag","标签管理"),
|
||||||
LOG("log", "操作记录审计"),
|
|
||||||
PERMISSION("permission", "权限管理");
|
PERMISSION("permission", "权限管理");
|
||||||
|
|
||||||
public final String key;
|
public final String key;
|
||||||
public final String desc;
|
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