package com.prolog.rdc.tms.service.impl;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import com.prolog.rdc.tms.model.dto.e6.EquipInfoDTO;
import com.prolog.rdc.tms.model.dto.e6.EquipInfoHistoryDTO;
import com.prolog.rdc.tms.model.dto.e6.TrackDetailDTO;
import com.prolog.rdc.tms.model.dto.e6.VehicleInfoDTO;
import com.prolog.rdc.tms.model.dto.e6.VehicleTemperatureInfoDTO;
import com.prolog.rdc.tms.model.dto.e6.VehiclesAllAlarmInfoDTO;
import com.prolog.rdc.tms.model.vo.e6.EquipInfoHistoryVO;
import com.prolog.rdc.tms.model.vo.e6.EquipInfoVO;
import com.prolog.rdc.tms.model.vo.e6.TrackDetailVO;
import com.prolog.rdc.tms.model.vo.e6.VehicleInfoVO;
import com.prolog.rdc.tms.model.vo.e6.VehicleTemperatureInfoVO;
import com.prolog.rdc.tms.model.vo.e6.VehiclesAllAlarmInfoVO;
import com.prolog.rdc.tms.service.E6GpsService;
import com.prolog.rdc.tms.util.E6GpsUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author hongbo.pan
 * @date 2023/3/21
 */
@Slf4j
@Service
public class E6GpsServiceImpl implements E6GpsService {


    @Override
    public List<VehicleInfoDTO> getVehicleInfo(VehicleInfoVO vo) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("method", "GetVehcileInfo");
        map.put("vehicle", vo.getVehicle());
        map.put("isoffsetlonlat", "1");
        String data = E6GpsUtil.post(E6GpsUtil.INTERFACE_URL, map);
        return JSON.parseArray(data, VehicleInfoDTO.class);
    }

    @Override
    public List<TrackDetailDTO> getTrackDetail(TrackDetailVO vo) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("method", "GetTrackDetailAndSecond");
        map.put("vehicle", vo.getVehicle());
        map.put("btime", E6GpsUtil.formatDate(vo.getBtime()));
        map.put("etime", E6GpsUtil.formatDate(vo.getEtime()));
        map.put("second", 10);
        map.put("isoffsetlonlat", "1");
        String data = E6GpsUtil.post(E6GpsUtil.REPORT_URL, map);
        return JSON.parseArray(data, TrackDetailDTO.class);
    }

    @Override
    public List<VehicleTemperatureInfoDTO> getVehicleTemperatureInfo(VehicleTemperatureInfoVO vo) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("method", "GetVehicleTemperatureInfo");
        map.put("vehicle", vo.getVehicle());
        map.put("btime", E6GpsUtil.formatDate(vo.getBtime()));
        map.put("etime", E6GpsUtil.formatDate(vo.getEtime()));
        map.put("isoffsetlonlat", "1");
        String data = E6GpsUtil.post(E6GpsUtil.REPORT_URL, map);
        return JSON.parseArray(data, VehicleTemperatureInfoDTO.class);
    }

    @Override
    public List<VehiclesAllAlarmInfoDTO> getVechilesAllAlarmInfo(VehiclesAllAlarmInfoVO vo) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("method", "GetVechilesAllAlarmInfo");
        map.put("vehicles", vo.getVehicles());
        map.put("btime", E6GpsUtil.formatDate(vo.getBtime()));
        map.put("etime", E6GpsUtil.formatDate(vo.getEtime()));
        String data = E6GpsUtil.post(E6GpsUtil.REPORT_URL, map);
        return JSON.parseArray(data, VehiclesAllAlarmInfoDTO.class);
    }

    @Override
    public List<EquipInfoDTO> getEquipInfoReal(EquipInfoVO vo) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("equipcode", vo.getEquipCode());
        map.put("isoffsetlonlat", "1");
        String data = E6GpsUtil.post2(E6GpsUtil.BASIC_URL + "/getEquipInfoReal", map);
        return JSON.parseArray(data, EquipInfoDTO.class);
    }

    @Override
    public List<EquipInfoHistoryDTO> getEquipInfoHistory(EquipInfoHistoryVO vo) {
        Map<String, Object> map = Maps.newHashMap();
        map.put("equipcode", vo.getEquipCode());
        map.put("isoffsetlonlat", "1");
        map.put("hasPlace", "1");
        map.put("btime", E6GpsUtil.formatDate(vo.getBtime()));
        map.put("etime", E6GpsUtil.formatDate(vo.getEtime()));
        map.put("second", 0);
        String data = E6GpsUtil.post2(E6GpsUtil.BASIC_URL + "/getEquipInfoHistory", map);
        return JSON.parseArray(data, EquipInfoHistoryDTO.class);
    }

}
