package com.elephant.framework.galaxy.aroad.module.roadcondition.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.elephant.framework.galaxy.aroad.module.roadcondition.dto.*;
import com.elephant.framework.galaxy.aroad.module.roadcondition.entity.RoadConditionEvent;
import com.elephant.framework.galaxy.aroad.module.roadcondition.mapper.RoadConditionEventMapper;
import com.elephant.framework.galaxy.aroad.module.roadcondition.service.RoadConditionEventService;
import org.apache.ibatis.annotations.Param;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 路况事件统计
 *
 * @author Xingyuyang
 * @date 2019-04-23 16:41:06
 */
@Service
public class RoadConditionEventServiceImpl
    extends ServiceImpl<RoadConditionEventMapper, RoadConditionEvent>
    implements RoadConditionEventService {

    public RoadConditionEvent getById(@Param("id") Integer id){
        return baseMapper.getById(id);
    }

    public IPage<RoadConditionEvent> getRoadConditionEventPage(Page<RoadConditionEvent> page, RoadConditionEvent roadConditionEvent) {
        return baseMapper.getRoadConditionEventPage(page, roadConditionEvent);
    }

    /**
   * @description : 根据事件类型查询
   * @author : Xingyuyang
   * @date : 2019/4/23 0023 17:54
   * @param :
   * @return : null
   */
  //  @Cacheable(value = "staticByEventType")
  public List<staticByEventTypeDto> staticByEventType() {
    return baseMapper.staticByEventType();
  }

  /**
   * @description : 根据影响程度查询
   * @author : Xingyuyang
   * @date : 2019/4/23 0023 17:54
   * @param :
   * @return : null
   */
  //  @Cacheable(value = "staticByInfluence")
  public List<staticByInfluenceDto> staticByInfluence() {
    return baseMapper.staticByInfluence();
  }

  /**
   * @description : 根据月份查询
   * @author : Xingyuyang
   * @date : 2019-4-24 10:27:35
   * @param :
   * @return : null
   */
  //  @Cacheable(value = "staticByMonth")
  public List<staticByMonthDto> staticByMonth() {
    return baseMapper.staticByMonth();
  }

  /**
   * @description : 根据月份查询
   * @author : Xingyuyang
   * @date : 2019-4-24 10:27:35
   * @param :
   * @return : null
   */
  //  @Cacheable(value = "staticByRoadCode")
  public List<staticByRoadCodeDto> staticByRoadCode() {
    return baseMapper.staticByRoadCode();
  }

  /**
   * @description : 根据城市查询
   * @author : Xingyuyang
   * @date : 2019/4/24 0024 14:27
   * @return :
   *     java.util.List<com.elephant.framework.galaxy.aroad.module.roadcondition.dto.staticByCityDto>
   */
  public List<staticByCityDto> staticByCity() {
    return baseMapper.staticByCity();
  }

    @Cacheable(value = "roadConditionCoordinates")
    public List<CoordinateDto> getCoordinates() {
        return baseMapper.getCoordinates();
    }

    @Cacheable(value = "tqCoordinates")
    public List<CoordinateDto> getTQCoordinates() {
        return baseMapper.getTQCoordinates();
    }

    @Cacheable(value = "yhCoordinates")
    public List<YHCoordinateDto> getYHCoordinates() {
        return baseMapper.getYHCoordinates();
    }

    @Cacheable(value = "sfzCoordinates")
    public List<CoordinateDto> getSFZCoordinates() {
        return baseMapper.getSFZCoordinates();
    }

    @Cacheable(value = "tfCoordinates")
    public List<CoordinateDto> getTFCoordinates() {
        return baseMapper.getTFCoordinates();
    }

    /**
     * @description : 根据城市查询
     * @author : Xingyuyang
     * @date : 2019/4/24 0024 14:27
     * @return :
     *     java.util.List<com.elephant.framework.galaxy.aroad.module.roadcondition.dto.staticByCityDto>
     */
    public List<staticByYHCityDto> staticByYHCity() {
        return baseMapper.staticByYHCity();
    }

    /**
   * @Description: 查询所有服务区所属路线名称和编码的树形结构 @Param: []
   *
   * @return:
   *     java.util.List<com.elephant.framework.galaxy.travel.module.basic_resources.entity.BaseServiceArea> @Author:
   *     songwenjie @Date: 2019/4/10
   */
//  @Cacheable(value="cityTree")
  public BaseTreeDto getTree() {
    List<CityNameDto> cityTree = baseMapper.getTree();
    List<SingleNameDto> Jinan = new ArrayList<>();
    List<SingleNameDto> Qingdao = new ArrayList<>();
    List<SingleNameDto> Zibo = new ArrayList<>();
    List<SingleNameDto> Dongying = new ArrayList<>();
    List<SingleNameDto> Yantai = new ArrayList<>();
    List<SingleNameDto> Weihai = new ArrayList<>();
    List<SingleNameDto> Rizhao = new ArrayList<>();
    List<SingleNameDto> Taian = new ArrayList<>();
    List<SingleNameDto> Binzhou = new ArrayList<>();
    List<SingleNameDto> Dezhou = new ArrayList<>();
    List<SingleNameDto> Liaocheng = new ArrayList<>();
    List<SingleNameDto> Heze = new ArrayList<>();
    List<SingleNameDto> Weifang = new ArrayList<>();
    List<SingleNameDto> Linyi = new ArrayList<>();
    List<SingleNameDto> Jining = new ArrayList<>();
    List<SingleNameDto> Zaozhuang = new ArrayList<>();
    List<CitysWithOrganizes> citysWithOrganizes = new ArrayList<>();
    cityTree.forEach(
        a -> {
          if (a.getCityName().equals("济南")) {
            Jinan.add(SingleNameDto.builder().organizeName(a.getOrganizeName()).build());
          }
          if (a.getCityName().equals("青岛")) {
            Qingdao.add(SingleNameDto.builder().organizeName(a.getOrganizeName()).build());
          }
          if (a.getCityName().equals("东营")) {
            Dongying.add(SingleNameDto.builder().organizeName(a.getOrganizeName()).build());
          }
          if (a.getCityName().equals("临沂")) {
            Linyi.add(SingleNameDto.builder().organizeName(a.getOrganizeName()).build());
          }
          if (a.getCityName().equals("日照")) {
            Rizhao.add(SingleNameDto.builder().organizeName(a.getOrganizeName()).build());
          }
          if (a.getCityName().equals("潍坊")) {
            Weifang.add(SingleNameDto.builder().organizeName(a.getOrganizeName()).build());
          }
          if (a.getCityName().equals("淄博")) {
            Zibo.add(SingleNameDto.builder().organizeName(a.getOrganizeName()).build());
          }
          if (a.getCityName().equals("烟台")) {
            Yantai.add(SingleNameDto.builder().organizeName(a.getOrganizeName()).build());
          }
          if (a.getCityName().equals("菏泽")) {
            Heze.add(SingleNameDto.builder().organizeName(a.getOrganizeName()).build());
          }
          if (a.getCityName().equals("济宁")) {
            Jining.add(SingleNameDto.builder().organizeName(a.getOrganizeName()).build());
          }
          if (a.getCityName().equals("泰安")) {
            Taian.add(SingleNameDto.builder().organizeName(a.getOrganizeName()).build());
          }
          if (a.getCityName().equals("威海")) {
            Weihai.add(SingleNameDto.builder().organizeName(a.getOrganizeName()).build());
          }
          if (a.getCityName().equals("枣庄")) {
            Zaozhuang.add(SingleNameDto.builder().organizeName(a.getOrganizeName()).build());
          }
          if (a.getCityName().equals("滨州")) {
            Binzhou.add(SingleNameDto.builder().organizeName(a.getOrganizeName()).build());
          }
          if (a.getCityName().equals("德州")) {
            Dezhou.add(SingleNameDto.builder().organizeName(a.getOrganizeName()).build());
          }
          if (a.getCityName().equals("聊城")) {
            Liaocheng.add(SingleNameDto.builder().organizeName(a.getOrganizeName()).build());
          }
        });

    {
      citysWithOrganizes.add(CitysWithOrganizes.builder().city("济南").names(Jinan).build());
      citysWithOrganizes.add(CitysWithOrganizes.builder().city("青岛").names(Qingdao).build());
      citysWithOrganizes.add(CitysWithOrganizes.builder().city("淄博").names(Zibo).build());
      citysWithOrganizes.add(CitysWithOrganizes.builder().city("潍坊").names(Weifang).build());
      citysWithOrganizes.add(CitysWithOrganizes.builder().city("东营").names(Dongying).build());
      citysWithOrganizes.add(CitysWithOrganizes.builder().city("滨州").names(Binzhou).build());
      citysWithOrganizes.add(CitysWithOrganizes.builder().city("德州").names(Dezhou).build());
      citysWithOrganizes.add(CitysWithOrganizes.builder().city("威海").names(Weihai).build());
      citysWithOrganizes.add(CitysWithOrganizes.builder().city("烟台").names(Yantai).build());
      citysWithOrganizes.add(CitysWithOrganizes.builder().city("聊城").names(Liaocheng).build());
      citysWithOrganizes.add(CitysWithOrganizes.builder().city("泰安").names(Taian).build());
      citysWithOrganizes.add(CitysWithOrganizes.builder().city("临沂").names(Linyi).build());
      citysWithOrganizes.add(CitysWithOrganizes.builder().city("日照").names(Rizhao).build());
      citysWithOrganizes.add(CitysWithOrganizes.builder().city("枣庄").names(Zaozhuang).build());
      citysWithOrganizes.add(CitysWithOrganizes.builder().city("济宁").names(Jining).build());
      citysWithOrganizes.add(CitysWithOrganizes.builder().city("菏泽").names(Heze).build());
    }
    return BaseTreeDto.builder().citysWithOrganizes(citysWithOrganizes).build();
  }
}
