<?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.jumeirah.common.mapper.BusinessPlainMapper">

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,
        mc_id,
        business_type,
        img_url,
        introduction,
        name,
        phone,
        wechat,
        status,
        create_time,
        update_time
    </sql>

    <sql id="Base_Column_ListForApp">
        bp.business_type,
        bp.img_url,
        bp.introduction,
        bp.name,
        bp.phone,
        bp.wechat,
        m.`name` AS mcName
    </sql>

    <select id="getBusinessPlainById" resultType="com.jumeirah.common.vo.BusinessPlainQueryVo">
        select
        <include refid="Base_Column_List"/>
        from business_plain where id = #{id}
    </select>

    <select id="getBusinessPlainPageList" parameterType="com.jumeirah.common.param.BusinessPlainPageParam"
            resultMap="pageListMap">
        select
            <include refid="Base_Column_List"/>
        from business_plain
    </select>

    <resultMap id="pageListMap" type="com.jumeirah.common.vo.BusinessPlainQueryVo">
        <id column="id" jdbcType="BIGINT" property="id" />
        <result column="img_url" property="imgList" typeHandler="com.jumeirah.common.campusstore.ArrayJsonHandler"></result>
    </resultMap>

    <select id="getBusinessPlainPageListForApp" parameterType="com.jumeirah.common.param.BusinessPlainPageParam"
            resultMap="pageListMapForApp">
        select
            <include refid="Base_Column_ListForApp"/>,
            m.`head` AS mcHead
        from business_plain bp
        INNER JOIN merchant m ON bp.mc_id=m.id
        where bp.business_type = #{param.type}
            AND m.state = 1
            and m.audit_register_status = 1
    </select>

    <resultMap id="pageListMapForApp" type="com.jumeirah.common.vo.BusinessPlainQueryForAppVo">
        <result column="img_url" property="imgList" typeHandler="com.jumeirah.common.campusstore.ArrayJsonHandler"></result>
    </resultMap>

</mapper>
