<?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.flossom.common.core.mapper.WxClockStatisticsMapper">
    
    <resultMap type="WxClockStatistics" id="WxClockStatisticsResult">
        <result property="id"    column="id"    />
        <result property="year"    column="year"    />
        <result property="month"    column="month"    />
        <result property="userId"    column="user_id"    />
        <result property="clockNum"    column="clock_num"    />
        <result property="percentage"    column="percentage"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectWxClockStatisticsVo">
        select id, `year`, `month`, user_id, clock_num, percentage, status, create_by, create_time, update_by, update_time from wx_clock_statistics
    </sql>

    <select id="selectWxClockStatisticsList" parameterType="WxClockStatistics" resultMap="WxClockStatisticsResult">
        <include refid="selectWxClockStatisticsVo"/>
        <where>  
            <if test="year != null "> and `year` = #{year}</if>
            <if test="month != null "> and `month` = #{month}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="clockNum != null "> and clock_num = #{clockNum}</if>
            <if test="percentage != null "> and percentage = #{percentage}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectWxClockStatisticsById" parameterType="Long" resultMap="WxClockStatisticsResult">
        <include refid="selectWxClockStatisticsVo"/>
        where id = #{id}
    </select>

    <select id="selectByUserIdAndYearMonth" resultMap="WxClockStatisticsResult">
        <include refid="selectWxClockStatisticsVo"/>
        <where>
            `year` = #{year} and `month` = #{month}
            <if test="userIdList != null and userIdList.size > 0">
                and user_id in
                <foreach item="userId" collection="userIdList" open="(" separator="," close=")">
                    #{userId}
                </foreach>
            </if>
        </where>


    </select>

    <insert id="insertWxClockStatistics" parameterType="WxClockStatistics" useGeneratedKeys="true" keyProperty="id">
        insert into wx_clock_statistics
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="year != null">`year`,</if>
            <if test="month != null">`month`,</if>
            <if test="userId != null">user_id,</if>
            <if test="clockNum != null">clock_num,</if>
            <if test="percentage != null">percentage,</if>
            <if test="status != null">status,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="year != null">#{year},</if>
            <if test="month != null">#{month},</if>
            <if test="userId != null">#{userId},</if>
            <if test="clockNum != null">#{clockNum},</if>
            <if test="percentage != null">#{percentage},</if>
            <if test="status != null">#{status},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateWxClockStatistics" parameterType="WxClockStatistics">
        update wx_clock_statistics
        <trim prefix="SET" suffixOverrides=",">
            <if test="year != null">`year` = #{year},</if>
            <if test="month != null">`month` = #{month},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="clockNum != null">clock_num = #{clockNum},</if>
            <if test="percentage != null">percentage = #{percentage},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWxClockStatisticsById" parameterType="Long">
        delete from wx_clock_statistics where id = #{id}
    </delete>

    <delete id="deleteWxClockStatisticsByIds" parameterType="String">
        delete from wx_clock_statistics where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>