<?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="org.springblade.modules.system.mapper.UserMerchantMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="userMerchantResultMap" type="org.springblade.modules.system.entity.UserMerchant">
        <result column="id" property="id"/>
        <result column="merchant_name" property="merchantName"/>
        <result column="user_id" property="userId"/>
        <result column="id_card" property="idCard"/>
        <result column="business_licence" property="businessLicence"/>
        <result column="address" property="address"/>
        <result column="parent_id" property="parentId"/>
        <result column="auth_menu" property="authMenu"/>
        <result column="audit_status" property="auditStatus"/>
    </resultMap>
    <select id="selectUserMerchantPage" resultType="org.springblade.modules.system.vo.UserMerchantVO">
        SELECT
            m.*,
            u.avatar,
            u.phone,
            u.real_name,
            u.`name`,
            u.account,
            m.id childAccountId
        FROM
            blade_user_merchant m
                JOIN blade_user u ON m.user_id = u.id
        WHERE u.is_deleted = 0
        <if test="@cn.hutool.core.util.StrUtil@isNotBlank(p.merchantName)">
            AND INSTR( m.merchant_name, #{p.merchantName} ) > 0
        </if>
        <if test="p.auditStatus != null">
            AND m.audit_status = #{p.auditStatus}
        </if>
        <if test="p.parentId != null">
            AND m.parent_id = #{p.parentId}
        </if>
    </select>


</mapper>
