package com.base.track.controller.rpc;


import com.base.api.model.CalEphRpcDTO;
import com.base.orbit.utils.BizUtils;
import com.base.orbit.utils.DateUtils;
import com.base.orbit.utils.StringUtil;
import com.base.track.model.dto.request.QueryEphListDTO;
import com.base.track.model.dto.response.EphDataDTO;
import com.base.track.service.EphDataService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RestController;

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

@Api(tags = "星历查询", description = "业务服务星历查询接口")
@RestController

@RequestMapping("/rpc/eph")
public class EphRpcController {

    @Resource
    EphDataService ephDataService;

    /**
     * 根据条件查询eph文件读取星历数据
     *
     * @param
     * @return
     */
    @GetMapping(value = "/list")
    public List<CalEphRpcDTO> selEphDataByFile(@RequestParam String code, @RequestParam String startTime, @RequestParam String endTime) {
        Date start= DateUtils.StringToDate(startTime);
        Date end= DateUtils.StringToDate(endTime);
        // 如果开始结束时间为同一天，则结束时间+1
        QueryEphListDTO queryEphListDTO = new QueryEphListDTO();
        queryEphListDTO.setStartTime(start);
        queryEphListDTO.setEndTime(end);
        queryEphListDTO.setCode(StringUtil.change(code));
        List<EphDataDTO> ephDataDTOList=ephDataService.getEphList(queryEphListDTO);
        return BizUtils.copyEntityToDto(CalEphRpcDTO.class,ephDataDTOList);
    }
}
