单据上传功能代码提交
parent
d14f2dbefd
commit
b4acc0a913
@ -0,0 +1,77 @@
|
||||
package com.glxp.api.controller.inout;
|
||||
|
||||
import com.glxp.api.common.res.BaseResponse;
|
||||
import com.glxp.api.common.util.ResultVOUtils;
|
||||
import com.glxp.api.idc.utils.IDCUtils;
|
||||
import com.glxp.api.util.FileUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@RestController
|
||||
public class IoOrderUploadController {
|
||||
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(IoOrderUploadController.class);
|
||||
@Value("${file_path}")
|
||||
private String filePath;
|
||||
@Value("${API_KEY}")
|
||||
private String apiKey;
|
||||
@Value("${API_SECRET}")
|
||||
private String apiSecret;
|
||||
private String imagePath = "register/file/image2/";
|
||||
String pdfPath = "pdf/template/";
|
||||
|
||||
|
||||
@RequestMapping(value = "/udiwms/file/uploadFile")
|
||||
public BaseResponse uploadFile(HttpServletRequest request,
|
||||
@RequestParam(value = "content" , required = false) String content,
|
||||
@RequestParam(value = "files", required = false) MultipartFile[] files) {
|
||||
//
|
||||
return receiveFile(request,content,files);
|
||||
}
|
||||
|
||||
|
||||
public BaseResponse receiveFile(HttpServletRequest request, String content, MultipartFile[] files) {
|
||||
boolean isRelay = false;
|
||||
String filePathSlash = filePath.substring(filePath.length() - 1).equals("/") ? "" : "/";
|
||||
String host = "";
|
||||
ArrayList<String> saveFiles = new ArrayList<>();
|
||||
if (files != null) {
|
||||
if (!FileUtils.makeDirectory(filePath + filePathSlash + imagePath))
|
||||
IDCUtils.createDirectory(filePath + filePathSlash + imagePath);
|
||||
try {
|
||||
for (MultipartFile file : files) {
|
||||
String flodPath;
|
||||
if (file.getName().contains(".jrxml") || file.getName().contains(".jasper")) {
|
||||
flodPath = pdfPath;
|
||||
} else {
|
||||
flodPath = imagePath;
|
||||
}
|
||||
String imageName = filePath + filePathSlash + flodPath + file.getOriginalFilename();
|
||||
saveFiles.add(imageName);
|
||||
IDCUtils.writeFile(file.getBytes(), filePath + filePathSlash + flodPath, file.getOriginalFilename());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ResultVOUtils.success(null);
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue