|
@@ -0,0 +1,72 @@
|
|
|
|
+package cn.com.qmth.examcloud.exchange.inner.api.provider;
|
|
|
|
+
|
|
|
|
+import java.io.IOException;
|
|
|
|
+
|
|
|
|
+import javax.servlet.ServletInputStream;
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+
|
|
|
|
+import org.apache.poi.util.IOUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
+
|
|
|
|
+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.support.ControllerSupport;
|
|
|
|
+import cn.com.qmth.examcloud.exchange.inner.api.UpyunCloudService;
|
|
|
|
+import cn.com.qmth.examcloud.exchange.inner.api.request.PutFileReq;
|
|
|
|
+import cn.com.qmth.examcloud.exchange.inner.api.response.PutFileResp;
|
|
|
|
+import cn.com.qmth.examcloud.exchange.inner.service.UpyunService;
|
|
|
|
+import cn.com.qmth.examcloud.exchange.inner.service.bean.UpyunPathEnvironmentInfo;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Upyun服务
|
|
|
|
+ *
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ * @date 2018年11月21日
|
|
|
|
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
|
|
|
|
+ */
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("${$rmp.cloud.exchange.inner}/upyun")
|
|
|
|
+public class UpyunCloudServiceProvider extends ControllerSupport implements UpyunCloudService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ UpyunService upyunService;
|
|
|
|
+
|
|
|
|
+ AES aes = new AES();
|
|
|
|
+
|
|
|
|
+ @PostMapping("putFile")
|
|
|
|
+ @Override
|
|
|
|
+ public PutFileResp putFile(PutFileReq req) {
|
|
|
|
+ HttpServletRequest request = getRequest();
|
|
|
|
+ String fileName = request.getParameter("fileName");
|
|
|
|
+ String fileSuffix = fileName.substring(fileName.lastIndexOf("."));
|
|
|
|
+ Long rootOrgId = Long.parseLong(request.getParameter("rootOrgId"));
|
|
|
|
+ Long userId = Long.parseLong(request.getParameter("userId"));
|
|
|
|
+ String siteId = request.getParameter("siteId");
|
|
|
|
+
|
|
|
|
+ ServletInputStream in = null;
|
|
|
|
+ String url;
|
|
|
|
+ try {
|
|
|
|
+ in = request.getInputStream();
|
|
|
|
+
|
|
|
|
+ UpyunPathEnvironmentInfo env = new UpyunPathEnvironmentInfo();
|
|
|
|
+ env.setRootOrgId(String.valueOf(rootOrgId));
|
|
|
|
+ env.setUserId(String.valueOf(userId));
|
|
|
|
+ env.setFileSuffix(fileSuffix);
|
|
|
|
+ url = upyunService.writeFile(siteId, env, in);
|
|
|
|
+ url = aes.encrypt(url);
|
|
|
|
+
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ throw new ExamCloudRuntimeException(e);
|
|
|
|
+ } finally {
|
|
|
|
+ IOUtils.closeQuietly(in);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ PutFileResp resp = new PutFileResp();
|
|
|
|
+ resp.setUrl(url);
|
|
|
|
+ return resp;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|