<?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="cn.pluss.platform.mapper.MerchantComplaintRecordMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.pluss.platform.entity.MerchantComplaintRecord">
        <id column="id" property="id" />
        <result column="merchantCode" property="merchantCode" />
        <result column="orderAmt" property="orderAmt" />
        <result column="payTime" property="payTime" />
        <result column="complaintPhone" property="complaintPhone" />
        <result column="remark" property="remark" />
        <result column="orderNumber" property="orderNumber" />
        <result column="createTime" property="createTime" />
        <result column="status" property="status" />
        <association property="userInfo" javaType="cn.pluss.platform.entity.UserInfo">
            <id column="u_id" property="id" />
            <result column="u_loginName" property="loginName"/>
        </association>
        <collection property="imageList" javaType="java.util.List" column="id" select="getImageList">
        </collection>
    </resultMap>

    <select id="getImageList" resultType="java.lang.String">
        select picUrl from tb_pluss_merchant_complaint_image where complaintId = #{id}
    </select>

    <select id="pageData" resultMap="BaseResultMap" parameterType="cn.pluss.platform.entity.MerchantComplaintRecord">
        SELECT cr.*,
            ui.id as  'u_id',
            ui.loginName as 'u_loginName'
        FROM tb_pluss_merchant_complaint_record cr
            left join tb_pluss_user_app ua on ua.merchantCode = cr.merchantCode and ua.userType = 'promoter'
            left join tb_pluss_user_info ui on ui.id = ua.userId
        <where>
            <if test="record.merchantName != null and record.merchantName != null and record.merchantName != ''">
                and cr.merchantName LIKE CONCAT("%",#{record.merchantName},"%")
            </if>
            <if test="record.userInfo != null and record.userInfo.id != null">
                and ui.id = #{record.userInfo.id}
            </if>
            <if test="record.userInfo != null and record.userInfo.loginName != null and record.userInfo.loginName != ''">
                and ui.loginName = #{record.userInfo.loginName}
            </if>
            <if test="record.complaintPhone != null and record.complaintPhone != ''">
                and cr.complaintPhone = #{record.complaintPhone}
            </if>
            <if test="record.orderNumber != null and record.orderNumber != ''">
                and cr.orderNumber = #{record.orderNumber}
            </if>
            <if test="record.status != null and record.status != ''">
                and cr.status = #{record.status}
            </if>
        </where>
        order by cr.createTime desc
    </select>
</mapper>
