<?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="org.linlinjava.jz.db.dao.HmEmployClockMapper">
    <resultMap id="BaseResultMap" type="org.linlinjava.jz.db.domain.HmEmployClock">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="work_data" jdbcType="TIMESTAMP" property="workData"/>
        <result column="is_restday" jdbcType="INTEGER" property="isRestday"/>
        <result column="is_holiday" jdbcType="INTEGER" property="isHoliday"/>
        <result column="start_work_time" jdbcType="TIMESTAMP" property="startWorkTime"/>
        <result column="end_work_time" jdbcType="TIMESTAMP" property="endWorkTime"/>
        <result column="status" jdbcType="INTEGER" property="status"/>
        <result column="leave_date" jdbcType="TIMESTAMP" property="leaveDate"/>
        <result column="leave_reason" jdbcType="VARCHAR" property="leaveReason"/>
        <result column="approval_state" jdbcType="INTEGER" property="approvalState"/>
        <result column="approval_reason" jdbcType="VARCHAR" property="approvalReason"/>
        <result column="order_no" jdbcType="VARCHAR" property="orderNo"/>
        <result column="employ_relation_id" jdbcType="BIGINT" property="employRelationId"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="remark" jdbcType="VARCHAR" property="remark"/>
    </resultMap>
    <sql id="Example_Where_Clause">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        <where>
            <foreach collection="oredCriteria" item="criteria" separator="or">
                <if test="criteria.valid">
                    <trim prefix="(" prefixOverrides="and" suffix=")">
                        <foreach collection="criteria.criteria" item="criterion">
                            <choose>
                                <when test="criterion.noValue">
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue">
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue">
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue">
                                    and ${criterion.condition}
                                    <foreach close=")" collection="criterion.value" item="listItem" open="("
                                             separator=",">
                                        #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
    <sql id="Update_By_Example_Where_Clause">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        <where>
            <foreach collection="example.oredCriteria" item="criteria" separator="or">
                <if test="criteria.valid">
                    <trim prefix="(" prefixOverrides="and" suffix=")">
                        <foreach collection="criteria.criteria" item="criterion">
                            <choose>
                                <when test="criterion.noValue">
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue">
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue">
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue">
                                    and ${criterion.condition}
                                    <foreach close=")" collection="criterion.value" item="listItem" open="("
                                             separator=",">
                                        #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
    <sql id="Base_Column_List">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        id, work_data, is_restday, is_holiday, start_work_time, end_work_time, `status`, leave_date,
        leave_reason, approval_state, approval_reason, order_no, employ_relation_id, create_time,
        update_time, remark
    </sql>
    <select id="selectByExample" parameterType="org.linlinjava.jz.db.domain.HmEmployClockExample"
            resultMap="BaseResultMap">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        select
        <if test="distinct">
            distinct
        </if>
        <include refid="Base_Column_List"/>
        from hm_employ_clock
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
        <if test="orderByClause != null">
            order by ${orderByClause}
        </if>
    </select>
    <select id="selectByExampleSelective" parameterType="map" resultMap="BaseResultMap">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        select
        <if test="example != null and example.distinct">
            distinct
        </if>
        <choose>
            <when test="selective != null and selective.length &gt; 0">
                <foreach collection="selective" item="column" separator=",">
                    ${column.aliasedEscapedColumnName}
                </foreach>
            </when>
            <otherwise>
                <include refid="Base_Column_List"/>
            </otherwise>
        </choose>
        from hm_employ_clock
        <if test="example != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
        <if test="example != null and example.orderByClause != null">
            order by ${example.orderByClause}
        </if>
    </select>
    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        select
        <include refid="Base_Column_List"/>
        from hm_employ_clock
        where id = #{id,jdbcType=BIGINT}
    </select>
    <select id="selectByPrimaryKeySelective" parameterType="map" resultMap="BaseResultMap">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        select
        <choose>
            <when test="selective != null and selective.length &gt; 0">
                <foreach collection="selective" item="column" separator=",">
                    ${column.aliasedEscapedColumnName}
                </foreach>
            </when>
            <otherwise>
                <include refid="Base_Column_List"/>
            </otherwise>
        </choose>
        from hm_employ_clock
        where id = #{id,jdbcType=BIGINT}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        delete from hm_employ_clock
        where id = #{id,jdbcType=BIGINT}
    </delete>
    <delete id="deleteByExample" parameterType="org.linlinjava.jz.db.domain.HmEmployClockExample">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        delete from hm_employ_clock
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </delete>
    <insert id="insert" parameterType="org.linlinjava.jz.db.domain.HmEmployClock">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
            SELECT LAST_INSERT_ID()
        </selectKey>
        insert into hm_employ_clock (work_data, is_restday,is_holiday, start_work_time,
        end_work_time, `status`, leave_date,
        leave_reason, approval_state, approval_reason,
        order_no, employ_relation_id, create_time,
        update_time, remark)
        values (#{workData,jdbcType=TIMESTAMP}, #{isRestday,jdbcType=INTEGER},
        #{isHoliday,jdbcType=INTEGER},#{startWorkTime,jdbcType=TIMESTAMP},
        #{endWorkTime,jdbcType=TIMESTAMP}, #{status,jdbcType=INTEGER}, #{leaveDate,jdbcType=TIMESTAMP},
        #{leaveReason,jdbcType=VARCHAR}, #{approvalState,jdbcType=INTEGER}, #{approvalReason,jdbcType=VARCHAR},
        #{orderNo,jdbcType=VARCHAR}, #{employRelationId,jdbcType=BIGINT}, #{createTime,jdbcType=TIMESTAMP},
        #{updateTime,jdbcType=TIMESTAMP}, #{remark,jdbcType=VARCHAR})
    </insert>
    <insert id="insertSelective" parameterType="org.linlinjava.jz.db.domain.HmEmployClock">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
            SELECT LAST_INSERT_ID()
        </selectKey>
        insert into hm_employ_clock
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="workData != null">
                work_data,
            </if>
            <if test="isRestday != null">
                is_restday,
            </if>
            <if test="isHoliday != null">
                is_holiday,
            </if>
            <if test="startWorkTime != null">
                start_work_time,
            </if>
            <if test="endWorkTime != null">
                end_work_time,
            </if>
            <if test="status != null">
                `status`,
            </if>
            <if test="leaveDate != null">
                leave_date,
            </if>
            <if test="leaveReason != null">
                leave_reason,
            </if>
            <if test="approvalState != null">
                approval_state,
            </if>
            <if test="approvalReason != null">
                approval_reason,
            </if>
            <if test="orderNo != null">
                order_no,
            </if>
            <if test="employRelationId != null">
                employ_relation_id,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="remark != null">
                remark,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="workData != null">
                #{workData,jdbcType=TIMESTAMP},
            </if>
            <if test="isRestday != null">
                #{isRestday,jdbcType=INTEGER},
            </if>
            <if test="isHoliday != null">
                #{isHoliday,jdbcType=INTEGER},
            </if>
            <if test="startWorkTime != null">
                #{startWorkTime,jdbcType=TIMESTAMP},
            </if>
            <if test="endWorkTime != null">
                #{endWorkTime,jdbcType=TIMESTAMP},
            </if>
            <if test="status != null">
                #{status,jdbcType=INTEGER},
            </if>
            <if test="leaveDate != null">
                #{leaveDate,jdbcType=TIMESTAMP},
            </if>
            <if test="leaveReason != null">
                #{leaveReason,jdbcType=VARCHAR},
            </if>
            <if test="approvalState != null">
                #{approvalState,jdbcType=INTEGER},
            </if>
            <if test="approvalReason != null">
                #{approvalReason,jdbcType=VARCHAR},
            </if>
            <if test="orderNo != null">
                #{orderNo,jdbcType=VARCHAR},
            </if>
            <if test="employRelationId != null">
                #{employRelationId,jdbcType=BIGINT},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="remark != null">
                #{remark,jdbcType=VARCHAR},
            </if>
        </trim>
    </insert>
    <select id="countByExample" parameterType="org.linlinjava.jz.db.domain.HmEmployClockExample"
            resultType="java.lang.Long">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        select count(*) from hm_employ_clock
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </select>
    <update id="updateByExampleSelective" parameterType="map">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update hm_employ_clock
        <set>
            <if test="record.id != null">
                id = #{record.id,jdbcType=BIGINT},
            </if>
            <if test="record.workData != null">
                work_data = #{record.workData,jdbcType=TIMESTAMP},
            </if>
            <if test="record.isRestday != null">
                is_restday = #{record.isRestday,jdbcType=INTEGER},
            </if>
            <if test="record.isHoliday != null">
                is_holiday = #{record.isHoliday,jdbcType=INTEGER},
            </if>
            <if test="record.startWorkTime != null">
                start_work_time = #{record.startWorkTime,jdbcType=TIMESTAMP},
            </if>
            <if test="record.endWorkTime != null">
                end_work_time = #{record.endWorkTime,jdbcType=TIMESTAMP},
            </if>
            <if test="record.status != null">
                `status` = #{record.status,jdbcType=INTEGER},
            </if>
            <if test="record.leaveDate != null">
                leave_date = #{record.leaveDate,jdbcType=TIMESTAMP},
            </if>
            <if test="record.leaveReason != null">
                leave_reason = #{record.leaveReason,jdbcType=VARCHAR},
            </if>
            <if test="record.approvalState != null">
                approval_state = #{record.approvalState,jdbcType=INTEGER},
            </if>
            <if test="record.approvalReason != null">
                approval_reason = #{record.approvalReason,jdbcType=VARCHAR},
            </if>
            <if test="record.orderNo != null">
                order_no = #{record.orderNo,jdbcType=VARCHAR},
            </if>
            <if test="record.employRelationId != null">
                employ_relation_id = #{record.employRelationId,jdbcType=BIGINT},
            </if>
            <if test="record.createTime != null">
                create_time = #{record.createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="record.updateTime != null">
                update_time = #{record.updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="record.remark != null">
                remark = #{record.remark,jdbcType=VARCHAR},
            </if>
        </set>
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
    </update>
    <update id="updateByExample" parameterType="map">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update hm_employ_clock
        set id = #{record.id,jdbcType=BIGINT},
        work_data = #{record.workData,jdbcType=TIMESTAMP},
        is_restday = #{record.isRestday,jdbcType=INTEGER},
        is_holiday = #{record.isHoliday,jdbcType=INTEGER},
        start_work_time = #{record.startWorkTime,jdbcType=TIMESTAMP},
        end_work_time = #{record.endWorkTime,jdbcType=TIMESTAMP},
        `status` = #{record.status,jdbcType=INTEGER},
        leave_date = #{record.leaveDate,jdbcType=TIMESTAMP},
        leave_reason = #{record.leaveReason,jdbcType=VARCHAR},
        approval_state = #{record.approvalState,jdbcType=INTEGER},
        approval_reason = #{record.approvalReason,jdbcType=VARCHAR},
        order_no = #{record.orderNo,jdbcType=VARCHAR},
        employ_relation_id = #{record.employRelationId,jdbcType=BIGINT},
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
        update_time = #{record.updateTime,jdbcType=TIMESTAMP},
        remark = #{record.remark,jdbcType=VARCHAR}
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="org.linlinjava.jz.db.domain.HmEmployClock">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update hm_employ_clock
        <set>
            <if test="workData != null">
                work_data = #{workData,jdbcType=TIMESTAMP},
            </if>
            <if test="isRestday != null">
                is_restday = #{isRestday,jdbcType=INTEGER},
            </if>
            <if test="isHoliday != null">
                is_holiday = #{isHoliday,jdbcType=INTEGER},
            </if>
            <if test="startWorkTime != null">
                start_work_time = #{startWorkTime,jdbcType=TIMESTAMP},
            </if>
            <if test="endWorkTime != null">
                end_work_time = #{endWorkTime,jdbcType=TIMESTAMP},
            </if>
            <if test="status != null">
                `status` = #{status,jdbcType=INTEGER},
            </if>
            <if test="leaveDate != null">
                leave_date = #{leaveDate,jdbcType=TIMESTAMP},
            </if>
            <if test="leaveReason != null">
                leave_reason = #{leaveReason,jdbcType=VARCHAR},
            </if>
            <if test="approvalState != null">
                approval_state = #{approvalState,jdbcType=INTEGER},
            </if>
            <if test="approvalReason != null">
                approval_reason = #{approvalReason,jdbcType=VARCHAR},
            </if>
            <if test="orderNo != null">
                order_no = #{orderNo,jdbcType=VARCHAR},
            </if>
            <if test="employRelationId != null">
                employ_relation_id = #{employRelationId,jdbcType=BIGINT},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="remark != null">
                remark = #{remark,jdbcType=VARCHAR},
            </if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKey" parameterType="org.linlinjava.jz.db.domain.HmEmployClock">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update hm_employ_clock
        set work_data = #{workData,jdbcType=TIMESTAMP},
        is_restday = #{isRestday,jdbcType=INTEGER},
        is_holiday = #{isHoliday,jdbcType=INTEGER},
        start_work_time = #{startWorkTime,jdbcType=TIMESTAMP},
        end_work_time = #{endWorkTime,jdbcType=TIMESTAMP},
        `status` = #{status,jdbcType=INTEGER},
        leave_date = #{leaveDate,jdbcType=TIMESTAMP},
        leave_reason = #{leaveReason,jdbcType=VARCHAR},
        approval_state = #{approvalState,jdbcType=INTEGER},
        approval_reason = #{approvalReason,jdbcType=VARCHAR},
        order_no = #{orderNo,jdbcType=VARCHAR},
        employ_relation_id = #{employRelationId,jdbcType=BIGINT},
        create_time = #{createTime,jdbcType=TIMESTAMP},
        update_time = #{updateTime,jdbcType=TIMESTAMP},
        remark = #{remark,jdbcType=VARCHAR}
        where id = #{id,jdbcType=BIGINT}
    </update>
    <select id="selectOneByExample" parameterType="org.linlinjava.jz.db.domain.HmEmployClockExample"
            resultMap="BaseResultMap">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        select
        <include refid="Base_Column_List"/>
        from hm_employ_clock
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
        <if test="orderByClause != null">
            order by ${orderByClause}
        </if>
        limit 1
    </select>
    <select id="selectOneByExampleSelective" parameterType="map" resultMap="BaseResultMap">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        select
        <choose>
            <when test="selective != null and selective.length &gt; 0">
                <foreach collection="selective" item="column" separator=",">
                    ${column.aliasedEscapedColumnName}
                </foreach>
            </when>
            <otherwise>
                <include refid="Base_Column_List"/>
            </otherwise>
        </choose>
        from hm_employ_clock
        <if test="example != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
        <if test="example != null and example.orderByClause != null">
            order by ${example.orderByClause}
        </if>
        limit 1
    </select>
    <select id="getHoursOfMonthClock" resultType="java.lang.Long">
        SELECT IFNULL(SUM(
        TIMESTAMPDIFF(
        HOUR,
        `start_work_time`,
        `end_work_time`
        )),0)
        FROM `hm_employ_clock`
        where employ_relation_id = #{employRelationId}
        and status = 2
        <if test="startTime != null">
            and `work_data` >= #{startTime}
        </if>
        <if test="endTime != null">
            and `work_data` <![CDATA[ <= ]]> #{endTime}
        </if>
        <if test="isRestday != null">
            and is_restday = #{isRestday}
        </if>
        <if test="isHoliday != null">
            and is_holiday = #{isHoliday}
        </if>
    </select>
    <select id="queryByMonth" resultType="java.util.Map">
        SELECT DISTINCT c.`id`,
                        DATE_FORMAT(c.`work_data`, '%Y-%m-%d') as work_data,
                        c.`status`,
                        t.`comments`,
                        t.`star`,
                        IF(star IS NULL, 0, 1) AS isComment
        FROM `hm_employ_clock` c
                 LEFT JOIN `hm_comment` t
                           ON c.`id` = t.`r_id`
                               AND t.`r_type` = 3
        WHERE c.`employ_relation_id` = #{employRelationId}
          AND DATE_FORMAT(c.`work_data`, '%Y-%m') = #{date}
        ORDER BY c.id DESC
    </select>
</mapper>