<?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.inspect.metadata.mqtt.mapper.HrTaskProcessMapper">

    <resultMap id="HrTaskProcessResult" type="com.inspect.metadata.mqtt.domain.HrTaskProcess">
        <id property="processId" column="process_id"/>
        <result property="nestCode" column="nest_code"/>
        <result property="content" column="content"/>
        <result property="stepid" column="stepid"/>
        <result property="result" column="result"/>
        <result property="state" column="state"/>
        <result property="time" column="time"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectHrTaskProcessVo">
        select process_id,
               nest_code,
               content,
               stepid,
               result,
               state,
               time,
               create_time,
               update_time
        from basedata_hr_task_process
    </sql>

    <select id="selectTaskProcessList" parameterType="com.inspect.metadata.mqtt.domain.HrTaskProcess"
            resultMap="HrTaskProcessResult">
        <include refid="selectHrTaskProcessVo"/>
        <where>
            <if test="nestCode != null ">and nest_code = #{nestCode}</if>
            <if test="result != null ">and result = #{result}</if>
            <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
                and date_format(create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
            </if>
            <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
                and date_format(create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
            </if>
        </where>
        order by create_time desc
    </select>

    <select id="countWarnThreeDay" resultType="java.lang.Integer" parameterType="com.inspect.metadata.mqtt.domain.HrTaskProcess">
        select count(1) from basedata_hr_task_process
        <where>
            <if test="nestCode != null ">and nest_code = #{nestCode}</if>
            <if test="result != null ">and result = #{result}</if>
        </where>
        and create_time >= DATE_SUB(CURDATE(),INTERVAL 3 DAY)
    </select>

    <insert id="insertTaskProcess">
        insert into basedata_hr_task_process(nest_code, content, stepid, result, state, time, create_time)
        values (#{nestCode}, #{content}, #{stepid}, #{result}, #{state}, #{time}, sysdate())
    </insert>

</mapper>