package com.hai.dao;

import com.hai.entity.HighGoldRec;
import com.hai.entity.HighGoldRecExample;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;

import java.util.List;
import java.util.Map;

/**
 * mapper扩展类
 */
public interface HighGoldRecMapperExt {
    @Select({"<script>" +
            "SELECT" +
            " gold_type , SUM(gold) AS sum FROM high_gold_rec" +
            " WHERE" +
            " 1 = 1" +
            " <if test='map.createTimeS != null'> AND create_time BETWEEN '${map.createTimeS}' AND '${map.createTimeE}'</if>  " +
            " <if test='map.resType != null'> AND res_type = #{map.resType}</if>  " +
            " <if test='map.goldType != null'> AND gold_type = #{map.goldType}</if>" +
            " GROUP BY gold_type" +
            " </script>"})
        // 查询申请记录
    List<Map<Long,Long>> queryGold(@Param("map") Map<String,Object> map);

    @Select("select * from high_gold_rec WHERE status = 1 and  res_type = 4 and DATE_ADD(create_time,INTERVAL #{day} DAY) < NOW() and user_id = #{userId} ")
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT),
            @Result(column="gold_type", property="goldType", jdbcType=JdbcType.BIGINT),
            @Result(column="gold", property="gold", jdbcType=JdbcType.INTEGER),
            @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="res_type", property="resType", jdbcType=JdbcType.INTEGER),
            @Result(column="res_id", property="resId", jdbcType=JdbcType.BIGINT),
            @Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR),
            @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
            @Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR),
            @Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR),
            @Result(column="ext_3", property="ext3", jdbcType=JdbcType.VARCHAR)
    })
    List<HighGoldRec> selectByExpiringSoon(@Param("userId") Long userId , @Param("day") Integer day);

    @Select("select * from high_gold_rec WHERE status = 1 and  res_type = 4 and DATE_ADD(create_time,INTERVAL #{day} DAY) < NOW()")
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT),
            @Result(column="gold_type", property="goldType", jdbcType=JdbcType.BIGINT),
            @Result(column="gold", property="gold", jdbcType=JdbcType.INTEGER),
            @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="res_type", property="resType", jdbcType=JdbcType.INTEGER),
            @Result(column="res_id", property="resId", jdbcType=JdbcType.BIGINT),
            @Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR),
            @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
            @Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR),
            @Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR),
            @Result(column="ext_3", property="ext3", jdbcType=JdbcType.VARCHAR)
    })
    List<HighGoldRec> selectByExpiringSoonByAll(@Param("day") Integer day);
}
