<?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.kiisoo.ic.system.mapper.PrivilageAccountDOMapper">

    <select id="selectUserAndRoleInfo" resultType="com.kiisoo.ic.system.bean.AccountBean">
        select t1.id as userId,t1.name as userName, t3.name as roleName, t3.id as roleId, t3.code as roleCode,t1.mobil,t1.abbreviation
        from privilage_user t1, privilage_user_role t2, privilage_role t3
        where t1.id = t2.user_id
        and t2.role_id = t3.id
        and t1.id = #{userId}
        limit 1
    </select>

    <select id="selectAccountIdByRoleAndSearchContent" resultType="java.lang.Long">
      select t1.id from privilage_account t1,privilage_user t2,privilage_user_role t3, privilage_role t4
        where t1.user_id = t2.id
        and t2.id = t3.user_id
        and t3.role_id = t4.id
        <if test="roleId != null">
            and t3.role_id = #{roleId}
        </if>
        <if test="searchContent != null and searchContent != ''">
            and
            CONCAT(IFNULL(t1.login,''),IFNULL(t2.name,''))
            LIKE CONCAT('%',#{searchContent},'%')
        </if>
    </select>

    <select id="selectAccountIdByShopId" resultType="java.lang.Long">
        select t3.id from poi_store_staff t1, privilage_user t2, privilage_account t3
        where t1.user_id = t2.id
        and t2.id = t3.user_id
        and t1.store_id = #{shopId}
    </select>
    <delete id="deleteByUserId">
        delete from privilage_account where user_id =#{userId}
    </delete>

</mapper>
