xiatian 10 miesięcy temu
rodzic
commit
0b35e5c423

+ 7 - 4
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/exam/service/impl/ExamSubjectServiceImpl.java

@@ -19,6 +19,7 @@ import org.springframework.data.domain.Page;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
 import org.springframework.util.CollectionUtils;
 
 import cn.com.qmth.stmms.biz.common.BaseQueryService;
@@ -369,7 +370,7 @@ public class ExamSubjectServiceImpl extends BaseQueryService<ExamSubject> implem
 	    		}
     		}
     		if(line.length()>0) {
-    			err.append("第"+(index+2)+"行 "+line);
+    			err.append(" 第"+(index+2)+"行 "+line);
     		}
     	}
     	if(err.length()>0) {
@@ -379,8 +380,10 @@ public class ExamSubjectServiceImpl extends BaseQueryService<ExamSubject> implem
 			disposeSplit(schoolId, examId, list);
 		} catch (StatusException e) {
 			err.append(e.getDesc());
+			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
 		} catch (Exception e) {
 			err.append("导入出错:"+e.getMessage());
+			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
 		}
 		return err.toString();
 	}
@@ -392,7 +395,7 @@ public class ExamSubjectServiceImpl extends BaseQueryService<ExamSubject> implem
     		index++;
     		long groupCount=markGroupService.countByExamAndSubject(examId, vo.getStudent().getSubjectCode());
     		if(groupCount>0) {
-    			throw new StatusException("第"+(index+2)+"行 科目"+vo.getStudent().getSubjectCode()+"有分组,请先删除分组再执行");
+    			throw new StatusException(" 第"+(index+2)+"行 科目"+vo.getStudent().getSubjectCode()+"有分组,请先删除分组再执行");
     		}
     		validSubjects.add(vo.getStudent().getSubjectCode());
     		if(!validSubjects.contains(vo.getSubjectCode())) {
@@ -404,7 +407,7 @@ public class ExamSubjectServiceImpl extends BaseQueryService<ExamSubject> implem
     				es.setCode(vo.getSubjectCode());
     				es.setObjectiveScore(0.0);
     				es.setSubjectiveScore(0.0);
-    				es.setObjectiveScore(0.0);
+    				es.setTotalScore(0.0);
     				es.setUploadCount(0);
     				es.setDisplayQuestionName(true);
     				es.setInspectRound(1);
@@ -413,7 +416,7 @@ public class ExamSubjectServiceImpl extends BaseQueryService<ExamSubject> implem
     			}else {
     				long count=markGroupService.countByExamAndSubject(examId, vo.getSubjectCode());
     	    		if(count>0) {
-    	    			throw new StatusException("第"+(index+2)+"行 科目"+vo.getSubjectCode()+"有分组,请先删除分组再执行");
+    	    			throw new StatusException(" 第"+(index+2)+"行 科目"+vo.getSubjectCode()+"有分组,请先删除分组再执行");
     	    		}
     			}
     			validSubjects.add(vo.getSubjectCode());

+ 8 - 6
stmms-web/src/main/java/cn/com/qmth/stmms/admin/exam/SubjectController.java

@@ -8,6 +8,8 @@ import javax.servlet.http.HttpServletResponse;
 
 import org.apache.commons.lang.StringEscapeUtils;
 import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
@@ -21,7 +23,6 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
 import cn.com.qmth.stmms.biz.exam.bean.SubjectSplit;
 import cn.com.qmth.stmms.biz.exam.model.Exam;
 import cn.com.qmth.stmms.biz.exam.model.ExamSubject;
-import cn.com.qmth.stmms.biz.exam.model.SubjectUser;
 import cn.com.qmth.stmms.biz.exam.service.ExamService;
 import cn.com.qmth.stmms.biz.exam.service.ExamSubjectService;
 import cn.com.qmth.stmms.biz.exam.service.query.ExamSubjectSearchQuery;
@@ -41,7 +42,7 @@ import net.sf.json.JsonConfig;
 @Controller
 @RequestMapping("/admin/exam/subject")
 public class SubjectController extends BaseExamController {
-
+    private static Logger log = LoggerFactory.getLogger(SubjectController.class);
 	@Autowired
 	private ExamSubjectService subjectService;
 
@@ -146,18 +147,19 @@ public class SubjectController extends BaseExamController {
 			School s = schoolService.findById(schoolId);
 			ImportExcel ei= new ImportExcel(file, 1, 0);
 			List<SubjectSplit> list = ei.getDataList(SubjectSplit.class);
-			String errMsg=subjectService.split(schoolId,examId,list);
 			model.addAttribute("examId", examId);
 			model.addAttribute("schoolId", schoolId);
 			model.addAttribute("schoolName", s.getName());
 			List<Exam> examList = examService.findBySchoolId(schoolId);
 			model.addAttribute("examList", examList);
+			String errMsg=subjectService.split(schoolId,examId,list);
 			if(StringUtils.isBlank(errMsg)) {
 				model.addAttribute("message", "已成功导入");
 			}else {
 				model.addAttribute("errmsg", errMsg);
 			}
 		}catch (Exception e) {
+			log.error("导入失败",e);
 			model.addAttribute("errmsg", "导入失败:"+e.getMessage());
 		}
 		return "modules/exam/subjectSplit";
@@ -166,9 +168,9 @@ public class SubjectController extends BaseExamController {
 	@RequestMapping(value = "split/template")
 	public String splitTemplate(HttpServletResponse response, RedirectAttributes redirectAttributes) {
 		try {
-			List<SubjectUser> list = new ArrayList<SubjectUser>();
-			list.add(new SubjectUser());
-			new ExportExcel("科目拆分数据", SubjectUser.class, 2).setDataList(list).write(response, "科目拆分导入模板.xlsx")
+			List<SubjectSplit> list = new ArrayList<>();
+			list.add(new SubjectSplit());
+			new ExportExcel("科目拆分数据", SubjectSplit.class, 2).setDataList(list).write(response, "科目拆分导入模板.xlsx")
 					.dispose();
 			return null;
 		} catch (Exception e) {

+ 1 - 1
stmms-web/src/main/webapp/WEB-INF/views/modules/exam/subjectSplit.jsp

@@ -27,7 +27,7 @@
     </script>
 </head>
 <body>
-<form:form id="inputForm" action="${ctx}/admin/exam/subject/split/save" method="post" class="form-horizontal">
+<form:form id="inputForm" action="${ctx}/admin/exam/subject/split/save" method="post" class="form-horizontal" enctype="multipart/form-data">
     <tags:message content="${message}"/>
     <tags:message content="${errmsg}" type="error" />
     <input type="hidden" id="schoolId" name="schoolId" value="${schoolId}" />