| | |
| | | using Dm.filter; |
| | | using MailKit.Search; |
| | | using Microsoft.Extensions.Logging; |
| | | using Newtonsoft.Json; |
| | | using Org.BouncyCastle.Asn1.Ocsp; |
| | |
| | | using System.Linq; |
| | | using System.Net; |
| | | using System.Net.Http; |
| | | using System.Reflection.Metadata; |
| | | using System.Security.Policy; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | |
| | | |
| | | namespace WIDESEA_BasicService |
| | | { |
| | | public class TransferDataDto |
| | | { |
| | | public DateTime TransferTime { get; set; } |
| | | public List<TransferItemDto> Items { get; set; } |
| | | } |
| | | |
| | | public class TransferItemDto |
| | | { |
| | | public string MaterialCode { get; set; } |
| | | public decimal TotalQuantity { get; set; } |
| | | public List<LocationInfoDto> Locations { get; set; } |
| | | } |
| | | public class LocationInfoDto |
| | | { |
| | | public string LocationCode { get; set; } |
| | | public decimal Quantity { get; set; } |
| | | public List<BarcodeInfoDto> Barcodes { get; set; } |
| | | } |
| | | |
| | | public class BarcodeInfoDto |
| | | { |
| | | public string Barcode { get; set; } |
| | | public decimal Quantity { get; set; } |
| | | } |
| | | public class InvokeMESService : IInvokeMESService |
| | | { |
| | | private readonly IHttpClientFactory _httpClientFactory; |
| | |
| | | private readonly IRepository<Dt_StockInfoDetail> _stockInfoDetailRepository; |
| | | private readonly IRepository<Dt_StockInfo> _stockInfoRepository; |
| | | private readonly IRepository<Dt_InboundOrder> _inboundOrderRepository; |
| | | private readonly IRepository<Dt_PickingRecord> _pickingRecoreRepository; |
| | | private readonly IMaterialUnitService _materialUnitService; |
| | | private readonly IOutboundOrderService _outboundOrderService; |
| | | private readonly IOutboundOrderDetailService _outboundOrderDetailService; |
| | | private readonly IOutStockLockInfoService _outStockLockInfoService; |
| | | public InvokeMESService(IHttpClientFactory httpClientFactory, ILogger<InvokeMESService> logger, IRepository<Dt_FeedbackToMes> feedbacktomesRepository, IRepository<Dt_StockInfoDetail> stockInfoDetailRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_InboundOrder> inboundOrderRepository, IOutboundOrderService outboundOrderService, IOutboundOrderDetailService outboundOrderDetailService, IOutStockLockInfoService outStockLockInfoService, IMaterialUnitService materialUnitService) |
| | | public InvokeMESService(IHttpClientFactory httpClientFactory, ILogger<InvokeMESService> logger, IRepository<Dt_FeedbackToMes> feedbacktomesRepository, IRepository<Dt_StockInfoDetail> stockInfoDetailRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_InboundOrder> inboundOrderRepository, IOutboundOrderService outboundOrderService, IOutboundOrderDetailService outboundOrderDetailService, IOutStockLockInfoService outStockLockInfoService, IMaterialUnitService materialUnitService, IRepository<Dt_PickingRecord> pickingRecoreRepository) |
| | | { |
| | | _httpClientFactory = httpClientFactory; |
| | | _logger = logger; |
| | |
| | | _outboundOrderDetailService = outboundOrderDetailService; |
| | | _outStockLockInfoService = outStockLockInfoService; |
| | | _materialUnitService = materialUnitService; |
| | | _pickingRecoreRepository = pickingRecoreRepository; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | _client.DefaultRequestHeaders.Clear(); |
| | | _client.DefaultRequestHeaders.Add("Accept", "application/json"); |
| | | |
| | | _logger.LogInformation("InvokeMESService FeedbackOutbound : " + json); |
| | | _logger.LogInformation("InvokeMESService FeedbackOutbound : "+ model.orderNo +" , " + json); |
| | | |
| | | var response = await _client.PostAsync("AldMaterialOutbound/MaterialOutbound", content); |
| | | string body = await response.Content.ReadAsStringAsync(); |
| | |
| | | |
| | | throw new HttpRequestException(body); |
| | | } |
| | | |
| | | _logger.LogInformation("InvokeMESService FeedbackOutbound body: " + body); |
| | | |
| | | return JsonConvert.DeserializeObject<ResponseModel>(body); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | |
| | | |
| | | }; |
| | | |
| | | var groupedData = lists.GroupBy(item => new { item.MaterielCode, item.SupplyCode, item.BatchNo, item.InboundOrderRowNo, item.BarcodeUnit, item.WarehouseCode }) |
| | | var groupedData = lists.GroupBy(item => new { item.MaterielCode, item.InboundOrderRowNo, item.BarcodeUnit, item.WarehouseCode }) |
| | | .Select(group => new AllocateDtoDetail |
| | | { |
| | | MaterialCode = group.Key.MaterielCode, |
| | | LineNo = group.Key.InboundOrderRowNo, |
| | | WarehouseCode = group.Key.WarehouseCode, |
| | | Qty = group.Sum(x => x.BarcodeQty), |
| | | // warehouseCode= "1072", |
| | | Unit = group.Key.BarcodeUnit, |
| | | Barcodes = group.Select(row => new BarcodeInfo |
| | | { |
| | |
| | | Qty = row.BarcodeQty, |
| | | BatchNo = row.BatchNo, |
| | | SupplyCode = row.SupplyCode, |
| | | Unit = row.Unit |
| | | Unit = row.BarcodeUnit |
| | | }).ToList() |
| | | }).ToList(); |
| | | allocatefeedmodel.Details = groupedData; |
| | |
| | | var outboundOrder = await _outboundOrderService.Db.Queryable<Dt_OutboundOrder>().FirstAsync(x => x.OrderNo == orderNo); |
| | | if (outboundOrder != null && outboundOrder.IsBatch == 0) |
| | | { |
| | | await HandleOutboundOrderToMESCompletion(outboundOrder, orderNo); |
| | | var result = await HandleOutboundOrderToMESCompletion(outboundOrder, orderNo); |
| | | return result; |
| | | } |
| | | else if (outboundOrder != null && outboundOrder.IsBatch == 1) |
| | | { |
| | | await HandleOutboundOrderBatchToMESCompletion(outboundOrder, orderNo); |
| | | var result = await HandleOutboundOrderBatchToMESCompletion(outboundOrder, orderNo); |
| | | return result; |
| | | } |
| | | } |
| | | |
| | | } |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | private async Task HandleOutboundOrderBatchToMESCompletion(Dt_OutboundOrder outboundOrder, string orderNo) |
| | | { |
| | | |
| | | private async Task<WebResponseContent> HandleOutboundOrderBatchToMESCompletion(Dt_OutboundOrder outboundOrder, string orderNo) |
| | | { |
| | | // å®ä¹é»è®¤è¿åï¼æåæï¼ |
| | | WebResponseContent response = WebResponseContent.Instance.OK("åä¼ MESå¤ç宿"); |
| | | //0 = æªåä¼ ï¼1 = å·²åä¼ æåï¼2 = åä¼ å¤±è´¥ |
| | | try |
| | | { |
| | | // æ ¡éªï¼å·²åä¼ ç´æ¥è¿åé误 |
| | | if (outboundOrder.ReturnToMESStatus == 1) |
| | | { |
| | | return; |
| | | return WebResponseContent.Instance.Error("该åå·²ç»åä¼ ï¼"); |
| | | } |
| | | |
| | | // æ¥è¯¢è®¢åæç»ï¼ä»
æ¥è¯¢æªåä¼ æåçï¼ |
| | | var orderDetails = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>() |
| | | .LeftJoin<Dt_OutboundOrder>((o, item) => o.OrderId == item.Id) |
| | | .Where((o, item) => item.OrderNo == orderNo && item.ReturnToMESStatus != 1) |
| | | .Select((o, item) => o) |
| | | .ToListAsync(); |
| | | |
| | | var detailids = new List<int>(); |
| | | var allCompleted = true; |
| | | foreach (var detail in orderDetails.Where(x => x.ReturnToMESStatus == 0).ToList()) |
| | | if (!orderDetails.Any()) |
| | | { |
| | | if (detail.OverOutQuantity >= detail.NeedOutQuantity) |
| | | { |
| | | detailids.Add(detail.Id); |
| | | } |
| | | else |
| | | { |
| | | allCompleted = false; |
| | | } |
| | | } |
| | | if (orderDetails.Any(x => x.ReturnToMESStatus == 2)) |
| | | { |
| | | allCompleted = false; |
| | | return WebResponseContent.Instance.Error("ææ éè¦å¤çç订åæç»"); |
| | | } |
| | | |
| | | int newStatus = allCompleted ? (int)OutOrderStatusEnum.åºåºå®æ : (int)OutOrderStatusEnum.åºåºä¸; |
| | | |
| | | if (outboundOrder.OrderStatus != newStatus) |
| | | { |
| | | await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>() |
| | | .SetColumns(x => x.OrderStatus == newStatus) |
| | | .Where(x => x.OrderNo == orderNo) |
| | | .ExecuteCommandAsync(); |
| | | var pickingRecords = await _pickingRecoreRepository.Db.Queryable<Dt_PickingRecord>().Where(x => x.OrderNo == orderNo && x.ReturnToMESStatus != 1 && !x.IsCancelled).ToListAsync(); |
| | | |
| | | } |
| | | var documentno = UniqueValueGenerator.Generate(); |
| | | var feedmodel = new FeedbackOutboundRequestModel |
| | | if (!pickingRecords.Any()) |
| | | return WebResponseContent.Instance.Error("没æéè¦åä¼ çåæ£è®°å½"); |
| | | |
| | | |
| | | var documentNo = UniqueValueGenerator.Generate(); |
| | | |
| | | |
| | | var feedModel = new FeedbackOutboundRequestModel |
| | | { |
| | | reqCode = Guid.NewGuid().ToString(), |
| | | reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), |
| | | business_type = outboundOrder.BusinessType, |
| | | factoryArea = outboundOrder.FactoryArea, |
| | | operationType = 1, |
| | | Operator = outboundOrder.Operator, |
| | | Operator = outboundOrder.Operator!=""? outboundOrder.Operator:App.User.UserName, |
| | | orderNo = outboundOrder.UpperOrderNo, |
| | | documentsNO = documentno, |
| | | documentsNO = documentNo, |
| | | status = outboundOrder.OrderStatus, |
| | | details = new List<FeedbackOutboundDetailsModel>() |
| | | }; |
| | | |
| | | |
| | | foreach (var detail in orderDetails.Where(x => detailids.Contains(x.Id)).ToList()) |
| | | var detailIds = new List<int>(); |
| | | // å¡«å
æç»åæ¡ç ä¿¡æ¯ |
| | | foreach (var detail in orderDetails) |
| | | { |
| | | // è·å该æç»å¯¹åºçæ¡ç ä¿¡æ¯ï¼ä»éå®è®°å½ï¼ |
| | | var detailLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>() |
| | | .Where(x => x.OrderNo == orderNo && detailids.Contains(x.OrderDetailId) && |
| | | x.Status == (int)OutLockStockStatusEnum.æ£é宿) |
| | | .ToListAsync(); |
| | | // æ¥è¯¢è¯¥æç»å¯¹åºçé宿¡ç è®°å½ |
| | | var detailPicks = pickingRecords.Where(x => x.OrderNo == orderNo |
| | | && detail.Id == x.OrderDetailId).ToList(); |
| | | if (!detailPicks.Any()) |
| | | { |
| | | continue; |
| | | } |
| | | var detailModel = new FeedbackOutboundDetailsModel |
| | | { |
| | | materialCode = detail.MaterielCode, |
| | | lineNo = detail.lineNo, // 注æï¼è¿éå¯è½éè¦è°æ´å段å |
| | | lineNo = detail.lineNo, |
| | | warehouseCode = detail.WarehouseCode, |
| | | qty = detail.BarcodeQty, // 使ç¨è®¢åæç»çå·²åºåºæ°é |
| | | currentDeliveryQty = detail.BarcodeQty, |
| | | qty = detail.BarcodeQty, |
| | | currentDeliveryQty = 0, |
| | | unit = detail.BarcodeUnit, |
| | | barcodes = new List<WIDESEA_DTO.Outbound.BarcodesModel> () |
| | | barcodes = new List<WIDESEA_DTO.Outbound.BarcodesModel>() |
| | | }; |
| | | |
| | | if (detailLocks.Any(x => x.BarcodeUnit != x.Unit)) |
| | | // å¡«å
æ¡ç ä¿¡æ¯ï¼å«åä½è½¬æ¢ï¼ |
| | | foreach (var item in detailPicks) |
| | | { |
| | | foreach (var item in detailLocks) |
| | | if (item.PickQuantity <= 0) |
| | | { |
| | | var barmodel = new WIDESEA_DTO.Outbound.BarcodesModel |
| | | { |
| | | barcode = item.CurrentBarcode, |
| | | supplyCode = item.SupplyCode, |
| | | batchNo = item.BatchNo, |
| | | unit = item.BarcodeUnit, |
| | | qty = item.BarcodeQty // æ¡ç 级å«çæ°éä»ç¨éå®è®°å½ |
| | | }; |
| | | if (item.BarcodeUnit != item.Unit) |
| | | { |
| | | var issueoStockResult = await _materialUnitService.ConvertAsync(item.MaterielCode, item.BarcodeQty, item.Unit,item.BarcodeUnit); |
| | | barmodel.unit = issueoStockResult.Unit; |
| | | barmodel.qty = issueoStockResult.Quantity; |
| | | } |
| | | detailModel.qty = barmodel.qty; |
| | | detailModel.currentDeliveryQty = barmodel.qty; |
| | | detailModel.barcodes.Add(barmodel); |
| | | continue; |
| | | } |
| | | } |
| | | feedmodel.details.Add(detailModel); |
| | | var barModel = new WIDESEA_DTO.Outbound.BarcodesModel |
| | | { |
| | | barcode = item.Barcode, |
| | | supplyCode = item.SupplyCode, |
| | | batchNo = item.BatchNo, |
| | | unit = item.BarcodeUnit, |
| | | qty = item.PickQuantity |
| | | }; |
| | | |
| | | // åä½ä¸ä¸è´æ¶è½¬æ¢ |
| | | if (detail.BarcodeUnit != detail.Unit) |
| | | { |
| | | var convertResult = await _materialUnitService.ConvertAsync( |
| | | item.MaterielCode, item.PickQuantity, detail.Unit, detail.BarcodeUnit); |
| | | barModel.unit = convertResult.Unit; |
| | | barModel.qty = convertResult.Quantity; |
| | | } |
| | | else |
| | | { |
| | | barModel.qty = item.PickQuantity; |
| | | } |
| | | detailModel.currentDeliveryQty += barModel.qty; |
| | | detailModel.barcodes.Add(barModel); |
| | | } |
| | | detailIds.Add(detail.Id); |
| | | feedModel.details.Add(detailModel); |
| | | } |
| | | |
| | | var result = await FeedbackOutbound(feedmodel); |
| | | if (result != null && result.code == 200) |
| | | feedModel.details = feedModel.details.GroupBy(item => new { item.materialCode, item.lineNo, item.warehouseCode, item.unit,item.qty }).Select(group => new FeedbackOutboundDetailsModel |
| | | { |
| | | materialCode = group.Key.materialCode, |
| | | lineNo = group.Key.lineNo, |
| | | warehouseCode = group.Key.warehouseCode, |
| | | qty = group.Key.qty, |
| | | currentDeliveryQty = group.Sum(x => x.currentDeliveryQty), |
| | | unit = group.Key.unit, |
| | | barcodes = group.SelectMany(x => x.barcodes.GroupBy(o => new { o.barcode, o.supplyCode, o.batchNo, o.unit }).Select(row => new WIDESEA_DTO.Outbound.BarcodesModel |
| | | { |
| | | barcode = row.Key.barcode, |
| | | supplyCode = row.Key.supplyCode, |
| | | batchNo = row.Key.batchNo, |
| | | unit = row.Key.unit, |
| | | qty = row.Sum(y => y.qty) |
| | | })).ToList() |
| | | }).ToList(); |
| | | |
| | | var allCompleted = true; |
| | | |
| | | // çéå¾
åä¼ çæç»ï¼ReturnToMESStatus=0ï¼ |
| | | var pendingDetails = orderDetails.Where(x => x.ReturnToMESStatus == 0).ToList(); |
| | | foreach (var detail in pendingDetails) |
| | | { |
| | | if (detail.OverOutQuantity < detail.NeedOutQuantity) |
| | | { |
| | | allCompleted = false; |
| | | } |
| | | } |
| | | |
| | | // åå¨åä¼ å¤±è´¥çæç»ï¼ReturnToMESStatus=2ï¼ï¼æ è®°æªå®æ |
| | | if (orderDetails.Any(x => x.ReturnToMESStatus == 2)) |
| | | { |
| | | allCompleted = false; |
| | | } |
| | | |
| | | // æ´æ°è®¢åç¶æ |
| | | int newStatus = allCompleted ? (int)OutOrderStatusEnum.åºåºå®æ : (int)OutOrderStatusEnum.åºåºä¸; |
| | | if (outboundOrder.OrderStatus != newStatus) |
| | | { |
| | | |
| | | await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>() |
| | | .SetColumns(it => new Dt_OutboundOrderDetail |
| | | { |
| | | ReturnToMESStatus = 1, |
| | | documentsNO = documentno, |
| | | }) |
| | | .Where(x => detailids.Contains(x.Id)) |
| | | int updateCount = await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>() |
| | | .SetColumns(x => x.OrderStatus == newStatus) |
| | | .Where(x => x.OrderNo == orderNo) |
| | | .ExecuteCommandAsync(); |
| | | |
| | | if (allCompleted && newStatus == (int)OutOrderStatusEnum.åºåºå®æ) |
| | | if (updateCount <= 0) |
| | | { |
| | | await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>() |
| | | .SetColumns(x => x.ReturnToMESStatus == 1) |
| | | .Where(x => x.OrderNo == orderNo) |
| | | .ExecuteCommandAsync(); |
| | | _logger.LogWarning($"æ´æ°åºåºåç¶æå¤±è´¥ - OrderNo: {orderNo}, ç®æ ç¶æ: {newStatus}"); |
| | | |
| | | } |
| | | else |
| | | { |
| | | var dborderDetails = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>() |
| | | .LeftJoin<Dt_OutboundOrder>((o, item) => o.OrderId == item.Id) |
| | | .Where((o, item) => item.OrderNo == orderNo && item.ReturnToMESStatus != 1) |
| | | .Select((o, item) => o) |
| | | .ToListAsync(); |
| | | var secallCompleted = true; |
| | | foreach (var detail in orderDetails.Where(x => x.ReturnToMESStatus == 0).ToList()) |
| | | } |
| | | |
| | | |
| | | // è°ç¨MESåä¼ æ¥å£ |
| | | var mesResult = await FeedbackOutbound(feedModel); |
| | | if (mesResult == null || mesResult.code != 200) |
| | | { |
| | | |
| | | // æ´æ°æç»ä¸ºåä¼ å¤±è´¥ï¼ReturnToMESStatus=2ï¼ |
| | | await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>() |
| | | .SetColumns(it => new Dt_OutboundOrderDetail |
| | | { |
| | | if (detail.OverOutQuantity < detail.NeedOutQuantity) |
| | | { |
| | | secallCompleted = false; |
| | | } |
| | | } |
| | | if (secallCompleted) |
| | | ReturnToMESStatus = 2, |
| | | documentsNO = documentNo, |
| | | }) |
| | | .Where(x => detailIds.Contains(x.Id)) |
| | | .ExecuteCommandAsync(); |
| | | |
| | | return WebResponseContent.Instance.Error($"åä¼ MES失败"); |
| | | } |
| | | foreach (var record in pickingRecords.Where(x => detailIds.Contains(x.OrderDetailId)).ToList()) |
| | | { |
| | | record.ReturnToMESStatus = 1; |
| | | } |
| | | var updates = pickingRecords.Where(x => detailIds.Contains(x.OrderDetailId)).ToList(); |
| | | updates.ForEach(x => |
| | | { |
| | | x.ReturnToMESStatus = 1; |
| | | }); |
| | | await _pickingRecoreRepository.Db.Updateable(updates).ExecuteCommandAsync(); |
| | | if (allCompleted) |
| | | { |
| | | //MESåä¼ æåï¼æ´æ°æç»ä¸ºåä¼ æåç¶æ |
| | | await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>() |
| | | .SetColumns(it => new Dt_OutboundOrderDetail |
| | | { |
| | | await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>() |
| | | .SetColumns(it => new Dt_OutboundOrder |
| | | { |
| | | ReturnToMESStatus = 1, |
| | | OrderStatus = OutOrderStatusEnum.åºåºå®æ.ObjToInt(), |
| | | }) |
| | | .Where(x => x.OrderNo == orderNo) |
| | | .ExecuteCommandAsync(); |
| | | } |
| | | } |
| | | ReturnToMESStatus = 1, |
| | | documentsNO = documentNo, |
| | | }) |
| | | .Where(x => detailIds.Contains(x.Id)) |
| | | .ExecuteCommandAsync(); |
| | | } |
| | | // æ ¡éªæ¯å¦æææç»é½å®æï¼æ´æ°è®¢åæç»ç¶æ |
| | | if (allCompleted && newStatus == (int)OutOrderStatusEnum.åºåºå®æ) |
| | | { |
| | | await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>() |
| | | .SetColumns(x => new Dt_OutboundOrder |
| | | { |
| | | ReturnToMESStatus = 1, |
| | | OrderStatus = newStatus |
| | | }) |
| | | .Where(x => x.OrderNo == orderNo) |
| | | .ExecuteCommandAsync(); |
| | | } |
| | | else |
| | | { |
| | | await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>() |
| | | .SetColumns(it => new Dt_OutboundOrderDetail |
| | | { |
| | | ReturnToMESStatus = 2, |
| | | documentsNO = documentno, |
| | | }) |
| | | .Where(x => detailids.Contains(x.Id)) |
| | | .ExecuteCommandAsync(); |
| | | // äºæ¬¡æ ¡éªæ¯å¦æææªåä¼ æç»é½å·²å®æ |
| | | var dbOrderDetails = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>() |
| | | .LeftJoin<Dt_OutboundOrder>((o, item) => o.OrderId == item.Id) |
| | | .Where((o, item) => item.OrderNo == orderNo && item.ReturnToMESStatus != 1) |
| | | .Select((o, item) => o) |
| | | .ToListAsync(); |
| | | |
| | | var secAllCompleted = true; |
| | | foreach (var detail in dbOrderDetails.Where(x => x.ReturnToMESStatus == 0).ToList()) |
| | | { |
| | | if (detail.OverOutQuantity < detail.NeedOutQuantity) |
| | | { |
| | | secAllCompleted = false; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (secAllCompleted) |
| | | { |
| | | await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>() |
| | | .SetColumns(it => new Dt_OutboundOrder |
| | | { |
| | | ReturnToMESStatus = 1, |
| | | OrderStatus = OutOrderStatusEnum.åºåºå®æ.ObjToInt(), |
| | | }) |
| | | .Where(x => x.OrderNo == orderNo) |
| | | .ExecuteCommandAsync(); |
| | | } |
| | | } |
| | | |
| | | // åä¼ æåçæç»è¿å |
| | | response = WebResponseContent.Instance.OK($"åä¼ MESæåï¼åæ®å·ï¼{documentNo}"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _logger.LogError($"CheckAndUpdateOrderStatus失败 - OrderNo: {orderNo}, Error: {ex.Message}"); |
| | | // å
¨å±å¼å¸¸æè·ï¼è®°å½è¯¦ç»æ¥å¿ + è¿åé误 |
| | | string errorMsg = $"å¤çåºåºååä¼ MESæ¶åçå¼å¸¸ - OrderNo: {orderNo}, Error: {ex.Message}, StackTrace: {ex.StackTrace}"; |
| | | _logger.LogError(ex, errorMsg); // è®°å½å¸¦å¼å¸¸å æ çæ¥å¿ |
| | | |
| | | // å¼å¸¸è¿åï¼ç»å端çå好æç¤ºï¼éèå æ ä¿¡æ¯ï¼ |
| | | response = WebResponseContent.Instance.Error("å¤çåä¼ MESæ¶åçå¼å¸¸ï¼è¯·è系管çå"); |
| | | } |
| | | |
| | | return response; |
| | | } |
| | | |
| | | |
| | | private async Task HandleOutboundOrderToMESCompletion(Dt_OutboundOrder outboundOrder, string orderNo) |
| | | private async Task<WebResponseContent> HandleOutboundOrderToMESCompletion(Dt_OutboundOrder outboundOrder, string orderNo) |
| | | { |
| | | // åç½®åæ°æ ¡éªï¼ç©ºå¼ç´æ¥è¿åé误 |
| | | if (outboundOrder == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("åºåºåå®ä½ä¸ºç©ºï¼æ æ³å¤çåä¼ MES"); |
| | | } |
| | | |
| | | if (string.IsNullOrWhiteSpace(orderNo)) |
| | | { |
| | | return WebResponseContent.Instance.Error("订åå·ä¸ºç©ºï¼æ æ³å¤çåä¼ MES"); |
| | | } |
| | | |
| | | try |
| | | { |
| | | |
| | | if (outboundOrder.ReturnToMESStatus == 1) |
| | | { |
| | | return; |
| | | return WebResponseContent.Instance.Error($"OrderNo: {orderNo}, 该åå·²ç»åä¼ ï¼"); |
| | | } |
| | | |
| | | |
| | | var orderDetails = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>() |
| | | .LeftJoin<Dt_OutboundOrder>((o, item) => o.OrderId == item.Id) |
| | | .Where((o, item) => item.OrderNo == orderNo) |
| | | .Select((o, item) => o) |
| | | .ToListAsync(); |
| | | |
| | | // æ æç»åºæ¯è¿åè¦å |
| | | if (!orderDetails.Any()) |
| | | { |
| | | return WebResponseContent.Instance.Error($"OrderNo: {orderNo} æªæ¥è¯¢å°è®¢åæç»"); |
| | | } |
| | | |
| | | // 夿æ¯å¦æææç»å®æåºåº |
| | | bool allCompleted = true; |
| | | foreach (var detail in orderDetails) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | // æ´æ°è®¢åç¶æï¼ä¿®æ£è¯æ³é误ï¼== â =ï¼ |
| | | int newStatus = allCompleted ? (int)OutOrderStatusEnum.åºåºå®æ : (int)OutOrderStatusEnum.åºåºä¸; |
| | | |
| | | if (outboundOrder.OrderStatus != newStatus) |
| | | { |
| | | await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>() |
| | | .SetColumns(x => x.OrderStatus == newStatus) |
| | | .SetColumns(x => x.OrderStatus == newStatus) // å
³é®ä¿®æ£ï¼èµå¼èé夿 |
| | | .Where(x => x.OrderNo == orderNo) |
| | | .ExecuteCommandAsync(); |
| | | |
| | | } |
| | | //åªææ£å¸¸åæ£å®ææ¶æåMESåé¦ |
| | | |
| | | // ä»
忣宿æ¶åMESåé¦ |
| | | if (allCompleted && newStatus == (int)OutOrderStatusEnum.åºåºå®æ) |
| | | { |
| | | var feedmodel = new FeedbackOutboundRequestModel |
| | |
| | | details = new List<FeedbackOutboundDetailsModel>() |
| | | }; |
| | | |
| | | |
| | | // æå»ºæç»æ°æ® |
| | | foreach (var detail in orderDetails) |
| | | { |
| | | // è·å该æç»å¯¹åºçæ¡ç ä¿¡æ¯ï¼ä»éå®è®°å½ï¼ |
| | | var detailLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>() |
| | | .Where(x => x.OrderNo == orderNo && |
| | | x.OrderDetailId == detail.Id && |
| | | x.Status == (int)OutLockStockStatusEnum.æ£é宿) |
| | | (x.Status == (int)OutLockStockStatusEnum.æ£é宿 || x.Status == (int)OutLockStockStatusEnum.å·²ååº)) |
| | | .ToListAsync(); |
| | | |
| | | var detailModel = new FeedbackOutboundDetailsModel |
| | | { |
| | | materialCode = detail.MaterielCode, |
| | | lineNo = detail.lineNo, // 注æï¼è¿éå¯è½éè¦è°æ´å段å |
| | | warehouseCode = detail.WarehouseCode, |
| | | qty = detail.BarcodeQty, |
| | | currentDeliveryQty = detail.BarcodeQty, |
| | | unit = detail.BarcodeUnit, |
| | | barcodes = detailLocks.Select(lockInfo => new WIDESEA_DTO.Outbound.BarcodesModel |
| | | var groupdata = detailLocks.GroupBy(item => new { item.MaterielCode, item.lineNo, item.BarcodeUnit, item.WarehouseCode }) |
| | | .Select(group => new FeedbackOutboundDetailsModel |
| | | { |
| | | barcode = lockInfo.CurrentBarcode, |
| | | supplyCode = lockInfo.SupplyCode, |
| | | batchNo = lockInfo.BatchNo, |
| | | unit = lockInfo.BarcodeUnit, |
| | | qty = lockInfo.BarcodeQty // æ¡ç 级å«çæ°éä»ç¨éå®è®°å½ |
| | | }).ToList() |
| | | }; |
| | | materialCode = group.Key.MaterielCode, |
| | | lineNo = group.Key.lineNo, |
| | | warehouseCode = group.Key.WarehouseCode, |
| | | qty = group.Sum(x => x.PickedQty), |
| | | currentDeliveryQty = group.Sum(x => x.PickedQty), |
| | | unit = group.Key.BarcodeUnit, |
| | | barcodes = group.Select(lockInfo => new WIDESEA_DTO.Outbound.BarcodesModel |
| | | { |
| | | barcode = lockInfo.CurrentBarcode, |
| | | supplyCode = lockInfo.SupplyCode, |
| | | batchNo = lockInfo.BatchNo, |
| | | unit = lockInfo.BarcodeUnit, |
| | | qty = lockInfo.PickedQty |
| | | }).ToList() |
| | | }).ToList(); |
| | | |
| | | feedmodel.details.Add(detailModel); |
| | | feedmodel.details.AddRange(groupdata); |
| | | } |
| | | |
| | | // è°ç¨MESæ¥å£ |
| | | var result = await FeedbackOutbound(feedmodel); |
| | | if (result != null && result.code == 200) |
| | | if (result == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"OrderNo: {orderNo} MESåä¼ æ¥å£è¿å空"); |
| | | } |
| | | |
| | | if (result.code == 200) |
| | | { |
| | | // åä¼ æåï¼æ´æ°åä¼ ç¶æ |
| | | await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>() |
| | | .SetColumns(x => x.ReturnToMESStatus == 1) |
| | | .Where(x => x.OrderId == outboundOrder.Id) |
| | |
| | | .SetColumns(x => x.ReturnToMESStatus == 1) |
| | | .Where(x => x.OrderNo == orderNo) |
| | | .ExecuteCommandAsync(); |
| | | |
| | | await _pickingRecoreRepository.Db.Updateable<Dt_PickingRecord>() |
| | | .SetColumns(x => x.ReturnToMESStatus == 1) |
| | | .Where(x => x.OrderNo == orderNo) |
| | | .ExecuteCommandAsync(); |
| | | |
| | | return WebResponseContent.Instance.OK("åä¼ MESæå"); |
| | | } |
| | | else |
| | | { |
| | | var errorMsg = $"OrderNo: {orderNo} åä¼ MES失败ï¼é误ç ï¼{result.code}ï¼é误信æ¯ï¼{result.message ?? "æ "}"; |
| | | _logger.LogError(errorMsg); |
| | | return WebResponseContent.Instance.Error(errorMsg); |
| | | } |
| | | } |
| | | return WebResponseContent.Instance.OK("订åç¶æå·²æ´æ°ï¼æªå®å
¨å®æåæ£æ éåä¼ MES"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _logger.LogError($"CheckAndUpdateOrderStatus失败 - OrderNo: {orderNo}, Error: {ex.Message}"); |
| | | // å
¨å±å¼å¸¸æè·ï¼è¿åé误+è®°å½è¯¦ç»æ¥å¿ |
| | | var errorMsg = $"OrderNo: {orderNo} å¤çåä¼ MESæ¶åçå¼å¸¸ï¼{ex.Message}"; |
| | | _logger.LogError(ex, errorMsg); // è®°å½å æ ä¿¡æ¯ä¾¿äºææ¥ |
| | | return WebResponseContent.Instance.Error("å¤çåä¼ MESæ¶åçå¼å¸¸ï¼è¯·è系管çå"); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | public static class UniqueValueGenerator |
| | |
| | | public static string Generate() |
| | | { |
| | | var now = DateTime.Now; |
| | | string datePart = now.ToString("yyyyMMdd"); |
| | | long ticksPart = now.Ticks; |
| | | string datePart = now.ToString("yyyyMMddHHmmss"); |
| | | |
| | | |
| | | // ååéå¢è®¡æ°å¨ï¼å模1000ï¼ç¡®ä¿è®¡æ°å¨ä»
3ä½ï¼æ§å¶é¿åº¦ï¼ |
| | | long counterPart = Interlocked.Increment(ref _counter) % 1000; |
| | | |
| | | // æ¼æ¥ï¼è®¡æ°å¨è¡¥0为3ä½ï¼é¿å
使°ä¸ä¸è´ï¼ |
| | | return $"{datePart}{ticksPart}{counterPart:D3}"; |
| | | return $"{datePart}{counterPart:D3}"; |
| | | } |
| | | } |
| | | } |