|
@@ -29,6 +29,8 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.io.*;
|
|
import java.io.*;
|
|
|
|
+import java.net.HttpURLConnection;
|
|
|
|
+import java.net.URL;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -95,27 +97,33 @@ public class ImportController extends BaseController {
|
|
@PostMapping(value = "oaUploadFile")
|
|
@PostMapping(value = "oaUploadFile")
|
|
public Object uploadFile(@ApiParam(value = "上传的文件", required = true) @RequestParam("file") MultipartFile file,Integer processId) throws Exception {
|
|
public Object uploadFile(@ApiParam(value = "上传的文件", required = true) @RequestParam("file") MultipartFile file,Integer processId) throws Exception {
|
|
if (file != null && StringUtils.isNotBlank(file.getOriginalFilename())) {
|
|
if (file != null && StringUtils.isNotBlank(file.getOriginalFilename())) {
|
|
- String filename = file.getOriginalFilename();
|
|
|
|
- String prefix = filename.substring(filename.lastIndexOf("."));
|
|
|
|
- File excelFile = File.createTempFile(UUID.randomUUID().toString(), prefix);
|
|
|
|
- file.transferTo(excelFile);
|
|
|
|
- //如果是乐团退费,校验excel
|
|
|
|
- if(processId != null && processId.equals(19)){
|
|
|
|
- if(!"xls".equals(prefix.substring(1)) && !"xlsx".equals(prefix.substring(1))){
|
|
|
|
- throw new BizException("请上传Excel文件");
|
|
|
|
- }
|
|
|
|
- financialExpenditureService.checkOaQuitMusicGroupExcel(FileUtils.readFileToByteArray(excelFile),filename);
|
|
|
|
- }
|
|
|
|
- UploadReturnBean bean = uploadFileService.uploadFile(FileUtils.openInputStream(excelFile), UploadUtil.getExtension(filename));
|
|
|
|
|
|
+ String fileName = UploadUtil.getExtension(file.getOriginalFilename());
|
|
|
|
+ UploadReturnBean bean = uploadFileService.uploadFile(file.getInputStream(),fileName);
|
|
bean.setName(file.getOriginalFilename());
|
|
bean.setName(file.getOriginalFilename());
|
|
- if (bean.isStatus()) {
|
|
|
|
|
|
+ if(bean.isStatus()){
|
|
|
|
+ //如果是乐团退费,校验excel
|
|
|
|
+ if(processId != null && processId.equals(19)){
|
|
|
|
+ if(!"xls".equals(fileName) && !"xlsx".equals(fileName)){
|
|
|
|
+ throw new BizException("请上传Excel文件");
|
|
|
|
+ }
|
|
|
|
+ URL url = new URL(bean.getUrl());
|
|
|
|
+ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
|
|
|
+ conn.setConnectTimeout(3*1000);
|
|
|
|
+ File excelFile = File.createTempFile(UUID.randomUUID().toString(), ".xls");
|
|
|
|
+ try {
|
|
|
|
+ FileUtils.copyInputStreamToFile(conn.getInputStream(),excelFile);
|
|
|
|
+ financialExpenditureService.checkOaQuitMusicGroupExcel(FileUtils.readFileToByteArray(excelFile),fileName);
|
|
|
|
+ }finally {
|
|
|
|
+ //删除临时文件
|
|
|
|
+ if (excelFile.exists()) {
|
|
|
|
+ excelFile.delete();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
return succeed(bean);
|
|
return succeed(bean);
|
|
|
|
+ }else {
|
|
|
|
+ return failed(bean.getMessage());
|
|
}
|
|
}
|
|
- //删除临时文件
|
|
|
|
- if (excelFile.exists()) {
|
|
|
|
- excelFile.delete();
|
|
|
|
- }
|
|
|
|
- return failed(bean.getMessage());
|
|
|
|
}
|
|
}
|
|
return failed("上传失败");
|
|
return failed("上传失败");
|
|
}
|
|
}
|