<?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.AlarmConfigDAO">
    <resultMap id="AlarmConfigMap" type="com.jpsoft.shinestar.modules.base.entity.AlarmConfig">
        <result property="id" column="id_"/>
        <result property="companyId" column="company_id"/>
        <result property="companyName" column="company_name"/>
        <result property="weekdays" column="weekdays_"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_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"/>
        <result property="subordinate" column="subordinate_"/>
        <result property="attendanceTime" column="attendance_time"/>
        <result property="classifier" column="classifier_"/>
        <result property="attendanceType" column="attendance_type"/>
        <result property="needMeasureTemperature" column="need_measure_temperature"/>
        <result property="realTimeStat" column="real_time_stat"/>
    </resultMap>
    <insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.AlarmConfig">
        <!--
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="${pkFieldName}">
            select sys_guid() from dual
        </selectKey>
        -->
        <![CDATA[
		insert into base_alarm_config
	    (id_,company_id,weekdays_,start_time,end_time,del_flag,create_by,create_time,
	    update_by,update_time,subordinate_,attendance_time,classifier_,
	    need_measure_temperature,attendance_type,real_time_stat)
		values
		(
            #{id,jdbcType=VARCHAR}
            ,#{companyId,jdbcType=VARCHAR}
            ,#{weekdays,jdbcType=VARCHAR}
            ,#{startTime,jdbcType=VARCHAR}
            ,#{endTime,jdbcType=VARCHAR}
            ,#{delFlag,jdbcType= NUMERIC }
            ,#{createBy,jdbcType=VARCHAR}
            ,#{createTime,jdbcType= TIMESTAMP }
            ,#{updateBy,jdbcType=VARCHAR}
            ,#{updateTime,jdbcType= TIMESTAMP }
            ,#{subordinate,jdbcType= NUMERIC }
            ,#{attendanceTime,jdbcType= VARCHAR }
            ,#{classifier,jdbcType= NUMERIC}
            ,#{needMeasureTemperature,jdbcType= NUMERIC}
            ,#{attendanceType,jdbcType= NUMERIC }
            ,#{realTimeStat,jdbcType= NUMERIC }
		)
	]]>
    </insert>
    <delete id="delete" parameterType="string">
        delete from base_alarm_config where id_=#{id,jdbcType=VARCHAR}
    </delete>
    <update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.AlarmConfig">
        update base_alarm_config
        <set>
            <if test="id!=null">
                id_=#{id,jdbcType=VARCHAR},
            </if>
            <if test="companyId!=null">
                company_id=#{companyId,jdbcType=VARCHAR},
            </if>
            <if test="weekdays!=null">
                weekdays_=#{weekdays,jdbcType=VARCHAR},
            </if>
            <if test="startTime!=null">
                start_time=#{startTime,jdbcType=VARCHAR},
            </if>
            <if test="endTime!=null">
                end_time=#{endTime,jdbcType=VARCHAR},
            </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>
            <if test="subordinate!=null">
                subordinate_=#{subordinate,jdbcType= NUMERIC },
            </if>
            <if test="attendanceTime!=null">
                attendance_time=#{attendanceTime,jdbcType= VARCHAR },
            </if>
            <if test="classifier!=null">
                classifier_=#{classifier,jdbcType= NUMERIC },
            </if>
            <if test="needMeasureTemperature!=null">
                need_measure_temperature=#{needMeasureTemperature,jdbcType= NUMERIC },
            </if>
            <if test="attendanceType!=null">
                attendance_type=#{attendanceType,jdbcType= NUMERIC },
            </if>
            <if test="realTimeStat!=null">
                real_time_stat=#{realTimeStat,jdbcType= NUMERIC },
            </if>
        </set>
        where id_=#{id}
    </update>
    <select id="get" parameterType="string" resultMap="AlarmConfigMap">
        select * from base_alarm_config where id_=#{0}  and del_flag=0
    </select>
    <select id="exist" parameterType="string" resultType="int">
        select count(*) from base_alarm_config where id_=#{0}  and del_flag=0
    </select>
    <select id="list" resultMap="AlarmConfigMap">
        select * from base_alarm_config where del_flag=0
    </select>
    <select id="search" parameterType="hashmap" resultMap="AlarmConfigMap">
        <![CDATA[
			select a.*,b.name_ as company_name from base_alarm_config a left join base_company_info b
			on a.company_id = b.id_
		]]>
        <where>
            a.del_flag = 0
            <if test="searchParams.id != null">
                and a.ID_ like #{searchParams.id}
            </if>
            <if test="searchParams.companyId != null">
                and a.company_id = #{searchParams.companyId}
            </if>
            <if test="searchParams.companyCode != null">
                and b.code_ like #{searchParams.companyCode}
            </if>
        </where>
        <foreach item="sort" collection="sortList" open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
    </select>
    <select id="findByCompanyId" resultMap="AlarmConfigMap">
    <![CDATA[
        select * from base_alarm_config
        where company_id=#{companyId} and del_flag=0
        order by attendance_type asc,start_time asc
    ]]>
    </select>
    <select id="findByCompanyIdAndWeekDay" resultMap="AlarmConfigMap">
        select * from base_alarm_config
        where company_id=#{companyId}
        and weekdays_ like #{weekDay}
        and attendance_type=#{attendanceType}
        and del_flag=0
    </select>
    <select id="findByTime" resultMap="AlarmConfigMap">
        <![CDATA[
            select * from base_alarm_config
            where del_flag=0
            and start_time<=#{time}
            and end_time>=#{time}
            and real_time_stat=1
            order by create_time asc
        ]]>
    </select>
    <select id="findSubCompanyList" resultType="string">
        <![CDATA[
            select distinct(a.company_id) from base_alarm_config a,base_company_info b
            where a.company_id = b.id_
            and a.del_flag = 0
            and b.code_ like #{companyCode}
            and a.company_id<>#{companyId}
        ]]>
    </select>
    <select id="findByCompanyIdAndType" resultMap="AlarmConfigMap">
        <![CDATA[
        select * from base_alarm_config
        where company_id=#{companyId}
        and del_flag=0
        and attendance_type=#{attendanceType}
        and real_time_stat=1
        order by start_time asc
    ]]>
    </select>
</mapper>