From 70f22c9c06c7dfe2a2a83c0d2fcc79892dba7d8f Mon Sep 17 00:00:00 2001
From: hutongqing <hutongqing@hnkhzn.com>
Date: 星期三, 18 十二月 2024 17:08:29 +0800
Subject: [PATCH] 1

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs |  244 ++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 220 insertions(+), 24 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
index 7198373..73909ec 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
@@ -16,29 +16,21 @@
 #endregion << 鐗� 鏈� 娉� 閲� >>
 
 using AutoMapper;
-using MailKit.Search;
 using Newtonsoft.Json;
-using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
 using SqlSugar;
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Diagnostics.CodeAnalysis;
-using System.Linq;
-using System.Linq.Expressions;
-using System.Net.Http.Headers;
-using System.Reflection;
-using System.Reflection.Metadata;
-using System.Text;
 using System.Threading.Tasks;
+using WIDESEA_Common.CommonEnum;
+using WIDESEA_Common.LocationEnum;
+using WIDESEA_Common.StockEnum;
+using WIDESEA_Common.TaskEnum;
 using WIDESEA_Core;
 using WIDESEA_Core.BaseRepository;
 using WIDESEA_Core.BaseServices;
 using WIDESEA_Core.Enums;
 using WIDESEA_Core.Helper;
-using WIDESEA_Core.Log;
 using WIDESEA_DTO.Inbound;
 using WIDESEA_DTO.Stock;
+using WIDESEA_DTO.Task;
 using WIDESEA_IBasicRepository;
 using WIDESEA_IBasicService;
 using WIDESEA_IInboundService;
@@ -58,30 +50,234 @@
     {
         private readonly IMapper _mapper;
         private readonly IUnitOfWorkManage _unitOfWorkManage;
-
+        private readonly IStockRepository _stockRepository;
         private readonly IBasicService _basicService;
-        private readonly IOutboundService _outboundService;
-        private readonly IInboundService _inboundService;
         private readonly IRecordService _recordService;
+        private readonly IOutboundService _outboundService;
         private readonly IStockService _stockService;
-        private readonly ITask_HtyService _taskHtyService;
-        private readonly ILocationInfoService _locationInfoService;
 
         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> _taskOrderBy = new()
+            {
+                {nameof(Dt_Task.Grade),OrderByType.Desc },
+                {nameof(Dt_Task.CreateDate),OrderByType.Asc},
+            };
+
+        public List<int> TaskInboundTypes => typeof(TaskInboundTypeEnum).GetEnumIndexList();
+
+        public List<int> TaskOutboundTypes => typeof(TaskOutboundTypeEnum).GetEnumIndexList();
+
+        public TaskService(ITaskRepository BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IStockRepository stockRepository, IBasicService basicService, IRecordService recordService, IOutboundService outboundService, IStockService stockService) : base(BaseDal)
         {
             _mapper = mapper;
             _unitOfWorkManage = unitOfWorkManage;
+            _stockRepository = stockRepository;
             _basicService = basicService;
-            _outboundService = outboundService;
-            _inboundService = inboundService;
             _recordService = recordService;
+            _outboundService = outboundService;
             _stockService = stockService;
-            _taskHtyService = taskHtyService;
-            _locationInfoService = locationInfoService;
         }
 
-        
+        /// <summary>
+        /// 浠诲姟淇℃伅鎺ㄩ�佽嚦WCS
+        /// </summary>
+        /// <returns></returns>
+        public WebResponseContent PushTasksToWCS()
+        {
+            try
+            {
+                List<Dt_Task> tasks = BaseDal.QueryData(x => (TaskInboundTypes.Contains(x.TaskType) && x.TaskStatus == (int)TaskInStatusEnum.InNew || TaskOutboundTypes.Contains(x.TaskType) && x.TaskStatus == (int)TaskOutStatusEnum.OutNew));
+
+                List<WMSTaskDTO> taskDTOs = _mapper.Map<List<WMSTaskDTO>>(tasks);
+
+                string response = HttpHelper.Post("http://127.0.0.1:9291/api/Task/ReceiveTask", taskDTOs.Serialize());
+
+                return JsonConvert.DeserializeObject<WebResponseContent>(response) ?? WebResponseContent.Instance.Error("杩斿洖閿欒");
+            }
+            catch (Exception ex)
+            {
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+
+        /// <summary>
+        /// 鐢宠鍏ュ簱浠诲姟(PDA浣跨敤锛屼粎鎵樼洏缁戝畾鍏ュ簱绔欏彴锛屼笉鍒嗛厤璐т綅)
+        /// </summary>
+        /// <param name="palletCode">鎵樼洏鍙�</param>
+        /// <param name="stationCode">绔欏彴鍙�</param>
+        /// <returns></returns>
+        public WebResponseContent RequestInboundTask(string palletCode, string stationCode)
+        {
+            try
+            {
+                Dt_Task task = Repository.QueryFirst(x => x.PalletCode == palletCode);
+                if (task != null)
+                {
+                    return WebResponseContent.Instance.Error($"璇ユ墭鐩樺凡鐢熸垚浠诲姟");
+                }
+
+                if (Repository.QueryFirst(x => x.SourceAddress == stationCode && x.TaskStatus == TaskInStatusEnum.InNew.ObjToInt()) != null)
+                {
+                    return WebResponseContent.Instance.Error($"璇ョ珯鐐瑰凡鏈夋湭鎵ц鐨勪换鍔�");
+                }
+
+                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == palletCode);
+                if (stockInfo == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒扮粍鐩樹俊鎭�");
+                }
+                if (stockInfo.StockStatus != StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt())
+                {
+                    return WebResponseContent.Instance.Error($"璇ユ墭鐩樼姸鎬佷笉姝g‘,涓嶅彲鐢宠鍏ュ簱");
+                }
+                if (!string.IsNullOrEmpty(stockInfo.LocationCode))
+                {
+                    return WebResponseContent.Instance.Error($"璇ユ墭鐩樺凡缁戝畾璐т綅");
+                }
+
+                Dt_Task newTask = new Dt_Task()
+                {
+                    CurrentAddress = stationCode,
+                    Grade = 0,
+                    NextAddress = "",
+                    PalletCode = palletCode,
+                    Roadway = "",
+                    SourceAddress = stationCode,
+                    TargetAddress = "",
+                    TaskType = TaskInboundTypeEnum.Inbound.ObjToInt(),
+                    TaskStatus = TaskInStatusEnum.SC_InExecute.ObjToInt(),
+                };
+
+                stockInfo.StockStatus = StockStatusEmun.鍏ュ簱纭.ObjToInt();
+
+                _unitOfWorkManage.BeginTran();
+                int taskId = BaseDal.AddData(newTask);
+                newTask.TaskId = taskId;
+                _stockRepository.StockInfoRepository.UpdateData(stockInfo);
+                _unitOfWorkManage.CommitTran();
+
+                return WebResponseContent.Instance.OK(data: newTask);
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+
+        /// <summary>
+        /// 鍏ュ簱浠诲姟鐢宠鍒嗛厤璐т綅
+        /// </summary>
+        /// <param name="taskNum">浠诲姟鍙�</param>
+        /// <param name="roadwayNo">宸烽亾鍙�</param>
+        /// <param name="palletType">鎵樼洏绫诲瀷</param>
+        /// <returns></returns>
+        public WebResponseContent AssignInboundTaskLocation(int taskNum, string roadwayNo)
+        {
+            try
+            {
+                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
+                if (task == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒拌鍏ュ簱浠诲姟");
+                }
+
+                Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayNo, (PalletTypeEnum)task.PalletType, task.WarehouseId);
+                if (locationInfo == null)
+                {
+                    return WebResponseContent.Instance.Error($"璐т綅鍒嗛厤澶辫触,鏈壘鍒板彲鍒嗛厤璐т綅");
+                }
+
+                task.Roadway = roadwayNo;
+                task.TargetAddress = locationInfo.LocationCode;
+                task.TaskStatus = TaskInStatusEnum.SC_InExecute.ObjToInt();
+
+                LocationStatusEnum lastStatus = (LocationStatusEnum)locationInfo.LocationStatus;
+
+                _unitOfWorkManage.BeginTran();
+                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationChangeType.InboundAssignLocation);
+                _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, (PalletTypeEnum)task.PalletType, LocationStatusEnum.Lock, task.WarehouseId);
+                BaseDal.UpdateData(task);
+                _unitOfWorkManage.CommitTran();
+                return WebResponseContent.Instance.OK();
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+
+        /// <summary>
+        /// 鍏ュ簱浠诲姟瀹屾垚
+        /// </summary>
+        /// <param name="taskNum">浠诲姟鍙�</param>
+        /// <returns></returns>
+        public WebResponseContent InboundTaskCompleted(int taskNum)
+        {
+            try
+            {
+                Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
+                if (task == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒拌浠诲姟淇℃伅");
+                }
+
+                if (task.TaskType != TaskInboundTypeEnum.Inbound.ObjToInt())
+                {
+                    return WebResponseContent.Instance.Error($"浠诲姟绫诲瀷閿欒");
+                }
+
+                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == task.PalletCode).Includes(x => x.Details).First();
+                if (stockInfo == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒版墭鐩樺搴旂殑缁勭洏淇℃伅");
+                }
+
+                if (!string.IsNullOrEmpty(stockInfo.LocationCode))
+                {
+                    return WebResponseContent.Instance.Error($"璇ユ墭鐩樺凡缁戝畾璐т綅");
+                }
+
+                if (stockInfo.Details == null || stockInfo.Details.Count == 0)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒拌鎵樼洏搴撳瓨鏄庣粏淇℃伅");
+                }
+
+                Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress);
+                if (locationInfo == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒扮洰鏍囪揣浣嶄俊鎭�");
+                }
+
+                if (locationInfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt())
+                {
+                    return WebResponseContent.Instance.Error($"璐т綅鐘舵�佷笉姝g‘");
+                }
+
+                LocationStatusEnum lastStatus = (LocationStatusEnum)locationInfo.LocationStatus;
+                locationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
+
+                stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+                stockInfo.LocationCode = locationInfo.LocationCode;
+
+                _unitOfWorkManage.BeginTran();
+                BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateTypeEnum.浜哄伐瀹屾垚 : OperateTypeEnum.鑷姩瀹屾垚);
+
+                _basicService.LocationInfoService.Repository.UpdateData(locationInfo);
+
+                _stockRepository.StockInfoRepository.UpdateData(stockInfo);
+
+                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationChangeType.InboundCompleted);
+                _unitOfWorkManage.CommitTran();
+                return WebResponseContent.Instance.OK();
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
     }
 }

--
Gitblit v1.9.3