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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.pluss.platform.entity.UserIntegralUse">
        <id column="id" property="id" />
        <result column="name" property="name" />
        <result column="userId" property="userId" />
        <result column="integral" property="integral" />
        <result column="status" property="status" />
        <result column="remark" property="remark" />
        <result column="orderNumber" property="orderNumber" />
        <result column="handleTime" property="handleTime" />
        <result column="createTime" property="createTime" />
    </resultMap>

    <select id="getUseIntegral" resultType="java.math.BigDecimal">
        SELECT IFNULL(sum(integral),0.00)
        FROM tb_pluss_user_integral_use WHERE userId = #{userId} AND `status` = '2'
        <if test="date != null and date != ''">
            and date_format(createTime, '%Y-%m') = #{date}
        </if>
    </select>

    <select id="pageInfo" parameterType="cn.pluss.platform.entity.UserIntegralUse"
            resultType="cn.pluss.platform.entity.UserIntegralUse">
        select * from tb_pluss_user_integral_use
        where status = '2'
        <if test="entity.userId != null">
            and userId = #{entity.userId}
        </if>
        <if test="entity.orderNumber != null and entity.orderNumber != ''">
            and orderNumber = #{entity.orderNumber}
        </if>
        <if test="entity.name != null and entity.name != ''">
            and name like CONCAT('%',#{entity.name},'%')
        </if>
        ORDER BY createTime desc
    </select>
</mapper>
