1.增加数据库导出接口部分代码逻辑。(不能运行)

This commit is contained in:
sxlong 2024-11-21 18:12:43 +08:00
parent 1bc5ab6c4d
commit 8619126d16
8 changed files with 211 additions and 8 deletions

2
.gitignore vendored
View File

@ -24,3 +24,5 @@ hs_err_pid*
.vs
.idea
*.iml
**/target/

View File

@ -15,4 +15,19 @@ public interface CategoryRepository {
* 获取所有节点
*/
List<Category> getAllCategories();
/**
* 获取节点通过编码ID
* @param category
* @return
*/
List<Category> selectCategories(Category category);
/**
* 获取子节点通过父ID
* @param category
* @return
*/
List<Category> selectChildCategories(Category category);
}

View File

@ -11,4 +11,32 @@ public interface CategoryService {
*/
public List<Category> buildCategoryTree();
/**
* 获取所有节点
* @return
*/
List<Category> selectAllCategories();
/**
* 获取节点通过编码ID
* @param category
* @return
*/
List<Category> selectCategories(Category category);
/**
* 获取子节点通过父ID
* @param category
* @return
*/
List<Category> selectChildCategories(Category category);
/**
* 获取 指定节点的 父节点 从所有节点数组中
* @param categoryId
* @param categoryList
* @return
*/
Category getParentCategories(String categoryId, List<Category> categoryList);
}

View File

@ -80,4 +80,55 @@ public class CategoryServiceImpl implements CategoryService {
private boolean hasChild(List<Category> list, Category category) {
return !getChildList(list, category).isEmpty();
}
/**
* 获取所有节点
* @return
*/
public List<Category> selectAllCategories() { return categoryRepository.getAllCategories(); }
/**
* 获取节点通过编码ID
* @param category
* @return
*/
public List<Category> selectCategories(Category category) { return categoryRepository.selectCategories(category); }
/**
* 获取子节点通过父ID
* @param category
* @return
*/
public List<Category> selectChildCategories(Category category) { return categoryRepository.selectChildCategories(category); }
/**
* 获取 指定节点的 父节点 从所有节点数组中
* @param categoryId
* @param categoryList
* @return
*/
public Category getParentCategories(String categoryId, List<Category> categoryList)
{
Category category = null;
Category categoryParent = null;
for(Category iter : categoryList)
{
if(category == null && iter.getCategoryId().equals(categoryId))
{
category = iter;
break;
}
}
for(Category iter : categoryList)
{
if(categoryParent == null && iter.getCategoryId().equals(category.getParentId()))
{
categoryParent = iter;
break;
}
}
return categoryParent;
}
}

View File

@ -19,4 +19,16 @@ public interface CategoryMapper {
* @return
*/
List<Category> selectAllCategories();
/**
* 获取节点通过编码ID
* @return
*/
List<Category> selectCategories(Category category);
/**
* 获取子节点通过父ID
* @return
*/
List<Category> selectChildCategories(Category category);
}

View File

@ -26,8 +26,22 @@ public class CategoryRepositoryImpl implements CategoryRepository {
* 获取所有节点
*/
@Override
public List<Category> getAllCategories(){
return categoryMapper.selectAllCategories();
}
public List<Category> getAllCategories() { return categoryMapper.selectAllCategories(); }
/**
* 获取节点通过编码ID
* @param category
* @return
*/
@Override
public List<Category> selectCategories(Category category) { return categoryMapper.selectCategories(category); }
/**
* 获取子节点通过父ID
* @param category
* @return
*/
@Override
public List<Category> selectChildCategories(Category category) { return categoryMapper.selectChildCategories(category); }
}

View File

@ -32,4 +32,17 @@
<include refid="selectUserVo" />
where category_status="available"
</select>
<select id="selectCategories" resultMap="CategoryResultMap"
parameterType="com.electromagnetic.industry.software.data.manage.domain.boardservice.category.model.Category">
<include refid="selectUserVo" />
where category_id = categoryId and category_status="available"
</select>
<select id="selectChildCategories" resultMap="CategoryResultMap"
parameterType="com.electromagnetic.industry.software.data.manage.domain.boardservice.category.model.Category">
<include refid="selectUserVo" />
where parent_id = parentId and category_status="available"
</select>
</mapper>

View File

@ -2,10 +2,12 @@ package com.electromagnetic.industry.software.data.manage.service.facade;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.electromagnetic.industry.software.data.manage.domain.boardservice.category.model.Category;
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.model.EDDataInfo;
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.model.EDDataPage;
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.parames.EDDataParams;
import com.electromagnetic.industry.software.data.manage.domain.boardservice.indicator.service.EDDataService;
import com.electromagnetic.industry.software.data.manage.domain.boardservice.user.service.CategoryService;
import com.electromagnetic.industry.software.data.manage.facade.EDDataFacade;
import com.electromagnetic.industry.software.data.manage.request.indicator.EDDataRequest;
import com.electromagnetic.industry.software.data.manage.response.indicator.EDDataPageResponse;
@ -29,6 +31,7 @@ public class EDDataFacadeImpl implements EDDataFacade {
@Resource
private EDDataService edDataService;
private CategoryService categoryService;
/**
* 创建文件夹
@ -59,7 +62,7 @@ public class EDDataFacadeImpl implements EDDataFacade {
edDataInfo.setNote(request.getNote());
edDataInfo.setDataId(IdWorker.getSnowFlakeIdString());
edDataInfo.setDataNo(IdWorker.getSnowFlakeIdString());
edDataInfo.setDataNo(edDataInfo.getDataId());
edDataInfo.setDataType("folder");
edDataInfo.setVersion("1.0.0");
edDataInfo.setDataStatus("publish");
@ -228,7 +231,8 @@ public class EDDataFacadeImpl implements EDDataFacade {
// 文件保存目录路径
String fileSavePath = storageDirectory + "/" + parentFolderPath;
String treeName = "目录树名称";
String newFileName = treeName + "," + parentFolderName + "," + fileFullName;
//String newFileName = treeName + "," + parentFolderName + "," + fileFullName;
String newFileName = fileFullName;
// 文件数据信息写到数据库
{
@ -253,7 +257,7 @@ public class EDDataFacadeImpl implements EDDataFacade {
edDataInfo.setGmtBatchUpload(request.getGmtBatchUpload());
edDataInfo.setDataId(IdWorker.getSnowFlakeIdString());
edDataInfo.setDataNo(IdWorker.getSnowFlakeIdString());
edDataInfo.setDataNo(edDataInfo.getDataId());
edDataInfo.setDataType("file");
edDataInfo.setVersion("1.0.0");
edDataInfo.setDataStatus("publish");
@ -267,7 +271,7 @@ public class EDDataFacadeImpl implements EDDataFacade {
boolean isSuccess = edDataService.createDataInfo(edDataInfo);
String userHome = System.getProperty("user.home");
File cacheDirectory = new File(userHome + "\\AppData\\Local\\Temp\\EDData");
File cacheDirectory = new File(userHome + "\\AppData\\Local\\Temp\\EDData\\Upload");
if (!cacheDirectory.exists()) {
cacheDirectory.mkdirs();
}
@ -358,6 +362,70 @@ public class EDDataFacadeImpl implements EDDataFacade {
//2循环list将每个文件复制到新建目录并进行重命名命名规则目录树编码+,+文件夹编码有则填写无则为空+,+文件编码
//3打包新建为zip并根据生产下载地址域名+文件路径+文件
//4返回前端下载的地址
// **********在导出的过程中可能会出现有用户上传文件的情况
// 获取目录编码ID
String categoryId = request.getParentId();
// 获取缓存文件夹的绝对路径
String userHome = System.getProperty("user.home");
File cacheDirectory = new File(userHome + "\\AppData\\Local\\Temp\\EDData\\Export");
if (!cacheDirectory.exists()) {
cacheDirectory.mkdirs();
}
String cacheFolder = cacheDirectory.getAbsolutePath(); // 缓存文件夹的绝对路径
List<Category> categoryList = categoryService.selectAllCategories();
{
// 遍历客户端上传的
EDDataParams folderParames = new EDDataParams();
for (String dataId : request.getDataIdArr()) {
Category category = new Category();
category.setCategoryId(dataId);
categoryService.selectCategories(category);
//folderParames.setDataId(dataId);
//EDDataInfo edDataInfo = edDataService.getDataInfo(folderParames);
//if(edDataInfo != null)
//{
// JSONObject implantJsonObject = JSON.parseObject(edDataInfo.getImplantJson());
// String filePath = implantJsonObject.getString("folderPath");
// filePath = storageDirectory + "/" + filePath + "/" + edDataInfo.getDataName();
// dataPathArr.add(filePath);
//}
}
}
String parentFolderPath = ""; //上级文件夹路径
String parentFolderIdPath = ""; //上级文件夹ID路径
String parentFolderName = ""; //上级文件夹名称
// 获取上级文件夹路径
{
EDDataParams folderParames = new EDDataParams();
folderParames.setDataId(categoryId);
EDDataInfo edDataInfoParent = edDataService.getDataInfo(folderParames);
if(edDataInfoParent == null) {
ElectromagneticResultUtil.fail(HttpStatus.BAD_REQUEST.toString(),"上级文件夹为空!");
}
JSONObject implantJsonObject = JSON.parseObject(edDataInfoParent.getImplantJson());
parentFolderPath = implantJsonObject.getString("folderPath");
parentFolderIdPath = implantJsonObject.getString("folderIdPath");
if(!parentFolderPath.isEmpty())
parentFolderPath += "/" ;
if(!parentFolderIdPath.isEmpty())
parentFolderIdPath += "/" ;
parentFolderPath += edDataInfoParent.getDataName();
parentFolderIdPath += edDataInfoParent.getDataId();
parentFolderName = edDataInfoParent.getDataName();
}
return null;
}