From 531c6e89dc07bb6997e6249a6cd9f53a9bd474a5 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期一, 23 三月 2026 10:31:54 +0800
Subject: [PATCH] 出库逻辑变更

---
 项目代码/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService.cs |  278 +++++++++++++++++++++++++------------------------------
 1 files changed, 128 insertions(+), 150 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService.cs"
index 8805d0a..56634a7 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService.cs"
@@ -18,11 +18,13 @@
 using AutoMapper;
 using Microsoft.AspNetCore.Mvc.ApiExplorer;
 using Newtonsoft.Json;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
 using SqlSugar;
 using System.Reflection.Emit;
 using System.Threading.Tasks;
 using WIDESEA_Common.CommonEnum;
 using WIDESEA_Common.LocationEnum;
+using WIDESEA_Common.MaterielEnum;
 using WIDESEA_Common.OrderEnum;
 using WIDESEA_Common.StockEnum;
 using WIDESEA_Common.TaskEnum;
@@ -33,14 +35,21 @@
 using WIDESEA_Core.Enums;
 using WIDESEA_Core.Helper;
 using WIDESEA_DTO;
+using WIDESEA_DTO.ERP;
 using WIDESEA_DTO.Inbound;
-using WIDESEA_DTO.MES;
+using WIDESEA_DTO.Outbound;
 using WIDESEA_DTO.Stock;
 using WIDESEA_DTO.Task;
 using WIDESEA_External.ERPService;
+using WIDESEA_External.MESService;
 using WIDESEA_External.Model;
 using WIDESEA_IBasicRepository;
 using WIDESEA_IBasicService;
+using WIDESEA_IInboundRepository;
+using WIDESEA_IInboundService;
+using WIDESEA_InboundRepository;
+using WIDESEA_IOutboundRepository;
+using WIDESEA_IOutboundService;
 using WIDESEA_IRecordService;
 using WIDESEA_IStockRepository;
 using WIDESEA_IStockService;
@@ -55,14 +64,17 @@
     {
         private readonly IMapper _mapper;
         private readonly IUnitOfWorkManage _unitOfWorkManage;
-        private readonly IStockRepository _stockRepository;
-        private readonly IBasicService _basicService;
         private readonly IRecordService _recordService;
+        private readonly IStockRepository _stockRepository;
         private readonly IStockService _stockService;
         private readonly IBasicRepository _basicRepository;
-        private readonly IApiInfoRepository _apiInfoRepository;
+        private readonly IBasicService _basicService;
         private readonly IInvokeERPService _invokeERPService;
-        private readonly IPalletTypeInfoRepository _palletTypeInfoRepository;
+        private readonly IInvokeMESService _invokeMESService;
+        private readonly IOutboundRepository _outboundRepository;
+        private readonly IOutboundService _outboundService;
+        private readonly IInboundRepository _inboundRepository;
+        private readonly IInboundService _inboundService;
         public ITaskRepository Repository => BaseDal;
 
         private Dictionary<string, OrderByType> _taskOrderBy = new()
@@ -71,11 +83,11 @@
                 {nameof(Dt_Task.CreateDate),OrderByType.Asc},
             };
 
-        public List<int> TaskTypes => typeof(TaskTypeEnum).GetEnumIndexList();
+        public List<int> TaskInboundTypes => typeof(TaskTypeEnum).GetEnumIndexList().Where(x => x >= 500 && x < 900).ToList();
 
-        public List<int> TaskOutboundTypes => typeof(TaskTypeEnum).GetEnumIndexList();
+        public List<int> TaskOutboundTypes => typeof(TaskTypeEnum).GetEnumIndexList().Where(x => x >= 100 && x < 500).ToList();
 
-        public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IStockRepository stockRepository, IBasicService basicService, IRecordService recordService, IStockService stockService, IBasicRepository basicRepository, IApiInfoRepository apiInfoRepository, IInvokeERPService invokeERPService, IPalletTypeInfoRepository palletTypeInfoRepository) : base(BaseDal)
+        public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IStockRepository stockRepository, IBasicService basicService, IRecordService recordService, IStockService stockService, IBasicRepository basicRepository, IInvokeERPService invokeERPService,  IOutboundRepository outboundRepository, IOutboundService outboundService, IInboundRepository inboundRepository,IInboundService inboundService,IInvokeMESService invokeMESService) : base(BaseDal)
         {
             _mapper = mapper;
             _unitOfWorkManage = unitOfWorkManage;
@@ -84,9 +96,12 @@
             _recordService = recordService;
             _stockService = stockService;
             _basicRepository = basicRepository;
-            _apiInfoRepository = apiInfoRepository;
             _invokeERPService = invokeERPService;
-            _palletTypeInfoRepository = palletTypeInfoRepository;
+            _invokeMESService = invokeMESService;
+            _outboundRepository = outboundRepository;
+            _outboundService = outboundService;
+            _inboundRepository = inboundRepository;
+            _inboundService = inboundService;
         }
 
         /// <summary>
@@ -97,6 +112,10 @@
         {
             try
             {
+                if (tasks==null || tasks.Count == 0)
+                {
+                    return WebResponseContent.Instance.Error($"浼犲叆浠诲姟涓虹┖");
+                }
                 List<WMSTaskDTO> taskDTOs = _mapper.Map<List<WMSTaskDTO>>(tasks);
                 taskDTOs.ForEach(x =>
                 {
@@ -114,6 +133,28 @@
             catch (Exception ex)
             {
                 return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+        /// <summary>
+        /// 浠诲姟淇℃伅鎺ㄩ�佽嚦WCS
+        /// </summary>
+        /// <returns></returns>
+        public List<string> ExistRoadwaysError()
+        {
+            try
+            {
+                string url = AppSettings.Get("WCS");
+                if (string.IsNullOrEmpty(url))
+                {
+                    return null;
+                }
+                string response = HttpHelper.Get($"{url}/api/Task/ExistRoadwaysError");
+
+                return JsonConvert.DeserializeObject<List<string>>(response) ?? throw new Exception("杩斿洖閿欒");
+            }
+            catch (Exception ex)
+            {
+                return null;
             }
         }
         /// <summary>
@@ -139,169 +180,106 @@
                 return WebResponseContent.Instance.Error(ex.Message);
             }
         }
-
-        public WebResponseContent AGVTasks(SaveModel saveModel)
-        {
-            try
-            {
-                var palletCode = saveModel.MainData["barcode"].ToString();
-                var stationCode = saveModel.MainData["address"].ToString();
-                var warehouseId = saveModel.MainData["warehouseId"].ObjToInt();
-                Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == warehouseId);
-                if (warehouse == null)
-                {
-                    return WebResponseContent.Instance.Error("鏈壘鍒板簱鍖�");
-                }
-
-                Dt_Task task = Repository.QueryFirst(x => x.PalletCode == palletCode && x.WarehouseId == warehouseId);
-                if (task != null)
-                {
-                    return WebResponseContent.Instance.Error($"璇ユ墭鐩樺凡鐢熸垚浠诲姟");
-                }
-                if (Repository.QueryFirst(x => x.SourceAddress == stationCode && x.TaskStatus == TaskStatusEnum.New.ObjToInt()) != null && warehouse.WarehouseCode != WarehouseEnum.HA58.ToString())
-                {
-                    return WebResponseContent.Instance.Error($"璇ョ珯鐐瑰凡鏈夋湭鎵ц鐨勪换鍔�");
-                }
-                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == palletCode).Includes(x => x.Details).First();
-                if (stockInfo == null)
-                {
-                    return WebResponseContent.Instance.Error($"鏈壘鍒扮粍鐩樹俊鎭�");
-                }
-                if (stockInfo.StockStatus != StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt())
-                {
-                    return WebResponseContent.Instance.Error($"璇ユ墭鐩樼姸鎬佷笉姝g‘");
-                }
-                if (warehouseId != stockInfo.WarehouseId)
-                {
-                    return WebResponseContent.Instance.Error($"浠撳簱涓嶆纭�");
-                }
-                Dt_Task newTask = new Dt_Task()
-                {
-                    CurrentAddress = stationCode,
-                    Grade = 0,
-                    NextAddress = "",
-                    PalletCode = palletCode,
-                    Roadway = warehouse.Remark,//鏌ヨ瀵瑰簲绾胯竟浠撳湴鍧�宸烽亾鍙�
-                    SourceAddress = stationCode,
-                    TargetAddress = "",
-                    TaskType = TaskTypeEnum.OutAllocate.ObjToInt(),
-                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
-                    WarehouseId = stockInfo.WarehouseId,
-                    PalletType = stockInfo.PalletType,
-                    MaterielCode = stockInfo.Details.Where(x => x.StockId == stockInfo.Id).FirstOrDefault()?.MaterielCode,
-                    Quantity = (float)stockInfo.Details.Where(x => x.StockId == stockInfo.Id).FirstOrDefault()?.StockQuantity,
-                };
-                _unitOfWorkManage.BeginTran();
-                BaseDal.AddData(newTask);
-                PushTasksToWCS(new List<Dt_Task> { newTask });
-                _unitOfWorkManage.CommitTran();
-                return WebResponseContent.Instance.OK();
-            }
-            catch (Exception ex)
-            {
-                _unitOfWorkManage.RollbackTran();
-                return WebResponseContent.Instance.Error(ex.Message);
-            }
-        }
-
-        /// <summary>
-        /// 鎴愬搧浠撳叆搴撲换鍔″畬鎴�
-        /// </summary>
-        public WebResponseContent InProductCompleted(Dt_Task task)
-        {
-            WebResponseContent content=new WebResponseContent();
-            try
-            {
-                switch (task.TaskType)
-                {
-                    case (int)TaskTypeEnum.EmptyProductBack:
-                        content = EmptyProBackCompleted(task);
-                        break;
-                    case (int)TaskTypeEnum.InProductBack:
-                        content = InProBackCompleted(task);
-                        break;
-                    default:
-                        content.Error("鏈煡浠诲姟绫诲瀷");
-                        break;
-                }
-            }
-            catch (Exception ex)
-            {
-                _unitOfWorkManage.RollbackTran();
-                content.Error(ex.Message);
-            }
-            return content;
-        }
-        public WebResponseContent EmptyProBackCompleted(Dt_Task task)
+        private readonly static object lockerAddSG = new object();
+        public WebResponseContent AddOutSGOrder(List<SGOutOrderDTO> outOrderDTOs)
         {
             WebResponseContent content = new WebResponseContent();
             try
             {
-                //鏇存柊鍏ュ簱鐘舵��
-                task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
-                _unitOfWorkManage.BeginTran();
-                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateTypeEnum.浜哄伐瀹屾垚 : OperateTypeEnum.鑷姩瀹屾垚);
-                _unitOfWorkManage.CommitTran();
-                content.OK();
+                lock (lockerAddSG)
+                {
+                    int outDetailId = _outboundRepository.OutSGOrderDetailRepository.QueryData().OrderByDescending(x=>x.Id).FirstOrDefault()?.Id ?? 0;
+                    content = _outboundService.OutSGOrderService.AddOutSGOrder(outOrderDTOs);
+                    if (!content.Status)
+                    {
+                        return content;
+                    }
+                    //鑾峰彇鎵�鏈夌殑鍑哄簱璇︽儏鍒ゆ柇鏄惁婊¤冻鍑哄簱閲忓皬浜�5涓囦笖灏忎簬17鍗�
+                    //List<Dt_OutStockLockInfo> outStockLockInfos = _outboundRepository.OutStockLockInfoRepository.QueryData(x=>x.OrderType==OutOrderTypeEnum.OutSGPick.ObjToInt() && x.Status<OutLockStockStatusEnum.鍏抽棴.ObjToInt());
+                    //decimal sumAssignQty = outStockLockInfos.Sum(x => x.AssignQuantity);
+                    //int outCount= outStockLockInfos.Select(x=>x.PalletCode).Distinct().Count();
+                    //if (sumAssignQty < AppSettings.Get("OutSGLength").ObjToInt() && outCount < AppSettings.Get("OutSGCount").ObjToInt())
+                    //{
+                        List<int> ints = _outboundRepository.OutSGOrderDetailRepository.QueryData(x => x.Id > outDetailId).Select(x => x.Id).ToList();
+                        int[] reseponse = new int[ints.Count];
+                        for (int i = 0; i < ints.Count; i++)
+                        {
+                            reseponse[i] = ints[i];
+                        }
+                        content.Message = CreateSGOutboundTasks(reseponse).Message;
+                    //}
+                    //else
+                    //{
+                    //    return content.Error($"褰撳墠鍑哄簱閲忥細{sumAssignQty},褰撳墠鍑哄簱鍗锋暟锛歿outCount},涓嶆弧瓒冲皬浜�5涓囦笖灏忎簬17鍗峰嚭搴撴潯浠�");
+                    //}
+                }
+
             }
             catch (Exception ex)
             {
-                _unitOfWorkManage.RollbackTran();
                 content.Error(ex.Message);
             }
             return content;
         }
+        
         /// <summary>
-        /// 鎴愬搧浣欐枡閫�搴撲换鍔″畬鎴�
+        /// 鍚敤
         /// </summary>
-        /// <param name="task"></param>
         /// <returns></returns>
-        public WebResponseContent InProBackCompleted(Dt_Task task)
+        public WebResponseContent EnableStatus(int[] keys)
         {
             WebResponseContent content = new WebResponseContent();
             try
             {
-                //鑾峰彇缁勭洏淇℃伅
-                Dt_ProStockInfo proStockInfo = _stockRepository.ProStockInfoRepository.Db.Queryable<Dt_ProStockInfo>().Where(x => x.PalletCode == task.PalletCode).Includes(x => x.proStockInfoDetails).First();
-                if (proStockInfo == null)
+                List<Dt_Task> tasks = BaseDal.QueryData(x => x.TaskType < TaskTypeEnum.Inbound.ObjToInt());
+                List<Dt_AGVStationInfo> stationInfos = _basicRepository.AGVStationInfoRepository.QueryData(x => keys.Contains(x.Id));
+                foreach (var station in stationInfos)
                 {
-                    return content.Error($"鏈壘鍒拌兌妗嗕负{task.PalletCode}缁勭洏淇℃伅");
+                    Dt_Task? taskOld = tasks.FirstOrDefault(x => x.TargetAddress == station.AGVStationCode);
+                    if (taskOld!=null)
+                    {
+                        content.Message+= $"{station.AGVStationCode}鍑哄簱{taskOld.TaskNum}浠诲姟鎵ц涓�;";
+                        continue;
+                    }
+                    if (station.StationArea==StationAreaEnum.涓�妤兼殏瀛樻灦.ToString())
+                    {
+                        Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x=>x.LocationCode==station.AGVStationCode);
+                        if (stockInfo!=null)
+                        {
+                            content.Message += $"{station.AGVStationCode}{stockInfo.PalletCode}搴撳瓨缁戝畾;";
+                            continue;
+                        }
+                    }
+                    station.IsOccupied = WhetherEnum.False.ObjToInt();
                 }
-                Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
-                if (locationInfo == null)
-                {
-                    return content.Error($"鏈壘鍒扮洰鏍囪揣浣嶄俊鎭�");
-                }
-                if (locationInfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt())
-                {
-                    return content.Error($"璐т綅鐘舵�佷笉姝g‘");
-                }
-                if (proStockInfo.StockStatus!=StockStatusEmun.鎴愬搧浣欐枡鍥炲簱.ObjToInt())
-                {
-                    return content.Error($"鑳舵{proStockInfo.PalletCode}搴撳瓨鐘舵�佷笉姝g‘");
-                }
-                LocationStatusEnum lastStatus = (LocationStatusEnum)locationInfo.LocationStatus;
-                locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
-                proStockInfo.LocationCode = locationInfo.LocationCode;
-                proStockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
-                proStockInfo.proStockInfoDetails.ForEach(x =>
-                {
-                    x.ProOutDetailStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
-                });
-                //鏇存柊鍏ュ簱鐘舵��
-                task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
-                _unitOfWorkManage.BeginTran();
-                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateTypeEnum.浜哄伐瀹屾垚 : OperateTypeEnum.鑷姩瀹屾垚);
-                _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, proStockInfo.PalletType, LocationStatusEnum.InStock, locationInfo.WarehouseId);
-                _stockRepository.ProStockInfoRepository.UpdateData(proStockInfo);
-                _stockRepository.ProStockInfoDetailRepository.UpdateData(proStockInfo.proStockInfoDetails);
-                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationStatusEnum.InStock, LocationChangeType.InboundCompleted);
-                _unitOfWorkManage.CommitTran();
-                content.OK();
+                _basicRepository.AGVStationInfoRepository.UpdateData(stationInfos);
+                content.OK(content.Message.IsNullOrEmpty() ? "鎴愬姛" : $"閮ㄥ垎鎴愬姛鍚敤!{content.Message}鏃犳硶鍚敤");
             }
             catch (Exception ex)
             {
-                _unitOfWorkManage.RollbackTran();
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        /// <summary>
+        /// 绂佺敤
+        /// </summary>
+        /// <returns></returns>
+        public WebResponseContent DisableStatus(int[] keys)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                List<Dt_AGVStationInfo> stationInfos = _basicRepository.AGVStationInfoRepository.QueryData(x => keys.Contains(x.Id));
+                stationInfos.ForEach(x =>
+                {
+                    x.IsOccupied = WhetherEnum.True.ObjToInt();
+                });
+                _basicRepository.AGVStationInfoRepository.UpdateData(stationInfos);
+                content.OK("鎴愬姛");
+            }
+            catch (Exception ex)
+            {
                 content.Error(ex.Message);
             }
             return content;

--
Gitblit v1.9.3