瀏覽代碼

试卷结构上传-客观题、主观题同步优化

xiaof 3 年之前
父節點
當前提交
bf45f20234

+ 27 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/ExamPaperStructure.java

@@ -27,6 +27,17 @@ public class ExamPaperStructure extends BaseEntity implements Serializable {
     @TableField("school_id")
     private Long schoolId;
 
+    @ApiModelProperty(value = "学期ID")
+    @JsonSerialize(using = ToStringSerializer.class)
+    @TableField(value = "semester_id")
+    private Long semesterId;
+
+    /**
+     * 学期名称
+     */
+    @TableField("semester_name")
+    private String semesterName;
+
     @ApiModelProperty(value = "云阅卷考试ID")
     @JsonSerialize(using = ToStringSerializer.class)
     @TableField(value = "third_relate_id")
@@ -98,6 +109,22 @@ public class ExamPaperStructure extends BaseEntity implements Serializable {
         this.schoolId = schoolId;
     }
 
+    public Long getSemesterId() {
+        return semesterId;
+    }
+
+    public void setSemesterId(Long semesterId) {
+        this.semesterId = semesterId;
+    }
+
+    public String getSemesterName() {
+        return semesterName;
+    }
+
+    public void setSemesterName(String semesterName) {
+        this.semesterName = semesterName;
+    }
+
     public Long getThirdRelateId() {
         return thirdRelateId;
     }

+ 4 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/mapper/ExamPaperStructureMapper.java

@@ -1,7 +1,10 @@
 package com.qmth.distributed.print.business.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.qmth.distributed.print.business.entity.ExamPaperStructure;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * <p>
@@ -11,4 +14,5 @@ import com.qmth.distributed.print.business.entity.ExamPaperStructure;
  * @author xf
  */
 public interface ExamPaperStructureMapper extends BaseMapper<ExamPaperStructure> {
+    IPage<ExamPaperStructure> listByPropositionTeacherId(@Param("page") Page<ExamPaperStructure> page, @Param("schoolId") Long schoolId, @Param("propositionTeacherId") Long propositionTeacherId);
 }

+ 1 - 3
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/ExamPaperStructureService.java

@@ -6,8 +6,6 @@ import com.qmth.distributed.print.business.entity.ExamPaperStructure;
 import com.qmth.distributed.print.business.enums.ExamPaperStructureStatusEnum;
 import org.springframework.web.multipart.MultipartFile;
 
-import java.util.List;
-
 /**
  * <p>
  * 试卷结构 服务类
@@ -19,7 +17,7 @@ public interface ExamPaperStructureService extends IService<ExamPaperStructure>
 
     IPage<ExamPaperStructure> listByPropositionTeacherId(Integer pageNumber, Integer pageSize);
 
-    ExamPaperStructure upload(Long id, String md5, String paperType, MultipartFile[] files);
+    ExamPaperStructure upload(String examPaperStructure, String md5, MultipartFile[] files);
 
     void updateStatusById(Long id, ExamPaperStructureStatusEnum startSync);
 }

+ 18 - 4
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/DataSyncServiceImpl.java

@@ -15,7 +15,6 @@ import com.qmth.distributed.print.business.enums.ExamPaperStructureStatusEnum;
 import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
 import com.qmth.distributed.print.business.service.*;
 import com.qmth.teachcloud.common.bean.dto.SyncStructureData;
-import com.qmth.teachcloud.common.config.DictionaryConfig;
 import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.BasicAttachment;
 import com.qmth.teachcloud.common.entity.SysConfig;
@@ -24,6 +23,7 @@ import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
 import com.qmth.teachcloud.common.enums.SyncFileTypeEnum;
 import com.qmth.teachcloud.common.enums.TaskResultEnum;
 import com.qmth.teachcloud.common.enums.TaskStatusEnum;
+import com.qmth.teachcloud.common.enums.userPush.SpecialPrivilegeEnum;
 import com.qmth.teachcloud.common.service.BasicAttachmentService;
 import com.qmth.teachcloud.common.service.SysConfigService;
 import com.qmth.teachcloud.common.service.SysUserService;
@@ -416,10 +416,14 @@ public class DataSyncServiceImpl implements DataSyncService {
     public Map<String, Object> markerLoginInfo() {
         try {
             SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
-
+            SpecialPrivilegeEnum userSpecialPrivilege = sysUserService.findUserSpecialPrivilegeByUserId(sysUser.getId());
+            if (SpecialPrivilegeEnum.UNIDENTIFIED.equals(userSpecialPrivilege)
+                    || SpecialPrivilegeEnum.SUBJECT_HEADER.equals(userSpecialPrivilege)) {
+                throw ExceptionResultEnum.ERROR.exception("该用户没有评卷员角色,无法登录");
+            }
             return stmmsUtils.markLogin(sysUser);
         } catch (Exception e) {
-            throw ExceptionResultEnum.ERROR.exception("评卷员登录失败");
+            throw ExceptionResultEnum.ERROR.exception(e.getMessage());
         }
     }
 
@@ -427,12 +431,22 @@ public class DataSyncServiceImpl implements DataSyncService {
     public Map<String, Object> markerLeaderLoginInfo() {
         try {
             SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
+            SpecialPrivilegeEnum userSpecialPrivilege = sysUserService.findUserSpecialPrivilegeByUserId(sysUser.getId());
+            if (SpecialPrivilegeEnum.UNIDENTIFIED.equals(userSpecialPrivilege)
+                    || SpecialPrivilegeEnum.MARKER.equals(userSpecialPrivilege)) {
+                throw ExceptionResultEnum.ERROR.exception("该用户没有科组长角色,无法登录");
+            }
             return stmmsUtils.markLeaderLogin(sysUser);
         } catch (Exception e) {
-            throw ExceptionResultEnum.ERROR.exception("科组长登录失败");
+            throw ExceptionResultEnum.ERROR.exception(e.getMessage());
         }
     }
 
+    /**
+     * 上传文件临时目录
+     * @param type
+     * @return
+     */
     private String getTempDir(SyncFileTypeEnum type) {
         return SystemConstant.TEMP_FILES_DIR + File.separator + "upload-temp" + File.separator + type.name().toLowerCase() + File.separator + System.currentTimeMillis();
     }

+ 23 - 13
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/ExamPaperStructureServiceImpl.java

@@ -20,6 +20,7 @@ import com.qmth.distributed.print.business.service.ExamPaperStructureService;
 import com.qmth.distributed.print.business.service.ExamTaskDetailService;
 import com.qmth.distributed.print.business.service.ExamTaskService;
 import com.qmth.distributed.print.business.service.PrintCommonService;
+import com.qmth.teachcloud.common.contant.SystemConstant;
 import com.qmth.teachcloud.common.entity.BasicAttachment;
 import com.qmth.teachcloud.common.entity.SysUser;
 import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
@@ -69,16 +70,25 @@ public class ExamPaperStructureServiceImpl extends ServiceImpl<ExamPaperStructur
         Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
         Page<ExamPaperStructure> page = new Page<>(pageNumber, pageSize);
-        QueryWrapper<ExamPaperStructure> queryWrapper = new QueryWrapper<>();
-        queryWrapper.lambda().eq(ExamPaperStructure::getSchoolId, schoolId).eq(ExamPaperStructure::getPropositionTeacherId, sysUser.getId());
-        return this.page(page, queryWrapper);
+        IPage<ExamPaperStructure> examPaperStructureIPage = this.baseMapper.listByPropositionTeacherId(page, schoolId, sysUser.getId());
+        return examPaperStructureIPage;
     }
 
     @Transactional
     @Override
-    public ExamPaperStructure upload(Long id, String md5, String paperType, MultipartFile[] files) {
+    public ExamPaperStructure upload(String examPaperStructure, String md5, MultipartFile[] files) {
+
+        ExamPaperStructure examPaperStructureTemp = JSONObject.parseObject(JSONObject.toJSONString(examPaperStructure), ExamPaperStructure.class);
+        if(Objects.isNull(examPaperStructureTemp.getId())){
+            // 保存
+            examPaperStructureTemp.setId(SystemConstant.getDbUuid());
+            this.save(examPaperStructureTemp);
+        } else {
+            examPaperStructureTemp = this.getById(examPaperStructureTemp.getId());
+        }
+
         // 组装ExamPaperStructureDto
-        List<ExamPaperStructureDto> examPaperStructureDtos = createExamPaperStructure(md5, paperType, files);
+        List<ExamPaperStructureDto> examPaperStructureDtos = createExamPaperStructure(md5, examPaperStructureTemp.getPaperType(), files);
         List<BasicAttachment> basicAttachmentList = new ArrayList<>();
 
         List<Map<String, Object>> paperAnswerList = new ArrayList<>();
@@ -86,8 +96,7 @@ public class ExamPaperStructureServiceImpl extends ServiceImpl<ExamPaperStructur
         List<Map<String, Object>> objectiveStructureList = new ArrayList<>();
 
         // 试卷卷型及原卷附件ID
-        ExamPaperStructure examPaperStructure = this.getById(id);
-        Map<String, String> paperMap = createExamTaskAttachmentIds(examPaperStructure);
+        Map<String, String> paperMap = createExamTaskAttachmentIds(examPaperStructureTemp);
 
         // 上传试卷结构、标答文件
         for (ExamPaperStructureDto examPaperStructureDto : examPaperStructureDtos) {
@@ -143,14 +152,14 @@ public class ExamPaperStructureServiceImpl extends ServiceImpl<ExamPaperStructur
         }
 
         // 保存
-        examPaperStructure.setPaperAnswer(JSONObject.toJSONString(paperAnswerList));
-        examPaperStructure.setSubjectiveStructure(JSONObject.toJSONString(subjectiveStructureList));
-        examPaperStructure.setObjectiveStructure(JSONObject.toJSONString(objectiveStructureList));
+        examPaperStructureTemp.setPaperAnswer(JSONObject.toJSONString(paperAnswerList));
+        examPaperStructureTemp.setSubjectiveStructure(JSONObject.toJSONString(subjectiveStructureList));
+        examPaperStructureTemp.setObjectiveStructure(JSONObject.toJSONString(objectiveStructureList));
         // 上传成功
-        examPaperStructure.setStatus(ExamPaperStructureStatusEnum.UPLOAD_FINISH);
+        examPaperStructureTemp.setStatus(ExamPaperStructureStatusEnum.UPLOAD_FINISH);
 
-        this.updateById(examPaperStructure);
-        return examPaperStructure;
+        this.updateById(examPaperStructureTemp);
+        return examPaperStructureTemp;
     }
 
     @Override
@@ -160,6 +169,7 @@ public class ExamPaperStructureServiceImpl extends ServiceImpl<ExamPaperStructur
         this.update(updateWrapper);
     }
 
+
     private Map<String, String> createExamTaskAttachmentIds(ExamPaperStructure examPaperStructure) {
         ExamTask examTask = examTaskService.getByCourseCodeAndPaperNumber(examPaperStructure.getSchoolId(), examPaperStructure.getCourseCode(), examPaperStructure.getPaperNumber());
 

+ 39 - 0
distributed-print-business/src/main/resources/mapper/ExamPaperStructureMapper.xml

@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.qmth.distributed.print.business.mapper.ExamPaperStructureMapper">
+    <select id="listByPropositionTeacherId"
+            resultType="com.qmth.distributed.print.business.entity.ExamPaperStructure">
+        SELECT
+            eps.id,
+            epp.school_id schoolId,
+            epp.semester_id semesterId,
+            bs.name semesterName,
+            epp.third_relate_id thirdRelateId,
+            epp.third_relate_name thirdRelateName,
+            edc.paper_number paperNumber,
+            edc.course_code courseCode,
+            edc.course_name courseName,
+            edc.paper_type paperType,
+            et.user_id propositionTeacherId
+        FROM
+            exam_print_plan epp
+                LEFT JOIN
+            basic_semester bs ON epp.semester_id = bs.name
+                LEFT JOIN
+            exam_detail ed ON epp.id = ed.print_plan_id
+                LEFT JOIN
+            exam_detail_course edc ON ed.id = edc.exam_detail_id
+                LEFT JOIN
+            exam_task et ON edc.school_id = et.school_id
+                AND edc.paper_number = et.paper_number
+                AND edc.course_code = et.course_code
+                LEFT JOIN
+            exam_paper_structure eps ON edc.school_id = eps.school_id
+                AND edc.paper_number = eps.paper_number
+                AND edc.course_code = eps.course_code
+        WHERE
+            epp.school_id = #{schoolId}
+            and et.user_id = #{propositionTeacherId}
+            and epp.sync_status = TRUE
+    </select>
+</mapper>

+ 6 - 8
distributed-print/src/main/java/com/qmth/distributed/print/api/ExamPaperStructureController.java

@@ -58,21 +58,19 @@ public class ExamPaperStructureController {
 
     /**
      * 上传
-     * @param id
-     * @param md5 文件md5
-     * @param paperType 试卷类型
-     * @param files 文件数组
+     *
+     * @param md5       文件md5
+     * @param files     文件数组
      * @return
      */
     @ApiOperation(value = "上传试卷结构、标答")
     @RequestMapping(value = "/upload", method = RequestMethod.POST)
-    public Result upload(@RequestParam("id") Long id,
+    public Result upload(@RequestParam("examPaperStructure") String  examPaperStructure,
                          @RequestParam("md5") String md5,
-                         @RequestParam("paperType") String paperType,
                          @RequestParam("files") MultipartFile[] files) {
-        ExamPaperStructure examPaperStructure = examPaperStructureService.upload(id, md5, paperType, files);
+        ExamPaperStructure examPaper = examPaperStructureService.upload(examPaperStructure, md5, files);
         // 推送云阅卷
-        dataSyncService.uploadStructure(examPaperStructure);
+        dataSyncService.uploadStructure(examPaper);
         return ResultUtil.ok(true, null);
     }
 }

+ 0 - 7
distributed-print/src/main/java/com/qmth/distributed/print/api/SsoController.java

@@ -1,12 +1,8 @@
 package com.qmth.distributed.print.api;
 
 
-import com.qmth.boot.api.annotation.Aac;
-import com.qmth.boot.api.annotation.BOOL;
 import com.qmth.boot.api.constant.ApiConstant;
-import com.qmth.distributed.print.business.entity.ExamPaperStructure;
 import com.qmth.distributed.print.business.service.DataSyncService;
-import com.qmth.distributed.print.business.service.ExamPaperStructureService;
 import com.qmth.teachcloud.common.util.Result;
 import com.qmth.teachcloud.common.util.ResultUtil;
 import io.swagger.annotations.Api;
@@ -14,11 +10,8 @@ import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.multipart.MultipartFile;
 
-import java.util.List;
 import java.util.Map;
 
 /**

+ 40 - 48
teachcloud-common/src/main/java/com/qmth/teachcloud/common/sync/StmmsUtils.java

@@ -26,8 +26,8 @@ import java.util.Map;
 
 /**
  * 同步云阅卷接口工具类
- *
- * @Date: 2021/10/29.
+ * <p>
+ * Date: 2021/10/29.
  */
 @Component
 public class StmmsUtils {
@@ -54,7 +54,7 @@ public class StmmsUtils {
     public Long syncExam(String code, String name, String examTime) {
         String hostUrl = dictionaryConfig.syncDataDomain().getHostUrl();
         String examSaveUrl = dictionaryConfig.syncDataDomain().getExamSaveUrl();
-        validatUrl(hostUrl, examSaveUrl);
+        validUrl(hostUrl, examSaveUrl);
         String postUrl = hostUrl.concat(examSaveUrl);
         //参数
         Map<String, String> map = new HashMap<>();
@@ -88,14 +88,13 @@ public class StmmsUtils {
      * @param paperType   试卷类型
      * @param examSite    考点
      * @param examRoom    考场
-     * @return
      */
     public boolean syncStudent(String examId, String examNumber, String studentCode, String name, String college,
                                String className, String teacher, String subjectCode, String subjectName,
                                String packageCode, String paperType, String examSite, String examRoom) {
         String hostUrl = dictionaryConfig.syncDataDomain().getHostUrl();
         String studentSaveUrl = dictionaryConfig.syncDataDomain().getStudentSaveUrl();
-        validatUrl(hostUrl, studentSaveUrl);
+        validUrl(hostUrl, studentSaveUrl);
         String postUrl = hostUrl.concat(studentSaveUrl);
         try {
             //参数
@@ -133,12 +132,11 @@ public class StmmsUtils {
      * @param subjectCode 科目代码
      * @param type        文件类型  SyncFileTypeEnum枚举
      * @param file        文件
-     * @return
      */
     public boolean syncFile(String examId, String subjectCode, SyncFileTypeEnum type, File file) {
         String hostUrl = dictionaryConfig.syncDataDomain().getHostUrl();
         String fileUploadUrl = dictionaryConfig.syncDataDomain().getFileUploadUrl();
-        validatUrl(hostUrl, fileUploadUrl);
+        validUrl(hostUrl, fileUploadUrl);
         fileUploadUrl = fileUploadUrl.replace("{type}", type.name().toLowerCase());
         String postUrl = hostUrl.concat(fileUploadUrl);
         try {
@@ -185,18 +183,17 @@ public class StmmsUtils {
     /**
      * 试卷结构创建/更新接口
      *
-     * @param examId
-     * @param subjectCode
-     * @param objective
-     * @param paperType
-     * @param questions
-     * @return
+     * @param examId      考试ID
+     * @param subjectCode 科目代码
+     * @param objective   是否客观题
+     * @param paperType   试卷类型
+     * @param questions   试卷结构JSON
      */
     public boolean syncPaperStructure(String examId, String subjectCode, Boolean objective,
                                       String paperType, List<SyncStructureData> questions) {
         String hostUrl = dictionaryConfig.syncDataDomain().getHostUrl();
         String structureUrl = dictionaryConfig.syncDataDomain().getStructureUrl();
-        validatUrl(hostUrl, structureUrl);
+        validUrl(hostUrl, structureUrl);
         String postUrl = hostUrl.concat(structureUrl);
         try {
             //参数
@@ -222,7 +219,6 @@ public class StmmsUtils {
 
     /**
      * 评卷员登录
-     * @return
      */
     public Map<String, Object> markLogin(SysUser sysUser) {
         String markLoginUrl = dictionaryConfig.syncDataDomain().getMarkLoginUrl();
@@ -236,7 +232,6 @@ public class StmmsUtils {
 
     /**
      * 科组长登录
-     * @return
      */
     public Map<String, Object> markLeaderLogin(SysUser sysUser) {
         String markLeaderLoginUrl = dictionaryConfig.syncDataDomain().getMarkLeaderLoginUrl();
@@ -250,31 +245,33 @@ public class StmmsUtils {
 
     /**
      * 组装登录参数
-     * @param loginUrl
-     * @param prefix
-     * @return
+     *
+     * @param loginUrl 登录url
+     * @param prefix   账号前缀
      */
     private Map<String, Object> openLogin(SysUser sysUser, String loginUrl, String prefix) {
         String hostUrl = dictionaryConfig.syncDataDomain().getHostUrl();
-        validatUrl(hostUrl, loginUrl);
+        validUrl(hostUrl, loginUrl);
         String postUrl = hostUrl.concat(loginUrl);
 
-
-        long time = System.currentTimeMillis();
-        Map<String, Object> map = new HashMap<>();
-        map.put("redirectUrl", postUrl);
-        map.put("account", prefix + sysUser.getLoginName());
-        map.put("name", sysUser.getLoginName());
-        map.put("time", time);
-        map.put("authorization", createSign(time, loginUrl));
-        return map;
+        try {
+            long time = System.currentTimeMillis();
+            Map<String, Object> map = new HashMap<>();
+            map.put("redirectUrl", postUrl);
+            map.put("account", prefix + sysUser.getLoginName());
+            map.put("name", sysUser.getLoginName());
+            map.put("time", time);
+            map.put("authorization", createSign(time, loginUrl));
+            return map;
+        } catch (Exception e) {
+            throw ExceptionResultEnum.ERROR.exception("登录信息获取失败");
+        }
     }
 
     /**
      * http请求头
      *
-     * @param url
-     * @return
+     * @param url 请求URL
      */
     private Map<String, String> getHeaders(String url) {
         long time = System.currentTimeMillis();
@@ -287,11 +284,10 @@ public class StmmsUtils {
     /**
      * 签名
      *
-     * @param time
-     * @param url
-     * @return
+     * @param time 时间戳
+     * @param url  请求URL
      */
-    public String createSign(long time, String url) {
+    private String createSign(long time, String url) {
         Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
         BasicSchool basicSchool = commonCacheService.schoolCache(schoolId);
         if (basicSchool == null) {
@@ -301,8 +297,7 @@ public class StmmsUtils {
             throw ExceptionResultEnum.ERROR.exception("学校已禁用");
         }
 
-        String signature = SignatureEntityTest.build(SignatureType.SECRET, POST_METHOD, url, time, basicSchool.getAccessKey(), basicSchool.getAccessSecret());
-        return signature;
+        return SignatureEntityTest.build(SignatureType.SECRET, POST_METHOD, url, time, basicSchool.getAccessKey(), basicSchool.getAccessSecret());
     }
 
     /**
@@ -312,7 +307,6 @@ public class StmmsUtils {
      * @param defaulValue 默认值
      * @param require     是否必填(true:是,false:否)
      * @param name        参数名称
-     * @return
      */
     private String validParam(String value, String defaulValue, boolean require, String name) {
         if (require && StringUtils.isAnyBlank(value, defaulValue)) {
@@ -325,11 +319,10 @@ public class StmmsUtils {
     /**
      * 校验参数值并返回 (布尔型)
      *
-     * @param value
-     * @param defaulValue
-     * @param require
-     * @param name
-     * @return
+     * @param value       参数值
+     * @param defaulValue 默认值
+     * @param require     是否必填
+     * @param name        描述
      */
     private Boolean validParam(Boolean value, Boolean defaulValue, Boolean require, String name) {
         if (require && value == null && defaulValue == null) {
@@ -342,9 +335,8 @@ public class StmmsUtils {
     /**
      * 校验试卷结构值
      *
-     * @param objective
-     * @param questions
-     * @return
+     * @param objective 是否客观题
+     * @param questions 试卷结构JSON
      */
     private Object validParam(Boolean objective, List<SyncStructureData> questions) {
         for (SyncStructureData question : questions) {
@@ -362,9 +354,9 @@ public class StmmsUtils {
     /**
      * 校验url是否配置
      *
-     * @param urls
+     * @param urls URL数组
      */
-    private void validatUrl(String... urls) {
+    private void validUrl(String... urls) {
         if (StringUtils.isAnyBlank(urls)) {
             throw ExceptionResultEnum.ERROR.exception("云阅卷同步接口未正确配置");
         }