[新增功能](hyx_changeFileUpload_2024-9-10)

ClearFilesJob.java
 - 定时清除临时文件任务
FileUploadUtil.java
 - 上传文件到服务器临时地址
 - 临时文件拷贝到正式
MfolderController.java
 - 未完成
hyx_changeFileUpload_2024-9-10
huangyuxuan 2024-09-10 17:52:05 +08:00
parent 1d66e96757
commit a24771a505
4 changed files with 184 additions and 10 deletions

View File

@ -1,5 +1,6 @@
package com.zcloud.controller.filemanager; package com.zcloud.controller.filemanager;
import com.zcloud.util.*;
import net.sf.json.JSONArray; import net.sf.json.JSONArray;
import java.io.Console; import java.io.Console;
@ -22,16 +23,6 @@ import com.zcloud.controller.base.BaseController;
import com.zcloud.entity.Page; import com.zcloud.entity.Page;
import com.zcloud.entity.PageData; import com.zcloud.entity.PageData;
import com.zcloud.service.filemanager.MfolderService; import com.zcloud.service.filemanager.MfolderService;
import com.zcloud.util.Const;
import com.zcloud.util.DateUtil;
import com.zcloud.util.DelFileUtil;
import com.zcloud.util.FileDownload;
import com.zcloud.util.FileUpload;
import com.zcloud.util.FileUtil;
import com.zcloud.util.Jurisdiction;
import com.zcloud.util.PathUtil;
import com.zcloud.util.Smb;
import com.zcloud.util.Tools;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
@ -75,6 +66,53 @@ public class MfolderController extends BaseController {
return map; return map;
} }
/**
*
* @return
* @throws Exception
* @date 2024-9-10
* @author hyx
*/
@RequestMapping("upLoadTemporary")
@ResponseBody
public Object upLoadTemporary(@RequestParam(value="FFILE",required=false) MultipartFile file) throws Exception{
Map<String,Object> map = new HashMap<String,Object>();
if (null != file && !file.isEmpty()) {
}
String CORPINFO_ID = Jurisdiction.getCORPINFO_ID();
String temporaryFilePath = FileUploadUtil.uploadTemporaryFile(file, CORPINFO_ID);
map.put("temporaryFilePath", temporaryFilePath);
return map;
}
/**
*
* @param temporaryFilePath
* @param PARENT_ID id
* @param REMARKS
* @param SHARE
* @return
* @throws Exception
* @date 2024-9-10
* @author hyx
*/
public Object saveFile(@RequestParam(value="temporaryFilePath",required=false) String temporaryFilePath,
@RequestParam(value="NAME",required=false) String NAME,
@RequestParam(value="PARENT_ID",required=false) String PARENT_ID,
@RequestParam(value="REMARKS",required=false) String REMARKS,
@RequestParam(value="SHARE",required=false) String SHARE
) throws Exception {
Map<String,Object> map = new HashMap<String,Object>();
PageData pd = new PageData();
String productFilePath = FileUploadUtil.copyTemporaryFileToProduct(temporaryFilePath, Jurisdiction.getCORPINFO_ID());
return null;
}
/** /**
* @param * @param
* @throws Exception * @throws Exception

View File

@ -0,0 +1,64 @@
package com.zcloud.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;
import java.io.File;
/**
*
* 30 /uploadFiles/linshi/
* @date 2024-9-10
* @author hyx
*/
@Configuration
public class ClearFilesJob {
private final static Logger log = LoggerFactory.getLogger(ClearFilesJob.class);
@Scheduled(cron ="0 0 0 30 * ?")
public void scheduled(){
log.info("==========清除临时文件定时任务开启==========");
String filePath = Const.PATH_PREFIX + Const.TEMPORARY_FILE_PATH;
log.info(delAllFile(filePath) ? "临时文件清除成功!" : "临时文件清除失败!");
}
/**
*
* @param path
* @return
*/
public static boolean delAllFile(String path) {
boolean flag = false;
File file = new File(path);
if (!file.exists()) {
return flag;
}
if (!file.isDirectory()) {
return flag;
}
String[] tempList = file.list();
File temp = null;
for (int i = 0; i < tempList.length; i++) {
if (path.endsWith(File.separator)) {
temp = new File(path + tempList[i]);
} else {
temp = new File(path + File.separator + tempList[i]);
}
if (temp.isFile()) {
temp.delete();
}
if (temp.isDirectory()) {
//删除文件夹下文件
delAllFile(path + "/" + tempList[i]);
flag = true;
}
}
return flag;
}
}

View File

@ -63,4 +63,8 @@ public class Const {
public static final String USER_CITY_CODE = "SESSION_USER_CITY_CODE"; public static final String USER_CITY_CODE = "SESSION_USER_CITY_CODE";
public static final String USER_CITY_NAME = "SESSION_USER_CITY_NAME"; public static final String USER_CITY_NAME = "SESSION_USER_CITY_NAME";
public final static String TEMPORARY_FILE_PATH = "/uploadFiles/linshi/"; // 临时文件路径
public final static String PRODUCT_FILE_PATH = "/uploadFiles/yhtp/"; //正式文件路径
public final static String PATH_PREFIX = "/mnt/vdc1/qask/file"; //服务器路径前缀
} }

View File

@ -0,0 +1,68 @@
package com.zcloud.util;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IORuntimeException;
import org.springframework.web.multipart.MultipartFile;
/**
*
*
* -> -> -> ->
* @date 2024-9-10
* @author hyx
* @version V1.0
*/
public class FileUploadUtil {
private final static String PATH_PREFIX = "/mnt/vdc1/qask/file"; //服务器路径前缀
private final static String TEMPORARY_FILE_PATH = "/uploadFiles/linshi/"; //临时文件储存路径
private final static String PRODUCT_FILE_PATH = "/uploadFiles/yhtp/"; //正式文件储存路径
/**
*
*
* @param file
* @param CORPINFO_ID id
* @return
* @throws Exception
* @date 2024-9-10
* @author hyx
*/
public static String uploadTemporaryFile(MultipartFile file,String CORPINFO_ID) throws Exception {
String ffile = DateUtil.getDays();
String fileName = UuidUtil.get32UUID()+file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
try {
Smb.sshSftp(file,fileName,TEMPORARY_FILE_PATH + CORPINFO_ID + "/" + ffile);
} catch (Exception e) {
throw new RuntimeException(e);
}
return TEMPORARY_FILE_PATH + CORPINFO_ID+ "/" + ffile + "/" + fileName;
}
/**
*
*
* @param temporaryFilePath
* @param CORPINFO_ID id
* @return
* @throws Exception
* @date 2024-9-10
* @author hyx
*/
public static String copyTemporaryFileToProduct(String temporaryFilePath,String CORPINFO_ID) throws Exception {
//临时文件在服务器的完整路径
String completeTemporaryPath = PATH_PREFIX + temporaryFilePath;
//截取文件名
String fileName = completeTemporaryPath.substring(completeTemporaryPath.lastIndexOf("")).replace("/","");
//正式文件完整路径
String completeProductPath = PATH_PREFIX + PRODUCT_FILE_PATH + CORPINFO_ID + "/" + DateUtil.getDays() + "/";
//临时文件拷贝到正式路径
try {
FileUtil.copy(completeTemporaryPath,completeProductPath,true);
} catch (IORuntimeException e) {
throw new RuntimeException(e);
}
return PRODUCT_FILE_PATH + fileName;
}
}