xiatian před 2 roky
rodič
revize
5f6808f183

+ 1 - 1
src/main/java/cn/com/qmth/mps/controller/PaperController.java

@@ -62,7 +62,7 @@ public class PaperController extends BaseController {
 	@PostMapping("import-struct-subject")
 	@ApiOperation(value = "导入主观题试卷结构")
 	public ImportMsg importSubjectStruct(@RequestParam Long examId, @RequestParam MultipartFile file) {
-		List<String> failRecords = paperService.importPaper(examId, getAccessUser(), file);
+		List<String> failRecords = paperService.importSubjectStruct(examId, getAccessUser(), file);
 		ImportMsg msg = new ImportMsg();
 		msg.setHasError(CollectionUtils.isNotEmpty(failRecords));
 		msg.setErrMsg(failRecords);

+ 2 - 0
src/main/java/cn/com/qmth/mps/service/PaperService.java

@@ -28,4 +28,6 @@ public interface PaperService  extends IService<PaperEntity> {
 
 	PaperInfoVo info(Long id, User accessUser);
 
+	List<String> importSubjectStruct(Long examId, User accessUser, MultipartFile file);
+
 }

+ 91 - 0
src/main/java/cn/com/qmth/mps/service/impl/PaperServiceImpl.java

@@ -238,6 +238,97 @@ public class PaperServiceImpl extends ServiceImpl<PaperDao, PaperEntity> impleme
 		return vo;
 	}
 
+	@Transactional
+	@Override
+	public List<String> importSubjectStruct(Long examId, User user, MultipartFile file) {
+		ExamEntity exam=examService.getById(examId);
+		if(exam==null) {
+			throw new StatusException("未找到考试批次");
+		}
+		if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(exam.getSchoolId())) {
+			throw new StatusException("没有权限");
+		}
+		InputStream inputStream = null;
+		try {
+			inputStream=file.getInputStream();
+			List<DataMap> lineList = ExcelReader.create(ExcelType.XLSX, inputStream, 0).getDataMapList();
+			if (CollectionUtils.isEmpty(lineList)) {
+				throw new StatusException("Excel无内容");
+			}
+			if (1001 < lineList.size()) {
+				throw new StatusException("数据行数不能超过1000");
+			}
+			List<String> failRecords = new ArrayList<>();
+			List<PaperEntity> ret = new ArrayList<>();
+			for (int i = 0; i < lineList.size(); i++) {
+				DataMap line = lineList.get(i);
+
+				StringBuilder msg = new StringBuilder();
+
+				PaperEntity imp = new PaperEntity();
+				imp.setTotalScore(0.0);
+				imp.setObjectiveScore(0.0);
+				imp.setSubjectiveScore(0.0);
+				imp.setSchoolId(exam.getSchoolId());
+				imp.setGroupFinish(false);
+				imp.setExamId(examId);
+				String code = trimAndNullIfBlank(line.getValue(0));
+				if (StringUtils.isBlank(code)) {
+					msg.append("  科目代码不能为空");
+				} else if (code.length() > 20) {
+					msg.append("  科目代码不能超过20个字符");
+				}
+
+				String name = trimAndNullIfBlank(line.getValue(1));
+				if (StringUtils.isBlank(name)) {
+					msg.append("  科目名称不能为空");
+				} else if (name.length() > 20) {
+					msg.append("  科目名称不能超过20个字符");
+				}
+				if (msg.length() == 0) {
+					CourseEntity course=courseService.saveOrGet(exam.getSchoolId(), code, name);
+					imp.setCourseId(course.getId());
+				}
+
+				if (msg.length() > 0) {
+					failRecords.add(newError(i + 1, msg.toString()));
+				} else {
+					ret.add(imp);
+				}
+
+			}
+			if (CollectionUtils.isNotEmpty(failRecords)) {
+				return failRecords;
+			}
+			for (int i = 0; i < ret.size(); i++) {
+				PaperEntity cur = ret.get(i);
+				try {
+					this.save(cur);
+				} catch (DuplicateKeyException e) {
+					failRecords.add(newError(i + 1, "科目已存在"));
+				} catch (Exception e) {
+					failRecords.add(newError(i + 1, "系统异常"));
+					log.error("科目导入系统异常", e);
+				}
+			}
+			if (CollectionUtils.isNotEmpty(failRecords)) {
+				TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+			}
+			return failRecords;
+		} catch (StatusException e) {
+			throw e;
+		} catch (Exception e) {
+			throw new StatusException("系统错误",e);
+		} finally {
+			if(inputStream!=null) {
+				try {
+					inputStream.close();
+				} catch (IOException e) {
+				}
+			}
+		}
+	}
+
 
 
 }

+ 64 - 0
src/main/java/cn/com/qmth/mps/vo/paper/PaperStructInfoVo.java

@@ -0,0 +1,64 @@
+package cn.com.qmth.mps.vo.paper;
+
+import io.swagger.annotations.ApiModelProperty;
+
+public class PaperStructInfoVo {
+	@ApiModelProperty("科目代码")
+	private String courseCode;
+	@ApiModelProperty("科目名称")
+    private String courseName;
+	@ApiModelProperty("大题名称")
+	private String detailName;
+	@ApiModelProperty("大题号")
+	private Integer detailNumber;
+	@ApiModelProperty("小题号")
+	private Integer deatailUnitNumber;
+	@ApiModelProperty("小题满分")
+	private Double score;
+	@ApiModelProperty("给分间隔")
+	private Double scoreStep;
+	public String getCourseCode() {
+		return courseCode;
+	}
+	public void setCourseCode(String courseCode) {
+		this.courseCode = courseCode;
+	}
+	public String getCourseName() {
+		return courseName;
+	}
+	public void setCourseName(String courseName) {
+		this.courseName = courseName;
+	}
+	public String getDetailName() {
+		return detailName;
+	}
+	public void setDetailName(String detailName) {
+		this.detailName = detailName;
+	}
+	public Integer getDetailNumber() {
+		return detailNumber;
+	}
+	public void setDetailNumber(Integer detailNumber) {
+		this.detailNumber = detailNumber;
+	}
+	public Integer getDeatailUnitNumber() {
+		return deatailUnitNumber;
+	}
+	public void setDeatailUnitNumber(Integer deatailUnitNumber) {
+		this.deatailUnitNumber = deatailUnitNumber;
+	}
+	public Double getScore() {
+		return score;
+	}
+	public void setScore(Double score) {
+		this.score = score;
+	}
+	public Double getScoreStep() {
+		return scoreStep;
+	}
+	public void setScoreStep(Double scoreStep) {
+		this.scoreStep = scoreStep;
+	}
+	
+	
+}

+ 4 - 3
src/main/resources/application-test.properties

@@ -28,9 +28,10 @@ spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
 spring.jackson.time-zone=GMT+8
 
 session-timeout=7200
-wxapp-url=xxx
-wxapp-appid=xxx
-wxapp-secret=xxxx
+
+wxapp-url=wxapp5.qmth.com.cn
+wxapp-appid=wx3564271a274bd400
+wxapp-secret=0bcbea00b9283890f3b6b0a672d5cda5
 
 markingcloud.server=http://192.168.10.224:8080
 qmth.solar.host=https://solar.qmth.com.cn

+ 3 - 3
src/main/resources/application.properties

@@ -29,9 +29,9 @@ spring.jackson.time-zone=GMT+8
 
 session-timeout=7200
 
-wxapp-url=xxx
-wxapp-appid=wx10dd4d0b8b83cc1f
-wxapp-secret=e2cddb7ac0962f6b92ea860aeaeb4b77
+wxapp-url=wxapp5.qmth.com.cn
+wxapp-appid=wx3564271a274bd400
+wxapp-secret=0bcbea00b9283890f3b6b0a672d5cda5
 markingcloud.server=http://192.168.10.224:8080
 qmth.solar.host=https://solar.qmth.com.cn
 qmth.solar.org.uri=/api/open/org/query