<?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.iamberry.wechat.service.mapper.AcceStatisticsMapper">
    <resultMap  id="BaseResultMap" type="AcceStatistics" >
        <result    column="acce_stat_id"    property="acceStatId" />
        <result    column="acce_stat_type"    property="acceStatType" />
        <result    column="acce_stat_open_id"    property="acceStatOpenId" />
        <result    column="acce_stat_create_time"    property="acceStatCreateTime" />
    </resultMap>
    <sql    id="Base_List" >
        t.acce_stat_id,
        t.acce_stat_type,
        t.acce_stat_open_id,
        t.acce_stat_create_time
    </sql>
    <select id="getAcceStatisticsList" resultMap="BaseResultMap" parameterType="AcceStatistics" >
        select
        <include refid="Base_List" />
        from tb_iamberry_access_statistics t
        <where>
            <if test="acceStatId != null ">
                AND t.acce_stat_id = #{acceStatId}
            </if >
            <if test="acceStatType != null ">
                AND t.acce_stat_type = #{acceStatType}
            </if >
            <if test="acceStatOpenId != null ">
                AND t.acce_stat_open_id = #{acceStatOpenId}
            </if >
        </where>
    </select>
    <select id="getAcceStatisticsById" resultMap="BaseResultMap" parameterType="Integer" >
        select
        <include refid="Base_List" />
        from tb_iamberry_access_statistics t
        where t.acce_stat_id= #{acceStatId}
    </select>
    <insert id="save" parameterType="AcceStatistics" >
        insert into
        tb_iamberry_access_statistics
        (
        acce_stat_id,
        acce_stat_type,
        acce_stat_open_id
        )
        values
        (
        #{acceStatId},
        #{acceStatType},
        #{acceStatOpenId}
        )
    </insert>
    <update id="update" parameterType="AcceStatistics" >
        update
        tb_iamberry_access_statistics
        <set >
            <if test="acceStatType != null ">
                acce_stat_type = #{acceStatType},
            </if >
            <if test="acceStatOpenId != null ">
                acce_stat_open_id = #{acceStatOpenId},
            </if >
        </set >
        where acce_stat_id= #{acceStatId}
    </update>

    <select id="getAcceStatiCount" resultType="Integer" parameterType="AcceStatistics" >
        SELECT
          COUNT(t.acce_stat_id)
        FROM
          tb_iamberry_access_statistics t
        WHERE
          date_format(t.acce_stat_create_time,'%Y-%m-%d') = date_format(#{judgeTime},'%Y-%m-%d')
        AND t.acce_stat_open_id = #{acceStatOpenId}
        AND t.acce_stat_type = #{acceStatType}
    </select>


</mapper>