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

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; 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.common.resp.ElectromagneticResult;
import com.electromagnetic.industry.software.manage.pojo.models.EdFileRelation; 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.CheckNameUniqueRequest;
import com.electromagnetic.industry.software.manage.pojo.resp.FileRelationViewVO; import com.electromagnetic.industry.software.manage.pojo.resp.FileRelationViewVO;
import org.springframework.web.multipart.MultipartFile; 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; 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.common.resp.ElectromagneticResult;
import com.electromagnetic.industry.software.manage.pojo.models.UserAccessLog;
import com.electromagnetic.industry.software.manage.pojo.req.AccessLogQueryDTO; 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 @Resource
private FileTagRelationService fileTagRelationService; private FileTagRelationService fileTagRelationService;
@Resource @Resource
private FileTagRelationMapper fileTagRelationMapper; private UserAccessLogService userAccessLogService;
@Resource @Resource
private EdFileRelationMapper edFileRelationMapper; private EdFileRelationService edFileRelationService;
@Resource
private EdFileFavoriteMapper edFileFavoriteMapper;
@Resource
private UserAccessLogMapper userAccessLogMapper;
/** /**
* 查询文件列表 * 查询文件列表
@ -95,7 +91,6 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
*/ */
@Override @Override
public ElectromagneticResult<?> queryEdFileInfo(FileInfoQueryDTO pars, int dataOwnCode) { public ElectromagneticResult<?> queryEdFileInfo(FileInfoQueryDTO pars, int dataOwnCode) {
if (DataOwnEnum.isSysCode(dataOwnCode)) { if (DataOwnEnum.isSysCode(dataOwnCode)) {
String parentId = pars.getParentId(); String parentId = pars.getParentId();
List<String> accessibleTree = permissionService.getAccessibleTree(); List<String> accessibleTree = permissionService.getAccessibleTree();
@ -485,29 +480,40 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
public void update2Database(String prjDirPath, int dataOwnCode) { public void update2Database(String prjDirPath, int dataOwnCode) {
String info = FileUtil.readString(prjDirPath + File.separator + "mysql.json", Charset.defaultCharset()); updatePrjInfo(prjDirPath, dataOwnCode);
Map<String, Object> importInfoMap = JSONUtil.toBean(info, Map.class); updateCollectionInfo(prjDirPath);
updatePrjInfo(importInfoMap, prjDirPath, dataOwnCode); updateFileTageInfo(prjDirPath);
updateCollectionInfo(importInfoMap); updateFileRelationInfo(prjDirPath);
updateFileTageInfo(importInfoMap); updateUserAccessLog(prjDirPath);
updateFileRelationInfo(importInfoMap);
} }
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) { private void updateFileTageInfo(String prjDirPath) {
List<EdFileFavorite> edFileFavorites = (List<EdFileFavorite>) importInfoMap.getOrDefault(ED_FILE_FAVORITE, new ArrayList<>()); String path = prjDirPath + File.separator + USER_ACCESS_LOG + ".json";
edFileFavoriteMapper.insertOrUpdate(edFileFavorites); 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) { private void updateCollectionInfo(String prjDirPath) {
List<EdFileInfo> importAllFiles = (List<EdFileInfo>) importInfoMap.getOrDefault(PRJ_INFO, new ArrayList<>()); 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())) List<EdFileInfo> prjFolders = importAllFiles.stream().filter(e -> DataOwnEnum.isPrjCode(e.getDataOwn()))
.toList(); .toList();
@ -781,21 +787,21 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
} }
private void exportLogInfo(String nowTimeStr, List<String> exportFileIds, String userDownloadDataDir) { 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 json = JSONUtil.toJsonStr(userAccessLogs);
String path = userDownloadDataDir + File.separator + EXPORT_PRJ_NAME + "_" + nowTimeStr + File.separator + USER_ACCESS_LOG + ".json"; String path = userDownloadDataDir + File.separator + EXPORT_PRJ_NAME + "_" + nowTimeStr + File.separator + USER_ACCESS_LOG + ".json";
fileSystemService.writeStringToFile(path, json); fileSystemService.writeStringToFile(path, json);
} }
private void exportFileTagInfo(String nowTimeStr, List<String> exportFileIds, String userDownloadDataDir) { 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 path = userDownloadDataDir + File.separator + EXPORT_PRJ_NAME + "_" + nowTimeStr + File.separator + ED_TAG_RELATIONS + ".json";
String json = JSONUtil.toJsonStr(fileTagRelations); String json = JSONUtil.toJsonStr(fileTagRelations);
fileSystemService.writeStringToFile(path, json); fileSystemService.writeStringToFile(path, json);
} }
private void exportFileRelationInfo(String nowTimeStr, List<String> exportFileIds, String userDownloadDataDir) { 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() .or()
.in(EdFileRelation::getId2, exportFileIds)); .in(EdFileRelation::getId2, exportFileIds));
String json = JSONUtil.toJsonStr(edFileRelations); 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) { 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 json = JSONUtil.toJsonStr(edFileFavorites);
String path = userDownloadDataDir + File.separator + EXPORT_PRJ_NAME + "_" + nowTimeStr + File.separator + ED_FILE_FAVORITE + ".json"; String path = userDownloadDataDir + File.separator + EXPORT_PRJ_NAME + "_" + nowTimeStr + File.separator + ED_FILE_FAVORITE + ".json";
fileSystemService.writeStringToFile(path, json); fileSystemService.writeStringToFile(path, json);

View File

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