<?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.flossom.common.core.mapper.WxModeMapper">

    <resultMap type="WxMode" id="WxModeResult">
        <result property="id"    column="id"    />
        <result property="instrumentType"    column="instrument_type"    />
        <result property="instrumentModel"    column="instrument_model"    />
        <result property="modeName"    column="mode_name"    />
        <result property="modeDesc"    column="mode_desc"    />
        <result property="modeBanner"    column="mode_banner"    />
        <result property="modeVideo"    column="mode_video"    />
        <result property="modeType"    column="mode_type"    />
        <result property="modeClass"    column="mode_class"    />
        <result property="isCabinMode"    column="is_cabin_mode"    />
        <result property="modeTime"    column="mode_time"    />
        <result property="preparationVideo"    column="preparation_video"    />
        <result property="beganVideo"    column="began_video"    />
        <result property="pauseVideo"    column="pause_video"    />
        <result property="status"    column="status"    />
        <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="selectWxModeVo">
        select id, instrument_type, instrument_model, mode_name, mode_desc, mode_banner, mode_video, mode_type, mode_class, is_cabin_mode, mode_time, preparation_video, began_video, pause_video, status, create_by, create_time, update_by, update_time, remark from wx_mode
    </sql>

    <select id="selectWxModeList" parameterType="WxMode" resultMap="WxModeResult">
        <include refid="selectWxModeVo"/>
        <where>
            <if test="instrumentType != null "> and instrument_type = #{instrumentType}</if>
            <if test="instrumentModel != null  and instrumentModel != ''"> and instrument_model = #{instrumentModel}</if>
            <if test="modeName != null  and modeName != ''"> and mode_name like concat('%', #{modeName}, '%')</if>
            <if test="modeDesc != null  and modeDesc != ''"> and mode_desc = #{modeDesc}</if>
            <if test="modeBanner != null  and modeBanner != ''"> and mode_banner = #{modeBanner}</if>
            <if test="modeVideo != null  and modeVideo != ''"> and mode_video = #{modeVideo}</if>
            <if test="modeType != null "> and mode_type = #{modeType}</if>
            <if test="modeClass != null "> and mode_class = #{modeClass}</if>
            <if test="isCabinMode != null "> and is_cabin_mode = #{isCabinMode}</if>
            <if test="modeTime != null "> and mode_time = #{modeTime}</if>
            <if test="preparationVideo != null  and preparationVideo != ''"> and preparation_video = #{preparationVideo}</if>
            <if test="beganVideo != null  and beganVideo != ''"> and began_video = #{beganVideo}</if>
            <if test="pauseVideo != null  and pauseVideo != ''"> and pause_video = #{pauseVideo}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>

    <select id="selectListByInstrumentId" parameterType="Long" resultMap="WxModeResult">
        SELECT
            DISTINCT mo.*, imo.mode_sort
        FROM
            wx_mode mo
            LEFT JOIN `wx_instrument_mode` imo ON imo.mode_id = mo.id
        WHERE
            imo.instrument_id = #{instrumentId}
        ORDER BY imo.mode_sort ASC
    </select>

    <select id="selectWxModeById" parameterType="Long" resultMap="WxModeResult">
        <include refid="selectWxModeVo"/>
        where id = #{id}
    </select>

    <insert id="insertWxMode" parameterType="WxMode" useGeneratedKeys="true" keyProperty="id">
        insert into wx_mode
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="instrumentType != null">instrument_type,</if>
            <if test="instrumentModel != null">instrument_model,</if>
            <if test="modeName != null">mode_name,</if>
            <if test="modeDesc != null">mode_desc,</if>
            <if test="modeBanner != null">mode_banner,</if>
            <if test="modeVideo != null">mode_video,</if>
            <if test="modeType != null">mode_type,</if>
            <if test="modeClass != null">mode_class,</if>
            <if test="isCabinMode != null">is_cabin_mode,</if>
            <if test="modeTime != null">mode_time,</if>
            <if test="preparationVideo != null">preparation_video,</if>
            <if test="beganVideo != null">began_video,</if>
            <if test="pauseVideo != null">pause_video,</if>
            <if test="status != null">status,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="instrumentType != null">#{instrumentType},</if>
            <if test="instrumentModel != null">#{instrumentModel},</if>
            <if test="modeName != null">#{modeName},</if>
            <if test="modeDesc != null">#{modeDesc},</if>
            <if test="modeBanner != null">#{modeBanner},</if>
            <if test="modeVideo != null">#{modeVideo},</if>
            <if test="modeType != null">#{modeType},</if>
            <if test="modeClass != null">#{modeClass},</if>
            <if test="isCabinMode != null">#{isCabinMode},</if>
            <if test="modeTime != null">#{modeTime},</if>
            <if test="preparationVideo != null">#{preparationVideo},</if>
            <if test="beganVideo != null">#{beganVideo},</if>
            <if test="pauseVideo != null">#{pauseVideo},</if>
            <if test="status != null">#{status},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateWxMode" parameterType="WxMode">
        update wx_mode
        <trim prefix="SET" suffixOverrides=",">
            <if test="instrumentType != null">instrument_type = #{instrumentType},</if>
            <if test="instrumentModel != null">instrument_model = #{instrumentModel},</if>
            <if test="modeName != null">mode_name = #{modeName},</if>
            <if test="modeDesc != null">mode_desc = #{modeDesc},</if>
            <if test="modeBanner != null">mode_banner = #{modeBanner},</if>
            <if test="modeVideo != null">mode_video = #{modeVideo},</if>
            <if test="modeType != null">mode_type = #{modeType},</if>
            <if test="modeClass != null">mode_class = #{modeClass},</if>
            <if test="isCabinMode != null">is_cabin_mode = #{isCabinMode},</if>
            <if test="modeTime != null">mode_time = #{modeTime},</if>
            <if test="preparationVideo != null">preparation_video = #{preparationVideo},</if>
            <if test="beganVideo != null">began_video = #{beganVideo},</if>
            <if test="pauseVideo != null">pause_video = #{pauseVideo},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWxModeById" parameterType="Long">
        delete from wx_mode where id = #{id}
    </delete>



    <delete id="deleteWxModeByIds" parameterType="String">
        delete from wx_mode where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
