package com.elephant.framework.galaxy.aroad.module.roadcondition.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.elephant.framework.galaxy.aroad.module.roadcondition.dto.*;
import com.elephant.framework.galaxy.aroad.module.roadcondition.entity.RoadConditionEvent;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 路况事件统计
 *
 * @author Xingyuyang
 * @date 2019-04-23 16:41:06
 */
public interface RoadConditionEventMapper extends BaseMapper<RoadConditionEvent> {
  IPage<RoadConditionEvent> getRoadConditionEventPage(
      IPage<RoadConditionEvent> page, RoadConditionEvent roadConditionEvent,@Param("units")List units);

  List<SaveUnitDto> getUnitTree();

  List<RoadConditionEvent> getRoadConditionEventMobilePage();

  List<staticByEventTypeDto> staticByEventType();

  List<staticByInfluenceDto> staticByInfluence();

  List<staticByMonthDto> staticByMonth();

  List<staticByRoadCodeDto> staticByRoadCode();

  List<staticByCityDto> staticByCity();

  List<DeptUnitDto> getUnitByDept(@Param("deptId") String deptId);

  List<CoordinateDto> getCoordinates(@Param("units") List units);

  EventAmountDto getLKAmount();
  EventAmountDto getSPAmount();
  EventAmountDto getJTLAmount();

  List<CoordinateDto> getTQCoordinates();

  List<CoordinateDto> getYHCoordinates();

  List<CoordinateDto> getSFZCoordinates();

  List<CoordinateDto> getTFCoordinates();

  List<staticByYHCityDto> staticByYHCity();
  /**
   * @Description: 查询树形 @Param: []
   *
   * @return:
   *     java.util.List<com.elephant.framework.galaxy.travel.module.basic_resources.entity.BaseServiceArea> @Author:
   *     Xingyuyang @Date: 2019/4/25
   */
  List<CityNameDto> getTree();

  RoadConditionEvent getById(@Param("eventId") String eventId);

  @Insert("insert into roadcondition_emergencyevent (dept_id, unit_id) values (#{deptId},#{unit})")
  boolean saveUnitWithDept(@Param("deptId") String deptId, @Param("unit") String unit);

  @Delete("delete from roadcondition_emergencyevent where dept_id=#{deptId}")
  boolean deleteUnitByDept(@Param("deptId") String deptId);

  @Insert("INSERT INTO roadcondition_emergency ( event_id, emergency_event_id )\n"
          + "\t\tvalues (#{eventId},#{emergencyEventId})")
  boolean saveEmergencyUnit(
      @Param("eventId") String eventId, @Param("emergencyEventId") String emergencyEventId);

  /**
   * 查询数据库是否存在该实体
   *
   * @param event
   * @return
   */
  RoadConditionEvent selectRoadMaintainEvent(RoadConditionEvent event);

  /**
   * 撤销事件，更新flag标识为0
   *
   * @param eventIdList
   * @return
   */
  Integer updateBatchByEventId(@Param("eventIdList") List<Object> eventIdList);

  /**
   * 删除养护施工事件（假删除）更新flag标识为1
   *
   * @param event
   * @return
   */
  Integer deleteBatchByEvent(RoadConditionEvent event);

  @Insert("\t\tINSERT INTO roadcondition_unit ( unit_id, unit_name )\n"
          + "\t\tSELECT start_unit_no, maintain_unit FROM road_condition_event\n"
          + "\t\tGROUP BY start_unit_no, maintain_unit")
  boolean saveUnit();

  @Delete("delete from emergency_event where event_id=(select emergency_event_id from roadcondition_emergency where event_id=#{eventId})")
  boolean deleteEmergencyEvent(@Param("eventId")String eventId);

  @Delete("delete from roadcondition_emergency where event_id=#{eventId}")
  boolean deleteEmergencyUnit(@Param("eventId")String eventId);

  @Delete("delete from roadcondition_unit;")
  boolean deleteUnit();

  @Delete("delete from road_condition_event")
  boolean deleteEvent();

    List<RoadConditionEvent> getLksjForQS(String lxbh, Double zxzh);
  /**
   * 根据路线起点与止点路线编号查询路况事件
   */
  List<RoadConditionEvent> getQzdzhEvent( String qdzh,String zdzh,String lxbh);
}
