<?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.PointRecordMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="pointRecordResultMap" type="org.springblade.sing.point.vo.PointRecordVO">
        <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="user_id" property="userId"/>
        <result column="help_goods_id" property="helpGoodsId"/>
        <result column="point_goods_id" property="pointGoodsId"/>
        <result column="point" property="point"/>
        <result column="point_type" property="pointType"/>
        <result column="userName" property="userName"/>
        <result column="pointGoodsName" property="pointGoodsName"/>
        <result column="helpGoodsName" property="helpGoodsName"/>
        <result column="activeProductName" property="activeProductName"/>
    </resultMap>


    <select id="selectPointRecordPage" resultMap="pointRecordResultMap">
        select pr.id,pr.point_type,pr.point,pr.help_goods_id,u.nick_name userName,apr.title activeProductName,hg.name helpGoodsName,pg.name pointGoodsName,pr.create_time
        from sing_point_record pr
        left join sing_login_user u on u.id = pr.user_id
        left join sing_active_product_record apr on apr.id = pr.active_product_id
		left join sing_help_goods hg on hg.id = pr.help_goods_id
		left join sing_point_goods pg on pg.id = pr.point_goods_id
		where pr.is_deleted = 0
		<if test="pointRecord.activeProductName != null">
            and apr.title like concat('%',#{pointRecord.activeProductName},'%')
        </if>
        <if test="pointRecord.helpGoodsName != null">
            and hg.name like concat('%',#{pointRecord.helpGoodsName},'%')
        </if>
        <if test="pointRecord.pointGoodsName != null">
            and pg.name like concat('%',#{pointRecord.pointGoodsName},'%')
        </if>
        <if test="pointRecord.userName != null">
            and u.nick_name like concat('%',#{pointRecord.userName},'%')
        </if>
        order by pr.create_time DESC
    </select>

</mapper>
