heshaofeng
6 天以前 ba30538b12f66d8483b925e44f38b9ec486b4999
ÏîÄ¿´úÂë/WMSÎÞ²Ö´¢°æ/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
@@ -84,6 +84,7 @@
        private readonly IRecordService _recordService;
        private readonly IAllocateService _allocateService;
        private readonly IInvokeMESService _invokeMESService;
        private readonly ITask_HtyService _task_HtyService;
        public IRepository<Dt_Task> Repository => BaseDal;
        private Dictionary<string, SqlSugar.OrderByType> _taskOrderBy = new()
@@ -103,7 +104,7 @@
        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) : 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) : base(BaseDal)
        {
            _mapper = mapper;
            _unitOfWorkManage = unitOfWorkManage;
@@ -126,8 +127,21 @@
            _allocateOrderDetailRepository = allocateOrderDetailRepository;
            _allocateOrderRepository = allocateOrderRepository;
            _materialUnitService = materialUnitService;
            _task_HtyService = task_HtyService;
        }
        public async Task TaskStatusChange(string taskNum,TaskStatusEnum taskStatusEnum)
        {
            if (int.TryParse(taskNum, out var newTaskNum))
            {
                await Db.Updateable<Dt_Task>().SetColumns(it => new Dt_Task {
                        TaskStatus = taskStatusEnum.ObjToInt()
                    })
                    .Where(it => it.TaskNum == newTaskNum)
                    .ExecuteCommandAsync();
            }
        }
        /// <summary>
        /// 
@@ -276,8 +290,12 @@
            task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
            BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.自动完成 : OperateTypeEnum.人工完成);
            //  BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.自动完成 : OperateTypeEnum.人工完成);
            var result = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.人工删除);
            if (!result)
            {
                await Db.Deleteable(task).ExecuteCommandAsync();
            }
            _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
            _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfo.Details, beforeQuantity, stockInfo.Details.Sum(x => x.StockQuantity) + beforeQuantity, WIDESEA_Common.StockEnum.StockChangeType.MaterielGroup);
@@ -325,8 +343,8 @@
                               }).ToList();
                            allocatefeedmodel.Details = groupedData;
                            var result = await _invokeMESService.FeedbackAllocate(allocatefeedmodel);
                            if (result != null && result.code == 200)
                            var feedbackresult = await _invokeMESService.FeedbackAllocate(allocatefeedmodel);
                            if (feedbackresult != null && feedbackresult.code == 200)
                            {
                                _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1 })
                                .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
@@ -381,8 +399,8 @@
                               }).ToList();
                            allocatefeedmodel.Details = groupedData;
                            var result = await _invokeMESService.FeedbackAllocate(allocatefeedmodel);
                            if (result != null && result.code == 200)
                            var feedbackresult = await _invokeMESService.FeedbackAllocate(allocatefeedmodel);
                            if (feedbackresult != null && feedbackresult.code == 200)
                            {
                                _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1 })
                                .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
@@ -429,8 +447,8 @@
                               }).ToList();
                            feedmodel.details = groupedData;
                            var result = await _invokeMESService.FeedbackInbound(feedmodel);
                            if (result != null && result.code == 200)
                            var feedbackresult = await _invokeMESService.FeedbackInbound(feedmodel);
                            if (feedbackresult != null && feedbackresult.code == 200)
                            {
                                _inboundOrderService.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1 })
                                .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
@@ -536,8 +554,12 @@
                var outboundOrder = _outboundOrderService.Db.Queryable<Dt_OutboundOrder>().First(x => x.OrderNo == task.OrderNo);
                task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? WIDESEA_Core.Enums.OperateTypeEnum.自动完成 : OperateTypeEnum.人工完成);
                // BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? WIDESEA_Core.Enums.OperateTypeEnum.自动完成 : OperateTypeEnum.人工完成);
                var result = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.人工删除);
                if (!result)
                {
                    await Db.Deleteable(task).ExecuteCommandAsync();
                }
                _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforelocationStatus, StockChangeType.Inbound.ObjToInt(), "", task.TaskNum);
@@ -564,9 +586,7 @@
            _logger.LogInformation($"TaskService InPickTaskCompleted: {task.TaskNum}");
            try
            {
                _unitOfWorkManage.BeginTran(); // æ·»åŠ äº‹åŠ¡ç®¡ç†
            {
                // æŸ¥åº“å­˜
                Dt_StockInfo stockInfo = await _stockRepository.Db.Queryable<Dt_StockInfo>()
                    .Includes(x => x.Details)
@@ -584,7 +604,6 @@
                    _logger.LogInformation($"TaskService InPickTaskCompleted: æœªæ‰¾åˆ°è¯¥æ‰˜ç›˜åº“存明细信息.{task.TaskNum}");
                    return WebResponseContent.Instance.Error($"未找到该托盘库存明细信息");
                }
                // æŸ¥è´§ä½
                Dt_LocationInfo locationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
                if (locationInfo == null)
@@ -605,8 +624,7 @@
                // æ›´æ–°å‡ºåº“锁定记录状态为回库完成
                foreach (var lockInfo in returnLocks)
                {
                    lockInfo.Status = (int)OutLockStockStatusEnum.已回库;
                    lockInfo.Operator = App.User.UserName;
                    lockInfo.Status = (int)OutLockStockStatusEnum.已回库;
                }
                if (returnLocks.Any())
@@ -650,9 +668,13 @@
                task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
                // åˆ é™¤ä»»åŠ¡è®°å½•
                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.自动完成 : OperateTypeEnum.人工完成);
                BaseDal.DeleteData(task);
                //BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.自动完成 : OperateTypeEnum.人工完成);
                //BaseDal.DeleteData(task);
                var result = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.人工删除);
                if (!result)
                {
                    await Db.Deleteable(task).ExecuteCommandAsync();
                }
                // è®°å½•货位状态变更
                _locationStatusChangeRecordService.AddLocationStatusChangeRecord(
                    locationInfo,
@@ -663,7 +685,7 @@
                );
                await RecalculateOrderStatus(task.OrderNo);
                _unitOfWorkManage.CommitTran(); // æäº¤äº‹åŠ¡
                _logger.LogInformation($"托盘回库完成处理成功 - ä»»åŠ¡å·: {task.TaskNum}, æ‰˜ç›˜: {task.PalletCode}, è®¢å•: {task.OrderNo}");
                _ = Task.Run(async () =>
                {
@@ -939,8 +961,7 @@
                    await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>()
                        .SetColumns(x => new Dt_OutboundOrder
                        {
                            OrderStatus = newStatus,
                            Operator = App.User.UserName,
                            OrderStatus = newStatus,
                        })
                        .Where(x => x.OrderNo == orderNo)
                        .ExecuteCommandAsync();
@@ -1094,8 +1115,7 @@
                                await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>()
                                      .SetColumns(x => new Dt_OutboundOrder
                                      {
                                          ReturnToMESStatus = 1,
                                          Operator = App.User.UserName,
                                          ReturnToMESStatus = 1,
                                      }).Where(x => x.OrderNo == orderNo).ExecuteCommandAsync();
                            }
                        }
@@ -1106,84 +1126,90 @@
                    }
                    else
                    {
                        var feedmodel = new FeedbackOutboundRequestModel
                        if (outboundOrder != null && outboundOrder.IsBatch == 0)
                        {
                            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 detailModel = new FeedbackOutboundDetailsModel
                            var feedmodel = new FeedbackOutboundRequestModel
                            {
                                materialCode = detail.MaterielCode,
                                lineNo = detail.lineNo, // æ³¨æ„ï¼šè¿™é‡Œå¯èƒ½éœ€è¦è°ƒæ•´å­—段名
                                warehouseCode = detail.WarehouseCode,
                                qty = 0,
                                currentDeliveryQty = 0,
                                unit = detail.Unit,
                                barcodes = new List<WIDESEA_DTO.Outbound.BarcodesModel>()
                                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 item in detailLocks)
                            foreach (var detail in orderDetails)
                            {
                                if (item.PickedQty > 0)
                                // èŽ·å–è¯¥æ˜Žç»†å¯¹åº”çš„æ¡ç ä¿¡æ¯ï¼ˆä»Žé”å®šè®°å½•ï¼‰
                                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 detailModel = new FeedbackOutboundDetailsModel
                                {
                                    var barModel = new WIDESEA_DTO.Outbound.BarcodesModel
                                    materialCode = detail.MaterielCode,
                                    lineNo = detail.lineNo, // æ³¨æ„ï¼šè¿™é‡Œå¯èƒ½éœ€è¦è°ƒæ•´å­—段名
                                    warehouseCode = detail.WarehouseCode,
                                    qty = 0,
                                    currentDeliveryQty = 0,
                                    unit = detail.Unit,
                                    barcodes = new List<WIDESEA_DTO.Outbound.BarcodesModel>()
                                };
                                foreach (var item in detailLocks)
                                {
                                    if (item.PickedQty > 0)
                                    {
                                        barcode = item.CurrentBarcode,
                                        supplyCode = item.SupplyCode,
                                        batchNo = item.BatchNo,
                                        unit = item.BarcodeUnit,
                                        qty = item.PickedQty
                                    };
                                    // å•位不一致时转换
                                    if (detail.BarcodeUnit != detail.Unit)
                                    {
                                        var convertResult = await _materialUnitService.ConvertAsync(item.MaterielCode, item.PickedQty, detail.Unit, detail.BarcodeUnit);
                                        barModel.unit = convertResult.Unit;
                                        barModel.qty = convertResult.Quantity;
                                        var barModel = new WIDESEA_DTO.Outbound.BarcodesModel
                                        {
                                            barcode = item.CurrentBarcode,
                                            supplyCode = item.SupplyCode,
                                            batchNo = item.BatchNo,
                                            unit = item.BarcodeUnit,
                                            qty = item.PickedQty
                                        };
                                        // å•位不一致时转换
                                        if (detail.BarcodeUnit != detail.Unit)
                                        {
                                            var convertResult = await _materialUnitService.ConvertAsync(item.MaterielCode, item.PickedQty, detail.Unit, detail.BarcodeUnit);
                                            barModel.unit = convertResult.Unit;
                                            barModel.qty = convertResult.Quantity;
                                        }
                                        else
                                        {
                                            barModel.qty = item.PickedQty;
                                        }
                                        detailModel.qty += barModel.qty;
                                        detailModel.currentDeliveryQty += barModel.qty;
                                        detailModel.barcodes.Add(barModel);
                                    }
                                    else
                                    {
                                        barModel.qty = item.PickedQty;
                                    }
                                    detailModel.qty += barModel.qty;
                                    detailModel.currentDeliveryQty += barModel.qty;
                                    detailModel.barcodes.Add(barModel);
                                }
                                feedmodel.details.Add(detailModel);
                            }
                            feedmodel.details.Add(detailModel);
                        }
                        var result = await _invokeMESService.FeedbackOutbound(feedmodel);
                        if (result != null && result.code == 200)
                            var result = await _invokeMESService.FeedbackOutbound(feedmodel);
                            if (result != null && 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();
                            }
                        }
                        else if (outboundOrder != null && outboundOrder.IsBatch == 1)
                        {
                            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 _invokeMESService.BatchOrderFeedbackToMes(new List<string>() { outboundOrder.OrderNo }, 2);
                        }
                    }
                }
            }
@@ -1221,9 +1247,18 @@
                task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.自动完成 : OperateTypeEnum.人工完成);
                _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(stockInfo, App.User.UserId == 0 ? OperateTypeEnum.自动完成 : OperateTypeEnum.人工完成);
                //_stockRepository.Db.Deleteable(stockInfo).ExecuteCommand();
                // BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateTypeEnum.自动完成 : OperateTypeEnum.人工完成);
                var result = _task_HtyService.DeleteAndMoveIntoHty(task, OperateTypeEnum.人工删除);
                if (!result)
                {
                    await Db.Deleteable(task).ExecuteCommandAsync();
                }
                var stockresult = _stockService.StockInfoService.Repository.DeleteAndMoveIntoHty(stockInfo, App.User.UserId == 0 ? OperateTypeEnum.自动完成 : OperateTypeEnum.人工完成);
                if (!stockresult)
                {
                    _stockRepository.Db.Deleteable(stockInfo).ExecuteCommand();
                }
                _stockService.StockInfoService.DeleteData(stockInfo);
                _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Outbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum);