<?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.pcloud.book.applet.dao.impl.AppletUserDaoImpl">

    <resultMap type="com.pcloud.book.applet.entity.AppletUser" id="AppletUserMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="appletId" column="applet_id" jdbcType="VARCHAR"/>
        <result property="accountSettingId" column="account_setting_id" jdbcType="INTEGER"/>
        <result property="wechatUserId" column="wechat_user_id" jdbcType="INTEGER"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into book.applet_user(applet_id, account_setting_id, wechat_user_id, create_time)
        values (#{appletId}, #{accountSettingId}, #{wechatUserId}, now())
    </insert>

    <select id="getUserCount" parameterType="map" resultType="com.pcloud.book.applet.dto.AppletUserCountDTO">
        SELECT
        COUNT(id) count,
        COUNT(DISTINCT wechat_user_id) userCount
        FROM
            applet_user
        WHERE
            account_setting_id = #{accountSettingId}
        <if test="startTime != null">
            AND create_time >= #{startTime}
        </if>
        <if test="endTime != null">
            AND create_time &lt;= #{endTime}
        </if>
    </select>


</mapper>