Browse Source

新增考生导入密码修改

wangliang 3 years ago
parent
commit
e4a9b6f6e0

+ 11 - 0
themis-business/src/main/java/com/qmth/themis/business/dto/ExamStudentImportDto.java

@@ -36,6 +36,9 @@ public class ExamStudentImportDto implements Serializable {
     @ExcelNote(value = "教学班级")
     private String classNo; //教学班级
 
+    @ExcelNote(value = "密码")
+    private String password; //密码
+
     @NotNull
     @ExcelNote(value = "场次")
     private String examActivityCode; //场次
@@ -48,6 +51,14 @@ public class ExamStudentImportDto implements Serializable {
     @ExcelNote(value = "考场名称")
     private String roomName; //考场名称
 
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
     public String getName() {
         return name;
     }

+ 0 - 1
themis-business/src/main/java/com/qmth/themis/business/entity/TEStudent.java

@@ -66,7 +66,6 @@ public class TEStudent extends BaseEntity {
         this.orgId = orgId;
         this.identity = identity;
         this.name = name;
-        this.password = SystemConstant.DEFAULT_PASSWORD;
         setCreateId(createId);
     }
 

+ 15 - 2
themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskExamStudentImportTemplete.java

@@ -28,6 +28,8 @@ import javax.annotation.Resource;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * @Description: 考生导入任务
@@ -88,16 +90,27 @@ public class TaskExamStudentImportTemplete implements TaskImportTemplete {
                                     }
                                 }
                             }
+                            if (Objects.nonNull(examStudentImportDto.getPassword()) && !Objects.equals(examStudentImportDto.getPassword().trim(), "")) {
+                                if (examStudentImportDto.getPassword().trim().length() > 8) {
+                                    excelErrorList.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[密码]长度不能大于8位"));
+                                } else if (examStudentImportDto.getPassword().trim().length() < 6) {
+                                    excelErrorList.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[密码]长度不能小于6位"));
+                                } else {
+                                    Pattern pattern = Pattern.compile("^[A-Za-z0-9]*");
+                                    Matcher matcher = pattern.matcher(examStudentImportDto.getPassword().trim());
+                                    if (!matcher.matches()) {
+                                        excelErrorList.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[密码]不能包含特殊字符,只能为字母和数字"));
+                                    }
+                                }
+                            }
                         }
                     }
                     if (excelErrorList.size() > 0) {
-                        taskImportCommon.getTxtList().add(DateUtil.format(new Date(), Constants.DEFAULT_DATE_PATTERN) + "->数据校验异常:" + JSONObject.toJSONString(excelErrorList));
                         taskImportCommon.setException(true);
                         taskImportCommon.getTbTaskHistory().setFinishTime(System.currentTimeMillis());
                         taskImportCommon.getTbTaskHistory().setProgress(0d);
                         taskImportCommon.getTbTaskHistory().setStatus(TaskStatusEnum.FINISH);
                         taskImportCommon.getTbTaskHistory().setSummary(taskImportCommon.getTxtList().toString());
-                        taskImportCommon.writeImportResultTxt(taskImportCommon.getTxtList().toString());
                         throw new BusinessException(JSONObject.toJSONString(excelErrorList));
                     }
                     finalMap.put("courseCodeMap", courseCodeMap);

+ 0 - 2
themis-business/src/main/java/com/qmth/themis/business/templete/impl/TaskRoomCodeImportTemplete.java

@@ -66,13 +66,11 @@ public class TaskRoomCodeImportTemplete implements TaskImportTemplete {
                         }
                     }
                     if (excelErrorList.size() > 0) {
-                        taskImportCommon.getTxtList().add(DateUtil.format(new Date(), Constants.DEFAULT_DATE_PATTERN) + "->数据校验异常:" + JSONObject.toJSONString(excelErrorList));
                         taskImportCommon.setException(true);
                         taskImportCommon.getTbTaskHistory().setFinishTime(System.currentTimeMillis());
                         taskImportCommon.getTbTaskHistory().setProgress(0d);
                         taskImportCommon.getTbTaskHistory().setStatus(TaskStatusEnum.FINISH);
                         taskImportCommon.getTbTaskHistory().setSummary(taskImportCommon.getTxtList().toString());
-                        taskImportCommon.writeImportResultTxt(taskImportCommon.getTxtList().toString());
                         throw new BusinessException(JSONObject.toJSONString(excelErrorList));
                     }
                     return finalList;

+ 2 - 1
themis-business/src/main/java/com/qmth/themis/business/templete/service/TempleteLogicService.java

@@ -2,6 +2,7 @@ package com.qmth.themis.business.templete.service;
 
 import org.springframework.util.LinkedMultiValueMap;
 
+import java.io.UnsupportedEncodingException;
 import java.util.List;
 import java.util.Map;
 
@@ -21,7 +22,7 @@ public interface TempleteLogicService {
      * @param map
      * @return
      */
-    public Map<String, Object> execImportExamStudentLogic(List<LinkedMultiValueMap<Integer, Object>> finalList, Map<String, Object> map);
+    public Map<String, Object> execImportExamStudentLogic(List<LinkedMultiValueMap<Integer, Object>> finalList, Map<String, Object> map) throws UnsupportedEncodingException;
 
     /**
      * 考场导入逻辑

+ 11 - 1
themis-business/src/main/java/com/qmth/themis/business/templete/service/impl/TempleteLogicServiceImpl.java

@@ -13,13 +13,16 @@ import com.qmth.themis.business.enums.RoleEnum;
 import com.qmth.themis.business.enums.TaskStatusEnum;
 import com.qmth.themis.business.service.*;
 import com.qmth.themis.business.templete.service.TempleteLogicService;
+import com.qmth.themis.business.util.Base64Util;
 import com.qmth.themis.common.contanst.Constants;
 import com.qmth.themis.common.exception.BusinessException;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.Base64Utils;
 import org.springframework.util.LinkedMultiValueMap;
 
 import javax.annotation.Resource;
+import java.io.UnsupportedEncodingException;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -62,7 +65,7 @@ public class TempleteLogicServiceImpl implements TempleteLogicService {
      */
     @Override
     @Transactional
-    public Map<String, Object> execImportExamStudentLogic(List<LinkedMultiValueMap<Integer, Object>> finalList, Map<String, Object> map) {
+    public Map<String, Object> execImportExamStudentLogic(List<LinkedMultiValueMap<Integer, Object>> finalList, Map<String, Object> map) throws UnsupportedEncodingException {
         Long orgId = Long.parseLong(String.valueOf(map.get("orgId")));
         Long examId = Long.parseLong(String.valueOf(map.get("examId")));
         Long createId = Long.parseLong(String.valueOf(map.get("createId")));
@@ -157,6 +160,13 @@ public class TempleteLogicServiceImpl implements TempleteLogicService {
                         teExamStudent.setExamActivityId(teExamActivity.getId());
                         teExamStudent.setAlreadyExamCount(0);
                     }
+                    if (Objects.nonNull(examStudentImportDto.getPassword()) && !Objects.equals(examStudentImportDto.getPassword().trim(), "")) {
+                        teStudent.setPassword(Base64Util.encode(examStudentImportDto.getPassword().trim().getBytes(SystemConstant.CHARSET_NAME)));
+                    } else {
+                        if (Objects.isNull(teStudent.getPassword())) {
+                            teStudent.setPassword(SystemConstant.DEFAULT_PASSWORD);
+                        }
+                    }
                     teStudent.setName(examStudentImportDto.getName());
                     teStudentList.add(teStudent);
 

+ 17 - 0
themis-business/src/main/java/com/qmth/themis/business/util/Base64Util.java

@@ -0,0 +1,17 @@
+package com.qmth.themis.business.util;
+
+import com.qmth.themis.business.constant.SystemConstant;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Base64;
+
+public class Base64Util {
+
+    public static String encode(byte[] input) throws UnsupportedEncodingException {
+        return new String(Base64.getEncoder().encode(input), SystemConstant.CHARSET_NAME);
+    }
+
+    public static byte[] decode(String input) throws UnsupportedEncodingException {
+        return Base64.getDecoder().decode(input.getBytes(SystemConstant.CHARSET_NAME));
+    }
+}

+ 15 - 0
themis-exam/src/main/java/com/qmth/themis/exam/api/TEExamController.java

@@ -356,4 +356,19 @@ public class TEExamController {
         }
         return ResultUtil.ok(Collections.singletonMap("updateTime", System.currentTimeMillis()));
     }
+
+    @ApiOperation(value = "查询考试状态")
+    @RequestMapping(value = "/status", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "试卷信息")})
+    public Result status(@RequestBody ResultParamBean param) {
+        if (Objects.isNull(param)) {
+            throw new BusinessException(ExceptionResultEnum.PARAMS_ILLEGALITY);
+        }
+        if (Objects.isNull(param.getRecordId())) {
+            throw new BusinessException(ExceptionResultEnum.RECORD_ID_IS_NULL);
+        }
+        Map<String, Object> map = new HashMap<>();
+        map.put("status", ExamRecordCacheUtil.getStatus(param.getRecordId()));
+        return ResultUtil.ok(map);
+    }
 }