|
|
|
|
package com.hxjt.dataupload.controller;
|
|
|
|
|
|
|
|
|
|
import com.hxjt.dataupload.service.FxfxdxService;
|
|
|
|
|
import com.hxjt.dataupload.task.AsyncTask;
|
|
|
|
|
import com.hxjt.dataupload.utils.JsonData;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
import java.nio.file.StandardCopyOption;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
import java.util.concurrent.Future;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* liwenxuan
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("dataupload/api/v1")
|
|
|
|
|
public class UploadController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private AsyncTask asyncTask;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private FxfxdxService fxfxdxService;
|
|
|
|
|
|
|
|
|
|
@RequestMapping("list")
|
|
|
|
|
public Object list(){
|
|
|
|
|
|
|
|
|
|
Map<String,String > map = new HashMap<>();
|
|
|
|
|
map.put("1","asdfdsa");
|
|
|
|
|
map.put("2","S6543465");
|
|
|
|
|
|
|
|
|
|
return map;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@GetMapping("async")
|
|
|
|
|
public JsonData testAsync(){
|
|
|
|
|
long begin = System.currentTimeMillis();
|
|
|
|
|
/*asyncTask.task1();
|
|
|
|
|
asyncTask.task2();
|
|
|
|
|
asyncTask.task3();*/
|
|
|
|
|
Future<String> task4 = asyncTask.task4();
|
|
|
|
|
Future<String> task5 = asyncTask.task5();
|
|
|
|
|
for(;;){
|
|
|
|
|
if(task4.isDone() && task5.isDone()){
|
|
|
|
|
try {
|
|
|
|
|
String task4Result = task4.get();
|
|
|
|
|
System.out.println(task4Result);
|
|
|
|
|
|
|
|
|
|
String task5Result = task5.get();
|
|
|
|
|
System.out.println(task5Result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}catch (InterruptedException e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}catch (ExecutionException e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}finally {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long end = System.currentTimeMillis();
|
|
|
|
|
return JsonData.buildSuccess(end-begin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*获取用户有权限的启用状态的表单列表树形结构*/
|
|
|
|
|
@RequestMapping(value = "/getOTBILLIDById")
|
|
|
|
|
public JsonData getCustomerFormList(@RequestBody Map<String,String> requestBody) {
|
|
|
|
|
//System.out.println(requestBody.get("id"));
|
|
|
|
|
if(!StringUtils.isBlank(requestBody.get("id"))){
|
|
|
|
|
String result = fxfxdxService.getOTBILLIDById(requestBody.get("id"));
|
|
|
|
|
return JsonData.buildSuccess(result);
|
|
|
|
|
}else{
|
|
|
|
|
return JsonData.buildError("请先输入id");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/uploadPDF")
|
|
|
|
|
public ResponseEntity<String> uploadPdf(
|
|
|
|
|
@RequestParam("file") MultipartFile file,
|
|
|
|
|
@RequestParam("id") String id,
|
|
|
|
|
@RequestParam("ticketNumber") String ticketNumber) {
|
|
|
|
|
//上线
|
|
|
|
|
String uploadDir = "F://dataUpload/zypPdfs/";
|
|
|
|
|
// 1. 验证文件类型和大小
|
|
|
|
|
if (file.isEmpty()) {
|
|
|
|
|
return ResponseEntity.badRequest().body("文件不能为空");
|
|
|
|
|
}
|
|
|
|
|
if (!file.getContentType().equals("application/pdf")) {
|
|
|
|
|
return ResponseEntity.badRequest().body("仅支持PDF格式");
|
|
|
|
|
}
|
|
|
|
|
if (file.getSize() > 10 * 1024 * 1024) { // 限制10MB
|
|
|
|
|
return ResponseEntity.badRequest().body("文件大小超过限制");
|
|
|
|
|
}
|
|
|
|
|
System.out.println(id);
|
|
|
|
|
System.out.println(ticketNumber);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// 确保目录存在
|
|
|
|
|
File targetDir = new File(uploadDir);
|
|
|
|
|
if (!targetDir.exists()) {
|
|
|
|
|
targetDir.mkdirs(); // 自动创建多级目录
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 生成唯一文件名(可选,避免重复覆盖)
|
|
|
|
|
String fileName = id+ "_" +ticketNumber+".pdf";
|
|
|
|
|
|
|
|
|
|
// 构建目标文件的绝对路径
|
|
|
|
|
File targetFile = new File(targetDir.getAbsolutePath() + File.separator + fileName);
|
|
|
|
|
|
|
|
|
|
// 保存文件到磁盘
|
|
|
|
|
file.transferTo(targetFile);
|
|
|
|
|
return ResponseEntity.ok("上传成功");
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
return ResponseEntity.internalServerError().body("文件存储失败:" + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|