| | |
| | | using AutoMapper; |
| | | using Microsoft.Extensions.Options; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Serialization; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | |
| | | using WIDESEA_Core.Utilities; |
| | | using WIDESEA_DTO.Inbound; |
| | | using WIDESEA_DTO.Outbound; |
| | | using WIDESEA_DTO.Stock; |
| | | using WIDESEA_DTO.WCSInfo; |
| | | using WIDESEA_IBasicService; |
| | | using WIDESEA_IOutboundRepository; |
| | | using WIDESEA_IOutboundService; |
| | | using WIDESEA_IStockService; |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEAWCS_DTO.WCSInfo; |
| | | |
| | | namespace WIDESEA_OutboundService |
| | | { |
| | | public partial class OutboundOrderService : ServiceBase<Dt_OutboundOrder, IOutboundOrderRepository>, IOutboundOrderService |
| | | { |
| | | /// <summary> |
| | | /// 空æåºåº |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | /// <exception cref="NotImplementedException"></exception> |
| | | public WebResponseContent PdaOutEmpty() |
| | | { |
| | | try |
| | | { |
| | | ISugarQueryable<Dt_StockInfo> sugarQueryable1 = _dbBase.Queryable<Dt_StockInfo>(); |
| | | ISugarQueryable<Dt_StockInfoDetail> sugarQueryable2 = _dbBase.Queryable<Dt_StockInfoDetail>(); |
| | | List<StockViewDTO1> list = sugarQueryable1.InnerJoin(sugarQueryable2, (a, b) => a.Id == b.StockId && b.MaterielName.Contains("空æç") && a.StockStatus == StockStatusEmun.å·²å
¥åº.ObjToInt()).Select((a, b) => new StockViewDTO1 |
| | | { |
| | | LocationCode = a.LocationCode, |
| | | PalletCode = a.PalletCode, |
| | | MaterielCode = b.MaterielCode, |
| | | MaterielName = b.MaterielName, |
| | | InDate = a.InDate, |
| | | StockId = a.Id |
| | | }).ToList(); |
| | | StockViewDTO1? stockViewDTO = list.OrderBy(x => x.InDate).FirstOrDefault(); |
| | | if (stockViewDTO == null) throw new Exception("æªæ¾å°å¯åºåºç©ºæ"); |
| | | #region 夿æ¯å¦ä¸ºç¬¬ä¸æè´§ä½ |
| | | var strings = stockViewDTO.LocationCode.ToLower().Split('-'); |
| | | var Row = Convert.ToInt32(strings[0]); |
| | | if (Row == 1) |
| | | { |
| | | var locationcode = 2.ToString("000") + "-" + strings[1] + "-" + strings[2]; |
| | | var stockViewDTO1 = list.Where(x => x.LocationCode == locationcode).OrderBy(x => x.InDate).FirstOrDefault(); |
| | | if (stockViewDTO1 != null) stockViewDTO = stockViewDTO1; |
| | | } |
| | | #endregion |
| | | stockViewDTO = list.Where(x => x.LocationCode == stockViewDTO.LocationCode).OrderByDescending(x => x.InDate).FirstOrDefault(); |
| | | Dt_LocationInfo locationInfo = _dbBase.Queryable<Dt_LocationInfo>().Where(x => x.LocationCode == stockViewDTO.LocationCode).First(); |
| | | if (locationInfo == null) throw new Exception($"æªæ¾å°è´§ä½ã{stockViewDTO.LocationCode}ãä¿¡æ¯"); |
| | | Dt_StockInfo stockInfo = _stockService.Repository.QueryFirst(a => a.Id == stockViewDTO.StockId); |
| | | if (stockInfo == null) throw new Exception($"æªæ¾å°ç©ºæåºåä¿¡æ¯"); |
| | | stockInfo.StockStatus = StockStatusEmun.åºåºä¸.ObjToInt(); |
| | | Dt_Task _Task = new Dt_Task() |
| | | { |
| | | CurrentAddress = locationInfo.LocationCode, |
| | | NextAddress = "SC01", |
| | | SourceAddress = locationInfo.LocationCode, |
| | | SourceIsPickPlace = locationInfo.Row == 1 ? false : locationInfo.CurrentQty == locationInfo.MaxQty, |
| | | TargetIsPickPlace = false, |
| | | TargetAddress = "1008", |
| | | CreateDate = DateTime.Now, |
| | | Creater = "System", |
| | | PalletCode = stockViewDTO.PalletCode, |
| | | Roadway = locationInfo.RoadwayNo, |
| | | OrderNo = "", |
| | | TaskNum = _taskRepository.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)), |
| | | TaskState = OutTaskStatusEnum.OutNew.ObjToInt(), |
| | | TaskType = TaskTypeEnum.PalletOutbound.ObjToInt(), |
| | | Dispatchertime = DateTime.Now, |
| | | }; |
| | | locationInfo.CurrentQty--; |
| | | List<WMSTaskDTO> wMSTaskDTOs = _mapper.Map<List<WMSTaskDTO>>(new List<Dt_Task>() { _Task }); |
| | | Db.Ado.BeginTran(); |
| | | _basicRepository.LocationInfoRepository.UpdateData(locationInfo); |
| | | _stockService.Repository.UpdateData(stockInfo); |
| | | _taskRepository.AddData(_Task); |
| | | var ResultData = HttpHelper.PostAsync(WCSInterfaceAddress.ReceiveTask, wMSTaskDTOs.ToJson(), headers: new Dictionary<string, string>()); |
| | | if (ResultData.Result == null) throw new Exception($"åWCSä¸å空æåºåºä»»å¡è¶
æ¶"); |
| | | WebResponseContent content = JsonConvert.DeserializeObject<WebResponseContent>(ResultData.Result); |
| | | if (content == null) throw new Exception($"ä¸å空æåºåºä»»å¡WCSæ ååº"); |
| | | if (!content.Status) throw new Exception(content.Message); |
| | | Db.Ado.CommitTran(); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Db.Ado.RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | } |
| | | } |