|
@@ -0,0 +1,65 @@
|
|
|
+package com.lc.admin.controller;
|
|
|
+
|
|
|
+import com.aliyun.oss.ClientException;
|
|
|
+import com.aliyun.oss.OSS;
|
|
|
+import com.aliyun.oss.OSSClientBuilder;
|
|
|
+import com.aliyun.oss.OSSException;
|
|
|
+import com.aliyun.oss.model.PutObjectRequest;
|
|
|
+import com.aliyun.oss.model.PutObjectResult;
|
|
|
+import com.lc.common.pojo.TravelParams;
|
|
|
+import com.lc.common.utils.Result;
|
|
|
+import com.lc.service.SetmealService;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
+import org.springframework.context.annotation.PropertySource;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.IOException;
|
|
|
+
|
|
|
+@RequestMapping("/setmeal")
|
|
|
+@RestController
|
|
|
+public class SetmealController {
|
|
|
+
|
|
|
+ @Value("${setmeal.upload.alioss.endpoint}")
|
|
|
+ private String endpoint;
|
|
|
+ @Value("${setmeal.upload.alioss.accessKeyId}")
|
|
|
+ private String accessKeyId;
|
|
|
+ @Value("${setmeal.upload.alioss.accessKeySecret}")
|
|
|
+ private String accessKeySecret;
|
|
|
+ @Value("${setmeal.upload.alioss.bucketName}")
|
|
|
+ private String bucketName;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ SetmealService setmealService;
|
|
|
+
|
|
|
+ @PostMapping("/findPage.do")
|
|
|
+ public Result findPage( @RequestBody TravelParams travelParams ){
|
|
|
+ return Result.data( setmealService.findPage( travelParams ) );
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/upload.do")
|
|
|
+ public Result upload(MultipartFile imgFile){
|
|
|
+ String originalFilename = imgFile.getOriginalFilename();
|
|
|
+ OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
|
|
+ try {
|
|
|
+ PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName,
|
|
|
+ originalFilename, imgFile.getInputStream() );
|
|
|
+ PutObjectResult result = ossClient.putObject(putObjectRequest);
|
|
|
+ //System.out.println( result );
|
|
|
+ } catch (OSSException oe) {
|
|
|
+ System.out.println( oe.getMessage() );
|
|
|
+ } catch (ClientException ce) {
|
|
|
+ System.out.println( ce.getMessage() );
|
|
|
+ } catch (IOException e) {
|
|
|
+ System.out.println( e.getMessage() );
|
|
|
+ } finally {
|
|
|
+ if (ossClient != null) {
|
|
|
+ ossClient.shutdown();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result.data(originalFilename);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|