package com.base.track.controller.rpc;

import com.base.api.model.QueryEphListRpcDTO;
import com.base.api.model.SubPointDataRpcDTO;
import com.base.orbit.utils.BizUtils;
import com.base.orbit.utils.DateUtils;
import com.base.track.model.dto.request.QueryEphListDTO;
import com.base.track.model.dto.response.SubPointDataDTO;
import com.base.track.service.SubPointDataService;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController

@RequestMapping("/rpc/subpoint")
public class SubPointDataRpcController {

    @Resource
    SubPointDataService subPointDataService;

    @GetMapping("/list/getSingleSatelliteSubPointDataList")
    public List<SubPointDataRpcDTO> getSingleSatelliteSubPointDataList(@RequestParam("satelliteCode") String satelliteCode, @RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime) {
        Date start= DateUtils.StringToDate(startTime);
        Date end= DateUtils.StringToDate(endTime);
        List<SubPointDataDTO> subPointDataList = subPointDataService.getSingleSatelliteSubPointDataList(satelliteCode, start, end);
        return BizUtils.copyEntityToDto(SubPointDataRpcDTO.class, subPointDataList);
    }

    @PostMapping("/list/getSubPointListForStripExcute")
    public List<SubPointDataRpcDTO> getSubPointListForStripExcute(@RequestBody QueryEphListRpcDTO queryEphListRpcDTO) {
        QueryEphListDTO queryEphListDTO = new QueryEphListDTO();
        BeanUtils.copyProperties(queryEphListRpcDTO, queryEphListDTO);
        List<SubPointDataDTO> subPointDataList = null;
        try {
            subPointDataList = subPointDataService.getSubPointListForStripExcute(queryEphListDTO);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return BizUtils.copyEntityToDto(SubPointDataRpcDTO.class, subPointDataList);
    }

    @GetMapping("/list/getSubPointDataList")
    public List<SubPointDataRpcDTO> getSubPointDataList(@RequestParam("satelliteCode") String satelliteCode, @RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime, @RequestParam("updown") String updown) {
        Date start= DateUtils.StringToDate(startTime);
        Date end= DateUtils.StringToDate(endTime);
        List<SubPointDataDTO> subPointDataList = subPointDataService.getSubPointDataLists(satelliteCode, start, end,updown);
        return BizUtils.copyEntityToDto(SubPointDataRpcDTO.class, subPointDataList);
    }

    @GetMapping("/list/getSubPointDataListForTaskUpload")
    public List<SubPointDataRpcDTO> getSubPointDataListForTaskUpload(@RequestParam("satelliteCode") String satelliteCode, @RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime) {
        Date start= DateUtils.StringToDate(startTime);
        Date end= DateUtils.StringToDate(endTime);
        List<SubPointDataDTO> subPointDataList = subPointDataService.getSubPointDataLists(satelliteCode, start, end,null);
        return BizUtils.copyEntityToDto(SubPointDataRpcDTO.class, subPointDataList);
    }
}
