Jelajahi Sumber

测试环境

Tiroble 3 tahun lalu
induk
melakukan
2730e0d79d

+ 46 - 3
src/main/java/com/steerinfo/dil/controller/RmsMaterialController.java

@@ -3,13 +3,23 @@ package com.steerinfo.dil.controller;
 import com.steerinfo.dil.service.impl.RmsMaterialServiceImpl;
 import com.steerinfo.dil.util.BaseRESTfulController;
 import com.steerinfo.framework.controller.RESTfulResult;
+import com.steerinfo.framework.utils.misc.IdGenerator;
+import com.steerinfo.framework.utils.upload.UploadUtils;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartRequest;
 
+import java.io.File;
 import java.io.IOException;
+import java.lang.reflect.Field;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
 
 /**
  * @author luobang
@@ -18,6 +28,8 @@ import java.io.IOException;
 @RestController
 @RequestMapping("${api.version}/material")
 public class RmsMaterialController extends BaseRESTfulController {
+    @Value("${piction.path}")
+    private String path;
 
     @Autowired
     RmsMaterialServiceImpl rmsMaterialServiceImpl;
@@ -39,4 +51,35 @@ public class RmsMaterialController extends BaseRESTfulController {
        return success(count);
     }
 
+    @PostMapping(value = "/updateFiles", headers = "content-type=multipart/form-data")
+    public synchronized List<String> updateFiles( @RequestParam(value = "files") MultipartFile files[]) throws Exception {
+        //首先通过Calendard对象获得年月日
+        Calendar calendar=Calendar.getInstance();
+        int year = calendar.get(Calendar.YEAR);
+        int month = calendar.get(Calendar.MONTH);
+        int day= calendar.get(Calendar.DAY_OF_MONTH);
+        //year+File.separator+month+File.separator+day
+        System.out.println(year+File.separator+month+File.separator+day);
+        //上传文件夹路径
+        String uploadPath=replaceSeparator(path);
+        List<String> urls=new ArrayList<>();
+        for (int i=0;i<files.length;i++){
+            String url = UploadUtils.uploadFile(files[i], new IdGenerator(1, 10), uploadPath, File.separator+year+File.separator+month+File.separator+day+File.separator);
+            urls.add(url);
+        }
+
+        return urls;
+    }
+
+    /**
+     *将正斜杠和反斜杠替代为window和linux都支持的
+     * @param path
+     * @return
+     */
+    public String replaceSeparator(String path){
+        return path.replaceAll("/", File.separator);
+
+    }
+
+
 }

+ 5 - 0
src/main/resources/application-dev.yml

@@ -16,6 +16,11 @@ openfeign:
   TmsTruckFeign:
     url: ${TMSTRUCKFEIGN_URL:172.16.33.162:8008}
 
+
+#图片上传配置
+piction:
+  path: /icore/data/nginx/image
+
 server:
   port: 8012