Compare commits

..

No commits in common. "26954302dee5146c55266e2ec72fea7e04ec4675" and "c389f408481e5eaf532024f7486a7770521ca26d" have entirely different histories.

7 changed files with 20 additions and 80 deletions

View File

@ -25,7 +25,6 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.Optional;
@Component
@Slf4j
@ -108,11 +107,9 @@ 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(user.getUserId())
.userId(UserThreadLocal.getUserId())
.accessStartTime(DateUtil.date(accessStartTime))
.accessEndTime(DateUtil.date(accessEndTime))
.accessDuration(accessEndTime - accessStartTime)
@ -125,11 +122,9 @@ 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 = user.getResult();
ElectromagneticResult<?> result = UserThreadLocal.getResult();
if (result != null) {
if (!result.getSuccess()) {
userAccessLog.setAccessSuccess(false);

View File

@ -1,39 +1,11 @@
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);
}
}

View File

@ -161,4 +161,8 @@ public class EdFileInfoController {
return edFileInfoService.preview(id, response, DataOwnEnum.COMMON.code);
}
}

View File

@ -11,12 +11,12 @@ import java.util.List;
public class RespPageVO<T> implements Serializable {
private static final long serialVersionUID = 1L;
private List<T> records;
private List<T> list;
private long total;
public RespPageVO(long total, List<T> records) {
this.records = records;
public RespPageVO(long total, List<T> list) {
this.list = list;
this.total = total;
}

View File

@ -1251,32 +1251,20 @@ 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);
String fileSaveTmpPath = tmpDir + File.separator + IdUtil.fastSimpleUUID() + "." + fileInfo.getFileType();
FileUtil.copy(fileSysPath, fileSaveTmpPath, true);
EleCommonUtil.decryptFile(fileSaveTmpPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));
EleCommonUtil.decryptFile(fileSysPath, 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(fileSaveTmpPath, pdfTmpPath);
fileSaveTmpPath = pdfTmpPath;
OfficeFileUtil.doc2pdf(fileSysPath, pdfTmpPath);
fileSysPath = pdfTmpPath;
}
String mimeType = Files.probeContentType(Paths.get(fileSaveTmpPath));
if (mimeType == null) {
// 如果无法探测到MIME类型则使用默认值 application/octet-stream
mimeType = "application/octet-stream";
}
FileSystemResource fileSystemResource = new FileSystemResource(fileSaveTmpPath);
FileSystemResource fileSystemResource = new FileSystemResource(fileSysPath);
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(".")));
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);
response.setHeader("content-disposition", "attachment;filename=" + fileName);
// 构建响应实体(可以返回<byte[]或Resource返回类型取决body入参类型)
UserThreadLocal.setSuccessInfo(fileInfo.getFileId(), "文件预览成功,文件名为 {}", fileInfo.getFileName() + "." + fileInfo.getFileType());
return ResponseEntity

View File

@ -5,7 +5,6 @@ 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;
@ -51,20 +50,15 @@ 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);
setOtherInfo(res);
setUserName(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());
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()));
e.setOperationModule(UserOperationModuleEnum.getDesc(e.getOperationModule()));
});
res.forEach(e -> e.setUsername(idNameMap.get(e.getUserId())));
}
}

View File

@ -2,8 +2,6 @@ package com.electromagnetic.industry.software.common.enums;
import lombok.AllArgsConstructor;
import java.util.Objects;
@AllArgsConstructor
public enum UserOperationModuleEnum {
@ -13,20 +11,9 @@ 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 "";
}
}