gongchunyi
6 天以前 cecd7580b5e629173bdb5b258f2676d16d580f72
src/main/resources/mapper/safe/SafeTrainingMapper.xml
@@ -30,13 +30,42 @@
        <result column="update_user" property="updateUser" />
        <result column="tenant_id" property="tenantId" />
    </resultMap>
    <sql id="trainingStateExpression">
        CASE
            WHEN CURRENT_TIMESTAMP() &lt; STR_TO_DATE(CONCAT(training_date, ' ', opening_time), '%Y-%m-%d %H:%i:%s') THEN 0
            WHEN CURRENT_TIMESTAMP() &gt;= STR_TO_DATE(CONCAT(training_date, ' ', end_time), '%Y-%m-%d %H:%i:%s') THEN 2
            ELSE 1
        END
    </sql>
    <update id="refreshTrainingState">
        UPDATE safe_training
        SET state = <include refid="trainingStateExpression"/>
        WHERE training_date IS NOT NULL
          AND opening_time IS NOT NULL
          AND end_time IS NOT NULL
          AND STR_TO_DATE(CONCAT(training_date, ' ', opening_time), '%Y-%m-%d %H:%i:%s') IS NOT NULL
          AND STR_TO_DATE(CONCAT(training_date, ' ', end_time), '%Y-%m-%d %H:%i:%s') IS NOT NULL
          AND (
              state IS NULL
              OR state != <include refid="trainingStateExpression"/>
          )
    </update>
    <select id="pageSafeTraining" resultType="com.ruoyi.safe.dto.SafeTrainingDto">
        SELECT
        st.*,
        su.nick_name AS assessmentUserName,
        COUNT(std.id) AS nums
        EXISTS(
            SELECT 1
            FROM safe_training_details signed_std
            WHERE signed_std.safe_training_id = st.id
              AND signed_std.user_id = #{c.currentUserId}
        ) AS signed,
        (
            SELECT COUNT(1)
            FROM safe_training_details nums_std
            WHERE nums_std.safe_training_id = st.id
        ) AS nums
        FROM safe_training st
        LEFT JOIN safe_training_details std ON std.safe_training_id = st.id
        LEFT JOIN sys_user su ON st.assessment_user_id = su.user_id
        WHERE st.state = #{c.state}
        <if test="c.placeTraining != null and c.placeTraining != ''">