<?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.supervision.combatduty.mapper.BdglTaskdutyMapper">
    
    <resultMap type="BdglTaskduty" id="BdglTaskdutyResult">
        <result property="id"    column="id"    />
        <result property="unitName"    column="unit_name"    />
        <result property="unitId"    column="unit_id"    />
        <result property="commanderName"    column="commander_name"    />
        <result property="commanderId"    column="commander_id"    />
        <result property="commanderPhone"    column="commander_phone"    />
        <result property="participantsName"    column="participants_name"    />
        <result property="participantsId"    column="participants_id"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="adress"    column="adress"    />
        <result property="question"    column="question"    />
        <result property="remarks"    column="remarks"    />

    </resultMap>

    <sql id="selectBdglTaskdutyVo">
        select id, unit_name, unit_id, commander_name, commander_id, commander_phone, participants_name, participants_id, start_time, end_time, adress, question, remarks from bdgl_taskduty
    </sql>

    <select id="selectBdglTaskdutyList" parameterType="BdglTaskduty" resultMap="BdglTaskdutyResult">
        <include refid="selectBdglTaskdutyVo"/>
        <where>  
            <if test="unitName != null  and unitName != ''"> and unit_name like concat('%', #{unitName}, '%')</if>
            <if test="unitId != null "> and unit_id = #{unitId}</if>
            <if test="commanderName != null  and commanderName != ''"> and commander_name like concat('%', #{commanderName}, '%')</if>
            <if test="commanderId != null "> and commander_id = #{commanderId}</if>
            <if test="commanderPhone != null  and commanderPhone != ''"> and commander_phone = #{commanderPhone}</if>
            <if test="participantsName != null  and participantsName != ''"> and participants_name like concat('%', #{participantsName}, '%')</if>
            <if test="participantsId != null  and participantsId != ''"> and participants_id = #{participantsId}</if>
            <if test="startTime != null  and startTime != ''">
                <![CDATA[
                    start_time<=#{startTime} and  end_time>=#{startTime}
                 ]]>
            </if>
             <!--and start_time = #{startTime}</if>-->
            <!--<if test="endTime != null  and endTime != ''"> and end_time = #{endTime}</if>-->
            <if test="adress != null  and adress != ''"> and adress = #{adress}</if>
            <if test="question != null  and question != ''"> and question = #{question}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
        </where>
        order by id desc
    </select>
    
    <select id="selectBdglTaskdutyById" parameterType="Long" resultMap="BdglTaskdutyResult">
        <include refid="selectBdglTaskdutyVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertBdglTaskduty" parameterType="BdglTaskduty" useGeneratedKeys="true" keyProperty="id">
        insert into bdgl_taskduty
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="unitName != null">unit_name,</if>
            <if test="unitId != null">unit_id,</if>
            <if test="commanderName != null">commander_name,</if>
            <if test="commanderId != null">commander_id,</if>
            <if test="commanderPhone != null">commander_phone,</if>
            <if test="participantsName != null">participants_name,</if>
            <if test="participantsId != null">participants_id,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="adress != null">adress,</if>
            <if test="question != null">question,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="unitName != null">#{unitName},</if>
            <if test="unitId != null">#{unitId},</if>
            <if test="commanderName != null">#{commanderName},</if>
            <if test="commanderId != null">#{commanderId},</if>
            <if test="commanderPhone != null">#{commanderPhone},</if>
            <if test="participantsName != null">#{participantsName},</if>
            <if test="participantsId != null">#{participantsId},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="adress != null">#{adress},</if>
            <if test="question != null">#{question},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateBdglTaskduty" parameterType="BdglTaskduty">
        update bdgl_taskduty
        <trim prefix="SET" suffixOverrides=",">
            <if test="unitName != null">unit_name = #{unitName},</if>
            <if test="unitId != null">unit_id = #{unitId},</if>
            <if test="commanderName != null">commander_name = #{commanderName},</if>
            <if test="commanderId != null">commander_id = #{commanderId},</if>
            <if test="commanderPhone != null">commander_phone = #{commanderPhone},</if>
            <if test="participantsName != null">participants_name = #{participantsName},</if>
            <if test="participantsId != null">participants_id = #{participantsId},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="adress != null">adress = #{adress},</if>
            <if test="question != null">question = #{question},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBdglTaskdutyById" parameterType="Long">
        delete from bdgl_taskduty where id = #{id}
    </delete>

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