浏览代码

。。。。

WANG 6 年之前
父节点
当前提交
cdde95e11b

+ 146 - 0
src/main/java/cn/com/qmth/examcloud/web/upyun/UpyunPathEnvironmentInfo.java

@@ -0,0 +1,146 @@
+package cn.com.qmth.examcloud.web.upyun;
+
+import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
+
+/**
+ * 又拍云路径变量
+ *
+ * @author WANGWEI
+ * @date 2018年11月21日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public class UpyunPathEnvironmentInfo implements JsonSerializable {
+
+	private static final long serialVersionUID = -3579995914084929142L;
+
+	/**
+	 * 顶级机构
+	 */
+	private String rootOrgId;
+
+	/**
+	 * 用户ID
+	 */
+	private String userId;
+
+	/**
+	 * 时间戳
+	 */
+	private String currentTimeMillis;
+
+	/**
+	 * 文件后缀(以"."开头,如 ".jpg",".zip")
+	 */
+	private String fileSuffix;
+
+	/**
+	 * 相对路径
+	 */
+	private String relativePath;
+
+	/**
+	 * 扩展属性
+	 */
+	private String ext1;
+
+	/**
+	 * 扩展属性
+	 */
+	private String ext2;
+
+	/**
+	 * 扩展属性
+	 */
+	private String ext3;
+
+	/**
+	 * 扩展属性
+	 */
+	private String ext4;
+
+	/**
+	 * 扩展属性
+	 */
+	private String ext5;
+
+	public String getRootOrgId() {
+		return rootOrgId;
+	}
+
+	public void setRootOrgId(String rootOrgId) {
+		this.rootOrgId = rootOrgId;
+	}
+
+	public String getUserId() {
+		return userId;
+	}
+
+	public void setUserId(String userId) {
+		this.userId = userId;
+	}
+
+	public String getCurrentTimeMillis() {
+		return currentTimeMillis;
+	}
+
+	public void setCurrentTimeMillis(String currentTimeMillis) {
+		this.currentTimeMillis = currentTimeMillis;
+	}
+
+	public String getFileSuffix() {
+		return fileSuffix;
+	}
+
+	public void setFileSuffix(String fileSuffix) {
+		this.fileSuffix = fileSuffix;
+	}
+
+	public String getRelativePath() {
+		return relativePath;
+	}
+
+	public void setRelativePath(String relativePath) {
+		this.relativePath = relativePath;
+	}
+
+	public String getExt1() {
+		return ext1;
+	}
+
+	public void setExt1(String ext1) {
+		this.ext1 = ext1;
+	}
+
+	public String getExt2() {
+		return ext2;
+	}
+
+	public void setExt2(String ext2) {
+		this.ext2 = ext2;
+	}
+
+	public String getExt3() {
+		return ext3;
+	}
+
+	public void setExt3(String ext3) {
+		this.ext3 = ext3;
+	}
+
+	public String getExt4() {
+		return ext4;
+	}
+
+	public void setExt4(String ext4) {
+		this.ext4 = ext4;
+	}
+
+	public String getExt5() {
+		return ext5;
+	}
+
+	public void setExt5(String ext5) {
+		this.ext5 = ext5;
+	}
+
+}

+ 55 - 0
src/main/java/cn/com/qmth/examcloud/web/upyun/UpyunService.java

@@ -0,0 +1,55 @@
+package cn.com.qmth.examcloud.web.upyun;
+
+import java.io.File;
+import java.io.InputStream;
+
+/**
+ * 又拍云 服务
+ *
+ * @author WANGWEI
+ * @date 2018年6月29日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public interface UpyunService {
+
+	/**
+	 * 写文件
+	 *
+	 * @author WANGWEI
+	 * @param siteId
+	 * @param env
+	 * @param in
+	 * @return
+	 */
+	UpYunPathInfo writeFile(String siteId, UpyunPathEnvironmentInfo env, InputStream in);
+
+	/**
+	 * 写文件
+	 *
+	 * @author WANGWEI
+	 * @param siteId
+	 * @param env
+	 * @param file
+	 * @return
+	 */
+	UpYunPathInfo writeFile(String siteId, UpyunPathEnvironmentInfo env, File file);
+
+	/**
+	 * 删除文件
+	 *
+	 * @author WANGWEI
+	 * @param siteId
+	 * @param filePath
+	 */
+	void delete(String siteId, String filePath);
+
+	/**
+	 * 创建签名
+	 *
+	 * @author WANGWEI
+	 * @param filePath
+	 * @return
+	 */
+	UpYunSign buildUpYunSign(String siteId, UpyunPathEnvironmentInfo env);
+
+}

+ 64 - 0
src/main/java/cn/com/qmth/examcloud/web/upyun/UpyunServiceImpl.java

@@ -0,0 +1,64 @@
+package cn.com.qmth.examcloud.web.upyun;
+
+import java.io.File;
+import java.io.InputStream;
+
+import org.springframework.stereotype.Service;
+
+import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
+import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
+import cn.com.qmth.examcloud.commons.util.FreeMarkerUtil;
+
+/**
+ * 类注释
+ *
+ * @author WANGWEI
+ * @date 2018年9月4日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+@Service
+public class UpyunServiceImpl implements UpyunService {
+
+	protected ExamCloudLog log = ExamCloudLogFactory.getLog(this.getClass());
+
+	@Override
+	public UpYunPathInfo writeFile(String siteId, UpyunPathEnvironmentInfo env, InputStream in) {
+		env.setCurrentTimeMillis(String.valueOf(System.currentTimeMillis()));
+
+		UpyunSite upyunSite = UpyunSiteManager.getUpyunSite(siteId);
+		UpYunClient upYunClient = UpyunSiteManager.getUpYunClient(siteId);
+
+		String path = FreeMarkerUtil.process(upyunSite.getPath(), env);
+		UpYunPathInfo pathInfo = upYunClient.writeFile(path, in);
+		return pathInfo;
+	}
+
+	@Override
+	public UpYunPathInfo writeFile(String siteId, UpyunPathEnvironmentInfo env, File file) {
+		env.setCurrentTimeMillis(String.valueOf(System.currentTimeMillis()));
+
+		UpyunSite upyunSite = UpyunSiteManager.getUpyunSite(siteId);
+		UpYunClient upYunClient = UpyunSiteManager.getUpYunClient(siteId);
+
+		String path = FreeMarkerUtil.process(upyunSite.getPath(), env);
+		UpYunPathInfo pathInfo = upYunClient.writeFile(path, file);
+		return pathInfo;
+	}
+
+	@Override
+	public void delete(String siteId, String filePath) {
+		UpYunClient upYunClient = UpyunSiteManager.getUpYunClient(siteId);
+		upYunClient.deleteFile(filePath);
+	}
+
+	@Override
+	public UpYunSign buildUpYunSign(String siteId, UpyunPathEnvironmentInfo env) {
+		UpyunSite upyunSite = UpyunSiteManager.getUpyunSite(siteId);
+		UpYunClient upYunClient = UpyunSiteManager.getUpYunClient(siteId);
+
+		String path = FreeMarkerUtil.process(upyunSite.getPath(), env);
+		UpYunSign sign = upYunClient.buildUpYunSign(path);
+		return sign;
+	}
+
+}