<?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.securitycontrol.background.mapper.EmergencyMapper">
	<insert id="addTelData"  useGeneratedKeys="true"  keyProperty="id">
		insert  into tb_emergency_plan ( emerge_type,emerge_name,emerge_source,create_time,del_flag)
			value (#{emergencyType},#{emergencyName},#{emergencySource},now(),0)
	</insert>
	<update id="updTelData">
		update  tb_emergency_plan set  emerge_name=#{emergencyName}, emerge_source=#{emergencySource},update_time=now()
			where  id=#{id}
	</update>
	<update id="deleteData">
		update  tb_emergency_plan set del_flag=1 where id=#{id} and del_flag=0
	</update>

	<select id="getList" resultType="com.securitycontrol.entity.background.vo.EmergencyPlanVo">
		 select  tp.id, ANY_VALUE(tp.emerge_type)  emergencyType, ANY_VALUE(tp.emerge_name) emergencyName,
			 ANY_VALUE(tp.emerge_source) emergencySource,ANY_VALUE(create_time) createTime,
			 ANY_VALUE(tp.update_time) updateTime,count(trf.file_id) fileNum
			from tb_emergency_plan tp
			left join tb_resource_file trf on  trf.source_id=tp.id and trf.del_flag=0
			<if test='emergencyType=="2"'> and  trf.source_type='应急预案'</if>
			<if test='emergencyType=="3"'> and  trf.source_type='应急流程'</if>
				WHERE tp.del_flag=0  AND tp.emerge_type=#{emergencyType}
				<if test="emergencyName!=null and emergencyName!=''">
					and	INSTR(tp.emerge_name,#{emergencyName}) > 0
				</if>
				GROUP BY  tp.id
    </select>
	<select id="getNumByData" resultType="java.lang.Integer">
		 select count(1)
		 	FROM  tb_emergency_plan tp
		 	WHERE  tp.emerge_type=1  AND  tp.emerge_source=#{emergencySource}
			<if test="id!=null and id!=''">
				AND id!=#{id}
			</if>
	</select>
    <select id="getDetail" resultType="com.securitycontrol.entity.background.vo.EmergencyPlanVo">
			select  tp.emerge_type emergencyType,tp.emerge_name  emergencyName
				from tb_emergency_plan tp
				where  tp.id=#{id}
	</select>


</mapper>