|
@@ -8,21 +8,30 @@ import com.yunzhi.marketing.common.AliOSSUtils;
|
8
|
8
|
import com.yunzhi.marketing.common.CommConstant;
|
9
|
9
|
import com.yunzhi.marketing.common.SMSUtils;
|
10
|
10
|
import com.yunzhi.marketing.common.StringUtils;
|
|
11
|
+import com.yunzhi.marketing.common.VideoThreadDownLoad;
|
11
|
12
|
import com.yunzhi.marketing.service.IMiniAppService;
|
12
|
13
|
import com.yunzhi.marketing.service.ITdMiniappTemplateTypeService;
|
|
14
|
+import io.swagger.annotations.Api;
|
|
15
|
+import io.swagger.annotations.ApiOperation;
|
13
|
16
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
17
|
+import org.springframework.beans.factory.annotation.Value;
|
14
|
18
|
import org.springframework.web.bind.annotation.*;
|
15
|
19
|
import org.springframework.web.multipart.MultipartFile;
|
16
|
20
|
|
17
|
21
|
import javax.servlet.http.HttpServletRequest;
|
|
22
|
+import java.io.File;
|
18
|
23
|
import java.io.IOException;
|
|
24
|
+import java.text.SimpleDateFormat;
|
19
|
25
|
import java.util.ArrayList;
|
|
26
|
+import java.util.Date;
|
20
|
27
|
import java.util.HashMap;
|
21
|
28
|
import java.util.Map;
|
|
29
|
+import java.util.UUID;
|
22
|
30
|
|
23
|
31
|
|
24
|
32
|
@RestController
|
25
|
33
|
@RequestMapping("/api")
|
|
34
|
+@Api(value = "文件上传", tags = "文件上传")
|
26
|
35
|
public class CommonController extends BaseController {
|
27
|
36
|
@Autowired
|
28
|
37
|
SMSUtils smsUtils;
|
|
@@ -33,21 +42,71 @@ public class CommonController extends BaseController {
|
33
|
42
|
@Autowired
|
34
|
43
|
IMiniAppService iMiniAppService;
|
35
|
44
|
|
|
45
|
+ @Value("${file.path}")
|
|
46
|
+ private String FILE_PATH;
|
|
47
|
+
|
|
48
|
+ @Value("${file.domain}")
|
|
49
|
+ private String FILE_DOMAIN;
|
|
50
|
+
|
|
51
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyMMdd/");
|
|
52
|
+
|
36
|
53
|
/**
|
37
|
54
|
* 图片
|
38
|
55
|
* @param multipartFile
|
39
|
56
|
* @return
|
40
|
57
|
*/
|
|
58
|
+ @ApiOperation(value = "图片/视频上传", notes = "图片/视频上传")
|
41
|
59
|
@PostMapping("/{plat}/image")
|
42
|
|
- public ResponseBean uploadImage(@RequestParam("file") MultipartFile multipartFile) {
|
|
60
|
+ public ResponseBean uploadImage(@PathVariable String plat, @RequestParam("file") MultipartFile multipartFile) {
|
43
|
61
|
try {
|
44
|
|
- String img = AliOSSUtils.putObject(multipartFile, CommConstant.ALIOSS_DEFAULT_UPLOAD);
|
45
|
|
- return ResponseBean.success(img);
|
|
62
|
+ // 本地保存的文件夹
|
|
63
|
+ String format = sdf.format(new Date());
|
|
64
|
+ File folder = new File(FILE_PATH + format);
|
|
65
|
+ if(!folder.isDirectory()) {
|
|
66
|
+ folder.mkdirs();
|
|
67
|
+ }
|
|
68
|
+ // 新文件夹
|
|
69
|
+ String oldName = multipartFile.getOriginalFilename();
|
|
70
|
+ String newName = UUID.randomUUID().toString() +
|
|
71
|
+ oldName.substring(oldName.lastIndexOf("."));
|
|
72
|
+
|
|
73
|
+ // 文件保存操作
|
|
74
|
+ multipartFile.transferTo(new File(folder, newName));
|
|
75
|
+ return ResponseBean.success(FILE_DOMAIN+"/file/"+ format + newName);
|
46
|
76
|
} catch (IOException e) {
|
47
|
77
|
return ResponseBean.error("上传图片失败: " + e.getMessage(), ResponseBean.ERROR_UNAVAILABLE);
|
48
|
78
|
}
|
49
|
79
|
}
|
50
|
80
|
|
|
81
|
+
|
|
82
|
+// /**
|
|
83
|
+// * 图片
|
|
84
|
+// * @param multipartFile
|
|
85
|
+// * @return
|
|
86
|
+// */
|
|
87
|
+// @ApiOperation(value = "视频上传", notes = "视频上传")
|
|
88
|
+// @PostMapping("/admin/upload/video")
|
|
89
|
+// public ResponseBean uploadVideo(@RequestParam("file") MultipartFile multipartFile) {
|
|
90
|
+// try {
|
|
91
|
+// // 本地保存的文件夹
|
|
92
|
+// String format = sdf.format(new Date());
|
|
93
|
+// File folder = new File(FILE_PATH + format);
|
|
94
|
+// if(!folder.isDirectory()) {
|
|
95
|
+// folder.mkdirs();
|
|
96
|
+// }
|
|
97
|
+// // 新文件夹
|
|
98
|
+// String oldName = multipartFile.getOriginalFilename();
|
|
99
|
+// String newName = UUID.randomUUID().toString() +
|
|
100
|
+// oldName.substring(oldName.lastIndexOf("."));
|
|
101
|
+//
|
|
102
|
+// //多线程下载文件
|
|
103
|
+// VideoThreadDownLoad.downLoad(multipartFile,FILE_PATH + format + newName);
|
|
104
|
+// return ResponseBean.success(FILE_DOMAIN+"/file/"+ format + newName);
|
|
105
|
+// } catch (Exception e) {
|
|
106
|
+// return ResponseBean.error("上传图片失败: " + e.getMessage(), ResponseBean.ERROR_UNAVAILABLE);
|
|
107
|
+// }
|
|
108
|
+// }
|
|
109
|
+
|
51
|
110
|
@PostMapping("/admin/qrcode")
|
52
|
111
|
public ResponseBean createQrCode(@RequestBody String jsonStr, HttpServletRequest request) {
|
53
|
112
|
Integer orgId = getOrgId(request);
|
|
@@ -96,8 +155,20 @@ public class CommonController extends BaseController {
|
96
|
155
|
Map<String, String> result = new HashMap<>();
|
97
|
156
|
|
98
|
157
|
try {
|
99
|
|
- String img = AliOSSUtils.putObject(multipartFile, CommConstant.ALIOSS_DEFAULT_UPLOAD);
|
|
158
|
+ // 本地保存的文件夹
|
|
159
|
+ String format = sdf.format(new Date());
|
|
160
|
+ File folder = new File(FILE_PATH + format);
|
|
161
|
+ if(!folder.isDirectory()) {
|
|
162
|
+ folder.mkdirs();
|
|
163
|
+ }
|
|
164
|
+ // 新文件夹
|
|
165
|
+ String oldName = multipartFile.getOriginalFilename();
|
|
166
|
+ String newName = UUID.randomUUID().toString() +
|
|
167
|
+ oldName.substring(oldName.lastIndexOf("."));
|
100
|
168
|
|
|
169
|
+ // 文件保存操作
|
|
170
|
+ multipartFile.transferTo(new File(folder, newName));
|
|
171
|
+ String img = FILE_DOMAIN+"/file/"+ format + newName;
|
101
|
172
|
result.put("name", StringUtils.ifNull(multipartFile.getOriginalFilename(), multipartFile.getName()));
|
102
|
173
|
result.put("status", "done");
|
103
|
174
|
result.put("thumbUrl", img + "?x-oss-process=style/thumbnail");
|