UserWithdrawStatisticsMapper.xml 2.17 KB
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">


<!-- 不使用namespace的话sql搜索定位会比较方便 -->
<mapper namespace="UserWithdrawStatistics">

	<resultMap id="UserWithdrawStatistics" type="com.bjivt.job.executor.service.jobhandler.mijia.model.UserWithdrawStatistics">
		<id column="id" jdbcType="INTEGER" property="id" />
        <result property="date" column="date" jdbcType="TIMESTAMP"/>
        <result property="userId" column="user_id" jdbcType="INTEGER"/>
        <result property="withdraw" column="withdraw" jdbcType="FLOAT"/>
	</resultMap>
	<resultMap id="UserMoneyMap" type="com.bjivt.job.executor.service.jobhandler.mijia.model.UserMoney">
        <result property="userId" column="user_id" jdbcType="INTEGER"/>
        <result property="money" column="money" jdbcType="FLOAT"/>
	</resultMap>
	
	<!-- 用于select查询公用抽取的列 -->
	<sql id="columns">
	    <![CDATA[
		id,date,user_id,withdraw
	    ]]>
	</sql>

	<!-- useGeneratedKeys="true" keyProperty="xxx" for sqlserver and mysql -->
	<insert id="insert" parameterType="com.bjivt.job.executor.service.jobhandler.mijia.model.UserWithdrawStatistics">
    <![CDATA[
        INSERT INTO db_showtime_stat.tbl_user_withdraw_statistics (
        	date ,
        	user_id ,
        	withdraw 
        ) VALUES (
        	#{date} ,
        	#{userId} ,
        	#{withdraw} 
        )
    ]]>
	</insert>
	<insert id="insertSaveBatch" parameterType="java.util.List">
	    insert into db_showtime_stat.tbl_user_withdraw_statistics (   
	         	date ,
	        	user_id ,
	        	withdraw 
		 )
	    values
	    <foreach collection="list" item="item" index="index" separator=",">
	    (#{item.date},#{item.userId},#{item.withdraw})
	    </foreach>
    </insert>
	<!-- 获取每日发送礼物的数量 -->
  <select id="getUserMoneyStatistics" resultMap="UserMoneyMap" parameterType="java.util.HashMap">
	  select rr.user_id, sum(me_coin) as money from db_showtime_log.tbl_withdraw_record rr 
	where date_format(rr.record_time,'%Y-%m-%d') =  date_sub(curdate(),interval 1 day) 
	 group by rr.user_id
 </select>

</mapper>