duyongjia
2024-12-29 9a0acba23c5b5095be2a89b8ca190fe5202c2ea6
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
@@ -31,6 +31,7 @@
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_BasicRepository;
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
@@ -41,16 +42,21 @@
using WIDESEA_DTO.Stock;
using WIDESEA_IBasicRepository;
using WIDESEA_IBasicService;
using WIDESEA_IInboundRepository;
using WIDESEA_IInboundService;
using WIDESEA_IOutboundRepository;
using WIDESEA_IOutboundService;
using WIDESEA_IRecordService;
using WIDESEA_IStockRepository;
using WIDESEA_IStockService;
using WIDESEA_ISystemService;
using WIDESEA_ITaskInfoRepository;
using WIDESEA_ITaskInfoService;
using WIDESEA_Model;
using WIDESEA_Model.Models;
using WIDESEA_Model.Models.Inbound;
using WIDESEA_TaskInfoRepository;
using OrderByType = SqlSugar.OrderByType;
namespace WIDESEA_TaskInfoService
{
@@ -66,10 +72,27 @@
        private readonly IStockService _stockService;
        private readonly ITask_HtyService _taskHtyService;
        private readonly ILocationInfoService _locationInfoService;
        private readonly ISys_JobService _sys_JobService;
        private readonly ILabelMasterRepository _labelMasterRepository;
        private readonly IOutStockLockInfoRepository _outStockLockInfoRepository;
        private readonly IOutboundOrderRepository _outboundOrderRepository;
        private readonly IOutboundOrderDetailRepository _outboundOrderDetailRepository;
        private readonly IOutboundOrder_HtyRepository _outboundOrder_HtyRepository;
        private readonly IOutboundOrderDetail_HtyRepository _outboundOrderDetail_HtyRepository;
        private readonly IOutBoundOrderBYDRepository _outBoundOrderBYDRepository;
        private readonly IOutboundOrderDetailBYDRepository _outboundOrderDetailByDRepository;
        private readonly IMainReturnInventoryRepository _mainReturnInventoryRepository;
        private readonly IReturnInventoryDetailRepository _returnInventoryDetailRepository;
        public ITaskRepository Repository => BaseDal;
        public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IBasicService basicService, IOutboundService outboundService, IInboundService inboundService, IRecordService recordService, IStockService stockService, ITask_HtyService taskHtyService, ILocationInfoService locationInfoService) : base(BaseDal)
        private Dictionary<string, OrderByType> _OutLockOrderBy = new Dictionary<string, OrderByType>()
        {
            { nameof(Dt_OutStockLockInfo.CreateDate), OrderByType.Desc },
        };
        public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IBasicService basicService, IOutboundService outboundService, IInboundService inboundService, IRecordService recordService, IStockService stockService, ITask_HtyService taskHtyService, ILocationInfoService locationInfoService, ISys_JobService sys_JobService, ILabelMasterRepository labelMasterRepository, IOutStockLockInfoRepository outStockLockInfoRepository, IOutboundOrderDetailRepository outboundOrderDetailRepository, IOutBoundOrderBYDRepository outBoundOrderBYDRepository, IOutboundOrderDetailBYDRepository outboundOrderDetailByDRepository, IOutboundOrderRepository outboundOrderRepository, IOutboundOrder_HtyRepository outboundOrder_HtyRepository, IOutboundOrderDetail_HtyRepository outboundOrderDetail_HtyRepository, IReturnInventoryDetailRepository returnInventoryDetailRepository,IMainReturnInventoryRepository mainReturnInventoryRepository) : base(BaseDal)
        {
            _mapper = mapper;
            _unitOfWorkManage = unitOfWorkManage;
@@ -80,7 +103,20 @@
            _stockService = stockService;
            _taskHtyService = taskHtyService;
            _locationInfoService = locationInfoService;
            _sys_JobService = sys_JobService;
            _labelMasterRepository = labelMasterRepository;
            _outStockLockInfoRepository = outStockLockInfoRepository;
            _outboundOrderDetailRepository = outboundOrderDetailRepository;
            _outBoundOrderBYDRepository = outBoundOrderBYDRepository;
            _outboundOrderDetailByDRepository = outboundOrderDetailByDRepository;
            _outboundOrderRepository = outboundOrderRepository;
            _outboundOrder_HtyRepository = outboundOrder_HtyRepository;
            _outboundOrderDetail_HtyRepository = outboundOrderDetail_HtyRepository;
            _returnInventoryDetailRepository = returnInventoryDetailRepository;
            _mainReturnInventoryRepository = mainReturnInventoryRepository;
        }
        /// <summary>
        /// ä»»åŠ¡å®Œæˆ
@@ -189,21 +225,44 @@
                {
                    return WebResponseContent.Instance.Error("未找到任务信息");
                }
                if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt() || task.TaskType == TaskTypeEnum.PalletOutbound.ObjToInt())
                if (task.TaskStatus == 100 || task.TaskStatus == 200)//如果是新建任务状态改为执行中
                {
                    task.TaskStatus = OutTaskStatusEnum.SC_OutExecuting.ObjToInt();
                }
                else if (task.TaskType == TaskTypeEnum.Inbound.ObjToInt() || task.TaskType == TaskTypeEnum.PalletInbound.ObjToInt())
                {
                    task.TaskStatus = InTaskStatusEnum.SC_InExecuting.ObjToInt();
                }
                else if (task.TaskType == TaskTypeEnum.Relocation.ObjToInt())
                {
                    task.TaskStatus = InTaskStatusEnum.RelocationExecuting.ObjToInt();
                    if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt() || task.TaskType == TaskTypeEnum.PalletOutbound.ObjToInt())
                    {
                        task.TaskStatus = OutTaskStatusEnum.SC_OutExecuting.ObjToInt();
                    }
                    else if (task.TaskType == TaskTypeEnum.Inbound.ObjToInt() || task.TaskType == TaskTypeEnum.PalletInbound.ObjToInt() || task.TaskType == TaskTypeEnum.PalletReturnInbound.ObjToInt())
                    {
                        task.TaskStatus = InTaskStatusEnum.SC_InExecuting.ObjToInt();
                    }
                    //else if (task.TaskType == TaskTypeEnum.Relocation.ObjToInt())
                    //{
                    //    task.TaskStatus = InTaskStatusEnum.RelocationExecuting.ObjToInt();
                    //}
                    else
                    {
                        throw new Exception($"任务类型错误,未找到该任务类型,任务号:【{task.TaskNum}】,任务类型:【{task.TaskType}】");
                    }
                }
                else
                {
                    throw new Exception($"任务类型错误,未找到该任务类型,任务号:【{task.TaskNum}】,任务类型:【{task.TaskType}】");
                    if (task.TaskType == TaskTypeEnum.Outbound.ObjToInt() || task.TaskType == TaskTypeEnum.PalletOutbound.ObjToInt())
                    {
                        task.TaskStatus = OutTaskStatusEnum.SC_OutFinish.ObjToInt();
                    }
                    else if (task.TaskType == TaskTypeEnum.Inbound.ObjToInt() || task.TaskType == TaskTypeEnum.PalletInbound.ObjToInt() || task.TaskType == TaskTypeEnum.PalletReturnInbound.ObjToInt())
                    {
                        task.TaskStatus = InTaskStatusEnum.SC_InFinish.ObjToInt();
                    }
                    //else if (task.TaskType == TaskTypeEnum.Relocation.ObjToInt())
                    //{
                    //    task.TaskStatus = InTaskStatusEnum.RelocationExecuting.ObjToInt();
                    //}
                    else
                    {
                        throw new Exception($"任务类型错误,未找到该任务类型,任务号:【{task.TaskNum}】,任务类型:【{task.TaskType}】");
                    }
                }
                _unitOfWorkManage.BeginTran();
                task.Dispatchertime = DateTime.Now;
@@ -223,13 +282,11 @@
        {
            try
            {
                _unitOfWorkManage.BeginTran();
                decimal beforeQuantity = 0;
                Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);
                Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
                Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);
                CheckCompleted(stockInfo, locationInfo);
                stockInfo.LocationCode = locationInfo.LocationCode;
@@ -250,15 +307,85 @@
                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum);
                _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfo.Details, beforeQuantity, stockInfo.Details.Sum(x => x.StockQuantity) + beforeQuantity, StockChangeType.Inbound,task.TaskNum);
                _unitOfWorkManage.CommitTran();
                return WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
            //原料入库完成后,需要将组盘信息调用上游WMS原料上架结果接口
            #region å›žä¼ é€»è¾‘处理
            try
            {
                PutAwayRequest request = new PutAwayRequest();
                List<PutAway> itemData = new List<PutAway>();
                request.ITEMDATA = itemData;
                request.WERKS = AppSettings.Configuration["WERKS"];
                request.WH_NUMBER = AppSettings.Configuration["WERKS"];
                request.IZLID = request.WERKS + request.WH_NUMBER+ DateTime.Now.ToString("yyyyMMdd") + task.TaskNum.ToString();
                request.CREATE_DATE = task.CreateDate.ToString("yyyy-MM-dd HH:mm:ss");
                request.PSTNG_DATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                request.INBOUND_NO = "";//todo:单号要从条码主数据中获取,不然回传会提示:该条码无进仓单数据!
                request.RECEIPT_NO = "";//todo:单号要从条码主数据中,不然回传会提示:该条码无进仓单数据!
                Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);
                foreach (Dt_StockInfoDetail detail in stockInfo.Details)
                {
                    Dt_LabelMaster labMaster = _labelMasterRepository.QueryFirst(x => x.LABEL_NO == detail.SerialNumber);
                    if (labMaster != null)
                    {
                        if (request.INBOUND_NO == "")
                        {
                            request.INBOUND_NO = labMaster.INBOUND_NO;
                        }
                        if (request.RECEIPT_NO == "")
                        {
                            request.RECEIPT_NO = labMaster.RECEIPT_NO;
                        }
                        PutAway putAway = new PutAway();
                        putAway.MATNR = labMaster.MATNR;
                        putAway.BATCH = labMaster.BATCH;
                        putAway.LIFNR = labMaster.LIFNR;
                        putAway.LIKTX = labMaster.LIKTX;
                        putAway.RECEIPT_QTY = labMaster.BOX_QTY;
                        putAway.UNIT = labMaster.UNIT;
                        putAway.LABEL_NO = labMaster.LABEL_NO;
                        putAway.PACK_LABEL_NO = labMaster.Pack_LABEL_No;
                        putAway.PALLET_LABEL_NO = labMaster.Pallet_label_no;
                        putAway.TPNUM = task.PalletCode;
                        putAway.FLAG = "0";
                        putAway.TKTXT = "";
                        putAway.PO_NO = labMaster.PO_NO;
                        putAway.PO_ITEM_NO = labMaster.PO_ITEM_NO;
                        putAway.SOBKZ = labMaster.SOBKZ;
                        putAway.RECEIPT_ITEM_NO = labMaster.RECEIPT_ITEM_NO;
                        putAway.INBOUND_NO = task.TaskNum.ToString();
                        //LABEL _STATUS æ¡ç çŠ¶æ€  02已收料(无需质检)03 å¾…进仓(已质检),并且,QC RESULT CODE质检状态为“02” æ‰å…è®¡ä¸Šæž¶
                        if (labMaster.QC_RESULT_CODE=="02"&&(labMaster.LABEL_STATUS=="02"|| labMaster.LABEL_STATUS == "03"))
                        {
                            itemData.Add(putAway);
                        }
                    }
                }
                if (itemData.Count > 0)
                {
                    _sys_JobService.CallPutAway(request);
                }
            }
            catch(Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
            #endregion
            return WebResponseContent.Instance.OK();
        }
        /// <summary>
        /// ç©ºæ‰˜ç›˜å…¥åº“完成处理
@@ -305,6 +432,106 @@
            }
        }
        /// <summary>
        /// ä½™æ–™é€€åº“完成处理
        /// </summary>
        /// <param name="task">任务实体对象</param>
        /// <returns>返回处理结果</returns>
        public WebResponseContent PalletReturnInboundTaskCompleted(Dt_Task task)
        {
            try
            {
                _unitOfWorkManage.BeginTran();
                decimal beforeQuantity = 0;
                Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
                Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);
                CheckCompleted(stockInfo, locationInfo);
                stockInfo.LocationCode = locationInfo.LocationCode;
                stockInfo.StockStatus = StockStatusEmun.已入库.ObjToInt();
                _stockService.StockInfoService.Repository.UpdateData(stockInfo);
                beforeQuantity = stockInfo.Details.Where(x => x.Id != 0).Sum(x => x.StockQuantity);
                int beforeStatus = locationInfo.LocationStatus;
                locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
                _basicService.LocationInfoService.UpdateLocationFree(locationInfo, task.TaskNum, StockChangeType.Inbound.ObjToInt(), false);
                _basicService.LocationInfoService.Repository.UpdateData(locationInfo);
                task.TaskStatus = InTaskStatusEnum.InFinish.ObjToInt();
                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId == 0 ? OperateType.自动完成 : OperateType.人工完成);
                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Inbound.ObjToInt(), stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", task.TaskNum);
                _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfo.Details, beforeQuantity, stockInfo.Details.Sum(x => x.StockQuantity) + beforeQuantity, StockChangeType.Inbound, task.TaskNum);
                _unitOfWorkManage.CommitTran();
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
            //余料入库完成后,需要将组盘信息调用上游WMS余料退回结果接口
            #region å›žä¼ é€»è¾‘处理
            try
            {
                PutAwayReturnRequest request = new PutAwayReturnRequest();
                List<PutAwayReturn> DATA = new List<PutAwayReturn>();
                request.DATA = DATA;
                request.WERKS = AppSettings.Configuration["WERKS"];
                request.WH_NUMBER = AppSettings.Configuration["SYSNO"];
                request.IZLID = task.OrderNo;//这个值会在接收上游回库组盘信息时,存在库存表中,再存到任务表中
                Dt_MainReturnInventory mainReturnInventory = _mainReturnInventoryRepository.QueryFirst(x => x.IZLID == task.OrderNo);
                if (mainReturnInventory != null)
                {
                    request.RETURN_NO = mainReturnInventory.RETURN_NO;
                    request.RETURN_ITEM_NO = mainReturnInventory.RETURN_ITEM_NO;
                    request.BUSINESS_NAME = mainReturnInventory.BUSINESS_NAME;
                    request.BUSINESS_CODE = mainReturnInventory.BUSINESS_CODE;
                    request.TPNUM = mainReturnInventory.TPNUM;
                    request.LGORT = mainReturnInventory.LGORT;
                    request.MO_NO = mainReturnInventory.MO_NO;
                    Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);
                    foreach (Dt_StockInfoDetail detail in stockInfo.Details)
                    {
                        Dt_ReturnInventoryDetail dt_ReturnInventoryDetail = _returnInventoryDetailRepository.QueryFirst(x => x.LABEL_NO == detail.SerialNumber);
                        if (dt_ReturnInventoryDetail != null)
                        {
                            PutAwayReturn putAwayReturn = new PutAwayReturn();
                            putAwayReturn.LABEL_NO = dt_ReturnInventoryDetail.LABEL_NO;
                            putAwayReturn.SOBKZ = dt_ReturnInventoryDetail.SOBKZ;
                            putAwayReturn.UNIT = dt_ReturnInventoryDetail.UNIT;
                            putAwayReturn.LGORT = dt_ReturnInventoryDetail.LGORT;
                            putAwayReturn.TOTAL_RETURN_QTY = dt_ReturnInventoryDetail.QTY;
                            putAwayReturn.F_LGORT = dt_ReturnInventoryDetail.F_LGORT;
                            putAwayReturn.MO_NO = mainReturnInventory.MO_NO;
                            putAwayReturn.LIFNR = dt_ReturnInventoryDetail.LIFNR;
                            putAwayReturn.MATNR = dt_ReturnInventoryDetail.MATNR;
                            putAwayReturn.BATCH = "";
                            DATA.Add(putAwayReturn);
                        }
                    }
                    if(DATA.Count>0)
                    {
                        _sys_JobService.CallPutAwayReturn(request);//余料退库回传
                    }
                }
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
            #endregion
            return WebResponseContent.Instance.OK();
        }
        /// <summary>
        /// éªŒè¯æ•°æ®
        /// </summary>
@@ -333,11 +560,15 @@
        public WebResponseContent OutboundTaskCompleted(Dt_Task task)
        {
            Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);
            Dt_StockInfo stockInfoCatch = stockInfo;//先缓存起来,供后面的回传接口调用
            try
            {
                _unitOfWorkManage.BeginTran();
                decimal beforeQuantity = 0;
                Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);
                //Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode);
                //Dt_StockInfo stockInfoCatch = stockInfo;//先缓存起来,供后面的回传接口调用
                Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress);
@@ -369,14 +600,75 @@
                _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfo.Details, beforeQuantity, stockInfo.Details.Sum(x => x.StockQuantity) - beforeQuantity, StockChangeType.Outbound, task.TaskNum);
                _unitOfWorkManage.CommitTran();
                return OnOutboundTaskCompleted?.Invoke(task) ?? WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
            //原料出库完成后,调用上游系统WMS出库完成信息接口
            #region å›žä¼ é€»è¾‘处理
            try
            {
                PickAndPostRequest request = new PickAndPostRequest();
                List<PickAndPost> itemData = new List<PickAndPost>();
                request.ITEMDATA = itemData;
                request.WH_NUMBER = AppSettings.Configuration["SYSNO"];
                request.SYSNOD = AppSettings.Configuration["SYSNO"];
                request.WERKS = AppSettings.Configuration["CallMaterialID"];
                Dt_OutboundOrderDetail_Hty detail = _outboundOrderDetail_HtyRepository.QueryFirst(x => x.SourceId.ToString() == task.Remark);// task.Remark存需求明细ID
                if (detail != null)
                {
                    Dt_OutboundOrder_Hty outboundOrder = _outboundOrder_HtyRepository.QueryFirst(x => x.SourceId == detail.OrderId);
                    if (outboundOrder != null)
                    {
                        Dt_OutBoundOrderBYD outboundOrderBYD = _outBoundOrderBYDRepository.QueryFirst(x => x.REQUIREMENT_NO == outboundOrder.OrderNo);
                        if (outboundOrderBYD != null)
                        {
                            Dt_OutboundOrderDetailBYD outboundOrderDetailBYD = _outboundOrderDetailByDRepository.QueryFirst(x => x.REQUIREMENT_NO == outboundOrderBYD.REQUIREMENT_NO && x.REQUIREMENT_ITEM_NO == detail.Remark);//detail.Remark å­˜éœ€æ±‚行
                            //根据托盘号查立库的条码和批次进行回传
                            foreach (var item in stockInfoCatch.Details)
                            {
                                PickAndPost pickpost = new PickAndPost();
                                pickpost.REQUIREMENT_NO = outboundOrderDetailBYD.REQUIREMENT_NO;
                                pickpost.REQUIREMENT_ITEM_NO = outboundOrderDetailBYD.REQUIREMENT_ITEM_NO;
                                pickpost.WERKS = outboundOrderBYD.WRKS;
                                pickpost.SYSNOD = outboundOrderBYD.SYSNOD;
                                pickpost.MATNR = outboundOrderDetailBYD.MATNR;
                                pickpost.LIFNR = "";//没有返回,暂时转空
                                pickpost.QTY = outboundOrderDetailBYD.QTY;
                                pickpost.BATCH = item.BatchNo;//取立库入库库存的条码
                                pickpost.LGORT = outboundOrderBYD.LGORT;
                                pickpost.BUSINESS_CODE = outboundOrderBYD.BUSINESS_CODE;
                                pickpost.BUSINESS_NAME = outboundOrderBYD.BUSINESS_NAME;
                                pickpost.STATION = outboundOrderBYD.STATION;
                                pickpost.SPLIT = outboundOrderBYD.SPLIT;
                                pickpost.LABEL_NO = item.SerialNumber;//取立库入库库存的条码
                                pickpost.CREATE_DATE = outboundOrderBYD.CREATE_DATE;
                                pickpost.UPDATE_DATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                pickpost.STATUS = outboundOrderBYD.STATUS;
                                itemData.Add(pickpost);
                            }
                            _sys_JobService.CallPickAndPost(request);//回传
                        }
                    }
                }
            }
            catch(Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
            #endregion
            return WebResponseContent.Instance.OK();
        }
        public WebResponseContent PalletOutboundTaskCompleted(Dt_Task task)