| | |
| | | using Newtonsoft.Json; |
| | | using Dm.filter; |
| | | using MailKit.Search; |
| | | using Microsoft.Extensions.Logging; |
| | | using Newtonsoft.Json; |
| | | using Org.BouncyCastle.Asn1.Ocsp; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | 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; |
| | | using WIDESEA_Common.OrderEnum; |
| | | using WIDESEA_Common.StockEnum; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.BaseRepository; |
| | | using WIDESEA_Core.Helper; |
| | | using WIDESEA_DTO.Allocate; |
| | | using WIDESEA_DTO.Basic; |
| | | using WIDESEA_DTO.Inbound; |
| | | using WIDESEA_DTO.Outbound; |
| | | using WIDESEA_IBasicService; |
| | | using WIDESEA_IOutboundService; |
| | | using WIDESEA_Model.Models; |
| | | |
| | | 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 ILogger<InvokeMESService> _logger; |
| | | private string UserName = "12312"; |
| | | private string Password = "1"; |
| | | public InvokeMESService(IHttpClientFactory httpClientFactory) |
| | | |
| | | private readonly IRepository<Dt_FeedbackToMes> _feedbacktomesRepository; |
| | | 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, IRepository<Dt_PickingRecord> pickingRecoreRepository) |
| | | { |
| | | _httpClientFactory = httpClientFactory; |
| | | _logger = logger; |
| | | _feedbacktomesRepository = feedbacktomesRepository; |
| | | _stockInfoDetailRepository = stockInfoDetailRepository; |
| | | _stockInfoRepository = stockInfoRepository; |
| | | _inboundOrderRepository = inboundOrderRepository; |
| | | _outboundOrderService = outboundOrderService; |
| | | _outboundOrderDetailService = outboundOrderDetailService; |
| | | _outStockLockInfoService = outStockLockInfoService; |
| | | _materialUnitService = materialUnitService; |
| | | _pickingRecoreRepository = pickingRecoreRepository; |
| | | } |
| | | |
| | | public async Task FeedbackInbound(string url, FeedbackInboundRequestModel model) |
| | | /// <summary> |
| | | /// å
¥åºåé¦ |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="HttpRequestException"></exception> |
| | | public async Task<ResponseModel> FeedbackInbound(FeedbackInboundRequestModel model) |
| | | { |
| | | string json = JsonConvert.SerializeObject(model); |
| | | string json = JsonConvert.SerializeObject(model, new JsonSerializerSettings |
| | | { |
| | | ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver() |
| | | }); |
| | | var content = new StringContent(json, Encoding.UTF8, "application/json"); |
| | | var _client = _httpClientFactory.CreateClient("MESUrl"); |
| | | _client.DefaultRequestHeaders.Clear(); |
| | | _client.DefaultRequestHeaders.Add("Accept", "application/json"); |
| | | _logger.LogInformation("InvokeMESService FeedbackInbound : " + json); |
| | | var response = await _client.PostAsync("AldMaterialWarehousing/MaterialWarehousing", content); |
| | | string body = await response.Content.ReadAsStringAsync(); |
| | | _logger.LogInformation("InvokeMESService FeedbackInbound body: " + body); |
| | | if (!response.IsSuccessStatusCode) |
| | | { |
| | | |
| | | throw new HttpRequestException(body); |
| | | } |
| | | |
| | | return JsonConvert.DeserializeObject<ResponseModel>(body); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åºåºåé¦ |
| | | /// </summary> |
| | | /// <param name="model"></param> |
| | | /// <returns></returns> |
| | | /// <exception cref="HttpRequestException"></exception> |
| | | public async Task<ResponseModel> FeedbackOutbound(FeedbackOutboundRequestModel model) |
| | | { |
| | | string json = JsonConvert.SerializeObject(model, new JsonSerializerSettings |
| | | { |
| | | ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver() |
| | | }); |
| | | var content = new StringContent(json, Encoding.UTF8, "application/json"); |
| | | var _client = _httpClientFactory.CreateClient("MESUrl"); |
| | | _client.DefaultRequestHeaders.Clear(); |
| | | _client.DefaultRequestHeaders.Add("Accept", "application/json"); |
| | | |
| | | var response = await _client.PostAsync(url, content); |
| | | _logger.LogInformation("InvokeMESService FeedbackOutbound : "+ model.orderNo +" , " + json); |
| | | |
| | | var response = await _client.PostAsync("AldMaterialOutbound/MaterialOutbound", content); |
| | | string body = await response.Content.ReadAsStringAsync(); |
| | | |
| | | if (!response.IsSuccessStatusCode) |
| | |
| | | |
| | | throw new HttpRequestException(body); |
| | | } |
| | | _logger.LogInformation("InvokeMESService FeedbackOutbound body: " + body); |
| | | |
| | | // JsonConvert.DeserializeObject<ResponseModel>(body); |
| | | return JsonConvert.DeserializeObject<ResponseModel>(body); |
| | | } |
| | | |
| | | public async Task FeedbackOutbound(string url, FeedbackOutboundRequestModel model) |
| | | public async Task<ResponseModel> FeedbackAllocate(AllocateDto model) |
| | | { |
| | | string json = JsonConvert.SerializeObject(model); |
| | | _logger.LogInformation($"InvokeMESService FeedbackAllocate åºååå: {JsonConvert.SerializeObject(model)}"); |
| | | string json = JsonConvert.SerializeObject(model, new JsonSerializerSettings |
| | | { |
| | | ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver(), |
| | | NullValueHandling = NullValueHandling.Include |
| | | }); |
| | | var content = new StringContent(json, Encoding.UTF8, "application/json"); |
| | | var _client = _httpClientFactory.CreateClient("MESUrl"); |
| | | _client.DefaultRequestHeaders.Clear(); |
| | | _client.DefaultRequestHeaders.Add("Accept", "application/json"); |
| | | |
| | | var response = await _client.PostAsync(url, content); |
| | | _logger.LogInformation("InvokeMESService FeedbackAllocate : " + json); |
| | | var response = await _client.PostAsync("AldAllocationOperation/AllocationOperation", content); |
| | | string body = await response.Content.ReadAsStringAsync(); |
| | | |
| | | _logger.LogInformation("InvokeMESService FeedbackAllocate body: " + body); |
| | | if (!response.IsSuccessStatusCode) |
| | | { |
| | | |
| | | throw new HttpRequestException(body); |
| | | } |
| | | |
| | | // JsonConvert.DeserializeObject<ResponseModel>(body); |
| | | return JsonConvert.DeserializeObject<ResponseModel>(body); |
| | | } |
| | | |
| | | public async Task<ResponseModel> NewMaterielToMes(MaterielToMesDTO model) |
| | | { |
| | | string json = JsonConvert.SerializeObject(model); |
| | | string json = JsonConvert.SerializeObject(model, new JsonSerializerSettings |
| | | { |
| | | ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver() |
| | | }); |
| | | |
| | | |
| | | string userDataEncoded = Uri.EscapeDataString(json); |
| | | //string baseUrl = "http://mestest.ald.com//OrBitWCFServiceR15/orbitwebapi.ashx?"; |
| | | string userTicket = await GetToken(UserName, Password); |
| | | string api = "WMS_BarcodeInformation"; |
| | | //string userDataEncoded = Uri.EscapeDataString(json); |
| | | ////string baseUrl = "http://mestest.ald.com//OrBitWCFServiceR15/orbitwebapi.ashx?"; |
| | | //string userTicket = await GetToken(UserName, Password); |
| | | //string api = "WMS_BarcodeInformation"; |
| | | |
| | | |
| | | var client = _httpClientFactory.CreateClient("MESUrl"); |
| | | // æ¼æ¥ URL åæ° |
| | | string url = $"{client.BaseAddress}UserTicket={userTicket}&API={api}&UserData={userDataEncoded}"; |
| | | // string url = $"{client.BaseAddress}UserTicket={userTicket}&API={api}&UserData={userDataEncoded}"; |
| | | |
| | | |
| | | client.DefaultRequestHeaders.Clear(); |
| | |
| | | |
| | | var content = new StringContent(json, Encoding.UTF8, "application/json"); |
| | | |
| | | using var response = await client.PostAsync(url, content); |
| | | _logger.LogInformation("InvokeMESService NewMaterielToMes : " + json); |
| | | |
| | | using var response = await client.PostAsync("AldBarcodeInformation/BarcodeInformation", content); |
| | | var responseText = await response.Content.ReadAsStringAsync(); |
| | | _logger.LogInformation("InvokeMESService NewMaterielToMes body: " + responseText); |
| | | if (!response.IsSuccessStatusCode) |
| | | { |
| | | throw new HttpRequestException(responseText); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="orderNos"></param> |
| | | /// <param name="inout">å
¥åºä¼ 1 åºåºä¼ 2</param> |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> BatchOrderFeedbackToMes(List<string> orderNos, int inout) |
| | | { |
| | | if (inout == 1) |
| | | { |
| | | foreach (var orderNo in orderNos) |
| | | { |
| | | try |
| | | { |
| | | var stockinfos = _stockInfoRepository.Db.Queryable<Dt_StockInfo>("info").Where(info => info.StockStatus == 6) |
| | | .Where(it => SqlFunc.Subqueryable<Dt_StockInfoDetail>().Where(s => s.StockId == it.Id && s.OrderNo == orderNo).Any()) |
| | | .ToList(); |
| | | var feeds = _feedbacktomesRepository.Db.Queryable<Dt_FeedbackToMes>().Where(x => x.OrderNo == orderNo && x.ReportStatus == 1).Select(o => o.PalletCode).ToList(); |
| | | var unreports = stockinfos.Where(x => !feeds.Contains(x.PalletCode)).ToList(); |
| | | if (unreports != null && !unreports.Any()) |
| | | { |
| | | return WebResponseContent.Instance.Error("没æéè¦åä¼ çæ°æ®"); |
| | | } |
| | | foreach (var item in unreports) |
| | | { |
| | | var lists = _stockInfoDetailRepository.Db.Queryable<Dt_StockInfoDetail>().Where(x => x.StockId == item.Id).ToList(); |
| | | if (lists.Any()) |
| | | { |
| | | var inboundOrder = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>().First(x => x.InboundOrderNo == lists.FirstOrDefault().OrderNo); |
| | | if (inboundOrder != null) |
| | | { |
| | | if (inboundOrder.OrderType == (int)InOrderTypeEnum.AllocatInbound)//è°æ¨å
¥åº |
| | | { |
| | | var allocate = SqlSugarHelper.DbWMS.Queryable<Dt_AllocateOrder>().Where(x => x.OrderNo == inboundOrder.InboundOrderNo).First(); |
| | | var allocatefeedmodel = new AllocateDto |
| | | { |
| | | ReqCode = Guid.NewGuid().ToString(), |
| | | ReqTime = DateTime.Now.ToString(), |
| | | BusinessType = "2", |
| | | FactoryArea = inboundOrder.FactoryArea, |
| | | OperationType = 1, |
| | | Operator = inboundOrder.Operator, |
| | | OrderNo = inboundOrder.UpperOrderNo, |
| | | fromWarehouse = allocate?.FromWarehouse ?? "", |
| | | toWarehouse = allocate?.ToWarehouse ?? "", |
| | | Details = new List<AllocateDtoDetail>() |
| | | |
| | | }; |
| | | |
| | | 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), |
| | | Unit = group.Key.BarcodeUnit, |
| | | Barcodes = group.Select(row => new BarcodeInfo |
| | | { |
| | | Barcode = row.Barcode, |
| | | Qty = row.BarcodeQty, |
| | | BatchNo = row.BatchNo, |
| | | SupplyCode = row.SupplyCode, |
| | | Unit = row.BarcodeUnit |
| | | }).ToList() |
| | | }).ToList(); |
| | | allocatefeedmodel.Details = groupedData; |
| | | |
| | | var result = await FeedbackAllocate(allocatefeedmodel); |
| | | if (result != null && result.code == 200) |
| | | { |
| | | _feedbacktomesRepository.Db.Insertable(new Dt_FeedbackToMes { OrderNo = orderNo, PalletCode = item.PalletCode, ReportStatus = 1 }).ExecuteCommand(); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | var feedmodel = new FeedbackInboundRequestModel |
| | | { |
| | | reqCode = Guid.NewGuid().ToString(), |
| | | reqTime = DateTime.Now.ToString(), |
| | | business_type = inboundOrder.BusinessType, |
| | | factoryArea = inboundOrder.FactoryArea, |
| | | operationType = 1, |
| | | Operator = inboundOrder.Operator, |
| | | orderNo = inboundOrder.UpperOrderNo, |
| | | status = inboundOrder.OrderStatus, |
| | | details = new List<FeedbackInboundDetailsModel>() |
| | | |
| | | }; |
| | | |
| | | var groupedData = lists.GroupBy(item => new { item.MaterielCode, item.SupplyCode, item.BatchNo, item.InboundOrderRowNo, item.BarcodeUnit, item.WarehouseCode }) |
| | | .Select(group => new FeedbackInboundDetailsModel |
| | | { |
| | | materialCode = group.Key.MaterielCode, |
| | | supplyCode = group.Key.SupplyCode, |
| | | batchNo = group.Key.BatchNo, |
| | | lineNo = group.Key.InboundOrderRowNo, |
| | | qty = group.Sum(x => x.BarcodeQty), |
| | | // warehouseCode = group.Key.WarehouseCode=="0"?"1072": group.Key.WarehouseCode, |
| | | warehouseCode = group.Key.WarehouseCode, |
| | | unit = group.Key.BarcodeUnit, |
| | | barcodes = group.Select(row => new FeedbackBarcodesModel |
| | | { |
| | | barcode = row.Barcode, |
| | | qty = row.BarcodeQty |
| | | }).ToList() |
| | | }).ToList(); |
| | | feedmodel.details = groupedData; |
| | | var result = await FeedbackInbound(feedmodel); |
| | | if (result != null && result.code == 200) |
| | | { |
| | | _feedbacktomesRepository.Db.Insertable(new Dt_FeedbackToMes { OrderNo = orderNo, PalletCode = item.PalletCode, ReportStatus = 1 }).ExecuteCommand(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _logger.LogInformation("InvokeMESService BatchOrderFeedbackToMes ååMES失败: " + ex.Message); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | |
| | | } |
| | | } |
| | | else if (inout == 2) |
| | | { |
| | | foreach (var orderNo in orderNos) |
| | | { |
| | | var outboundOrder = await _outboundOrderService.Db.Queryable<Dt_OutboundOrder>().FirstAsync(x => x.OrderNo == orderNo); |
| | | if (outboundOrder != null && outboundOrder.IsBatch == 0) |
| | | { |
| | | var result = await HandleOutboundOrderToMESCompletion(outboundOrder, orderNo); |
| | | return result; |
| | | } |
| | | else if (outboundOrder != null && outboundOrder.IsBatch == 1) |
| | | { |
| | | var result = await HandleOutboundOrderBatchToMESCompletion(outboundOrder, orderNo); |
| | | return result; |
| | | } |
| | | } |
| | | |
| | | } |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | |
| | | 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 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(); |
| | | |
| | | if (!orderDetails.Any()) |
| | | { |
| | | return WebResponseContent.Instance.Error("ææ éè¦å¤çç订åæç»"); |
| | | } |
| | | |
| | | |
| | | var pickingRecords = await _pickingRecoreRepository.Db.Queryable<Dt_PickingRecord>().Where(x => x.OrderNo == orderNo && x.ReturnToMESStatus != 1 && !x.IsCancelled).ToListAsync(); |
| | | |
| | | 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!=""? outboundOrder.Operator:App.User.UserName, |
| | | orderNo = outboundOrder.UpperOrderNo, |
| | | documentsNO = documentNo, |
| | | status = outboundOrder.OrderStatus, |
| | | details = new List<FeedbackOutboundDetailsModel>() |
| | | }; |
| | | var detailIds = new List<int>(); |
| | | // å¡«å
æç»åæ¡ç ä¿¡æ¯ |
| | | foreach (var detail in orderDetails) |
| | | { |
| | | // æ¥è¯¢è¯¥æç»å¯¹åºçé宿¡ç è®°å½ |
| | | 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, |
| | | warehouseCode = detail.WarehouseCode, |
| | | qty = detail.BarcodeQty, |
| | | currentDeliveryQty = 0, |
| | | unit = detail.BarcodeUnit, |
| | | barcodes = new List<WIDESEA_DTO.Outbound.BarcodesModel>() |
| | | }; |
| | | |
| | | // å¡«å
æ¡ç ä¿¡æ¯ï¼å«åä½è½¬æ¢ï¼ |
| | | foreach (var item in detailPicks) |
| | | { |
| | | if (item.PickQuantity <= 0) |
| | | { |
| | | continue; |
| | | } |
| | | 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); |
| | | } |
| | | |
| | | 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) |
| | | { |
| | | |
| | | int updateCount = await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>() |
| | | .SetColumns(x => x.OrderStatus == newStatus) |
| | | .Where(x => x.OrderNo == orderNo) |
| | | .ExecuteCommandAsync(); |
| | | |
| | | if (updateCount <= 0) |
| | | { |
| | | _logger.LogWarning($"æ´æ°åºåºåç¶æå¤±è´¥ - OrderNo: {orderNo}, ç®æ ç¶æ: {newStatus}"); |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | // è°ç¨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 |
| | | { |
| | | 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 |
| | | { |
| | | 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 |
| | | { |
| | | // äºæ¬¡æ ¡éªæ¯å¦æææªåä¼ æç»é½å·²å®æ |
| | | 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) |
| | | { |
| | | // å
¨å±å¼å¸¸æè·ï¼è®°å½è¯¦ç»æ¥å¿ + è¿åé误 |
| | | 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<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 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) |
| | | { |
| | | if (detail.OverOutQuantity < detail.NeedOutQuantity) |
| | | { |
| | | allCompleted = false; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | // æ´æ°è®¢åç¶æï¼ä¿®æ£è¯æ³é误ï¼== â =ï¼ |
| | | 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(); |
| | | } |
| | | |
| | | // ä»
忣宿æ¶åMESåé¦ |
| | | if (allCompleted && newStatus == (int)OutOrderStatusEnum.åºåºå®æ) |
| | | { |
| | | 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, |
| | | orderNo = outboundOrder.UpperOrderNo, |
| | | documentsNO = outboundOrder.OrderNo, |
| | | status = outboundOrder.OrderStatus, |
| | | 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.å·²ååº)) |
| | | .ToListAsync(); |
| | | |
| | | var groupdata = detailLocks.GroupBy(item => new { item.MaterielCode, item.lineNo, item.BarcodeUnit, item.WarehouseCode }) |
| | | .Select(group => new FeedbackOutboundDetailsModel |
| | | { |
| | | 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.AddRange(groupdata); |
| | | } |
| | | |
| | | // è°ç¨MESæ¥å£ |
| | | var result = await FeedbackOutbound(feedmodel); |
| | | 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) |
| | | .ExecuteCommandAsync(); |
| | | |
| | | await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>() |
| | | .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) |
| | | { |
| | | // å
¨å±å¼å¸¸æè·ï¼è¿åé误+è®°å½è¯¦ç»æ¥å¿ |
| | | var errorMsg = $"OrderNo: {orderNo} å¤çåä¼ MESæ¶åçå¼å¸¸ï¼{ex.Message}"; |
| | | _logger.LogError(ex, errorMsg); // è®°å½å æ ä¿¡æ¯ä¾¿äºææ¥ |
| | | return WebResponseContent.Instance.Error("å¤çåä¼ MESæ¶åçå¼å¸¸ï¼è¯·è系管çå"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public static class UniqueValueGenerator |
| | | { |
| | | // åå计æ°å¨ï¼çº¿ç¨å®å
¨ï¼æ¯æ¬¡éå¢1ï¼é¿å
åä¸Tickséå¤ï¼ |
| | | private static long _counter = 0; |
| | | |
| | | /// <summary> |
| | | /// çæå¯ä¸å¼ï¼æ¯æé«å¹¶åï¼ |
| | | /// </summary> |
| | | /// <returns>æ ¼å¼ï¼yyyyMMdd + Ticks + 3ä½è®¡æ°å¨ï¼å¦2025112563867890123001ï¼</returns> |
| | | public static string Generate() |
| | | { |
| | | var now = DateTime.Now; |
| | | string datePart = now.ToString("MMdd"); |
| | | long ticksPart = now.Ticks; |
| | | |
| | | // ååéå¢è®¡æ°å¨ï¼å模1000ï¼ç¡®ä¿è®¡æ°å¨ä»
3ä½ï¼æ§å¶é¿åº¦ï¼ |
| | | long counterPart = Interlocked.Increment(ref _counter) % 1000; |
| | | |
| | | // æ¼æ¥ï¼è®¡æ°å¨è¡¥0为3ä½ï¼é¿å
使°ä¸ä¸è´ï¼ |
| | | return $"{datePart}{ticksPart}"; |
| | | } |
| | | } |
| | | } |