package com.yeejoin.equipmanage.service.impl;

import com.yeejoin.equipmanage.common.utils.XmlBuilder;
import com.yeejoin.equipmanage.common.vo.LonAndLatEntityVo;
import com.yeejoin.equipmanage.common.vo.LonAndLatList;
import com.yeejoin.equipmanage.common.vo.SpeedAndTimeEntityVo;
import com.yeejoin.equipmanage.common.vo.SpeedAndTimeList;
import com.yeejoin.equipmanage.service.ICarLonAndLatDataService;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;


/**
 * @author keyong
 * @title: CarLonAndLatDataServiceImpl
 * <pre>
 * @description: TODO
 * </pre>
 * @date 2020/11/27 10:19
 */
@Service
public class CarLonAndLatDataServiceImpl implements ICarLonAndLatDataService {

    @Override
    public List<LonAndLatEntityVo> listCarLonAndLat() throws Exception {
        Resource resource = new ClassPathResource("car-history-track-data.xml");
        BufferedReader br = new BufferedReader(new InputStreamReader(resource.getInputStream()));
        StringBuffer buffer = new StringBuffer();
        String line = "";
        while((line = br.readLine())!=null)
        {
            buffer.append(line);
        }
        br.close();
        LonAndLatList list = (LonAndLatList) XmlBuilder.xmlStrToObject(LonAndLatList.class, buffer.toString());
        return list.getDataList();
    }

    @Override
    public List<SpeedAndTimeEntityVo> listCarSpeedAndGround() throws Exception {
        Resource resource = new ClassPathResource("car-history-trend-data.xml");
        BufferedReader br = new BufferedReader(new InputStreamReader(resource.getInputStream()));
        StringBuffer buffer = new StringBuffer();
        String line = "";
        while((line = br.readLine())!=null)
        {
            buffer.append(line);
        }
        br.close();
        SpeedAndTimeList list = (SpeedAndTimeList) XmlBuilder.xmlStrToObject(SpeedAndTimeList.class, buffer.toString());
        return list.getDataList();
    }
}
