1.增加文件上传时将文件重命名并存到缓存目录再移动的逻辑;2.增加相关接口中批量上传时间和保存状态字段。
This commit is contained in:
parent
512f9724d8
commit
55ad1665b9
|
|
@ -10,6 +10,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Date;
|
||||
|
||||
@RequestMapping("/data/ed/file")
|
||||
@RestController
|
||||
|
|
@ -49,10 +50,12 @@ public class EDDataController {
|
|||
@ApiOperation(value = "上传",notes = "")
|
||||
@RequestMapping(value = "/upload", consumes = "multipart/form-data",method = RequestMethod.POST)
|
||||
public ElectromagneticResult<?> upload(@RequestParam("parentId") String parentId,
|
||||
@RequestParam("file") MultipartFile file){
|
||||
@RequestParam("file") MultipartFile file,
|
||||
@RequestParam("gmtBatchUpload") Long gmtBatchUpload){
|
||||
EDDataRequest request = new EDDataRequest();
|
||||
request.setParentId(parentId);
|
||||
request.setFileData(file);
|
||||
request.setGmtBatchUpload(new Date(gmtBatchUpload));
|
||||
return edDataFacade.upload(request);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,7 +64,11 @@ public class EDDataInfo {
|
|||
/**
|
||||
* 批量上传时间
|
||||
*/
|
||||
private String gmtBatchUpload;
|
||||
private Date gmtBatchUpload;
|
||||
/**
|
||||
* 保存状态
|
||||
*/
|
||||
private String saveStatus;
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import lombok.Data;
|
|||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class EDDataParams implements Serializable {
|
||||
|
|
@ -51,7 +52,11 @@ public class EDDataParams implements Serializable {
|
|||
/**
|
||||
* 批量上传时间
|
||||
*/
|
||||
private String gmtBatchUpload;
|
||||
private Date gmtBatchUpload;
|
||||
/**
|
||||
* 保存状态
|
||||
*/
|
||||
private String saveStatus;
|
||||
/**
|
||||
* 文件数据编码数组
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
import electromagnetic.data.framework.share.model.BaseRequest;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class EDDataRequest extends BaseRequest {
|
||||
|
||||
|
|
@ -47,6 +49,14 @@ public class EDDataRequest extends BaseRequest {
|
|||
* 关键词
|
||||
*/
|
||||
private String keyWord;
|
||||
/**
|
||||
* 批量上传时间
|
||||
*/
|
||||
private Date gmtBatchUpload;
|
||||
/**
|
||||
* 保存状态
|
||||
*/
|
||||
private String saveStatus;
|
||||
/**
|
||||
* 文件数据编码数组
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -32,19 +32,4 @@ public interface EDDataMapper {
|
|||
*/
|
||||
Boolean updateFileInfo(EDDataParams parames);
|
||||
|
||||
/**
|
||||
* 获取子文件数量
|
||||
* @param parames
|
||||
* @return
|
||||
*/
|
||||
Integer getChildFileCount(EDDataParams parames);
|
||||
|
||||
/**
|
||||
* 获取目录路径
|
||||
* @param categoryId
|
||||
* @return
|
||||
*/
|
||||
String getDirectoryPath(String categoryId);
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -17,6 +17,7 @@
|
|||
<result column="note" jdbcType="VARCHAR" property="note" />
|
||||
<result column="editor" jdbcType="VARCHAR" property="editor" />
|
||||
<result column="gmt_batch_upload" jdbcType="TIMESTAMP" property="gmtBatchUpload" />
|
||||
<result column="save_status" jdbcType="VARCHAR" property="saveStatus" />
|
||||
<result column="creator" jdbcType="VARCHAR" property="creator" />
|
||||
<result column="creator_name" jdbcType="VARCHAR" property="creatorName" />
|
||||
<result column="gmt_create" jdbcType="TIMESTAMP" property="gmtCreate" />
|
||||
|
|
@ -27,7 +28,7 @@
|
|||
</resultMap>
|
||||
<sql id="Base_Column_list">
|
||||
id,category_id,data_id,data_no,data_name,data_type,file_type,version,content,
|
||||
implant_json,data_status,note,creator,creator_name,gmt_create,modifier,modifier_name,
|
||||
implant_json,data_status,note,editor,gmt_batch_upload,save_status,creator,creator_name,gmt_create,modifier,modifier_name,
|
||||
gmt_modified,effect_flag
|
||||
</sql>
|
||||
|
||||
|
|
@ -40,7 +41,7 @@
|
|||
data_id, data_no, data_name,
|
||||
data_type, file_type, version,
|
||||
content, implant_json, data_status,
|
||||
note, editor, gmt_batch_upload,
|
||||
note, editor, gmt_batch_upload, save_status,
|
||||
creator, creator_name, gmt_create,
|
||||
modifier, modifier_name, gmt_modified,
|
||||
effect_flag
|
||||
|
|
@ -49,7 +50,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}, #{editor,jdbcType=VARCHAR}, #{gmtBatchUpload,jdbcType=TIMESTAMP},
|
||||
#{note,jdbcType=VARCHAR}, #{editor,jdbcType=VARCHAR}, #{gmtBatchUpload,jdbcType=TIMESTAMP}, #{saveStatus,jdbcType=VARCHAR},
|
||||
#{creator,jdbcType=VARCHAR}, #{creatorName,jdbcType=VARCHAR}, now(), #{modifier,jdbcType=VARCHAR},
|
||||
#{modifierName,jdbcType=VARCHAR},now(),1
|
||||
)
|
||||
|
|
@ -72,6 +73,9 @@
|
|||
<if test="keyWord!=null and keyWord!=''">
|
||||
and data_name LIKE '%${keyWord}%'
|
||||
</if>
|
||||
<if test="saveStatus!=null and saveStatus!=''">
|
||||
and save_status='${saveStatus}'
|
||||
</if>
|
||||
GROUP BY id
|
||||
<if test="gmtCreate == 'asc' or gmtCreate =='desc'">
|
||||
order by gmt_create ${gmtCreate}
|
||||
|
|
@ -90,6 +94,9 @@
|
|||
<if test="note != null and note!=''">
|
||||
note = #{note,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="saveStatus != null and note!=''">
|
||||
save_status = #{saveStatus,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="effectFlag != null and effectFlag!=''">
|
||||
effect_flag = #{effectFlag,jdbcType=VARCHAR},
|
||||
</if>
|
||||
|
|
|
|||
|
|
@ -19,7 +19,9 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
|
|
@ -120,6 +122,7 @@ public class EDDataFacadeImpl implements EDDataFacade {
|
|||
*/
|
||||
public ElectromagneticResult<EDDataPageResponse> getDataInfoList(EDDataRequest request)
|
||||
{
|
||||
|
||||
EDDataParams parames= EDDataMappers.INSTANCE.getEDDataParames(request);
|
||||
//获取中支指标配置列表
|
||||
EDDataPage edDataPage = edDataService.getDataInfoList(parames);
|
||||
|
|
@ -174,15 +177,15 @@ public class EDDataFacadeImpl implements EDDataFacade {
|
|||
String categoryId = request.getParentId();
|
||||
|
||||
// 获取要上传的文件
|
||||
MultipartFile file = request.getFileData();
|
||||
MultipartFile fileInput = request.getFileData();
|
||||
|
||||
// 检查文件是否为空
|
||||
if (file == null || file.isEmpty()) {
|
||||
if (fileInput == null || fileInput.isEmpty()) {
|
||||
return ElectromagneticResultUtil.fail(HttpStatus.BAD_REQUEST.toString(),"上传的文件为空");
|
||||
}
|
||||
|
||||
// 获取文件名
|
||||
String fileFullName = file.getOriginalFilename();
|
||||
String fileFullName = fileInput.getOriginalFilename();
|
||||
// 获取文件类型
|
||||
String fileType = "";
|
||||
// 获取文件名称
|
||||
|
|
@ -198,8 +201,9 @@ public class EDDataFacadeImpl implements EDDataFacade {
|
|||
edDataService.createMultiLevelDirectory(storageDirectory);
|
||||
}
|
||||
|
||||
String parentFolderPath = "";
|
||||
String parentFolderIdPath = "";
|
||||
String parentFolderPath = ""; //上级文件夹路径
|
||||
String parentFolderIdPath = ""; //上级文件夹ID路径
|
||||
String parentFolderName = ""; //上级文件夹名称
|
||||
|
||||
// 获取上级文件夹路径
|
||||
{
|
||||
|
|
@ -218,16 +222,13 @@ public class EDDataFacadeImpl implements EDDataFacade {
|
|||
parentFolderIdPath += "/" ;
|
||||
parentFolderPath += edDataInfoParent.getDataName();
|
||||
parentFolderIdPath += edDataInfoParent.getDataId();
|
||||
parentFolderName = edDataInfoParent.getDataName();
|
||||
}
|
||||
|
||||
// 文件保存目录路径
|
||||
String fileSavePath = storageDirectory + "/" + parentFolderPath + "/" + fileFullName;
|
||||
|
||||
// 这里可以添加将文件保存到本地磁盘或其他存储介质的逻辑
|
||||
File saveFile = new File(fileSavePath);
|
||||
|
||||
// 将文件保存到硬盘
|
||||
file.transferTo(saveFile);
|
||||
String fileSavePath = storageDirectory + "/" + parentFolderPath;
|
||||
String treeName = "目录树名称";
|
||||
String newFileName = treeName + "," + parentFolderName + "," + fileFullName;
|
||||
|
||||
// 文件数据信息写到数据库
|
||||
{
|
||||
|
|
@ -246,14 +247,17 @@ public class EDDataFacadeImpl implements EDDataFacade {
|
|||
edDataInfo.setModifier(request.getUserId());
|
||||
edDataInfo.setModifierName(request.getUserName());
|
||||
edDataInfo.setCategoryId(request.getParentId());
|
||||
edDataInfo.setDataName(fileFullName);
|
||||
edDataInfo.setDataName(newFileName);
|
||||
edDataInfo.setNote(request.getNote());
|
||||
edDataInfo.setFileType(fileType);
|
||||
edDataInfo.setGmtBatchUpload(request.getGmtBatchUpload());
|
||||
|
||||
edDataInfo.setDataId(IdWorker.getSnowFlakeIdString());
|
||||
edDataInfo.setDataNo(IdWorker.getSnowFlakeIdString());
|
||||
edDataInfo.setDataType("file");
|
||||
edDataInfo.setVersion("1.0.0");
|
||||
edDataInfo.setDataStatus("publish");
|
||||
edDataInfo.setSaveStatus("saving");
|
||||
|
||||
JSONObject newImplantJsonObject = new JSONObject();
|
||||
newImplantJsonObject.put("folderPath", parentFolderPath);
|
||||
|
|
@ -262,6 +266,42 @@ 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");
|
||||
if (!cacheDirectory.exists()) {
|
||||
cacheDirectory.mkdirs();
|
||||
}
|
||||
|
||||
String cacheFolder = cacheDirectory.getAbsolutePath();
|
||||
|
||||
String cachePath = cacheFolder + "/" + newFileName;
|
||||
System.out.println("文件缓存路径为: " + cacheDirectory.getAbsolutePath());
|
||||
fileSavePath += "/" + newFileName;
|
||||
|
||||
|
||||
// 这里可以添加将文件保存到本地磁盘或其他存储介质的逻辑
|
||||
File saveFile = new File(cachePath);//fileSavePath
|
||||
|
||||
// 将文件保存到硬盘
|
||||
fileInput.transferTo(saveFile);
|
||||
|
||||
EDDataParams fileParames = new EDDataParams();
|
||||
fileParames.setDataId(edDataInfo.getDataId());
|
||||
if(fileInput.getSize() == saveFile.length())
|
||||
{
|
||||
Path source = Paths.get(cachePath);
|
||||
Path target = Paths.get(fileSavePath);
|
||||
Files.move(source, target);
|
||||
fileParames.setSaveStatus("success");
|
||||
}
|
||||
else
|
||||
{
|
||||
saveFile.delete();
|
||||
fileParames.setSaveStatus("failure");
|
||||
}
|
||||
|
||||
isSuccess = edDataService.updateFileInfo(fileParames);
|
||||
|
||||
}
|
||||
|
||||
// 如果文件上传成功,返回成功消息
|
||||
|
|
|
|||
Loading…
Reference in New Issue