wangwei пре 7 година
родитељ
комит
6f2df4d238

+ 28 - 1
examcloud-exchange-outer-service/src/main/java/cn/com/qmth/examcloud/exchange/outer/service/UpyunService.java

@@ -4,6 +4,9 @@ import main.java.com.UpYun;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
+
+import java.io.File;
 import java.io.IOException;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
@@ -68,7 +71,31 @@ public class UpyunService {
         }
 
     }
-
+    
+	/**
+	 * 新方案
+	 *
+	 * @author WANGWEI
+	 * @param studentId
+	 * @param rootOrgId
+	 * @param fileSuffix
+	 * @param file
+	 * @return
+	 */
+	public boolean saveStudentPhoto(Long studentId, Long rootOrgId, String fileSuffix, File file) {
+		String filePath = null;
+		if (fileSuffix.startsWith(".")) {
+			filePath = path + "/" + rootOrgId + "/" + studentId + fileSuffix;
+		} else {
+			filePath = path + "/" + rootOrgId + "/" + studentId + "." + fileSuffix;
+		}
+		try {
+			return getUpyun().writeFile(filePath, file, true);
+		} catch (IOException e) {
+			throw new StatusException("EX-100001", "调用又拍云API写文件失败");
+		}
+	}
+    
     private UpYun getUpyun() {
         if (upyun == null) {
             upyun = new UpYun(bucket, operator, password);