wangwei 7 jaren geleden
bovenliggende
commit
1680b3fea4

+ 0 - 4
examcloud-exchange-base/pom.xml

@@ -25,10 +25,6 @@
 			<artifactId>java-sdk</artifactId>
 			<version>3.14</version>
 		</dependency>
-		<dependency>
-			<groupId>org.apache.httpcomponents</groupId>
-			<artifactId>httpclient</artifactId>
-		</dependency>
 
 	</dependencies>
 </project>

+ 8 - 0
examcloud-exchange-outer-api-provider/src/main/java/cn/com/qmth/examcloud/exchange/outer/api/provider/StudentOuterServiceProvider.java

@@ -10,6 +10,7 @@ import cn.com.qmth.examcloud.core.basic.api.request.InsertOrUpdateStudentReq;
 import cn.com.qmth.examcloud.exchange.outer.api.StudentOuterService;
 import cn.com.qmth.examcloud.exchange.outer.api.request.SaveStudentReq;
 import cn.com.qmth.examcloud.exchange.outer.api.response.SaveStudentResp;
+import cn.com.qmth.examcloud.exchange.outer.service.UpyunService;
 import io.swagger.annotations.ApiOperation;
 
 /**
@@ -26,10 +27,17 @@ public class StudentOuterServiceProvider extends ControllerSupport implements St
 	@Autowired
 	StudentCloudService studentCloudService;
 
+	@Autowired
+	UpyunService upyunService;
+
 	@ApiOperation(value = "保存学生信息")
 	@PostMapping("saveStudent")
 	@Override
 	public SaveStudentResp saveStudent(@RequestBody SaveStudentReq req) {
+		
+		String photoPath = req.getPhotoPath();
+		
+		
 
 		InsertOrUpdateStudentReq request = new InsertOrUpdateStudentReq();
 		request.setIdentityNumber(req.getIdentityNumber());

+ 12 - 0
examcloud-exchange-outer-service/src/main/java/cn/com/qmth/examcloud/exchange/outer/service/UpyunService.java

@@ -23,4 +23,16 @@ public interface UpyunService {
 	 */
 	boolean saveStudentPhoto(Long studentId, Long rootOrgId, String fileSuffix, File file);
 
+	/**
+	 * 新方案
+	 *
+	 * @author WANGWEI
+	 * @param studentId
+	 * @param rootOrgId
+	 * @param fileSuffix
+	 * @param bytes
+	 * @return
+	 */
+	boolean saveStudentPhoto(Long studentId, Long rootOrgId, String fileSuffix, byte[] bytes);
+
 }

+ 72 - 50
examcloud-exchange-outer-service/src/main/java/cn/com/qmth/examcloud/exchange/outer/service/impl/UpyunServiceImpl.java

@@ -16,64 +16,77 @@ import java.security.NoSuchAlgorithmException;
  * Created by yuanpan on 2017/5/11.
  */
 @Service
-public class UpyunServiceImpl implements UpyunService{
+public class UpyunServiceImpl implements UpyunService {
 
-    private UpYun upyun;
+	private UpYun upyun;
 
-    @Value("${app.upyun.path}")
-    private String path;
+	@Value("${app.upyun.path}")
+	private String path;
 
-    @Value("${app.upyun.bucket}")
-    private String bucket;
+	@Value("${app.upyun.bucket}")
+	private String bucket;
 
-    @Value("${app.upyun.operator}")
-    private String operator;
+	@Value("${app.upyun.operator}")
+	private String operator;
 
-    @Value("${app.upyun.password}")
-    private String password;
+	@Value("${app.upyun.password}")
+	private String password;
 
-    public String getDownloadUrl(String identityNumber, String fileName, String fileSuffix) {
-//        http://exam-cloud-test.b0.upaiyun.com/student_base_photo/420678442922121/11b1841125259151f0347415d1740595.jpg
+	private UpYun getUpyun() {
+		if (upyun == null) {
+			upyun = new UpYun(bucket, operator, password);
+		}
+		return upyun;
+	}
 
-        if (fileSuffix.startsWith(".")) {
-            return "http://" + bucket + ".b0.upaiyun.com/student_base_photo/" + identityNumber + "/" + fileName + "" + fileSuffix;
-        } else {
-            return "http://" + bucket + ".b0.upaiyun.com/student_base_photo/" + identityNumber + "/" + fileName + "." + fileSuffix;
-        }
+	public String getDownloadUrl(String identityNumber, String fileName, String fileSuffix) {
+		// http://exam-cloud-test.b0.upaiyun.com/student_base_photo/420678442922121/11b1841125259151f0347415d1740595.jpg
 
-    }
+		if (fileSuffix.startsWith(".")) {
+			return "http://" + bucket + ".b0.upaiyun.com/student_base_photo/" + identityNumber + "/"
+					+ fileName + "" + fileSuffix;
+		} else {
+			return "http://" + bucket + ".b0.upaiyun.com/student_base_photo/" + identityNumber + "/"
+					+ fileName + "." + fileSuffix;
+		}
 
-    public String getMd5(byte[] bytes) throws NoSuchAlgorithmException {
-        //用来计算md5摘要的
-        char[] hexDigits = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
+	}
 
-        MessageDigest md5 = MessageDigest.getInstance("MD5");
-        md5.update(bytes);
+	public String getMd5(byte[] bytes) throws NoSuchAlgorithmException {
+		// 用来计算md5摘要的
+		char[] hexDigits = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b',
+				'c', 'd', 'e', 'f'};
 
-        byte[] md5DigestBytes = md5.digest();
-        int dlen = md5DigestBytes.length;
+		MessageDigest md5 = MessageDigest.getInstance("MD5");
+		md5.update(bytes);
 
-        char[] md5val = new char[dlen * 2];
-        int k = 0;
-        for (byte encoded : md5DigestBytes) {
-            md5val[k++] = hexDigits[encoded >> 4 & 15];
-            md5val[k++] = hexDigits[encoded & 5];
-        }
+		byte[] md5DigestBytes = md5.digest();
+		int dlen = md5DigestBytes.length;
 
-        return new String(md5val);
-    }
+		char[] md5val = new char[dlen * 2];
+		int k = 0;
+		for (byte encoded : md5DigestBytes) {
+			md5val[k++] = hexDigits[encoded >> 4 & 15];
+			md5val[k++] = hexDigits[encoded & 5];
+		}
 
-    public boolean saveStudentPhoto(String identityNumber, byte[] bytes, String fileName, String fileSuffix) throws IOException {
+		return new String(md5val);
+	}
+
+	public boolean saveStudentPhoto(String identityNumber, byte[] bytes, String fileName,
+			String fileSuffix) throws IOException {
 
-        if (fileSuffix.startsWith(".")) {
-            return getUpyun().writeFile(path + "/" + identityNumber + "/" + fileName + fileSuffix, bytes, true);
-        } else {
-            return getUpyun().writeFile(path + "/" + identityNumber + "/" + fileName + "." + fileSuffix, bytes, true);
-        }
+		if (fileSuffix.startsWith(".")) {
+			return getUpyun().writeFile(path + "/" + identityNumber + "/" + fileName + fileSuffix,
+					bytes, true);
+		} else {
+			return getUpyun().writeFile(
+					path + "/" + identityNumber + "/" + fileName + "." + fileSuffix, bytes, true);
+		}
 
-    }
-    
-    @Override
+	}
+
+	@Override
 	public boolean saveStudentPhoto(Long studentId, Long rootOrgId, String fileSuffix, File file) {
 		String filePath = null;
 		if (fileSuffix.startsWith(".")) {
@@ -83,15 +96,24 @@ public class UpyunServiceImpl implements UpyunService{
 		}
 		try {
 			return getUpyun().writeFile(filePath, file, true);
-		} catch (IOException e) {
+		} catch (Exception e) {
+			throw new StatusException("EX-100001", "调用又拍云API写文件失败");
+		}
+	}
+
+	@Override
+	public boolean saveStudentPhoto(Long studentId, Long rootOrgId, String fileSuffix,
+			byte[] bytes) {
+		String filePath = null;
+		if (fileSuffix.startsWith(".")) {
+			filePath = path + "/" + rootOrgId + "/" + studentId + fileSuffix;
+		} else {
+			filePath = path + "/" + rootOrgId + "/" + studentId + "." + fileSuffix;
+		}
+		try {
+			return getUpyun().writeFile(filePath, bytes, true);
+		} catch (Exception e) {
 			throw new StatusException("EX-100001", "调用又拍云API写文件失败");
 		}
 	}
-    
-    private UpYun getUpyun() {
-        if (upyun == null) {
-            upyun = new UpYun(bucket, operator, password);
-        }
-        return upyun;
-    }
 }