using Autofac.Core; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using SqlSugar; using System.Net; using System.Threading.Tasks; using WIDESEA_BasicService; using WIDESEA_Common.OrderEnum; using WIDESEA_Core; using WIDESEA_Core.Attributes; using WIDESEA_Core.BaseController; using WIDESEA_DTO.Inbound; using WIDESEA_DTO.Mes; using WIDESEA_IBasicService; using WIDESEA_IInboundService; using WIDESEA_InboundService; using WIDESEA_Model.Models; namespace WIDESEA_WMSServer.Controllers.Inbound { /// /// 入库单 /// [Route("api/InboundOrder")] [ApiController] public class InboundOrderController : ApiBaseController { private readonly WIDESEA_IBasicService.IErpApiService erpApiService; private readonly WIDESEA_IBasicService.IInvokeMESService _invokeMESService; private readonly IESSApiService _eSSApiService; private readonly ILocationInfoService _locationInfoService; private readonly IDailySequenceService _dailySequenceService; private readonly IMaterialUnitService _materialUnitService; private readonly ILogger _logger; public InboundOrderController(IInboundOrderService service, WIDESEA_IBasicService.IErpApiService erpApiService, WIDESEA_IBasicService.IInvokeMESService invokeMESService, IESSApiService eSSApiService, IDailySequenceService dailySequenceService, ILocationInfoService locationInfoService, ILogger logger, IMaterialUnitService materialUnitService) : base(service) { this.erpApiService = erpApiService; _invokeMESService = invokeMESService; _eSSApiService = eSSApiService; _dailySequenceService = dailySequenceService; _locationInfoService = locationInfoService; _logger = logger; _materialUnitService = materialUnitService; } [HttpPost, Route("Test"), AllowAnonymous, MethodParamsValidate] public async Task Test() { // var purchaseToStockResult = await _materialUnitService.ConvertPurchaseToStockAsync("101001-00002", 10); // var pdddurchaseToStockResult = await _materialUnitService.ConvertPurchaseToStockAsync("100513-00210", 10); //var sddd = _locationInfoService.AssignLocation(); //var code = sddd.LocationCode; //var ssss=await _dailySequenceService.GetNextSequenceAsync(); //var ddddssss = "WSLOT" + DateTime.Now.ToString("yyyyMMddHHmmss") + ssss.ToString().PadLeft(5, '0'); //erpApiService.GetSuppliersAsync(); //erpApiService.GetMaterialUnitAsync(); //var sss=await _invokeMESService.NewMaterielToMes(new WIDESEA_DTO.Basic.MaterielToMesDTO // { // reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), // reqCode = Guid.NewGuid().ToString(), // oldmaterialCode = "b001", // newmaterialCode = "Bar01", // unit = "A01", // operationType = 1, // supplyCode = "A0001", // batchNo = "A0002", // materialCode = "FC00001", // warehouseCode = "", // factoryArea = "A01", // qty = "20.0", // }); //await _eSSApiService.MoveContainerAsync(new WIDESEA_DTO.Basic.MoveContainerRequest //{ // slotCode = "3-5", // containerCode = "A000008009" //}); //await erpApiService.GetSuppliersAsync(); //await erpApiService.GetMaterialUnitAsync(); //await erpApiService.GetMaterialInfoAsync(new WIDESEA_DTO.Basic.MaterialRequest()); return WebResponseContent.Instance.OK(code); } /// /// 接收MES入库单信息 /// /// /// [HttpPost, Route("ReceiveInboundOrder"), AllowAnonymous, MethodParamsValidate] public async Task ReceiveInboundOrder([FromBody] InboundRequestModel model) { if(model.inBounds == null || !model.inBounds.Any()) { return WebResponseContent.Instance.Error("入库单不能为空"); } _logger.LogInformation("InboundOrderController ReceiveInboundOrder: " + JsonConvert.SerializeObject(model)); List inboundOrders = new List(); foreach (var item in model.inBounds) { Dt_InboundOrder dt_InboundOrder = new Dt_InboundOrder() { Details = new List() }; foreach (var detailitem in item.details) { if (detailitem.barcodes != null && detailitem.barcodes.Any()) { foreach (var barcode in detailitem.barcodes) { Dt_InboundOrderDetail inboundOrderDetail = new Dt_InboundOrderDetail() { lineNo = detailitem.lineNo, MaterielCode = detailitem.materialCode, SupplyCode = detailitem.supplyCode, BatchNo = detailitem.batchNo, Unit = detailitem.unit, WarehouseCode = detailitem.warehouseCode, Barcode = barcode.barcode, OutBoxbarcodes = barcode.outBoxbarcodes, BarcodeUnit = barcode.unit, BarcodeQty = barcode.qty, OrderQuantity = barcode.qty }; dt_InboundOrder.Details.Add(inboundOrderDetail); } } else { Dt_InboundOrderDetail inboundOrderDetail = new Dt_InboundOrderDetail() { lineNo = detailitem.lineNo, MaterielCode = detailitem.materialCode, SupplyCode = detailitem.supplyCode, BatchNo = detailitem.batchNo, Unit = detailitem.unit, WarehouseCode = detailitem.warehouseCode, OrderQuantity = detailitem.qty, BarcodeUnit = detailitem.unit, BarcodeQty = detailitem.qty, }; dt_InboundOrder.Details.Add(inboundOrderDetail); } } dt_InboundOrder.UpperOrderNo = item.orderNo; dt_InboundOrder.BusinessType = item.business_type; dt_InboundOrder.IsBatch = item.isBatch; dt_InboundOrder.FactoryArea = item.factoryArea; inboundOrders.Add(dt_InboundOrder); } var content =await Service.ReceiveInboundOrder(inboundOrders, model.operationType); if (content.Status) return WebResponseContent.Instance.OK(200); else return WebResponseContent.Instance.Error(content.Message); } /// /// /// /// /// [HttpPost, Route("BarcodeMaterielGroup"), AllowAnonymous, MethodParamsValidate] public WebResponseContent BarcodeMaterielGroup([FromBody] BarcodeMaterielGroupDTO data) { var content = Service.BarcodeMaterielGroup(data); return content; } [HttpPost, Route("UndoPalletGroup"), AllowAnonymous, MethodParamsValidate] public WebResponseContent UndoPalletGroup(string palletCode) { return Service.UndoPalletGroup(palletCode); } /// /// /// /// /// [HttpPost, Route("EmptyMaterielGroup"), AllowAnonymous, MethodParamsValidate] public WebResponseContent EmptyMaterielGroup([FromBody] EmptyBarcodeMaterielGroupDTO data) { var content = Service.EmptyMaterielGroup(data); return content; } [HttpPost, Route("UnPalletQuantity"), AllowAnonymous, MethodParamsValidate] public WebResponseContent UnPalletQuantity(string orderNo) { return Service.UnPalletQuantity(orderNo); } [HttpPost, Route("BatchOrderFeedbackToMes"), AllowAnonymous] public async Task BatchOrderFeedbackToMes([FromBody] BatchOrderFeedbackToMesDto request) { return await _invokeMESService.BatchOrderFeedbackToMes(request.orderNos, request.inout); } } }