This commit is contained in:
s2042968 2025-02-26 16:53:27 +08:00
commit 38fcdcb859
16 changed files with 145 additions and 48 deletions

View File

@ -32,7 +32,7 @@ public class FileController {
public ElectromagneticResult<?> upload(@RequestParam("file") MultipartFile file, @RequestParam("path") String path) { public ElectromagneticResult<?> upload(@RequestParam("file") MultipartFile file, @RequestParam("path") String path) {
BackupFileResLog backupFileResLog = BackupFileResLog.builder().backupStartTime(new Date()).fileName(file.getOriginalFilename()).backupStatus(true).build(); BackupFileResLog backupFileResLog = BackupFileResLog.builder().backupStartTime(new Date()).fileName(file.getOriginalFilename()).backupStatus(true).build();
try { try {
fileService.upload(file, path); fileService.upload(file);
} catch (Exception e) { } catch (Exception e) {
String details = ExceptionUtil.stacktraceToString(e); String details = ExceptionUtil.stacktraceToString(e);
backupFileResLog.setBackupStatus(false); backupFileResLog.setBackupStatus(false);

View File

@ -6,6 +6,6 @@ import java.io.IOException;
public interface FileService { public interface FileService {
void upload(MultipartFile file, String path) throws IOException; void upload(MultipartFile file) throws IOException;
} }

View File

@ -17,10 +17,10 @@ public class FileServiceImpl implements FileService {
private BackupPro backupPro; private BackupPro backupPro;
@Override @Override
public void upload(MultipartFile file, String path) throws IOException { public void upload(MultipartFile file) throws IOException {
String saveFolder = backupPro.getSaveFolder(); String saveFolder = backupPro.getSaveFolder();
String fileName = file.getOriginalFilename(); String fileName = file.getOriginalFilename();
String destPath = saveFolder + File.separator + path + File.separator + fileName; String destPath = saveFolder + File.separator + File.separator + fileName;
if (!FileUtil.exist(destPath)) { if (!FileUtil.exist(destPath)) {
FileUtil.writeFromStream(file.getInputStream(), destPath); FileUtil.writeFromStream(file.getInputStream(), destPath);
} }

View File

@ -2,6 +2,7 @@ package com.electromagnetic.industry.software.manage.config;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.SystemClock; import cn.hutool.core.date.SystemClock;
import cn.hutool.json.JSONUtil;
import com.electromagnetic.industry.software.common.annotations.UserOperation; import com.electromagnetic.industry.software.common.annotations.UserOperation;
import com.electromagnetic.industry.software.common.cons.UserConstants; import com.electromagnetic.industry.software.common.cons.UserConstants;
import com.electromagnetic.industry.software.common.enums.AdminTypeEnum; import com.electromagnetic.industry.software.common.enums.AdminTypeEnum;
@ -25,6 +26,7 @@ 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
@ -107,9 +109,11 @@ 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(UserThreadLocal.getUserId()) .userId(user.getUserId())
.accessStartTime(DateUtil.date(accessStartTime)) .accessStartTime(DateUtil.date(accessStartTime))
.accessEndTime(DateUtil.date(accessEndTime)) .accessEndTime(DateUtil.date(accessEndTime))
.accessDuration(accessEndTime - accessStartTime) .accessDuration(accessEndTime - accessStartTime)
@ -122,10 +126,13 @@ 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 = UserThreadLocal.getResult(); ElectromagneticResult<?> result = user.getResult();
if (result != null) { if (result != null) {
userAccessLog.setResponse(JSONUtil.toJsonStr(result));
if (!result.getSuccess()) { if (!result.getSuccess()) {
userAccessLog.setAccessSuccess(false); userAccessLog.setAccessSuccess(false);
userAccessLog.setOperationMsg(result.getErrorMessage()); userAccessLog.setOperationMsg(result.getErrorMessage());

View File

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

View File

@ -39,7 +39,7 @@ public class EdFileInfoController {
return edFileInfoService.createFolder(createFolderDTO, DataOwnEnum.COMMON.code); return edFileInfoService.createFolder(createFolderDTO, DataOwnEnum.COMMON.code);
} }
@UserOperation(value = "作废文件夹", modelName = UserOperationModuleEnum.DATABASE) @UserOperation(value = "作废", modelName = UserOperationModuleEnum.DATABASE)
@RequiredPermission(value = FilePermission.DELETE) @RequiredPermission(value = FilePermission.DELETE)
@RequestMapping("delete") @RequestMapping("delete")
public ElectromagneticResult<?> delete(@RequestParam String id) { public ElectromagneticResult<?> delete(@RequestParam String id) {
@ -161,8 +161,4 @@ public class EdFileInfoController {
return edFileInfoService.preview(id, response, DataOwnEnum.COMMON.code); return edFileInfoService.preview(id, response, DataOwnEnum.COMMON.code);
} }
} }

View File

@ -61,4 +61,7 @@ public class UserAccessLog {
// 父id最权限需要 // 父id最权限需要
private String parentId; private String parentId;
// 请求返回的结果
private String response;
} }

View File

@ -11,4 +11,6 @@ public class AccessLogQueryDTO {
private int pageSize; private int pageSize;
private String keyword;
} }

View File

@ -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> list; private List<T> records;
private long total; private long total;
public RespPageVO(long total, List<T> list) { public RespPageVO(long total, List<T> records) {
this.list = list; this.records = records;
this.total = total; this.total = total;
} }

View File

@ -110,7 +110,7 @@ public class CommonService {
public String getFileSysPath(String dbPath, int dataOwnCode) { public String getFileSysPath(String dbPath, int dataOwnCode) {
ArrayList<String> paths = CollUtil.newArrayList(dbPath.split(MYSQL_FILE_PATH_SPLIT)); ArrayList<String> paths = CollUtil.newArrayList(dbPath.split(MYSQL_FILE_PATH_SPLIT));
String path = getDbPath(paths); String path = getDbPath(paths);
String prePath = dataOwnCode == DataOwnEnum.USER_PRJ.code ? eleDataPath : userDataPath; String prePath = dataOwnCode == DataOwnEnum.USER_PRJ.code ? userDataPath : eleDataPath;
return prePath + File.separator + path; return prePath + File.separator + path;
} }
@ -306,11 +306,10 @@ public class CommonService {
if (fileInfo.getDataOwn().equals(DataOwnEnum.SYS_PRJ.code)) { // 删除的是层级目录 if (fileInfo.getDataOwn().equals(DataOwnEnum.SYS_PRJ.code)) { // 删除的是层级目录
long count = edFileInfoMapper.selectCount(Wrappers.<EdFileInfo>lambdaQuery() long count = edFileInfoMapper.selectCount(Wrappers.<EdFileInfo>lambdaQuery()
.eq(EdFileInfo::getDataOwn, DataOwnEnum.COMMON.code) .eq(EdFileInfo::getDataOwn, DataOwnEnum.COMMON.code)
.eq(EdFileInfo::getDataOwn, dataOwnCode)
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code) .eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
.like(EdFileInfo::getFilePath, MYSQL_FILE_PATH_SPLIT + id + MYSQL_FILE_PATH_SPLIT)); .like(EdFileInfo::getFilePath, MYSQL_FILE_PATH_SPLIT + id + MYSQL_FILE_PATH_SPLIT));
if (count > 0) { if (count > 0) {
String info = StrFormatter.format("删除文件 {} 失败,目录非空。", fileInfo.getFileName()); String info = StrFormatter.format("删除层级 {} 失败,目录非空。", fileInfo.getFileName());
log.info(info); log.info(info);
return ElectromagneticResultUtil.fail("-1", info); return ElectromagneticResultUtil.fail("-1", info);
} else { } else {
@ -344,7 +343,7 @@ public class CommonService {
.eq(EdFileInfo::getParentId, id) .eq(EdFileInfo::getParentId, id)
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)); .eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code));
if (count > 0) { if (count > 0) {
String info = StrFormatter.format("删除文件 {} 失败,目录非空。", fileInfo.getFileName()); String info = StrFormatter.format("删除文件 {} 失败,目录非空。", fileInfo.getFileName());
log.info(info); log.info(info);
return ElectromagneticResultUtil.fail("-1", info); return ElectromagneticResultUtil.fail("-1", info);
} else { } else {
@ -358,10 +357,10 @@ public class CommonService {
} }
} }
// fileSystemService.renameFile(srcFilePath, srcPrjName + "." + IdUtil.fastSimpleUUID() + DELETE_FLAG); // fileSystemService.renameFile(srcFilePath, srcPrjName + "." + IdUtil.fastSimpleUUID() + DELETE_FLAG);
UserThreadLocal.setSuccessInfo(id, "删除目录 {} 成功", fileInfo.getFileName()); UserThreadLocal.setSuccessInfo(srcFileInfo.getParentId(), id, "删除目录 {} 成功", fileInfo.getFileName());
return ElectromagneticResultUtil.success(true); return ElectromagneticResultUtil.success(true);
} catch (Exception e) { } catch (Exception e) {
String info = StrFormatter.format("删除文件 {} 失败,目录非空。", fileInfo.getFileName()); String info = StrFormatter.format("删除 {} 失败,原因 {}", fileInfo.getFileName(), e.getMessage());
log.error(info, e); log.error(info, e);
throw new BizException(info); throw new BizException(info);
} }
@ -421,4 +420,15 @@ public class CommonService {
} }
} }
public String getLastPrjLeafId(String path) {
String[] split = path.split(MYSQL_FILE_PATH_SPLIT);
for (int i = split.length - 1; i >= 0; i--) {
if (split[i].length() < 19) {
return split[i];
}
}
return "";
}
} }

View File

@ -145,7 +145,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
long total = edFileInfoPage.getTotal(); long total = edFileInfoPage.getTotal();
List<FileInfoVO> records = BeanUtil.copyToList(edFileInfoPage.getRecords(), FileInfoVO.class); List<FileInfoVO> records = BeanUtil.copyToList(edFileInfoPage.getRecords(), FileInfoVO.class);
resetFileSize(records); resetFileSize(records);
UserThreadLocal.setSuccessInfo("", "", "查询搜索文件成功"); UserThreadLocal.setSuccessInfo("", "", "查询文件成功");
return ElectromagneticResultUtil.success(new RespPageVO<>(total, records)); return ElectromagneticResultUtil.success(new RespPageVO<>(total, records));
} }
@ -174,7 +174,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
Assert.isTrue(EleCommonUtil.isFileNameValid(createFolderDTO.getNewFolderName()), NAME_VALID_MSG); Assert.isTrue(EleCommonUtil.isFileNameValid(createFolderDTO.getNewFolderName()), NAME_VALID_MSG);
String folderId = IdWorker.getSnowFlakeIdString(); String folderId = IdWorker.getSnowFlakeIdString();
ElectromagneticResult<?> res = commonService.addFolder(createFolderDTO.getParentId(), createFolderDTO.getNewFolderName(), false, folderId, createFolderDTO.getFileNote(), dataOwnCode); ElectromagneticResult<?> res = commonService.addFolder(createFolderDTO.getParentId(), createFolderDTO.getNewFolderName(), false, folderId, createFolderDTO.getFileNote(), dataOwnCode);
UserThreadLocal.setSuccessInfo(createFolderDTO.getParentId(), res.getData() + "", "创建文件夹成功"); UserThreadLocal.setSuccessInfo(createFolderDTO.getParentId(), res.getData() + "", "创建文件夹 {} 成功", createFolderDTO.getNewFolderName());
return res; return res;
} }
@ -211,7 +211,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
EdFileInfo fileInfo = this.baseMapper.selectById(id); EdFileInfo fileInfo = this.baseMapper.selectById(id);
if (fileInfo.getDataType() == EleDataTypeEnum.FOLDER.code) { if (fileInfo.getDataType() == EleDataTypeEnum.FOLDER.code) {
ElectromagneticResult<?> res = commonService.deleteFolder(id, dataOwnCode); ElectromagneticResult<?> res = commonService.deleteFolder(id, dataOwnCode);
UserThreadLocal.setSuccessInfo(id, "作废目录 {} 成功", fileInfo.getFileName()); UserThreadLocal.setSuccessInfo(fileInfo.getParentId(), id, "作废目录 {} 成功", fileInfo.getFileName());
return res; return res;
} }
Date now = new Date(); Date now = new Date();
@ -222,7 +222,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
.set(EdFileInfo::getEffectFlag, false) .set(EdFileInfo::getEffectFlag, false)
.set(EdFileInfo::getAllDeleted, true) .set(EdFileInfo::getAllDeleted, true)
.eq(EdFileInfo::getFileId, fileInfo.getFileId())); .eq(EdFileInfo::getFileId, fileInfo.getFileId()));
UserThreadLocal.setSuccessInfo(id, "作废目录 {} 成功", fileInfo.getFileName()); UserThreadLocal.setSuccessInfo(fileInfo.getParentId(), id, "作废文件 {}.{} 成功", fileInfo.getFileName(), fileInfo.getFileType());
return ElectromagneticResultUtil.success(true); return ElectromagneticResultUtil.success(true);
} }
@ -247,7 +247,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
headers.add("Expires", "0"); headers.add("Expires", "0");
String newFileName = Base64.encode(fileName.substring(0, fileName.lastIndexOf("."))); String newFileName = Base64.encode(fileName.substring(0, fileName.lastIndexOf(".")));
response.setHeader("content-disposition", "attachment;filename=" + newFileName); response.setHeader("content-disposition", "attachment;filename=" + newFileName);
UserThreadLocal.setSuccessInfo(fileInfo.getFileId(), "下载文件 {} 成功", fileName); UserThreadLocal.setSuccessInfo(fileInfo.getParentId(), fileInfo.getFileId(), "下载文件 {} 成功", fileName);
// 构建响应实体(可以返回<byte[]或Resource返回类型取决body入参类型) // 构建响应实体(可以返回<byte[]或Resource返回类型取决body入参类型)
return ResponseEntity return ResponseEntity
.ok() .ok()
@ -316,7 +316,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
.set(EdFileInfo::getFileNote, updateFileInfoDTO.getFileNote())); .set(EdFileInfo::getFileNote, updateFileInfoDTO.getFileNote()));
String newName = updateFileInfoDTO.getFileName() + "." + fileInfo.getFileType() + "." + fileInfo.getFileCode(); String newName = updateFileInfoDTO.getFileName() + "." + fileInfo.getFileType() + "." + fileInfo.getFileCode();
fileSystemService.renameFile(srcFilePath, newName); fileSystemService.renameFile(srcFilePath, newName);
UserThreadLocal.setSuccessInfo(updateFileInfoDTO.getId(), "更新文件信息成功,新文件名为 {}", newFileName); UserThreadLocal.setSuccessInfo(commonService.getLastPrjLeafId(fileInfo.getFilePath()), updateFileInfoDTO.getId(), "更新文件信息成功,新文件名为 {}.{}", newFileName, fileInfo.getFileType());
return ElectromagneticResultUtil.success(true); return ElectromagneticResultUtil.success(true);
} catch (Exception e) { } catch (Exception e) {
String info = StrFormatter.format("更新文件信息失败,新文件名 {} 原因 {}", newFileName, e.getMessage()); String info = StrFormatter.format("更新文件信息失败,新文件名 {} 原因 {}", newFileName, e.getMessage());
@ -805,7 +805,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
log.error(info, e); log.error(info, e);
throw new BizException(info); throw new BizException(info);
} }
UserThreadLocal.setSuccessInfo(finalEdFileInfo.getFileId(), "文件 {} 为上传到 {} 成功,同名同后缀的处理方式为 {},存入的文件名为 {}", fileName, destPath, strategyStr, finalEdFileInfo.getFileName()+ "." + finalEdFileInfo.getFileType()); UserThreadLocal.setSuccessInfo(finalEdFileInfo.getParentId(), finalEdFileInfo.getFileId(), "文件 {} 为上传到 {} 成功,同名同后缀的处理方式为 {},存入的文件名为 {}", fileName, destPath, strategyStr, finalEdFileInfo.getFileName()+ "." + finalEdFileInfo.getFileType());
return ElectromagneticResultUtil.success(true); return ElectromagneticResultUtil.success(true);
} }
@ -866,7 +866,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
} else { } else {
srcFileInfo = handMoveConflict(targetFolderId, strategy, srcFileInfo, destFolderInfo, dataOwnCode); srcFileInfo = handMoveConflict(targetFolderId, strategy, srcFileInfo, destFolderInfo, dataOwnCode);
} }
UserThreadLocal.setSuccessInfo(srcFileInfo.getFileId(), "文件 {} 移动到 {},成功,处理文件同名同后缀的方式为 {},最终文件名为 {}", srcFileInfo.getFileName() + "." + srcFileInfo.getFileName(), UserThreadLocal.setSuccessInfo(srcFileInfo.getParentId(), srcFileInfo.getFileId(), "文件 {} 移动到 {},成功,处理文件同名同后缀的方式为 {},最终文件名为 {}", srcFileInfo.getFileName() + "." + srcFileInfo.getFileName(),
commonService.getDbPath(destFolderInfo.getFilePath()), FileRepeatEnum.getDesc(strategy), srcFileInfo.getFileName()); commonService.getDbPath(destFolderInfo.getFilePath()), FileRepeatEnum.getDesc(strategy), srcFileInfo.getFileName());
return ElectromagneticResultUtil.success(true); return ElectromagneticResultUtil.success(true);
} }
@ -953,7 +953,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)); .eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code));
EdFileInfo destFolderInfo = this.baseMapper.selectOne(Wrappers.lambdaQuery(EdFileInfo.class) EdFileInfo destFolderInfo = this.baseMapper.selectOne(Wrappers.lambdaQuery(EdFileInfo.class)
.eq(EdFileInfo::getId, targetFolderId)); .eq(EdFileInfo::getId, targetFolderId));
EdFileInfo destFileInfo = null; EdFileInfo destFileInfo;
if (count == 0) { if (count == 0) {
// 没有同名文件 // 没有同名文件
// 首先将信息保存到MySQL // 首先将信息保存到MySQL
@ -975,7 +975,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
} else { } else {
destFileInfo = handCopyConflict(targetFolderId, strategy, srcFileInfo, destFolderInfo, dataOwnCode); destFileInfo = handCopyConflict(targetFolderId, strategy, srcFileInfo, destFolderInfo, dataOwnCode);
} }
UserThreadLocal.setSuccessInfo(destFileInfo.getFileId(), "文件 {} 复制到 {},成功,处理文件同名同后缀的方式为 {},最终文件名为 {}", destFileInfo.getFileName() + "." + destFileInfo.getFileName(), UserThreadLocal.setSuccessInfo(destFileInfo.getParentId(), destFileInfo.getFileId(), "文件 {} 复制到 {},成功,处理文件同名同后缀的方式为 {},最终文件名为 {}", destFileInfo.getFileName() + "." + destFileInfo.getFileName(),
commonService.getDbPath(destFolderInfo.getFilePath()), FileRepeatEnum.getDesc(strategy), srcFileInfo.getFileName()); commonService.getDbPath(destFolderInfo.getFilePath()), FileRepeatEnum.getDesc(strategy), srcFileInfo.getFileName());
return ElectromagneticResultUtil.success(true); return ElectromagneticResultUtil.success(true);
} }
@ -1251,22 +1251,34 @@ 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);
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())) { 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(fileSysPath, pdfTmpPath); OfficeFileUtil.doc2pdf(fileSaveTmpPath, pdfTmpPath);
fileSysPath = 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(); 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(".")));
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入参类型) // 构建响应实体(可以返回<byte[]或Resource返回类型取决body入参类型)
UserThreadLocal.setSuccessInfo(fileInfo.getFileId(), "文件预览成功,文件名为 {}", fileInfo.getFileName() + "." + fileInfo.getFileType()); UserThreadLocal.setSuccessInfo(fileInfo.getParentId(), fileInfo.getFileId(), "文件预览成功,文件名为 {}", fileInfo.getFileName() + "." + fileInfo.getFileType());
return ResponseEntity return ResponseEntity
.ok() .ok()
.headers(headers) .headers(headers)

View File

@ -109,7 +109,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
this.save(fileInfo); this.save(fileInfo);
// 保存到文件系统 // 保存到文件系统
fileSystemService.createDirectory(commonService.getEleDataPath(dataOwnCode) + File.separator + prjName); fileSystemService.createDirectory(commonService.getEleDataPath(dataOwnCode) + File.separator + prjName);
UserThreadLocal.setSuccessInfo(newPrjId, "创建 {} 项目成功。", prjName); UserThreadLocal.setSuccessInfo("", newPrjId, "创建 {} 项目成功。", prjName);
} catch (Exception e) { } catch (Exception e) {
String info = StrFormatter.format("工程 {} 创建失败,具体为--->{}", prjName, e.getMessage()); String info = StrFormatter.format("工程 {} 创建失败,具体为--->{}", prjName, e.getMessage());
log.error(info, e); log.error(info, e);
@ -156,7 +156,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
.set(EdFileInfo::getUpdatedBy, UserThreadLocal.getUserId()) .set(EdFileInfo::getUpdatedBy, UserThreadLocal.getUserId())
.set(EdFileInfo::getUpdatedTime, new Date())); .set(EdFileInfo::getUpdatedTime, new Date()));
fileSystemService.renameFile(commonService.getEleDataPath(dataOwnCode), oldPrjName, newPrjName); fileSystemService.renameFile(commonService.getEleDataPath(dataOwnCode), oldPrjName, newPrjName);
UserThreadLocal.setSuccessInfo(prjId, "修改工层名 {} 为 {} 成功。", oldPrjName, newPrjName); UserThreadLocal.setSuccessInfo("", prjId, "修改工层名 {} 为 {} 成功。", oldPrjName, newPrjName);
} catch (Exception e) { } catch (Exception e) {
String info = StrFormatter.format("修改工程名异常--->{}{}", newPrjName, e.getMessage()); String info = StrFormatter.format("修改工程名异常--->{}{}", newPrjName, e.getMessage());
log.error(info, e); log.error(info, e);
@ -197,7 +197,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
// 对原文件进行处理 // 对原文件进行处理
EdFileInfo prjFile = this.getById(prjId); EdFileInfo prjFile = this.getById(prjId);
fileSystemService.renameFile(commonService.getFileSysPath(prjId, dataOwnCode), prjFile + "_" + IdUtil.fastSimpleUUID() + DELETE_FLAG); fileSystemService.renameFile(commonService.getFileSysPath(prjId, dataOwnCode), prjFile + "_" + IdUtil.fastSimpleUUID() + DELETE_FLAG);
UserThreadLocal.setSuccessInfo(prjId, "废除 {} 项目成功。", prjFile.getFileName()); UserThreadLocal.setSuccessInfo("", prjId, "废除 {} 项目成功。", prjFile.getFileName());
return ElectromagneticResultUtil.success(true); return ElectromagneticResultUtil.success(true);
} catch (Exception e) { } catch (Exception e) {
String info = "废除项目失败"; String info = "废除项目失败";
@ -228,7 +228,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
int id = Integer.parseInt(this.baseMapper.maxPrjId()); int id = Integer.parseInt(this.baseMapper.maxPrjId());
String folderId = String.valueOf(id + 1); String folderId = String.valueOf(id + 1);
ElectromagneticResult<?> electromagneticResult = commonService.addFolder(parentId, folderName, true, folderId, null, dataOwnCode); ElectromagneticResult<?> electromagneticResult = commonService.addFolder(parentId, folderName, true, folderId, null, dataOwnCode);
UserThreadLocal.setSuccessInfo(electromagneticResult.getData() + "", "添加子集 {} 成功", folderName); UserThreadLocal.setSuccessInfo(parentId, electromagneticResult.getData() + "", "添加子集 {} 成功", folderName);
return electromagneticResult; return electromagneticResult;
} }
@ -319,7 +319,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
.likeRight(EdFileInfo::getFilePath, prjId); .likeRight(EdFileInfo::getFilePath, prjId);
this.update(updateWrapper); this.update(updateWrapper);
commonService.deletePrjSysDir(fileSysPaths); commonService.deletePrjSysDir(fileSysPaths);
UserThreadLocal.setSuccessInfo(prjId, "项目 {} 发布成功", fileInfo.getFileName()); UserThreadLocal.setSuccessInfo("", prjId, "项目 {} 发布成功", fileInfo.getFileName());
return ElectromagneticResultUtil.success(true); return ElectromagneticResultUtil.success(true);
} catch (Exception e) { } catch (Exception e) {
String info = StrFormatter.format("项目 {} 发布异常", fileInfo.getFileName()); String info = StrFormatter.format("项目 {} 发布异常", fileInfo.getFileName());
@ -463,7 +463,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
.eq(EdFileInfo::getId, id) .eq(EdFileInfo::getId, id)
.set(EdFileInfo::getFileName, newFolderName)); .set(EdFileInfo::getFileName, newFolderName));
fileSystemService.renameFile(sysFilePath, newFolderName); fileSystemService.renameFile(sysFilePath, newFolderName);
UserThreadLocal.setSuccessInfo(id, "子集名称 {} 修改成功", newFolderName); UserThreadLocal.setSuccessInfo(parentId, id, "子集名称 {} 修改成功", newFolderName);
return ElectromagneticResultUtil.success(true); return ElectromagneticResultUtil.success(true);
} catch (Exception e) { } catch (Exception e) {
String info = StrFormatter.format("修改子集名称为 {} 失败", newFolderName); String info = StrFormatter.format("修改子集名称为 {} 失败", newFolderName);

View File

@ -40,6 +40,8 @@ public class FileSystemServiceImpl implements FileSystemService {
@Override @Override
public void renameFile(String sourcePath, String newName) { public void renameFile(String sourcePath, String newName) {
sourcePath = sourcePath.replace("//", "/");
sourcePath = sourcePath.endsWith("/") ? sourcePath.substring(0, sourcePath.length() - 1) : sourcePath;
FileUtil.rename(new File(sourcePath), newName, true); FileUtil.rename(new File(sourcePath), newName, true);
} }

View File

@ -1,10 +1,12 @@
package com.electromagnetic.industry.software.manage.service.serviceimpl; package com.electromagnetic.industry.software.manage.service.serviceimpl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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;
@ -47,18 +49,38 @@ public class UserAccessLogServiceImpl extends ServiceImpl<UserAccessLogMapper, U
if (!adminQuery) { if (!adminQuery) {
queryWrapper.eq(UserAccessLog::getDataId, pars.getDataId()); queryWrapper.eq(UserAccessLog::getDataId, pars.getDataId());
} }
if (StrUtil.isNotEmpty(pars.getKeyword())) {
queryWrapper.and(qr -> qr.like(UserAccessLog::getAction, pars.getKeyword())
.or()
.like(UserAccessLog::getRequestUrl, pars.getKeyword())
.or()
.like(UserAccessLog::getRequestIp, pars.getKeyword())
.or()
.like(UserAccessLog::getRemoteAddr, pars.getKeyword())
.or()
.like(UserAccessLog::getOperationMsg, pars.getKeyword())
.or()
.like(UserAccessLog::getOperationModule, pars.getKeyword()));
}
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);
setUserName(res); setOtherInfo(res);
return ElectromagneticResultUtil.success(new RespPageVO<>(logs.getTotal(), 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()); 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()));
});
} }
} }

View File

@ -2,6 +2,8 @@ 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 {
@ -11,9 +13,20 @@ 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 "";
}
} }

View File

@ -2,6 +2,7 @@ package com.electromagnetic.industry.software.common.util;
import cn.hutool.core.text.StrFormatter; import cn.hutool.core.text.StrFormatter;
import cn.hutool.core.util.StrUtil;
import com.electromagnetic.industry.software.common.pojo.UserLoginInfo; import com.electromagnetic.industry.software.common.pojo.UserLoginInfo;
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult; import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
@ -52,6 +53,8 @@ public class UserThreadLocal {
} }
public static void setSuccessInfo(String parentId, String dataId, String strPattern, Object... argArray) { public static void setSuccessInfo(String parentId, String dataId, String strPattern, Object... argArray) {
parentId = StrUtil.isEmpty(parentId) ? "" : parentId;
dataId = StrUtil.isEmpty(dataId) ? "" : dataId;
String successMsg = StrFormatter.format(strPattern, argArray); String successMsg = StrFormatter.format(strPattern, argArray);
userThread.get().setSuccessInfo(parentId, successMsg, dataId); userThread.get().setSuccessInfo(parentId, successMsg, dataId);
} }