<?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.aidex.system.mapper.SysMiniappDailyVisitMapper">

    <sql id="sysMiniappDailyVisitColumns">
        a.ref_date as "refDate",

        a.session_cnt as "sessionCnt",

        a.visit_pv as "visitPv",

        a.visit_uv as "visitUv",

        a.visit_uv_new as "visitUvNew",

        a.stay_time_uv as "stayTimeUv",

        a.stay_time_session as "stayTimeSession",

        a.visit_depth as "visitDepth",

        a.remark as "remark",

        a.id as "id",

        a.create_by as "createBy",

        a.create_dept as "createDept",

        a.create_time as "createTime",

        a.update_by as "updateBy",

        a.update_time as "updateTime",

        a.update_ip as "updateIp",

        a.version as "version",

        a.del_flag as "delFlag"

    </sql>

    <sql id="sysMiniappDailyVisitJoins">
    </sql>

    <select id="get" resultType="SysMiniappDailyVisit">
        SELECT
            <include refid="sysMiniappDailyVisitColumns"/>
        FROM sys_miniapp_daily_visit a
        <include refid="sysMiniappDailyVisitJoins"/>
        WHERE a.id = #{id}
    </select>

    <select id="findList" resultType="SysMiniappDailyVisit">
        SELECT
            <include refid="sysMiniappDailyVisitColumns"/>
        FROM sys_miniapp_daily_visit a
        <include refid="sysMiniappDailyVisitJoins"/>
        <where>
            a.del_flag = #{DEL_FLAG_NORMAL}
            <if test="beginRefDate != null and beginRefDate != ''"><!-- 开始时间检索 -->
                AND date_format(a.ref_date,'%y%m%d') &gt;= date_format(#{beginRefDate},'%y%m%d')
            </if>
            <if test="endRefDate != null and endRefDate != ''"><!-- 结束时间检索 -->
                AND date_format(a.ref_date,'%y%m%d')  &lt;= date_format(#{endRefDate},'%y%m%d')
            </if>
            <if test="sessionCnt != null ">
                AND a.session_cnt = #{sessionCnt}
            </if>
            <if test="visitPv != null ">
                AND a.visit_pv = #{visitPv}
            </if>
            <if test="visitUv != null ">
                AND a.visit_uv = #{visitUv}
            </if>
        </where>
        <choose>
            <when test="page !=null and page.orderBy != null and page.orderBy != ''">
                ORDER BY ${page.orderBy}
            </when>
            <otherwise>
            </otherwise>
        </choose>
    </select>

    <select id="findListWithUnique" resultType="SysMiniappDailyVisit">
        SELECT
            a.id
        FROM sys_miniapp_daily_visit a
        <include refid="sysMiniappDailyVisitJoins"/>
        <where>
            a.del_flag = #{DEL_FLAG_NORMAL}
            <if test="notEqualId != null and notEqualId != ''">
                AND id != #{notEqualId}
            </if>
        </where>
    </select>


    <insert id="insert">
        INSERT INTO sys_miniapp_daily_visit(
            ref_date,

            session_cnt,

            visit_pv,

            visit_uv,

            visit_uv_new,

            stay_time_uv,

            stay_time_session,

            visit_depth,

            remark,

            id,

            create_by,

            create_dept,

            create_time,

            update_by,

            update_time,

            update_ip,

            version,

            del_flag

        ) VALUES (
            #{refDate},

            #{sessionCnt},

            #{visitPv},

            #{visitUv},

            #{visitUvNew},

            #{stayTimeUv},

            #{stayTimeSession},

            #{visitDepth},

            #{remark},

            #{id},

            #{createBy},

            #{createDept},

            #{createTime},

            #{updateBy},

            #{updateTime},

            #{updateIp},

            #{version},

            #{delFlag}

        )
    </insert>

    <update id="update">
        UPDATE sys_miniapp_daily_visit SET
            ref_date = #{refDate},
            session_cnt = #{sessionCnt},
            visit_pv = #{visitPv},
            visit_uv = #{visitUv},
            visit_uv_new = #{visitUvNew},
            stay_time_uv = #{stayTimeUv},
            stay_time_session = #{stayTimeSession},
            visit_depth = #{visitDepth},
            remark = #{remark},
            update_by = #{updateBy},
            update_time = #{updateTime},
            update_ip = #{updateIp},
            version = version + 1
        WHERE id = #{id} and version = #{version}
    </update>

    <update id="updateStatus">
        UPDATE sys_miniapp_daily_visit SET
            status = #{status},
            version = version + 1
        WHERE id = #{id}
    </update>

    <update id="delete">
        UPDATE sys_miniapp_daily_visit SET
            del_flag = #{DEL_FLAG_DELETE}
        WHERE id = #{id}
    </update>

    <delete id="deleteSysMiniappDailyVisitByIds">
        UPDATE sys_miniapp_daily_visit SET
            del_flag = #{DEL_FLAG_DELETE}
        WHERE id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>
