package com.base.track.service;


import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.base.api.client.PayloadRpcService;
import com.base.api.model.PayloadRpcDTO;
import com.base.api.model.PayloadWorkModeRpcDTO;
import com.base.api.model.request.PayloadRpcReqDTO;
import com.base.orbit.utils.DateUtils;
import com.base.orbit.utils.StringUtil;
import com.base.track.mapper.SubPointDataMapper;
import com.base.track.model.dto.request.QueryEphListDTO;
import com.base.track.model.dto.request.SubPointRequestDTO;
import com.base.track.model.dto.response.SubPointDataDTO;
import com.base.track.model.dto.response.SubPointSatelliteListByDTO;
import com.base.track.model.entity.SubPointData;
import com.base.track.model.enums.PayloadTypeEnums;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Date;
import java.util.stream.Collectors;

@Service
@Slf4j
public class SubPointDataService extends ServiceImpl<SubPointDataMapper, SubPointData> {

    private static String driver = "com.mysql.cj.jdbc.Driver";
    private static String url = "jdbc:mysql://192.168.1.188:3306/orbit_base_track?useUnicode=true&characterEncoding=UTF8&useSSL=false&serverTimezone=GMT%2b8&allowPublicKeyRetrieval=true";
    private static String userName = "root";
    private static String password = "root";

    @Resource
    SubPointDataMapper subPointDataMapper;

    @Resource
    PayloadRpcService payloadRpcService;

    public List<SubPointSatelliteListByDTO> listsub(SubPointRequestDTO subPointRequestDTO) {
        List<SubPointSatelliteListByDTO> subPointSatelliteListByDTOS = new ArrayList<>();
        List<String> satelliteCodes = subPointRequestDTO.getSatelliteCodes();
        PayloadRpcReqDTO payloadRpcReqDTO = new PayloadRpcReqDTO();
        if (!CollectionUtils.isEmpty(satelliteCodes)){
            payloadRpcReqDTO.setSatelliteCodes(satelliteCodes);
        }
        List<PayloadRpcDTO> payloadRpcDTOList = payloadRpcService.getPayloadRpcDTOList(payloadRpcReqDTO);
        //目前一个卫星只对应一个载荷 所以直接遍历载荷就行
        /*Map<String, List<PayloadRpcDTO>> codePayloadMap = payloadRpcDTOList.stream().collect(Collectors.groupingBy(PayloadRpcDTO::getSatelliteCode));
        */
        if (!CollectionUtils.isEmpty(payloadRpcDTOList)){
            for (PayloadRpcDTO p:payloadRpcDTOList){
                    String satelliteCode=p.getSatelliteCode();
                    SubPointSatelliteListByDTO subPointSatelliteListByDTO = new SubPointSatelliteListByDTO();
                    String code = satelliteCode;
                    satelliteCode = StringUtil.change(satelliteCode);
                    //目前一个卫星只对应一个载荷 所以幅宽只有一个
                   /* subPointSatelliteListByDTO.setMaxSwathWidth(getMaxMaxSwathWidth(codePayloadMap, code));*/
                subPointSatelliteListByDTO.setMaxSwathWidth(String.valueOf(p.getSwathWidth()));
//            subPointSatelliteListByDTO.setPayloadType(PayloadTypeEnums.getPayloadTypeEnumsByVal(payloadRpcDTOS.get(0).getPayloadType()));
                    /*subPointSatelliteListByDTO.setPayloadType(PayloadTypeEnums.getPayloadTypeEnumsByVal(code.substring(0,3)));*/
                subPointSatelliteListByDTO.setPayloadType(PayloadTypeEnums.getPayloadTypeEnumsByVal(p.getPayloadType()));
                subPointSatelliteListByDTO.setFox(p.getFox());
/*                QueryWrapper<SubPointData> subPointDataQueryWrapper=new QueryWrapper<>();
                if (subPointRequestDTO.getStartTime()!=null){
                    subPointDataQueryWrapper.ge("date", subPointRequestDTO.getStartTime());
                }
                if (subPointRequestDTO.getEndTime()!=null){
                    subPointDataQueryWrapper.le("date", subPointRequestDTO.getEndTime());
                }
                    subPointDataQueryWrapper.eq("code", satelliteCode);
                List<SubPointData> subPointDataList =subPointDataMapper.selectList(subPointDataQueryWrapper);*/
                List<SubPointData> subPointDataList = subPointDataMapper.satelliteSubPointDataList(satelliteCode, DateUtils.StringToDate(subPointRequestDTO.getStartTime()), DateUtils.StringToDate(subPointRequestDTO.getEndTime()));


                    if (!CollectionUtils.isEmpty(subPointDataList)) {
                        /*List<SubPointDataDTO> subPointDataDTOS = changeToSubPointDataDTO(subPointDataList);*/
                        subPointSatelliteListByDTO.setSatelliteCode(code);
                        subPointSatelliteListByDTO.setStartTime(subPointDataList.get(0).getDate());
                        subPointSatelliteListByDTO.setEndTime(subPointDataList.get(subPointDataList.size() - 1).getDate());
                        subPointSatelliteListByDTO.setSubPointDataDTOS(subPointDataList);
                        subPointSatelliteListByDTOS.add(subPointSatelliteListByDTO);
                    }
            }
        }
        return subPointSatelliteListByDTOS;
    }

    public String getMaxMaxSwathWidth(Map<String, List<PayloadRpcDTO>> codePayloadMap, String satelliteCode) {
        List<PayloadRpcDTO> payloadRpcDTOS = codePayloadMap.get(satelliteCode);
        List<Double> strings = new ArrayList<>();
        for (PayloadRpcDTO p : payloadRpcDTOS) {
            //运控多幅宽 工作模式情况
           /* List<PayloadWorkModeRpcDTO> payloadWorkModeRpcDTOS = new ArrayList<>();
            if (p.getPayloadWorkModes() != null) {
                payloadWorkModeRpcDTOS = JSONArray.parseArray(p.getPayloadWorkModes(), PayloadWorkModeRpcDTO.class);
                PayloadWorkModeRpcDTO payloadWorkModeRpcDTO = payloadWorkModeRpcDTOS.stream().max(Comparator.comparing(PayloadWorkModeRpcDTO::getSwathWidth)).get();
                strings.add(payloadWorkModeRpcDTO.getSwathWidth());
            }*/
            strings.add(p.getSwathWidth());
        }
        String MaxMaxSwathWidth = Collections.max(strings).toString();
        return MaxMaxSwathWidth;
    }


    public List<SubPointDataDTO> getSingleSatelliteSubPointDataList(String satelliteCode, Date startTime, Date endTime) {
        satelliteCode = StringUtil.change(satelliteCode);
        List<SubPointData> list = subPointDataMapper.getSingleSatelliteSubPointDataList(satelliteCode, startTime, endTime);
        return changeToSubPointDataDTO(list);
    }


    List<SubPointDataDTO> changeToSubPointDataDTO(List<SubPointData> list) {
        List<SubPointDataDTO> res = new ArrayList<>();
        for (SubPointData subPointData : list) {
            SubPointDataDTO subPointDataDTO = new SubPointDataDTO();
            BeanUtils.copyProperties(subPointData, subPointDataDTO);
            res.add(subPointDataDTO);
        }
        return res;
    }

    public List<SubPointDataDTO> getSubPointListForStripExcute(QueryEphListDTO queryEphListDTO) throws Exception {
        queryEphListDTO.setCode(StringUtil.change(queryEphListDTO.getCode()));
        List<SubPointData> list = null;
        if (queryEphListDTO.getPayloadType().equals("ELECTRON") || queryEphListDTO.getPayloadType().equals("AIS")) {
            //电子星 暂时不用写
            list = queryEphEle(queryEphListDTO);
        } else {
            list = queryEphVrss2(queryEphListDTO);
        }
        return changeToSubPointDataDTO(list);
    }

    public List<SubPointData> queryEphEle(QueryEphListDTO queryEphListDTO) throws Exception {
        System.out.println("====================查询星下点方法中，载荷中卫星编号为" + queryEphListDTO.getCode() + "============================");
        System.out.println("====================查询星下点方法中，请求对象为" + queryEphListDTO.toString() + "============================");
        List<SubPointData> subPointDataListall = new ArrayList<>();
        List<SubPointData> subPointDataListall1 = new ArrayList<>();
        List<SubPointData> subPointDataListall2 = new ArrayList<>();
        String starttime = DateUtils.DateToString(queryEphListDTO.getStartTime());
        String endtime = DateUtils.DateToString(queryEphListDTO.getEndTime());
        int updown = queryEphListDTO.getUpDown();
        double northlat = queryEphListDTO.getNorthLat();
        double southlat = queryEphListDTO.getSouthLat();
        double eastlon = queryEphListDTO.getEastLon();
        double westlon = queryEphListDTO.getWestLon();
        if ((updown != 0) && (updown != 1) && (updown != 2)) {
            return null;
        }
        if ((updown == 0) || (updown == 2)) {
            double westlonQuery = westlon;
            double eastlonQuery = eastlon;
            int updownint = 0;
            List<SubPointData> subPointDataList1 = subPointDataMapper.selectSubPointDataListforStrip1(
                    queryEphListDTO.getCode()
                    , updownint
                    , starttime
                    , endtime
                    , southlat
                    , northlat
                    , westlonQuery
                    , eastlonQuery
            );
            subPointDataListall1.addAll(subPointDataList1);


            //跨子午线
            if (westlon < 0) {
                westlonQuery += 360.0;
            }
            if (eastlon < 0) {
                eastlonQuery += 360.0;
            }
            // 异常情况 lr_lon > rr_lon 跨子午线
            List<SubPointData> subPointDataList2 = subPointDataMapper.selectSubPointDataListforStrip2(
                    queryEphListDTO.getCode()
                    , updownint
                    , starttime
                    , endtime
                    , southlat
                    , northlat
                    , westlonQuery
                    , eastlonQuery
            );
            subPointDataListall1.addAll(subPointDataList2);

            if (updown == 0) {
                //按eph_time先后排序
                listSort(subPointDataListall1);
                return subPointDataListall1;
            }
        }

        if ((updown == 1) || (updown == 2)) {
            double westlonQuery = westlon;
            double eastlonQuery = eastlon;
            int updownint = 1;

            List<SubPointData> subPointDataList1 = subPointDataMapper.selectSubPointDataListforStrip3(
                    queryEphListDTO.getCode()
                    , updownint
                    , starttime
                    , endtime
                    , southlat
                    , northlat
                    , westlonQuery
                    , eastlonQuery
            );
            subPointDataListall2.addAll(subPointDataList1);

            //跨子午线
            if (westlon < 0) {
                westlonQuery += 360.0;
            }
            if (eastlon < 0) {
                eastlonQuery += 360.0;
            }
            // 异常情况 lr_lon > rr_lon 跨子午线

            List<SubPointData> subPointDataList2 = subPointDataMapper.selectSubPointDataListforStrip4(
                    queryEphListDTO.getCode()
                    , updownint
                    , starttime
                    , endtime
                    , southlat
                    , northlat
                    , westlonQuery
                    , eastlonQuery
            );
            subPointDataListall2.addAll(subPointDataList2);

            if (updown == 1) {
                //按eph_time先后排序
                listSort(subPointDataListall2);
                return subPointDataListall2;
            }
        }
        subPointDataListall.addAll(subPointDataListall1);
        subPointDataListall.addAll(subPointDataListall2);
        //按eph_time先后排序
        listSort(subPointDataListall);
        return subPointDataListall;
    }

    public List<SubPointData> queryEphVrss2(QueryEphListDTO queryEphListDTO) throws Exception {
        List<SubPointData> subPointDataListall = new ArrayList<>();
        List<SubPointData> subPointDataListall1 = new ArrayList<>();
        List<SubPointData> subPointDataListall2 = new ArrayList<>();
        String starttime = DateUtils.DateToString(queryEphListDTO.getStartTime());
        log.info("星下点查询开始时间:{}", starttime);
        String endtime = DateUtils.DateToString(queryEphListDTO.getEndTime());
        log.info("星下点查询结束时间:{}", endtime);
        int updown = queryEphListDTO.getUpDown();
        double northlat = queryEphListDTO.getNorthLat();
        double southlat = queryEphListDTO.getSouthLat();
        double eastlon = queryEphListDTO.getEastLon();
        double westlon = queryEphListDTO.getWestLon();
        if ((updown != 0) && (updown != 1) && (updown != 2)) {
            return null;
        }
        if ((updown == 1) || (updown == 2)) {
            double westlonQuery = westlon;
            double eastlonQuery = eastlon;
            int updownint = 1;
            List<SubPointData> subPointDataList1 = subPointDataMapper.selectSubPointDataListforStrip1(
                    queryEphListDTO.getCode()
                    , updownint
                    , starttime
                    , endtime
                    , southlat
                    , northlat
                    , westlonQuery
                    , eastlonQuery
            );
            subPointDataListall1.addAll(subPointDataList1);


            //跨子午线
            if (westlon < 0) {
                westlonQuery += 360.0;
            }
            if (eastlon < 0) {
                eastlonQuery += 360.0;
            }
            // 异常情况 lr_lon > rr_lon 跨子午线
            List<SubPointData> subPointDataList2 = subPointDataMapper.selectSubPointDataListforStrip2(
                    queryEphListDTO.getCode()
                    , updownint
                    , starttime
                    , endtime
                    , southlat
                    , northlat
                    , westlonQuery
                    , eastlonQuery
            );
            subPointDataListall1.addAll(subPointDataList2);

            if (updown == 1) {
                //按eph_time先后排序
                listSort(subPointDataListall1);
                return subPointDataListall1;
            }
        }

        if ((updown == 0) || (updown == 2)) {
            double westlonQuery = westlon;
            double eastlonQuery = eastlon;
            int updownint = 0;

            List<SubPointData> subPointDataList1 = subPointDataMapper.selectSubPointDataListforStrip3(
                    queryEphListDTO.getCode()
                    , updownint
                    , starttime
                    , endtime
                    , southlat
                    , northlat
                    , westlonQuery
                    , eastlonQuery
            );
            subPointDataListall2.addAll(subPointDataList1);

            //跨子午线
            if (westlon < 0) {
                westlonQuery += 360.0;
            }
            if (eastlon < 0) {
                eastlonQuery += 360.0;
            }
            // 异常情况 lr_lon > rr_lon 跨子午线

            List<SubPointData> subPointDataList2 = subPointDataMapper.selectSubPointDataListforStrip4(
                    queryEphListDTO.getCode()
                    , updownint
                    , starttime
                    , endtime
                    , southlat
                    , northlat
                    , westlonQuery
                    , eastlonQuery
            );
            subPointDataListall2.addAll(subPointDataList2);

            if (updown == 0) {
                //按eph_time先后排序
                listSort(subPointDataListall2);
                return subPointDataListall2;
            }
        }
        subPointDataListall.addAll(subPointDataListall1);
        subPointDataListall.addAll(subPointDataListall2);
        //按eph_time先后排序
        listSort(subPointDataListall);
        return subPointDataListall;
    }

/*    public   List<SubPointData> queryEphVrss2(QueryEphListDTO queryEphListDTO) throws Exception {
        try {

            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy,MM,dd,HH,mm,ss");
            String starttime=simpleDateFormat.format(queryEphListDTO.getStartTime());
            String endtime=simpleDateFormat.format(queryEphListDTO.getEndTime());
            int updown=queryEphListDTO.getUpDown();
            double northlat=queryEphListDTO.getNorthLat();
            double southlat=queryEphListDTO.getSouthLat();
            double eastlon=queryEphListDTO.getEastLon();
            double westlon=queryEphListDTO.getWestLon();
            String tablename="subpoint_"+queryEphListDTO.getCode();
// 连接数据库
            Class.forName(driver);
            // url中是否包含useSSL字段，没有则添加设该字段且禁用
            if (!url.contains("?")) {
                url = url + "?useSSL=false";
            } else if (!url.contains("useSSL=false") || !url.contains("useSSL=true")) {
                url = url + "&useSSL=false";
            }
            // 获取连接
            Connection conn = DriverManager.getConnection(url, userName, password);
            // 设置事务为非自动提交
            conn.setAutoCommit(false);

            if ((updown != 0)&& (updown != 1)&&(updown != 2)){

                return null;
            }

            String sql,sql2;
            List<SubPointData> result = new ArrayList<>();
            List<SubPointData> result0 = new ArrayList<>();
            List<SubPointData> result1 = new ArrayList<>();
            List<SubPointData> result2 = new ArrayList<>();

            if ((updown == 1)||(updown == 2)) {
                double westlonQuery=westlon;
                double eastlonQuery=eastlon;
                int updownint=1;
                sql = "select a.* from " + tablename + " a where a.UPDOWN = '" + updownint + "' and a.date >= str_to_date('" + starttime
                        + "','%Y,%m,%d,%H,%i,%s') and a.date <=  str_to_date('" + endtime + "','%Y,%m,%d,%H,%i,%s') and (a.lr_lat >= " + southlat + " and a.rr_lat <= " + northlat
                        + ") and (a.lr_lon <a.rr_lon and a.rr_lon >= " + westlonQuery + " and a.lr_lon <= " + eastlonQuery
                        + ") order by date asc";
                System.err.println(sql);
                PreparedStatement pst = conn.prepareStatement(" ");
                ResultSet resultSet1= pst.executeQuery(sql);
                while (resultSet1.next()){
                    SubPointData subPointData = new SubPointData();
                    Timestamp res =  resultSet1.getTimestamp("date");
                    Date res1 = new Date(res.getTime());
                    subPointData.setDate(res1);
                    subPointData.setLat(resultSet1.getDouble("lat"));
                    subPointData.setLon(resultSet1.getDouble("lon"));
                    subPointData.setAlt(resultSet1.getDouble("alt"));
                    subPointData.setUpdown(resultSet1.getString("updown"));
                    subPointData.setRsLon(Double.valueOf(resultSet1.getString("rs_lon")));
                    subPointData.setRrLon(Double.valueOf(resultSet1.getString("rr_lon")));
                    subPointData.setLrLon(Double.valueOf(resultSet1.getString("lr_lon")));
                    subPointData.setLsLon(Double.valueOf(resultSet1.getString("ls_lon")));

                    result.add(subPointData);
                }
                conn.commit();
                pst.close();
                result1.addAll(result);
                result.clear();

                //跨子午线
                if (westlon < 0) {
                    westlonQuery += 360.0;
                }
                if (eastlon < 0) {
                    eastlonQuery += 360.0;
                }
                // 异常情况 lr_lon > rr_lon 跨子午线


                sql2 = "select a.* from " + tablename + " a where a.UPDOWN = '" + updownint + "' and a.date >=  str_to_date('"
                        + starttime + "','%Y,%m,%d,%H,%i,%s') and a.date <=  str_to_date('" + endtime + "','%Y,%m,%d,%H,%i,%s') and (a.lr_lat >= " + southlat
                        + " and a.rr_lat <= " + northlat + ") and ((a.lr_lon >a.rr_lon )and ((a.rr_lon+360.0) >= " + westlonQuery
                        + ") and (a.lr_lon <= " + eastlonQuery + ")) order by date asc";
                System.err.println(sql2);
                PreparedStatement pst1 = conn.prepareStatement(" ");
                ResultSet resultSet2= pst1.executeQuery(sql2);
                while (resultSet2.next()){
                    SubPointData subPointData = new SubPointData();

                    Timestamp res =  resultSet2.getTimestamp("date");
                    Date res1 = new Date(res.getTime());
                    subPointData.setDate(res1);
                    subPointData.setLat(resultSet2.getDouble("lat"));
                    subPointData.setLon(resultSet2.getDouble("lon"));
                    subPointData.setAlt(resultSet2.getDouble("alt"));
                    subPointData.setUpdown(resultSet2.getString("updown"));
                    subPointData.setRsLon(Double.valueOf(resultSet2.getString("rs_lon")));
                    subPointData.setRrLon(Double.valueOf(resultSet2.getString("rr_lon")));
                    subPointData.setLrLon(Double.valueOf(resultSet2.getString("lr_lon")));
                    subPointData.setLsLon(Double.valueOf(resultSet2.getString("ls_lon")));
                    result.add(subPointData);
                }
                result1.addAll(result);
                result.clear();

                if (updown == 1) {
                    conn.close();
                    //按eph_time先后排序
                    listSort(result1);
                    return result1;
                }
            }

            if ((updown == 0)||(updown == 2)) {
                double westlonQuery=westlon;
                double eastlonQuery=eastlon;
                int updownint=0;
                sql = "select a.* from " + tablename + " a where a.UPDOWN = '" + updownint + "' and a.date >=  str_to_date('" + starttime
                        + "','%Y,%m,%d,%H,%i,%s') and a.date <=  str_to_date('" + endtime + "','%Y,%m,%d,%H,%i,%s') and (a.rr_lat >= " + southlat + " and a.lr_lat <= " + northlat
                        + ") and (a.lr_lon <a.rr_lon and a.rr_lon >= " + westlonQuery + " and a.lr_lon <= " + eastlonQuery
                        + ") order by date asc";
                System.err.println(sql);
                PreparedStatement pst2 = conn.prepareStatement(" ");
                ResultSet resultSet3 = pst2.executeQuery(sql);
                while (resultSet3.next()) {
                    SubPointData subPointData = new SubPointData();
                    Timestamp res =  resultSet3.getTimestamp("date");
                    Date res1 = new Date(res.getTime());
                    subPointData.setDate(res1);
                    subPointData.setLat(resultSet3.getDouble("lat"));
                    subPointData.setLon(resultSet3.getDouble("lon"));
                    subPointData.setAlt(resultSet3.getDouble("alt"));
                    subPointData.setRsLon(Double.valueOf(resultSet3.getString("rs_lon")));
                    subPointData.setRrLon(Double.valueOf(resultSet3.getString("rr_lon")));
                    subPointData.setLrLon(Double.valueOf(resultSet3.getString("lr_lon")));
                    subPointData.setLsLon(Double.valueOf(resultSet3.getString("ls_lon")));
                    subPointData.setUpdown(resultSet3.getString("updown"));
                    result.add(subPointData);
                }
                result0.addAll(result);
                result.clear();

                //跨子午线
                if (westlon < 0) {
                    westlonQuery += 360.0;
                }
                if (eastlon < 0) {
                    eastlonQuery += 360.0;
                }
                // 异常情况 lr_lon > rr_lon 跨子午线

                sql2 = "select a.* from " + tablename + " a where a.UPDOWN = '" + updownint + "' and a.date >=  str_to_date('"
                        + starttime + "','%Y,%m,%d,%H,%i,%s') and a.date <=  str_to_date('" + endtime + "','%Y,%m,%d,%H,%i,%s') and (a.rr_lat >= " + southlat
                        + " and a.lr_lat <= " + northlat + ") and ((a.lr_lon >a.rr_lon )and ((a.rr_lon+360.0) >= " + westlonQuery
                        + ") and (a.lr_lon <= " + eastlonQuery + ")) order by date asc";
                System.err.println(sql2);
                PreparedStatement pst3 = conn.prepareStatement(" ");
                ResultSet resultSet4 = pst3.executeQuery(sql2);
                while (resultSet4.next()) {
                    SubPointData subPointData = new SubPointData();
                    Timestamp res =  resultSet4.getTimestamp("date");
                    Date res1 = new Date(res.getTime());
                    subPointData.setDate(res1);
                    subPointData.setLat(resultSet4.getDouble("lat"));
                    subPointData.setAlt(resultSet4.getDouble("alt"));
                    subPointData.setLon(resultSet4.getDouble("lon"));
                    subPointData.setRsLon(Double.valueOf(resultSet4.getString("rs_lon")));
                    subPointData.setRrLon(Double.valueOf(resultSet4.getString("rr_lon")));
                    subPointData.setLrLon(Double.valueOf(resultSet4.getString("lr_lon")));
                    subPointData.setLsLon(Double.valueOf(resultSet4.getString("ls_lon")));
                    subPointData.setUpdown(resultSet4.getString("updown"));
                    result.add(subPointData);
                }
                result0.addAll(result);
                result.clear();

                if (updown == 0) {
                    conn.close();
                    //按eph_time先后排序
                    listSort(result0);
                    return result0;
                }
            }


            result2.addAll(result1);
            result2.addAll(result0);
            conn.close();
            //按eph_time先后排序
            listSort(result2);

            return result2;

        }catch (Exception e){
            log.error(e.toString(),e);
            throw e;
        }


    }*/

    public void listSort(List<SubPointData> subPointDatas) throws Exception {

        Collections.sort(subPointDatas, new Comparator<SubPointData>() {

            public int compare(SubPointData o1, SubPointData o2) {

                Date d1 = o1.getDate();
                Date d2 = o2.getDate();
                long l1 = d1.getTime();
                long l2 = d2.getTime();

                if (l1 < l2) {
                    return -1;
                } else {
                    return 1;
                }

            }
        });
    }

    public List<SubPointDataDTO> getSubPointDataLists(String satelliteCode, Date startTime, Date endTime, String updown) {
        satelliteCode = StringUtil.change(satelliteCode);
        List<SubPointData> list = subPointDataMapper.getSubPointDataLists(satelliteCode, startTime, endTime,  updown);
        return changeToSubPointDataDTO(list);
    }

}
