<?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.base.biz.mapper.TargetDemandMapper">

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, target_code, target_level, target_state, target_name, country_name, type, point_direction, point_count, moving_status, moving_evg_speed, moving_max_speed, satellite_selected, station_selected, has_custom_feature, has_electronic_feature, has_optics_feature, has_radar_feature, has_motion_feature, times, priority, target_type, first_property, unit, created_date, created_by, last_modified_by, last_modified_date,parent_id,start_time,end_time,investigative_means,observation_purpose,status,target_id
    </sql>

    <insert id="batch" parameterType="com.base.biz.model.entity.TargetDemand">
        insert into target_demand (<include refid="Base_Column_List"/>)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.id},
            #{item.targetCode},
            #{item.targetLevel},
            #{item.targetState},
            #{item.targetName},
            #{item.countryName},
            #{item.type},
            #{item.pointDirection},
            #{item.pointCount},
            #{item.movingStatus},
            #{item.movingEvgSpeed},
            #{item.movingMaxSpeed},
            #{item.satelliteSelected},
            #{item.stationSelected},
            #{item.hasCustomFeature},
            #{item.hasElectronicFeature},
            #{item.hasOpticsFeature},
            #{item.hasRadarFeature},
            #{item.hasMotionFeature},
            #{item.times},
            #{item.priority},
            #{item.targetType},
            #{item.firstProperty},
            #{item.unit},
            #{item.createdDate},
            #{item.createdBy},
            #{item.lastModifiedBy},
            #{item.lastModifiedDate},
            #{item.parentId},
            #{item.startTime},
            #{item.endTime},
            #{item.investigativeMeans},
            #{item.observationPurpose},
            #{item.status},
            #{item.targetId}
            )
        </foreach>

    </insert>

    <select id="selectTargetRelationDTOList" resultType="com.base.biz.model.entity.TargetDemand">
        select * from target_demand
        <where>
            <if test="req.parentId!=null and req.parentId!=''">
                parent_id like "%${req.parentId}%"
            </if>
            <if test="req.status!=null and req.status!=''">
                and status = #{req.status}
            </if>
            <if test="req.startTime!=null">
                and start_time &gt;= #{req.startTime}
            </if>
            <if test="req.endTime!=null">
                and end_time &lt;= #{req.endTime}
            </if>
        </where>
    </select>

    <select id="selectTargetRelationDTOListByParentIds" resultType="com.base.biz.model.entity.TargetDemand">
        select * from target_demand
        <where>
            <if test="parentIds != null and parentIds.size!=0">
                parent_id in
                <foreach collection="parentIds" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>

            </if>
        </where>
    </select>

    <!-- 批量修改需求发布状态 -->
    <update id="batchUpdateStatus" parameterType="java.util.List">
        update target_demand
        set status =
        <foreach collection="list" item="item" index="index" open="case ID" close="end" separator=" ">
            when #{item.id} then #{item.status}
        </foreach>
        where id in
        <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
            #{item.id}
        </foreach>
    </update>
</mapper>
