package com.base.biz.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.base.biz.model.dto.request.QueryTargetRelationListDTO;
import com.base.biz.model.entity.TargetDemand;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.Date;
import java.util.List;

@Mapper
@Repository
public interface TargetDemandMapper extends BaseMapper<TargetDemand> {

    void batch(@Param("list") List<TargetDemand> list);

    List<TargetDemand> selectTargetRelationDTOList(@Param("req") QueryTargetRelationListDTO queryTargetRelationListDTO);

    @Select("SELECT parent_id FROM `target_demand` ORDER BY created_date desc limit 1")
    String getParentId();

    @Select("SELECT parent_id FROM `target_demand` where parent_id like concat ('%','${parentId}','%') ORDER BY created_date desc limit 1")
    String getParentIdByParentId(@Param("parentId") String parentId);

    @Update("update target_demand set investigative_means = #{investigativeMeans} ,  satellite_selected = #{satelliteSelected} where parent_id like concat ('%','${parentId}','%')")
    void updateInvestigativeMeansByParentId(@Param("parentId") String parentId, @Param("investigativeMeans")String investigativeMeans, @Param("satelliteSelected")String satelliteSelected);

    @Update("update target_demand set start_time = #{startTime} , end_time = #{endTime} where parent_id like concat ('%','${parentId}','%')")
    void updateTimeByParentId(@Param("parentId") String parentId, @Param("startTime")Date startTime, @Param("endTime")Date endTime);

    @Delete("delete from target_demand where parent_id like concat ('%','${parentId}','%')")
    void deleteByParentId(@Param("parentId") String parentId);

    @Update("update target_demand set status = 1 where parent_id like concat ('%','${parentId}','%') and status=0")
    void updateStatusByParentId(@Param("parentId") String parentId);

    List<TargetDemand>  selectTargetRelationDTOListByParentIds(@Param("parentIds") Collection<String> parentIds);

    int batchUpdateStatus(@Param("list")List<TargetDemand> list);




}
