<?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.yami.shop.dao.ChannelMapper">

    <select id="selectByName" resultType="com.yami.shop.bean.model.Channel">
        select *
        from tz_channel
        where channel_name = #{channelName}
    </select>
    <select id="statisticsPage" resultType="com.yami.shop.bean.vo.ChannelVO">

        select
        c.id AS id,
        c.channel_no AS channelNo,
        c.channel_name AS channelName,
        c.type AS type,
        c.status AS status,
        c.create_time AS createTime,
        count(tu.user_id) AS staffCount,
        count(if(tu.status = 1, tu.user_id, null)) AS normalCount

        from tz_channel c left join tz_user tu on c.id = tu.channel_id
        <where>
            <if test="channel.channelName != null">
                and c.channel_name like concat('%',#{channel.channelName},'%')
            </if>
            <if test="channel.status != null">
                and c.status = #{channel.status}
            </if>
        </where>
        group by c.id

    </select>
</mapper>
