WANG 6 anni fa
parent
commit
865647be32

+ 9 - 4
src/main/java/cn/com/qmth/examcloud/web/upyun/UpyunServiceImpl.java

@@ -23,10 +23,11 @@ public class UpyunServiceImpl implements UpyunService {
 
 	@Override
 	public UpYunPathInfo writeFile(String siteId, UpyunPathEnvironmentInfo env, InputStream in) {
+
 		env.setTimeMillis(String.valueOf(System.currentTimeMillis()));
 
 		UpyunSite upyunSite = UpyunSiteManager.getUpyunSite(siteId);
-		UpYunClient upYunClient = UpyunSiteManager.getUpYunClient(siteId);
+		UpYunClient upYunClient = UpyunSiteManager.getUpYunClientByUpyunId(upyunSite.getUpyunId());
 
 		String path = FreeMarkerUtil.process(upyunSite.getPath(), env);
 		UpYunPathInfo pathInfo = upYunClient.writeFile(path, in);
@@ -35,10 +36,11 @@ public class UpyunServiceImpl implements UpyunService {
 
 	@Override
 	public UpYunPathInfo writeFile(String siteId, UpyunPathEnvironmentInfo env, File file) {
+
 		env.setTimeMillis(String.valueOf(System.currentTimeMillis()));
 
 		UpyunSite upyunSite = UpyunSiteManager.getUpyunSite(siteId);
-		UpYunClient upYunClient = UpyunSiteManager.getUpYunClient(siteId);
+		UpYunClient upYunClient = UpyunSiteManager.getUpYunClientByUpyunId(upyunSite.getUpyunId());
 
 		String path = FreeMarkerUtil.process(upyunSite.getPath(), env);
 		UpYunPathInfo pathInfo = upYunClient.writeFile(path, file);
@@ -47,8 +49,9 @@ public class UpyunServiceImpl implements UpyunService {
 
 	@Override
 	public void delete(String siteId, UpyunPathEnvironmentInfo env) {
+
 		UpyunSite upyunSite = UpyunSiteManager.getUpyunSite(siteId);
-		UpYunClient upYunClient = UpyunSiteManager.getUpYunClient(siteId);
+		UpYunClient upYunClient = UpyunSiteManager.getUpYunClientByUpyunId(upyunSite.getUpyunId());
 
 		String path = FreeMarkerUtil.process(upyunSite.getPath(), env);
 		upYunClient.deleteFile(path);
@@ -56,9 +59,11 @@ public class UpyunServiceImpl implements UpyunService {
 
 	@Override
 	public UpYunSign buildUpYunSign(String siteId, UpyunPathEnvironmentInfo env) {
+
 		env.setTimeMillis(String.valueOf(System.currentTimeMillis()));
+
 		UpyunSite upyunSite = UpyunSiteManager.getUpyunSite(siteId);
-		UpYunClient upYunClient = UpyunSiteManager.getUpYunClient(siteId);
+		UpYunClient upYunClient = UpyunSiteManager.getUpYunClientByUpyunId(upyunSite.getUpyunId());
 
 		String path = FreeMarkerUtil.process(upyunSite.getPath(), env);
 		UpYunSign sign = upYunClient.buildUpYunSign(path);

+ 21 - 4
src/main/java/cn/com/qmth/examcloud/web/upyun/UpyunSiteManager.java

@@ -71,14 +71,30 @@ public class UpyunSiteManager {
 				throw new StatusException("520004", "domain is not configured. upyunId=" + upyunId);
 			}
 
-			if (null == CLIENT_HOLDERS.get(upyunSite.getId())) {
+			if (null == CLIENT_HOLDERS.get(upyunId)) {
 				UpYunClient upYunClient = new UpYunClient(bucketName, userName, password, domain);
-				CLIENT_HOLDERS.put(upyunSite.getId(), upYunClient);
+				CLIENT_HOLDERS.put(upyunId, upYunClient);
 			}
 		}
 
 	}
 
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param upyunId
+	 * @return
+	 */
+	public static UpYunClient getUpYunClientByUpyunId(String upyunId) {
+		UpYunClient upYunClient = CLIENT_HOLDERS.get(upyunId);
+
+		if (null == upYunClient) {
+			throw new StatusException("520005", "upYunClient is null");
+		}
+		return upYunClient;
+	}
+
 	/**
 	 * 方法注释
 	 *
@@ -86,8 +102,9 @@ public class UpyunSiteManager {
 	 * @param siteId
 	 * @return
 	 */
-	public static UpYunClient getUpYunClient(String siteId) {
-		UpYunClient upYunClient = CLIENT_HOLDERS.get(siteId);
+	public static UpYunClient getUpYunClientBySiteId(String siteId) {
+		UpyunSite upyunSite = getUpyunSite(siteId);
+		UpYunClient upYunClient = CLIENT_HOLDERS.get(upyunSite.getUpyunId());
 
 		if (null == upYunClient) {
 			throw new StatusException("520005", "upYunClient is null");