using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using XYY.Common.Standard;
using XYY.Core.Standard.Mvc;
using XYY.Service.Standard.TrackingService;

namespace XYY.API.Tracking.Controllers
{
    [AllowAnonymous]
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TraceSupplementLogController : ApiControllerBase
    {
        private readonly ITraceSupplementLogService _traceSupplementLogService;
        private readonly ITrackingService _trackingService;
        
        public TraceSupplementLogController(ITraceSupplementLogService traceSupplementLogService
            , ITrackingService trackingService
            ) {
            this._traceSupplementLogService = traceSupplementLogService;
            this._trackingService = trackingService;
        }
        [HttpPost]
        public async Task<IActionResult> QueryData(QueryModel model)
        {
            var result = await _traceSupplementLogService.QueryData(model);
            return Ok(result);
        }
        [HttpPost]
        public async Task<IActionResult> DownloadSupplementLog(QueryModel queryModel)
        {
            var data = await _traceSupplementLogService.DownloadSupplementLog(queryModel);
            return File(DateTime.Now.ToString_yyyyMMddHHmmss() + ".xlsx", data);
        }
        public async Task<IActionResult> deleteEsLog(string TrackingNumber)
        {
           await _trackingService.deleteEs(TrackingNumber);
            return Ok();
        }
        /// <summary>
        /// 补充失败的轨迹数据
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> SupplementaryFailureTrajectory(string dateStartTime)
        {
            DateTime inputDateTime = Convert.ToDateTime(dateStartTime);
            await _trackingService.SupplementaryFailureTrajectory(inputDateTime);
            return Ok();
        }

        public async Task<IActionResult> SupplementLogs([FromForm] IFormFile file)
        {
            //System.IO.FileStream fileStream = new System.IO.FileStream(@"D:\副本tr3.xlsx", System.IO.FileMode.Open);
            _trackingService.Input(file.OpenReadStream());
            return Ok();
        }

    }
}
