<?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.uav.mapper.UavOrganizationMapper">

    <resultMap type="com.djhk.uav.uav.model.UavOrganization" id="UavOrganizationResult">
        <result property="id"    column="id"    />
        <result property="organizationName"    column="organization_name"    />
        <result property="organizationStatus"    column="organization_status"    />
        <result property="organizationNo"    column="organization_no"    />
        <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="remark"    column="remark"    />
        <result property="deleteTime"    column="delete_time"    />
        <result property="deleteBy"    column="delete_by"    />
    </resultMap>

    <sql id="selectUavOrganizationVo">
        select id, organization_name, organization_status, organization_no, del_flag, create_by, create_time, update_by, update_time, remark, delete_time, delete_by from uav_organization
    </sql>

    <select id="selectUavOrganizationList" parameterType="com.djhk.uav.uav.model.UavOrganization" resultMap="UavOrganizationResult">
        <include refid="selectUavOrganizationVo"/>
        <where>
            and del_flag = "0"
            <if test="organizationName != null  and organizationName != ''"> and organization_name like concat('%', #{organizationName}, '%')</if>
            <if test="organizationStatus != null "> and organization_status = #{organizationStatus}</if>
            <if test="organizationNo != null  and organizationNo != ''"> and organization_no = #{organizationNo}</if>
            <if test="deleteTime != null "> and delete_time = #{deleteTime}</if>
            <if test="deleteBy != null  and deleteBy != ''"> and delete_by = #{deleteBy}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectUavOrganizationById" parameterType="Long" resultMap="UavOrganizationResult">
        <include refid="selectUavOrganizationVo"/>
        where id = #{id}
    </select>

    <insert id="insertUavOrganization" parameterType="com.djhk.uav.uav.model.UavOrganization" useGeneratedKeys="true" keyProperty="id">
        insert into uav_organization
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="organizationName != null">organization_name,</if>
            <if test="organizationStatus != null">organization_status,</if>
            <if test="organizationNo != null">organization_no,</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="remark != null">remark,</if>
            <if test="deleteTime != null">delete_time,</if>
            <if test="deleteBy != null">delete_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="organizationName != null">#{organizationName},</if>
            <if test="organizationStatus != null">#{organizationStatus},</if>
            <if test="organizationNo != null">#{organizationNo},</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="remark != null">#{remark},</if>
            <if test="deleteTime != null">#{deleteTime},</if>
            <if test="deleteBy != null">#{deleteBy},</if>
         </trim>
    </insert>

    <update id="updateUavOrganization" parameterType="com.djhk.uav.uav.model.UavOrganization">
        update uav_organization
        <trim prefix="SET" suffixOverrides=",">
            <if test="organizationName != null">organization_name = #{organizationName},</if>
            <if test="organizationStatus != null">organization_status = #{organizationStatus},</if>
            <if test="organizationNo != null">organization_no = #{organizationNo},</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="remark != null">remark = #{remark},</if>
            <if test="deleteTime != null">delete_time = #{deleteTime},</if>
            <if test="deleteBy != null">delete_by = #{deleteBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteUavOrganizationById" parameterType="Long">
        delete from uav_organization where id = #{id}
    </delete>

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