<?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.mmc.iuav.user.dao.userpoints.UserPointsDetailsDao">
    <resultMap id="detailPointList" type="com.mmc.iuav.user.entity.userpoints.UserPointsDetails">
        <result property="id" column="id"/>
        <result property="userAccountId" column="user_account_id"/>
        <result property="point" column="point"/>
        <result property="pointSource" column="point_source"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="timeOfRelease" column="time_of_release"/>
        <result property="nickName" column="nick_name"/>
        <result property="phoneNum" column="phone_num"/>

    </resultMap>

    <insert id="insertPointsDetails" parameterType="com.mmc.iuav.user.entity.userpoints.UserPointsDetails">
        insert into user_points_details(point, user_account_id, create_time,
                                        update_time, point_source, time_of_release)
        values (#{point}, #{userAccountId}, NOW(), NOW(), #{pointSource}, NOW())
    </insert>

    <select id="detailPoint" resultMap="detailPointList">
        SELECT upd.id,
               upd.user_account_id,
               upd.point,
               upd.point_source,
               upd.create_time,
               upd.update_time,
               upd.time_of_release,
               ua.nick_name,
               ua.phone_num
        FROM user_points_details upd
                 INNER JOIN user_account ua ON upd.user_account_id = ua.id
        WHERE ua.`disable` = 0
          AND upd.user_account_id = #{userAccountId}
        order by upd.create_time desc, upd.id desc
            limit #{pageNo}, #{pageSize}
    </select>


    <select id="detailPointCount" resultType="java.lang.Integer">
        SELECT count(*)
        FROM user_points_details upd
                 INNER JOIN user_account ua ON upd.user_account_id = ua.id
        WHERE ua.`disable` = 0
          AND upd.user_account_id = #{userAccountId}
    </select>

    <select id="appDetailPoint" resultMap="detailPointList">
        SELECT upd.id,
               upd.user_account_id,
               upd.point,
               upd.point_source,
               upd.create_time,
               upd.update_time,
               upd.time_of_release,
               ua.nick_name,
               ua.phone_num
        FROM user_points_details upd
                 INNER JOIN user_account ua ON upd.user_account_id = ua.id
        WHERE ua.`disable` = 0
          AND upd.user_account_id = #{userAccountId}
        order by upd.create_time desc, upd.id desc
            limit #{pageNo}, #{pageSize}
    </select>

    <select id="appDetailPointCount" resultType="java.lang.Integer">
        SELECT count(*)
        FROM user_points_details upd
                 INNER JOIN user_account ua ON upd.user_account_id = ua.id
        WHERE ua.`disable` = 0
          AND upd.user_account_id = #{userAccountId}
    </select>
</mapper>
