|
@@ -1,13 +1,24 @@
|
|
|
package cn.com.qmth.examcloud.exchange.inner.api.controller;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+
|
|
|
+import javax.servlet.ServletInputStream;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import org.apache.poi.util.IOUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
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.commons.CommonsMultipartFile;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.exception.ExamCloudRuntimeException;
|
|
|
+import cn.com.qmth.examcloud.commons.base.util.AES;
|
|
|
+import cn.com.qmth.examcloud.commons.web.security.bean.User;
|
|
|
import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
|
+import cn.com.qmth.examcloud.exchange.inner.service.UpyunService;
|
|
|
+import cn.com.qmth.examcloud.exchange.inner.service.bean.UpyunPathEnvironmentInfo;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
/**
|
|
@@ -21,15 +32,31 @@ import io.swagger.annotations.ApiOperation;
|
|
|
@RequestMapping("${$rmp.ctr.exchange.inner}/upyun")
|
|
|
public class UpyunController extends ControllerSupport {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ UpyunService upyunService;
|
|
|
+
|
|
|
+ AES aes = new AES();
|
|
|
+
|
|
|
@ApiOperation(value = "保存照片")
|
|
|
@PostMapping("put/{siteId}")
|
|
|
- public String addPhoto(@PathVariable String siteId,
|
|
|
- @RequestParam(required = true) CommonsMultipartFile file) {
|
|
|
+ public String addPhoto(@PathVariable String siteId, HttpServletRequest req,
|
|
|
+ HttpServletResponse resp) {
|
|
|
+ User accessUser = getAccessUser();
|
|
|
+ ServletInputStream in = null;
|
|
|
+ try {
|
|
|
+ in = req.getInputStream();
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- return null;
|
|
|
+ UpyunPathEnvironmentInfo env = new UpyunPathEnvironmentInfo();
|
|
|
+ env.setRootOrgId(String.valueOf(accessUser.getRootOrgId()));
|
|
|
+ env.setUserId(String.valueOf(accessUser.getUserId()));
|
|
|
+ String url = upyunService.writeFile(siteId, env, in);
|
|
|
+ url = aes.encrypt(url);
|
|
|
+ return url;
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new ExamCloudRuntimeException(e);
|
|
|
+ } finally {
|
|
|
+ IOUtils.closeQuietly(in);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|