Merge branch 'develop' of http://139.196.179.195:3000/chenxudong/electromagnetic-data-new into develop
This commit is contained in:
commit
38fcdcb859
|
|
@ -32,7 +32,7 @@ public class FileController {
|
|||
public ElectromagneticResult<?> upload(@RequestParam("file") MultipartFile file, @RequestParam("path") String path) {
|
||||
BackupFileResLog backupFileResLog = BackupFileResLog.builder().backupStartTime(new Date()).fileName(file.getOriginalFilename()).backupStatus(true).build();
|
||||
try {
|
||||
fileService.upload(file, path);
|
||||
fileService.upload(file);
|
||||
} catch (Exception e) {
|
||||
String details = ExceptionUtil.stacktraceToString(e);
|
||||
backupFileResLog.setBackupStatus(false);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,6 @@ import java.io.IOException;
|
|||
|
||||
public interface FileService {
|
||||
|
||||
void upload(MultipartFile file, String path) throws IOException;
|
||||
void upload(MultipartFile file) throws IOException;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@ public class FileServiceImpl implements FileService {
|
|||
private BackupPro backupPro;
|
||||
|
||||
@Override
|
||||
public void upload(MultipartFile file, String path) throws IOException {
|
||||
public void upload(MultipartFile file) throws IOException {
|
||||
String saveFolder = backupPro.getSaveFolder();
|
||||
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)) {
|
||||
FileUtil.writeFromStream(file.getInputStream(), destPath);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.electromagnetic.industry.software.manage.config;
|
|||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
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.cons.UserConstants;
|
||||
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.HttpServletResponse;
|
||||
import java.util.Date;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
|
|
@ -107,9 +109,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,10 +126,13 @@ 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) {
|
||||
userAccessLog.setResponse(JSONUtil.toJsonStr(result));
|
||||
if (!result.getSuccess()) {
|
||||
userAccessLog.setAccessSuccess(false);
|
||||
userAccessLog.setOperationMsg(result.getErrorMessage());
|
||||
|
|
|
|||
|
|
@ -1,11 +1,38 @@
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class EdFileInfoController {
|
|||
return edFileInfoService.createFolder(createFolderDTO, DataOwnEnum.COMMON.code);
|
||||
}
|
||||
|
||||
@UserOperation(value = "作废文件夹", modelName = UserOperationModuleEnum.DATABASE)
|
||||
@UserOperation(value = "作废", modelName = UserOperationModuleEnum.DATABASE)
|
||||
@RequiredPermission(value = FilePermission.DELETE)
|
||||
@RequestMapping("delete")
|
||||
public ElectromagneticResult<?> delete(@RequestParam String id) {
|
||||
|
|
@ -161,8 +161,4 @@ public class EdFileInfoController {
|
|||
return edFileInfoService.preview(id, response, DataOwnEnum.COMMON.code);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,4 +61,7 @@ public class UserAccessLog {
|
|||
// 父id,最权限需要
|
||||
private String parentId;
|
||||
|
||||
// 请求返回的结果
|
||||
private String response;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,4 +11,6 @@ public class AccessLogQueryDTO {
|
|||
|
||||
private int pageSize;
|
||||
|
||||
private String keyword;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ public class CommonService {
|
|||
public String getFileSysPath(String dbPath, int dataOwnCode) {
|
||||
ArrayList<String> paths = CollUtil.newArrayList(dbPath.split(MYSQL_FILE_PATH_SPLIT));
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -306,11 +306,10 @@ public class CommonService {
|
|||
if (fileInfo.getDataOwn().equals(DataOwnEnum.SYS_PRJ.code)) { // 删除的是层级目录
|
||||
long count = edFileInfoMapper.selectCount(Wrappers.<EdFileInfo>lambdaQuery()
|
||||
.eq(EdFileInfo::getDataOwn, DataOwnEnum.COMMON.code)
|
||||
.eq(EdFileInfo::getDataOwn, dataOwnCode)
|
||||
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
||||
.like(EdFileInfo::getFilePath, MYSQL_FILE_PATH_SPLIT + id + MYSQL_FILE_PATH_SPLIT));
|
||||
if (count > 0) {
|
||||
String info = StrFormatter.format("删除文件 {} 失败,目录非空。", fileInfo.getFileName());
|
||||
String info = StrFormatter.format("删除层级 {} 失败,目录非空。", fileInfo.getFileName());
|
||||
log.info(info);
|
||||
return ElectromagneticResultUtil.fail("-1", info);
|
||||
} else {
|
||||
|
|
@ -344,7 +343,7 @@ public class CommonService {
|
|||
.eq(EdFileInfo::getParentId, id)
|
||||
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code));
|
||||
if (count > 0) {
|
||||
String info = StrFormatter.format("删除文件 {} 失败,目录非空。", fileInfo.getFileName());
|
||||
String info = StrFormatter.format("删除文件夹 {} 失败,目录非空。", fileInfo.getFileName());
|
||||
log.info(info);
|
||||
return ElectromagneticResultUtil.fail("-1", info);
|
||||
} else {
|
||||
|
|
@ -358,10 +357,10 @@ public class CommonService {
|
|||
}
|
||||
}
|
||||
// fileSystemService.renameFile(srcFilePath, srcPrjName + "." + IdUtil.fastSimpleUUID() + DELETE_FLAG);
|
||||
UserThreadLocal.setSuccessInfo(id, "删除目录 {} 成功", fileInfo.getFileName());
|
||||
UserThreadLocal.setSuccessInfo(srcFileInfo.getParentId(), id, "删除目录 {} 成功", fileInfo.getFileName());
|
||||
return ElectromagneticResultUtil.success(true);
|
||||
} catch (Exception e) {
|
||||
String info = StrFormatter.format("删除文件 {} 失败,目录非空。", fileInfo.getFileName());
|
||||
String info = StrFormatter.format("删除 {} 失败,原因 {}", fileInfo.getFileName(), e.getMessage());
|
||||
log.error(info, e);
|
||||
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 "";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
long total = edFileInfoPage.getTotal();
|
||||
List<FileInfoVO> records = BeanUtil.copyToList(edFileInfoPage.getRecords(), FileInfoVO.class);
|
||||
resetFileSize(records);
|
||||
UserThreadLocal.setSuccessInfo("", "", "查询搜索文件成功");
|
||||
UserThreadLocal.setSuccessInfo("", "", "查询文件成功");
|
||||
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);
|
||||
String folderId = IdWorker.getSnowFlakeIdString();
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -211,7 +211,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
EdFileInfo fileInfo = this.baseMapper.selectById(id);
|
||||
if (fileInfo.getDataType() == EleDataTypeEnum.FOLDER.code) {
|
||||
ElectromagneticResult<?> res = commonService.deleteFolder(id, dataOwnCode);
|
||||
UserThreadLocal.setSuccessInfo(id, "作废目录 {} 成功", fileInfo.getFileName());
|
||||
UserThreadLocal.setSuccessInfo(fileInfo.getParentId(), id, "作废目录 {} 成功", fileInfo.getFileName());
|
||||
return res;
|
||||
}
|
||||
Date now = new Date();
|
||||
|
|
@ -222,7 +222,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
.set(EdFileInfo::getEffectFlag, false)
|
||||
.set(EdFileInfo::getAllDeleted, true)
|
||||
.eq(EdFileInfo::getFileId, fileInfo.getFileId()));
|
||||
UserThreadLocal.setSuccessInfo(id, "作废目录 {} 成功", fileInfo.getFileName());
|
||||
UserThreadLocal.setSuccessInfo(fileInfo.getParentId(), id, "作废文件 {}.{} 成功", fileInfo.getFileName(), fileInfo.getFileType());
|
||||
return ElectromagneticResultUtil.success(true);
|
||||
}
|
||||
|
||||
|
|
@ -247,7 +247,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
headers.add("Expires", "0");
|
||||
String newFileName = Base64.encode(fileName.substring(0, fileName.lastIndexOf(".")));
|
||||
response.setHeader("content-disposition", "attachment;filename=" + newFileName);
|
||||
UserThreadLocal.setSuccessInfo(fileInfo.getFileId(), "下载文件 {} 成功", fileName);
|
||||
UserThreadLocal.setSuccessInfo(fileInfo.getParentId(), fileInfo.getFileId(), "下载文件 {} 成功", fileName);
|
||||
// 构建响应实体(可以返回<byte[]或Resource,返回类型取决body入参类型)
|
||||
return ResponseEntity
|
||||
.ok()
|
||||
|
|
@ -316,7 +316,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
.set(EdFileInfo::getFileNote, updateFileInfoDTO.getFileNote()));
|
||||
String newName = updateFileInfoDTO.getFileName() + "." + fileInfo.getFileType() + "." + fileInfo.getFileCode();
|
||||
fileSystemService.renameFile(srcFilePath, newName);
|
||||
UserThreadLocal.setSuccessInfo(updateFileInfoDTO.getId(), "更新文件信息成功,新文件名为 {}", newFileName);
|
||||
UserThreadLocal.setSuccessInfo(commonService.getLastPrjLeafId(fileInfo.getFilePath()), updateFileInfoDTO.getId(), "更新文件信息成功,新文件名为 {}.{}", newFileName, fileInfo.getFileType());
|
||||
return ElectromagneticResultUtil.success(true);
|
||||
} catch (Exception e) {
|
||||
String info = StrFormatter.format("更新文件信息失败,新文件名 {}, 原因 {}", newFileName, e.getMessage());
|
||||
|
|
@ -805,7 +805,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
log.error(info, e);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -866,7 +866,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
} else {
|
||||
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());
|
||||
return ElectromagneticResultUtil.success(true);
|
||||
}
|
||||
|
|
@ -953,7 +953,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code));
|
||||
EdFileInfo destFolderInfo = this.baseMapper.selectOne(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
.eq(EdFileInfo::getId, targetFolderId));
|
||||
EdFileInfo destFileInfo = null;
|
||||
EdFileInfo destFileInfo;
|
||||
if (count == 0) {
|
||||
// 没有同名文件
|
||||
// 首先将信息保存到MySQL
|
||||
|
|
@ -975,7 +975,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
} else {
|
||||
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());
|
||||
return ElectromagneticResultUtil.success(true);
|
||||
}
|
||||
|
|
@ -1251,22 +1251,34 @@ 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());
|
||||
UserThreadLocal.setSuccessInfo(fileInfo.getParentId(), fileInfo.getFileId(), "文件预览成功,文件名为 {}", fileInfo.getFileName() + "." + fileInfo.getFileType());
|
||||
return ResponseEntity
|
||||
.ok()
|
||||
.headers(headers)
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
|||
this.save(fileInfo);
|
||||
// 保存到文件系统
|
||||
fileSystemService.createDirectory(commonService.getEleDataPath(dataOwnCode) + File.separator + prjName);
|
||||
UserThreadLocal.setSuccessInfo(newPrjId, "创建 {} 项目成功。", prjName);
|
||||
UserThreadLocal.setSuccessInfo("", newPrjId, "创建 {} 项目成功。", prjName);
|
||||
} catch (Exception e) {
|
||||
String info = StrFormatter.format("工程 {} 创建失败,具体为--->{}", prjName, e.getMessage());
|
||||
log.error(info, e);
|
||||
|
|
@ -156,7 +156,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
|||
.set(EdFileInfo::getUpdatedBy, UserThreadLocal.getUserId())
|
||||
.set(EdFileInfo::getUpdatedTime, new Date()));
|
||||
fileSystemService.renameFile(commonService.getEleDataPath(dataOwnCode), oldPrjName, newPrjName);
|
||||
UserThreadLocal.setSuccessInfo(prjId, "修改工层名 {} 为 {} 成功。", oldPrjName, newPrjName);
|
||||
UserThreadLocal.setSuccessInfo("", prjId, "修改工层名 {} 为 {} 成功。", oldPrjName, newPrjName);
|
||||
} catch (Exception e) {
|
||||
String info = StrFormatter.format("修改工程名异常--->{},{}", newPrjName, e.getMessage());
|
||||
log.error(info, e);
|
||||
|
|
@ -197,7 +197,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
|||
// 对原文件进行处理
|
||||
EdFileInfo prjFile = this.getById(prjId);
|
||||
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);
|
||||
} catch (Exception e) {
|
||||
String info = "废除项目失败";
|
||||
|
|
@ -228,7 +228,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
|||
int id = Integer.parseInt(this.baseMapper.maxPrjId());
|
||||
String folderId = String.valueOf(id + 1);
|
||||
ElectromagneticResult<?> electromagneticResult = commonService.addFolder(parentId, folderName, true, folderId, null, dataOwnCode);
|
||||
UserThreadLocal.setSuccessInfo(electromagneticResult.getData() + "", "添加子集 {} 成功", folderName);
|
||||
UserThreadLocal.setSuccessInfo(parentId, electromagneticResult.getData() + "", "添加子集 {} 成功", folderName);
|
||||
return electromagneticResult;
|
||||
}
|
||||
|
||||
|
|
@ -319,7 +319,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
|||
.likeRight(EdFileInfo::getFilePath, prjId);
|
||||
this.update(updateWrapper);
|
||||
commonService.deletePrjSysDir(fileSysPaths);
|
||||
UserThreadLocal.setSuccessInfo(prjId, "项目 {} 发布成功", fileInfo.getFileName());
|
||||
UserThreadLocal.setSuccessInfo("", prjId, "项目 {} 发布成功", fileInfo.getFileName());
|
||||
return ElectromagneticResultUtil.success(true);
|
||||
} catch (Exception e) {
|
||||
String info = StrFormatter.format("项目 {} 发布异常", fileInfo.getFileName());
|
||||
|
|
@ -463,7 +463,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
|
|||
.eq(EdFileInfo::getId, id)
|
||||
.set(EdFileInfo::getFileName, newFolderName));
|
||||
fileSystemService.renameFile(sysFilePath, newFolderName);
|
||||
UserThreadLocal.setSuccessInfo(id, "子集名称 {} 修改成功", newFolderName);
|
||||
UserThreadLocal.setSuccessInfo(parentId, id, "子集名称 {} 修改成功", newFolderName);
|
||||
return ElectromagneticResultUtil.success(true);
|
||||
} catch (Exception e) {
|
||||
String info = StrFormatter.format("修改子集名称为 {} 失败", newFolderName);
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@ public class FileSystemServiceImpl implements FileSystemService {
|
|||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
||||
|
||||
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.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;
|
||||
|
|
@ -47,18 +49,38 @@ public class UserAccessLogServiceImpl extends ServiceImpl<UserAccessLogMapper, U
|
|||
if (!adminQuery) {
|
||||
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);
|
||||
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 "";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.electromagnetic.industry.software.common.util;
|
|||
|
||||
|
||||
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.resp.ElectromagneticResult;
|
||||
|
||||
|
|
@ -52,6 +53,8 @@ public class UserThreadLocal {
|
|||
}
|
||||
|
||||
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);
|
||||
userThread.get().setSuccessInfo(parentId, successMsg, dataId);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue