duyongjia
2024-12-27 d3470bb47c0f4627962b270f9667f420e394d0de
ÏîÄ¿´úÂë/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;
@@ -47,10 +48,13 @@
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_TaskInfoRepository;
using OrderByType = SqlSugar.OrderByType;
namespace WIDESEA_TaskInfoService
{
@@ -66,10 +70,25 @@
        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;
        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) : base(BaseDal)
        {
            _mapper = mapper;
            _unitOfWorkManage = unitOfWorkManage;
@@ -80,7 +99,17 @@
            _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;
        }
        /// <summary>
        /// ä»»åŠ¡å®Œæˆ
@@ -223,13 +252,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,13 +277,80 @@
                _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();
            
        }
@@ -333,11 +427,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,8 +467,6 @@
                _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfo.Details, beforeQuantity, stockInfo.Details.Sum(x => x.StockQuantity) - beforeQuantity, StockChangeType.Outbound, task.TaskNum);
                _unitOfWorkManage.CommitTran();
                return WebResponseContent.Instance.OK();
                //return OnOutboundTaskCompleted?.Invoke(task) ?? WebResponseContent.Instance.OK();
            }
            catch (Exception ex)
@@ -378,6 +474,71 @@
                _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["WERKS"];
                request.SYSNOD = AppSettings.Configuration["SYSNO"];
                request.WERKS = AppSettings.Configuration["WERKS"];
                //暂时根据托盘号查出库锁定表中Dt_OutStockLockInfo中的状态为1的最新一条,因为先锁定,才有任务,所以没有关联任务号
                //Dt_OutStockLockInfo outStockLockInfo= _outStockLockInfoRepository.QueryFirst(x => x.PalletCode == task.PalletCode && x.Status == 1, _OutLockOrderBy);
                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)