Kaynağa Gözat

任务接口

wangliang 5 yıl önce
ebeveyn
işleme
919ad71726

+ 54 - 0
themis-backend/src/main/java/com/qmth/themis/backend/api/TBTaskHistoryController.java

@@ -0,0 +1,54 @@
+package com.qmth.themis.backend.api;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.qmth.themis.business.constant.SystemConstant;
+import com.qmth.themis.business.entity.TBTaskHistory;
+import com.qmth.themis.business.enums.TaskTypeEnum;
+import com.qmth.themis.business.service.TBTaskHistoryService;
+import com.qmth.themis.common.enums.ExceptionResultEnum;
+import com.qmth.themis.common.exception.BusinessException;
+import com.qmth.themis.common.util.Result;
+import com.qmth.themis.common.util.ResultUtil;
+import io.swagger.annotations.*;
+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 javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * @Description: 任务 前端控制器
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2020/6/25
+ */
+@Api(tags = "任务Controller")
+@RestController
+@RequestMapping("/${prefix.url.admin}/task")
+public class TBTaskHistoryController {
+
+    @Resource
+    TBTaskHistoryService tbTaskHistoryService;
+
+    @ApiOperation(value = "任务查询接口")
+    @RequestMapping(value = "/query", method = RequestMethod.GET)
+    @ApiResponses({@ApiResponse(code = 200, message = "任务信息", response = TBTaskHistory.class)})
+    public Result query(@ApiParam(value = "任务id", required = false) @RequestParam(required = false) Long id, @ApiParam(value = "业务对象id", required = false) @RequestParam(required = false) Long entityId, @ApiParam(value = "任务类型", required = true) @RequestParam Integer type, @ApiParam(value = "任务状态", required = false) @RequestParam(required = false) Integer status, @ApiParam(value = "分页页码", required = true) @RequestParam int pageNumber, @ApiParam(value = "分页数", required = true) @RequestParam int pageSize) {
+        if (Objects.isNull(type) || Objects.equals(type, "")) {
+            throw new BusinessException(ExceptionResultEnum.TASK_TYPE_IS_NULL);
+        }
+        if (Objects.isNull(TaskTypeEnum.convertToName(type))) {
+            throw new BusinessException(ExceptionResultEnum.TASK_TYPE_ERROR);
+        }
+        IPage<Map> teExamStudentIPage = tbTaskHistoryService.taskQuery(new Page<>(pageNumber, pageSize), id, entityId, type, status);
+        Map map = new HashMap<>();
+        map.put(SystemConstant.RECORDS, teExamStudentIPage);
+        return ResultUtil.ok(map);
+    }
+}

+ 15 - 0
themis-business/src/main/java/com/qmth/themis/business/dao/TBTaskHistoryMapper.java

@@ -1,8 +1,12 @@
 package com.qmth.themis.business.dao;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.qmth.themis.business.entity.TBTaskHistory;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.Map;
 
 /**
  * @Description: 异步任务 Mapper 接口
@@ -14,4 +18,15 @@ import org.apache.ibatis.annotations.Mapper;
 @Mapper
 public interface TBTaskHistoryMapper extends BaseMapper<TBTaskHistory> {
 
+    /**
+     * 查询任务
+     *
+     * @param iPage
+     * @param taskId
+     * @param entityId
+     * @param type
+     * @param status
+     * @return
+     */
+    public IPage<Map> taskQuery(IPage<Map> iPage, @Param("taskId") Long taskId, @Param("entityId") Long entityId, @Param("type") Integer type, @Param("status") Integer status);
 }

+ 42 - 0
themis-business/src/main/java/com/qmth/themis/business/enums/TaskTypeEnum.java

@@ -1,5 +1,7 @@
 package com.qmth.themis.business.enums;
 
+import java.util.Objects;
+
 /**
  * @Description: 任务类型
  * @Param:
@@ -43,4 +45,44 @@ public enum TaskTypeEnum {
     public int getId() {
         return id;
     }
+
+    /**
+     * 状态转换 toId
+     *
+     * @param value
+     * @return
+     */
+    public static int convertToId(String value) {
+        if (Objects.equals(value.trim(), calculate_exam_score.name())) {
+            return calculate_exam_score.getId();
+        } else if (Objects.equals(value.trim(), import_exam_student.name())) {
+            return import_exam_student.getId();
+        } else if (Objects.equals(value.trim(), import_exam_paper.name())) {
+            return import_exam_paper.getId();
+        } else if (Objects.equals(value.trim(), import_invigilate_user.name())) {
+            return import_invigilate_user.getId();
+        } else {
+            return export_invigilate_user.getId();
+        }
+    }
+
+    /**
+     * 状态转换 toName
+     *
+     * @param value
+     * @return
+     */
+    public static String convertToName(int value) {
+        if (value == calculate_exam_score.getId()) {
+            return calculate_exam_score.name();
+        } else if (value == import_exam_student.getId()) {
+            return import_exam_student.name();
+        } else if (value == import_exam_paper.getId()) {
+            return import_exam_paper.name();
+        } else if (value == import_invigilate_user.getId()) {
+            return import_invigilate_user.name();
+        } else {
+            return export_invigilate_user.name();
+        }
+    }
 }

+ 15 - 0
themis-business/src/main/java/com/qmth/themis/business/service/TBTaskHistoryService.java

@@ -1,7 +1,11 @@
 package com.qmth.themis.business.service;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.themis.business.entity.TBTaskHistory;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.Map;
 
 /**
  * @Description: 异步任务 服务类
@@ -12,4 +16,15 @@ import com.qmth.themis.business.entity.TBTaskHistory;
  */
 public interface TBTaskHistoryService extends IService<TBTaskHistory> {
 
+    /**
+     * 查询任务
+     *
+     * @param iPage
+     * @param taskId
+     * @param entityId
+     * @param type
+     * @param status
+     * @return
+     */
+    public IPage<Map> taskQuery(IPage<Map> iPage, Long taskId, Long entityId, Integer type, Integer status);
 }

+ 21 - 0
themis-business/src/main/java/com/qmth/themis/business/service/impl/TBTaskHistoryServiceImpl.java

@@ -1,11 +1,15 @@
 package com.qmth.themis.business.service.impl;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.themis.business.dao.TBTaskHistoryMapper;
 import com.qmth.themis.business.entity.TBTaskHistory;
 import com.qmth.themis.business.service.TBTaskHistoryService;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
+import java.util.Map;
+
 /**
  * @Description: 异步任务 服务实现类
  * @Param:
@@ -16,4 +20,21 @@ import org.springframework.stereotype.Service;
 @Service
 public class TBTaskHistoryServiceImpl extends ServiceImpl<TBTaskHistoryMapper, TBTaskHistory> implements TBTaskHistoryService {
 
+    @Resource
+    TBTaskHistoryMapper tbTaskHistoryMapper;
+
+    /**
+     * 查询任务
+     *
+     * @param iPage
+     * @param taskId
+     * @param entityId
+     * @param type
+     * @param status
+     * @return
+     */
+    @Override
+    public IPage<Map> taskQuery(IPage<Map> iPage, Long taskId, Long entityId, Integer type, Integer status) {
+        return tbTaskHistoryMapper.taskQuery(iPage, taskId, entityId, type, status);
+    }
 }

+ 38 - 0
themis-business/src/main/resources/mapper/TBTaskHistoryMapper.xml

@@ -2,4 +2,42 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.qmth.themis.business.dao.TBTaskHistoryMapper">
 
+    <select id="taskQuery" resultType="java.util.Map">
+        select
+            tbth.id,
+            tbth.`type`,
+            tbth.entity_id as entityid,
+            tbth.status,
+            tbth.summary,
+            tbth.progress,
+            ISNULL(tbth.result_file_path) as hasResultFile,
+            ISNULL(tbth.error_file_path) as hasErrorFile,
+            tbth.create_time as createTime,
+            tbth.start_time as startTime,
+            tbth.finish_time as finishTime,
+            tbth.create_id as createId,
+            (
+            select
+                tbu.name
+            from
+                t_b_user tbu
+            where
+                tbu.id = tbth.create_id) as createName
+        from
+            t_b_task_history tbth
+            <where>
+                <if test="taskId != null and taskId != ''">
+                    and tbth.id = #{taskId}
+                </if>
+                <if test="entityId != null and entityId != ''">
+                    and tbth.entity_id = #{entityId}
+                </if>
+                <if test="type != null and type != '' or type == 0">
+                    and tbth.`type` = #{type}
+                </if>
+                <if test="status != null and status != '' or status == 0">
+                    and tbth.`status` = #{status}
+                </if>
+            </where>
+    </select>
 </mapper>

+ 4 - 0
themis-common/src/main/java/com/qmth/themis/common/enums/ExceptionResultEnum.java

@@ -26,6 +26,10 @@ public enum ExceptionResultEnum {
 
     TASK_ID_IS_NULL("102", "任务id不能为空"),
 
+    TASK_TYPE_IS_NULL("102", "任务类型不能为空"),
+
+    TASK_TYPE_ERROR("102", "任务类型不匹配"),
+
     EXAM_ID_IS_NULL("102", "考试批次id不能为空"),
 
     EXAM_INFO_IS_NULL("102", "考试批次信息不能为空"),