This commit is contained in:
s2042968 2025-03-04 15:19:37 +08:00
commit 2ea2a156ca
8 changed files with 42 additions and 62 deletions

View File

@ -1,10 +1,12 @@
package com.electromagnetic.industry.software.manage.config; package com.electromagnetic.industry.software.manage.config;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
import org.apache.ibatis.reflection.MetaObject; import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Date; import java.util.Date;
import java.util.Optional;
@Component @Component
public class EdMetaObjectHandler implements MetaObjectHandler { public class EdMetaObjectHandler implements MetaObjectHandler {
@ -26,8 +28,8 @@ public class EdMetaObjectHandler implements MetaObjectHandler {
if (metaObject.hasGetter("updatedAt")) { if (metaObject.hasGetter("updatedAt")) {
this.strictInsertFill(metaObject, "updatedAt", Date.class, new Date()); this.strictInsertFill(metaObject, "updatedAt", Date.class, new Date());
} }
if (metaObject.hasGetter("updatedTime")) { if (metaObject.hasGetter("createdBy")) {
this.strictInsertFill(metaObject, "updatedTime", Date.class, new Date()); this.strictUpdateFill(metaObject, "createdBy", String.class, Optional.of(UserThreadLocal.getUserId()).orElse(""));
} }
} }
@ -42,6 +44,9 @@ public class EdMetaObjectHandler implements MetaObjectHandler {
if (metaObject.hasGetter("updatedTime")) { if (metaObject.hasGetter("updatedTime")) {
this.strictUpdateFill(metaObject, "updatedTime", Date.class, new Date()); this.strictUpdateFill(metaObject, "updatedTime", Date.class, new Date());
} }
if (metaObject.hasGetter("updatedBy")) {
this.strictUpdateFill(metaObject, "updatedTime", String.class, Optional.of(UserThreadLocal.getUserId()).orElse(""));
}
} }
} }

View File

@ -1,5 +1,6 @@
package com.electromagnetic.industry.software.manage.pojo.models; package com.electromagnetic.industry.software.manage.pojo.models;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data; import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
@ -12,24 +13,24 @@ public class BaseModel {
/** /**
* 创建时间 * 创建时间
*/ */
@TableField(value = "created_time") @TableField(value = "created_time", fill = FieldFill.INSERT)
private Date createdTime; private Date createdTime;
/** /**
* 创建人 * 创建人
*/ */
@TableField(value = "created_by") @TableField(value = "created_by", fill = FieldFill.INSERT)
private String createdBy; private String createdBy;
/** /**
* 最后更新时间 * 最后更新时间
*/ */
@TableField(value = "updated_time") @TableField(value = "updated_time", fill = FieldFill.UPDATE)
private Date updatedTime; private Date updatedTime;
/** /**
* 最后更新人 * 最后更新人
*/ */
@TableField(value = "updated_by") @TableField(value = "updated_by", fill = FieldFill.UPDATE)
private String updatedBy; private String updatedBy;
} }

View File

@ -1,9 +1,11 @@
package com.electromagnetic.industry.software.manage.pojo.other; package com.electromagnetic.industry.software.manage.pojo.other;
import com.electromagnetic.industry.software.manage.pojo.resp.FileTagInfo;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
import java.util.Date; import java.util.Date;
import java.util.List;
@Data @Data
public class FileInfoVO { public class FileInfoVO {
@ -43,4 +45,7 @@ public class FileInfoVO {
private String fileCode; private String fileCode;
private String createdBy; private String createdBy;
private List<FileTagInfo> labels;
} }

View File

@ -0,0 +1,12 @@
package com.electromagnetic.industry.software.manage.pojo.resp;
import lombok.Data;
@Data
public class FileTagInfo {
private String tagId;
private String tagName;
}

View File

@ -188,8 +188,6 @@ public class CommonService {
.eq(EdFileInfo::getParentId, parentId)); .eq(EdFileInfo::getParentId, parentId));
List<String> names = edFileInfos.stream().map(EdFileInfo::getFileName).collect(Collectors.toList()); List<String> names = edFileInfos.stream().map(EdFileInfo::getFileName).collect(Collectors.toList());
try { try {
Date now = new Date();
String currentUserId = UserThreadLocal.getUserId();
String path = currentPath + MYSQL_FILE_PATH_SPLIT + folderId; String path = currentPath + MYSQL_FILE_PATH_SPLIT + folderId;
EdFileInfo fileInfo = new EdFileInfo(); EdFileInfo fileInfo = new EdFileInfo();
String nowTimeStr = EleCommonUtil.getNowTimeStr(); String nowTimeStr = EleCommonUtil.getNowTimeStr();
@ -208,11 +206,7 @@ public class CommonService {
.setFilePath(path) .setFilePath(path)
.setSort(names.size() + 1) .setSort(names.size() + 1)
.setFileNote(fileNote) .setFileNote(fileNote)
.setDataOwn(dataOwnCode) .setDataOwn(dataOwnCode);
.setCreatedTime(now)
.setUpdatedTime(now)
.setCreatedBy(currentUserId)
.setUpdatedBy(currentUserId);
edFileInfoMapper.insert(fileInfo); edFileInfoMapper.insert(fileInfo);
// 保存到文件系统 // 保存到文件系统
String targetFilePath = getEleDataPath(dataOwnCode) + File.separator + getDbPath(paths) + File.separator + folderName; String targetFilePath = getEleDataPath(dataOwnCode) + File.separator + getDbPath(paths) + File.separator + folderName;
@ -297,8 +291,6 @@ public class CommonService {
public ElectromagneticResult<?> deleteFolder(String id, int dataOwnCode) { public ElectromagneticResult<?> deleteFolder(String id, int dataOwnCode) {
// 如果文件夹下存在文件包括文件夹和已经逻辑删除的文件则不允许删除后面管理员选择会有物理删除文件夹和文件的功能此时MySQL和文件系统则会进行物理删除该文件 // 如果文件夹下存在文件包括文件夹和已经逻辑删除的文件则不允许删除后面管理员选择会有物理删除文件夹和文件的功能此时MySQL和文件系统则会进行物理删除该文件
Date now = new Date();
String currentUserId = UserThreadLocal.getUserId();
EdFileInfo srcFileInfo = edFileInfoMapper.selectById(id); EdFileInfo srcFileInfo = edFileInfoMapper.selectById(id);
String srcPrjName = srcFileInfo.getFileName(); String srcPrjName = srcFileInfo.getFileName();
String srcFilePath = getFileSysPath(srcFileInfo.getFilePath(), dataOwnCode); String srcFilePath = getFileSysPath(srcFileInfo.getFilePath(), dataOwnCode);
@ -320,8 +312,6 @@ public class CommonService {
edFileInfoMapper.update(null, Wrappers.<EdFileInfo>lambdaUpdate() edFileInfoMapper.update(null, Wrappers.<EdFileInfo>lambdaUpdate()
.like(EdFileInfo::getFilePath, id) .like(EdFileInfo::getFilePath, id)
.set(EdFileInfo::getSort, -1) .set(EdFileInfo::getSort, -1)
.set(EdFileInfo::getUpdatedBy, currentUserId)
.set(EdFileInfo::getUpdatedTime, now)
.set(EdFileInfo::getDataStatus, EleDataStatusEnum.DELETED.code)); .set(EdFileInfo::getDataStatus, EleDataStatusEnum.DELETED.code));
// 层级文件夹重排序 // 层级文件夹重排序
List<EdFileInfo> edFileInfos1 = edFileInfoMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class) List<EdFileInfo> edFileInfos1 = edFileInfoMapper.selectList(Wrappers.lambdaQuery(EdFileInfo.class)
@ -335,8 +325,6 @@ public class CommonService {
String tmp = edFileInfos1.get(i).getId(); String tmp = edFileInfos1.get(i).getId();
edFileInfoMapper.update(null, Wrappers.lambdaUpdate(EdFileInfo.class) edFileInfoMapper.update(null, Wrappers.lambdaUpdate(EdFileInfo.class)
.set(EdFileInfo::getSort, i + 1) .set(EdFileInfo::getSort, i + 1)
.set(EdFileInfo::getUpdatedBy, currentUserId)
.set(EdFileInfo::getUpdatedTime, now)
.eq(EdFileInfo::getId, tmp)); .eq(EdFileInfo::getId, tmp));
} }
} }
@ -353,8 +341,6 @@ public class CommonService {
// 逻辑删除文件夹 // 逻辑删除文件夹
edFileInfoMapper.update(null, Wrappers.<EdFileInfo>lambdaUpdate() edFileInfoMapper.update(null, Wrappers.<EdFileInfo>lambdaUpdate()
.eq(EdFileInfo::getId, id) .eq(EdFileInfo::getId, id)
.set(EdFileInfo::getUpdatedBy, currentUserId)
.set(EdFileInfo::getUpdatedTime, now)
.set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)); .set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code));
fileSystemService.renameFile(srcFilePath, srcPrjName + "_" + IdUtil.fastSimpleUUID() + DELETE_FLAG); fileSystemService.renameFile(srcFilePath, srcPrjName + "_" + IdUtil.fastSimpleUUID() + DELETE_FLAG);
} }
@ -423,7 +409,6 @@ public class CommonService {
} }
} }
public String getLastPrjLeafId(String path) { public String getLastPrjLeafId(String path) {
String[] split = path.split(MYSQL_FILE_PATH_SPLIT); String[] split = path.split(MYSQL_FILE_PATH_SPLIT);
for (int i = split.length - 1; i >= 0; i--) { for (int i = split.length - 1; i >= 0; i--) {
@ -440,5 +425,4 @@ public class CommonService {
} }
} }

View File

@ -34,6 +34,7 @@ import com.electromagnetic.industry.software.manage.pojo.other.UploadRecordDTO;
import com.electromagnetic.industry.software.manage.pojo.req.*; import com.electromagnetic.industry.software.manage.pojo.req.*;
import com.electromagnetic.industry.software.manage.pojo.resp.*; import com.electromagnetic.industry.software.manage.pojo.resp.*;
import com.electromagnetic.industry.software.manage.service.EdFileInfoService; import com.electromagnetic.industry.software.manage.service.EdFileInfoService;
import com.electromagnetic.industry.software.manage.service.EdTagLibraryService;
import com.electromagnetic.industry.software.manage.service.FileSystemService; import com.electromagnetic.industry.software.manage.service.FileSystemService;
import com.electromagnetic.industry.software.manage.service.PermissionService; import com.electromagnetic.industry.software.manage.service.PermissionService;
import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.FileSystemResource;
@ -77,6 +78,9 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
@Resource @Resource
private ElePropertyConfig elePropertyConfig; private ElePropertyConfig elePropertyConfig;
@Resource
private EdTagLibraryService edTagLibraryService;
/** /**
* 查询文件列表 * 查询文件列表
* *
@ -93,7 +97,6 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
} }
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class) LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
.select(EdFileInfo.class, file -> !file.getColumn().equals("file_content")) .select(EdFileInfo.class, file -> !file.getColumn().equals("file_content"))
.eq(EdFileInfo::getSaveStatus, EleDataSaveStatusEnum.SUCCESS.code) .eq(EdFileInfo::getSaveStatus, EleDataSaveStatusEnum.SUCCESS.code)
@ -208,11 +211,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
UserThreadLocal.setSuccessInfo(fileInfo.getParentId(), id, "作废目录 {} 成功", fileInfo.getFileName()); UserThreadLocal.setSuccessInfo(fileInfo.getParentId(), id, "作废目录 {} 成功", fileInfo.getFileName());
return res; return res;
} }
Date now = new Date();
String currentUserId = UserThreadLocal.getUserId();
this.baseMapper.update(null, Wrappers.lambdaUpdate(EdFileInfo.class) this.baseMapper.update(null, Wrappers.lambdaUpdate(EdFileInfo.class)
.set(EdFileInfo::getUpdatedBy, currentUserId)
.set(EdFileInfo::getUpdatedTime, now)
.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()));
@ -300,12 +299,8 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
} }
String srcFilePath = commonService.getFileSysPath(fileInfo.getFilePath(), dataOwnCode); String srcFilePath = commonService.getFileSysPath(fileInfo.getFilePath(), dataOwnCode);
Date now = new Date();
String currentUserId = UserThreadLocal.getUserId();
this.baseMapper.update(null, Wrappers.lambdaUpdate(EdFileInfo.class) this.baseMapper.update(null, Wrappers.lambdaUpdate(EdFileInfo.class)
.eq(EdFileInfo::getId, updateFileInfoDTO.getId()) .eq(EdFileInfo::getId, updateFileInfoDTO.getId())
.set(EdFileInfo::getUpdatedBy, currentUserId)
.set(EdFileInfo::getUpdatedTime, now)
.set(EdFileInfo::getFileName, updateFileInfoDTO.getFileName()) .set(EdFileInfo::getFileName, updateFileInfoDTO.getFileName())
.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();

View File

@ -18,7 +18,6 @@ import com.electromagnetic.industry.software.common.util.ElectromagneticResultUt
import com.electromagnetic.industry.software.common.util.UserThreadLocal; import com.electromagnetic.industry.software.common.util.UserThreadLocal;
import com.electromagnetic.industry.software.manage.mapper.EdFileInfoMapper; import com.electromagnetic.industry.software.manage.mapper.EdFileInfoMapper;
import com.electromagnetic.industry.software.manage.pojo.models.EdFileInfo; import com.electromagnetic.industry.software.manage.pojo.models.EdFileInfo;
import com.electromagnetic.industry.software.manage.pojo.models.User;
import com.electromagnetic.industry.software.manage.pojo.req.FolderResortDTO; import com.electromagnetic.industry.software.manage.pojo.req.FolderResortDTO;
import com.electromagnetic.industry.software.manage.pojo.req.QueryPublishStatus; import com.electromagnetic.industry.software.manage.pojo.req.QueryPublishStatus;
import com.electromagnetic.industry.software.manage.pojo.resp.ProjectVO; import com.electromagnetic.industry.software.manage.pojo.resp.ProjectVO;
@ -82,8 +81,6 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
String maxPrjId = this.baseMapper.maxPrjId(); String maxPrjId = this.baseMapper.maxPrjId();
int prjCount = this.baseMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class).eq(EdFileInfo::getParentId, PRJ_PARENT_ID)).intValue(); int prjCount = this.baseMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class).eq(EdFileInfo::getParentId, PRJ_PARENT_ID)).intValue();
int id = Integer.parseInt(StrUtil.isEmpty(maxPrjId) ? "100000" : maxPrjId); int id = Integer.parseInt(StrUtil.isEmpty(maxPrjId) ? "100000" : maxPrjId);
Date now = new Date();
String currentUserId = UserThreadLocal.getUserId();
String newPrjId = String.valueOf(id + 1); String newPrjId = String.valueOf(id + 1);
EdFileInfo fileInfo = new EdFileInfo(); EdFileInfo fileInfo = new EdFileInfo();
@ -101,11 +98,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
.setFilePath(newPrjId) .setFilePath(newPrjId)
.setSort(++prjCount) .setSort(++prjCount)
.setFileCode(commonService.createFileCode(newPrjId, EleDataTypeEnum.FOLDER.desc, FILE_START_VERSION, nowTimeStr)) .setFileCode(commonService.createFileCode(newPrjId, EleDataTypeEnum.FOLDER.desc, FILE_START_VERSION, nowTimeStr))
.setDataOwn(dataOwnCode) .setDataOwn(dataOwnCode);
.setCreatedTime(now)
.setUpdatedTime(now)
.setCreatedBy(currentUserId)
.setUpdatedBy(currentUserId);
this.save(fileInfo); this.save(fileInfo);
// 保存到文件系统 // 保存到文件系统
fileSystemService.createDirectory(commonService.getEleDataPath(dataOwnCode) + File.separator + prjName); fileSystemService.createDirectory(commonService.getEleDataPath(dataOwnCode) + File.separator + prjName);
@ -152,9 +145,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
} }
this.baseMapper.update(null, Wrappers.lambdaUpdate(EdFileInfo.class) this.baseMapper.update(null, Wrappers.lambdaUpdate(EdFileInfo.class)
.eq(EdFileInfo::getId, prjId) .eq(EdFileInfo::getId, prjId)
.set(EdFileInfo::getFileName, newPrjName) .set(EdFileInfo::getFileName, newPrjName));
.set(EdFileInfo::getUpdatedBy, UserThreadLocal.getUserId())
.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) {
@ -265,8 +256,6 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
for (FolderResortDTO folderResortDTO : folderResortDTOList) { for (FolderResortDTO folderResortDTO : folderResortDTOList) {
LambdaUpdateWrapper<EdFileInfo> updateWrapper = Wrappers.lambdaUpdate(EdFileInfo.class) LambdaUpdateWrapper<EdFileInfo> updateWrapper = Wrappers.lambdaUpdate(EdFileInfo.class)
.set(EdFileInfo::getSort, folderResortDTO.getSort()) .set(EdFileInfo::getSort, folderResortDTO.getSort())
.set(EdFileInfo::getUpdatedBy, currentUserId)
.set(EdFileInfo::getUpdatedTime, now)
.eq(EdFileInfo::getId, folderResortDTO.getId()); .eq(EdFileInfo::getId, folderResortDTO.getId());
this.update(updateWrapper); this.update(updateWrapper);
} }
@ -290,8 +279,6 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
public ElectromagneticResult<?> publish(String prjId, int dataOwnCode) { public ElectromagneticResult<?> publish(String prjId, int dataOwnCode) {
EdFileInfo fileInfo = this.baseMapper.selectById(prjId); EdFileInfo fileInfo = this.baseMapper.selectById(prjId);
try { try {
Date now = new Date();
String currentUserId = UserThreadLocal.getUserId();
// 将已经处于删除状态设置成逻辑删除 // 将已经处于删除状态设置成逻辑删除
LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class) LambdaQueryWrapper<EdFileInfo> queryWrapper = Wrappers.lambdaQuery(EdFileInfo.class)
.select(EdFileInfo::getId, EdFileInfo::getFilePath) .select(EdFileInfo::getId, EdFileInfo::getFilePath)
@ -307,15 +294,11 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
this.update(Wrappers.lambdaUpdate(EdFileInfo.class) this.update(Wrappers.lambdaUpdate(EdFileInfo.class)
.eq(EdFileInfo::getDataStatus, EleDataStatusEnum.DELETED.code) .eq(EdFileInfo::getDataStatus, EleDataStatusEnum.DELETED.code)
.set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code) .set(EdFileInfo::getEffectFlag, EffectFlagEnum.NOT_EFFECTIVE.code)
.set(EdFileInfo::getUpdatedBy, currentUserId)
.set(EdFileInfo::getUpdatedTime, now)
.likeRight(EdFileInfo::getFilePath, prjId)); .likeRight(EdFileInfo::getFilePath, prjId));
// 其余置为发布状态 // 其余置为发布状态
LambdaUpdateWrapper<EdFileInfo> updateWrapper = Wrappers.lambdaUpdate(EdFileInfo.class) LambdaUpdateWrapper<EdFileInfo> updateWrapper = Wrappers.lambdaUpdate(EdFileInfo.class)
.set(EdFileInfo::getDataStatus, EleDataStatusEnum.PUBLISHED.code) .set(EdFileInfo::getDataStatus, EleDataStatusEnum.PUBLISHED.code)
.eq(EdFileInfo::getDataStatus, EleDataStatusEnum.NOT_PUBLISHED.code) .eq(EdFileInfo::getDataStatus, EleDataStatusEnum.NOT_PUBLISHED.code)
.set(EdFileInfo::getUpdatedBy, currentUserId)
.set(EdFileInfo::getUpdatedTime, now)
.likeRight(EdFileInfo::getFilePath, prjId); .likeRight(EdFileInfo::getFilePath, prjId);
this.update(updateWrapper); this.update(updateWrapper);
commonService.deletePrjSysDir(fileSysPaths); commonService.deletePrjSysDir(fileSysPaths);
@ -352,7 +335,6 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
public ElectromagneticResult<?> follow(String sourceId, String targetId, int dataOwnCode) { public ElectromagneticResult<?> follow(String sourceId, String targetId, int dataOwnCode) {
try { try {
String currentUserId = UserThreadLocal.getUserId();
// 把source工程的层级结构copy到目标工程 // 把source工程的层级结构copy到目标工程
// 查找source的全部目录 // 查找source的全部目录
List<EdFileInfo> sourceEdFileInfos = commonService.selectAllAdminFolder(sourceId, null, dataOwnCode); List<EdFileInfo> sourceEdFileInfos = commonService.selectAllAdminFolder(sourceId, null, dataOwnCode);
@ -408,11 +390,7 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
.setFileType("文件夹") .setFileType("文件夹")
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code) .setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
.setFilePath(targetParentFile.getFilePath() + MYSQL_FILE_PATH_SPLIT + newFolderId) .setFilePath(targetParentFile.getFilePath() + MYSQL_FILE_PATH_SPLIT + newFolderId)
.setSort(++sort) .setSort(++sort);
.setCreatedTime(now)
.setUpdatedTime(now)
.setCreatedBy(currentUserId)
.setUpdatedBy(currentUserId);
this.save(targetFile); this.save(targetFile);
targetEdFileInfos.add(targetFile); targetEdFileInfos.add(targetFile);
String targetSysFilePath = commonService.getFileSysPath(targetFile.getFilePath(), dataOwnCode); String targetSysFilePath = commonService.getFileSysPath(targetFile.getFilePath(), dataOwnCode);
@ -452,14 +430,10 @@ public class EdPrjServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileInfo>
String parentId = this.baseMapper.selectById(id).getParentId(); String parentId = this.baseMapper.selectById(id).getParentId();
// 首先检查同层是否有同名目录 // 首先检查同层是否有同名目录
Assert.isTrue(commonService.notExistSameFolder(parentId, newFolderName, dataOwnCode), StrFormatter.format("{} 子集名已经存在", newFolderName)); Assert.isTrue(commonService.notExistSameFolder(parentId, newFolderName, dataOwnCode), StrFormatter.format("{} 子集名已经存在", newFolderName));
String currentUserId = UserThreadLocal.getUserId();
Date now = new Date();
EdFileInfo fileInfo = this.baseMapper.selectOne(Wrappers.lambdaQuery(EdFileInfo.class) EdFileInfo fileInfo = this.baseMapper.selectOne(Wrappers.lambdaQuery(EdFileInfo.class)
.eq(EdFileInfo::getId, id)); .eq(EdFileInfo::getId, id));
String sysFilePath = commonService.getFileSysPath(fileInfo.getFilePath(), dataOwnCode); String sysFilePath = commonService.getFileSysPath(fileInfo.getFilePath(), dataOwnCode);
this.baseMapper.update(null, Wrappers.lambdaUpdate(EdFileInfo.class) this.baseMapper.update(null, Wrappers.lambdaUpdate(EdFileInfo.class)
.set(EdFileInfo::getUpdatedTime, now)
.set(EdFileInfo::getUpdatedBy, currentUserId)
.eq(EdFileInfo::getId, id) .eq(EdFileInfo::getId, id)
.set(EdFileInfo::getFileName, newFolderName)); .set(EdFileInfo::getFileName, newFolderName));
fileSystemService.renameFile(sysFilePath, newFolderName); fileSystemService.renameFile(sysFilePath, newFolderName);

View File

@ -56,18 +56,22 @@ public class OfficeFileUtil {
try { try {
String pdfParentDir = FileUtil.getParent(pdfPath, 1) + File.separatorChar + IdUtil.fastSimpleUUID() + File.separatorChar; String pdfParentDir = FileUtil.getParent(pdfPath, 1) + File.separatorChar + IdUtil.fastSimpleUUID() + File.separatorChar;
StringBuilder command = new StringBuilder(); StringBuilder command = new StringBuilder();
command.append("libreoffice").append(" ").append("--headless") command.append("/usr/bin/libreoffice24.8").append(" ").append("--headless")
.append(" ").append("--convert-to") .append(" ").append("--convert-to")
.append(" ").append("pdf") .append(" ").append("pdf")
.append(" ").append(wordPath) .append(" ").append(wordPath)
.append(" ").append("--outdir") .append(" ").append("--outdir")
.append(" ").append(pdfParentDir); .append(" ").append(pdfParentDir);
log.info("convert word file to pdf, command: {}", command);
Process process = RuntimeUtil.exec(command.toString()); Process process = RuntimeUtil.exec(command.toString());
process.waitFor(); process.waitFor();
if (process.exitValue() != 0) { if (process.exitValue() != 0) {
String info = StrFormatter.format("word文档{}转换成pdf文档{}失败", wordPath, pdfPath); String info = StrFormatter.format("word文档{}转换成pdf文档{}失败", wordPath, pdfPath);
throw new BizException(info); throw new BizException(info);
} }
String outPdfPath = FileUtil.loopFiles(pdfParentDir).get(0).getAbsolutePath();
FileUtil.move(new File(outPdfPath), new File(pdfPath), true);
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
throw new BizException(e.getMessage(), e); throw new BizException(e.getMessage(), e);