|
@@ -4,13 +4,21 @@ import com.jiayue.biz.service.DataRecalculationService;
|
|
|
import com.jiayue.common.core.domain.AjaxResult;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.fileupload.FileItem;
|
|
|
+import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
+import org.apache.http.entity.ContentType;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
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 org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
|
|
|
+import java.io.*;
|
|
|
import java.util.Date;
|
|
|
|
|
|
/**
|
|
@@ -29,9 +37,41 @@ public class DataRecalculationController {
|
|
|
|
|
|
@PostMapping("/uploadFileAnalysis")
|
|
|
public AjaxResult uploadFileAnalysis(@RequestParam("file") MultipartFile file, @RequestParam("equipmentNo") String equipmentNo, @RequestParam("recorderNo") String recorderNo) {
|
|
|
- return dataRecalculationService.uploadFileAnalysis(file, equipmentNo, recorderNo);
|
|
|
+ MultipartFile file1 = null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ FileUtils.copyInputStreamToFile(file.getInputStream(), new File("../"+file.getOriginalFilename()));
|
|
|
+ file1 = getMultipartFile( new File("../"+file.getOriginalFilename()));
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ MultipartFile finalFile = file1;
|
|
|
+ Thread thread = new Thread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ dataRecalculationService.uploadFileAnalysis(finalFile, equipmentNo, recorderNo);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ thread.start();
|
|
|
+
|
|
|
+ return AjaxResult.success("提交后台处理文件成功");
|
|
|
}
|
|
|
|
|
|
+ public static MultipartFile getMultipartFile(File file) {
|
|
|
+ FileItem item = new DiskFileItemFactory().createItem("file"
|
|
|
+ , MediaType.MULTIPART_FORM_DATA_VALUE
|
|
|
+ , true
|
|
|
+ , file.getName());
|
|
|
+ try (InputStream input = new FileInputStream(file);
|
|
|
+ OutputStream os = item.getOutputStream()) {
|
|
|
+ // 流转移
|
|
|
+ IOUtils.copy(input, os);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new IllegalArgumentException("Invalid file: " + e, e);
|
|
|
+ }
|
|
|
+
|
|
|
+ return new CommonsMultipartFile(item);
|
|
|
+ }
|
|
|
@PostMapping("/dataCheck")
|
|
|
public AjaxResult dataCheck(@RequestParam("startTime") Long startTime, @RequestParam("endTime") Long endTime, @RequestParam("equipmentNo") String equipmentNo) {
|
|
|
return dataRecalculationService.dataCheck(new Date(startTime), new Date(endTime), equipmentNo);
|