Răsfoiți Sursa

考试可以根据状态查询;sql实时计算考试状态

yangfeng 1 an în urmă
părinte
comite
2e98dab991

+ 1 - 0
web/src/main/java/com/ynfy/app/api/v1/controller/ApiExamController.java

@@ -60,6 +60,7 @@ public class ApiExamController extends ApiBaseController {
         Page<Exam> page = new Page<>(dto.getPageNo(), dto.getPageSize());
         Exam exam = new Exam();
         exam.setTitle(dto.getExamTitle());
+        exam.setState(dto.getState());
         LoginUser user = sysUserService.getLoginUser(TokenUtil.getToken(request));
         IPage<Exam> pageList = examService.selectExamList(page, exam, user);
         return Result.OK(pageList);

+ 2 - 0
web/src/main/java/com/ynfy/app/api/v1/entity/dto/ExamDTO.java

@@ -9,6 +9,8 @@ public class ExamDTO {
 
     private String examTitle;
 
+    private Integer state;
+
     private Integer pageNo;
 
     private Integer pageSize;

+ 0 - 24
web/src/main/java/com/ynfy/buss/exam/exam/entity/Exam.java

@@ -202,28 +202,4 @@ public class Exam implements Serializable {
     @ApiModelProperty(value = "是否通过")
     private Integer passed;
 
-    /**
-     * 是否结束
-     *
-     * @return
-     */
-    public Integer getState() {
-        if (!Objects.isNull(startTime)) {
-            if (System.currentTimeMillis() < startTime.getTime()) {
-                return ExamState.READY_START;
-            }
-        }
-        if (!Objects.isNull(endTime)) {
-            if (System.currentTimeMillis() > endTime.getTime()) {
-                return ExamState.OVERDUE;
-            }
-        }
-        if (!Objects.isNull(startTime) && !Objects.isNull(endTime)) {
-            if (System.currentTimeMillis() > startTime.getTime()
-                    && System.currentTimeMillis() < endTime.getTime()) {
-                return ExamState.ENABLE;
-            }
-        }
-        return null;
-    }
 }

+ 21 - 5
web/src/main/java/com/ynfy/buss/exam/exam/mapper/xml/ExamMapper.xml

@@ -31,7 +31,8 @@
                 p.create_by,
                 p.create_time,
                 p.question_count,
-                p.has_subjective
+                p.has_subjective,
+                <include refid="stateCondition" />
         FROM exam e
         LEFT JOIN paper p on e.paper_id = p.id
         <where>
@@ -63,6 +64,7 @@
         <result column="image" property="image" jdbcType="VARCHAR"/>
         <result column="exam_result_showtype" property="examResultShowtype" jdbcType="INTEGER"/>
         <result column="show_deadline" property="showDeadline" jdbcType="INTEGER"/>
+        <result column="state" property="state" jdbcType="INTEGER"/>
 
         <association property="paper" javaType="com.ynfy.buss.exam.paper.entity.Paper">
             <id column="paper_id" property="id" jdbcType="VARCHAR"/>
@@ -89,7 +91,8 @@
         FROM
         (
             SELECT
-                    *
+                    *,
+                    <include refid="stateCondition" />
             FROM exam
             WHERE
                 open_type = 1
@@ -97,7 +100,8 @@
                 <when test="user!=null and user.orgCode!=null and user.orgCode!=''">
                 UNION
                     SELECT
-                            *
+                            *,
+                            <include refid="stateCondition" />
                     FROM exam
                     WHERE
                         open_type = 2
@@ -106,7 +110,8 @@
                 <when test="user!=null and user.username!=null and user.username!=''">
                 UNION
                     SELECT
-                        *
+                            *,
+                            <include refid="stateCondition" />
                     FROM exam
                     WHERE
                         open_type = 3
@@ -119,7 +124,7 @@
                 LEFT JOIN (
                     SELECT
                         exam_id,
-                        COUNT ( * ) AS try_count
+                        COUNT(*) AS try_count
                     FROM
                         user_exam uer
                     WHERE
@@ -138,6 +143,9 @@
             <if test="exam.openType!=null">
                 AND tmp1.open_type = #{exam.openType}
             </if>
+            <if test="exam.state!=null">
+                AND tmp1.state = #{exam.state}
+            </if>
         </where>
     </select>
 
@@ -182,4 +190,12 @@
             LIMIT #{limit}
         </if>
     </select>
+    <sql id="stateCondition">
+        CASE
+        WHEN NOW() &lt; START_TIME THEN 2
+        WHEN NOW() &gt; end_TIME THEN 3
+        WHEN NOW() &gt; START_TIME AND NOW() &lt; end_TIME THEN 0
+        ELSE NULL
+        END AS state
+    </sql>
 </mapper>