using Microsoft.AspNetCore.Mvc;
using MiniExcelLibs;
using NPOI.SS.UserModel;
using SqlSugar;
using System.Xml.Linq;
using WCS.BLL.DbModels;
using WCS.BLL.Manager;
using WCS.BLL.Services.IService;
using WCS.BLL.Services.Service;
using WCS.DAL.Db;
using WCS.Model;
using WCS.Model.ApiModel;
using WCS.Model.ApiModel.InOutRecord;
using WCS.Model.ApiModel.MatInventoryDetail;
using WCS.WebApi.Helper;

namespace WCS.WebApi.Controllers
{
    /// <summary>
    /// 接口记录
    /// </summary>
    [ApiController]
    [Route("[controller]")]
    public class InOutRecordController : ControllerBase
    {
        public IInOutRecordService _inOutRecordService { get; set; }

        public InOutRecordController(IInOutRecordService inOutRecordService)
        {
            _inOutRecordService = inOutRecordService;
        }

        [Route("getInOutRecord")]
        [HttpPost(Name = "getInOutRecord")]
        public async Task<ResponseBase> getInOutRecord(GetInOutRecordRequest request)
        {
            return await _inOutRecordService.getInOutRecord(request);
        }

        [HttpPost("exportInOutRecord")]
        public async Task<IActionResult> exportInOutRecord([FromBody] GetInOutRecordRequest request)
        {
            var result = await _inOutRecordService.exportInOutRecord(request);
            var data = result.Data?.Lists;
            var columns = new[]
            {
                new ExportableColumn("序号","RowNumber"),
                new ExportableColumn("库位","StoreCode"),
                new ExportableColumn("物料编码","MatCode"),
                new ExportableColumn("物料名称","MatName"),
                new ExportableColumn("规格","MatSpec"),
                new ExportableColumn("批次","MatBatch"),
                new ExportableColumn("供应商","MatSupplier"),
                new ExportableColumn("客户","MatCustomer"),
                new ExportableColumn("数量","MatQty"),
                new ExportableColumn("类型","Direction"),

                new ExportableColumn("操作人","OperateUser"),
                new ExportableColumn("操作时间","OperateTime"),

                new ExportableColumn("物料SN", "MatSN"),
            };
            if (data == null)
            {
                return NotFound();
            }
            else
                return ExportExcelHelper.Export("导出数据", columns, data);
        }

    }
}
