From 9753fb2756f6b4e30ff79d901a7bb86145517c8b Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期四, 18 十二月 2025 11:29:13 +0800
Subject: [PATCH] 1

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs |  386 +++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 288 insertions(+), 98 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs"
index 6457db1..e85a591 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs"
@@ -2,6 +2,7 @@
 using Microsoft.Extensions.Logging;
 using Newtonsoft.Json;
 using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
+using SqlSugar;
 using System;
 using System.Collections.Concurrent;
 using System.Collections.Generic;
@@ -16,9 +17,13 @@
 using WIDESEA_Common.StockEnum;
 using WIDESEA_Common.TaskEnum;
 using WIDESEA_Core;
+using WIDESEA_Core.CodeConfigEnum;
+using WIDESEA_Core.DB;
 using WIDESEA_Core.Helper;
+using WIDESEA_Core.Seed;
 using WIDESEA_DTO.Basic;
 using WIDESEA_DTO.Stock;
+using WIDESEA_IBasicService;
 using WIDESEA_Model.Models;
 using WIDESEA_Model.Models.Basic;
 using WIDESEA_Model.Models.Check;
@@ -83,31 +88,33 @@
 
                     _unitOfWorkManage.CommitTran();
 
-                    TaskModel esstask = new TaskModel()
-                    {
-                        taskType = "carry",
-                        taskGroupCode = "",
-                        groupPriority = 0,
-                        tasks = new List<TasksType>
-                        {
-                                new()
-                                {
-                                    taskCode=task.TaskNum.ToString(),
-                                    taskPriority=0,
-                                    taskDescribe=new TaskDescribeType{
-                                    containerCode=stockInfo.PalletCode,
-                                    containerType= "CT_KUBOT_STANDARD",
-                                    fromLocationCode=stockInfo.LocationCode??"",
-                                    toStationCode="",
-                                    toLocationCode="1-2",
-                                    deadline=0,storageTag=""
-                                    }
-                                }
-                        }
-                    };
-                    var result = await _eSSApiService.CreateTaskAsync(esstask);
+                    //TaskModel esstask = new TaskModel()
+                    //{
+                    //    taskType = "carry",
+                    //    taskGroupCode = "",
+                    //    groupPriority = 0,
+                    //    tasks = new List<TasksType>
+                    //    {
+                    //            new()
+                    //            {
+                    //                taskCode=task.TaskNum.ToString(),
+                    //                taskPriority=0,
+                    //                taskDescribe=new TaskDescribeType
+                    //                {
+                    //                    containerCode=stockInfo.PalletCode,
+                    //                    containerType= "CT_KUBOT_STANDARD",
+                    //                    fromLocationCode=stockInfo.LocationCode??"",
+                    //                    toStationCode="",
+                    //                    toLocationCode="1-2",
+                    //                    deadline=0,
+                    //                    storageTag=""
+                    //                }
+                    //            }
+                    //    }
+                    //};
+                    //var result = await _eSSApiService.CreateTaskAsync(esstask);
 
-                    _logger.LogInformation("鍒涘缓浠诲姟PalletOutboundTask 杩斿洖:  " + result);
+                    //_logger.LogInformation("鍒涘缓浠诲姟PalletOutboundTask 杩斿洖:  " + result);
                 }
                 return content.OK("绌烘墭鍑哄簱鎴愬姛!");
             }
@@ -309,45 +316,46 @@
                     _outboundOrderDetailService.Repository.UpdateData(outboundOrderDetails);
                 }
                 _unitOfWorkManage.CommitTran();
-                TaskModel esstask = new TaskModel()
-                {
-                    taskType = "carry",
-                    taskGroupCode = "",
-                    groupPriority = 0,
-                    tasks = new List<TasksType>()
-                };
+                return WebResponseContent.Instance.OK();
+                //TaskModel esstask = new TaskModel()
+                //{
+                //    taskType = "carry",
+                //    taskGroupCode = "",
+                //    groupPriority = 0,
+                //    tasks = new List<TasksType>()
+                //};
 
-                foreach (var task in tasks)
-                {
-                    esstask.
-                       tasks.Add(new TasksType
-                       {
-                           taskCode = task.TaskNum.ToString(),
-                           taskPriority = 0,
-                           taskDescribe = new TaskDescribeType
-                           {
-                               containerCode = task.PalletCode,
-                               containerType = "CT_KUBOT_STANDARD",
-                               fromLocationCode = task.SourceAddress ?? "",
-                               toStationCode = "",
-                               toLocationCode = task.TargetAddress,
-                               deadline = 0,
-                               storageTag = ""
-                           }
-                       }
-                   );
-                }
-                var result = await _eSSApiService.CreateTaskAsync(esstask);
+                //foreach (var task in tasks)
+                //{
+                //    esstask.
+                //       tasks.Add(new TasksType
+                //       {
+                //           taskCode = task.TaskNum.ToString(),
+                //           taskPriority = 0,
+                //           taskDescribe = new TaskDescribeType
+                //           {
+                //               containerCode = task.PalletCode,
+                //               containerType = "CT_KUBOT_STANDARD",
+                //               fromLocationCode = task.SourceAddress ?? "",
+                //               toStationCode = "",
+                //               toLocationCode = task.TargetAddress,
+                //               deadline = 0,
+                //               storageTag = ""
+                //           }
+                //       }
+                //   );
+                //}
+                //var result = await _eSSApiService.CreateTaskAsync(esstask);
 
-                _logger.LogInformation("鍒涘缓浠诲姟PalletOutboundTask 杩斿洖:  " + result);
-                if (result)
-                {
-                    return WebResponseContent.Instance.OK();
-                }
-                else
-                {
-                    return WebResponseContent.Instance.Error("涓嬪彂鏈哄櫒浜轰换鍔″け璐ワ紒");
-                }
+                //_logger.LogInformation("鍒涘缓浠诲姟PalletOutboundTask 杩斿洖:  " + result);
+                //if (result)
+                //{
+                //    return WebResponseContent.Instance.OK();
+                //}
+                //else
+                //{
+                //    return WebResponseContent.Instance.Error("涓嬪彂鏈哄櫒浜轰换鍔″け璐ワ紒");
+                //}
             }
             catch (Exception ex)
             {
@@ -771,46 +779,47 @@
                     _outboundOrderDetailService.Repository.UpdateData(outboundOrderDetails);
                 }
                 _unitOfWorkManage.CommitTran();
+                return WebResponseContent.Instance.OK();
                 //PushTasksToWCS(tasks);
-                TaskModel esstask = new TaskModel()
-                {
-                    taskType = "carry",
-                    taskGroupCode = "",
-                    groupPriority = 0,
-                    tasks = new List<TasksType>()
-                };
+                //TaskModel esstask = new TaskModel()
+                //{
+                //    taskType = "carry",
+                //    taskGroupCode = "",
+                //    groupPriority = 0,
+                //    tasks = new List<TasksType>()
+                //};
 
-                foreach (var task in tasks)
-                {
-                    esstask.
-                       tasks.Add(new TasksType
-                       {
-                           taskCode = task.TaskNum.ToString(),
-                           taskPriority = 0,
-                           taskDescribe = new TaskDescribeType
-                           {
-                               containerCode = task.PalletCode,
-                               containerType = "CT_KUBOT_STANDARD",
-                               fromLocationCode = task.SourceAddress ?? "",
-                               toStationCode = "",
-                               toLocationCode = task.TargetAddress,
-                               deadline = 0,
-                               storageTag = ""
-                           }
-                       }
-                   );
-                }
-                var result = await _eSSApiService.CreateTaskAsync(esstask);
+                //foreach (var task in tasks)
+                //{
+                //    esstask.
+                //       tasks.Add(new TasksType
+                //       {
+                //           taskCode = task.TaskNum.ToString(),
+                //           taskPriority = 0,
+                //           taskDescribe = new TaskDescribeType
+                //           {
+                //               containerCode = task.PalletCode,
+                //               containerType = "CT_KUBOT_STANDARD",
+                //               fromLocationCode = task.SourceAddress ?? "",
+                //               toStationCode = "",
+                //               toLocationCode = task.TargetAddress,
+                //               deadline = 0,
+                //               storageTag = ""
+                //           }
+                //       }
+                //   );
+                //}
+                //var result = await _eSSApiService.CreateTaskAsync(esstask);
 
-                _logger.LogInformation("鍒涘缓浠诲姟PalletOutboundTask 杩斿洖:  " + result);
-                if (result)
-                {
-                    return WebResponseContent.Instance.OK();
-                }
-                else
-                {
-                    return WebResponseContent.Instance.Error("涓嬪彂鏈哄櫒浜轰换鍔″け璐ワ紒");
-                }
+                //_logger.LogInformation("鍒涘缓浠诲姟PalletOutboundTask 杩斿洖:  " + result);
+                //if (result)
+                //{
+                //    return WebResponseContent.Instance.OK();
+                //}
+                //else
+                //{
+                //    return WebResponseContent.Instance.Error("涓嬪彂鏈哄櫒浜轰换鍔″け璐ワ紒");
+                //}
 
             }
             catch (Exception ex)
@@ -1098,6 +1107,187 @@
 
         #endregion
 
+        /// <summary>
+        /// 閫夊畾搴撳瓨鐢熸垚鐩樼偣鍗曞嚭搴�
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        public async Task<WebResponseContent> TakeOutbound(List<StockViewDTO> stockViews, string outStation)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                List<int> ids = stockViews.Select(x => x.StockId).ToList();
+                //鑾峰彇搴撳瓨
+                List<Dt_StockInfo> stockInfos = _stockRepository.Db.Queryable<Dt_StockInfo>().Where(x => ids.Contains(x.Id)).Includes(x => x.Details).ToList();
+                if (stockInfos.Count != stockViews.Count)
+                {
+                    StockViewDTO? stockViewDTO = stockViews.FirstOrDefault(x => !stockInfos.Select(x => x.PalletCode).ToList().Contains(x.PalletCode));
+                    return content.Error($"鏈壘鍒皗stockViewDTO?.PalletCode}搴撳瓨");
+                }
+                //鑾峰彇璐т綅
+                List<string> locStrs = stockInfos.Select(x => x.LocationCode).ToList();
+                List<Dt_LocationInfo> locationInfos = (List<Dt_LocationInfo>)_locationInfoService.Db.Queryable<Dt_LocationInfo>().Where(x => locStrs.Contains(x.LocationCode));
+                if (stockInfos.Count != locationInfos.Count)
+                {
+                    string? locStr = locStrs.FirstOrDefault(x => !locationInfos.Select(x => x.LocationCode).ToList().Contains(x));
+                    return content.Error($"鏈壘鍒皗locStr}璐т綅鏁版嵁");
+                }
+                Dt_TakeStockOrder takeStockOrder = new Dt_TakeStockOrder()
+                {
+                    WarehouseId = stockInfos.FirstOrDefault().WarehouseId,
+                    TakeStockStatus = TakeStockStatusEnum.鐩樼偣涓�.ObjToInt(),
+                    OrderNo = CreateCodeByRule(nameof(RuleCodeEnum.PDCodeRule)),
+                    Details = new List<Dt_TakeStockOrderDetail>()
+                };
+                foreach (var item in stockInfos)
+                {
+                    if (item.Details.Count <= 0)
+                    {
+                        return content.Error($"鏈壘鍒皗item.PalletCode}搴撳瓨鏄庣粏鏁版嵁");
+                    }
+                    Dt_LocationInfo? locationInfo = locationInfos.FirstOrDefault(x => x.LocationCode == item.LocationCode);
+                    if (locationInfo == null && (locationInfo.EnableStatus == EnableStatusEnum.Disable.ObjToInt() || locationInfo.EnableStatus != EnableStatusEnum.Normal.ObjToInt()) && locationInfo.LocationStatus != LocationStatusEnum.InStock.ObjToInt() && item.StockStatus != StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt())
+                    {
+                        content.Error($"{item.PalletCode}璐т綅鎴栧簱瀛樼姸鎬佷笉婊¤冻鍑哄簱鏉′欢");
+                    }   
+                }
+                List<Dt_Task> tasks = GetTasks(stockInfos, TaskTypeEnum.OutInventory,outStation);
+                if (tasks == null || tasks.Count <= 0)
+                {
+                    return content.Error($"鐢熸垚浠诲姟澶辫触");
+                }
+                stockInfos.ForEach(x =>
+                {
+                    x.StockStatus = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt();
+                });
+                tasks.ForEach(x =>
+                {
+                    x.OrderNo = takeStockOrder.OrderNo;
+                });
+                locationInfos.ForEach(x =>
+                {
+                    x.LocationStatus = LocationStatusEnum.Lock.ObjToInt();
+                });
+                _unitOfWorkManage.BeginTran();
+                //鏇存柊搴撳瓨鐘舵��
+                _stockRepository.UpdateData(stockInfos);
+                BaseDal.Db.InsertNav(takeStockOrder);
+                //鏂板缓浠诲姟
+                BaseDal.AddData(tasks);
+                _locationInfoService.UpdateData(locationInfos);
+                _unitOfWorkManage.CommitTran();
+                content.OK();
+                //TaskModel esstask = new TaskModel()
+                //{
+                //    taskType = "carry",
+                //    taskGroupCode = "",
+                //    groupPriority = 0,
+                //    tasks = new List<TasksType>()
+                //};
 
+                //foreach (var task in tasks)
+                //{
+                //    esstask.
+                //       tasks.Add(new TasksType
+                //       {
+                //           taskCode = task.TaskNum.ToString(),
+                //           taskPriority = 0,
+                //           taskDescribe = new TaskDescribeType
+                //           {
+                //               containerCode = task.PalletCode,
+                //               containerType = "CT_KUBOT_STANDARD",
+                //               fromLocationCode = task.SourceAddress ?? "",
+                //               toStationCode = "",
+                //               toLocationCode = task.TargetAddress,
+                //               deadline = 0,
+                //               storageTag = ""
+                //           }
+                //       }
+                //   );
+                //}
+                //var result = await _eSSApiService.CreateTaskAsync(esstask);
+
+                //_logger.LogInformation("鍒涘缓浠诲姟PalletOutboundTask 杩斿洖:  " + result);
+                //if (result)
+                //{
+                //    return WebResponseContent.Instance.OK();
+                //}
+                //else
+                //{
+                //    return WebResponseContent.Instance.Error("涓嬪彂鏈哄櫒浜轰换鍔″け璐ワ紒");
+                //}
+                //content.OK();
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        /// <summary>
+        /// 鍗曟嵁鐢熸垚鏂规硶
+        /// </summary>
+        static object lock_code = new object();
+        public string CreateCodeByRule(string ruleCode)
+        {
+            lock (lock_code)
+            {
+
+                string code = string.Empty;
+                DateTime dateTime = DateTime.Now;
+                DateTime now = DateTime.Now;
+                try
+                {
+                    if (string.IsNullOrEmpty(ruleCode))
+                        throw new ArgumentNullException(nameof(ruleCode));
+                    SqlSugarClient sugarClient = new SqlSugarClient(new ConnectionConfig
+                    {
+                        IsAutoCloseConnection = true,
+                        DbType = DbType.SqlServer,
+                        ConnectionString = DBContext.ConnectionString
+                    });
+                    Dt_CodeRuleConfig codeRuleConfig = sugarClient.Queryable<Dt_CodeRuleConfig>().Where(x => x.RuleCode == ruleCode).First();
+                    if (codeRuleConfig == null)
+                        throw new ArgumentNullException(nameof(codeRuleConfig));
+                    if (codeRuleConfig.ModifyDate != null)
+                    {
+                        dateTime = Convert.ToDateTime(codeRuleConfig.ModifyDate);
+                    }
+                    else
+                    {
+                        dateTime = Convert.ToDateTime(codeRuleConfig.CreateDate);
+                    }
+
+                    if (now.Year == dateTime.Year && now.Month == dateTime.Month && now.Day == dateTime.Day)
+                    {
+                        now = dateTime;
+                        codeRuleConfig.CurrentVal = Convert.ToInt32(codeRuleConfig.CurrentVal) + 1;
+                    }
+                    else
+                    {
+                        codeRuleConfig.CurrentVal = 1;
+                    }
+                    codeRuleConfig.ModifyDate = DateTime.Now;
+                    code = codeRuleConfig.StartStr + codeRuleConfig.Format;
+                    code = code.Replace($"[{CodeFormatTypeEnum.YYYY}]", now.Year.ToString().PadLeft(4, '0'));
+                    code = code.Replace($"[{CodeFormatTypeEnum.MM}]", now.Month.ToString().PadLeft(2, '0'));
+                    code = code.Replace($"[{CodeFormatTypeEnum.DD}]", now.Day.ToString().PadLeft(2, '0'));
+                    code = code.Replace($"[{CodeFormatTypeEnum.ST}]", codeRuleConfig.StartStr?.ToString() ?? "");
+                    code = code.Replace($"[{CodeFormatTypeEnum.NUM}]", codeRuleConfig.CurrentVal.ToString().PadLeft(codeRuleConfig.Length, '0'));
+                    Dictionary<string, object> keyValuePairs = new Dictionary<string, object>() { { nameof(codeRuleConfig.CurrentVal), codeRuleConfig.CurrentVal }, { nameof(codeRuleConfig.Id), codeRuleConfig.Id }, { nameof(codeRuleConfig.ModifyDate), DateTime.Now } };
+                    sugarClient.Updateable(keyValuePairs).AS(MainDb.CodeRuleConfig).WhereColumns(nameof(codeRuleConfig.Id)).ExecuteCommand();
+                    sugarClient.Updateable(codeRuleConfig);
+
+                }
+                catch (Exception ex)
+                {
+
+                }
+                return code;
+            }
+        }
     }
+
 }

--
Gitblit v1.9.3