<?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.neusoft.smart.pos.advertisement.persistent.mapper.MediaStrategyMapper">
    <resultMap id="BaseResultMap" type="com.neusoft.smart.pos.advertisement.persistent.domain.MediaStrategy">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="strategy_id" jdbcType="INTEGER" property="strategyId"/>
        <result column="device_id" jdbcType="INTEGER" property="deviceId"/>
        <result column="media_resource_id" jdbcType="INTEGER" property="mediaResourceId"/>
        <result column="play_length" jdbcType="INTEGER" property="playLength"/>
        <result column="show_time_begin" jdbcType="TIME" property="showTimeBegin"/>
        <result column="show_time_end" jdbcType="TIME" property="showTimeEnd"/>
        <result column="background_audio_id" jdbcType="INTEGER" property="backgroundAudioId"/>
        <result column="status" jdbcType="INTEGER" property="status"/>
    </resultMap>
    <sql id="Example_Where_Clause">
        <where>
            <foreach collection="oredCriteria" item="criteria" separator="or">
                <if test="criteria.valid">
                    <trim prefix="(" prefixOverrides="and" suffix=")">
                        <foreach collection="criteria.criteria" item="criterion">
                            <choose>
                                <when test="criterion.noValue">
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue">
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue">
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue">
                                    and ${criterion.condition}
                                    <foreach close=")" collection="criterion.value" item="listItem" open="("
                                             separator=",">
                                        #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
    <sql id="Update_By_Example_Where_Clause">
        <where>
            <foreach collection="example.oredCriteria" item="criteria" separator="or">
                <if test="criteria.valid">
                    <trim prefix="(" prefixOverrides="and" suffix=")">
                        <foreach collection="criteria.criteria" item="criterion">
                            <choose>
                                <when test="criterion.noValue">
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue">
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue">
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue">
                                    and ${criterion.condition}
                                    <foreach close=")" collection="criterion.value" item="listItem" open="("
                                             separator=",">
                                        #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
    <sql id="Base_Column_List">
        id, strategy_id, device_id, media_resource_id, play_length, show_time_begin, show_time_end,
        background_audio_id, status
    </sql>
    <select id="selectByExample"
            parameterType="com.neusoft.smart.pos.advertisement.persistent.domain.MediaStrategyExample"
            resultMap="BaseResultMap">
        select
        <if test="distinct">
            distinct
        </if>
        <include refid="Base_Column_List"/>
        from media_strategy
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
        <if test="orderByClause != null">
            order by ${orderByClause}
        </if>
        <if test="offset != null and limit != null">
            limit ${offset}, ${limit}
        </if>
    </select>
    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from media_strategy
        where id = #{id,jdbcType=INTEGER}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        delete from media_strategy
        where id = #{id,jdbcType=INTEGER}
    </delete>
    <delete id="deleteByExample"
            parameterType="com.neusoft.smart.pos.advertisement.persistent.domain.MediaStrategyExample">
        delete from media_strategy
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </delete>
    <insert id="insert" keyColumn="id" keyProperty="id"
            parameterType="com.neusoft.smart.pos.advertisement.persistent.domain.MediaStrategy" useGeneratedKeys="true">
        insert into media_strategy (strategy_id, device_id, media_resource_id,
        play_length, show_time_begin, show_time_end,
        background_audio_id, status)
        values (#{strategyId,jdbcType=INTEGER}, #{deviceId,jdbcType=INTEGER}, #{mediaResourceId,jdbcType=INTEGER},
        #{playLength,jdbcType=INTEGER}, #{showTimeBegin,jdbcType=TIME}, #{showTimeEnd,jdbcType=TIME},
        #{backgroundAudioId,jdbcType=INTEGER}, #{status,jdbcType=INTEGER})
    </insert>
    <insert id="insertSelective" keyColumn="id" keyProperty="id"
            parameterType="com.neusoft.smart.pos.advertisement.persistent.domain.MediaStrategy" useGeneratedKeys="true">
        insert into media_strategy
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="strategyId != null">
                strategy_id,
            </if>
            <if test="deviceId != null">
                device_id,
            </if>
            <if test="mediaResourceId != null">
                media_resource_id,
            </if>
            <if test="playLength != null">
                play_length,
            </if>
            <if test="showTimeBegin != null">
                show_time_begin,
            </if>
            <if test="showTimeEnd != null">
                show_time_end,
            </if>
            <if test="backgroundAudioId != null">
                background_audio_id,
            </if>
            <if test="status != null">
                status,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="strategyId != null">
                #{strategyId,jdbcType=INTEGER},
            </if>
            <if test="deviceId != null">
                #{deviceId,jdbcType=INTEGER},
            </if>
            <if test="mediaResourceId != null">
                #{mediaResourceId,jdbcType=INTEGER},
            </if>
            <if test="playLength != null">
                #{playLength,jdbcType=INTEGER},
            </if>
            <if test="showTimeBegin != null">
                #{showTimeBegin,jdbcType=TIME},
            </if>
            <if test="showTimeEnd != null">
                #{showTimeEnd,jdbcType=TIME},
            </if>
            <if test="backgroundAudioId != null">
                #{backgroundAudioId,jdbcType=INTEGER},
            </if>
            <if test="status != null">
                #{status,jdbcType=INTEGER},
            </if>
        </trim>
    </insert>
    <select id="countByExample"
            parameterType="com.neusoft.smart.pos.advertisement.persistent.domain.MediaStrategyExample"
            resultType="java.lang.Integer">
        select count(*) from media_strategy
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </select>
    <update id="updateByExampleSelective" parameterType="map">
        update media_strategy
        <set>
            <if test="record.id != null">
                id = #{record.id,jdbcType=INTEGER},
            </if>
            <if test="record.strategyId != null">
                strategy_id = #{record.strategyId,jdbcType=INTEGER},
            </if>
            <if test="record.deviceId != null">
                device_id = #{record.deviceId,jdbcType=INTEGER},
            </if>
            <if test="record.mediaResourceId != null">
                media_resource_id = #{record.mediaResourceId,jdbcType=INTEGER},
            </if>
            <if test="record.playLength != null">
                play_length = #{record.playLength,jdbcType=INTEGER},
            </if>
            <if test="record.showTimeBegin != null">
                show_time_begin = #{record.showTimeBegin,jdbcType=TIME},
            </if>
            <if test="record.showTimeEnd != null">
                show_time_end = #{record.showTimeEnd,jdbcType=TIME},
            </if>
            <if test="record.backgroundAudioId != null">
                background_audio_id = #{record.backgroundAudioId,jdbcType=INTEGER},
            </if>
            <if test="record.status != null">
                status = #{record.status,jdbcType=INTEGER},
            </if>
        </set>
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
    </update>
    <update id="updateByExample" parameterType="map">
        update media_strategy
        set id = #{record.id,jdbcType=INTEGER},
        strategy_id = #{record.strategyId,jdbcType=INTEGER},
        device_id = #{record.deviceId,jdbcType=INTEGER},
        media_resource_id = #{record.mediaResourceId,jdbcType=INTEGER},
        play_length = #{record.playLength,jdbcType=INTEGER},
        show_time_begin = #{record.showTimeBegin,jdbcType=TIME},
        show_time_end = #{record.showTimeEnd,jdbcType=TIME},
        background_audio_id = #{record.backgroundAudioId,jdbcType=INTEGER},
        status = #{record.status,jdbcType=INTEGER}
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
    </update>
    <update id="updateByPrimaryKeySelective"
            parameterType="com.neusoft.smart.pos.advertisement.persistent.domain.MediaStrategy">
        update media_strategy
        <set>
            <if test="strategyId != null">
                strategy_id = #{strategyId,jdbcType=INTEGER},
            </if>
            <if test="deviceId != null">
                device_id = #{deviceId,jdbcType=INTEGER},
            </if>
            <if test="mediaResourceId != null">
                media_resource_id = #{mediaResourceId,jdbcType=INTEGER},
            </if>
            <if test="playLength != null">
                play_length = #{playLength,jdbcType=INTEGER},
            </if>
            <if test="showTimeBegin != null">
                show_time_begin = #{showTimeBegin,jdbcType=TIME},
            </if>
            <if test="showTimeEnd != null">
                show_time_end = #{showTimeEnd,jdbcType=TIME},
            </if>
            <if test="backgroundAudioId != null">
                background_audio_id = #{backgroundAudioId,jdbcType=INTEGER},
            </if>
            <if test="status != null">
                status = #{status,jdbcType=INTEGER},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.neusoft.smart.pos.advertisement.persistent.domain.MediaStrategy">
        update media_strategy
        set strategy_id = #{strategyId,jdbcType=INTEGER},
        device_id = #{deviceId,jdbcType=INTEGER},
        media_resource_id = #{mediaResourceId,jdbcType=INTEGER},
        play_length = #{playLength,jdbcType=INTEGER},
        show_time_begin = #{showTimeBegin,jdbcType=TIME},
        show_time_end = #{showTimeEnd,jdbcType=TIME},
        background_audio_id = #{backgroundAudioId,jdbcType=INTEGER},
        status = #{status,jdbcType=INTEGER}
        where id = #{id,jdbcType=INTEGER}
    </update>
    <insert id="batchInsert">
        <if test="items.get(0) != null">
            insert into media_strategy (strategy_id, device_id, media_resource_id,
            play_length, show_time_begin, show_time_end,
            background_audio_id, status)
            values
            <foreach collection="items" item="item" index="index" separator=",">
                (#{item.strategyId,jdbcType=INTEGER}, #{item.deviceId,jdbcType=INTEGER},
                #{item.mediaResourceId,jdbcType=INTEGER},
                #{item.playLength,jdbcType=INTEGER}, #{item.showTimeBegin,jdbcType=TIME},
                #{item.showTimeEnd,jdbcType=TIME},
                #{item.backgroundAudioId,jdbcType=INTEGER}, #{item.status,jdbcType=INTEGER})
            </foreach>
        </if>
    </insert>
</mapper>