<?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.oqpo.api.mapper.MemberMapper">

    <select id="selectMemberById" resultType="com.oqpo.api.entity.oper.MemberEntity">
        SELECT /* selectMemberById */
            uinfo.user_id, uinfo.user_nm, uinfo.user_pw as password
            ,uinfo.system_admin_yn, uinfo.super_admin_yn, uinfo.auth_tp_cd
             ,case when uinfo.auth_tp_cd in ('10','20') then '오더퀸'
                 when uinfo.auth_tp_cd in ('30') then fn_affl_nm(uinfo.affl_shop_id)
                 when uinfo.auth_tp_cd in ('40') then fn_brand_nm(uinfo.brand_id)
                 when uinfo.auth_tp_cd in ('50') then fn_store_nm(uinfo.brand_id, uinfo.store_id)
                 when uinfo.auth_tp_cd in ('60') then fn_spply_nm(uinfo.spply_id)
                 end as auth_tp_nm
            , uinfo.affl_shop_id, fn_affl_nm(uinfo.affl_shop_id) as affl_shop_nm
            , uinfo.brand_id, fn_brand_nm(uinfo.brand_id) as brand_nm
            , uinfo.store_id, fn_store_nm(uinfo.brand_id, uinfo.store_id) as store_nm
            , uinfo.spply_id, fn_spply_nm(uinfo.spply_id) as spply_nm
            ,binfo.oq_brand_id, sinfo.oq_store_id
        FROM np_user_info uinfo
        left outer join brand_base_info binfo on binfo.brand_id = uinfo.brand_id
        left outer join store_base_info sinfo on sinfo.brand_id = uinfo.brand_id and sinfo.store_id = uinfo.store_id
        WHERE user_id = #{userId}
    </select>

    <select id="selectMemberFindId" resultType="com.oqpo.api.entity.oper.MemberEntity">
        select /* selectMemberFindId */
                a.user_id
        from np_user_info a
        where a.user_nm = #{userNm}
        and a.email = #{email}
        and replace(a.tel_no,'-','') = replace(#{telNo},'-','')
    </select>

    <select id="selectMemberFindPwCnt" resultType="Integer">
        select /* selectMemberFindPw */
                count(*) as id_cnt
        from np_user_info
        where user_id = #{userId}
        and email = #{email}
        and replace(tel_no,'-','') = replace(#{telNo},'-','')
    </select>

    <select id="selectMemberBrandList" resultType="com.oqpo.api.entity.oper.MemberEntity">
        select distinct binfo.brand_id, binfo.brand_nm
        from  brand_base_info binfo
                join 	(
                    select brand_id
                    from brand_base_info
                    where bsns_reg_no = #{bsnsRegNo}
                    or affl_shop_id in (select affl_shop_id from affl_shop_base_info
                                                where bsns_reg_no = #{bsnsRegNo}
                                                and   st_cd = 'S000' )
                    union all
                    select brand_id
                    from  store_base_info
                    where bsns_reg_no = #{bsnsRegNo}
                    and   store_st_cd = 'ST01'
                    union all
                    select brand_id
                    from  spply_base_info
                    where bsns_reg_no = #{bsnsRegNo}
                    and   st_cd = 'S000'
                    ) tinfo on binfo.brand_id = tinfo.brand_id
        where binfo.st_cd = 'S000'
    </select>




</mapper>
