<?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.ruoyi.member.mapper.MemberBusiCardMapper">

    <resultMap type="MemberBusiCard" id="MemberBusiCardResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="nickname"    column="nickname"    />
        <result property="platformCode"    column="platform_code"    />
        <result property="platformName"    column="platform_name"    />
        <result property="accountNumber"    column="account_number"    />
        <result property="accountName"    column="account_name"    />
        <result property="fansNum"    column="fans_num"    />
        <result property="image"    column="image"    />
        <result property="tel"    column="tel"    />
        <result property="price"    column="price"    />
        <result property="content"    column="content"    />
        <result property="addrId"    column="addr_id"    />
        <result property="approvalStatus"    column="approval_status"    />
        <result property="approvalUserId"    column="approval_user_id"    />
        <result property="approvalUserName"    column="approval_user_name"    />
        <result property="approvalTime"    column="approval_time"    />
        <result property="approvalRemark"    column="approval_remark"    />
        <result property="creator"    column="creator"    />
        <result property="createTime"    column="create_time"    />
        <result property="updater"    column="updater"    />
        <result property="updateTime"    column="update_time"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectMemberBusiCardVo">
        select id, user_id, nickname, platform_code, platform_name, account_number, account_name, fans_num, image, tel, price, content, addr_id, approval_status, approval_user_id, approval_user_name,approval_time, approval_remark, creator, create_time, updater, update_time, del_flag from dl_member_busi_card
    </sql>

    <select id="queryListPage" parameterType="MemberBusiCard" resultMap="MemberBusiCardResult">
        <include refid="selectMemberBusiCardVo"/>
        <where>
            del_flag = 0
            <if test="entity.nickname != null  and entity.nickname != ''"> and nickname like concat('%', #{entity.nickname}, '%')</if>
            <if test="entity.platformName != null  and entity.platformName != ''"> and platform_name like concat('%', #{entity.platformName}, '%')</if>
            <if test="entity.accountName != null  and entity.accountName != ''"> and account_name like concat('%', #{entity.accountName}, '%')</if>
            <if test="entity.approvalStatus == 10"> and approval_status != 0</if>
            <if test="entity.approvalStatus != null  and entity.approvalStatus != '' and entity.approvalStatus != 10"> and approval_status = #{entity.approvalStatus}</if>
        </where>
        <choose>
            <when test="entity.approvalStatus == 10">order by approval_time desc</when>
            <otherwise>order by create_time asc </otherwise>
        </choose>
    </select>
    <select id="queryById" resultType="com.ruoyi.member.vo.MemberBusiCardVO">
        SELECT
            main.*,
            CONCAT(dma.city_name, dma.detail) AS address
        FROM
            dl_member_busi_card main
                LEFT JOIN
            dl_member_address dma ON main.addr_id = dma.id AND dma.del_flag = 0
        WHERE
            main.del_flag = 0 and main.id = #{id}
    </select>
</mapper>