2 Commits db3f0e3e0f ... 92cccaecbf

Author SHA1 Message Date
  yuanrf 92cccaecbf Merge branch 'develop' of http://132.232.92.186:3000/XinXiBu/OA2023 into develop 3 weeks ago
  yuanrf c8569ce1d8 1+++++++ 3 weeks ago
1 changed files with 199 additions and 37 deletions
  1. 199 37
      OASystem/OASystem.Api/Controllers/MarketCustomerResourcesController.cs

+ 199 - 37
OASystem/OASystem.Api/Controllers/MarketCustomerResourcesController.cs

@@ -1,10 +1,12 @@
-using OASystem.API.OAMethodLib;
+using Aspose.Cells;
+using OASystem.API.OAMethodLib;
 using OASystem.Domain.AesEncryption;
 using OASystem.Domain.Dtos.CRM;
 using OASystem.Domain.Entities.Customer;
 using OASystem.Infrastructure.Repositories.CRM;
 using System.Collections;
 using System.Diagnostics;
+using System.Linq;
 
 namespace OASystem.API.Controllers
 {
@@ -560,53 +562,213 @@ namespace OASystem.API.Controllers
             return Ok(jw);
         }
 
+        #region 修改数据
+        //[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);
+        //}
+
         [HttpPost]
-        public IActionResult SynchronizationData()
+        public IActionResult QueryData()
         {
-            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)
+
+            var db = _sqlSugar.Queryable<Crm_NewClientData>()
+                 .Where(x => x.IsDel == 0)
+                 .Select(x => new Crm_NewClientData
+                 {
+                     Id = x.Id,
+                     Client = x.Client,
+                     Category = x.Category,
+                     Location = x.Location,
+                 }).ToList();
+
+            var count = 0;
+            var updateid = new List<int>();
+            foreach (var item in db)
+            {
+                EncryptionProcessor.DecryptProperties(item);
+                if (!string.IsNullOrWhiteSpace(item.Location) && item.Location.Contains("重庆") && item.Category == 0)
                 {
-                    foreach (var lv in keyValuePairs.Keys)
+                    count++;
+                    //if (!string.IsNullOrWhiteSpace(item.Client) && (item.Client.Contains("大学") || item.Client.Contains("学院")))
                     {
-                        var islv =  keyValuePairs[lv].Where(x => setData.Name.Contains(x)).Count() > 0;
-
-                        if (islv)
-                        {
-                            setData.Remark = lv.ToString();
-                        }
+                        updateid.Add(item.Id);
                     }
                 }
+            }
+
+            var updateCount = _sqlSugar.Updateable<Crm_NewClientData>().Where(x => updateid.Contains(x.Id))
+                .SetColumns(x => new Crm_NewClientData { Category = 456 }).ExecuteCommand();
+
+            return Ok( new
+            {
+                notCount = count,
+                updateCount = updateCount
+            });
+        }
+
+        [HttpPost]
+        public IActionResult InsertData()
+        {
+
+            string sql = $@"SELECT * FROM [dbo].[Crm_NewClientData] WHERE ID IN (
+	                    --所有四川省域的
+	                    select Id from [dbo].[Crm_NewClientData] where ISDEL = 0 AND Lvlid IN (
+			                    select S.Id  from Sys_SetData S
+			                    where STid = 33 and isdel = 0 and 
+			                    (Name like '%四%川%' or Name like '%成%都%')
+		                    )
+	
+                    ) AND IsDel = 0 
+                    AND ID IN (
+	                    SELECT NewClientDataId  FROM [dbo].[Crm_ClientDataAndUser] 
+		                    WHERE NewClientDataId IN (
+			                    --所有单独数据
+			                    SELECT NewClientDataId  FROM [dbo].[Crm_ClientDataAndUser] 
+			                    WHERE ISDEL = 0 
+			                    GROUP BY NewClientDataId 
+			                    HAVING COUNT(NewClientDataId) = 1  
+		                    ) AND IsDel = 0 AND UsersId = 21
+                    )";
+            var clientList = _sqlSugar.SqlQueryable<Crm_NewClientData>(sql).Select(x => x.Id).ToList().Select(x => new Crm_ClientDataAndUser
+            {
+                NewClientDataId = x,
+                usersId = 330,
+                CreateTime = DateTime.Now,
+                CreateUserId = 235,
+                IsDel = 0,
+            }).ToList();
+            var insertCount = _sqlSugar.Insertable(clientList).ExecuteCommand();
+            return Ok(insertCount);
+        }
 
-                arr.Add(setDataList_DB);
+        [HttpPost]
+        public IActionResult ExportData()
+        {
+
+           var soure =   _sqlSugar.Queryable<Crm_NewClientData>()
+                .InnerJoin<Crm_ClientDataAndUser>((a, b) => b.NewClientDataId == a.Id && b.IsDel == 0)
+                .Where((a, b) => a.IsDel == 0 && b.usersId == 95)
+                .Select((a, b) => a)
+                .ToList();
+
+            foreach (var item in soure)
+            {
+                EncryptionProcessor.DecryptProperties(item);
             }
 
-            _sqlSugar.Updateable(arr.SelectMany(x => x).ToList()).UpdateColumns(x => new
+            // 创建WorkbookDesigner对象
+            WorkbookDesigner designer = new WorkbookDesigner();
+
+            // 加载模板文件(包含智能标记)
+            designer.Workbook = new Workbook("C:\\Users\\PC\\Desktop\\111.xlsx");
+
+            // 设置数据源,这里假设你的List集合名为listData
+            designer.SetDataSource("ListData", soure);
+
+            // 处理智能标记以将数据填充到工作表中
+            designer.Process();
+
+            // 保存Excel文件
+            designer.Workbook.Save("C:\\Users\\PC\\Desktop\\111000.xlsx");
+
+            return Ok(1);
+        }
+
+        [HttpPost]
+        public IActionResult DeleteData()
+        {
+
+            var soure = _sqlSugar.Queryable<Crm_NewClientData>()
+                 .InnerJoin<Crm_ClientDataAndUser>((a, b) => b.NewClientDataId == a.Id && b.IsDel == 0)
+                 .Where((a, b) => a.IsDel == 0 && b.usersId == 330)
+                 .Select((a, b) => b.Id)
+                 .ToList();
+
+            var count = _sqlSugar.Updateable<Crm_ClientDataAndUser>()
+                 .Where(u => soure.Contains(u.Id) && u.IsDel == 0)
+                 .SetColumns(x => new Crm_ClientDataAndUser
+                 {
+                     DeleteTime = DateTime.Now.ToString(),
+                     DeleteUserId = 235,
+                     IsDel = 1
+                 }).ExecuteCommand();
+
+            return Ok(count);
+        }
+
+        [HttpPost]
+        public IActionResult InsertDataJiang()
+        {
+            var list_DB = _sqlSugar.Queryable<Crm_NewClientData>().Where(x => x.IsDel == 0).ToList();
+            foreach (var item in list_DB)
+            {
+                EncryptionProcessor.DecryptProperties(item);
+            }
+
+            list_DB = list_DB.Where(x => !string.IsNullOrWhiteSpace(x.Client) &&(x.Client.Contains("学院") || x.Client.Contains("大学"))).ToList();
+
+            var arr = list_DB.Select(x => x.Id).ToList().Select(x => new Crm_ClientDataAndUser
             {
-                x.Remark
-            }).ExecuteCommand();
+                NewClientDataId = x,
+                usersId = 327,
+                CreateTime = DateTime.Now,
+                CreateUserId = 235,
+                IsDel = 0,
+            }).ToList();
+            var insertCount = _sqlSugar.Insertable(arr).ExecuteCommand();
 
-            return Ok(arr);
+            return Ok(insertCount);
         }
+
+
+
+        #endregion  
+
+
     }
 }