wangwei 7 ani în urmă
părinte
comite
2deddb4802

+ 14 - 21
examcloud-exchange-outer-api-provider/src/main/java/cn/com/qmth/examcloud/exchange/outer/api/provider/FaceppController.java

@@ -1,6 +1,8 @@
 package cn.com.qmth.examcloud.exchange.outer.api.provider;
 
 import java.io.IOException;
+import java.net.URISyntaxException;
+import java.security.NoSuchAlgorithmException;
 import java.util.List;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
@@ -20,15 +22,17 @@ import org.springframework.web.multipart.MultipartFile;
 
 import cn.com.qmth.examcloud.common.dto.core.StudentFaceInfo;
 import cn.com.qmth.examcloud.common.dto.em.ExamStudent;
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
 import cn.com.qmth.examcloud.commons.base.util.GsonUtil;
 import cn.com.qmth.examcloud.commons.web.security.bean.User;
 import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
 import cn.com.qmth.examcloud.exchange.base.exception.DetectNoFaceException;
 import cn.com.qmth.examcloud.exchange.base.exception.ExamStudentNotExistException;
+import cn.com.qmth.examcloud.exchange.base.exception.FaceppException;
 import cn.com.qmth.examcloud.exchange.base.exception.InvalidJpgException;
+import cn.com.qmth.examcloud.exchange.base.exception.UpYunException;
 import cn.com.qmth.examcloud.exchange.base.response.FailureBaseResponse;
 import cn.com.qmth.examcloud.exchange.base.response.IBaseResponse;
-import cn.com.qmth.examcloud.exchange.base.response.SuccessBaseResponse;
 import cn.com.qmth.examcloud.exchange.outer.service.FaceppService;
 import cn.com.qmth.examcloud.exchange.outer.service.client.ExamStudentClient;
 import cn.com.qmth.examcloud.exchange.outer.service.client.StudentFaceInfoClient;
@@ -79,36 +83,25 @@ public class FaceppController extends ControllerSupport {
 	 * @param file
 	 * @param request
 	 * @return
+	 * @throws IOException
+	 * @throws UpYunException
+	 * @throws FaceppException
+	 * @throws URISyntaxException
+	 * @throws NoSuchAlgorithmException
 	 */
 	@PostMapping("/add")
-	public ResponseEntity<IBaseResponse> add(@RequestParam MultipartFile file,
-			HttpServletRequest request) {
+	public void add(@RequestParam MultipartFile file, HttpServletRequest request) throws Exception {
 		User accessUser = getAccessUser();
-		if (accessUser == null) {
-			return new ResponseEntity<>(new FailureBaseResponse("请先登录", null),
-					HttpStatus.BAD_REQUEST);
-		}
 		try {
 			log.debug("fileName =" + file.getOriginalFilename());
 			faceppService.processOne(accessUser, file.getOriginalFilename(), file.getBytes(),
 					accessUser.getRootOrgId());
-			return new ResponseEntity<>(new SuccessBaseResponse("上传成功", null), HttpStatus.OK);
 		} catch (InvalidJpgException e) {
-			log.error(e.getMessage(), e);
-			return new ResponseEntity<>(new FailureBaseResponse("不是一个图片文件", null),
-					HttpStatus.NOT_ACCEPTABLE);
+			throw new StatusException("EX-111001", "不是一个图片文件");
 		} catch (ExamStudentNotExistException e) {
-			log.error(e.getMessage(), e);
-			return new ResponseEntity<>(new FailureBaseResponse("考生不存在", null),
-					HttpStatus.NOT_ACCEPTABLE);
+			throw new StatusException("EX-111002", "考生不存在");
 		} catch (DetectNoFaceException e) {
-			log.error(e.getMessage(), e);
-			return new ResponseEntity<>(new FailureBaseResponse("检测不到人脸", null),
-					HttpStatus.NOT_ACCEPTABLE);
-		} catch (Exception e) {
-			log.error(e.getMessage(), e);
-			return new ResponseEntity<>(new FailureBaseResponse("上传失败", null),
-					HttpStatus.INTERNAL_SERVER_ERROR);
+			throw new StatusException("EX-111003", "检测不到人脸");
 		}
 	}
 

+ 0 - 31
examcloud-exchange-outer-service/src/main/java/cn/com/qmth/examcloud/exchange/outer/service/FaceppService.java

@@ -185,37 +185,6 @@ public class FaceppService {
 		return success;
 	}
 
-	/**
-	 * 添加人脸到人脸集合
-	 * 
-	 * @param faceToken
-	 * @return 添加成功则返回faceset_token,否则返回null
-	 * @throws URISyntaxException
-	 */
-	/*
-	 * public String createFaceset(String faceToken) throws URISyntaxException {
-	 * int time = 3;//重新检测次数为3次 while (time > 0) {
-	 * 
-	 * 
-	 * //调用人脸识别接口 CloseableHttpClient httpClient = HttpClients.createDefault();
-	 * URI uri = new URIBuilder() .setScheme("https")
-	 * .setHost("api-cn.faceplusplus.com") .setPath("/facepp/v3/faceset/create")
-	 * .setParameter("api_key", apiKey) .setParameter("api_secret", apiSecret)
-	 * .setParameter("face_tokens", faceToken) .build();
-	 * 
-	 * HttpPost httpPost = new HttpPost(uri); CloseableHttpResponse httpResponse
-	 * = null; try { httpResponse = httpClient.execute(httpPost); StatusLine
-	 * statusLine = httpResponse.getStatusLine(); if (statusLine.getStatusCode()
-	 * == 200) { HttpEntity httpEntity = httpResponse.getEntity(); Gson gson =
-	 * new GsonBuilder().create(); Reader reader = new
-	 * InputStreamReader(httpEntity.getContent()); CreateFacesetResponse
-	 * faceDetectResponse = gson.fromJson(reader, CreateFacesetResponse.class);
-	 * if (!StringUtils.isEmpty(faceDetectResponse.getFaceset_token())) { return
-	 * faceDetectResponse.getFaceset_token(); } } //准备重试 time--; } catch
-	 * (IOException e) { //重试 LOG.error("保存人脸失败,剩余次数:" + (time - 1), e); time--;
-	 * } finally { closeResponse(httpResponse); } } return null; }
-	 */
-
 	public void processOne(User accessUser, String fileName, byte[] dataBytes, Long rootOrgId)
 			throws InvalidJpgException, ExamStudentNotExistException, NoSuchAlgorithmException,
 			DetectNoFaceException, URISyntaxException, FaceppException, UpYunException {