<?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.patrolpointmnt.mapper.BasedataPatrolTypeMapper">

    <resultMap type="BasedataPatrolType" id="BasedataPatrolTypeResult">
        <result property="patrolTypeId" column="patrol_type_id"/>
        <result property="parentId" column="parent_id"/>
        <result property="patrolTypeName" column="patrol_type_name"/>
        <result property="patrolTypeCode" column="patrol_type_code"/>
        <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="patrolTypeLevel" column="patrol_type_level"/>
        <result property="patrolTypeRemark" column="patrol_type_remark"/>
    </resultMap>

    <sql id="selectBasedataPatrolTypeVo">
        select patrol_type_id,
               parent_id,
               patrol_type_name,
               patrol_type_code,
               del_flag,
               create_by,
               create_time,
               update_by,
               update_time,
               patrol_type_level,
               patrol_type_remark
        from basedata_patrol_type
    </sql>

    <select id="selectBasedataPatrolTypeList" parameterType="BasedataPatrolType" resultMap="BasedataPatrolTypeResult">
        <include refid="selectBasedataPatrolTypeVo"/>
        <where>
            <if test="parentId != null ">and parent_id = #{parentId}</if>
            <if test="patrolTypeName != null  and patrolTypeName != ''">and patrol_type_name like concat('%',
                #{patrolTypeName}, '%')
            </if>
            <if test="patrolTypeCode != null  and patrolTypeCode != ''">and patrol_type_code = #{patrolTypeCode}</if>
            <if test="patrolTypeLevel != null ">and patrol_type_level = #{patrolTypeLevel}</if>
            <if test="patrolTypeRemark != null  and patrolTypeRemark != ''">and patrol_type_remark =
                #{patrolTypeRemark}
            </if>
        </where>
    </select>

    <select id="selectBasedataPatrolTypeByPatrolTypeId" parameterType="Long" resultMap="BasedataPatrolTypeResult">
        <include refid="selectBasedataPatrolTypeVo"/>
        where patrol_type_id = #{patrolTypeId}
    </select>

    <insert id="insertBasedataPatrolType" parameterType="BasedataPatrolType" useGeneratedKeys="true"
            keyProperty="patrolTypeId">
        insert into basedata_patrol_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="parentId != null">parent_id,</if>
            <if test="patrolTypeName != null">patrol_type_name,</if>
            <if test="patrolTypeCode != null">patrol_type_code,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="patrolTypeLevel != null">patrol_type_level,</if>
            <if test="patrolTypeRemark != null">patrol_type_remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="parentId != null">#{parentId},</if>
            <if test="patrolTypeName != null">#{patrolTypeName},</if>
            <if test="patrolTypeCode != null">#{patrolTypeCode},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="patrolTypeLevel != null">#{patrolTypeLevel},</if>
            <if test="patrolTypeRemark != null">#{patrolTypeRemark},</if>
        </trim>
    </insert>

    <update id="updateBasedataPatrolType" parameterType="BasedataPatrolType">
        update basedata_patrol_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="patrolTypeName != null">patrol_type_name = #{patrolTypeName},</if>
            <if test="patrolTypeCode != null">patrol_type_code = #{patrolTypeCode},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="patrolTypeLevel != null">patrol_type_level = #{patrolTypeLevel},</if>
            <if test="patrolTypeRemark != null">patrol_type_remark = #{patrolTypeRemark},</if>
        </trim>
        where patrol_type_id = #{patrolTypeId}
    </update>

    <delete id="deleteBasedataPatrolTypeByPatrolTypeId" parameterType="Long">
        delete
        from basedata_patrol_type
        where patrol_type_id = #{patrolTypeId}
    </delete>

    <delete id="deleteBasedataPatrolTypeByPatrolTypeIds" parameterType="String">
        delete from basedata_patrol_type where patrol_type_id in
        <foreach item="patrolTypeId" collection="array" open="(" separator="," close=")">
            #{patrolTypeId}
        </foreach>
    </delete>
</mapper>