<?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">
<!-- namespace必须指向DAO接口 -->
<mapper namespace="com.jpsoft.shinestar.modules.base.dao.ExecuteFailLogDAO">
    <resultMap id="ExecuteFailLogMap" type="com.jpsoft.shinestar.modules.base.entity.ExecuteFailLog">
        <result property="id" column="id_"/>
        <result property="personId" column="person_id"/>
        <result property="deviceId" column="device_id"/>
        <result property="executeSuccess" column="execute_success"/>
        <result property="type" column="type_"/>
        <result property="executeTime" column="execute_time"/>
        <result property="delFlag" column="del_flag"/>
        <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>
    <insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.ExecuteFailLog">
        <!--
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="${pkFieldName}">
            select sys_guid() from dual
        </selectKey>
        -->
        <![CDATA[
		insert into base_execute_fail_log
	    (person_id,device_id,execute_success,type_,execute_time,del_flag,create_by,create_time,update_by,update_time)
		values
		(

            #{personId,jdbcType=BIGINT}
            ,#{deviceId,jdbcType=VARCHAR}
            ,#{executeSuccess,jdbcType=BOOLEAN}
            ,#{type,jdbcType=VARCHAR}
            ,#{executeTime,jdbcType=TIMESTAMP}
            ,#{delFlag,jdbcType= NUMERIC }
            ,#{createBy,jdbcType=VARCHAR}
            ,#{createTime,jdbcType= TIMESTAMP }
            ,#{updateBy,jdbcType=VARCHAR}
            ,#{updateTime,jdbcType= TIMESTAMP }
		)
	]]>
    </insert>
    <delete id="delete" parameterType="Long">
        delete from base_execute_fail_log where id_=#{id,jdbcType=BIGINT}
    </delete>
    <update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.ExecuteFailLog">
        update base_execute_fail_log
        <set>
            <if test="personId !=null">
                person_id=#{personId,jdbcType=BIGINT},
            </if>
            <if test="deviceId !=null">
                device_id=#{deviceId,jdbcType=VARCHAR},
            </if>
            <if test="executeSuccess!=null">
                execute_success=#{executeSuccess,jdbcType=BOOLEAN},
            </if>
            <if test="type!=null">
                type_=#{type,jdbcType=VARCHAR},
            </if>
            <if test="executeTime!=null">
                execute_time=#{executeTime,jdbcType=TIMESTAMP},
            </if>
            <if test="delFlag!=null">
                del_flag=#{delFlag,jdbcType= NUMERIC },
            </if>
            <if test="createBy!=null">
                create_by=#{createBy,jdbcType=VARCHAR},
            </if>
            <if test="createTime!=null">
                create_time=#{createTime,jdbcType= TIMESTAMP },
            </if>
            <if test="updateBy!=null">
                update_by=#{updateBy,jdbcType=VARCHAR},
            </if>
            <if test="updateTime!=null">
                update_time=#{updateTime,jdbcType= TIMESTAMP },
            </if>
        </set>
        where id_=#{id}
    </update>
    <select id="findByPersonIdAndDeviceIdAndType" resultMap="ExecuteFailLogMap">
        select * from base_execute_fail_log
        where person_id=#{personId} and  device_id=#{deviceId} and type_=#{type}
        and execute_success=0
        and del_flag=0
        order by create_time desc
        limit 1
    </select>
    <select id="get" parameterType="Long" resultMap="ExecuteFailLogMap">
        select * from base_execute_fail_log where id_=#{0}  and del_flag=0
    </select>
    <select id="exist" parameterType="Long" resultType="int">
        select count(*) from base_execute_fail_log where id_=#{0}  and del_flag=0
    </select>
    <select id="list" resultMap="ExecuteFailLogMap">
        select * from base_execute_fail_log where del_flag=0
    </select>
    <select id="search" parameterType="hashmap" resultMap="ExecuteFailLogMap">
        <![CDATA[
			select * from base_execute_fail_log
		]]>
        <where>
            <if test="searchParams.id != null">
                and ID_ like #{searchParams.id}
            </if>
            <if test="searchParams.personId != null">
                and person_id = #{searchParams.type}
            </if>
        </where>
        <foreach item="sort" collection="sortList"  open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
    </select>
    <select id="findByDeviceNo" resultMap="ExecuteFailLogMap">
        select * from base_execute_fail_log t1,base_device_info t2
        where t1.del_flag=0
        and t1.execute_success=0
        and t1.device_id = t2.id_
        and t2.device_no=#{deviceNo}
        order by t1.create_time asc limit ${limit}
    </select>
</mapper>