Pengxy 9 hónapja
szülő
commit
eb5efd9318

+ 49 - 7
MicroServices/Business/Business.Application/ReplenishmentManagement/ReplenishmentAppService.cs

@@ -22,12 +22,14 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal;
 using MongoDB.Driver;
 using MongoDB.Driver.Linq;
 using Newtonsoft.Json;
+using NPOI.SS.Formula.Functions;
 using System;
 using System.Collections;
 using System.Collections.Generic;
 using System.ComponentModel.Design;
 using System.Data;
 using System.Linq;
+using System.Reflection;
 using System.Threading.Tasks;
 using Volo.Abp.Application.Services;
 using Volo.Abp.DependencyInjection;
@@ -4667,17 +4669,57 @@ namespace Business.Replenishment
 
         public List<WorkOrdMaster> RefreshPriority(List<string> workOrdMasters, string domain)
         {
-            var prioritylist = _PriorityCode.Select(p => p.IsActive && p.Domain == domain).ToList();
+            //优先级越高越往后排
+            var custList = _custMaster.Select(c => c.IsActive && c.Domain == domain).ToList();
+            var prioritylist = _PriorityCode.Select(p => p.IsActive && p.Domain == domain).OrderByDescending(p=>p.Priority).ToList();
             var works = _workOrdMaster.Select(a => workOrdMasters.Contains(a.WorkOrd) && a.Domain == domain && a.IsActive);
-            prioritylist.ForEach(p => {
-                var propertyName = p.Value;
-                var sortedPeople = works.OrderBy(p => GetPropertyValue(p, propertyName)).ToList();
-                if (!p.OrderBy)
+            var workords = works.Select(w => w.WorkOrd).ToList();
+            var meslist = _mysql_mes_morder.GetListAsync(m => workords.Contains(m.morder_no) && !m.IsDeleted).Result;
+            var messenList = _mysql_mes_moentry.GetListAsync(m => workords.Contains(m.moentry_mono) && !m.IsDeleted).Result;
+            var crmoList = _mysql_crm_seorder.GetListAsync(m=>messenList.Select(s => s.fbill_no).ToList().Contains(m.bill_no) && !m.IsDeleted).Result;
+
+            //排序字段
+            string[] sortColumns = new string[prioritylist.Count];
+            bool[] sortDirections = new bool[prioritylist.Count];
+            for (int i = 0; i < prioritylist.Count; i++)
+            {
+                sortColumns[i] = prioritylist[i].Value;
+                sortDirections[i] = prioritylist[i].OrderBy;
+            }
+
+            //更新客户优先级
+            for (int i = 0; i < works.Count; i++)
+            {
+                var sum = 0;
+                var curmessen = messenList.Where(m => m.moentry_mono == works[i].WorkOrd).First();
+                if (curmessen != null)
+                {
+                    var curcrmo = crmoList.Where(c => c.bill_no == curmessen.fbill_no).First();
+                    if (curcrmo != null)
+                    {
+                        var curcust = custList.Where(c => c.Cust == curcrmo.custom_no).First();
+                        if (curcust != null)
+                        {
+                            works[i].Class = decimal.Parse(curcust.Class == "" ? "0" : curcust.Class);
+                        }
+                    }
+                }
+                //相加
+                foreach (var fieldName in sortColumns)
                 {
-                    sortedPeople = works.OrderByDescending(p => GetPropertyValue(p, propertyName)).ToList();
+                    PropertyInfo propertyInfo = works[i].GetType().GetProperty(fieldName);
+                    if (propertyInfo != null)
+                    {
+                        int value = (int)propertyInfo.GetValue(works[i]);
+                        sum += value;
+                    }
                 }
-            });
+                works[i].Priority = sum;
+            }
 
+            
+            works.Sort(new DynamicOrderComparer<WorkOrdMaster>(sortColumns, sortDirections));
+            //更新优先级
             List<WorkOrdMaster> orderedList = new List<WorkOrdMaster>();
             decimal Priority = 1.0m;
             for (int i = 0; i < works.Count; i++)

+ 39 - 0
MicroServices/Business/Business.Core/Utilities/DynamicOrderComparer.cs

@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Business.Core.Utilities
+{
+    public class DynamicOrderComparer<T> : IComparer<T>
+    {
+        private readonly string[] _sortColumns;
+        private readonly List<bool> _sortDirections; // true for ascending, false for descending
+
+        public DynamicOrderComparer(string[] sortColumns, bool[] sortDirections)
+        {
+            _sortColumns = sortColumns;
+            _sortDirections = sortDirections.ToList();
+        }
+
+        public int Compare(T x, T y)
+        {
+            for (int i = 0; i < _sortColumns.Length; i++)
+            {
+                var property = typeof(T).GetProperty(_sortColumns[i]);
+                if (property == null) throw new ArgumentException($"Property {_sortColumns[i]} not found in type {typeof(T)}");
+                var xValue = property.GetValue(x);
+                var yValue = property.GetValue(y);
+
+                if (xValue == null && yValue == null) return 0;
+                if (xValue == null) return _sortDirections[i] ? -1 : 1;
+                if (yValue == null) return _sortDirections[i] ? 1 : -1;
+
+                var comparison = Comparer<object>.Default.Compare(xValue, yValue);
+                if (comparison != 0) return _sortDirections[i] ? comparison : -comparison;
+            }
+            return 0;
+        }
+    }
+}

+ 6 - 0
MicroServices/Business/Business.Domain/StructuredDB/MES/IC/CustMaster.cs

@@ -46,6 +46,12 @@ namespace Business.Domain
         public string Curr { get; set; }
 
         /// <summary>
+        /// 客户级别
+        /// </summary>
+        [Comment("客户级别")]
+        public string Class { get; set; }
+
+        /// <summary>
         /// 销售人员
         /// </summary>
         [Comment("销售人员")]

+ 7 - 0
MicroServices/Business/Business.Domain/StructuredDB/Production/WorkOrdMaster.cs

@@ -209,5 +209,12 @@ namespace Business.Domain
         /// </summary>
         [Comment("是否VMI结算")]
         public string IssueSite { get; set; }
+
+        /// <summary>
+        /// 客户优先级
+        /// </summary>
+        [Comment("客户优先级")]
+        public decimal? Class { get; set; }
+
     }
 }