|
@@ -2,17 +2,29 @@ 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 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;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.common.util.ErrorMsg;
|
|
|
import cn.com.qmth.examcloud.common.util.excel.ExcelError;
|
|
|
import cn.com.qmth.examcloud.common.util.excel.ExcelReader;
|
|
|
import cn.com.qmth.examcloud.common.util.excel.ExcelReaderHandle;
|
|
@@ -20,6 +32,10 @@ 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;
|
|
|
|
|
|
/**
|
|
|
* 考试学生服务类
|
|
@@ -31,7 +47,18 @@ 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";
|
|
|
+
|
|
|
/**
|
|
|
* 获取所有考试学生(分页)
|
|
|
* @param examCriteria
|
|
@@ -122,7 +149,10 @@ public class ExamStudentService {
|
|
|
if (error == null) {
|
|
|
examStudents.add(dto);
|
|
|
}
|
|
|
-
|
|
|
+ if (examStudents.size() % 1000 == 0) {
|
|
|
+ examStudentRepo.save(examStudents);
|
|
|
+ examStudents.removeAll(examStudents);
|
|
|
+ }
|
|
|
return error;
|
|
|
}
|
|
|
});
|
|
@@ -136,6 +166,116 @@ public class ExamStudentService {
|
|
|
* @return
|
|
|
*/
|
|
|
public ExcelError importCheck(ExamStudent dto){
|
|
|
+
|
|
|
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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 照片检验
|
|
|
+ * @param examId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<ErrorMsg> photoCheck(Long examId) {
|
|
|
+ List<ErrorMsg> msgs = new ArrayList<ErrorMsg>();
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|