xiatian 1 жил өмнө
parent
commit
3c46f1e9ff

+ 0 - 1
db/am_db.sql

@@ -24,7 +24,6 @@ CREATE TABLE `am_student` (
   `exam_id` bigint NOT NULL,
   `student_code` varchar(255) COLLATE utf8mb4_bin NOT NULL,
   `subject_code` varchar(255) COLLATE utf8mb4_bin NOT NULL,
-  `subject_name` varchar(255) COLLATE utf8mb4_bin NOT NULL,
   PRIMARY KEY (`id`),
   UNIQUE KEY `IDX_STUDENT_01` (`exam_id`, `subject_code`, `student_code`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

+ 8 - 0
src/main/java/cn/com/qmth/am/entity/QuestionEntity.java

@@ -17,6 +17,7 @@ public class QuestionEntity extends IdEntity {
 	private Long examId;
 
 	private String subjectCode;
+	private String subjectName;
 	private Integer mainNumber;
 	private String subNumber;
 
@@ -78,6 +79,13 @@ public class QuestionEntity extends IdEntity {
 	public void setImageSlice(List<ImageSlice> imageSlice) {
 		this.imageSlice = imageSlice;
 	}
+	public String getSubjectName() {
+		return subjectName;
+	}
+
 
+	public void setSubjectName(String subjectName) {
+		this.subjectName = subjectName;
+	}
 
 }

+ 0 - 11
src/main/java/cn/com/qmth/am/entity/StudentEntity.java

@@ -13,7 +13,6 @@ public class StudentEntity extends IdEntity {
 	private Long examId;
 
 	private String subjectCode;
-	private String subjectName;
 	private String studentCode;
 
 
@@ -60,15 +59,5 @@ public class StudentEntity extends IdEntity {
 	}
 
 
-	public String getSubjectName() {
-		return subjectName;
-	}
-
-
-	public void setSubjectName(String subjectName) {
-		this.subjectName = subjectName;
-	}
-
-
 
 }

+ 33 - 12
src/main/java/cn/com/qmth/am/service/impl/QuestionServiceImpl.java

@@ -7,9 +7,9 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.HashSet;
+import java.util.HashMap;
 import java.util.List;
-import java.util.Set;
+import java.util.Map;
 
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.io.FileUtils;
@@ -265,8 +265,7 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionDao, QuestionEntity
 			return ret;
 		}
 		try {
-			int addCount = saveQuestionBatch(ss);
-			ret.setCountInfo("新增数量:" + addCount);
+			saveQuestionBatch(ret,ss);
 		} catch (Exception e) {
 			failRecords.add("系统错误:" + e.getMessage());
 		}
@@ -294,31 +293,53 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionDao, QuestionEntity
 		}
 	}
 
-	private int saveQuestionBatch(List<QuestionEntity> ss) {
+	private void saveQuestionBatch(ImportResult ret,List<QuestionEntity> ss) {
 		if (CollectionUtils.isEmpty(ss)) {
-			return 0;
+			ret.setCountInfo("新增数量:0,更新数量:0");
+			return;
 		}
 		List<QuestionEntity> all = this.list();
-		Set<String> set = new HashSet<>();
+		Map<String,QuestionEntity> old = new HashMap<>();
+		Map<String,QuestionEntity> addMap = new HashMap<>();
 		if (CollectionUtils.isNotEmpty(all)) {
 			for (QuestionEntity s : all) {
 				String key = s.getExamId() + "-" + s.getSubjectCode() + "-" + s.getMainNumber()+"-"+s.getSubNumber();
-				set.add(key);
+				old.put(key,s);
 			}
 		}
 		List<QuestionEntity> adds = new ArrayList<>();
+		List<QuestionEntity> updates = new ArrayList<>();
 		for (QuestionEntity s : ss) {
 			String key = s.getExamId() + "-" + s.getSubjectCode() + "-" + s.getMainNumber()+"-"+s.getSubNumber();
-			if (!set.contains(key)) {
-				adds.add(s);
+			if (old.get(key)==null) {
+				QuestionEntity add=addMap.get(key);
+				if(add!=null) {
+					add.setSubjectName(s.getSubjectName());
+					add.setFullScore(s.getFullScore());
+					add.setImageSlice(s.getImageSlice());
+					add.setContent(s.getContent());
+					add.setAnswer(s.getAnswer());
+				}else {
+					addMap.put(key, s);
+					adds.add(s);
+				}
 			} else {
-				set.add(key);
+				QuestionEntity up=old.get(key);
+				up.setSubjectName(s.getSubjectName());
+				up.setFullScore(s.getFullScore());
+				up.setImageSlice(s.getImageSlice());
+				up.setContent(s.getContent());
+				up.setAnswer(s.getAnswer());
+				updates.add(up);
 			}
 		}
 		if (CollectionUtils.isNotEmpty(adds)) {
 			saveBatch(adds);
 		}
-		return adds.size();
+		if (CollectionUtils.isNotEmpty(updates)) {
+			updateBatchById(updates);
+		}
+		ret.setCountInfo("新增数量:"+adds.size()+",更新数量:"+updates.size());
 	}
 
 }

+ 7 - 15
src/main/java/cn/com/qmth/am/service/impl/StudentServiceImpl.java

@@ -32,7 +32,7 @@ import cn.com.qmth.am.service.StudentService;
 
 @Service
 public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> implements StudentService {
-	private static final String[] EXCEL_HEADER = new String[] { "考试ID", "科目代码", "科目名称", "考生编号" };
+	private static final String[] EXCEL_HEADER = new String[] { "考试ID", "科目代码","考生编号" };
 	@Autowired
 	private SysProperty sysProperty;
 	@Autowired
@@ -181,15 +181,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
 			}
 			imp.setSubjectCode(subjectCode);
 
-			String subjectName = trimAndNullIfBlank(line.get(EXCEL_HEADER[2]));
-			if (StringUtils.isBlank(subjectName)) {
-				msg.append("  科目名称不能为空");
-			} else if (subjectName.length() > 100) {
-				msg.append("  科目名称不能超过100个字符");
-			}
-			imp.setSubjectName(subjectName);
-
-			String studentCode = trimAndNullIfBlank(line.get(EXCEL_HEADER[3]));
+			String studentCode = trimAndNullIfBlank(line.get(EXCEL_HEADER[2]));
 			if (StringUtils.isBlank(studentCode)) {
 				msg.append("  考生编号不能为空");
 			} else if (studentCode.length() > 100) {
@@ -209,17 +201,17 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
 			return ret;
 		}
 		try {
-			int addCount = saveStudentBatch(ss);
-			ret.setCountInfo("新增数量:" + addCount);
+			saveStudentBatch(ret,ss);
 		} catch (Exception e) {
 			failRecords.add("系统错误:" + e.getMessage());
 		}
 		return ret;
 	}
 
-	private int saveStudentBatch(List<StudentEntity> ss) {
+	private void saveStudentBatch(ImportResult ret,List<StudentEntity> ss) {
 		if (CollectionUtils.isEmpty(ss)) {
-			return 0;
+			ret.setCountInfo("新增数量:0");
+			return;
 		}
 		List<StudentEntity> all = this.list();
 		Set<String> set = new HashSet<>();
@@ -241,7 +233,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, StudentEntity> i
 		if (CollectionUtils.isNotEmpty(adds)) {
 			saveBatch(adds);
 		}
-		return adds.size();
+		ret.setCountInfo("新增数量:"+adds.size());
 	}
 
 }