|
@@ -0,0 +1,96 @@
|
|
|
+package kankan.daikan.core.controller;
|
|
|
+
|
|
|
+import fdage.back.sdk.base.entity.Result;
|
|
|
+import fdage.back.sdk.core.alibabaUtils.AlibabaOssHelper;
|
|
|
+import fdage.back.sdk.core.alibabaUtils.AlibabaSmsService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.log4j.Log4j2;
|
|
|
+import org.apache.velocity.shaded.commons.io.FilenameUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Api(tags = "公共操作相关接口")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/common")
|
|
|
+@Log4j2
|
|
|
+public class CommonController extends BaseController{
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AlibabaOssHelper alibabaOssHelper;
|
|
|
+
|
|
|
+
|
|
|
+ @Value("${image.local.path}")
|
|
|
+ private String imageLocalPath;
|
|
|
+
|
|
|
+ @Value("${image.oss.path}")
|
|
|
+ private String ossPath;
|
|
|
+
|
|
|
+ @Value("${oss.query.url}")
|
|
|
+ private String ossQueryUrl;
|
|
|
+
|
|
|
+ @ApiOperation("上传照片(只支持JPG或者PNG格式)")
|
|
|
+ @PostMapping(value = "/uploadImage")
|
|
|
+ public Result<Object> uploadImage(@RequestParam("file") MultipartFile file) throws Exception {
|
|
|
+
|
|
|
+ if (null == file) {
|
|
|
+ return Result.failure("缺失照片文件");
|
|
|
+ }
|
|
|
+ if (file.getSize() > 100000000l) {
|
|
|
+ return Result.failure("上传文件不能超过100M");
|
|
|
+ }
|
|
|
+ if (!file.getOriginalFilename().toLowerCase().endsWith("jpg") && !file.getOriginalFilename().toLowerCase().endsWith("png")) {
|
|
|
+ return Result.failure("只能上传.jpg或者.png的照片");
|
|
|
+ }
|
|
|
+ String outPutImageName = System.currentTimeMillis() + "." + FilenameUtils.getExtension(file.getOriginalFilename());
|
|
|
+ String outPutImageResultPath = imageLocalPath + File.separator + outPutImageName;
|
|
|
+ File localFile = new File(outPutImageResultPath);
|
|
|
+ file.transferTo(localFile);
|
|
|
+ String resultOssPath = ossPath + outPutImageName;
|
|
|
+ alibabaOssHelper.doUploadThenDelete(outPutImageResultPath, resultOssPath);
|
|
|
+ String totalOssQueryPath = ossQueryUrl + resultOssPath;
|
|
|
+ Map<String, String> mp = new HashMap<>();
|
|
|
+ mp.put("ossUrl", totalOssQueryPath);
|
|
|
+ return Result.success(mp);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("上传文件(只支持PDF或者WORD格式)")
|
|
|
+ @PostMapping(value = "/uploadFile")
|
|
|
+ public Result<Object> uploadFile(@RequestParam("file") MultipartFile file) throws Exception {
|
|
|
+
|
|
|
+ if (null == file) {
|
|
|
+ return Result.failure("缺失照片文件");
|
|
|
+ }
|
|
|
+ if (file.getSize() > 100000000l) {
|
|
|
+ return Result.failure("上传文件不能超过100M");
|
|
|
+ }
|
|
|
+ if (!file.getOriginalFilename().toLowerCase().endsWith("pdf")
|
|
|
+ && !file.getOriginalFilename().toLowerCase().endsWith("docx")
|
|
|
+ && !file.getOriginalFilename().toLowerCase().endsWith("doc")
|
|
|
+ ) {
|
|
|
+ return Result.failure("只能上传pdf或者word文档");
|
|
|
+ }
|
|
|
+ String outPutImageName = System.currentTimeMillis() + "." +
|
|
|
+ FilenameUtils.getExtension(file.getOriginalFilename());
|
|
|
+ String outPutImageResultPath = imageLocalPath + File.separator + outPutImageName;
|
|
|
+ File localFile = new File(outPutImageResultPath);
|
|
|
+ file.transferTo(localFile);
|
|
|
+ String resultOssPath = ossPath + outPutImageName;
|
|
|
+ alibabaOssHelper.doUploadThenDelete(outPutImageResultPath, resultOssPath);
|
|
|
+ String totalOssQueryPath = ossQueryUrl + resultOssPath;
|
|
|
+ Map<String, String> mp = new HashMap<>();
|
|
|
+ mp.put("ossUrl", totalOssQueryPath);
|
|
|
+ return Result.success(mp);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|