wangliang пре 2 година
родитељ
комит
ba1dadf31a

+ 2 - 94
themis-admin/src/main/java/com/qmth/themis/admin/api/TIeInvigilateController.java

@@ -30,7 +30,6 @@ import com.qmth.themis.common.util.ResultUtil;
 import io.swagger.annotations.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
@@ -495,7 +494,6 @@ public class TIeInvigilateController {
     @ApiOperation(value = "违纪处理接口")
     @RequestMapping(value = "/breach", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class)})
-    @Transactional
     public Result breach(@ApiJsonObject(name = "invigilateBreach", value = {
             @ApiJsonProperty(key = "examRecordId", type = "long", example = "1", description = "考试记录id", required = true),
             @ApiJsonProperty(key = "type", description = "违规类型", required = true),
@@ -506,107 +504,17 @@ public class TIeInvigilateController {
         if (Objects.isNull(mapParameter.get(SystemConstant.EXAM_RECORD_ID)) || Objects.equals(mapParameter.get(SystemConstant.EXAM_RECORD_ID), "")) {
             throw new BusinessException(ExceptionResultEnum.RECORD_ID_IS_NULL);
         }
-        List<String> recordIdList = (List<String>) mapParameter.get(SystemConstant.EXAM_RECORD_ID);
         if (Objects.isNull(mapParameter.get(SystemConstant.TYPE)) || Objects.equals(mapParameter.get(SystemConstant.TYPE), "")) {
             throw new BusinessException(ExceptionResultEnum.BREACH_TYPE_IS_NULL);
         }
         if (Objects.isNull(mapParameter.get("description")) || Objects.equals(mapParameter.get("description"), "")) {
             throw new BusinessException(ExceptionResultEnum.BREACH_DESC_IS_NULL);
         }
-        String description = String.valueOf(mapParameter.get("description"));
         if (Objects.isNull(mapParameter.get(SystemConstant.STATUS)) || Objects.equals(mapParameter.get(SystemConstant.STATUS), "")) {
             throw new BusinessException(ExceptionResultEnum.BREACH_STATUS_IS_NULL);
         }
-        List<TOeExamRecord> tOeExamRecordList = new ArrayList<>();
-        if (recordIdList.size() > 0) {
-            Integer status = Integer.parseInt(String.valueOf(mapParameter.get(SystemConstant.STATUS)));
-            TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
-            List<TEExamBreachLog> teExamBreachLogList = new ArrayList<>();
-            if (status.intValue() == 0) {//新建违纪
-                BreachTypeEnum type = BreachTypeEnum.valueOf(String.valueOf(mapParameter.get(SystemConstant.TYPE)));
-                List<TEExamBreachLog> finalTeExamBreachLogList = teExamBreachLogList;
-                for (int i = 0; i < recordIdList.size(); i++) {
-                    Long l = Long.parseLong(String.valueOf(recordIdList.get(i)));
-                    Long examId = null, examStudentId = null, examActivityId = null;
-                    TOeExamRecord tOeExamRecord = null;
-                    if (Objects.isNull(ExamRecordCacheUtil.getId(l))) {
-                        tOeExamRecord = tOeExamRecordService.getById(l);
-                        examId = tOeExamRecord.getExamId();
-                        examStudentId = tOeExamRecord.getExamStudentId();
-                        examActivityId = tOeExamRecord.getExamActivityId();
-                    } else {
-                        examId = ExamRecordCacheUtil.getExamId(l);
-                        examStudentId = ExamRecordCacheUtil.getExamStudentId(l);
-                        examActivityId = ExamRecordCacheUtil.getExamActivityId(l);
-                    }
-                    TEExamBreachLog teExamBreachLog = new TEExamBreachLog(examId, examActivityId, l, examStudentId, type.name(), description, status);
-                    teExamBreachLog.setCreateId(tbUser.getId());
-                    finalTeExamBreachLogList.add(teExamBreachLog);
-                    if (Objects.nonNull(ExamRecordCacheUtil.getId(l))) {
-                        Integer breachStatus = Objects.nonNull(ExamRecordCacheUtil.getBreachStatus(l)) ? ExamRecordCacheUtil.getBreachStatus(l) : 1;
-                        if (breachStatus.intValue() == 1) {
-                            Long timestamp = System.currentTimeMillis();
-                            ExamRecordCacheUtil.setBreachStatus(l, status, timestamp);
-                            tOeExamRecordService.sendExamRecordDataSaveMq(l, timestamp);
-                        }
-                    } else {
-                        Integer breachStatus = Objects.nonNull(tOeExamRecord.getBreachStatus()) ? tOeExamRecord.getBreachStatus() : 1;
-                        if (breachStatus.intValue() == 1) {
-                            tOeExamRecord.setBreachStatus(status);
-                            tOeExamRecordList.add(tOeExamRecord);
-                        }
-                    }
-                }
-            } else {//撤销违纪
-                Long breachLogId = (Long) mapParameter.get("breachLogId");
-                BreachCancelTypeEnum type = BreachCancelTypeEnum.valueOf(String.valueOf(mapParameter.get(SystemConstant.TYPE)));
-                TEExamBreachLog teExamBreachLog = teExamBreachLogService.getById(breachLogId);
-                Optional.ofNullable(teExamBreachLog).orElseThrow(() -> new BusinessException("未找到违纪记录"));
-
-                if (Objects.nonNull(teExamBreachLog.getStatus()) && teExamBreachLog.getStatus().intValue() == 1) {
-                    throw new BusinessException("该条违纪信息已处理");
-                }
-                teExamBreachLog.setType(type.name());
-                teExamBreachLog.setDescription(description);
-                teExamBreachLog.setStatus(status);
-                teExamBreachLog.setUpdateId(tbUser.getId());
-                teExamBreachLogList.add(teExamBreachLog);
-                for (int i = 0; i < recordIdList.size(); i++) {
-                    Long l = Long.parseLong(String.valueOf(recordIdList.get(i)));
-                    QueryWrapper<TEExamBreachLog> teExamBreachLogQueryWrapper = new QueryWrapper<>();
-                    teExamBreachLogQueryWrapper.lambda().eq(TEExamBreachLog::getExamRecordId, l)
-                            .eq(TEExamBreachLog::getStatus, 0);
-                    int count = teExamBreachLogService.count(teExamBreachLogQueryWrapper);
-                    if (count == 1) {//撤销违纪都处理完了这个考生的考试记录里的违纪才算取消
-                        TOeExamRecord tOeExamRecord = null;
-                        if (Objects.isNull(ExamRecordCacheUtil.getId(teExamBreachLog.getExamRecordId()))) {
-                            tOeExamRecord = tOeExamRecordService.getById(teExamBreachLog.getExamRecordId());
-                            tOeExamRecord.setBreachStatus(status);
-                            tOeExamRecordList.add(tOeExamRecord);
-                        } else {
-                            Long timestamp = System.currentTimeMillis();
-                            ExamRecordCacheUtil.setBreachStatus(teExamBreachLog.getExamRecordId(), status, timestamp);
-                            tOeExamRecordService.sendExamRecordDataSaveMq(teExamBreachLog.getExamRecordId(), timestamp);
-                        }
-                    }
-                }
-            }
-            if (Objects.nonNull(tOeExamRecordList) && tOeExamRecordList.size() > 0) {
-                tOeExamRecordService.saveOrUpdateBatch(tOeExamRecordList);
-            }
-            for (TEExamBreachLog eb : teExamBreachLogList) {
-                Map<String, Object> properties = new HashMap<>();
-                properties.put(SystemConstant.TYPE, eb.getDescription());
-                properties.put(SystemConstant.REMARK, eb.getType());
-                properties.put(SystemConstant.EXAM_STUDENT_ID, eb.getExamStudentId());
-                properties.put(SystemConstant.EXAM_RECORD_ID, eb.getExamRecordId());
-                properties.put("objId", eb.getId());
-                ExamStudentCacheBean examStudentCacheBean = teExamStudentService.getExamStudentCacheBean(eb.getExamStudentId());
-                MqDto mqDto = new MqDto(mqUtil.getTopic(), MqTagEnum.STUDENT.name(), eb.getStatus() == 0 ? SystemOperationEnum.BREACH_HANDLE : SystemOperationEnum.BREACH_REVOKE, MqTagEnum.STUDENT, String.valueOf(examStudentCacheBean.getStudentId()), properties, examStudentCacheBean.getIdentity());
-                mqDtoService.assembleSendOneWayMsg(mqDto);
-            }
-            teExamBreachLogService.saveOrUpdateBatch(teExamBreachLogList);
-        }
+        teExamBreachLogService.breachLogic(mapParameter);
+        teExamBreachLogService.updateBreachStatus(mapParameter);
         return ResultUtil.ok(true);
     }
 

+ 13 - 1
themis-business/src/main/java/com/qmth/themis/business/service/TEExamBreachLogService.java

@@ -3,7 +3,6 @@ package com.qmth.themis.business.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.themis.business.entity.TEExamBreachLog;
 
-import java.util.List;
 import java.util.Map;
 
 /**
@@ -15,4 +14,17 @@ import java.util.Map;
  */
 public interface TEExamBreachLogService extends IService<TEExamBreachLog> {
 
+    /**
+     * 违纪处理接口
+     *
+     * @param mapParameter
+     */
+    public void breachLogic(Map<String, Object> mapParameter);
+
+    /**
+     * 撤销违纪接口
+     *
+     * @param mapParameter
+     */
+    public void updateBreachStatus(Map<String, Object> mapParameter);
 }

+ 156 - 0
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEExamBreachLogServiceImpl.java

@@ -1,10 +1,32 @@
 package com.qmth.themis.business.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.themis.business.cache.ExamRecordCacheUtil;
+import com.qmth.themis.business.cache.bean.ExamStudentCacheBean;
+import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dao.TEExamBreachLogMapper;
+import com.qmth.themis.business.dto.MqDto;
+import com.qmth.themis.business.entity.TBUser;
 import com.qmth.themis.business.entity.TEExamBreachLog;
+import com.qmth.themis.business.entity.TOeExamRecord;
+import com.qmth.themis.business.enums.BreachCancelTypeEnum;
+import com.qmth.themis.business.enums.BreachTypeEnum;
+import com.qmth.themis.business.enums.MqTagEnum;
+import com.qmth.themis.business.enums.SystemOperationEnum;
+import com.qmth.themis.business.service.MqDtoService;
 import com.qmth.themis.business.service.TEExamBreachLogService;
+import com.qmth.themis.business.service.TEExamStudentService;
+import com.qmth.themis.business.service.TOeExamRecordService;
+import com.qmth.themis.business.util.MqUtil;
+import com.qmth.themis.business.util.ServletUtil;
+import com.qmth.themis.common.exception.BusinessException;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
+
+import javax.annotation.Resource;
+import java.util.*;
 
 /**
  * @Description: 考生违纪处理 服务实现类
@@ -16,4 +38,138 @@ import org.springframework.stereotype.Service;
 @Service
 public class TEExamBreachLogServiceImpl extends ServiceImpl<TEExamBreachLogMapper, TEExamBreachLog> implements TEExamBreachLogService {
 
+    @Resource
+    TOeExamRecordService tOeExamRecordService;
+
+    @Resource
+    TEExamBreachLogService teExamBreachLogService;
+
+    @Resource
+    TEExamStudentService teExamStudentService;
+
+    @Resource
+    MqUtil mqUtil;
+
+    @Resource
+    MqDtoService mqDtoService;
+
+    /**
+     * 违纪处理接口
+     *
+     * @param mapParameter
+     */
+    @Override
+    @Transactional
+    public void breachLogic(Map<String, Object> mapParameter) {
+        List<String> recordIdList = (List<String>) mapParameter.get(SystemConstant.EXAM_RECORD_ID);
+        String description = String.valueOf(mapParameter.get("description"));
+        List<TOeExamRecord> tOeExamRecordList = new ArrayList<>();
+
+        if (recordIdList.size() > 0) {
+            Integer status = Integer.parseInt(String.valueOf(mapParameter.get(SystemConstant.STATUS)));
+            TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
+            List<TEExamBreachLog> teExamBreachLogList = new ArrayList<>();
+            if (status.intValue() == 0) {//新建违纪
+                BreachTypeEnum type = BreachTypeEnum.valueOf(String.valueOf(mapParameter.get(SystemConstant.TYPE)));
+                List<TEExamBreachLog> finalTeExamBreachLogList = teExamBreachLogList;
+                for (int i = 0; i < recordIdList.size(); i++) {
+                    Long l = Long.parseLong(String.valueOf(recordIdList.get(i)));
+                    Long examId = null, examStudentId = null, examActivityId = null;
+                    TOeExamRecord tOeExamRecord = null;
+                    if (Objects.isNull(ExamRecordCacheUtil.getId(l))) {
+                        tOeExamRecord = tOeExamRecordService.getById(l);
+                        examId = tOeExamRecord.getExamId();
+                        examStudentId = tOeExamRecord.getExamStudentId();
+                        examActivityId = tOeExamRecord.getExamActivityId();
+                    } else {
+                        examId = ExamRecordCacheUtil.getExamId(l);
+                        examStudentId = ExamRecordCacheUtil.getExamStudentId(l);
+                        examActivityId = ExamRecordCacheUtil.getExamActivityId(l);
+                    }
+                    TEExamBreachLog teExamBreachLog = new TEExamBreachLog(examId, examActivityId, l, examStudentId, type.name(), description, status);
+                    teExamBreachLog.setCreateId(tbUser.getId());
+                    finalTeExamBreachLogList.add(teExamBreachLog);
+                    if (Objects.nonNull(ExamRecordCacheUtil.getId(l))) {
+                        Integer breachStatus = Objects.nonNull(ExamRecordCacheUtil.getBreachStatus(l)) ? ExamRecordCacheUtil.getBreachStatus(l) : 1;
+                        if (breachStatus.intValue() == 1) {
+                            Long timestamp = System.currentTimeMillis();
+                            ExamRecordCacheUtil.setBreachStatus(l, status, timestamp);
+                            tOeExamRecordService.sendExamRecordDataSaveMq(l, timestamp);
+                        }
+                    } else {
+                        Integer breachStatus = Objects.nonNull(tOeExamRecord.getBreachStatus()) ? tOeExamRecord.getBreachStatus() : 1;
+                        if (breachStatus.intValue() == 1) {
+                            tOeExamRecord.setBreachStatus(status);
+                            tOeExamRecordList.add(tOeExamRecord);
+                        }
+                    }
+                }
+            } else {//撤销违纪
+                Long breachLogId = (Long) mapParameter.get("breachLogId");
+                BreachCancelTypeEnum type = BreachCancelTypeEnum.valueOf(String.valueOf(mapParameter.get(SystemConstant.TYPE)));
+                TEExamBreachLog teExamBreachLog = teExamBreachLogService.getById(breachLogId);
+                Optional.ofNullable(teExamBreachLog).orElseThrow(() -> new BusinessException("未找到违纪记录"));
+
+                if (Objects.nonNull(teExamBreachLog.getStatus()) && teExamBreachLog.getStatus().intValue() == 1) {
+                    throw new BusinessException("该条违纪信息已处理");
+                }
+                teExamBreachLog.setType(type.name());
+                teExamBreachLog.setDescription(description);
+                teExamBreachLog.setStatus(status);
+                teExamBreachLog.setUpdateId(tbUser.getId());
+                teExamBreachLogList.add(teExamBreachLog);
+            }
+            if (!CollectionUtils.isEmpty(tOeExamRecordList)) {
+                tOeExamRecordService.saveOrUpdateBatch(tOeExamRecordList);
+            }
+            for (TEExamBreachLog eb : teExamBreachLogList) {
+                Map<String, Object> properties = new HashMap<>();
+                properties.put(SystemConstant.TYPE, eb.getDescription());
+                properties.put(SystemConstant.REMARK, eb.getType());
+                properties.put(SystemConstant.EXAM_STUDENT_ID, eb.getExamStudentId());
+                properties.put(SystemConstant.EXAM_RECORD_ID, eb.getExamRecordId());
+                properties.put("objId", eb.getId());
+                ExamStudentCacheBean examStudentCacheBean = teExamStudentService.getExamStudentCacheBean(eb.getExamStudentId());
+                MqDto mqDto = new MqDto(mqUtil.getTopic(), MqTagEnum.STUDENT.name(), eb.getStatus() == 0 ? SystemOperationEnum.BREACH_HANDLE : SystemOperationEnum.BREACH_REVOKE, MqTagEnum.STUDENT, String.valueOf(examStudentCacheBean.getStudentId()), properties, examStudentCacheBean.getIdentity());
+                mqDtoService.assembleSendOneWayMsg(mqDto);
+            }
+            teExamBreachLogService.saveOrUpdateBatch(teExamBreachLogList);
+        }
+    }
+
+    /**
+     * 撤销违纪接口
+     *
+     * @param mapParameter
+     */
+    @Override
+    @Transactional
+    public void updateBreachStatus(Map<String, Object> mapParameter) {
+        List<String> recordIdList = (List<String>) mapParameter.get(SystemConstant.EXAM_RECORD_ID);
+        Integer status = Integer.parseInt(String.valueOf(mapParameter.get(SystemConstant.STATUS)));
+        List<TOeExamRecord> tOeExamRecordList = new ArrayList<>();
+
+        for (int i = 0; i < recordIdList.size(); i++) {
+            Long l = Long.parseLong(String.valueOf(recordIdList.get(i)));
+            QueryWrapper<TEExamBreachLog> teExamBreachLogQueryWrapper = new QueryWrapper<>();
+            teExamBreachLogQueryWrapper.lambda().eq(TEExamBreachLog::getExamRecordId, l)
+                    .eq(TEExamBreachLog::getStatus, 0);
+            int count = teExamBreachLogService.count(teExamBreachLogQueryWrapper);
+            if (count == 0) {//撤销违纪都处理完了这个考生的考试记录里的违纪才算取消
+                TOeExamRecord tOeExamRecord = null;
+                if (Objects.isNull(ExamRecordCacheUtil.getId(l))) {
+                    tOeExamRecord = tOeExamRecordService.getById(l);
+                    tOeExamRecord.setBreachStatus(status);
+                    tOeExamRecordList.add(tOeExamRecord);
+                } else {
+                    Long timestamp = System.currentTimeMillis();
+                    ExamRecordCacheUtil.setBreachStatus(l, status, timestamp);
+                    tOeExamRecordService.sendExamRecordDataSaveMq(l, timestamp);
+                }
+            }
+        }
+        if (!CollectionUtils.isEmpty(tOeExamRecordList)) {
+            tOeExamRecordService.saveOrUpdateBatch(tOeExamRecordList);
+        }
+    }
 }