From 6d3ea08855337c0cfcc60df2903d3431611c7097 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期六, 13 十二月 2025 17:36:56 +0800
Subject: [PATCH] 优化程序,输送线入库按钮对接

---
 项目代码/WCSServices/WIDESEAWCS_BasicInfoService/LocationInfoService.cs |  159 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 155 insertions(+), 4 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_BasicInfoService/LocationInfoService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_BasicInfoService/LocationInfoService.cs"
index 8d28bdd..97ea408 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_BasicInfoService/LocationInfoService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_BasicInfoService/LocationInfoService.cs"
@@ -1,4 +1,8 @@
 锘縰sing HslCommunication.WebSocket;
+using Magicodes.ExporterAndImporter.Core;
+using Magicodes.ExporterAndImporter.Excel;
+using MathNet.Numerics.Statistics.Mcmc;
+using NPOI.Util.Collections;
 using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
 using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
 using SqlSugar;
@@ -9,19 +13,27 @@
 using System.Threading.Tasks;
 using WIDESEA_Core;
 using WIDESEA_Core.Enums;
+using WIDESEA_DTO.Basic;
 using WIDESEAWCS_Common;
 using WIDESEAWCS_Common.WareHouseEnum;
 using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.BaseRepository;
 using WIDESEAWCS_Core.BaseServices;
 using WIDESEAWCS_Core.Helper;
+using WIDESEAWCS_Core.Utilities;
 using WIDESEAWCS_IBasicInfoRepository;
 using WIDESEAWCS_IBasicInfoService;
 using WIDESEAWCS_Model.Models;
 
 namespace WIDESEAWCS_BasicInfoService
 {
-    public partial class LocationInfoService : ServiceBase<Dt_LocationInfo, ILocationInfoRepository>, ILocationInfoService
+    public class LocationCache
+    {
+        public string LocationCode { get; set; }
+
+        public DateTime DateTime { get; set; }
+    }
+    public class LocationInfoService : ServiceBase<Dt_LocationInfo, ILocationInfoRepository>, ILocationInfoService
     {
         private readonly IUnitOfWorkManage _unitOfWorkManage;
         public ILocationInfoRepository Repository => BaseDal;
@@ -84,13 +96,152 @@
         {
             return LocationDisableStatus(new int[] { key });
         }
-
+        private readonly static object _locker = new object();
+        private static List<LocationCache> locationCaches = new List<LocationCache>();
         /// <summary>
         /// 鍒嗛厤璐т綅
         /// </summary>
-        public Dt_LocationInfo? AssignLocation(string roadwayNo, int palletType, int warehouseId)
+        public Dt_LocationInfo? AssignLocation()
         {
-            return new Dt_LocationInfo();
+            lock (_locker)
+            {
+                List<LocationCache> removeItems = locationCaches.Where(x => (DateTime.Now - x.DateTime).TotalMinutes > 5).ToList();//鏌ヨ娣诲姞闈欐�佸彉閲忚秴杩�5鍒嗛挓鐨勮揣浣�
+                int count = removeItems.Count;
+                for (int i = 0; i < count; i++)
+                {
+                    locationCaches.Remove(removeItems[i]);//绉婚櫎鏌ヨ娣诲姞闈欐�佸彉閲忚秴杩�5鍒嗛挓鐨勮揣浣�
+                }
+
+                List<string> lockLocations = locationCaches.Select(x => x.LocationCode).ToList();
+
+                Dictionary<string, OrderByType> orderBy = new Dictionary<string, OrderByType>()
+                {
+                    { nameof(Dt_LocationInfo.Layer),OrderByType.Asc },
+                    { nameof(Dt_LocationInfo.Row),OrderByType.Asc },
+                    { nameof(Dt_LocationInfo.Columns),OrderByType.Desc },
+                };
+
+                Dt_LocationInfo locationInfo = BaseDal.QueryFirst(x => x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && x.EnableStatus != EnableStatusEnum.Disable.ObjToInt() && !lockLocations.Contains(x.LocationCode), orderBy);//鏌ヨ绌鸿揣浣嶄俊鎭苟鎺掗櫎5鍒嗛挓鍐呭垎閰嶇殑璐т綅,鏍规嵁灞傘�佸垪銆佹繁搴︺�佽鎺掑簭
+                if (locationInfo!=null)
+                {
+                    LocationCache locationCache = new LocationCache()
+                    {
+                        LocationCode = locationInfo.LocationCode,
+                        DateTime = DateTime.Now,
+                    };
+                    locationCaches.Add(locationCache);
+                }
+                return locationInfo;
+            }
+        }
+
+        /// <summary>
+        /// 鍒濆鍖栬揣浣�
+        /// </summary>
+        /// <param name="initializationLocationDTO"></param>
+        /// <returns></returns>
+        public WebResponseContent InitializationLocation(InitializationLocationDTO initializationLocationDTO)
+        {
+            try
+            {
+                List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>();
+                for (int i = 0; i < initializationLocationDTO.MaxRow; i++)
+                {
+                    for (int j = 0; j < initializationLocationDTO.MaxColumn; j++)
+                    {
+                        for (int k = 0; k < initializationLocationDTO.MaxLayer; k++)
+                        {
+                            Dt_LocationInfo locationInfo = new Dt_LocationInfo()
+                            {
+                                WarehouseId = 0,
+                                Columns = j + 1,
+                                EnableStatus = EnableStatusEnum.Normal.ObjToInt(),
+                                Layer = k + 1,
+                                LocationStatus = LocationStatusEnum.Free.ObjToInt(),
+                                RoadwayNo = $"{initializationLocationDTO.Roadway}",
+                                Row = i + 1,
+                            };
+                            locationInfo.LocationCode = $"{locationInfo.RoadwayNo}-{locationInfo.Row.ToString().PadLeft(3, '0')}-{locationInfo.Columns.ToString().PadLeft(3, '0')}-{locationInfo.Layer.ToString().PadLeft(3, '0')}";
+                            locationInfo.LocationName = $"{locationInfo.RoadwayNo}宸烽亾{locationInfo.Row.ToString().PadLeft(3, '0')}琛寋locationInfo.Columns.ToString().PadLeft(3, '0')}鍒梴locationInfo.Layer.ToString().PadLeft(3, '0')}灞�";
+                            int point = 0;
+                            if (locationInfo.Row%2==0)
+                            {
+                                point = locationInfo.Row / 2;
+                            }
+                            else
+                            {
+                                if (locationInfo.Row==1)
+                                {
+                                    point = 1;
+                                }
+                                else
+                                {
+                                    point = (locationInfo.Row / 2)+1;
+                                }
+                            }
+                            locationInfo.AgvPoint = $"{point.ToString().PadLeft(2, '0')}-{locationInfo.Columns.ToString().PadLeft(2, '0')}";
+                            locationInfos.Add(locationInfo);
+                        }
+                    }
+                }
+                BaseDal.AddData(locationInfos);
+                return WebResponseContent.Instance.OK();
+            }
+            catch (Exception ex)
+            {
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+        public override WebResponseContent Export(PageDataOptions options)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                string savePath = AppDomain.CurrentDomain.BaseDirectory + $"ExcelExport";
+                IExporter exporter = new ExcelExporter();
+                options.Page = 1;
+                options.Rows = 30;
+                options.Order = "asc";
+                options.Sort = "id";
+
+                string where = string.Empty;
+                ISugarQueryable<Dt_LocationInfo> sugarQueryable = BaseDal.Db.Queryable<Dt_LocationInfo>();
+                if (!string.IsNullOrEmpty(options.Wheres))
+                {
+                    try
+                    {
+                        List<SearchParameters> searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
+                        if (searchParametersList?.Any() == true)
+                        {
+                            foreach (var param in searchParametersList)
+                            {
+                                switch (param.Name)
+                                {
+                                    
+                                }
+                            }
+                        }
+                    }
+                    catch (Exception ex)
+                    {
+                    }
+                }
+
+                
+
+                byte[] data = exporter.ExportAsByteArray(sugarQueryable.ToList()).Result;
+
+                string fileName = "搴撲綅淇℃伅.xlsx";
+
+                FileHelper.WriteFile(savePath, fileName, data);
+
+                content = WebResponseContent.Instance.OK(data: savePath + "\\" + fileName);
+            }
+            catch (Exception ex)
+            {
+                content = WebResponseContent.Instance.Error(ex.Message);
+            }
+            return content;
         }
     }
 }

--
Gitblit v1.9.3