<?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.fs.statis.mapper.FsStatisEveryDayWatchMapper">

    <!-- 结果集映射 -->
    <resultMap id="BaseResultMap" type="com.fs.statis.domain.FsStatisEveryDayWatch">
        <id column="id" jdbcType="INTEGER" property="id" />
        <result column="data_date" jdbcType="TIMESTAMP" property="dataDate" />
        <result column="period_id" jdbcType="INTEGER" property="periodId" />
        <result column="period_num" jdbcType="INTEGER" property="periodNum" />
        <result column="not_reg_num" jdbcType="INTEGER" property="notRegNum" />
        <result column="registered_num" jdbcType="INTEGER" property="registeredNum" />
        <result column="reg_rate" jdbcType="REAL" property="regRate" /> <!-- Use REAL or FLOAT for float type -->
        <result column="completed_rate" jdbcType="REAL" property="completedRate" />
        <result column="offline_total" jdbcType="INTEGER" property="offlineTotal" />
        <result column="offline_not_reg_num" jdbcType="INTEGER" property="offlineNotRegNum" />
        <result column="offline_not_watch_num" jdbcType="INTEGER" property="offlineNotWatchNum" />
        <result column="online_total" jdbcType="INTEGER" property="onlineTotal" />
        <result column="online_rate" jdbcType="REAL" property="onlineRate" />
        <result column="online_completed_rate" jdbcType="REAL" property="onlineCompletedRate" />
        <result column="online_not_comp_rate_num" jdbcType="INTEGER" property="onlineNotCompRateNum" />
        <result column="online_completed_num" jdbcType="INTEGER" property="onlineCompletedNum" />
        <result column="company_user_id" jdbcType="INTEGER" property="companyUserId" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, data_date, period_id, period_num, not_reg_num, registered_num, reg_rate,
    completed_rate, offline_total, offline_not_reg_num, offline_not_watch_num,
    online_total, online_rate, online_completed_rate, online_not_comp_rate_num,
    online_completed_num, company_user_id
    </sql>

    <!-- 根据主键查询 -->
    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from fs_statis_every_day_watch
        where id = #{id,jdbcType=INTEGER}
    </select>

    <!-- 根据主键删除 -->
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        delete from fs_statis_every_day_watch
        where id = #{id,jdbcType=INTEGER}
    </delete>

    <!-- 选择性插入记录 (只插入非空字段) -->
    <insert id="insertSelective" parameterType="com.fs.statis.domain.FsStatisEveryDayWatch" useGeneratedKeys="true" keyProperty="id">
        insert into fs_statis_every_day_watch
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dataDate != null">data_date,</if>
            <if test="periodId != null">period_id,</if>
            <if test="periodNum != null">period_num,</if>
            <if test="notRegNum != null">not_reg_num,</if>
            <if test="registeredNum != null">registered_num,</if>
            <if test="regRate != null">reg_rate,</if>
            <if test="completedRate != null">completed_rate,</if>
            <if test="offlineTotal != null">offline_total,</if>
            <if test="offlineNotRegNum != null">offline_not_reg_num,</if>
            <if test="offlineNotWatchNum != null">offline_not_watch_num,</if>
            <if test="onlineTotal != null">online_total,</if>
            <if test="onlineRate != null">online_rate,</if>
            <if test="onlineCompletedRate != null">online_completed_rate,</if>
            <if test="onlineNotCompRateNum != null">online_not_comp_rate_num,</if>
            <if test="onlineCompletedNum != null">online_completed_num,</if>
            <if test="companyUserId != null">company_user_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="dataDate != null">#{dataDate,jdbcType=TIMESTAMP},</if>
            <if test="periodId != null">#{periodId,jdbcType=INTEGER},</if>
            <if test="periodNum != null">#{periodNum,jdbcType=INTEGER},</if>
            <if test="notRegNum != null">#{notRegNum,jdbcType=INTEGER},</if>
            <if test="registeredNum != null">#{registeredNum,jdbcType=INTEGER},</if>
            <if test="regRate != null">#{regRate,jdbcType=REAL},</if>
            <if test="completedRate != null">#{completedRate,jdbcType=REAL},</if>
            <if test="offlineTotal != null">#{offlineTotal,jdbcType=INTEGER},</if>
            <if test="offlineNotRegNum != null">#{offlineNotRegNum,jdbcType=INTEGER},</if>
            <if test="offlineNotWatchNum != null">#{offlineNotWatchNum,jdbcType=INTEGER},</if>
            <if test="onlineTotal != null">#{onlineTotal,jdbcType=INTEGER},</if>
            <if test="onlineRate != null">#{onlineRate,jdbcType=REAL},</if>
            <if test="onlineCompletedRate != null">#{onlineCompletedRate,jdbcType=REAL},</if>
            <if test="onlineNotCompRateNum != null">#{onlineNotCompRateNum,jdbcType=INTEGER},</if>
            <if test="onlineCompletedNum != null">#{onlineCompletedNum,jdbcType=INTEGER},</if>
            <if test="companyUserId != null">#{companyUserId,jdbcType=INTEGER},</if>
        </trim>
    </insert>

    <!-- 根据主键选择性更新 (只更新非空字段) -->
    <update id="updateByPrimaryKeySelective" parameterType="com.fs.statis.domain.FsStatisEveryDayWatch">
        update fs_statis_every_day_watch
        <set>
            <if test="dataDate != null">data_date = #{dataDate,jdbcType=TIMESTAMP},</if>
            <if test="periodId != null">period_id = #{periodId,jdbcType=INTEGER},</if>
            <if test="periodNum != null">period_num = #{periodNum,jdbcType=INTEGER},</if>
            <if test="notRegNum != null">not_reg_num = #{notRegNum,jdbcType=INTEGER},</if>
            <if test="registeredNum != null">registered_num = #{registeredNum,jdbcType=INTEGER},</if>
            <if test="regRate != null">reg_rate = #{regRate,jdbcType=REAL},</if>
            <if test="completedRate != null">completed_rate = #{completedRate,jdbcType=REAL},</if>
            <if test="offlineTotal != null">offline_total = #{offlineTotal,jdbcType=INTEGER},</if>
            <if test="offlineNotRegNum != null">offline_not_reg_num = #{offlineNotRegNum,jdbcType=INTEGER},</if>
            <if test="offlineNotWatchNum != null">offline_not_watch_num = #{offlineNotWatchNum,jdbcType=INTEGER},</if>
            <if test="onlineTotal != null">online_total = #{onlineTotal,jdbcType=INTEGER},</if>
            <if test="onlineRate != null">online_rate = #{onlineRate,jdbcType=REAL},</if>
            <if test="onlineCompletedRate != null">online_completed_rate = #{onlineCompletedRate,jdbcType=REAL},</if>
            <if test="onlineNotCompRateNum != null">online_not_comp_rate_num = #{onlineNotCompRateNum,jdbcType=INTEGER},</if>
            <if test="onlineCompletedNum != null">online_completed_num = #{onlineCompletedNum,jdbcType=INTEGER},</if>
            <if test="companyUserId != null">company_user_id = #{companyUserId,jdbcType=INTEGER},</if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>

    <!-- 根据主键更新 (所有字段) -->
    <update id="updateByPrimaryKey" parameterType="com.fs.statis.domain.FsStatisEveryDayWatch">
        update fs_statis_every_day_watch
        set data_date = #{dataDate,jdbcType=TIMESTAMP},
            period_id = #{periodId,jdbcType=INTEGER},
            period_num = #{periodNum,jdbcType=INTEGER},
            not_reg_num = #{notRegNum,jdbcType=INTEGER},
            registered_num = #{registeredNum,jdbcType=INTEGER},
            reg_rate = #{regRate,jdbcType=REAL},
            completed_rate = #{completedRate,jdbcType=REAL},
            offline_total = #{offlineTotal,jdbcType=INTEGER},
            offline_not_reg_num = #{offlineNotRegNum,jdbcType=INTEGER},
            offline_not_watch_num = #{offlineNotWatchNum,jdbcType=INTEGER},
            online_total = #{onlineTotal,jdbcType=INTEGER},
            online_rate = #{onlineRate,jdbcType=REAL},
            online_completed_rate = #{onlineCompletedRate,jdbcType=REAL},
            online_not_comp_rate_num = #{onlineNotCompRateNum,jdbcType=INTEGER},
            online_completed_num = #{onlineCompletedNum,jdbcType=INTEGER},
            company_user_id = #{companyUserId,jdbcType=INTEGER}
        where id = #{id,jdbcType=INTEGER}
    </update>

    <!-- 查询所有记录 -->
    <select id="selectAll" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from fs_statis_every_day_watch
    </select>
    <select id="queryList" resultType="com.fs.statis.domain.FsStatisSalerWatch">
        select * from fs_statis_every_day_watch
        <where>
            <if test="userIds != null and userIds.length > 0">
                AND company_user_id IN
                <foreach collection="userIds" open="(" close=")" separator="," item="item">
                    ${item}
                </foreach>
            </if>
            <if test="periodList != null and periodList.size() > 0">
                AND period_id IN
                <foreach collection="periodList" open="(" close=")" separator="," item="item">
                    ${item}
                </foreach>
            </if>
            <if test="startDate != null and endDate != null">
                AND data_date BETWEEN #{startDate} AND #{endDate}
            </if>
        </where>
    </select>

</mapper>
