|
@@ -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);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|