完成导入导出文件其余属性的大体逻辑。

This commit is contained in:
chenxudong 2025-04-16 18:00:42 +08:00
parent dda88c8aad
commit d9525bc13b
4 changed files with 37 additions and 29 deletions

View File

@ -1,12 +1,13 @@
package com.electromagnetic.industry.software.manage.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
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.resp.FileRelationViewVO;
import org.springframework.web.multipart.MultipartFile;
public interface EdFileRelationService {
public interface EdFileRelationService extends IService<EdFileRelation> {
/**
* 创建文件关系

View File

@ -1,9 +1,11 @@
package com.electromagnetic.industry.software.manage.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
import com.electromagnetic.industry.software.manage.pojo.models.UserAccessLog;
import com.electromagnetic.industry.software.manage.pojo.req.AccessLogQueryDTO;
public interface UserAccessLogService {
public interface UserAccessLogService extends IService<UserAccessLog> {
/**
* 分页查询操作记录审计

View File

@ -79,13 +79,9 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
@Resource
private FileTagRelationService fileTagRelationService;
@Resource
private FileTagRelationMapper fileTagRelationMapper;
private UserAccessLogService userAccessLogService;
@Resource
private EdFileRelationMapper edFileRelationMapper;
@Resource
private EdFileFavoriteMapper edFileFavoriteMapper;
@Resource
private UserAccessLogMapper userAccessLogMapper;
private EdFileRelationService edFileRelationService;
/**
* 查询文件列表
@ -95,7 +91,6 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
*/
@Override
public ElectromagneticResult<?> queryEdFileInfo(FileInfoQueryDTO pars, int dataOwnCode) {
if (DataOwnEnum.isSysCode(dataOwnCode)) {
String parentId = pars.getParentId();
List<String> accessibleTree = permissionService.getAccessibleTree();
@ -485,29 +480,40 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
public void update2Database(String prjDirPath, int dataOwnCode) {
String info = FileUtil.readString(prjDirPath + File.separator + "mysql.json", Charset.defaultCharset());
Map<String, Object> importInfoMap = JSONUtil.toBean(info, Map.class);
updatePrjInfo(importInfoMap, prjDirPath, dataOwnCode);
updateCollectionInfo(importInfoMap);
updateFileTageInfo(importInfoMap);
updateFileRelationInfo(importInfoMap);
updatePrjInfo(prjDirPath, dataOwnCode);
updateCollectionInfo(prjDirPath);
updateFileTageInfo(prjDirPath);
updateFileRelationInfo(prjDirPath);
updateUserAccessLog(prjDirPath);
}
private void updateFileRelationInfo(Map<String, Object> importInfoMap) {
private void updateUserAccessLog(String prjDirPath) {
String path = prjDirPath + File.separator + USER_ACCESS_LOG + ".json";
List<UserAccessLog> userAccessLogs = JSONUtil.toList(FileUtil.readString(path, Charset.defaultCharset()), UserAccessLog.class);
userAccessLogService.saveOrUpdateBatch(userAccessLogs);
}
private void updateFileTageInfo(Map<String, Object> importInfoMap) {
private void updateFileRelationInfo(String prjDirPath) {
String path = prjDirPath + File.separator + ED_TAG_RELATIONS + ".json";
List<EdFileRelation> relations = JSONUtil.toList(FileUtil.readString(path, Charset.defaultCharset()), EdFileRelation.class);
edFileRelationService.saveOrUpdateBatch(relations);
}
private void updateCollectionInfo(Map<String, Object> importInfoMap) {
List<EdFileFavorite> edFileFavorites = (List<EdFileFavorite>) importInfoMap.getOrDefault(ED_FILE_FAVORITE, new ArrayList<>());
edFileFavoriteMapper.insertOrUpdate(edFileFavorites);
private void updateFileTageInfo(String prjDirPath) {
String path = prjDirPath + File.separator + USER_ACCESS_LOG + ".json";
List<FileTagRelation> relations = JSONUtil.toList(FileUtil.readString(path, Charset.defaultCharset()), FileTagRelation.class);
fileTagRelationService.saveOrUpdateBatch(relations);
}
private void updatePrjInfo(Map<String, Object> importInfoMap, String prjDirPath, Integer dataOwnCode) {
List<EdFileInfo> importAllFiles = (List<EdFileInfo>) importInfoMap.getOrDefault(PRJ_INFO, new ArrayList<>());
private void updateCollectionInfo(String prjDirPath) {
String path = prjDirPath + File.separator + ED_FILE_FAVORITE + ".json";
List<EdFileFavorite> edFileFavorites = JSONUtil.toList(FileUtil.readString(path, Charset.defaultCharset()), EdFileFavorite.class);
fileFavoriteService.saveOrUpdateBatch(edFileFavorites);
}
private void updatePrjInfo(String prjDirPath, Integer dataOwnCode) {
String path = prjDirPath + File.separator + PRJ_INFO + ".json";
List<EdFileInfo> importAllFiles = JSONUtil.toList(FileUtil.readString(path, Charset.defaultCharset()), EdFileInfo.class);
// 找出层级文件夹
List<EdFileInfo> prjFolders = importAllFiles.stream().filter(e -> DataOwnEnum.isPrjCode(e.getDataOwn()))
.toList();
@ -781,21 +787,21 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
}
private void exportLogInfo(String nowTimeStr, List<String> exportFileIds, String userDownloadDataDir) {
List<UserAccessLog> userAccessLogs = userAccessLogMapper.selectList(null);
List<UserAccessLog> userAccessLogs = userAccessLogService.getBaseMapper().selectList(null);
String json = JSONUtil.toJsonStr(userAccessLogs);
String path = userDownloadDataDir + File.separator + EXPORT_PRJ_NAME + "_" + nowTimeStr + File.separator + USER_ACCESS_LOG + ".json";
fileSystemService.writeStringToFile(path, json);
}
private void exportFileTagInfo(String nowTimeStr, List<String> exportFileIds, String userDownloadDataDir) {
List<FileTagRelation> fileTagRelations = fileTagRelationMapper.selectList(Wrappers.lambdaQuery(FileTagRelation.class).in(FileTagRelation::getFileId, exportFileIds));
List<FileTagRelation> fileTagRelations = fileTagRelationService.getBaseMapper().selectList(Wrappers.lambdaQuery(FileTagRelation.class).in(FileTagRelation::getFileId, exportFileIds));
String path = userDownloadDataDir + File.separator + EXPORT_PRJ_NAME + "_" + nowTimeStr + File.separator + ED_TAG_RELATIONS + ".json";
String json = JSONUtil.toJsonStr(fileTagRelations);
fileSystemService.writeStringToFile(path, json);
}
private void exportFileRelationInfo(String nowTimeStr, List<String> exportFileIds, String userDownloadDataDir) {
List<EdFileRelation> edFileRelations = edFileRelationMapper.selectList(Wrappers.lambdaQuery(EdFileRelation.class).in(EdFileRelation::getId1, exportFileIds)
List<EdFileRelation> edFileRelations = edFileRelationService.getBaseMapper().selectList(Wrappers.lambdaQuery(EdFileRelation.class).in(EdFileRelation::getId1, exportFileIds)
.or()
.in(EdFileRelation::getId2, exportFileIds));
String json = JSONUtil.toJsonStr(edFileRelations);
@ -804,7 +810,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
}
private void exportCollectionInfo(String nowTimeStr, List<String> exportFileIds, String userDownloadDataDir) {
List<EdFileFavorite> edFileFavorites = edFileFavoriteMapper.selectList(Wrappers.lambdaQuery(EdFileFavorite.class).in(EdFileFavorite::getFileId, exportFileIds));
List<EdFileFavorite> edFileFavorites = fileFavoriteService.getBaseMapper().selectList(Wrappers.lambdaQuery(EdFileFavorite.class).in(EdFileFavorite::getFileId, exportFileIds));
String json = JSONUtil.toJsonStr(edFileFavorites);
String path = userDownloadDataDir + File.separator + EXPORT_PRJ_NAME + "_" + nowTimeStr + File.separator + ED_FILE_FAVORITE + ".json";
fileSystemService.writeStringToFile(path, json);

View File

@ -31,7 +31,6 @@ import java.util.stream.Collectors;
@Service
public class UserAccessLogServiceImpl extends ServiceImpl<UserAccessLogMapper, UserAccessLog> implements UserAccessLogService {
@Resource
private UserMapper userMapper;