<?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="cn.roadm.mapper.MmsChannelGroupMapper">

    <sql id="Base_Column_List">
        `id`
        ,`network`,`name`,`platform`,`biz`,`strategy`,`channels`,`weight`,`overstocks`,`modifyTime`
    </sql>
    <select id="listPageMmsChannelGroup" parameterType="cn.roadm.bo.SpChannelGroupInfo" resultType="MmsChannelGroup">
        select <include refid="Base_Column_List"/> from mms_channel_group g
        <where>
            g.status = '1'
            <if test="network != null and network != ''">
                and g.network = #{network}
            </if>
            <if test="name != null and name!=''">
                and g.name like CONCAT('%', #{name}, '%')
            </if>
            <if test="channels!=null and channels!=''">
                and CONCAT(',',channels, ',') like CONCAT('%,',#{channels}, ',%')
            </if>
        </where>
        order by g.id desc
    </select>

    <select id="getMmsChannelGroupAll" parameterType="cn.roadm.bo.SpChannelGroupInfo" resultType="MmsChannelGroup">
        select <include refid="Base_Column_List"/> from mms_channel_group g
        <where>
            g.status = '1'
            <if test="network != null and network != ''">
                and g.network = #{network}
            </if>
            <if test="name != null and name!=''">
                and g.name like CONCAT('%', #{name}, '%')
            </if>
            <if test="channels!=null and channels!=''">
                and CONCAT(',',channels, ',') like CONCAT('%,',#{channels}, ',%')
            </if>
        </where>

    </select>

    <insert id="insertMmsChannelGroup" useGeneratedKeys="true" keyProperty="id" parameterType="MmsChannelGroup">
        insert into mms_channel_group
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test = "id != null">
                id,
            </if>
            <if test = "network != '' and network!=null">
                network,
            </if>
            <if test = "name != null and name!= ''">
                `name`,
            </if>
            <if test = "platform != null and platform != ''">
                platform,
            </if>
            <if test = "biz != null and biz != ''">
                biz,
            </if>
            <if test = "strategy != null and strategy != ''">
                strategy,
            </if>
            <if test = "channels != null and channels != ''">
                channels,
            </if>
            <if test = "weight != null and weight != ''">
                weight,
            </if>
            <if test = "overstocks != null and overstocks != ''">
                overstocks,
            </if>
            modifyTime,
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test = "id != null">
                #{id, jdbcType=INTEGER},
            </if>
            <if test = "network != null">
                #{network, network=VARCHAR},
            </if>
            <if test = "name != null">
                #{name, jdbcType=VARCHAR},
            </if>
            <if test = "platform != null">
                #{platform, jdbcType=VARCHAR},
            </if>
            <if test = "biz != null">
                #{biz, jdbcType=VARCHAR},
            </if>
            <if test = "strategy != null">
                #{strategy, jdbcType=VARCHAR},
            </if>
            <if test = "channels != null">
                #{channels, jdbcType=VARCHAR},
            </if>
            <if test = "weight != null">
                #{weight, jdbcType=VARCHAR},
            </if>
            <if test = "overstocks != null and overstocks != ''">
                #{overstocks, jdbcType=VARCHAR},
            </if>
            sysdate(),
        </trim>
    </insert>

    <update id="updateMmsChannelGroup" parameterType="MmsChannelGroup">
        update mms_channel_group
        <set>
            <if test = "name != null and name != ''">
                `name` = #{name, jdbcType=VARCHAR},
            </if>
            <if test = "network != null and network != ''">
                network = #{network, jdbcType=VARCHAR},
            </if>
            <if test = "platform != null and platform != ''">
                platform = #{platform, jdbcType=VARCHAR},
            </if>
            <if test = "biz != null and biz != ''">
                biz = #{biz, jdbcType=VARCHAR},
            </if>
            <if test = "strategy != null and strategy != ''">
                strategy = #{strategy, jdbcType=VARCHAR},
            </if>
            <if test = "status != null and status != ''">
                status = #{status, jdbcType=INTEGER},
            </if>
            <if test = "channels != null and status != ''">
                channels = #{channels, jdbcType=VARCHAR},
            </if>
            <if test = "weight != null and weight != ''">
                weight = #{weight, jdbcType=VARCHAR},
            </if>
            <if test = "overstocks != null and overstocks != ''">
                overstocks = #{overstocks, jdbcType=VARCHAR},
            </if>
            modifyTime = sysdate(),
        </set>
        where id = #{id, jdbcType=INTEGER}
    </update>

    <update id="delMmsGroup" parameterType="int">
        update mms_channel_group set status=0 where id=#{id}
    </update>

    <select id="seleteById" resultType="MmsChannelGroup" parameterType="int">
        select <include refid="Base_Column_List"/> from mms_channel_group g
        where
        g.status = '1' and g.id = #{id}
    </select>
</mapper>
