| | |
| | | using SqlSugar; |
| | | using System.Reflection; |
| | | using System.Reflection.Emit; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using System.Xml.Linq; |
| | | using WIDESEA_BasicService; |
| | |
| | | private readonly IRepository<Dt_TakeStockOrder> _takeStockOrder; |
| | | public readonly IRepository<Dt_LocationType> _locationTypeRepository; |
| | | public readonly IRepository<Dt_WarehouseArea> _warehouseAreaRepository; |
| | | private readonly IRepository<Dt_OutStockLockInfo> _outboundLockInfoRepository; |
| | | public IRepository<Dt_Task> Repository => BaseDal; |
| | | |
| | | private Dictionary<string, SqlSugar.OrderByType> _taskOrderBy = new() |
| | |
| | | |
| | | public List<int> TaskOutboundTypes => typeof(TaskTypeEnum).GetEnumIndexList(); |
| | | |
| | | public TaskService(IRepository<Dt_Task> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_StockInfo> stockRepository, ILocationInfoService locationInfoService, IInboundOrderService inboundOrderService, ILocationStatusChangeRecordService locationStatusChangeRecordService, IESSApiService eSSApiService, ILogger<TaskService> logger, IStockService stockService, IRecordService recordService, IInboundOrderDetailService inboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutboundOrderDetailService outboundOrderDetailService, IInvokeMESService invokeMESService, IOutStockLockInfoService outStockLockInfoService, IAllocateService allocateService, IRepository<Dt_OutboundBatch> outboundBatchRepository, IRepository<Dt_ReCheckOrder> reCheckOrderRepository, IRepository<Dt_AllocateOrderDetail> allocateOrderDetailRepository, IRepository<Dt_AllocateOrder> allocateOrderRepository, IMaterialUnitService materialUnitService, ITask_HtyService task_HtyService, IRepository<Dt_AllocateMaterialInfo> allocateMaterialInfo, IRepository<Dt_AllocateMaterialInfo_Hty> allocateMaterialInfo_Hty, HttpClientHelper httpClientHelper, IBasicService basicService,IRepository<Dt_TakeStockOrder> takeStockOrder, IRepository<Dt_LocationType> locationTypeRepository, IRepository<Dt_WarehouseArea> warehouseAreaRepository) : base(BaseDal) |
| | | public TaskService(IRepository<Dt_Task> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_StockInfo> stockRepository, ILocationInfoService locationInfoService, IInboundOrderService inboundOrderService, ILocationStatusChangeRecordService locationStatusChangeRecordService, IESSApiService eSSApiService, ILogger<TaskService> logger, IStockService stockService, IRecordService recordService, IInboundOrderDetailService inboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutboundOrderDetailService outboundOrderDetailService, IInvokeMESService invokeMESService, IOutStockLockInfoService outStockLockInfoService, IAllocateService allocateService, IRepository<Dt_OutboundBatch> outboundBatchRepository, IRepository<Dt_ReCheckOrder> reCheckOrderRepository, IRepository<Dt_AllocateOrderDetail> allocateOrderDetailRepository, IRepository<Dt_AllocateOrder> allocateOrderRepository, IMaterialUnitService materialUnitService, ITask_HtyService task_HtyService, IRepository<Dt_AllocateMaterialInfo> allocateMaterialInfo, IRepository<Dt_AllocateMaterialInfo_Hty> allocateMaterialInfo_Hty, HttpClientHelper httpClientHelper, IBasicService basicService,IRepository<Dt_TakeStockOrder> takeStockOrder, IRepository<Dt_LocationType> locationTypeRepository, IRepository<Dt_WarehouseArea> warehouseAreaRepository, IRepository<Dt_OutStockLockInfo> outboundLockInfoRepository) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | |
| | | _takeStockOrder = takeStockOrder; |
| | | _locationTypeRepository = locationTypeRepository; |
| | | _warehouseAreaRepository = warehouseAreaRepository; |
| | | _outboundLockInfoRepository = outboundLockInfoRepository; |
| | | } |
| | | |
| | | public async Task TaskStatusChange(string taskNum, TaskStatusEnum taskStatusEnum) |
| | |
| | | } |
| | | } |
| | | stockInfo.LocationCode = task.TargetAddress; |
| | | stockInfo.StockStatus = StockStatusEmun.å
¥åºå®æ.ObjToInt(); |
| | | stockInfo.StockStatus = StockStatusEmun.å
¥åºç¡®è®¤.ObjToInt(); |
| | | stockInfo.Details.ForEach(x => |
| | | { |
| | | x.Status = StockStatusEmun.å
¥åºç¡®è®¤.ObjToInt(); |
| | |
| | | return await Task.FromResult(WebResponseContent.Instance.Error(ex.Message)); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ä»»å¡åæ¶ |
| | | /// </summary> |
| | | /// <param name="taskCodes"></param> |
| | | /// <returns></returns> |
| | | /// <summary> |
| | | public async Task<WebResponseContent> TaskCancel(List<int> taskCodes) |
| | | { |
| | | try |
| | | { |
| | | if (taskCodes == null || !taskCodes.Any()) |
| | | { |
| | | return WebResponseContent.Instance.Error("åæ¶çä»»å¡å·ä¸è½ä¸ºç©º"); |
| | | } |
| | | |
| | | //var taskCancelUrl = AppSettings.GetValue("TaskCancelUrl"); |
| | | //TaskCancelRequest taskc = new TaskCancelRequest(); |
| | | //taskc.TaskCodes = taskCodes.Select(x => x.ToString()).ToList(); |
| | | |
| | | //string json = JsonConvert.SerializeObject(taskc); |
| | | |
| | | //using var clientHttp = new HttpClient(); |
| | | //var content = new StringContent(json, Encoding.UTF8, "application/json"); |
| | | |
| | | //HttpResponseMessage response = await clientHttp.PostAsync(taskCancelUrl,content); |
| | | |
| | | //string responseJson = await response.Content.ReadAsStringAsync(); |
| | | //TaskCancelApiResponse apiResponse = JsonConvert.DeserializeObject<TaskCancelApiResponse>(responseJson); |
| | | |
| | | //if (apiResponse.Code != 0) |
| | | //{ |
| | | // return WebResponseContent.Instance.Error($"请æ±å¤±è´¥ï¼{apiResponse.Msg}"); |
| | | //} |
| | | _unitOfWorkManage.BeginTran(); |
| | | |
| | | var tasks = await Db.Queryable<Dt_Task>() |
| | | .Where(x => taskCodes.Contains(x.TaskNum)) |
| | | .ToListAsync(); |
| | | |
| | | if (!tasks.Any()) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return WebResponseContent.Instance.Error("æªæ¾å°å¯¹åºçä»»å¡ä¿¡æ¯"); |
| | | } |
| | | |
| | | int inPickType = TaskTypeEnum.InPick.ObjToInt(); |
| | | var inboundTypes = new List<int> |
| | | { |
| | | TaskTypeEnum.InAllocate.ObjToInt(), |
| | | TaskTypeEnum.InEmpty.ObjToInt(), |
| | | TaskTypeEnum.Inbound.ObjToInt(), |
| | | TaskTypeEnum.InInventory.ObjToInt(), |
| | | TaskTypeEnum.InQuality.ObjToInt() |
| | | }; |
| | | var outboundTypes = new List<int> |
| | | { |
| | | TaskTypeEnum.Outbound.ObjToInt(), |
| | | TaskTypeEnum.OutAllocate.ObjToInt() |
| | | }; |
| | | |
| | | foreach (var task in tasks) |
| | | { |
| | | if (task.TaskStatus == TaskStatusEnum.Cancel.ObjToInt()) |
| | | continue; |
| | | |
| | | var stock = await _stockRepository.QueryFirstAsync(x => x.PalletCode == task.PalletCode); |
| | | if (stock == null) |
| | | throw new Exception($"æç {task.PalletCode} æªæ¾å°åºåä¿¡æ¯"); |
| | | |
| | | if (task.TaskType == inPickType) |
| | | { |
| | | stock.StockStatus = StockStatusEmun.åºåºå®æ.ObjToInt(); |
| | | } |
| | | else if (inboundTypes.Contains(task.TaskType)) |
| | | { |
| | | stock.StockStatus = StockStatusEmun.ç»çæå.ObjToInt(); |
| | | } |
| | | else if (outboundTypes.Contains(task.TaskType)) |
| | | { |
| | | stock.StockStatus = StockStatusEmun.å
¥åºå®æ.ObjToInt(); |
| | | |
| | | var outStockLock = await _outStockLockInfoService.Db |
| | | .Queryable<Dt_OutStockLockInfo>() |
| | | .Where(x => x.PalletCode == task.PalletCode) |
| | | .FirstAsync(); |
| | | |
| | | if (outStockLock == null) |
| | | throw new Exception($"æç {task.PalletCode} æªæ¾å°åºåºéå®ä¿¡æ¯"); |
| | | |
| | | int detailId = outStockLock.OrderDetailIds.ObjToInt(); |
| | | var outboundDetail = await _outboundOrderDetailService.Db |
| | | .Queryable<Dt_OutboundOrderDetail>() |
| | | .Where(x => x.Id == detailId) |
| | | .FirstAsync(); |
| | | |
| | | if (outboundDetail == null) |
| | | throw new Exception($"åºåºæç»ID {detailId} ä¸åå¨"); |
| | | |
| | | if (outboundDetail.LockQuantity < outStockLock.AssignQuantity) |
| | | throw new Exception($"åºåºæç» {detailId} é宿°éä¸è¶³"); |
| | | |
| | | outboundDetail.LockQuantity -= outStockLock.AssignQuantity; |
| | | _outboundOrderDetailService.UpdateData(outboundDetail); |
| | | |
| | | _outboundLockInfoRepository.DeleteAndMoveIntoHty(outStockLock, OperateTypeEnum.人工å é¤); |
| | | } |
| | | |
| | | await _stockRepository.UpdateDataAsync(stock); |
| | | |
| | | task.TaskStatus = TaskStatusEnum.Cancel.ObjToInt(); |
| | | bool archiveSuccess = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.人工å é¤); |
| | | |
| | | if (!archiveSuccess) |
| | | { |
| | | await Db.Deleteable(task).ExecuteCommandAsync(); |
| | | } |
| | | } |
| | | |
| | | _unitOfWorkManage.CommitTran(); |
| | | return WebResponseContent.Instance.OK("ä»»å¡åæ¶æå"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | _logger.LogError(ex, "ä»»å¡åæ¶å¼å¸¸"); |
| | | return WebResponseContent.Instance.Error($"ä»»å¡åæ¶å¤±è´¥ï¼{ex.Message}"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |