Browse Source

市场客户资料++

yuanrf 3 weeks ago
parent
commit
0b12d7dc6e

+ 69 - 7
OASystem/OASystem.Api/Controllers/MarketCustomerResourcesController.cs

@@ -318,12 +318,9 @@ namespace OASystem.API.Controllers
             return Ok(JsonView(true, "操作成功!"));
         }
 
-        [HttpPost]
-        
-        public IActionResult QueryClientType(QueryClientTypeDto Dto)
+        private Dictionary<int, List<int>> MCRSetting()
         {
-            var jw = JsonView(true,"获取成功!");
-            Dictionary<int,List<int>> keyValuePairs = new Dictionary<int,List<int>>();
+            Dictionary<int, List<int>> keyValuePairs = new Dictionary<int, List<int>>();
             keyValuePairs.Add(419, new List<int>() //四川
             {
                 376,377,378,381,382,387,388,389,390,753,754
@@ -341,6 +338,16 @@ namespace OASystem.API.Controllers
             keyValuePairs.Add(625, new List<int>() { 617, 618, 619, 620, 621, 622, 622, 623, 624, 754 }); // 甘肃
             keyValuePairs.Add(634, new List<int>() { 455, 630, 631, 632, 633, 754 }); // 新疆
 
+            return keyValuePairs;
+        }
+
+        [HttpPost]
+        
+        public IActionResult QueryClientType(QueryClientTypeDto Dto)
+        {
+            var jw = JsonView(true,"获取成功!");
+
+            var keyValuePairs = MCRSetting();
             ArrayList arr = new ArrayList();
             var ids = new List<int>();
             foreach (var item in Dto.SetDataIdArr)
@@ -353,19 +360,74 @@ namespace OASystem.API.Controllers
 
             arr.AddRange(_sqlSugar.Queryable<Sys_SetData>()
                        .Where(u => ids.Contains(u.Id) && u.IsDel == 0)
-                       .Select(x => new { x.Id, x.Name })
+                       .Select(x => new { x.Id, x.Name , x.Remark })
                        .ToList());
 
             if (arr.Count == 0)
             {
                 arr.AddRange(_sqlSugar.Queryable<Sys_SetData>()
                         .Where(u => u.STid == 37 && u.IsDel == 0)
-                        .Select(x => new { x.Id, x.Name }).ToList());
+                        .Select(x => new { x.Id, x.Name, x.Remark }).ToList());
             }
 
+            // 创建比较器实例
+            IComparer remakeComparer = new RemakeComparer();
+            
+            // 使用ArrayList.Sort方法和自定义比较器对arr进行排序
+            arr.Sort(remakeComparer);
+
             jw.Data = arr;
             
             return Ok(jw);
         }
+
+        [HttpPost]
+        public IActionResult SynchronizationData()
+        {
+            var keyValuePairs = new Dictionary<int, List<string>>
+                {
+                    { 5, new List<string> { "省级部门", "省级单位" } },
+                    { 10, new List<string> { "市州" } },
+                    { 15, new List<string> { "省属国企" } },
+                    { 20, new List<string> { "省属学校", "省属高校" } },
+                    { 25, new List<string> { "省级行业协会", "省级社团", "省级联合会" , "省属行业协会", "民营企业", "地方国企" } },
+                    { 30, new List<string> { "市级部门", "市级单位" } },
+                    { 35, new List<string> { "区市县" } },
+                    { 40, new List<string> { "市级国企", "市属国企" } },
+                    { 45, new List<string> { "市属学校", "市属高校" } },
+                    { 50, new List<string> { "市级行业协会", "市级社团", "市级联合会" } }
+                };
+
+            var setting = MCRSetting();
+            var arr = new List<List<Sys_SetData>>();
+
+            foreach (var item in setting.Keys)
+            {
+                var setDataList_DB = _sqlSugar.Queryable<Sys_SetData>()
+                                            .Where(x => x.IsDel == 0 && setting[item].Contains(x.Id))
+                                            .ToList();
+                foreach (var setData in setDataList_DB)
+                {
+                    foreach (var lv in keyValuePairs.Keys)
+                    {
+                        var islv =  keyValuePairs[lv].Where(x => setData.Name.Contains(x)).Count() > 0;
+
+                        if (islv)
+                        {
+                            setData.Remark = lv.ToString();
+                        }
+                    }
+                }
+
+                arr.Add(setDataList_DB);
+            }
+
+            _sqlSugar.Updateable(arr.SelectMany(x => x).ToList()).UpdateColumns(x => new
+            {
+                x.Remark
+            }).ExecuteCommand();
+
+            return Ok(arr);
+        }
     }
 }

+ 38 - 0
OASystem/OASystem.Domain/Dtos/CRM/NewClientDataQueryDto.cs

@@ -3,8 +3,10 @@ using OASystem.Domain.ViewModels.CRM;
 using Org.BouncyCastle.Asn1.Ocsp;
 using Org.BouncyCastle.Asn1.X9;
 using System;
+using System.Collections;
 using System.Collections.Generic;
 using System.Linq;
+using System.Reflection;
 using System.Text;
 using System.Threading.Tasks;
 using static Google.Protobuf.Reflection.SourceCodeInfo.Types;
@@ -227,4 +229,40 @@ namespace OASystem.Domain.Dtos.CRM
     {
         public List<int> SetDataIdArr { get; set; }
     }
+
+    public class RemakeComparer : IComparer
+    {
+        public int Compare(object x, object y)
+        {
+            // 使用反射获取remake属性的值
+            PropertyInfo xProperty = x.GetType().GetProperty("Remark");
+            PropertyInfo yProperty = y.GetType().GetProperty("Remark");
+
+            if (xProperty == null || yProperty == null)
+            {
+                throw new ArgumentException("Both objects must have a 'remake' property.");
+            }
+
+            string xRemake = xProperty.GetValue(x, null) as string;
+            string yRemake = yProperty.GetValue(y, null) as string;
+
+            // 使用TryParse安全地将字符串转换为整数
+            bool xIsInt = int.TryParse(xRemake, out int xValue);
+            bool yIsInt = int.TryParse(yRemake, out int yValue);
+
+            // 如果x是整数而y不是,则x应该排在y前面
+            if (xIsInt && !yIsInt)
+                return -1;
+            // 如果y是整数而x不是,则x应该排在后面
+            else if (!xIsInt && yIsInt)
+                return 1;
+            // 如果x和y都是整数,则比较它们的值
+            else if (xIsInt && yIsInt)
+                return xValue.CompareTo(yValue);
+            // 如果x和y都不是整数,则认为它们相等
+            else
+                return 0;
+        }
+    }
+
 }

+ 38 - 9
OASystem/OASystem.Infrastructure/Repositories/CRM/NewClientDataRepository.cs

@@ -104,17 +104,22 @@ namespace OASystem.Infrastructure.Repositories.CRM
                     _level.Add(data);
                 };
                 //客户类别
-                List<dynamic> _CustomerClass = new List<dynamic>();
+                ArrayList _CustomerClass = new ArrayList();
                 List<Sys_SetData> CustomerClass = initData.Where(u => u.STid == 37 && u.IsDel == 0).ToList();
                 foreach (Sys_SetData item in CustomerClass)
                 {
                     var data = new
                     {
                         Id = item.Id,
-                        Name = item.Name
+                        Name = item.Name,
+                        item.Remark
                     };
                     _CustomerClass.Add(data);
                 };
+                // 创建比较器实例
+                IComparer remakeComparer = new RemakeComparer();
+                _CustomerClass.Sort(remakeComparer);
+
                 //业务分类 
                 List<dynamic> _ServiceClass = new List<dynamic>();
                 List<Sys_SetData> ServiceClass = initData.Where(u => u.STid == 36 && u.IsDel == 0).ToList();
@@ -415,7 +420,21 @@ namespace OASystem.Infrastructure.Repositories.CRM
                 var _level = setDatas.Where(u => u.STid == 33).Select(x => new { x.Id, x.Name }).ToList();
 
                 //客户类别
-                var _CustomerClass = setDatas.Where(u => u.STid == 37).Select(x => new { x.Id, x.Name }).ToList();
+                ArrayList _CustomerClass = new ArrayList();
+                List<Sys_SetData> CustomerClass = setDatas.Where(u => u.STid == 37 && u.IsDel == 0).ToList();
+                foreach (Sys_SetData item in CustomerClass)
+                {
+                    var data = new
+                    {
+                        Id = item.Id,
+                        Name = item.Name,
+                        item.Remark
+                    };
+                    _CustomerClass.Add(data);
+                };
+                // 创建比较器实例
+                IComparer remakeComparer = new RemakeComparer();
+                _CustomerClass.Sort(remakeComparer);
 
                 //业务分类 
                 var _ServiceClass = setDatas.Where(u => u.STid == 36).Select(x => new { x.Id, x.Name }).ToList();
@@ -807,18 +826,23 @@ namespace OASystem.Infrastructure.Repositories.CRM
                     _level.Add(data);
                 };
                 //客户类别
-                List<dynamic> _CustomerClass = new List<dynamic>();
+                ArrayList _CustomerClass = new ArrayList();
                 List<Sys_SetData> CustomerClass = _sqlSugar.Queryable<Sys_SetData>()
-                .Where(u => u.STid == 37 && u.IsDel == 0).ToList();
+                    .Where(u => u.STid == 37 && u.IsDel == 0).ToList();
                 foreach (Sys_SetData item in CustomerClass)
                 {
                     var data = new
                     {
                         Id = item.Id,
-                        Name = item.Name
+                        Name = item.Name,
+                        item.Remark
                     };
                     _CustomerClass.Add(data);
                 };
+                // 创建比较器实例
+                IComparer remakeComparer = new RemakeComparer();
+                _CustomerClass.Sort(remakeComparer);
+
                 //业务分类 
                 List<dynamic> _ServiceClass = new List<dynamic>();
                 List<Sys_SetData> ServiceClass = _sqlSugar.Queryable<Sys_SetData>()
@@ -1179,18 +1203,23 @@ namespace OASystem.Infrastructure.Repositories.CRM
                 _level.Add(data);
             };
             //客户类别
-            List<dynamic> _CustomerClass = new List<dynamic>();
+            ArrayList _CustomerClass = new ArrayList();
             List<Sys_SetData> CustomerClass = _sqlSugar.Queryable<Sys_SetData>()
-            .Where(u => u.STid == 37 && u.IsDel == 0).ToList();
+                .Where(u => u.STid == 37 && u.IsDel == 0).ToList();
             foreach (Sys_SetData item in CustomerClass)
             {
                 var data = new
                 {
                     Id = item.Id,
-                    Name = item.Name
+                    Name = item.Name,
+                    item.Remark
                 };
                 _CustomerClass.Add(data);
             };
+            // 创建比较器实例
+            IComparer remakeComparer = new RemakeComparer();
+            _CustomerClass.Sort(remakeComparer);
+
             //业务分类 
             List<dynamic> _ServiceClass = new List<dynamic>();
             List<Sys_SetData> ServiceClass = _sqlSugar.Queryable<Sys_SetData>()