文件上传修改
This commit is contained in:
parent
371362c0fd
commit
68492c89b7
|
|
@ -43,6 +43,9 @@ public class RemoteFaceController extends BaseController {
|
|||
@Value("${file.upload_path}")
|
||||
private String upload_path;
|
||||
|
||||
@Resource(name = "UploadFileUtil")
|
||||
private UploadFileUtil uploadFileUtil;
|
||||
|
||||
/**
|
||||
* @return java.util.Map<java.lang.String, java.lang.Object>
|
||||
* @author hay
|
||||
|
|
@ -81,7 +84,7 @@ public class RemoteFaceController extends BaseController {
|
|||
@RequestMapping(value = "uploadFile", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@SysLog(title = "远程人脸抽查照片上传", model = "值班任务->远程人脸抽查", operaType = OperaType.IMPORT, details = "照片上传",logType = 1)
|
||||
public AjaxRes uploadFile(HttpServletRequest request) throws IllegalStateException, IOException {
|
||||
public AjaxRes uploadFile(HttpServletRequest request){
|
||||
AjaxRes ar = new AjaxRes();
|
||||
List<String> urlStr = new LinkedList<>();
|
||||
try {
|
||||
|
|
@ -89,54 +92,11 @@ public class RemoteFaceController extends BaseController {
|
|||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<MultipartFile> items = (List<MultipartFile>) map.get("filePath");
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
MultipartFile item = items.get(i);
|
||||
// 完整路径 IE
|
||||
String tmpName = item.getOriginalFilename();
|
||||
if (StringHelper.isEmpty(tmpName)) {
|
||||
// 根据情况
|
||||
return null;
|
||||
}
|
||||
String suffix = tmpName.substring(tmpName.lastIndexOf("."));
|
||||
String fileName = DateTimeHelper.getNowDate().replace("-", "") + "_" + generateShortUuid() + "_salary" + suffix;
|
||||
String mkdirsName ="photo";
|
||||
|
||||
// String imageFiles = upload_path + File.separator + mkdirsName;
|
||||
// String path = imageFiles + File.separator + com.securityControl.common.core.utils.aes.DateTimeHelper.getYear(new Date()) + File.separator + com.securityControl.common.core.utils.aes.DateTimeHelper.getMonth(new Date()) + File.separator + fileName;
|
||||
// File file = new File(path);
|
||||
// //生成文件夹
|
||||
// if (!file.getParentFile().exists()) {
|
||||
// file.getParentFile().mkdirs();
|
||||
// }
|
||||
// // 存入临时文件
|
||||
// item.transferTo(file);
|
||||
// String imgPath = mkdirsName + File.separator + com.securityControl.common.core.utils.aes.DateTimeHelper.getYear(new Date()) + File.separator + com.securityControl.common.core.utils.aes.DateTimeHelper.getMonth(new Date()) + File.separator + fileName;
|
||||
// urlStr.add(imgPath);
|
||||
|
||||
|
||||
// linux 系统路径
|
||||
String imageFiles = "/data/ahsbs/file" + mkdirsName + "/";
|
||||
String os = System.getProperty("os.name");
|
||||
if(os.toLowerCase().startsWith("win")){
|
||||
imageFiles="D://file/"+mkdirsName;
|
||||
}
|
||||
String path=imageFiles+"/"+ DateTimeHelper.getNowYear()+"/"+DateTimeHelper.getNowMonths()+"/"+ DateTimeHelper.getNowDay() +"/"+fileName;
|
||||
File file = new File(path);
|
||||
//生成文件夹
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
// 存入临时文件
|
||||
item.transferTo(file);
|
||||
try {
|
||||
String imgPath = mkdirsName+"/"+ DateTimeHelper.getNowYear()+"/"+DateTimeHelper.getNowMonths()+"/"+ DateTimeHelper.getNowDay()+"/"+fileName;
|
||||
urlStr.add(imgPath);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.toString(), e);
|
||||
ar.setFailMsg("保存失败");
|
||||
}
|
||||
String filePath = uploadFileUtil.uploadImages(item, "faceSpotCheck");
|
||||
urlStr.add(filePath);
|
||||
}
|
||||
} catch (Exception e){
|
||||
logger.error(e.toString(), e);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
package com.sercurityControl.proteam.util;
|
||||
|
||||
import com.securityControl.common.core.utils.aes.DateTimeHelper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @className:UploadFileUtil
|
||||
* @author:cwchen
|
||||
* @date:2024-12-19-15:42
|
||||
* @version:1.0
|
||||
* @description:文件上传工具类
|
||||
*/
|
||||
@Slf4j
|
||||
@Component("UploadFileUtil")
|
||||
public class UploadFileUtil {
|
||||
|
||||
@Value("${file.upload_path}")
|
||||
private String upload_path;
|
||||
|
||||
public String uploadImages(MultipartFile item, String mkdirsName) {
|
||||
String image = "";
|
||||
try {
|
||||
String fileName = IDUtils.createID() + ".jpg";
|
||||
String imageFiles = upload_path + File.separator + mkdirsName;
|
||||
String path = imageFiles + File.separator + com.securityControl.common.core.utils.aes.DateTimeHelper.getYear(new Date()) + File.separator + com.securityControl.common.core.utils.aes.DateTimeHelper.getMonth(new Date()) + File.separator + fileName;
|
||||
File file = new File(path);
|
||||
//生成文件夹
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
// 存入临时文件
|
||||
item.transferTo(file);
|
||||
image = mkdirsName + File.separator + com.securityControl.common.core.utils.aes.DateTimeHelper.getYear(new Date()) + File.separator + DateTimeHelper.getMonth(new Date()) + File.separator + fileName;
|
||||
} catch (Exception e) {
|
||||
log.error(e.toString(),e);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue