Redeem před 1 rokem
rodič
revize
60d24d4d26

+ 23 - 0
src/main/java/com/steerinfo/dil/controller/TMSController.java

@@ -9,17 +9,21 @@ import com.steerinfo.dil.feign.TmsFeign;
 import com.steerinfo.dil.mapper.UniversalMapper;
 import com.steerinfo.dil.util.BaseRESTfulController;
 import com.steerinfo.dil.util.ExcelToolUtils;
+import com.steerinfo.dil.util.Util;
 import com.steerinfo.framework.controller.RESTfulResult;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import oracle.jdbc.proxy.annotation.Post;
+import org.apache.commons.io.FilenameUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.OutputStreamWriter;
 import java.math.BigDecimal;
 import java.text.DateFormat;
 import java.text.ParseException;
@@ -964,12 +968,31 @@ public class TMSController extends BaseRESTfulController {
                                                  String userName,
                                                  String resultType) throws Exception {
         Map<String, Object> map = new HashMap<>();
+        if (file.isEmpty()) {
+            return new HashMap<>();
+        }
+        // 获取源文件名称
+        String originalFilename = file.getOriginalFilename();
+        // 获取源文件后缀名
+        String extension = "." + FilenameUtils.getExtension(originalFilename);
+        // 定义新路径
+        String newPath = "/data/file/result/";
+        String newName = userName + "-" + originalFilename+ Util.RandomCreate(8) + ".xlsx";
+        File dataFile = new File(newPath);
+        if (!dataFile.exists()) {
+            dataFile.mkdirs();
+        }
+        FileOutputStream fileOutputStream = new FileOutputStream(newPath + newName);
+        fileOutputStream.write(file.getBytes());
+        fileOutputStream.flush();
+        fileOutputStream.close();
         //获取Excel中包含的对象数组
         List<Map<String, Object>> list = ExcelToolUtils.getExcelList(file, 0);
         map.put("list", list);
         map.put("userId", userId);
         map.put("userName", userName);
         map.put("resultType", resultType);
+        map.put("filePath",newPath + newName);
         return tmsFeign.importComprehensiveResult(map);
     }
     @ApiOperation(value = "火运大宗销售订单 删除销售运输订单")

+ 9 - 6
src/main/java/com/steerinfo/dil/controller/UniversalController.java

@@ -389,16 +389,19 @@ public class UniversalController extends BaseRESTfulController {
         }
         byte[] stream1 = exportExcelFile(columnMaps, listMap);
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
-        Random random = new Random();
-        String path = "/data/file/"+  map.get("userName") + "-" + simpleDateFormat.format(new Date()) + "-"
-                + map.get("exclename").toString()+ Util.RandomCreate(8) + ".xlsx";
-        FileOutputStream outputStream1 = new FileOutputStream(new File(path));
+        String path = "/data/file/exportExcel/" + simpleDateFormat.format(new Date()) + "/";
+        File datFile = new File(path);
+        if(!datFile.exists()) {
+            datFile.mkdirs();
+        }
+        String name = map.get("userName") + "-" + map.get("exclename").toString()+ Util.RandomCreate(8) + ".xlsx";
+        FileOutputStream outputStream1 = new FileOutputStream(new File(path + name));
         outputStream1.write(stream1);
         outputStream1.flush();
         outputStream1.close();
         Map<String, Object> response = new HashMap<>();
-        response.put("fileName",map.get("userName") + "-" + simpleDateFormat.format(new Date()) + "-" + map.get("exclename").toString() + ".xlsx");
-        response.put("filePath",path);
+        response.put("fileName",name);
+        response.put("filePath",path + name);
         return success(response);
     }
     @ApiModelProperty(value = "边输边查公司单位审批流程使用")