<?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.djhk.uav.policeWarLawLibrary.mapper.PoliceWarLawLibraryMapper">
    
    <resultMap type="com.djhk.uav.policeWarLawLibrary.domain.PoliceWarLawLibrary" id="PoliceWarLawLibraryResult">
        <result property="id"    column="id"    />
        <result property="warName"    column="war_name"    />
        <result property="nodeName"    column="node_name"    />
        <result property="sonNodeData"    column="son_node_data"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="remark"    column="remark"    />
        <result property="deptId"    column="dept_id"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectPoliceWarLawLibraryVo">
        select id, war_name, node_name,remark, son_node_data, create_by, create_time, del_flag, dept_id, update_by, update_time from police_war_law_library
    </sql>

        <select id="warNameList" resultType="com.djhk.uav.policeWarLawLibrary.domain.warNameVo">
           select DISTINCT war_name  from police_war_law_library
        <where>
            <if test="warName != null  and warName != ''"> and war_name like concat('%', #{warName}, '%')</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
        </where>
        order by create_time desc
    </select>
    <select id="selectPoliceWarLawLibraryList" parameterType="com.djhk.uav.policeWarLawLibrary.domain.PoliceWarLawLibrary" resultMap="PoliceWarLawLibraryResult">
        <include refid="selectPoliceWarLawLibraryVo"/>
        <where>
            <if test="warName != null  and warName != ''"> and war_name like concat('%', #{warName}, '%')</if>
            <if test="nodeName != null  and nodeName != ''"> and node_name like concat('%', #{nodeName}, '%')</if>
            <if test="sonNodeData != null  and sonNodeData != ''"> and son_node_data = #{sonNodeData}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
        </where>
    </select>

    <select id="selectPoliceWarLawLibraryById" parameterType="Long" resultMap="PoliceWarLawLibraryResult">
        <include refid="selectPoliceWarLawLibraryVo"/>
        where id = #{id}
    </select>



    <insert id="insertPoliceWarLawLibrary" parameterType="com.djhk.uav.policeWarLawLibrary.domain.PoliceWarLawLibrary" useGeneratedKeys="true" keyProperty="id">
        insert into police_war_law_library
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="warName != null">war_name,</if>
            <if test="nodeName != null">node_name,</if>
            <if test="sonNodeData != null">son_node_data,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="remark != null">remark,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="warName != null">#{warName},</if>
            <if test="nodeName != null">#{nodeName},</if>
            <if test="sonNodeData != null">#{sonNodeData},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="remark != null">#{remark},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updatePoliceWarLawLibrary" parameterType="com.djhk.uav.policeWarLawLibrary.domain.PoliceWarLawLibrary">
        update police_war_law_library
        <trim prefix="SET" suffixOverrides=",">
            <if test="warName != null">war_name = #{warName},</if>
            <if test="nodeName != null">node_name = #{nodeName},</if>
            <if test="sonNodeData != null">son_node_data = #{sonNodeData},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePoliceWarLawLibraryById" parameterType="Long">
        delete from police_war_law_library where id = #{id}
    </delete>

    <delete id="deletePoliceWarLawLibraryByIds" parameterType="String">
        delete from police_war_law_library where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <delete id="removeByWarName" parameterType="String">
         delete from police_war_law_library where war_name = #{warName}
    </delete>
</mapper>
