From 37454e625df68d40897112b2e8c2e3cf4d7163e3 Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期三, 25 三月 2026 11:43:10 +0800
Subject: [PATCH] 1

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_Core/BaseServices/ServiceBase.cs |  228 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 223 insertions(+), 5 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_Core/BaseServices/ServiceBase.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_Core/BaseServices/ServiceBase.cs"
index 6f32ad7..70c700e 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_Core/BaseServices/ServiceBase.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_Core/BaseServices/ServiceBase.cs"
@@ -12,6 +12,7 @@
 using System.Linq.Expressions;
 using System.Reflection;
 using System.Reflection.Metadata;
+using WIDESEA_Common.OrderEnum;
 using WIDESEA_Core.BaseRepository;
 using WIDESEA_Core.Const;
 using WIDESEA_Core.DB.Models;
@@ -148,6 +149,100 @@
                     }
                 }
             }
+        }
+
+        protected string ValidatePageOptions(PageDataOptions options)
+        {
+            options = options ?? new PageDataOptions();
+            string where = "";
+            List<SearchParameters> searchParametersList = new List<SearchParameters>();
+            if (options.Filter != null && options.Filter.Count > 0)
+            {
+                searchParametersList.AddRange(options.Filter);
+            }
+            else if (!string.IsNullOrEmpty(options.Wheres))
+            {
+                try
+                {
+                    searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
+                    options.Filter = searchParametersList;
+                }
+                catch { }
+            }
+            QueryRelativeList?.Invoke(searchParametersList);
+
+            for (int i = 0; i < searchParametersList.Count; i++)
+            {
+                if (string.IsNullOrEmpty(searchParametersList[i].Value))
+                {
+                    continue;
+                }
+
+                PropertyInfo property = TProperties.Where(c => c.Name.ToUpper() == searchParametersList[i].Name.ToUpper()).FirstOrDefault();
+
+                if (property == null) continue;
+
+                (bool, string, object) result = property.ValidationVal(searchParametersList[i].Value);
+                if (!result.Item1)
+                {
+                    continue;
+                }
+
+                LinqExpressionType expressionType = searchParametersList[i].DisplayType.GetLinqCondition();
+                if (expressionType == LinqExpressionType.Equal)
+                {
+                    if (string.IsNullOrEmpty(where))
+                    {
+                        // 閽堝瀛楃涓茬被鍨嬬殑瀛楁浣跨敤妯$硦鏌ヨ
+                        //where += $"{searchParametersList[i].Name} like '%{searchParametersList[i].Value}%'";
+                        if (searchParametersList[i].Value.ToLower() == "true" || searchParametersList[i].Value.ToLower() == "false")
+                        {
+                            where += $" {searchParametersList[i].Name} = '{searchParametersList[i].Value.ToLower()}'";
+                        }
+                        else
+                        {
+                            where += $"[{searchParametersList[i].Name}] like '%{searchParametersList[i].Value}%'";
+                        }
+                    }
+                    else
+                    {
+                        // 閽堝甯冨皵绫诲瀷瀛楁杩涜绮剧‘鏌ヨ
+                        if (searchParametersList[i].Value.ToLower() == "true" || searchParametersList[i].Value.ToLower() == "false")
+                        {
+                            where += $" and {searchParametersList[i].Name} = '{searchParametersList[i].Value.ToLower()}'";
+                        }
+                        else
+                        {
+                            where += $" and [{searchParametersList[i].Name}] like '%{searchParametersList[i].Value}%'";
+                        }
+                    }
+                }
+                else
+                {
+                    if (searchParametersList[i].DisplayType.GetLinqCondition() == LinqExpressionType.ThanOrEqual)
+                    {
+                        if (string.IsNullOrEmpty(where))
+                            where += $"{searchParametersList[i].Name} >= '{searchParametersList[i].Value}'";
+                        else
+                            where += $" and {searchParametersList[i].Name} >= '{searchParametersList[i].Value}'";
+                    }
+                    else if (searchParametersList[i].DisplayType.GetLinqCondition() == LinqExpressionType.LessThanOrEqual)
+                    {
+                        if (string.IsNullOrEmpty(where))
+                            where += $"{searchParametersList[i].Name} <= '{searchParametersList[i].Value}'";
+                        else
+                            where += $" and {searchParametersList[i].Name} <= '{searchParametersList[i].Value}'";
+                    }
+                    else
+                    {
+                        if (string.IsNullOrEmpty(where))
+                            where += $"{searchParametersList[i].Name} {searchParametersList[i].DisplayType} '{searchParametersList[i].Value}'";
+                        else
+                            where += $" and {searchParametersList[i].Name} {searchParametersList[i].DisplayType} '{searchParametersList[i].Value}'";
+                    }
+                }
+            }
+            return where;
         }
 
         protected Expression<Func<TEntity, bool>> GetWhereExpression(string propertyName, object propertyValue, ParameterExpression parameter, LinqExpressionType expressionType)
@@ -359,19 +454,138 @@
             Type t = typeof(TEntity);
 
             if (pageData.Value == null) return new PageGridData<object>(total: 0, null);
+
             string keyName = t.GetKeyName();
-            ////鐢熸垚鏌ヨ鏉′欢
-            //Expression<Func<TEntity, bool>> whereExpression = keyName.CreateExpression<TEntity>(pageData.Value, LinqExpressionType.Equal);
             int totalCount = 0;
             PropertyInfo propertyInfo = t.GetProperties().FirstOrDefault(x => x.GetCustomAttribute<Navigate>() != null);
+            List<ExpandoObject> detailList = new List<ExpandoObject>();
+
             if (propertyInfo != null)
             {
                 Type detailType = propertyInfo.PropertyType.GetGenericArguments()[0];
                 Navigate navigate = propertyInfo.GetCustomAttribute<Navigate>();
-                List<ExpandoObject> list = BaseDal.Db.Queryable(detailType.Name, "detail").Where(navigate.GetName(), "=", pageData.Value).ToPageList(pageData.Page, pageData.Rows, ref totalCount);
-                return new PageGridData<ExpandoObject>(totalCount, list);
+
+                detailList = BaseDal.Db.Queryable(detailType.Name, "detail")
+                    .Where(navigate.GetName(), "=", pageData.Value)
+                    .ToPageList(pageData.Page, pageData.Rows, ref totalCount);
+
+                if (detailList.Any())
+                {
+                    // 1. 鎻愬彇鏄庣粏鏈夋晥barcode
+                    List<string> allBarcodes = new List<string>();
+                    foreach (var expando in detailList)
+                    {
+                        var detailDict = (IDictionary<string, object>)expando;
+                        if (detailDict.ContainsKey("barcode") && detailDict["barcode"] != null)
+                        {
+                            string barcodeValue = (detailDict["barcode"] as string)?.Trim() ?? string.Empty;
+                            if (!string.IsNullOrWhiteSpace(barcodeValue))
+                            {
+                                allBarcodes.Add(barcodeValue);
+                            }
+                        }
+                    }
+
+                    if (allBarcodes.Count == 0)
+                    {
+                        foreach (var expando in detailList)
+                        {
+                            var detailDict = (IDictionary<string, object>)expando;
+                            detailDict["palletCode"] = "";
+                        }
+                        return new PageGridData<ExpandoObject>(totalCount, detailList);
+                    }
+
+                    // 2. 鏌ュ簱瀛樻槑缁嗚〃锛岃幏鍙朾arcode 鈫� StockId鏄犲皠
+                    Dictionary<string, object> barcodeToStockIdDict = new Dictionary<string, object>();
+                    var distinctBarcodes = allBarcodes.Distinct().ToList();
+                    var barcodeStockIdList = BaseDal.Db.Queryable("Dt_StockInfoDetail", "sd")
+                        .In("sd.barcode", distinctBarcodes)
+                        .Select("sd.barcode, sd.StockId")
+                        .ToList();
+
+                    foreach (var item in barcodeStockIdList)
+                    {
+                        if (item == null) continue;
+                        var itemDict = (IDictionary<string, object>)item;
+
+                        if (itemDict.ContainsKey("barcode") && itemDict["barcode"] != null)
+                        {
+                            string barcode = (itemDict["barcode"] as string)?.Trim() ?? string.Empty;
+                            object stockId = itemDict.ContainsKey("StockId") ? itemDict["StockId"] : null;
+
+                            if (!string.IsNullOrWhiteSpace(barcode) && !barcodeToStockIdDict.ContainsKey(barcode))
+                            {
+                                barcodeToStockIdDict.Add(barcode, stockId);
+                            }
+                        }
+                    }
+
+                    if (barcodeToStockIdDict.Count == 0)
+                    {
+                        foreach (var expando in detailList)
+                        {
+                            var detailDict = (IDictionary<string, object>)expando;
+                            detailDict["palletCode"] = "";
+                        }
+                        return new PageGridData<ExpandoObject>(totalCount, detailList);
+                    }
+
+                    Dictionary<object, string> stockIdToPalletDict = new Dictionary<object, string>();
+                    var allStockIds = barcodeToStockIdDict.Values.Distinct().ToList();
+                    var stockIdPalletList = BaseDal.Db.Queryable("Dt_StockInfo", "s")
+                        .In("s.Id", allStockIds)
+                        .Select("s.Id, s.PalletCode")
+                        .ToList();
+
+                    // 鎻愬彇 PalletCode
+                    foreach (var item in stockIdPalletList)
+                    {
+                        if (item == null) continue;
+                        var itemDict = (IDictionary<string, object>)item;
+                        if (itemDict.ContainsKey("Id") && itemDict["Id"] != null)
+                        {
+                            object stockId = itemDict["Id"];
+                            string palletCode = itemDict.ContainsKey("PalletCode") && itemDict["PalletCode"] != null
+                                ? (itemDict["PalletCode"] as string)?.Trim() ?? string.Empty
+                                : string.Empty;
+                            if (!stockIdToPalletDict.ContainsKey(stockId))
+                            {
+                                stockIdToPalletDict.Add(stockId, palletCode);
+                            }
+                        }
+                    }
+
+                    // 5. 缁欐槑缁嗙殑palletCode瀛楁璧嬪�间富琛ㄧ殑PalletCode鍊�
+                    foreach (var expando in detailList)
+                    {
+                        var detailDict = (IDictionary<string, object>)expando;
+                        string palletValue = string.Empty;
+
+                        if (detailDict.ContainsKey("barcode") && detailDict["barcode"] != null)
+                        {
+                            string barcode = (detailDict["barcode"] as string)?.Trim() ?? string.Empty;
+                            // 閫氳繃barcode鑾峰彇StockId
+                            if (!string.IsNullOrWhiteSpace(barcode) && barcodeToStockIdDict.TryGetValue(barcode, out var stockId))
+                            {
+                                // 閫氳繃StockId鑾峰彇涓昏〃鐨凱alletCode
+                                stockIdToPalletDict.TryGetValue(stockId, out palletValue);
+                            }
+                        }
+                        // 鍔ㄦ�佹洿鏂�/娣诲姞palletCode瀛楁
+                        if (detailDict.ContainsKey("palletCode"))
+                        {
+                            detailDict["palletCode"] = palletValue;
+                        }
+                        else
+                        {
+                            detailDict.Add("palletCode", palletValue);
+                        }
+                    }
+                }
             }
-            return new PageGridData<object>(total: 0, null);
+
+            return new PageGridData<ExpandoObject>(totalCount, detailList);
         }
 
         /// <summary>
@@ -446,6 +660,10 @@
                         saveModel.MainData.Remove(keyPro.Name.FirstLetterToLower());
                     }
                 }
+                    saveModel.MainData["CreateType"] = (int)OrderCreateTypeEnum.CreateInSystem;
+                    
+                    saveModel.MainData["ReturnToMESStatus"] = 5;
+
                 TEntity entity = saveModel.MainData.DicToModel<TEntity>();
                 if (saveModel.DetailData == null || saveModel.DetailData.Count == 0)
                 {

--
Gitblit v1.9.3