<?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.sing.point.mapper.CmccPointRecordMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="cmccPointRecordResultMap" type="org.springblade.sing.point.vo.CmccPointRecordVO">
        <result column="id" property="id"/>
        <result column="create_user" property="createUser"/>
        <result column="create_dept" property="createDept"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="pay_status" property="payStatus"/>
        <result column="user_id" property="userId"/>
        <result column="out_order_id" property="outOrderId"/>
        <result column="num" property="num"/>
        <result column="phone" property="phone"/>
        <result column="help_goods_id" property="helpGoodsId"/>
        <result column="point" property="point"/>
        <result column="helpGoodsName" property="helpGoodsName"/>
        <result column="userName" property="userName"/>
        <result column="activeName" property="activeName"/>
        <result column="activeProductName" property="activeProductName"/>
    </resultMap>


    <select id="selectCmccPointRecordPage" resultMap="cmccPointRecordResultMap">
        select pr.*,hg.name helpGoodsName,u.nick_name userName,sapr.title activeProductName,sar.title activeName from sing_cmcc_point_record pr
        left join sing_help_goods hg on pr.help_goods_id = hg.id
        left join sing_login_user u on pr.user_id = u.id
        left join sing_active_record sar on pr.active_id = sar.id
        left join sing_active_product_record sapr on pr.active_product_id = sapr.id
        where pr.is_deleted = 0
        <if test="cmccPointRecord.helpGoodsName != null">
            and hg.name like concat('%',#{cmccPointRecord.helpGoodsName},'%')
        </if>
        <if test="cmccPointRecord.payStatus != null">
            and pr.pay_status = #{cmccPointRecord.payStatus}
        </if>
        <if test="cmccPointRecord.point != null">
            and pr.point = #{cmccPointRecord.point}
        </if>
        <if test="cmccPointRecord.phone != null">
            and pr.phone = #{cmccPointRecord.phone}
        </if>
        <if test="cmccPointRecord.userName != null">
            and u.nick_name like concat('%',#{cmccPointRecord.userName},'%')
        </if>
        order by pr.create_time DESC
    </select>

</mapper>
