using Autofac.Core; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using SqlSugar; using System.Reflection; using WIDESEA_Core; using WIDESEA_Core.BaseController; using WIDESEA_DTO.Stock; using WIDESEA_IStockService; using WIDESEA_Model.Models; namespace WIDESEA_WMSServer.Controllers.Stock { /// /// 库存视图 /// [Route("api/StockView")] [Authorize, ApiController] public class StockViewController : Controller { private readonly IStockViewService _stockViewService; public StockViewController(IStockViewService stockViewService) { _stockViewService = stockViewService; } [HttpPost, Route("GetPageData")] public PageGridData GetPageData([FromBody] PageDataOptions options) { return _stockViewService.GetPageData(options); } [HttpPost, Route("GetDetailPage")] public object GetDetailPage([FromBody] PageDataOptions pageData) { return _stockViewService.GetDetailPage(pageData); } /// /// 导出数据 /// /// /// [HttpPost, Route("Export")] public virtual ActionResult Export([FromBody] PageDataOptions loadData) { WebResponseContent result = InvokeService("Export", new object[] { loadData }) as WebResponseContent; if (result.Status) return File( System.IO.File.ReadAllBytes(result.Data.ToString()), System.Net.Mime.MediaTypeNames.Application.Octet, Path.GetFileName(result.Data.ToString()) ); return Json(result); } private object InvokeService(string methodName, object[] parameters) { Type t = _stockViewService.GetType(); List types = new List(); foreach (var param in parameters) { types.Add(param.GetType()); } MethodInfo method = t.GetMethod(methodName, types.ToArray()); return method.Invoke(_stockViewService, parameters); } } }