<?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.ruoyi.web.modules.technology.mapper.BizPracticalTrainingMapper">

    <resultMap type="com.ruoyi.web.modules.technology.domain.BizPracticalTraining" id="BizPracticalTrainingResult">
        <id     property="id"                      column="id"/>
        <result property="trainingTopic"           column="training_topic"/>
        <result property="trainingTime"            column="training_time"/>
        <result property="trainingIntro"           column="training_intro"/>
        <result property="plannedHeadCount"        column="planned_head_count"/>
        <result property="trainingLocation"        column="training_location"/>
        <result property="expectedOutcome"         column="expected_outcome"/>
        <result property="registrationStartTime"   column="registration_start_time"/>
        <result property="registrationEndTime"     column="registration_end_time"/>
        <result property="coverFileUrl"            column="cover_file_url"/>
        <result property="coverFilePath"           column="cover_file_path"/>
        <result property="actualEnrolledCount"     column="actual_enrolled_count"/>
        <result property="trainingStatus"          column="training_status"/>
        <result property="publishStatus"           column="publish_status"/>
        <result property="publishTime"             column="publish_time"/>
        <result property="offlineTime"             column="offline_time"/>
        <result property="delFlag"                 column="del_flag"/>
        <result property="createBy"                column="create_by"/>
        <result property="createTime"              column="create_time"/>
        <result property="updateBy"                column="update_by"/>
        <result property="updateTime"              column="update_time"/>
        <result property="remark"                  column="remark"/>
    </resultMap>

    <sql id="selectVo">
        select id, training_topic, training_time, training_intro, planned_head_count,
               training_location, expected_outcome, registration_start_time, registration_end_time,
               cover_file_url, cover_file_path, actual_enrolled_count, training_status,
               publish_status, publish_time, offline_time, del_flag,
               create_by, create_time, update_by, update_time, remark
        from biz_practical_training
    </sql>

    <select id="selectBizPracticalTrainingById" parameterType="long" resultMap="BizPracticalTrainingResult">
        <include refid="selectVo"/>
        where id = #{id} and del_flag = '0'
    </select>

    <select id="selectBizPracticalTrainingByIdAny" parameterType="long" resultMap="BizPracticalTrainingResult">
        <include refid="selectVo"/>
        where id = #{id}
    </select>

    <select id="selectBizPracticalTrainingList" parameterType="com.ruoyi.web.modules.technology.domain.BizPracticalTraining" resultMap="BizPracticalTrainingResult">
        <include refid="selectVo"/>
        <where>
            del_flag = '0'
            <if test="trainingTopic != null and trainingTopic != ''">
                and training_topic = #{trainingTopic}
            </if>
            <if test="startDate != null and startDate != ''">
                and date(training_time) &gt;= #{startDate}
            </if>
            <if test="endDate != null and endDate != ''">
                and date(training_time) &lt;= #{endDate}
            </if>
        </where>
        order by training_time desc, id desc
    </select>

    <insert id="insertBizPracticalTraining" parameterType="com.ruoyi.web.modules.technology.domain.BizPracticalTraining" useGeneratedKeys="true" keyProperty="id">
        insert into biz_practical_training (
            training_topic, training_time, training_intro, planned_head_count,
            training_location, expected_outcome, registration_start_time, registration_end_time,
            cover_file_url, cover_file_path, actual_enrolled_count, training_status,
            publish_status, publish_time, offline_time, del_flag,
            create_by, create_time, remark
        ) values (
            #{trainingTopic}, #{trainingTime}, #{trainingIntro}, #{plannedHeadCount},
            #{trainingLocation}, #{expectedOutcome}, #{registrationStartTime}, #{registrationEndTime},
            #{coverFileUrl}, #{coverFilePath}, #{actualEnrolledCount}, #{trainingStatus},
            #{publishStatus}, #{publishTime}, #{offlineTime}, #{delFlag},
            #{createBy}, sysdate(), #{remark}
        )
    </insert>

    <update id="updateBizPracticalTraining" parameterType="com.ruoyi.web.modules.technology.domain.BizPracticalTraining">
        update biz_practical_training set
            training_topic = #{trainingTopic},
            training_time = #{trainingTime},
            training_intro = #{trainingIntro},
            planned_head_count = #{plannedHeadCount},
            training_location = #{trainingLocation},
            expected_outcome = #{expectedOutcome},
            registration_start_time = #{registrationStartTime},
            registration_end_time = #{registrationEndTime},
            cover_file_url = #{coverFileUrl},
            cover_file_path = #{coverFilePath},
            actual_enrolled_count = #{actualEnrolledCount},
            training_status = #{trainingStatus},
            publish_status = #{publishStatus},
            publish_time = #{publishTime},
            offline_time = #{offlineTime},
            update_by = #{updateBy},
            update_time = sysdate(),
            remark = #{remark}
        where id = #{id} and del_flag = '0'
    </update>

    <select id="selectPublishedBizPracticalTrainingById" parameterType="long" resultMap="BizPracticalTrainingResult">
        <include refid="selectVo"/>
        where id = #{id} and del_flag = '0' and publish_status = 1
    </select>

    <update id="updateTrainingStatusAndCount" parameterType="com.ruoyi.web.modules.technology.domain.BizPracticalTraining">
        update biz_practical_training set
            actual_enrolled_count = #{actualEnrolledCount},
            training_status = #{trainingStatus},
            update_time = sysdate()
        where id = #{id} and del_flag = '0'
    </update>

    <update id="logicDeleteBizPracticalTrainingByIds">
        update biz_practical_training set del_flag = '2', update_by = #{updateBy}, update_time = sysdate()
        where del_flag = '0' and publish_status = 0 and id in
        <foreach collection="ids" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
</mapper>
