<?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.unis.basic.info.modular.usercollect.mapper.UserCollectMapper">

    <select id="selectByUserId" resultType="com.unis.basic.info.modular.usercollect.vo.UserCollectVO">

        SELECT
            t1.id id,
            t1.NAME NAME,
            t1.PASSWORD,
            t1.phone,
            t1.address,
            GROUP_CONCAT( t2.price_monitor_id ) AS price_monitor_id,
            GROUP_CONCAT( t3.NAME ) AS priceMonitorName,
            t4.NAME orgName,
            t4.id orgId
        FROM
            biz_user_collect t1
                LEFT JOIN biz_user_price t2 ON t1.id = t2.user_collect_id
                LEFT JOIN biz_price_monitor t3 ON t2.price_monitor_id = t3.id
                LEFT JOIN sys_org t4 ON t3.sys_org_id = t4.id
        WHERE
            t1.id = #{id}
        GROUP BY
            t1.id,
            t1.NAME,
            t1.PASSWORD,
            t1.phone,
            t1.address,
            t4.NAME,
            t4.id

    </select>


    <select id="selectUserPage" resultType="com.unis.basic.info.modular.usercollect.vo.UserCollectVO">
        select t1.id id, t1.name name, t1.phone, t4.NAME orgName,t4.id orgId
        from biz_user_collect t1
        left join biz_user_price t2 on t1.id = t2.user_collect_id
        left join biz_price_monitor t3 on t2.price_monitor_id = t3.id
        left join sys_org t4 on t3.sys_org_id = t4.ID
        <where>
            t1.delete_flag='NOT_DELETE' and t1.type='1'
            <if test="name !=null and name !=''">
                and t1.name like concat("%",#{name},"%")
            </if>
            <if test="orgName !=null and orgName !=''">
                and t4.NAME=#{orgName}
            </if>
        </where>
        order by t1.create_time desc
    </select>
</mapper>