Преглед на файлове

Merge remote-tracking branch 'origin/dev' into dev

wangliang преди 4 години
родител
ревизия
faa4dc2241

+ 2 - 0
themis-business/src/main/java/com/qmth/themis/business/dao/TEExamPaperMapper.java

@@ -23,4 +23,6 @@ public interface TEExamPaperMapper extends BaseMapper<TEExamPaper> {
 
 	public List<TEExamPaper> findListByExamIdAndCourseCode(@Param("examId") Long examId,
 			@Param("courseCode") String courseCode);
+
+	public void updateWeight(@Param("id") Long id, @Param("weight") Double weight);
 }

+ 2 - 0
themis-business/src/main/java/com/qmth/themis/business/service/TEExamPaperService.java

@@ -24,5 +24,7 @@ public interface TEExamPaperService extends IService<TEExamPaper> {
 	ExamPaperCacheBean getExamPaperCacheBean(Long paperId);
 
 	Map<String, ObjectiveAnswerCacheBean> getObjectiveAnswerCacheBean(Long paperId);
+	
+	void  savePaperWeight(Map<Long,Double> map);
 
 }

+ 9 - 0
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamPaperServiceImpl.java

@@ -11,6 +11,7 @@ import javax.annotation.Resource;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -188,4 +189,12 @@ public class TEExamPaperServiceImpl extends ServiceImpl<TEExamPaperMapper, TEExa
 	public List<TEExamPaper> findByExamIdAndCourseCode(Long examId, String courseCode) {
 		return teExamPaperMapper.findListByExamIdAndCourseCode(examId, courseCode);
 	}
+
+	@Transactional
+	@Override
+	public void savePaperWeight(Map<Long, Double> map) {
+		for(Long id:map.keySet()) {
+			teExamPaperMapper.updateWeight(id, map.get(id));
+		}
+	}
 }

+ 22 - 1
themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskExamPaperImportTemplete.java

@@ -3,9 +3,11 @@ package com.qmth.themis.business.templete.impl;
 import java.io.File;
 import java.io.FilenameFilter;
 import java.io.IOException;
+import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -155,8 +157,27 @@ public class TaskExamPaperImportTemplete implements TaskImportTemplete {
         course.setPaperCount(list.size());
         course.setHasAnswer(hasAnswer);
         teExamCourseService.saveOrUpdate(course);
+        //设置调卷比例
+        teExamPaperService.savePaperWeight(paperWeight(list));
     }
-
+    
+    private Map<Long,Double> paperWeight(List<TEExamPaper> list){
+    	BigDecimal b1 = new BigDecimal(1.0);//基数总数
+    	BigDecimal b2 = new BigDecimal(list.size());//份数
+    	BigDecimal b3=b1.divide(b2,2, BigDecimal.ROUND_FLOOR );//平均数
+    	BigDecimal b4=b1.subtract(b3.multiply(b2).setScale(2, BigDecimal.ROUND_FLOOR ));//余数
+    	Map<Long,Double> map=new HashMap<Long,Double>();
+    	for(int i=0;i<list.size();i++) {
+    		TEExamPaper p=list.get(i);
+    		if(i==list.size()-1) {
+    			map.put(p.getId(), b3.add(b4).doubleValue());
+    		}else {
+    			map.put(p.getId(), b3.doubleValue());
+    		}
+    	}
+    	return map;
+    }
+    
     private void disposePaperDir(String rootDir, TEExam teExam, TEExamCourse course, File paperDir,
                                  Map<String, Object> map) {
         String paperCode = paperDir.getName();

+ 4 - 0
themis-business/src/main/resources/mapper/TEExamPaperMapper.xml

@@ -17,4 +17,8 @@
 		t.course_code=#{courseCode}
 	</select>
 	
+	<update id="updateWeight">
+		update t_e_exam_paper t set t.weight=#{weight} where t.id=#{id}
+	</update>
+	
 </mapper>