<?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.UavOperatorProfessionMapper">

    <resultMap type="com.djhk.uav.uav.model.UavOperatorProfession" id="UavOperatorResult">
        <result property="id"    column="id"    />
        <result property="awardsDate"    column="awards_date"    />
        <result property="awardsContent"    column="awards_content"    />
        <result property="trainDate"    column="train_date"    />
        <result property="trainContent"    column="train_content"    />
        <result property="dailyContent"    column="daily_content"    />
        <result property="dailyMonth"    column="daily_month"    />
        <result property="dailyDuration"    column="daily_duration"    />
        <result property="totalDuration"    column="total_duration"    />
        <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="type"    column="type"    />
        <result property="annexUrl"    column="annex_url"    />
        <result property="operatorId"    column="operator_id"    />
    </resultMap>


    <sql id="selectUavOperatorVo">
        select id, awards_date,  awards_content, train_date, train_content, daily_content, daily_month, daily_duration,total_duration,
        type, annex_url,operator_id,create_by,create_time, update_by, update_time
        from professional_work
    </sql>


    <select id="selectUavOperatorList" parameterType="com.djhk.uav.uav.model.UavOperatorProfession" resultMap="UavOperatorResult">
        select p.id, p.awards_date,  p.awards_content, p.train_date, p.train_content, p.daily_content, p.daily_month, p.daily_duration,p.total_duration,
        p.type, p.annex_url,p.operator_id,p.create_by,p.create_time, p.update_by, p.update_time,o.pic_url, o.job_type,o.celebrate_date,o.user_id,
        o.user_name, o.police_no, o.police_type,o.tel,o.status, o.email,o.sex, o.operator_type, o.certificate_type,
        o.certificate_name, o.certificate_no, o.certificate_file_id
        from professional_work p left join uav_operator o on p.operator_id=o.id
        <where>
            and operator_id = #{operatorId}
            <if test="awardsContent != null "> and awards_content like concat('%', #{awardsContent}, '%')</if>
            <if test="trainContent != null "> and train_content like concat('%', #{trainContent}, '%')</if>
            <if test="dailyContent != null "> and daily_content like concat('%', #{dailyContent}, '%')</if>
            <if test="type != null "> and type = #{type}</if>
        </where>
        order by o.create_Time desc
    </select>

    <select id="selectUavOperatorById" resultType="com.djhk.uav.uav.model.UavOperatorProfession">
        <include refid="selectUavOperatorVo"/>
        where id = #{id}
    </select>

    <!--    useGeneratedKeys="true" keyProperty="id"-->
    <insert id="insertUavOperator" parameterType="com.djhk.uav.uav.model.UavOperatorProfession" >
        insert into professional_work
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="awardsDate != null">awards_date,</if>
            <if test="awardsContent != null">awards_content,</if>
            <if test="trainDate != null">train_date,</if>
            <if test="trainContent != null">train_content,</if>
            <if test="dailyContent != null">daily_content,</if>
            <if test="dailyMonth != null">daily_month,</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="dailyDuration != null">daily_duration,</if>
            <if test="totalDuration != null">total_duration,</if>
            <if test="type != null">type,</if>
            <if test="annexUrl != null">annex_Url,</if>
            <if test="operatorId != null">operator_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="awardsDate != null">#{awardsDate},</if>
            <if test="awardsContent != null">#{awardsContent},</if>
            <if test="trainDate != null">#{trainDate},</if>
            <if test="trainContent != null">#{trainContent},</if>
            <if test="dailyContent != null">#{dailyContent},</if>
            <if test="dailyMonth != null">#{dailyMonth},</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="dailyDuration != null">#{dailyDuration},</if>
            <if test="totalDuration != null">#{totalDuration},</if>
            <if test="type != null">#{type},</if>
            <if test="annexUrl != null">#{annexUrl},</if>
            <if test="operatorId != null">#{operatorId},</if>
         </trim>
    </insert>

    <update id="updateUavOperator" parameterType="com.djhk.uav.uav.model.UavOperatorProfession">
        update professional_work
        <trim prefix="SET" suffixOverrides=",">
            <if test="awardsDate != null">awards_date =#{awardsDate},</if>
            <if test="awardsContent != null">awards_content =#{awardsContent},</if>
            <if test="trainDate != null">train_date =#{trainDate},</if>
            <if test="trainContent != null">train_content =#{trainContent},</if>
            <if test="dailyContent != null">daily_content =#{dailyContent},</if>
            <if test="dailyMonth != null">daily_content =#{dailyMonth},</if>
            <if test="updateBy != null">update_by =#{updateBy},</if>
            <if test="updateTime != null">update_time =#{updateTime},</if>
            <if test="dailyDuration != null">daily_duration =#{dailyDuration},</if>
            <if test="totalDuration != null">total_duration =#{totalDuration},</if>
            <if test="type != null">type =#{type},</if>
            <if test="annexUrl != null">annex_url =#{annexUrl},</if>
            <if test="operatorId != null">operator_id =#{operatorId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteUavOperatorById" parameterType="Long">
        delete from professional_work where id = #{id}
    </delete>

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