wangwei 7 năm trước cách đây
mục cha
commit
c495d7c43d

+ 8 - 2
examcloud-core-examwork-api-provider/src/main/java/cn/com/qmth/examcloud/core/examwork/api/controller/ExamStudentController.java

@@ -67,7 +67,6 @@ import io.swagger.annotations.ApiOperation;
 /**
  * 考生服务API Created by songyue on 17/1/13.
  */
-@Transactional
 @RestController
 @RequestMapping("${$rmp.ctr.examwork}/exam_student")
 public class ExamStudentController extends ControllerSupport {
@@ -272,6 +271,7 @@ public class ExamStudentController extends ControllerSupport {
 	 * @param examStudent
 	 * @return
 	 */
+	@Transactional
 	@ApiOperation(value = "新增考试学生", notes = "新增")
 	@PostMapping()
 	public ExamStudentDomain addExamStudent(HttpServletRequest request,
@@ -289,6 +289,7 @@ public class ExamStudentController extends ControllerSupport {
 	 * @param examStudent
 	 * @return
 	 */
+	@Transactional
 	@ApiOperation(value = "更新考试学生", notes = "更新")
 	@PutMapping()
 	public ExamStudentDomain updateExamStudent(@RequestBody ExamStudentDomain examStudent) {
@@ -353,6 +354,7 @@ public class ExamStudentController extends ControllerSupport {
 	}
 
 	@ApiOperation(value = "更新考试学生缺考状态", notes = "更新缺考")
+	@Transactional
 	@PutMapping("/{id}")
 	public ResponseEntity<ExamStudent> getExamStudentById(@PathVariable Long id,
 			@RequestParam boolean finished) {
@@ -373,6 +375,7 @@ public class ExamStudentController extends ControllerSupport {
 	 * @param ids
 	 * @return
 	 */
+	@Transactional
 	@ApiOperation(value = "按ID删除考试学生", notes = "删除")
 	@DeleteMapping("/{ids}")
 	public List<Long> deleteExamStudent(@PathVariable String ids) {
@@ -390,6 +393,7 @@ public class ExamStudentController extends ControllerSupport {
 	 * @return
 	 */
 	@ApiOperation(value = "按考试删除考试学生", notes = "按考试删除")
+	@Transactional
 	@DeleteMapping("/exam/{examId}")
 	public Long deleteExamStudents(@PathVariable Long examId) {
 		examStudentService.deleteExamStudents(examId);
@@ -412,7 +416,7 @@ public class ExamStudentController extends ControllerSupport {
 
 		DiskFileItem item = (DiskFileItem) file.getFileItem();
 		examStudentImportService.importExamStudent(item.getStoreLocation(),
-				file.getOriginalFilename());
+				file.getOriginalFilename(), getRootOrgId(), examId);
 		return null;
 	}
 
@@ -448,6 +452,7 @@ public class ExamStudentController extends ControllerSupport {
 	}
 
 	@ApiOperation(value = "复制考试学生", notes = "复制")
+	@Transactional
 	@PostMapping("/copy/{sourceExamId}/{targetExamId}")
 	public ResponseEntity copyExamStudent(@PathVariable Long sourceExamId,
 			@PathVariable Long targetExamId) {
@@ -547,6 +552,7 @@ public class ExamStudentController extends ControllerSupport {
 	}
 
 	@ApiOperation(value = "设置考生为重考状态", notes = "设置考生为重考状态")
+	@Transactional
 	@PostMapping("/setExamStudentReexamine")
 	public ResponseEntity<Object> setExamStudentIsReexamine(
 			@RequestBody CommonExamStudent commonExamStudent) {

+ 19 - 0
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/ExamStudentTempRepo.java

@@ -1,15 +1,34 @@
 package cn.com.qmth.examcloud.core.examwork.dao;
 
+import java.util.List;
+
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.jpa.repository.query.Procedure;
+import org.springframework.data.repository.query.Param;
 import org.springframework.data.repository.query.QueryByExampleExecutor;
 
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamStudentTempEntity;
 
+/**
+ * 类注释
+ *
+ * @author WANGWEI
+ * @date 2018年7月16日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
 public interface ExamStudentTempRepo
 		extends
 			JpaRepository<ExamStudentTempEntity, Long>,
 			QueryByExampleExecutor<ExamStudentTempEntity>,
 			JpaSpecificationExecutor<ExamStudentTempEntity> {
 
+	@Procedure(name = "import_exam_students")
+	void processExamStudentTemp(@Param("batch_id") Long batchId);
+
+	@Query("select s from ExamStudentTempEntity s where s.name is not null and s.orgId is not null "
+			+ "and s.identityNumber is not null and s.courseId is not null and s.batchId=?1")
+	List<ExamStudentTempEntity> findRight(Long batchId);
+
 }

+ 27 - 0
examcloud-core-examwork-dao/src/main/java/cn/com/qmth/examcloud/core/examwork/dao/entity/ExamStudentTempEntity.java

@@ -3,6 +3,9 @@ package cn.com.qmth.examcloud.core.examwork.dao.entity;
 import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
 import javax.persistence.Id;
+import javax.persistence.NamedStoredProcedureQueries;
+import javax.persistence.NamedStoredProcedureQuery;
+import javax.persistence.StoredProcedureParameter;
 import javax.persistence.Table;
 
 import cn.com.qmth.examcloud.commons.web.jpa.JpaEntity;
@@ -16,6 +19,9 @@ import cn.com.qmth.examcloud.commons.web.jpa.JpaEntity;
  */
 @Entity
 @Table(name = "EC_E_EXAM_STUDENT_TMP")
+@NamedStoredProcedureQueries({
+		@NamedStoredProcedureQuery(name = "import_exam_students", procedureName = "import_exam_students", parameters = {
+				@StoredProcedureParameter(name = "batch_id", type = Long.class)})})
 public class ExamStudentTempEntity extends JpaEntity {
 
 	private static final long serialVersionUID = -6030503185547639031L;
@@ -66,6 +72,11 @@ public class ExamStudentTempEntity extends JpaEntity {
 	 */
 	private String identityNumber;
 
+	/**
+	 * 课程ID
+	 */
+	private String courseId;
+
 	/**
 	 * 课程code
 	 */
@@ -121,6 +132,14 @@ public class ExamStudentTempEntity extends JpaEntity {
 	 */
 	private String phone;
 
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
 	public Long getBatchId() {
 		return batchId;
 	}
@@ -193,6 +212,14 @@ public class ExamStudentTempEntity extends JpaEntity {
 		this.identityNumber = identityNumber;
 	}
 
+	public String getCourseId() {
+		return courseId;
+	}
+
+	public void setCourseId(String courseId) {
+		this.courseId = courseId;
+	}
+
 	public String getCourseCode() {
 		return courseCode;
 	}

+ 6 - 0
examcloud-core-examwork-service/pom.xml

@@ -32,6 +32,12 @@
 			<version>${examcloud.version}</version>
 		</dependency>
 
+		<dependency>
+			<groupId>cn.com.qmth.examcloud.core.examwork</groupId>
+			<artifactId>examcloud-core-examwork-api</artifactId>
+			<version>${examcloud.version}</version>
+		</dependency>
+
 	</dependencies>
 
 </project>

+ 2 - 2
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/ExamStudentImportService.java

@@ -10,7 +10,7 @@ import java.io.File;
  * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
  */
 public interface ExamStudentImportService {
-	
-	void importExamStudent(File file,String fileName);
+
+	void importExamStudent(File file, String fileName, Long rootOrgId, Long examId);
 
 }

+ 82 - 5
examcloud-core-examwork-service/src/main/java/cn/com/qmth/examcloud/core/examwork/service/impl/ExamStudentImportServiceImpl.java

@@ -8,14 +8,24 @@ import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import com.google.common.collect.Lists;
 
 import cn.com.qmth.examcloud.commons.base.exception.StatusException;
 import cn.com.qmth.examcloud.commons.base.helpers.poi.ExcelParser;
+import cn.com.qmth.examcloud.commons.base.logging.ExamCloudLog;
+import cn.com.qmth.examcloud.commons.base.logging.ExamCloudLogFactory;
+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.core.examwork.dao.ExamStudentTempRepo;
 import cn.com.qmth.examcloud.core.examwork.dao.entity.ExamStudentTempEntity;
 import cn.com.qmth.examcloud.core.examwork.service.ExamStudentImportService;
+import cn.com.qmth.examcloud.examwork.api.ExamStudentCloudService;
+import cn.com.qmth.examcloud.examwork.api.bean.ExamStudentBean;
+import cn.com.qmth.examcloud.examwork.api.request.SaveExamStudentReq;
+import cn.com.qmth.examcloud.examwork.api.response.SaveExamStudentResp;
 
 /**
  * 类注释
@@ -27,14 +37,22 @@ import cn.com.qmth.examcloud.core.examwork.service.ExamStudentImportService;
 @Service
 public class ExamStudentImportServiceImpl implements ExamStudentImportService {
 
+	protected ExamCloudLog log = ExamCloudLogFactory.getLog(this.getClass());
+
 	private static final String[] EXCEL_HEADER = new String[]{"姓名", "学号", "身份证号", "学习中心代码",
 			"学习中心名称", "课程代码", "课程名称", "试卷类型", "专业", "考点", "信息采集人", "学生电话", "年级"};
 
 	@Autowired
-	ExamStudentTempRepo ExamStudentTempRepo;
+	ExamStudentTempRepo examStudentTempRepo;
+
+	@Autowired
+	StudentCloudService studentCloudService;
+
+	@Autowired
+	ExamStudentCloudService examStudentCloudService;
 
 	@Override
-	public void importExamStudent(File file, String fileName) {
+	public void importExamStudent(File file, String fileName, Long rootOrgId, Long examId) {
 		Workbook workBook = ExcelParser.getWorkBook(file, fileName);
 
 		Sheet sheet = workBook.getSheetAt(0);
@@ -43,16 +61,19 @@ public class ExamStudentImportServiceImpl implements ExamStudentImportService {
 		ExcelParser.close(workBook);
 
 		List<ExamStudentTempEntity> list = Lists.newArrayList();
-		long currentTimeMillis = System.currentTimeMillis();
+		long batchId = System.currentTimeMillis();
 
 		for (int i = 0; i < lineList.size(); i++) {
 			String[] line = lineList.get(i);
 			if (0 == i) {
 				checkExcelHeader(line);
+				continue;
 			}
 
 			ExamStudentTempEntity es = new ExamStudentTempEntity();
-			es.setBatchId(currentTimeMillis);
+			es.setRootOrgId(rootOrgId);
+			es.setExamId(examId);
+			es.setBatchId(batchId);
 			es.setName(trimAndNullIfBlank(line[0]));
 			es.setStudentCode(trimAndNullIfBlank(line[1]));
 			es.setIdentityNumber(trimAndNullIfBlank(line[2]));
@@ -68,10 +89,66 @@ public class ExamStudentImportServiceImpl implements ExamStudentImportService {
 			es.setGrade(trimAndNullIfBlank(line[12]));
 
 			list.add(es);
+			if (0 == i % 100) {
+				examStudentTempRepo.save(list);
+
+				list = Lists.newArrayList();
+			}
 		}
 
-		ExamStudentTempRepo.save(list);
+		examStudentTempRepo.save(list);
+
+		examStudentTempRepo.processExamStudentTemp(batchId);
+
+		saveExamStudents(batchId);
+	}
+
+	private void saveExamStudents(Long batchId) {
+		List<ExamStudentTempEntity> list = examStudentTempRepo.findRight(batchId);
+
+		for (ExamStudentTempEntity examStudent : list) {
+
+			saveExamStudent(examStudent);
+		}
+	}
 
+	@Transactional
+	private void saveExamStudent(ExamStudentTempEntity examStudent) {
+		InsertOrUpdateStudentReq saveStudentReq = new InsertOrUpdateStudentReq();
+		saveStudentReq.setIdentityNumber(examStudent.getIdentityNumber());
+		saveStudentReq.setName(examStudent.getName());
+		saveStudentReq.setPhoneNumber(examStudent.getPhone());
+		saveStudentReq.setOrgCode(examStudent.getOrgCode());
+		saveStudentReq.setOrgId(examStudent.getOrgId());
+		saveStudentReq.setOrgName(examStudent.getOrgName());
+		saveStudentReq.setRootOrgId(examStudent.getRootOrgId());
+		saveStudentReq.setStudentCode(examStudent.getStudentCode());
+
+		InsertOrUpdateStudentResp insertOrUpdateStudentResp = studentCloudService
+				.insertOrUpdateStudent(saveStudentReq);
+
+		Long studentId = insertOrUpdateStudentResp.getStudentId();
+
+		SaveExamStudentReq saveExamStudentReq = new SaveExamStudentReq();
+		saveExamStudentReq.setCourseCode(examStudent.getCourseCode());
+		saveExamStudentReq.setCourseLevel(examStudent.getCourseLevel());
+		saveExamStudentReq.setCourseName(examStudent.getCourseName());
+		saveExamStudentReq.setExamId(examStudent.getExamId());
+		saveExamStudentReq.setIdentityNumber(examStudent.getIdentityNumber());
+		saveExamStudentReq.setPaperType(examStudent.getPaperType());
+		saveExamStudentReq.setRootOrgId(examStudent.getRootOrgId());
+		saveExamStudentReq.setStudentCode(examStudent.getStudentCode());
+		saveExamStudentReq.setStudentName(examStudent.getName());
+		saveExamStudentReq.setStudentId(studentId);
+		saveExamStudentReq.setInfoCollector(examStudent.getInfoCollector());
+		saveExamStudentReq.setGrade(examStudent.getGrade());
+		saveExamStudentReq.setExamSite(examStudent.getExamSite());
+		saveExamStudentReq.setSpecialtyName(examStudent.getSpecialtyName());
+
+		SaveExamStudentResp saveExamStudentResp = examStudentCloudService
+				.saveExamStudent(saveExamStudentReq);
+		ExamStudentBean examStudentBean = saveExamStudentResp.getExamStudentBean();
+		log.debug("examStudentId=" + examStudentBean.getId());
 	}
 
 	/**