|
@@ -2,23 +2,13 @@ package cn.com.qmth.examcloud.service.examwork.service;
|
|
|
|
|
|
import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.startsWith;
|
|
|
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileNotFoundException;
|
|
|
-import java.io.FileOutputStream;
|
|
|
-import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
-import java.io.OutputStream;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
-import java.util.zip.ZipEntry;
|
|
|
-import java.util.zip.ZipInputStream;
|
|
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
|
|
|
-import org.json.JSONArray;
|
|
|
-import org.json.JSONObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.domain.Example;
|
|
|
import org.springframework.data.domain.ExampleMatcher;
|
|
|
import org.springframework.data.domain.Page;
|
|
@@ -35,10 +25,6 @@ import cn.com.qmth.examcloud.service.examwork.dao.ExamRepo;
|
|
|
import cn.com.qmth.examcloud.service.examwork.dao.ExamStudentRepo;
|
|
|
import cn.com.qmth.examcloud.service.examwork.entity.Exam;
|
|
|
import cn.com.qmth.examcloud.service.examwork.entity.ExamStudent;
|
|
|
-import cn.com.qmth.examcloud.service.examwork.service.rpc.StudentService;
|
|
|
-
|
|
|
-import com.facepp.http.HttpRequests;
|
|
|
-import com.facepp.http.PostParameters;
|
|
|
|
|
|
/**
|
|
|
* 考试学生服务类
|
|
@@ -50,17 +36,13 @@ public class ExamStudentService {
|
|
|
ExamStudentRepo examStudentRepo;
|
|
|
@Autowired
|
|
|
ExamRepo examRepo;
|
|
|
- @Autowired
|
|
|
- StudentService studentService;
|
|
|
|
|
|
- @Value("${app.em.photo.path}")
|
|
|
- private String PHOTO_PATH ;
|
|
|
- @Value("${app.em.facepp.key}")
|
|
|
- private String FACEPP_KEY;
|
|
|
- @Value("${app.em.facepp.secret}")
|
|
|
- private String FACEPP_SECRET;
|
|
|
-
|
|
|
- private static final String JPG = ".jpg";
|
|
|
+// @Value("${app.em.photo.path}")
|
|
|
+// private String PHOTO_PATH ;
|
|
|
+// @Value("${app.em.facepp.key}")
|
|
|
+// private String FACEPP_KEY;
|
|
|
+// @Value("${app.em.facepp.secret}")
|
|
|
+// private String FACEPP_SECRET;
|
|
|
|
|
|
/**
|
|
|
* 获取所有考试学生(分页)
|
|
@@ -170,6 +152,7 @@ public class ExamStudentService {
|
|
|
examStudents.removeAll(examStudents);
|
|
|
return excelErrors;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 考生导入验证
|
|
|
* @param stu
|
|
@@ -179,67 +162,6 @@ public class ExamStudentService {
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 导入照片
|
|
|
- * @param examId
|
|
|
- * @param photoFile
|
|
|
- * @throws IOException
|
|
|
- */
|
|
|
- public List<ErrorMsg> importPhoto(Long examId, InputStream inputStream) throws IOException {
|
|
|
- List<ErrorMsg> errorMsgs = new ArrayList<ErrorMsg>();
|
|
|
- Exam exam = examRepo.findOne(examId);
|
|
|
- ZipInputStream zin = new ZipInputStream(inputStream);
|
|
|
- ZipEntry ze;
|
|
|
- try {
|
|
|
- while ((ze = zin.getNextEntry()) != null) {
|
|
|
- if (ze.isDirectory()) {
|
|
|
-
|
|
|
- } else {
|
|
|
- if(!ze.getName().endsWith(JPG)){
|
|
|
- errorMsgs.add(new ErrorMsg(ze.getName()+"格式错误,文件名格式必须是jpg(小写)"));
|
|
|
- }
|
|
|
- if(ze.getSize()>300000){
|
|
|
- errorMsgs.add(new ErrorMsg(ze.getName()+"大于300KB,请处理后重新上传"));
|
|
|
- }
|
|
|
- String savePath = PHOTO_PATH + File.separator + exam.getOrgId() + File.separator + "photo";
|
|
|
- uploadPhoto(savePath, zin, ze);
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- errorMsgs.add(new ErrorMsg("压缩文件中有中文名称文件或文件夹,请修改后重新上传"));
|
|
|
- }finally{
|
|
|
- zin.closeEntry();
|
|
|
- }
|
|
|
- return errorMsgs;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 考生照片上传照片到服务器
|
|
|
- */
|
|
|
- public void uploadPhoto(String filePath,ZipInputStream zin,ZipEntry ze){
|
|
|
- try {
|
|
|
- File out = new File(filePath);
|
|
|
- if (!out.exists()) {
|
|
|
- out.mkdirs();
|
|
|
- }
|
|
|
- File outFile = new File(filePath + File.separator + ze.getName());
|
|
|
- if (!outFile.exists()) {
|
|
|
- outFile.createNewFile();
|
|
|
- }
|
|
|
- OutputStream output = new FileOutputStream(outFile);
|
|
|
- int temp = 0;
|
|
|
- while ((temp = zin.read()) != -1) {
|
|
|
- output.write(temp);
|
|
|
- }
|
|
|
- output.close();
|
|
|
- } catch (FileNotFoundException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 照片检验
|
|
@@ -251,41 +173,13 @@ public class ExamStudentService {
|
|
|
List<ExamStudent> examStudents = examStudentRepo.findByExamId(examId);
|
|
|
for (ExamStudent examStudent : examStudents) {
|
|
|
ErrorMsg errorMsg = null;
|
|
|
- if(!StringUtils.isEmpty(examStudent.getIdentityNumber())){
|
|
|
- errorMsg = checkExamStudent(examStudent.getOrgId(),examStudent.getIdentityNumber());
|
|
|
- msgs.add(errorMsg);
|
|
|
+ if(!StringUtils.isEmpty(examStudent.getStudentCode())){
|
|
|
+
|
|
|
+ }else if(!StringUtils.isEmpty(examStudent.getIdentityNumber())){
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
return msgs;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 身份证号检查
|
|
|
- * @param orgId
|
|
|
- * @param identityNumber
|
|
|
- * @return
|
|
|
- */
|
|
|
- private ErrorMsg checkExamStudent(Long orgId,String identityNumber) {
|
|
|
- ErrorMsg error = null;
|
|
|
- String filePath = PHOTO_PATH + File.separator + orgId + File.separator+"photo"+ File.separator;
|
|
|
- HttpRequests httpRequests = new HttpRequests(FACEPP_KEY, FACEPP_SECRET);
|
|
|
- try {
|
|
|
- JSONObject face = httpRequests.detectionDetect(new PostParameters()
|
|
|
- .setImg(new File(filePath + identityNumber + JPG)));
|
|
|
- JSONArray faceArray = face.getJSONArray("face");
|
|
|
- if (faceArray.length() > 0) {
|
|
|
- //人脸识别成功
|
|
|
- studentService.updatePhoto(identityNumber);
|
|
|
- } else {
|
|
|
- error = new ErrorMsg(identityNumber + JPG + "不能被识别人脸,请换一张清晰的照片重新上传!");
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- error = new ErrorMsg("人脸识别服务器错误,请联系技术人员!");
|
|
|
- }
|
|
|
- return error;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|