Merge branch 'dev-jdk17' of http://139.196.179.195:3000/chenxudong/electromagnetic-data-new into dev-jdk17
This commit is contained in:
commit
a0bbdaddc8
|
|
@ -10,7 +10,8 @@ import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
|||
import com.electromagnetic.industry.software.manage.pojo.models.EdFileRelation;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.CheckNameUniqueRequest;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.UpdateRelationDTO;
|
||||
import com.electromagnetic.industry.software.manage.service.serviceimpl.EdFileRelationServiceImpl;
|
||||
import com.electromagnetic.industry.software.manage.service.EdFileInfoService;
|
||||
import com.electromagnetic.industry.software.manage.service.EdFileRelationService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
|
@ -20,8 +21,10 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
public class RepoEdFileRelationController {
|
||||
|
||||
@Resource
|
||||
EdFileRelationServiceImpl edFileRelationService;
|
||||
EdFileRelationService edFileRelationService;
|
||||
|
||||
@Resource
|
||||
EdFileInfoService edFileInfoService;
|
||||
/**
|
||||
* 创建文件关系
|
||||
*
|
||||
|
|
@ -91,6 +94,6 @@ public class RepoEdFileRelationController {
|
|||
@RequestParam("file") MultipartFile file,
|
||||
@RequestParam("description") String description,
|
||||
@RequestParam("id") String id) {
|
||||
return ElectromagneticResultUtil.success(edFileRelationService.uploadFileAndRelation(parentId, id, file, description, DataOwnEnum.SYS_FILE.code));
|
||||
return ElectromagneticResultUtil.success(edFileInfoService.uploadFileAndRelation(parentId, id, file, description, DataOwnEnum.REPO_FILE.code));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@ import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
|||
import com.electromagnetic.industry.software.manage.pojo.models.EdFileRelation;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.CheckNameUniqueRequest;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.UpdateRelationDTO;
|
||||
import com.electromagnetic.industry.software.manage.service.serviceimpl.EdFileRelationServiceImpl;
|
||||
import com.electromagnetic.industry.software.manage.service.EdFileInfoService;
|
||||
import com.electromagnetic.industry.software.manage.service.EdFileRelationService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
|
@ -20,7 +21,9 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
public class SysEdFileRelationController {
|
||||
|
||||
@Resource
|
||||
EdFileRelationServiceImpl edFileRelationService;
|
||||
EdFileRelationService edFileRelationService;
|
||||
@Resource
|
||||
EdFileInfoService edFileInfoService;
|
||||
|
||||
/**
|
||||
* 创建文件关系
|
||||
|
|
@ -91,6 +94,6 @@ public class SysEdFileRelationController {
|
|||
@RequestParam("file") MultipartFile file,
|
||||
@RequestParam("description") String description,
|
||||
@RequestParam("id") String id) {
|
||||
return ElectromagneticResultUtil.success(edFileRelationService.uploadFileAndRelation(parentId, id, file, description, DataOwnEnum.SYS_FILE.code));
|
||||
return ElectromagneticResultUtil.success(edFileInfoService.uploadFileAndRelation(parentId, id, file, description, DataOwnEnum.SYS_FILE.code));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
|||
import com.electromagnetic.industry.software.manage.pojo.models.EdFileRelation;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.CheckNameUniqueRequest;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.UpdateRelationDTO;
|
||||
import com.electromagnetic.industry.software.manage.service.EdFileInfoService;
|
||||
import com.electromagnetic.industry.software.manage.service.EdFileRelationService;
|
||||
import com.electromagnetic.industry.software.manage.service.serviceimpl.EdFileRelationServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
|
@ -20,7 +22,9 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
public class UserEdFileRelationController {
|
||||
|
||||
@Resource
|
||||
EdFileRelationServiceImpl edFileRelationService;
|
||||
EdFileRelationService edFileRelationService;
|
||||
@Resource
|
||||
EdFileInfoService edFileInfoService;
|
||||
|
||||
/**
|
||||
* 创建文件关系
|
||||
|
|
@ -91,6 +95,6 @@ public class UserEdFileRelationController {
|
|||
@RequestParam("file") MultipartFile file,
|
||||
@RequestParam("description") String description,
|
||||
@RequestParam("id") String id) {
|
||||
return ElectromagneticResultUtil.success(edFileRelationService.uploadFileAndRelation(parentId, id, file, description, DataOwnEnum.SYS_FILE.code));
|
||||
return ElectromagneticResultUtil.success(edFileInfoService.uploadFileAndRelation(parentId, id, file, description, DataOwnEnum.USER_FILE.code));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -197,14 +197,6 @@ public interface EdFileInfoService {
|
|||
*/
|
||||
void resetFileInfoName(EdFileInfo fileInfo);
|
||||
|
||||
/**
|
||||
* 判断是否是文件夹
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public boolean isFolder(String id);
|
||||
|
||||
/**
|
||||
* 添加收藏
|
||||
*
|
||||
|
|
@ -240,4 +232,15 @@ public interface EdFileInfoService {
|
|||
* @return
|
||||
*/
|
||||
IPage<FileInfoVO> findFavorite(String userId, FileInfoQueryDTO fileInfoQueryDTO);
|
||||
|
||||
/**
|
||||
* 文件上传并建立关系
|
||||
*
|
||||
* @param parentId
|
||||
* @param id 主文件Id
|
||||
* @param file
|
||||
* @param desc 关系描述
|
||||
* @return
|
||||
*/
|
||||
ElectromagneticResult<?> uploadFileAndRelation(String parentId, String id, MultipartFile file, String desc, int dataOwnCode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,14 +40,4 @@ public interface EdFileRelationService extends IService<EdFileRelation> {
|
|||
*/
|
||||
Boolean checkNameExist(CheckNameUniqueRequest checkNameUniqueRequest);
|
||||
|
||||
/**
|
||||
* 文件上传并建立关系
|
||||
*
|
||||
* @param parentId
|
||||
* @param id 主文件Id
|
||||
* @param file
|
||||
* @param desc 关系描述
|
||||
* @return
|
||||
*/
|
||||
ElectromagneticResult<?> uploadFileAndRelation(String parentId, String id, MultipartFile file, String desc, int dataOwnCode);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1296,19 +1296,6 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
return this.baseMapper.queryFileList(page, ids, queryDTO, saveStatus, effectFlag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否是文件夹
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean isFolder(String id) {
|
||||
EdFileInfo fileInfo = this.baseMapper.selectById(id);
|
||||
Assert.notNull(fileInfo, StrFormatter.format("文件不存在,ID为{}", id));
|
||||
return fileInfo.getDataType().equals(EleDataTypeEnum.FOLDER.code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加收藏
|
||||
*
|
||||
|
|
@ -1422,4 +1409,31 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
return fileInfoVOIPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传并建立关系
|
||||
*
|
||||
* @param parentId
|
||||
* @param id 主文件Id
|
||||
* @param file
|
||||
* @param desc 关系描述
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ElectromagneticResult<?> uploadFileAndRelation(String parentId, String id, MultipartFile file, String desc, int dataOwnCode) {
|
||||
|
||||
// 上传文件
|
||||
ElectromagneticResult<?> uploadResult = upload(parentId, file, FileRepeatEnum.NEW.code, dataOwnCode);
|
||||
Assert.notNull(uploadResult.getData(), "上传失败");
|
||||
String relatedFileId = (String) uploadResult.getData();
|
||||
// 创建文件关系
|
||||
EdFileRelation relation = new EdFileRelation();
|
||||
relation.newInit();
|
||||
relation.setId1(id);
|
||||
relation.setId2(relatedFileId);
|
||||
relation.setRelationship(desc);
|
||||
edFileRelationService.createRelation(relation);
|
||||
UserThreadLocal.setSuccessInfo("", id, StrFormatter.format("建立了文件 {} 与文件 {} 的关系", id, relatedFileId));
|
||||
return ElectromagneticResultUtil.success(true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,12 @@
|
|||
package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.text.StrFormatter;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.electromagnetic.industry.software.common.enums.*;
|
||||
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||
import com.electromagnetic.industry.software.common.util.*;
|
||||
import com.electromagnetic.industry.software.manage.mapper.EdFileInfoMapper;
|
||||
import com.electromagnetic.industry.software.manage.mapper.EdFileRelationMapper;
|
||||
|
|
@ -25,7 +21,6 @@ import jakarta.annotation.Resource;
|
|||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
|
@ -36,8 +31,6 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
|||
|
||||
@Resource
|
||||
EdFileInfoMapper edFileInfoMapper;
|
||||
@Resource
|
||||
private CommonService commonService;
|
||||
|
||||
/**
|
||||
* 创建文件关系
|
||||
|
|
@ -52,7 +45,7 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
|||
String queryId1 = edFileRelation.getId1();
|
||||
String queryId2 = edFileRelation.getId2();
|
||||
|
||||
if (commonService.isFolder(queryId1) || commonService.isFolder(queryId2)) {
|
||||
if (isFolder(queryId1) || isFolder(queryId2)) {
|
||||
throw new BizException("文件夹无法建立关系");
|
||||
}
|
||||
|
||||
|
|
@ -202,108 +195,10 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
|||
return edges;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
*
|
||||
* @param parentId
|
||||
* @param id 主文件Id
|
||||
* @param file
|
||||
* @param desc 关系描述
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ElectromagneticResult<?> uploadFileAndRelation(String parentId, String id, MultipartFile file, String desc, int dataOwnCode) {
|
||||
|
||||
Assert.isTrue(EleCommonUtil.isFileNameValid(file.getOriginalFilename()), NAME_VALID_MSG);
|
||||
String fileName = file.getOriginalFilename();
|
||||
String mainName = FileUtil.mainName(fileName);
|
||||
String suffix = FileUtil.getSuffix(fileName);
|
||||
Assert.isTrue(StrUtil.isNotEmpty(suffix), "文件类型不能为空");
|
||||
// 查找下一层,看是否存在顶级定义相关文件,如果存在,则该层属于管理员层级定义的,不允许上传文件
|
||||
long dirCount = edFileInfoMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
.eq(EdFileInfo::getParentId, parentId)
|
||||
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
||||
.eq(EdFileInfo::getDataOwn, dataOwnCode)
|
||||
.eq(EdFileInfo::getDataType, EleDataTypeEnum.FOLDER.code));
|
||||
Assert.isTrue(dirCount == 0, "层级目录不允许上传文件");
|
||||
|
||||
EdFileInfo newEdFileInfo = new EdFileInfo();
|
||||
newEdFileInfo.newInit();
|
||||
try {
|
||||
Assert.isTrue(EleCommonUtil.isFileNameValid(fileName), NAME_VALID_MSG);
|
||||
Long count = edFileInfoMapper.selectCount(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
.eq(EdFileInfo::getParentId, parentId)
|
||||
.eq(EdFileInfo::getFileName, mainName)
|
||||
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code)
|
||||
.eq(EdFileInfo::getFileType, suffix));
|
||||
|
||||
EdFileInfo parentFileInfo = edFileInfoMapper.selectOne(Wrappers.lambdaQuery(EdFileInfo.class)
|
||||
.select(EdFileInfo.class, obj -> !StrUtil.equals(obj.getColumn(), "file_content"))
|
||||
.eq(EdFileInfo::getId, parentId)
|
||||
.eq(EdFileInfo::getEffectFlag, EffectFlagEnum.EFFECT.code));
|
||||
String codePathByDbPath = commonService.getCodePathByDbPath(parentFileInfo.getFilePath());
|
||||
String fileCode = commonService.createFileCode(codePathByDbPath, suffix, FILE_START_VERSION, newEdFileInfo.getFileTime());
|
||||
newEdFileInfo.setParentId(parentId)
|
||||
.setFileCode(fileCode)
|
||||
.setFileName(mainName)
|
||||
.setFileType(suffix)
|
||||
.setFileVersion(FILE_START_VERSION)
|
||||
.setFileTime(newEdFileInfo.getFileTime())
|
||||
.setFileSize(file.getSize())
|
||||
.setFilePath(parentFileInfo.getFilePath() + MYSQL_FILE_PATH_SPLIT + newEdFileInfo.getId())
|
||||
.setDataType(EleDataTypeEnum.FILE.code)
|
||||
.setDataStatus(PublishEnum.PUBLISHED.getCode())
|
||||
.setFileCode(fileCode)
|
||||
.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code)
|
||||
.setDataOwn(dataOwnCode)
|
||||
.setEffectFlag(EffectFlagEnum.EFFECT.code);
|
||||
|
||||
// 文件名加”_1“,存为新文件
|
||||
if (count > 0) {
|
||||
commonService.resetFileInfoName(newEdFileInfo);
|
||||
}
|
||||
edFileInfoMapper.insertOrUpdate(newEdFileInfo);
|
||||
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getId());
|
||||
FileUtil.writeFromStream(file.getInputStream(), fileDestPath);
|
||||
EleCommonUtil.encryptFile(fileDestPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes()));
|
||||
|
||||
// 创建文件关系
|
||||
EdFileRelation relation = new EdFileRelation();
|
||||
relation.setId1(id);
|
||||
relation.setId2(newEdFileInfo.getId());
|
||||
relation.setRelationship(desc);
|
||||
createRelation(relation);
|
||||
|
||||
} catch (Exception e) {
|
||||
newEdFileInfo.setParentId(parentId)
|
||||
.setFileName(mainName)
|
||||
.setFileType(suffix)
|
||||
.setFileSize(file.getSize())
|
||||
.setDataType(EleDataTypeEnum.FILE.code)
|
||||
.setDataStatus(PublishEnum.PUBLISHED.getCode())
|
||||
.setSaveStatus(EleDataSaveStatusEnum.FAIL.code)
|
||||
.setDataOwn(dataOwnCode)
|
||||
.setEffectFlag(EffectFlagEnum.NOT_EFFECTIVE.code);
|
||||
edFileInfoMapper.insertOrUpdate(newEdFileInfo);
|
||||
String info = "上传文件失败";
|
||||
log.error(info, e);
|
||||
throw new BizException(info);
|
||||
}
|
||||
UserThreadLocal.setSuccessInfo(newEdFileInfo.getParentId(), newEdFileInfo.getId(), "上传了文件并建立了文件关系");
|
||||
// 上传文件
|
||||
ElectromagneticResult<?> uploadResult = commonService.upload(parentId, file, FileRepeatEnum.NEW.code, dataOwnCode);
|
||||
Assert.notNull(uploadResult.getData(), "上传失败");
|
||||
String relatedFileId = (String) uploadResult.getData();
|
||||
// 创建文件关系
|
||||
EdFileRelation relation = new EdFileRelation();
|
||||
relation.newInit();
|
||||
relation.setId1(id);
|
||||
relation.setId2(relatedFileId);
|
||||
relation.setRelationship(desc);
|
||||
createRelation(relation);
|
||||
UserThreadLocal.setSuccessInfo("", id, StrFormatter.format("建立了文件 {} 与文件 {} 的关系", id, relatedFileId));
|
||||
return ElectromagneticResultUtil.success(true);
|
||||
private boolean isFolder(String id) {
|
||||
EdFileInfo fileInfo = edFileInfoMapper.selectById(id);
|
||||
Assert.notNull(fileInfo, StrFormatter.format("文件不存在,ID为{}", id));
|
||||
return fileInfo.getDataType().equals(EleDataTypeEnum.FOLDER.code);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue