using DS.Module.Core; using DS.Module.Core.Data; using DS.WMS.Core.Check.Dtos; using DS.WMS.Core.Check.Interface; using DS.WMS.Core.Check.View; using DS.WMS.Core.Op.Dtos; using DS.WMS.Core.Sys.Interface; using Microsoft.AspNetCore.Mvc; using MiniExcelLibs; namespace DS.WMS.CheckApi.Controllers; /// /// 自动对账服务 /// public class CheckBillAutoController : ApiController { private readonly ICheckBillAutoService _invokeService; /// /// 构造函数 /// /// public CheckBillAutoController(ICheckBillAutoService invokeService) { _invokeService = invokeService; } /// /// 自动对账列表 /// /// /// [HttpPost] [Route("GetCheckBillAutoList")] public DataResult> GetCheckBillAutoList([FromBody] PageRequest request) { var res = _invokeService.GetCheckBillAutoList(request); return res; } /// /// 自动对账明细列表 /// /// /// [HttpPost] [Route("GetCheckBillAutoDetailList")] public DataResult> GetCheckBillAutoDetailList([FromBody] PageRequest request) { var res = _invokeService.GetCheckBillAutoDetailList(request); return res; } /// /// 编辑 /// /// /// [HttpPost] [Route("EditCheckBillAutoInfo")] public DataResult EditCheckBillAutoInfo([FromBody] CheckBillAutoReq req) { var res = _invokeService.EditCheckBillAutoInfo(req); return res; } /// /// 详情 /// /// /// [HttpGet] [Route("GetCheckBillAutoInfo")] public DataResult GetCheckBillAutoInfo([FromQuery] string id) { var res = _invokeService.GetCheckBillAutoInfo(id); return res; } /// /// 导入对账excel /// /// excel文件 /// 对账主表id /// [HttpPost] public async Task ImportExcel(IFormFile file, [FromForm] string id) { try { var formFile = file; //DataResult api_Result = new Api_Result(); //获取文件名 var fileName = formFile.FileName; // 获取文件后缀 var fileExtension = Path.GetExtension(fileName); // 判断后缀是否是xlsx或者xls if (fileExtension != ".xlsx" && fileExtension != ".xls") { return DataResult.Failed("文件格式错误"); } var length = formFile.Length; if (length > 1024 * 1024 * 10) { return DataResult.Failed("文件大小不能超过10M"); } // MemoryStream 内存流 在内存当中创建一个流(开辟空间) using (var stream = new MemoryStream()) { //将文件写入内存流 formFile.CopyTo(stream); //将流的位置归零 stream.Position = 0; //将内存流转成List集合 var list = await stream.QueryAsync(); var res = await _invokeService.CreateCheckBillAutoByExcel(id,list.ToList()); return await Task.FromResult(res); } } catch (Exception ex) { throw new Exception(ex.ToString()); } } }