Răsfoiți Sursa

美术阅卷10月新增需求-新增一些功能

wangliang 5 ani în urmă
părinte
comite
9836743097

+ 19 - 13
stmms-ms-admin/src/main/java/cn/com/qmth/stmms/ms/admin/api/StudentApi.java

@@ -1,19 +1,18 @@
 package cn.com.qmth.stmms.ms.admin.api;
 
-import java.io.IOException;
-
 import cn.com.qmth.stmms.ms.admin.service.DataUploadService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Page;
-import org.springframework.web.bind.annotation.*;
-import org.springframework.web.multipart.MultipartFile;
-
 import cn.com.qmth.stmms.ms.commons.utils.specification.PagingAndSortingDTO;
 import cn.com.qmth.stmms.ms.core.domain.Student;
 import cn.com.qmth.stmms.ms.core.repository.PaperRepo;
 import cn.com.qmth.stmms.ms.core.repository.StudentRepo;
 import cn.com.qmth.stmms.ms.core.specification.StudentSpecification;
 import cn.com.qmth.stmms.ms.core.vo.Subject;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.IOException;
 
 /**
  * 考生数据api
@@ -33,6 +32,7 @@ public class StudentApi {
 
     /**
      * 考生列表
+     *
      * @param params
      * @return
      */
@@ -45,6 +45,7 @@ public class StudentApi {
 
     /**
      * 单个考生
+     *
      * @param domain 考生id
      * @return
      */
@@ -55,11 +56,12 @@ public class StudentApi {
 
     /**
      * 删除
+     *
      * @param domain
      */
     @RequestMapping(value = "{domain}", method = RequestMethod.DELETE)
     public void remove(@PathVariable Student domain) {
-    	Long isExist = paperRepo.countByWorkIdAndExamNumber(domain.getWorkId(), domain.getExamNumber());
+        Long isExist = paperRepo.countByWorkIdAndExamNumber(domain.getWorkId(), domain.getExamNumber());
         if (isExist > 0) {
             throw new RuntimeException("该考生已上传,无法删除");
         }
@@ -68,6 +70,7 @@ public class StudentApi {
 
     /**
      * 修改信息
+     *
      * @param domain
      * @param student
      */
@@ -85,6 +88,7 @@ public class StudentApi {
 
     /**
      * 新增
+     *
      * @param domain
      * @return
      */
@@ -95,6 +99,7 @@ public class StudentApi {
 
     /**
      * 清空所有
+     *
      * @param workId 评卷工作id
      */
     @RequestMapping(method = RequestMethod.DELETE)
@@ -104,6 +109,7 @@ public class StudentApi {
 
     /**
      * 新增
+     *
      * @param studentId
      * @param subject
      * @param isManual
@@ -112,11 +118,11 @@ public class StudentApi {
      */
     @RequestMapping(value = "{studentId}", method = RequestMethod.POST)
     public void addPaper(@PathVariable Long studentId,
-						 @RequestParam Subject subject,
-						 @RequestParam(required = false) boolean isManual,
-						 @RequestParam MultipartFile file)
-            throws IOException {
-        dataUploadService.uploadPaper(studentId, subject, file.getInputStream(),isManual);
+                         @RequestParam Subject subject,
+                         @RequestParam(required = false) boolean isManual,
+                         @RequestParam MultipartFile file)
+            throws Exception {
+        dataUploadService.uploadPaper(studentId, subject, file.getInputStream(), isManual);
     }
 
 }

+ 41 - 33
stmms-ms-admin/src/main/java/cn/com/qmth/stmms/ms/admin/api/WorkApi.java

@@ -1,20 +1,16 @@
 package cn.com.qmth.stmms.ms.admin.api;
 
-import java.util.List;
-
 import cn.com.qmth.stmms.ms.admin.assembler.WorkOverviewAssembler;
 import cn.com.qmth.stmms.ms.admin.dto.WorkOverview;
-import cn.com.qmth.stmms.ms.core.repository.*;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
-
 import cn.com.qmth.stmms.ms.admin.service.WorkService;
+import cn.com.qmth.stmms.ms.commons.utils.RandomUtil;
 import cn.com.qmth.stmms.ms.core.domain.Level;
 import cn.com.qmth.stmms.ms.core.domain.Work;
+import cn.com.qmth.stmms.ms.core.repository.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
 
 /**
  * 评卷工作api
@@ -29,13 +25,13 @@ public class WorkApi {
 
     @Autowired
     private LevelRepo levelRepo;
-    
+
     @Autowired
     private MarkUserRepo markUserRepo;
 
     @Autowired
     private ExamQuestionRepo questionRepo;
-    
+
     @Autowired
     private WorkService workService;
 
@@ -47,53 +43,61 @@ public class WorkApi {
 
     /**
      * 列表
+     *
      * @return
      */
     @RequestMapping(method = RequestMethod.GET)
-    public List<Work> list(){
+    public List<Work> list() {
         return workRepo.findAll();
     }
 
     /**
      * 单个信息
+     *
      * @param work
      * @return
      */
-    @RequestMapping(value = "{work}",method = RequestMethod.GET)
-    public Work getOne(@PathVariable Work work){
+    @RequestMapping(value = "{work}", method = RequestMethod.GET)
+    public Work getOne(@PathVariable Work work) {
+        if (work.isActive()) {
+            RandomUtil.getRandom(work.getId(), false);
+        }
         return work;
     }
 
     /**
      * 新增
+     *
      * @param work
      */
-	@RequestMapping(method = RequestMethod.POST)
-	public void create(@RequestBody Work work) {
+    @RequestMapping(method = RequestMethod.POST)
+    public void create(@RequestBody Work work) {
         workService.save(work);
-	}
+    }
 
     /**
      * 修改
+     *
      * @param workId
      * @param work
      * @return
      */
-    @RequestMapping(value = "{workId}",method = RequestMethod.PUT)
-    public Work update(@PathVariable Long workId, @RequestBody Work work){
+    @RequestMapping(value = "{workId}", method = RequestMethod.PUT)
+    public Work update(@PathVariable Long workId, @RequestBody Work work) {
         return workRepo.save(work);
     }
 
     /**
      * 激活为当前,采集和评卷用户登录影响
+     *
      * @param workId
      */
-    @RequestMapping(value = "{workId}",method = RequestMethod.PATCH)
-    public void active(@PathVariable Long workId){
+    @RequestMapping(value = "{workId}", method = RequestMethod.PATCH)
+    public void active(@PathVariable Long workId) {
         List<Work> works = workRepo.findAll();
-        for (Work w : works){
+        for (Work w : works) {
             w.setActive(false);
-            if(w.getId().equals(workId)){
+            if (w.getId().equals(workId)) {
                 w.setActive(true);
             }
         }
@@ -102,43 +106,47 @@ public class WorkApi {
 
     /**
      * 删除
+     *
      * @param workId
      */
-    @RequestMapping(value = "{workId}",method = RequestMethod.DELETE)
-    public void remove(@PathVariable Long workId){
-    	workService.delete(workId);
+    @RequestMapping(value = "{workId}", method = RequestMethod.DELETE)
+    public void remove(@PathVariable Long workId) {
+        workService.delete(workId);
     }
 
     //////////////////////    levels
 
     /**
      * 档位设定列表
+     *
      * @param workId
      * @return
      */
-    @RequestMapping(value = "{workId}/levels",method = RequestMethod.GET)
-    public List<Level> list(@PathVariable Long workId){
+    @RequestMapping(value = "{workId}/levels", method = RequestMethod.GET)
+    public List<Level> list(@PathVariable Long workId) {
         return levelRepo.findByWorkId(workId);
     }
 
     /**
      * 删除档位
+     *
      * @param workId
      * @param levelId
      */
-    @RequestMapping(value = "{workId}/levels/{levelId}",method = RequestMethod.DELETE)
-    public void deleteLevel(@PathVariable Long workId,@PathVariable Long levelId){
+    @RequestMapping(value = "{workId}/levels/{levelId}", method = RequestMethod.DELETE)
+    public void deleteLevel(@PathVariable Long workId, @PathVariable Long levelId) {
         levelRepo.delete(levelId);
     }
     //////////////////////   overview
 
     /**
      * 总览,各统计数据
+     *
      * @param work
      * @return
      */
-    @RequestMapping(value = "{work}/overview",method = RequestMethod.GET)
-    public WorkOverview overview(@PathVariable Work work){
+    @RequestMapping(value = "{work}/overview", method = RequestMethod.GET)
+    public WorkOverview overview(@PathVariable Work work) {
         return workOverviewAssembler.toDTO(work);
     }
 

+ 47 - 25
stmms-ms-admin/src/main/java/cn/com/qmth/stmms/ms/admin/service/DataUploadService.java

@@ -1,26 +1,9 @@
 package cn.com.qmth.stmms.ms.admin.service;
 
-import java.awt.image.BufferedImage;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Date;
-import java.util.List;
-
-import javax.imageio.ImageIO;
-
-import org.apache.commons.codec.digest.DigestUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
 import cn.com.qmth.stmms.ms.admin.dto.StudentDTO;
 import cn.com.qmth.stmms.ms.commons.config.ImageCompressionConfig;
 import cn.com.qmth.stmms.ms.commons.config.SystemConfig;
+import cn.com.qmth.stmms.ms.commons.utils.RandomUtil;
 import cn.com.qmth.stmms.ms.commons.utils.excel.ExcelError;
 import cn.com.qmth.stmms.ms.commons.utils.excel.ExcelReader;
 import cn.com.qmth.stmms.ms.commons.utils.excel.ExcelReaderHandle;
@@ -33,6 +16,17 @@ import cn.com.qmth.stmms.ms.core.repository.MarkTaskRepo;
 import cn.com.qmth.stmms.ms.core.repository.PaperRepo;
 import cn.com.qmth.stmms.ms.core.repository.StudentRepo;
 import cn.com.qmth.stmms.ms.core.vo.Subject;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
+import java.io.*;
+import java.util.Date;
+import java.util.List;
+import java.util.Random;
 
 /**
  * 数据上传服务 Created by zhengmin on 2016/11/18.
@@ -68,7 +62,7 @@ public class DataUploadService {
      * @throws IOException
      */
     @Transactional
-    public void uploadPaper(Long studentId, Subject subject, InputStream in, boolean isManual) throws IOException {
+    public void uploadPaper(Long studentId, Subject subject, InputStream in, boolean isManual) throws Exception {
         Student student = studentRepo.findOne(studentId);
         String savePath = systemConfig.getImageDir() + File.separator + student.getWorkId() + File.separator + subject
                 + File.separator + student.getAreaCode();
@@ -99,7 +93,7 @@ public class DataUploadService {
 
         Paper exist = paperRepo.findByWorkIdAndSubjectAndExamNumber(student.getWorkId(), subject,
                 student.getExamNumber());
-        
+
         FileInputStream sheetIn = new FileInputStream(savePath + File.separator + student.getExamNumber() + ".jpg");
         FileInputStream slicein = new FileInputStream(thumbFileName);
         String sheetMD5 = DigestUtils.md5Hex(sheetIn);
@@ -115,7 +109,8 @@ public class DataUploadService {
         } else {
             ExamQuestion examQuestion = examQuestionRepo.findByWorkIdAndSubjectAndAreaCode(student.getWorkId(), subject,
                     student.getAreaCode());
-            Paper paper = new Paper(student.getWorkId(), null, subject, examQuestion, student, false);
+            Long random = getRandom(student.getWorkId(), student.getExamNumber());
+            Paper paper = new Paper(student.getWorkId(), null, subject, examQuestion, student, false, random);
             paper.setSheetMD5(sheetMD5);
             paper.setSliceMD5(sliceMD5);
             paperRepo.save(paper);
@@ -215,18 +210,19 @@ public class DataUploadService {
     }
 
     @Transactional
-    public Paper savePaper(Student student, Subject subject, boolean isManual) throws FileNotFoundException, IOException {
+    public Paper savePaper(Student student, Subject subject, boolean isManual) throws Exception {
         ExamQuestion examQuestion = examQuestionRepo.findByWorkIdAndSubjectAndAreaCode(student.getWorkId(), subject, student.getAreaCode());
         Paper paper = paperRepo.findByWorkIdAndSubjectAndExamNumber(student.getWorkId(), subject, student.getExamNumber());
         if (paper == null) {
-            paper = new Paper(student.getWorkId(), null, subject, examQuestion, student, isManual);
+            Long random = getRandom(student.getWorkId(), student.getExamNumber());
+            paper = new Paper(student.getWorkId(), null, subject, examQuestion, student, isManual, random);
         }
         paper.setUploadedOn(new Date());
         paper.setManual(isManual);
         String sheetPath = systemConfig.getSheetDir() + File.separator + student.getWorkId() + File.separator + subject
-    			+ File.separator + student.getAreaCode() + File.separator + student.getExamNumber() + ".jpg";
+                + File.separator + student.getAreaCode() + File.separator + student.getExamNumber() + ".jpg";
         String slicePath = systemConfig.getImageDir() + File.separator + student.getWorkId() + File.separator + subject
-    			+ File.separator + student.getAreaCode() + File.separator + student.getExamNumber() + ".jpg";
+                + File.separator + student.getAreaCode() + File.separator + student.getExamNumber() + ".jpg";
         FileInputStream sheetIn = new FileInputStream(sheetPath);
         FileInputStream slicein = new FileInputStream(slicePath);
         String sheetMD5 = DigestUtils.md5Hex(sheetIn);
@@ -246,4 +242,30 @@ public class DataUploadService {
         }
         return paper;
     }
+
+    /**
+     * 获取随机号
+     *
+     * @param workId
+     * @param examNumber
+     * @return
+     * @throws Exception
+     */
+    public Long getRandom(Long workId, String examNumber) throws Exception {
+        int count = 0, result = 0;
+        Long random = 0L;
+        while (true) {
+            random = RandomUtil.randomMap.get(workId).get(new Random().nextInt(RandomUtil.randomMap.get(workId).size()));
+            result = paperRepo.countByWorkIdAndExamNumberAndRandomReq(workId, examNumber, random);
+            if (result == 0 && random != Long.parseLong(examNumber.substring(3, examNumber.length()))) {
+                break;
+            } else {
+                count++;
+            }
+            if (count > 100) {
+                throw new Exception("重复几率较高,建议重新生成随机号");
+            }
+        }
+        return random;
+    }
 }

+ 1 - 1
stmms-ms-collect/src/main/java/cn/com/qmth/stmms/ms/collect/api/CollectApi.java

@@ -120,7 +120,7 @@ public class CollectApi {
 
     @RequestMapping(value = "upload/student/{subjectId}", method = RequestMethod.POST)
     public List<CollectStuDTO> saveStudent(HttpServletRequest request, @PathVariable Integer subjectId,
-                                           @RequestBody CollectStuDTO[] uploadStudentArray) throws IOException {
+                                           @RequestBody CollectStuDTO[] uploadStudentArray) throws Exception {
         Subject subject = Subject.values()[subjectId - 1];
         Work activeWork = workRepo.findByActiveTrue();
         List<CollectStuDTO> list = new ArrayList<>();

+ 52 - 0
stmms-ms-commons/src/main/java/cn/com/qmth/stmms/ms/commons/utils/RandomUtil.java

@@ -0,0 +1,52 @@
+package cn.com.qmth.stmms.ms.commons.utils;
+
+import org.slf4j.LoggerFactory;
+
+import java.util.*;
+
+/**
+ * @Description: 随机数生成工具类
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2019/10/24
+ */
+public class RandomUtil {
+    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(RandomUtil.class);
+    public static final int minSize = 1000000;
+    public static final int maxSize = 1000001;
+    public static final int randomSize = 2000000;
+    public static Map<Long, List<Long>> randomMap = new HashMap<>();
+
+    /**
+     * 根据workId随机生成百万随机数
+     *
+     * @param workId
+     * @param againRandom
+     */
+    public static void getRandom(Long workId, boolean againRandom) {
+        List list = randomMap.get(workId);
+        if (Objects.isNull(list)) {
+            list = new ArrayList();
+        }
+        if (list.size() == 0 || againRandom) {
+            long start = System.currentTimeMillis();
+            Long randomReq = workId % 10;
+            randomReq = randomReq == 0L ? 1L : randomReq;
+            LOGGER.info("workId:{},开始生成随机数:{}", workId, start);
+            Long finalRandomReq = randomReq;
+            List finalList = list;
+            new Thread(() -> {
+                Set<Long> set = new HashSet<>();
+                for (int i = 0; i < randomSize; i++) {
+                    long id = (long) (Math.random() * minSize + maxSize * finalRandomReq);
+                    set.add(id);
+                }
+                finalList.addAll(set);
+                randomMap.put(workId, finalList);
+                long end = System.currentTimeMillis();
+                LOGGER.info("workId:{},生成随机数耗时:{},数据长度为:{}", workId, (end - start) / 1000 + "s", finalList.size());
+            }).start();
+        }
+    }
+}

+ 50 - 31
stmms-ms-core/src/main/java/cn/com/qmth/stmms/ms/core/domain/Paper.java

@@ -101,24 +101,46 @@ public class Paper implements Serializable {
      * 是否标记
      */
     private boolean isSample;
-    
+
     //抽查范围ID
     private Long inspectRange;
-	//生源地
+    //生源地
     private String sourceName;
     //原图MD5
-    @Column(name="sheet_md5")
+    @Column(name = "sheet_md5")
     private String sheetMD5;
     //裁切图MD5
-    @Column(name="slice_md5")
+    @Column(name = "slice_md5")
     private String sliceMD5;
 
     /**
      * 是否缺考
      */
     private boolean isMissing;
-    
-    public Paper(Long workId, Long idx, Subject subject, ExamQuestion examQuestion, Student student, boolean isManual) {
+
+    private Long randomReq;
+
+    public static long getSerialVersionUID() {
+        return serialVersionUID;
+    }
+
+    public boolean getIsMissing() {
+        return isMissing;
+    }
+
+    public void setIsMissing(boolean isMissing) {
+        this.isMissing = isMissing;
+    }
+
+    public Long getRandomReq() {
+        return randomReq;
+    }
+
+    public void setRandomReq(Long randomReq) {
+        this.randomReq = randomReq;
+    }
+
+    public Paper(Long workId, Long idx, Subject subject, ExamQuestion examQuestion, Student student, boolean isManual, Long randomReq) {
         this.workId = workId;
         this.idx = idx;
         this.studentName = student.getName();
@@ -129,11 +151,15 @@ public class Paper implements Serializable {
         this.questionId = examQuestion.getId();
         this.areaCode = examQuestion.getAreaCode();
         this.questionName = examQuestion.getName();
-        this.secretNumber = subject.ordinal() + examQuestion.getAreaCode() + examNumber.substring(3, examNumber.length());
+        //随机号生成修改规则
+//        this.secretNumber = subject.ordinal() + examQuestion.getAreaCode() + examNumber.substring(3, examNumber.length());
+        this.secretNumber = subject.ordinal() + examQuestion.getAreaCode() + randomReq;
+        this.randomReq = randomReq;
         this.isManual = isManual;
         this.uploadedOn = new Date();
     }
 
+
     public Paper() {
     }
 
@@ -393,35 +419,28 @@ public class Paper implements Serializable {
         this.inspector = inspector;
     }
 
-	public boolean isSample() {
-		return isSample;
-	}
-
-	public void setSample(boolean isSample) {
-		this.isSample = isSample;
-	}
-
-	public String getSheetMD5() {
-		return sheetMD5;
-	}
+    public boolean isSample() {
+        return isSample;
+    }
 
-	public void setSheetMD5(String sheetMD5) {
-		this.sheetMD5 = sheetMD5;
-	}
+    public void setSample(boolean isSample) {
+        this.isSample = isSample;
+    }
 
-	public String getSliceMD5() {
-		return sliceMD5;
-	}
+    public String getSheetMD5() {
+        return sheetMD5;
+    }
 
-	public void setSliceMD5(String sliceMD5) {
-		this.sliceMD5 = sliceMD5;
-	}
+    public void setSheetMD5(String sheetMD5) {
+        this.sheetMD5 = sheetMD5;
+    }
 
-    public boolean getIsMissing() {
-        return isMissing;
+    public String getSliceMD5() {
+        return sliceMD5;
     }
 
-    public void setIsMissing(boolean isMissing) {
-        this.isMissing = isMissing;
+    public void setSliceMD5(String sliceMD5) {
+        this.sliceMD5 = sliceMD5;
     }
+
 }

+ 9 - 9
stmms-ms-core/src/main/java/cn/com/qmth/stmms/ms/core/repository/PaperRepo.java

@@ -2,7 +2,6 @@ package cn.com.qmth.stmms.ms.core.repository;
 
 import cn.com.qmth.stmms.ms.core.domain.Paper;
 import cn.com.qmth.stmms.ms.core.vo.Subject;
-
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.domain.Sort;
@@ -13,13 +12,14 @@ import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.repository.query.Param;
 
 import java.util.List;
-import java.util.stream.Stream;
 
 /**
  * Created by zhengmin on 2016/9/23.
  */
 public interface PaperRepo extends JpaRepository<Paper, Long>, JpaSpecificationExecutor<Paper> {
 
+    int countByWorkIdAndExamNumberAndRandomReq(Long workId, String examNumber, Long randomReq);
+
     List<Paper> findByWorkIdAndSubject(Long workId, Subject subject);
 
     List<Paper> findByWorkIdAndSubject(Long workId, Subject subject, Sort sort);
@@ -144,17 +144,17 @@ public interface PaperRepo extends JpaRepository<Paper, Long>, JpaSpecificationE
     @Query(value = "update Paper p set p.inspectRange = ?1 where p.examNumber in ?2")
     void markInspectRange(Long inspectRange, List<String> examNumbers);
 
-	long countByWorkIdAndSubjectAndIsSampleIsTrue(Long workId, Subject subject);
+    long countByWorkIdAndSubjectAndIsSampleIsTrue(Long workId, Subject subject);
 
-	long countByWorkIdAndSubjectAndLevel(Long workId, Subject subject,String code);
+    long countByWorkIdAndSubjectAndLevel(Long workId, Subject subject, String code);
 
-	long countByWorkIdAndSubject(Long workId, Subject subject);
+    long countByWorkIdAndSubject(Long workId, Subject subject);
 
-	long countByWorkIdAndSubjectAndQuestionIdAndLevel(Long workId,
-			Subject subject, Long id, String code);
+    long countByWorkIdAndSubjectAndQuestionIdAndLevel(Long workId,
+                                                      Subject subject, Long id, String code);
 
-	long countByWorkIdAndSubjectAndQuestionId(Long workId, Subject subject,
-			Long id);
+    long countByWorkIdAndSubjectAndQuestionId(Long workId, Subject subject,
+                                              Long id);
 
 //    List<Paper> findByWorkIdAndSubjectAndInspectRange(Long workId, Subject subject, Long inspectRange);