wangwei 7 년 전
부모
커밋
274bdbc872

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

@@ -1,12 +1,17 @@
 package cn.com.qmth.examcloud.exchange.outer.api.provider;
 
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
+import cn.com.qmth.examcloud.commons.base.util.HttpClientUtil;
+import cn.com.qmth.examcloud.commons.base.util.UrlUtil;
 import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
 import cn.com.qmth.examcloud.core.basic.api.StudentCloudService;
 import cn.com.qmth.examcloud.core.basic.api.request.InsertOrUpdateStudentReq;
+import cn.com.qmth.examcloud.core.basic.api.response.InsertOrUpdateStudentResp;
 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;
@@ -34,10 +39,24 @@ public class StudentOuterServiceProvider extends ControllerSupport implements St
 	@PostMapping("saveStudent")
 	@Override
 	public SaveStudentResp saveStudent(@RequestBody SaveStudentReq req) {
-		
+		String identityNumber = req.getIdentityNumber();
+		Long rootOrgId = req.getRootOrgId();
+
 		String photoPath = req.getPhotoPath();
-		
-		
+		if (StringUtils.isNotBlank(photoPath)) {
+			if (photoPath.startsWith("http")) {
+				byte[] bs = HttpClientUtil.get(photoPath);
+
+				int lastIndexOf = photoPath.lastIndexOf(".");
+				if (0 > lastIndexOf) {
+					throw new StatusException("EX-100002",
+							"photoPath is not end with photo file suffix.");
+				}
+				String fileSuffix = photoPath.substring(lastIndexOf);
+				photoPath = upyunService.saveStudentPhoto(UrlUtil.encode(identityNumber), rootOrgId,
+						fileSuffix, bs);
+			}
+		}
 
 		InsertOrUpdateStudentReq request = new InsertOrUpdateStudentReq();
 		request.setIdentityNumber(req.getIdentityNumber());
@@ -49,11 +68,15 @@ public class StudentOuterServiceProvider extends ControllerSupport implements St
 		request.setRemark(req.getRemark());
 		request.setRootOrgId(req.getRootOrgId());
 		request.setStudentCode(req.getStudentCode());
+		request.setPhotoPath(photoPath);
 
-		request.setPhotoPath("");
-
-		studentCloudService.insertOrUpdateStudent(request);
-		return null;
+		InsertOrUpdateStudentResp response = studentCloudService.insertOrUpdateStudent(request);
+		SaveStudentResp resp = new SaveStudentResp();
+		resp.setOrgId(response.getOrgId());
+		resp.setOrgName(response.getOrgName());
+		resp.setRootOrgId(response.getRootOrgId());
+		resp.setStudentId(response.getStudentId());
+		return resp;
 	}
 
 }

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

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

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

@@ -1,16 +1,16 @@
 package cn.com.qmth.examcloud.exchange.outer.service.impl;
 
-import main.java.com.UpYun;
+import java.io.File;
+import java.io.IOException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import cn.com.qmth.examcloud.commons.base.exception.StatusException;
 import cn.com.qmth.examcloud.exchange.outer.service.UpyunService;
-
-import java.io.File;
-import java.io.IOException;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
+import main.java.com.UpYun;
 
 /**
  * Created by yuanpan on 2017/5/11.
@@ -87,31 +87,36 @@ public class UpyunServiceImpl implements UpyunService {
 	}
 
 	@Override
-	public boolean saveStudentPhoto(Long studentId, Long rootOrgId, String fileSuffix, File file) {
-		String filePath = null;
+	public String saveStudentPhoto(String identityNumber, Long rootOrgId, String fileSuffix,
+			File file) {
+		String filePath = path + "/" + rootOrgId + "/" + identityNumber + "/"
+				+ System.currentTimeMillis();
 		if (fileSuffix.startsWith(".")) {
-			filePath = path + "/" + rootOrgId + "/" + studentId + fileSuffix;
+			filePath += fileSuffix;
 		} else {
-			filePath = path + "/" + rootOrgId + "/" + studentId + "." + fileSuffix;
+			filePath += "." + fileSuffix;
 		}
 		try {
-			return getUpyun().writeFile(filePath, file, true);
+			getUpyun().writeFile(filePath, file, true);
+			return filePath;
 		} catch (Exception e) {
 			throw new StatusException("EX-100001", "调用又拍云API写文件失败");
 		}
 	}
 
 	@Override
-	public boolean saveStudentPhoto(Long studentId, Long rootOrgId, String fileSuffix,
+	public String saveStudentPhoto(String identityNumber, Long rootOrgId, String fileSuffix,
 			byte[] bytes) {
-		String filePath = null;
+		String filePath = path + "/" + rootOrgId + "/" + identityNumber + "/"
+				+ System.currentTimeMillis();
 		if (fileSuffix.startsWith(".")) {
-			filePath = path + "/" + rootOrgId + "/" + studentId + fileSuffix;
+			filePath += fileSuffix;
 		} else {
-			filePath = path + "/" + rootOrgId + "/" + studentId + "." + fileSuffix;
+			filePath += "." + fileSuffix;
 		}
 		try {
-			return getUpyun().writeFile(filePath, bytes, true);
+			getUpyun().writeFile(filePath, bytes, true);
+			return filePath;
 		} catch (Exception e) {
 			throw new StatusException("EX-100001", "调用又拍云API写文件失败");
 		}