1.更新创建文件夹和上传文件接口(能正常运行)。

This commit is contained in:
sxlong 2024-11-19 11:53:51 +08:00
parent ce18fd577e
commit 6fa792ae48
4 changed files with 47 additions and 23 deletions

View File

@ -15,7 +15,7 @@ spring.datasource.typd=com.alibaba.druid.pool.DruidDataSource
#spring.datasource.url=jdbc:mysql://${DATASOURCE_URL:obproxy-0c63.ops.cloud.cic.inter}:3306/${DATASOURCE_HOST:dataplatform_ptst}?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=true&rewriteBatchedStatements=true
#spring.datasource.username=${DATASOURCE_NAME:dataplatform@ProjectTest_tenant5#testdb}
#spring.datasource.password=${DATASOURCE_PASSWORD:Y7G6v4_3ijn77K_Kbl_U85}
spring.datasource.url=jdbc:mysql://139.196.179.195:3306/em_data?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=true&rewriteBatchedStatements=true
spring.datasource.url=jdbc:mysql://139.224.43.89:3306/em_data?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=true&rewriteBatchedStatements=true
spring.datasource.username=comac
spring.datasource.password=2024*Comac

View File

@ -58,7 +58,10 @@ public class EDDataRepositoryImpl implements EDDataRepository {
public EDDataInfo getDataInfo(EDDataParams parames)
{
List<EDDataInfo> edDataInfoList=edDataMapper.getDataInfoList(parames);
if(edDataInfoList.size()>0)
return edDataInfoList.get(0);
else
return null;
}
/**

View File

@ -15,6 +15,7 @@
<result column="implant_json" jdbcType="VARCHAR" property="implantJson" />
<result column="data_status" jdbcType="VARCHAR" property="dataStatus" />
<result column="note" jdbcType="VARCHAR" property="note" />
<result column="editor" jdbcType="VARCHAR" property="editor" />
<result column="creator" jdbcType="VARCHAR" property="creator" />
<result column="creator_name" jdbcType="VARCHAR" property="creatorName" />
<result column="gmt_create" jdbcType="TIMESTAMP" property="gmtCreate" />
@ -38,7 +39,7 @@
data_id, data_no, data_name,
data_type, file_type,version,
content, implant_json, data_status,note,
creator, creator_name, gmt_create,
editor, creator, creator_name, gmt_create,
modifier, modifier_name, gmt_modified,
effect_flag
)
@ -46,7 +47,7 @@
#{dataId,jdbcType=VARCHAR}, #{dataNo,jdbcType=VARCHAR}, #{dataName,jdbcType=VARCHAR},
#{dataType,jdbcType=VARCHAR}, #{fileType,jdbcType=VARCHAR},#{version,jdbcType=VARCHAR},
#{content,jdbcType=VARCHAR}, #{implantJson,jdbcType=VARCHAR}, #{dataStatus,jdbcType=VARCHAR}, #{note,jdbcType=VARCHAR},
#{creator,jdbcType=VARCHAR}, #{creatorName,jdbcType=VARCHAR}, now(), #{modifier,jdbcType=VARCHAR},
#{editor,jdbcType=VARCHAR}, #{creator,jdbcType=VARCHAR}, #{creatorName,jdbcType=VARCHAR}, now(), #{modifier,jdbcType=VARCHAR},
#{modifierName,jdbcType=VARCHAR},now(),1
)
</insert>

View File

@ -44,7 +44,7 @@ public class EDDataFacadeImpl implements EDDataFacade {
if (request.getUserId() == null || request.getUserId().isEmpty()) request.setUserId(IdWorker.getSnowFlakeIdString());
if (request.getUserName() == null || request.getUserName().isEmpty()) request.setUserName("user");
if (request.getName() == null || request.getName().isEmpty()) request.setName("testFolder");
if (request.getParentId() == null || request.getParentId().isEmpty()) request.setParentId(IdWorker.getSnowFlakeIdString());
//if (request.getParentId() == null || request.getParentId().isEmpty()) request.setParentId(IdWorker.getSnowFlakeIdString());
}
edDataInfo.setCreator(request.getUserId());
@ -61,22 +61,36 @@ public class EDDataFacadeImpl implements EDDataFacade {
edDataInfo.setVersion("1.0.0");
edDataInfo.setDataStatus("publish");
String newFolderPath = "";
String parentFolderPath = "";
// 获取上级目录的名称
if(!request.getParentId().isEmpty()) {
EDDataParams parames = new EDDataParams();
parames.setParentId(request.getParentId());
parames.setDataId(request.getParentId());
EDDataInfo edDataInfoParent = edDataService.getDataInfo(parames);
String folderName = edDataInfoParent.getDataName();
String folderId = edDataInfoParent.getDataId();
if(edDataInfoParent == null) {
ElectromagneticResultUtil.fail(HttpStatus.BAD_REQUEST.toString(),"上级文件夹为空!");
}
String folderNameParent = edDataInfoParent.getDataName();
String folderIdParent = edDataInfoParent.getDataId();
// 记录当前目录的文件夹路径和文件夹id路径
JSONObject implantJsonObject = JSON.parseObject(edDataInfoParent.getImplantJson());
if(implantJsonObject == null) {
implantJsonObject = new JSONObject();
parentFolderPath = folderNameParent;
implantJsonObject.put("folderPath", parentFolderPath);
implantJsonObject.put("folderIdPath", folderIdParent);
}
else
{
String folderPath = implantJsonObject.getString("folderPath");
String folderIdPath = implantJsonObject.getString("folderIdPath");
newFolderPath = folderPath + folderName;
implantJsonObject.put("folderPath", newFolderPath);
implantJsonObject.put("folderIdPath", folderIdPath + folderId);
parentFolderPath = folderPath + "/" + folderNameParent;
implantJsonObject.put("folderPath", parentFolderPath);
implantJsonObject.put("folderIdPath", folderIdPath + "/" + folderIdParent);
}
String newImplantJson = implantJsonObject.toJSONString();
edDataInfo.setImplantJson(newImplantJson);
}
@ -85,7 +99,7 @@ public class EDDataFacadeImpl implements EDDataFacade {
if(isSuccess)
{
// 获取文件存储的文件夹路径
String storageDirectory = "D:/fileTemp/" + newFolderPath;
String storageDirectory = "D:/fileTemp/" + parentFolderPath + "/" + edDataInfo.getDataName();
if(!edDataService.checkFolderIsExist(storageDirectory)) {
edDataService.createMultiLevelDirectory(storageDirectory);
}
@ -165,11 +179,14 @@ public class EDDataFacadeImpl implements EDDataFacade {
}
// 获取文件名
String fileName = file.getOriginalFilename();
String fileFullName = file.getOriginalFilename();
// 获取文件类型
String fileType = "";
if (fileName.lastIndexOf(".") != -1 && fileName.lastIndexOf(".") != 0) {
fileType = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
// 获取文件名称
String fileName = "";
if (fileFullName.lastIndexOf(".") != -1 && fileFullName.lastIndexOf(".") != 0) {
fileType = fileFullName.substring(fileFullName.lastIndexOf(".") + 1);
fileName = fileFullName.substring(fileFullName.lastIndexOf("."));
}
// 获取文件存储的文件夹路径
@ -184,17 +201,20 @@ public class EDDataFacadeImpl implements EDDataFacade {
// 获取上级文件夹路径
{
EDDataParams folderParames = new EDDataParams();
folderParames.setParentId(categoryId);
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 += "/";
parentFolderPath = parentFolderPath + "/" + edDataInfoParent.getDataName();
}
// 文件保存目录路径
String fileSavePath = storageDirectory + "/" + parentFolderPath + fileName;
String fileSavePath = storageDirectory + "/" + parentFolderPath + fileFullName;
// 这里可以添加将文件保存到本地磁盘或其他存储介质的逻辑
File saveFile = new File(fileSavePath);
@ -208,7 +228,7 @@ public class EDDataFacadeImpl implements EDDataFacade {
if(Boolean.TRUE) {
if (request.getUserId() == null || request.getUserId().isEmpty()) request.setUserId(IdWorker.getSnowFlakeIdString());
if (request.getUserName() == null || request.getUserName().isEmpty()) request.setUserName("user");
if (request.getName() == null || request.getName().isEmpty()) request.setName("testFolder");
//if (request.getName() == null || request.getName().isEmpty()) request.setName("testFolder");
if (request.getParentId() == null || request.getParentId().isEmpty()) request.setParentId(IdWorker.getSnowFlakeIdString());
}
@ -219,7 +239,7 @@ public class EDDataFacadeImpl implements EDDataFacade {
edDataInfo.setModifier(request.getUserId());
edDataInfo.setModifierName(request.getUserName());
edDataInfo.setCategoryId(request.getParentId());
edDataInfo.setDataName(request.getName());
edDataInfo.setDataName(fileFullName);
edDataInfo.setNote(request.getNote());
edDataInfo.setDataId(IdWorker.getSnowFlakeIdString());