Browse Source

课程增加状态

yangfeng 1 year ago
parent
commit
eab7ae2616

+ 4 - 0
web/src/main/java/com/ynfy/buss/course/course/entity/Course.java

@@ -266,4 +266,8 @@ public class Course implements Serializable {
      */
     @TableField(exist = false)
     private Integer learnerNumber;
+
+    @TableField(exist = false)
+    @Dict(dicCode = "exam_state")
+    private Integer state;
 }

+ 35 - 25
web/src/main/java/com/ynfy/buss/course/course/mapper/xml/CourseMapper.xml

@@ -5,11 +5,12 @@
         SELECT
             tmp1.*,
             u.realname AS teacherName,
-            tmp2.learner_number
+            tmp2.learner_number,
+            <include refid="stateCondition"/>
         FROM
         (
             SELECT
-            *
+                *
             FROM course
             WHERE
                 open_type = 1
@@ -34,16 +35,16 @@
         ) tmp1
         LEFT JOIN
         (
-        SELECT
-        cc.course_id,
-        count(
-        DISTINCT (ucc.user_id)) AS learner_number
-        FROM
-        user_course_catalog ucc
-        LEFT JOIN
-        course_catalog cc ON ucc.course_catalog_id = cc.id
-        GROUP BY
-        cc.course_id
+            SELECT
+                cc.course_id,
+                count(
+                DISTINCT (ucc.user_id)) AS learner_number
+            FROM
+                user_course_catalog ucc
+            LEFT JOIN
+                course_catalog cc ON ucc.course_catalog_id = cc.id
+            GROUP BY
+                cc.course_id
         ) tmp2
         ON tmp1.id = tmp2.course_id
         LEFT JOIN sys_user u on tmp1.teacher_id=u.id
@@ -74,27 +75,36 @@
 
     <select id="listHotCourse" resultType="com.ynfy.buss.course.course.entity.Course">
         SELECT
-        c.*,
-        tmp.learn_number
+            c.*,
+            tmp.learn_number
         FROM
-        course c
+            course c
         LEFT JOIN
         (
-        SELECT
-        cc.course_id,
-        count(
-        DISTINCT ( ucc.user_id )) AS learn_number
-        FROM
-        user_course_catalog ucc
-        LEFT JOIN course_catalog cc ON ucc.course_catalog_id = cc.id
-        GROUP BY
-        cc.course_id
+            SELECT
+                cc.course_id,
+                count(
+                DISTINCT ( ucc.user_id )) AS learn_number
+            FROM
+                user_course_catalog ucc
+            LEFT JOIN course_catalog cc ON ucc.course_catalog_id = cc.id
+            GROUP BY
+                cc.course_id
         ) tmp
         ON c.id = tmp.course_id
         ORDER BY
-        tmp.learn_number DESC
+            tmp.learn_number DESC
         <if test="limit !=null">
             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>

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

@@ -3,36 +3,36 @@
 <mapper namespace="com.ynfy.buss.exam.exam.mapper.ExamMapper">
     <select id="detail" resultMap="examMap">
         SELECT
-        e.id,
-        e.title,
-        e.open_type,
-        e.start_time,
-        e.end_time,
-        e.total_score as exam_total_score,
-        e.qualify_score,
-        e.total_time,
-        e.leave_on,
-        e.total_leave_times,
-        e.leave_time,
-        p.id as exam_paper_id,
-        e.limit_count,
-        e.examiner,
-        e.reviewer,
-        e.reviewer_type,
-        e.question_disorder,
-        e.answer_disorder,
-        e.image,
-        e.exam_result_showtype,
-        e.show_deadline,
-        p.id as paper_id,
-        p.title as paperName,
-        p.total_score,
-        p.join_type,
-        p.create_by,
-        p.create_time,
-        p.question_count,
-        p.has_subjective,
-        <include refid="stateCondition"/>
+            e.id,
+            e.title,
+            e.open_type,
+            e.start_time,
+            e.end_time,
+            e.total_score as exam_total_score,
+            e.qualify_score,
+            e.total_time,
+            e.leave_on,
+            e.total_leave_times,
+            e.leave_time,
+            p.id as exam_paper_id,
+            e.limit_count,
+            e.examiner,
+            e.reviewer,
+            e.reviewer_type,
+            e.question_disorder,
+            e.answer_disorder,
+            e.image,
+            e.exam_result_showtype,
+            e.show_deadline,
+            p.id as paper_id,
+            p.title as paperName,
+            p.total_score,
+            p.join_type,
+            p.create_by,
+            p.create_time,
+            p.question_count,
+            p.has_subjective,
+            <include refid="stateCondition"/>
         FROM exam e
         LEFT JOIN paper p on e.paper_id = p.id
         <where>
@@ -91,8 +91,8 @@
         FROM
         (
         SELECT
-        *,
-        <include refid="stateCondition"/>
+            *,
+            <include refid="stateCondition"/>
         FROM exam
         WHERE
             open_type = 1