|
@@ -1,102 +0,0 @@
|
|
|
-package cn.com.qmth.examcloud.exchange.inner.api.provider;
|
|
|
-
|
|
|
-import java.io.IOException;
|
|
|
-
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
-
|
|
|
-import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
-import cn.com.qmth.examcloud.commons.util.AES;
|
|
|
-import cn.com.qmth.examcloud.commons.util.PathUtil;
|
|
|
-import cn.com.qmth.examcloud.exchange.inner.api.UpyunCloudService;
|
|
|
-import cn.com.qmth.examcloud.exchange.inner.api.request.DeleteFileReq;
|
|
|
-import cn.com.qmth.examcloud.exchange.inner.api.request.PutFileReq;
|
|
|
-import cn.com.qmth.examcloud.exchange.inner.api.response.DeleteFileResp;
|
|
|
-import cn.com.qmth.examcloud.exchange.inner.api.response.PutFileResp;
|
|
|
-import cn.com.qmth.examcloud.support.filestorage.FileStorageUtil;
|
|
|
-import cn.com.qmth.examcloud.web.config.SystemProperties;
|
|
|
-import cn.com.qmth.examcloud.web.filestorage.FileStoragePathEnvInfo;
|
|
|
-import cn.com.qmth.examcloud.web.filestorage.YunPathInfo;
|
|
|
-import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
|
-import cn.com.qmth.examcloud.web.upyun.UpyunService;
|
|
|
-
|
|
|
-/**
|
|
|
- * 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 {
|
|
|
-
|
|
|
- private static final long serialVersionUID = -6911335293165224994L;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- UpyunService upyunService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- SystemProperties systemConfig;
|
|
|
-
|
|
|
- AES aes = new AES();
|
|
|
-
|
|
|
- @PostMapping("putFile")
|
|
|
- @Override
|
|
|
- public PutFileResp putFile(@ModelAttribute PutFileReq req) {
|
|
|
- String fileSuffix = req.getFileSuffix();
|
|
|
- String relativePath = req.getRelativePath();
|
|
|
- if (StringUtils.isNotBlank(relativePath)) {
|
|
|
- relativePath = PathUtil.startsWithoutSeparator(relativePath);
|
|
|
- }
|
|
|
- Long rootOrgId = req.getRootOrgId();
|
|
|
- String rootOrgDomain = req.getRootOrgDomain();
|
|
|
- Long userId = req.getUserId();
|
|
|
- String siteId = req.getSiteId();
|
|
|
- MultipartFile mf = req.getFile();
|
|
|
-
|
|
|
- FileStoragePathEnvInfo env = new FileStoragePathEnvInfo();
|
|
|
- env.setRootOrgId(String.valueOf(rootOrgId));
|
|
|
- env.setRootOrgDomain(rootOrgDomain);
|
|
|
- env.setUserId(String.valueOf(userId));
|
|
|
- env.setFileSuffix(fileSuffix);
|
|
|
- env.setRelativePath(relativePath);
|
|
|
-
|
|
|
- env.setExt1(req.getExt1());
|
|
|
- env.setExt2(req.getExt2());
|
|
|
- env.setExt3(req.getExt3());
|
|
|
- env.setExt4(req.getExt4());
|
|
|
- env.setExt5(req.getExt5());
|
|
|
-
|
|
|
- YunPathInfo pi = null;
|
|
|
- try {
|
|
|
- pi = FileStorageUtil.saveFile(siteId, env, mf.getInputStream(), null);
|
|
|
- } catch (IOException e) {
|
|
|
- throw new StatusException("005001", "fail to write to upyun", e);
|
|
|
- }
|
|
|
-
|
|
|
- PutFileResp resp = new PutFileResp();
|
|
|
- resp.setUrl(pi.getUrl());
|
|
|
- resp.setRelativePath(pi.getRelativePath());
|
|
|
- return resp;
|
|
|
- }
|
|
|
-
|
|
|
- @PostMapping("deleteFile")
|
|
|
- @Override
|
|
|
- public DeleteFileResp deleteFile(@RequestBody DeleteFileReq req) {
|
|
|
- String siteId = req.getSiteId();
|
|
|
- String filePath = req.getFilePath();
|
|
|
-
|
|
|
- upyunService.delete(siteId, filePath);
|
|
|
-
|
|
|
- DeleteFileResp resp = new DeleteFileResp();
|
|
|
- return resp;
|
|
|
- }
|
|
|
-
|
|
|
-}
|