| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631 | 
							- using Aspose.Cells;
 
- using EyeSoft.Extensions;
 
- using OASystem.API.OAMethodLib;
 
- using OASystem.Domain.AesEncryption;
 
- using OASystem.Domain.Attributes;
 
- using OASystem.Domain.Dtos.CRM;
 
- using OASystem.Domain.Entities.Customer;
 
- using OASystem.Infrastructure.Repositories.CRM;
 
- using OASystem.RedisRepository;
 
- using System.Collections;
 
- using System.Data;
 
- using System.Net;
 
- using UAParser;
 
- namespace OASystem.API.Controllers
 
- {
 
-     /// <summary>
 
-     /// 市场客户资料
 
-     /// </summary>
 
-     [Route("api/[controller]/[action]")]
 
-     public class MarketCustomerResourcesController : ControllerBase
 
-     {
 
-         private readonly NewClientDataRepository _clientDataRepository;
 
-         private readonly SqlSugarClient _sqlSugar;
 
-         private string keyName = "newClient_SearchKey";
 
-         /// <summary>
 
-         /// 初始化
 
-         /// </summary>
 
-         public MarketCustomerResourcesController(NewClientDataRepository clientDataRepository, SqlSugarClient sqlSugar)
 
-         {
 
-             this._clientDataRepository = clientDataRepository;
 
-             _sqlSugar = sqlSugar;
 
-         }
 
-         /// <summary>
 
-         /// 客户资料数据
 
-         /// 基础数据
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         [HttpPost]
 
-         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
 
-         public async Task<IActionResult> MarketCustomerInit(MarketCustomerInitDto dto)
 
-         {
 
-             JsonView jw = new JsonView();
 
-             try
 
-             {
 
-                 Result resultData = await _clientDataRepository._Init(dto);
 
-                 if (resultData.Code == 0)
 
-                 {
 
-                     jw = JsonView(true, "查询成功!", resultData.Data);
 
-                 }
 
-                 else
 
-                 {
 
-                     jw = JsonView(false, resultData.Msg);
 
-                 }
 
-             }
 
-             catch (Exception)
 
-             {
 
-                 jw = JsonView(false, "程序错误!");
 
-             }
 
-             return Ok(jw);
 
-         }
 
-         /// <summary>
 
-         /// 查询客户资料数据
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         [HttpPost]
 
-         //[ApiLog("Crm_NewClientData", OperationEnum.List)]
 
-         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
 
-         public async Task<IActionResult> QueryNewClientData(NewClientDataQueryDto dto)
 
-         {
 
-             #region 参数验证
 
-             if (dto.OperationUserId < 0)
 
-                 return Ok(JsonView(false, "请传入有效的OperationUserId参数!"));
 
-             if (dto.PortType < 0)
 
-                 return Ok(JsonView(false, "请传入有效的PortType参数!"));
 
-             #endregion
 
-             JsonView jw = new JsonView();
 
-             var startTime = DateTime.UtcNow; 
 
-             try
 
-             {
 
-                 Result resultData = await _clientDataRepository.QueryNewClientData(dto);
 
-                 if (resultData.Code == 0)
 
-                 {
 
-                     #region 客户资料表操作记录
 
-                     //await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.NoOperation, dto.OperationUserId, 0, "");
 
-                     #endregion
 
-                     jw = JsonView(true, resultData.Msg, resultData.Data);
 
-                 }
 
-                 else
 
-                 {
 
-                     jw = JsonView(false, resultData.Msg);
 
-                 }
 
-             }
 
-             catch (Exception)
 
-             {
 
-                 jw = JsonView(false, "程序错误!");
 
-             }
 
-             finally
 
-             {
 
-                 using var ssg = _sqlSugar.CopyNew();
 
-                 var status = HttpContext.Response.StatusCode.ToString();
 
-                 _ = Task.Run(async () =>
 
-                 {
 
-                     try
 
-                     {
 
-                         string remoteIp = string.Empty,
 
-                                location = string.Empty;
 
-                         // 检查请求头中的X-Forwarded-For,以获取真实的客户端IP地址
 
-                         if (HttpContext.Request.Headers.ContainsKey("X-Forwarded-For"))
 
-                         {
 
-                             remoteIp = HttpContext.Request.Headers["X-Forwarded-For"].ToString().Split(',', StringSplitOptions.RemoveEmptyEntries)[0];
 
-                         }
 
-                         else
 
-                         {
 
-                             remoteIp = HttpContext.Connection.RemoteIpAddress?.ToString();
 
-                         }
 
-                         var task = GetIpInfo(remoteIp);
 
-                         string deviceType = string.Empty, browser = string.Empty, os = string.Empty;
 
-                         var userAgent = HttpContext.Request.Headers["User-Agent"].FirstOrDefault();
 
-                         if (!string.IsNullOrEmpty(userAgent))
 
-                         {
 
-                             // 解析User-Agent头
 
-                             var parser = Parser.GetDefault();
 
-                             var client = parser.Parse(userAgent);
 
-                             // 提取浏览器信息
 
-                             browser = client.UA.Family; // 浏览器名称
 
-                             var browserVersion = client.UA.Major + "." + client.UA.Minor + "." + client.UA.Patch; // 浏览器版本
 
-                             browser += $"({browserVersion})";
 
-                             // 提取操作系统信息
 
-                             os = client.OS.Family; // 操作系统名称
 
-                             var osVersion = string.Empty; // 操作系统版本
 
-                             if (!string.IsNullOrEmpty(client.OS.Major)) osVersion += client.OS.Major;
 
-                             if (!string.IsNullOrEmpty(client.OS.Minor)) osVersion += "." + client.OS.Minor;
 
-                             if (!string.IsNullOrEmpty(client.OS.Patch)) osVersion += "." + client.OS.Patch;
 
-                             if (!string.IsNullOrEmpty(osVersion)) os += $"({osVersion})";
 
-                             // 提取设备信息
 
-                             deviceType = client.Device.Family; // 设备类型,如 'mobile', 'tablet', 'desktop' 等
 
-                         }
 
-                         // 记录请求结束时间
 
-                         var endTime = DateTime.UtcNow;
 
-                         // 计算耗时
 
-                         var duration = (long)(endTime - startTime).TotalMilliseconds;
 
-                         //等待任务进行
 
-                         (remoteIp, location) = await task;
 
-                         //单独记录操作
 
-                         var logInfo = new Crm_TableOperationRecord()
 
-                         {
 
-                             TableName = "Crm_NewClientData",
 
-                             PortType = dto.PortType,
 
-                             OperationItem = OperationEnum.List,
 
-                             DataId = 0,
 
-                             RequestUrl = "/api/MarketCustomerResources/QueryNewClientData",
 
-                             RemoteIp = remoteIp,
 
-                             Location = location,
 
-                             RequestParam = JsonConvert.SerializeObject(dto),
 
-                             ReturnResult = JsonConvert.SerializeObject(jw),
 
-                             Elapsed = duration,
 
-                             Status = status,
 
-                             CreateUserId = dto.OperationUserId,
 
-                             UpdatePreData = "",
 
-                             UpdateBefData = "",
 
-                             Browser = browser,
 
-                             Os = os,
 
-                             DeviceType = deviceType,
 
-                         };
 
-                         // 存储到数据库
 
-                         await ssg.Insertable(logInfo).ExecuteCommandAsync();
 
-                     }
 
-                     catch (Exception ex)
 
-                     {
 
-                     }
 
-                 });
 
-             }
 
-             return Ok(jw);
 
-         }
 
-         /// <summary>
 
-         /// 客户资料数据
 
-         /// Details
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         [HttpPost]
 
-         [ApiLog("Crm_NewClientData", OperationEnum.Details)]
 
-         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
 
-         public async Task<IActionResult> PostNewClientDataDetails(NewClientDataDetailsDto dto)
 
-         {
 
-             #region 参数验证
 
-             if (dto.Id < 0)
 
-                 return Ok(JsonView(false, "请传入有效的Id参数!"));
 
-             if (dto.UserId < 0)
 
-                 return Ok(JsonView(false, "请传入有效的UserId参数!"));
 
-             if (dto.PortType < 0)
 
-                 return Ok(JsonView(false, "请传入有效的PortType参数!"));
 
-             #endregion
 
-             JsonView jw = new JsonView();
 
-             try
 
-             {
 
-                 Result resultData = await _clientDataRepository._Details(dto.PortType, dto.Id);
 
-                 if (resultData.Code == 0)
 
-                 {
 
-                     #region 客户资料表操作记录
 
-                     //await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Details, dto.UserId, dto.Id, "");
 
-                     #endregion
 
-                     jw = JsonView(true, "查询成功!", resultData.Data);
 
-                 }
 
-                 else
 
-                 {
 
-                     jw = JsonView(false, resultData.Msg);
 
-                 }
 
-             }
 
-             catch (Exception)
 
-             {
 
-                 jw = JsonView(false, "程序错误!");
 
-             }
 
-             return Ok(jw);
 
-         }
 
-         /// <summary>
 
-         /// 客户资料操作(Status:1.新增,2.修改)
 
-         /// </summary>
 
-         /// <param name="dto"></param>
 
-         /// <returns></returns>
 
-         [HttpPost]
 
-         [ApiLog("Crm_NewClientData", OperationEnum.NoOperation)]
 
-         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
 
-         public async Task<IActionResult> NewClientOp(NewClientOpDto dto)
 
-         {
 
-             #region 参数验证
 
-             if (dto.CreateUserId < 0)
 
-             {
 
-                 return Ok(JsonView(false, "请传入有效的CreateUserId参数!"));
 
-             }
 
-             if (dto.PortType < 0)
 
-             {
 
-                 return Ok(JsonView(false, "请传入有效的PortType参数!"));
 
-             }
 
-             #endregion
 
-             try
 
-             {
 
-                 Domain.Result result = await _clientDataRepository.NewClientOp(dto);
 
-                 if (result.Code != 0)
 
-                 {
 
-                     return Ok(JsonView(false, result.Msg));
 
-                 }
 
-                 #region 客户资料操作记录
 
-                 //OperationEnum operationEnum = OperationEnum.NoOperation;
 
-                 //if (dto.Status == 1)
 
-                 //{
 
-                 //    operationEnum = OperationEnum.Add;
 
-                 //    dto.Id = Convert.ToInt32(result.Data);
 
-                 //}
 
-                 //else if (dto.Status == 2) operationEnum = OperationEnum.Edit;
 
-                 //await GeneralMethod.NewClientOperationRecord(dto.PortType, operationEnum, dto.CreateUserId, dto.Id, "");
 
-                 #endregion
 
-                 //this.keyName += "_" + dto.CreateUserId;
 
-                 //var exists = await RedisFactory.CreateRedisRepository().KeyExistsAsync(keyName);
 
-                 //if (exists) await RedisFactory.CreateRedisRepository().KeyDeleteAsync(keyName);
 
-                 return Ok(JsonView(true, result.Msg + "Id:" + dto.Id));
 
-             }
 
-             catch (Exception ex)
 
-             {
 
-                 return Ok(JsonView(false, "程序错误!Msg:" + ex.Message));
 
-             }
 
-         }
 
-         /// <summary>
 
-         /// 新客户资料操作(删除)
 
-         /// </summary>
 
-         /// <param name="dto"></param>
 
-         /// <returns></returns>
 
-         [HttpPost]
 
-         [ApiLog("Crm_NewClientData", OperationEnum.Del)]
 
-         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
 
-         public async Task<IActionResult> NewClientDel(DelBaseDto dto)
 
-         {
 
-             #region 参数验证
 
-             if (dto.Id < 0)
 
-             {
 
-                 return Ok(JsonView(false, "请传入有效的Id参数!"));
 
-             }
 
-             if (dto.DeleteUserId < 0)
 
-             {
 
-                 return Ok(JsonView(false, "请传入有效的DeleteUserId参数!"));
 
-             }
 
-             if (dto.PortType < 0)
 
-             {
 
-                 return Ok(JsonView(false, "请传入有效的PortType参数!"));
 
-             }
 
-             #endregion
 
-             var res = await _clientDataRepository.DelNewClientData(dto);
 
-             if (res.Code != 0)
 
-             {
 
-                 return Ok(JsonView(false, "删除失败"));
 
-             }
 
-             #region 客户资料表操作记录
 
-             //await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Del, dto.DeleteUserId, dto.Id, "");
 
-             #endregion
 
-             //this.keyName += "_" + dto.DeleteUserId;
 
-             //var exists = await RedisFactory.CreateRedisRepository().KeyExistsAsync(keyName);
 
-             //if (exists) await RedisFactory.CreateRedisRepository().KeyDeleteAsync(keyName);
 
-             return Ok(JsonView(true, "删除成功!"));
 
-         }
 
-         /// <summary>
 
-         /// 获取下拉列表数据和单条数据信息
 
-         /// </summary>
 
-         /// <param name="dto"></param>
 
-         /// <returns></returns>
 
-         [HttpPost]
 
-         [ApiLog("Crm_NewClientData", OperationEnum.Details)]
 
-         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
 
-         public async Task<IActionResult> QuerySelectAndSingleData(QuerySingleDto dto)
 
-         {
 
-             JsonView jw = new JsonView();
 
-             var result = await _clientDataRepository.QuerySelectAndSingleData(dto);
 
-             if (result.Code == 0)
 
-             {
 
-                 #region 客户资料表操作记录
 
-                 //await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Details, dto.UserId, dto.Id, "");
 
-                 #endregion
 
-                 jw = JsonView(true, result.Msg, result.Data);
 
-             }
 
-             else
 
-             {
 
-                 jw = JsonView(false, result.Msg);
 
-             }
 
-             return Ok(jw);
 
-         }
 
-         /// <summary>
 
-         /// 获取现有负责人
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         [HttpPost]
 
-         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
 
-         public async Task<IActionResult> QueryUserSelect()
 
-         {
 
-             Result resTable = _clientDataRepository.QueryUserSelect();
 
-             return Ok(JsonView(true, resTable.Msg, resTable.Data));
 
-         }
 
-         /// <summary>
 
-         /// 获取出团数据
 
-         /// </summary>
 
-         /// <returns></returns>
 
-         [HttpPost]
 
-         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
 
-         public async Task<IActionResult> QueryNumberGroups()
 
-         {
 
-             var result = await _clientDataRepository.QueryNumberGroups();
 
-             if (result.Code != 0)
 
-             {
 
-                 return Ok(JsonView(false, result.Msg));
 
-             }
 
-             return Ok(JsonView(true, result.Msg, result.Data));
 
-         }
 
-         /// <summary>
 
-         /// 新客户资料操作
 
-         /// 批量分配
 
-         /// </summary>
 
-         /// <param name="dto"></param>
 
-         /// <returns></returns>
 
-         [HttpPost]
 
-         [ApiLog("Crm_NewClientData", OperationEnum.BatchAssignment)]
 
-         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
 
-         public async Task<IActionResult> PostBatchAssignment(BatchAssignmentDto dto)
 
-         {
 
-             #region 参数验证
 
-             if (dto.UserId < 0)
 
-             {
 
-                 return Ok(JsonView(false, "请传入有效的UserId参数!"));
 
-             }
 
-             if (dto.PortType < 0)
 
-             {
 
-                 return Ok(JsonView(false, "请传入有效的PortType参数!"));
 
-             }
 
-             #endregion
 
-             var res = await _clientDataRepository._BatchAssignment(dto);
 
-             if (res.Code != 0)
 
-             {
 
-                 return Ok(JsonView(false, res.Msg));
 
-             }
 
-             return Ok(JsonView(true, "操作成功!"));
 
-         }
 
-         private Dictionary<int, List<int>> MCRSetting()
 
-         {
 
-             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,1296,1303
 
-             });
 
-             keyValuePairs.Add(420, new List<int>() //云南
 
-             {
 
-                 407,408,409,410,449,451,452,453,567,754,1297,1304
 
-             });
 
-             keyValuePairs.Add(421, new List<int>() { 424, 425, 426, 427, 428, 429, 754, 1298, 1305, 1307, 1306 }); // 贵州
 
-             keyValuePairs.Add(422, new List<int>() { 415, 416, 754, 1317, 1316, 1315, 455, 1321, 1320, 1319, 1318 }); // 西藏
 
-             keyValuePairs.Add(423, new List<int>() { 417, 418, 454, 456, 754, 1313, 1314 }); // 重庆
 
-             keyValuePairs.Add(578, new List<int>() { 581, 582, 583, 754, 1299, 1300 }); // 青海
 
-             keyValuePairs.Add(605, new List<int>() { 588, 589, 590, 591, 592, 593, 754, 1301, 1310, 1309, 1308 }); // 陕西
 
-             keyValuePairs.Add(606, new List<int>() { 597, 598, 599, 600, 601, 602, 603, 604, 754, 1324, 1323, 1322 }); // 宁夏
 
-             keyValuePairs.Add(625, new List<int>() { 617, 618, 619, 620, 621, 622, 622, 623, 624, 754, 1302, 1312, 1311 }); // 甘肃
 
-             keyValuePairs.Add(634, new List<int>() { 630, 631, 632, 633, 754 }); // 新疆
 
-             return keyValuePairs;
 
-         }
 
-         private Dictionary<int, List<int>> MCRSecondSetting()
 
-         {
 
-             Dictionary<int, List<int>> keyValuePairs = new Dictionary<int, List<int>>();
 
-             // 四川
 
-             keyValuePairs.Add(349, new List<int>() { 376, 378, 381, 387, 389, 1296 }); // 四川省级
 
-             keyValuePairs.Add(350, new List<int>() { 377, 382, 388, 390, 1303 }); // 成都市级
 
-             keyValuePairs.Add(348, new List<int>() { 387 }); // 四川地市州 - Explicitly assigning to ensure all source2 IDs are used
 
-             keyValuePairs.Add(701, new List<int>() { 388 }); // 成都区市县
 
-             // 云南
 
-             keyValuePairs.Add(399, new List<int>() { 407, 408, 409, 410, 451 }); // 云南省级
 
-             keyValuePairs.Add(400, new List<int>() { 449, 452, 453, 1297, 1304 }); // 昆明市级
 
-             keyValuePairs.Add(450, new List<int>() { 410 }); // 云南地市州
 
-             keyValuePairs.Add(566, new List<int>() { 567 }); // 昆明区市县
 
-             // 贵州
 
-             keyValuePairs.Add(401, new List<int>() { 424, 426, 427, 428, 1298 }); // 贵州省级
 
-             keyValuePairs.Add(402, new List<int>() { 425, 429, 1306, 1307, 1305 }); // 贵阳市级
 
-             keyValuePairs.Add(414, new List<int>() { 428 }); // 贵州地市州
 
-             //keyValuePairs.Add(1305, new List<int>() { /* Add relevant IDs if available */ }); // 贵阳区市县 - Placeholder for now
 
-             // 重庆
 
-             keyValuePairs.Add(403, new List<int>() { 417, 418, 454, 456, 1314 }); // 重庆市级
 
-             keyValuePairs.Add(404, new List<int>() { 1313 }); // 重庆区县 - No direct match in source1
 
-             // 西藏
 
-             keyValuePairs.Add(405, new List<int>() { 415, 1317, 1316, 1315 }); // 西藏自治区
 
-             keyValuePairs.Add(406, new List<int>() { 455, 1321, 1320, 1319, 1318 }); // 拉萨市级
 
-             keyValuePairs.Add(413, new List<int>() { 416 }); // 西藏地市州
 
-             // 青海
 
-             keyValuePairs.Add(579, new List<int>() { 581, 582, 583, 1300 }); // 青海省级
 
-             keyValuePairs.Add(580, new List<int>() { 1299 }); // 青海市州县  (Includes 地市州)
 
-             // 陕西
 
-             keyValuePairs.Add(585, new List<int>() { 588, 589, 590, 591, 1301 }); // 陕西省级
 
-             keyValuePairs.Add(586, new List<int>() { 589 }); // 陕西地市州
 
-             keyValuePairs.Add(587, new List<int>() { 592, 593, 1309, 1310, 1308 }); // 西安市级
 
-             //keyValuePairs.Add(1308, new List<int>() { /* Add relevant IDs if available */ }); // 西安区市县 - Placeholder
 
-             // 宁夏
 
-             keyValuePairs.Add(594, new List<int>() { 597, 598, 599, 600, 601, 1322 }); // 宁夏自治区 (Includes 地市州 and 区级)
 
-             keyValuePairs.Add(595, new List<int>() { 597 }); // 宁夏地市州
 
-             keyValuePairs.Add(596, new List<int>() { 598, 599, 600, 603, 604, 602, 1323, 1324 }); // 银川市级 (Includes 区级)
 
-             //keyValuePairs.Add(602, new List<int>()); // 银川区市县 - No direct match, but could be considered covered by "区级"
 
-             // 甘肃
 
-             keyValuePairs.Add(614, new List<int>() { 617, 618, 619, 620, 621, 1302 }); // 甘肃省级
 
-             keyValuePairs.Add(615, new List<int>() { 618 }); // 甘肃地市州
 
-             keyValuePairs.Add(616, new List<int>() { 622, 623, 624, 1312, 1311 }); // 兰州市级
 
-             //keyValuePairs.Add(1311, new List<int>() { /* Add relevant IDs if available */ }); // 兰州区市县 - Placeholder
 
-             // 新疆
 
-             keyValuePairs.Add(627, new List<int>() { 630, 631, 632, 1327, 1326, 1325 }); // 新疆自治区级
 
-             keyValuePairs.Add(628, new List<int>() { 1326 }); // 新疆地市州 - No direct match
 
-             keyValuePairs.Add(629, new List<int>() { 633, 1331, 1330, 1329, 1328 }); // 乌鲁木齐市级
 
-             // 中央直属企业 (Special case)
 
-             keyValuePairs.Add(351, new List<int>() { 754 }); //  Using "未分级" for 中央直属企业
 
-             return keyValuePairs;
 
-         }
 
-         private Dictionary<int, List<int>> MCRLvSetting()
 
-         {
 
-             var keyValuePairs = new Dictionary<int, List<int>>();
 
-             // 四川 (419)
 
-             keyValuePairs.Add(419, new List<int>() { 348, 349, 350, 701 }); // Includes all Sichuan-related IDs from source2
 
-             // 云南 (420)
 
-             keyValuePairs.Add(420, new List<int>() { 399, 400, 450, 566 }); // Includes all Yunnan-related IDs
 
-             // 贵州 (421)
 
-             keyValuePairs.Add(421, new List<int>() { 401, 402, 414 });
 
-             // 西藏 (422)
 
-             keyValuePairs.Add(422, new List<int>() { 405, 406, 413 });
 
-             // 重庆 (423)
 
-             keyValuePairs.Add(423, new List<int>() { 403, 404 });
 
-             // 青海 (578)
 
-             keyValuePairs.Add(578, new List<int>() { 579, 580, 626 }); // Includes 市州县 and 西宁市级
 
-             // 陕西 (605)
 
-             keyValuePairs.Add(605, new List<int>() { 585, 586, 587 });
 
-             // 宁夏 (606)
 
-             keyValuePairs.Add(606, new List<int>() { 594, 595, 596 });
 
-             // 甘肃 (625)
 
-             keyValuePairs.Add(625, new List<int>() { 614, 615, 616 });
 
-             // 新疆 (634)
 
-             keyValuePairs.Add(634, new List<int>() { 627, 628, 629 });
 
-             // 未分级 (351) -  You'll likely want to remove this as it's no longer a primary key.
 
-             //  keyValuePairs.Add(351, new List<int>());  //Remove this line.
 
-             return keyValuePairs;
 
-         }
 
-         [HttpPost]
 
-         public IActionResult QueryClientType(QueryClientTypeDto Dto)
 
-         {
 
-             var jw = JsonView(true, "获取成功!");
 
-             var dic_lv = MCRLvSetting();
 
-             var keyValuePairs = MCRSetting();
 
-             ArrayList arr = new ArrayList();
 
-             ArrayList lvArr = new ArrayList();
 
-             var ids = new List<int>();
 
-             var lvids = new List<int>();
 
-             foreach (var item in Dto.SetDataIdArr)
 
-             {
 
-                 if (keyValuePairs.Keys.Contains(item))
 
-                 {
 
-                     ids.AddRange(keyValuePairs[item]);
 
-                 }
 
-                 if (dic_lv.Keys.Contains(item))
 
-                 {
 
-                     lvids.AddRange(dic_lv[item]);
 
-                 }
 
-             }
 
-             arr.AddRange(_sqlSugar.Queryable<Sys_SetData>()
 
-                        .Where(u => ids.Contains(u.Id) && u.IsDel == 0)
 
-                        .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, x.Remark }).ToList());
 
-             }
 
-             // 创建比较器实例
 
-             IComparer remakeComparer = new RemakeComparer();
 
-             // 使用ArrayList.Sort方法和自定义比较器对arr进行排序
 
-             arr.Sort(remakeComparer);
 
-             var rangelv = _sqlSugar.Queryable<Sys_SetData>()
 
-                        .Where(u => lvids.Contains(u.Id) && u.IsDel == 0)
 
-                        .Select(x => new { x.Id, x.Name })
 
-                        .ToList();
 
-             lvArr.AddRange(rangelv);
 
-             if (lvArr.Count == 0)
 
-             {
 
-                 lvArr.AddRange(_sqlSugar.Queryable<Sys_SetData>()
 
-                         .Where(u => u.STid == 33 && u.IsDel == 0)
 
-                         .Select(x => new { x.Id, x.Name }).ToList());
 
-             }
 
-             jw.Data = new
 
-             {
 
-                 TypeArr = arr,
 
-                 LvArr = lvArr,
 
-             };
 
-             return Ok(jw);
 
-         }
 
-         [HttpPost]
 
-         public IActionResult QueryClientTypeSecond(QueryClientTypeDto Dto)
 
-         {
 
-             var jw = JsonView(true, "获取成功!");
 
-             var keyValuePairs = MCRSecondSetting();
 
-             ArrayList arr = new ArrayList();
 
-             var ids = new List<int>();
 
-             foreach (var item in Dto.SetDataIdArr)
 
-             {
 
-                 if (keyValuePairs.Keys.Contains(item))
 
-                 {
 
-                     ids.AddRange(keyValuePairs[item]);
 
-                 }
 
-             }
 
-             arr.AddRange(_sqlSugar.Queryable<Sys_SetData>()
 
-                        .Where(u => ids.Contains(u.Id) && u.IsDel == 0)
 
-                        .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, x.Remark }).ToList());
 
-             }
 
-             // 创建比较器实例
 
-             IComparer remakeComparer = new RemakeComparer();
 
-             // 使用ArrayList.Sort方法和自定义比较器对arr进行排序
 
-             arr.Sort(remakeComparer);
 
-             jw.Data = arr;
 
-             return Ok(jw);
 
-         }
 
-         /// <summary>
 
-         /// 客户资料数据 全信息导出 excel 下载
 
-         /// </summary>
 
-         /// <param name="dto"></param>
 
-         /// <returns></returns>
 
-         [HttpPost]
 
-         [ApiLog("Crm_NewClientData", OperationEnum.Download)]
 
-         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
 
-         public async Task<IActionResult> NewClientDataExcelDownload(NewClientDataExcelDownloadDto dto)
 
-         {
 
-             #region 参数验证
 
-             if (dto.OperationUserId < 0) return Ok(JsonView(false, "请传入有效的OperationUserId参数!"));
 
-             if (dto.PortType < 0) return Ok(JsonView(false, "请传入有效的PortType参数!"));
 
-             if (dto.PageId < 0) return Ok(JsonView(false, "请传入有效的PageId参数!"));
 
-             #endregion
 
-             #region 页面操作权限验证
 
-             var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.OperationUserId, dto.PageId);
 
-             if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权!"));
 
-             #endregion
 
-             var dt = await _clientDataRepository.NewClientDataExcelDownload(dto);
 
-             if (dt != null)
 
-             {
 
-                 string tempPath = (AppSettingsHelper.Get("ExcelBasePath") + "Template/公司客户资料导出模板.xlsx");
 
-                 var designer = new WorkbookDesigner();
 
-                 designer.Workbook = new Workbook(tempPath);
 
-                 designer.SetDataSource("NCDDT", dt);
 
-                 designer.Process();
 
-                 //文件名
 
-                 string fileName = $"公司客户资料(全信息导出){DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
 
-                 designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + "NewClientDataExcelDownload/" + fileName);
 
-                 string url = AppSettingsHelper.Get("ExcelBaseUrl") + "Office/Excel/NewClientDataExcelDownload/" + fileName;
 
-                 #region 客户资料表操作记录
 
-                 var respose = JsonView(true, "成功", url);
 
-                 //var paramData = new
 
-                 //{
 
-                 //    APIName = @"MarketCustomerResources/NewClientDataExcelDownload",
 
-                 //    RequestParam = dto,
 
-                 //    ResposeParam = respose
 
-                 //};
 
-                 //await GeneralMethod.NewClientOperationRecord(dto.PortType, OperationEnum.Download, dto.OperationUserId, 0, JsonConvert.SerializeObject(paramData));
 
-                 #endregion
 
-                 return Ok(respose);
 
-             }
 
-             return Ok(JsonView(false));
 
-         }
 
-         /// <summary>
 
-         /// 客户资料数据 分权限导出 excel 下载
 
-         /// </summary>
 
-         /// <param name="dto"></param>
 
-         /// <returns></returns>
 
-         [HttpPost]
 
-         [ApiLog("Crm_NewClientData", OperationEnum.Download)]
 
-         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
 
-         public async Task<IActionResult> NewClientDataAuthorityExcelDownload(NewClientDataExcelDownloadDto dto)
 
-         {
 
-             #region 参数验证
 
-             if (dto.OperationUserId < 0) return Ok(JsonView(false, "请传入有效的OperationUserId参数!"));
 
-             if (dto.PortType < 0) return Ok(JsonView(false, "请传入有效的PortType参数!"));
 
-             if (dto.PageId < 0) return Ok(JsonView(false, "请传入有效的PageId参数!"));
 
-             #endregion
 
-             #region 页面操作权限验证
 
-             var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.OperationUserId, dto.PageId);
 
-             if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您没有文件下载权!"));
 
-             #endregion
 
-             var dt = await _clientDataRepository.NewClientDataExcelDownload(dto);
 
-             if (dt != null)
 
-             {
 
-                 string tempPath = (AppSettingsHelper.Get("ExcelBasePath") + "Template/公司客户资料分权限导出模板.xlsx");
 
-                 var designer = new WorkbookDesigner();
 
-                 designer.Workbook = new Workbook(tempPath);
 
-                 designer.SetDataSource("NCDDT", dt);
 
-                 designer.Process();
 
-                 //文件名
 
-                 string fileName = $"公司客户资料(分权限导出){DateTime.Now.ToString("yyyyMMddHHmmss")}.xls";
 
-                 designer.Workbook.Save(AppSettingsHelper.Get("ExcelBasePath") + "NewClientDataExcelDownload/" + fileName);
 
-                 string url = AppSettingsHelper.Get("ExcelBaseUrl") + "Office/Excel/NewClientDataExcelDownload/" + fileName;
 
-                 var respose = JsonView(true, "成功", url);
 
-                 return Ok(respose);
 
-             }
 
-             return Ok(JsonView(false));
 
-         }
 
-         /// <summary>
 
-         /// 客户资料数据 历史记录 Init
 
-         /// </summary>
 
-         /// <param name="dto"></param>
 
-         /// <returns></returns>
 
-         [HttpPost]
 
-         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
 
-         public async Task<IActionResult> NewClientDataRecordInit(NewClientDataRecordInitDto dto)
 
-         {
 
-             #region 参数验证
 
-             if (dto.UserId < 0) return Ok(JsonView(false, MsgTips.UserId));
 
-             if (!SharingStaticData.PortTypes.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
 
-             if (dto.PageId < 0) return Ok(JsonView(false, MsgTips.PageId));
 
-             #endregion
 
-             #region 页面操作权限验证
 
-             var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
 
-             if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
 
-             #endregion
 
-             var enumfiltrates = new string[] { "NoOperation", "Audit", "Login" };
 
-             var operations = EnumHelper.GetEnumDescriptions(typeof(OperationEnum), enumfiltrates);
 
-             var operation1 = new List<dynamic>();
 
-             foreach (var item in operations)
 
-             {
 
-                 operation1.Add(new { value = item.Key, text = item.Value });
 
-             }
 
-             object userDatas = Array.Empty<object>();
 
-             if (dto.UserId == 21)
 
-             {
 
-                 var userIds = await _sqlSugar.Queryable<Crm_ClientDataAndUser>().Where(x => x.IsDel == 0).Select(x => x.usersId).Distinct().ToListAsync();
 
-                 if (userIds.Any())
 
-                 {
 
-                     userDatas = await _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && userIds.Contains(x.Id)).Select(x => new { value = x.Id, text = x.CnName }).ToListAsync();
 
-                 }
 
-             }
 
-             var data = new
 
-             {
 
-                 operations = operation1,
 
-                 userDatas = userDatas
 
-             };
 
-             return Ok(JsonView(data));
 
-         }
 
-         /// <summary>
 
-         /// 客户资料数据 历史记录
 
-         /// </summary>
 
-         /// <param name="dto"></param>
 
-         /// <returns></returns>
 
-         [HttpPost]
 
-         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
 
-         public async Task<IActionResult> NewClientDataRecord(NewClientDataRecordDto dto)
 
-         {
 
-             #region 参数验证
 
-             if (dto.UserId < 0) return Ok(JsonView(false, MsgTips.UserId));
 
-             if (!SharingStaticData.PortTypes.Contains(dto.PortType)) return Ok(JsonView(false, MsgTips.Port));
 
-             if (dto.PageId < 0) return Ok(JsonView(false, MsgTips.PageId));
 
-             #endregion
 
-             #region 页面操作权限验证
 
-             var pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
 
-             if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
 
-             #endregion
 
-             return Ok(await _clientDataRepository.NewClientDataRecord(dto));
 
-         }
 
-         #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 QueryData()
 
-         {
 
-             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)
 
-                 {
 
-                     count++;
 
-                     //if (!string.IsNullOrWhiteSpace(item.Client) && (item.Client.Contains("大学") || item.Client.Contains("学院")))
 
-                     {
 
-                         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);
 
-         }
 
-         [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);
 
-             }
 
-             // 创建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 ReassignCustomers()
 
-         {
 
-             var user_Client = _sqlSugar.Queryable<Crm_ClientDataAndUser>()
 
-                       .Where(x => x.usersId == 302 && x.IsDel == 0)
 
-                       .Select(x => new
 
-                       {
 
-                           x.Id,
 
-                           x.NewClientDataId
 
-                       })
 
-                       .ToList();
 
-             var ids = user_Client.Select(x => x.NewClientDataId).ToList();
 
-             string setDataSql = $"select * from Sys_SetData where STid = 33 and isdel = 0 and (Name like '%重庆%')  ";
 
-             var setDataids = _sqlSugar.SqlQueryable<Sys_SetData>(setDataSql).Select(x => x.Id).ToList();
 
-             var clients = _sqlSugar.Queryable<Crm_NewClientData>().Where(x => ids.Contains(x.Id) && setDataids.Contains(x.Lvlid) && x.IsDel == 0).ToList();
 
-             var clients_ids = clients.Select(x => x.Id).ToList();
 
-             int updateCount = 0;
 
-             _sqlSugar.BeginTran();
 
-             if (clients.Count == 223)
 
-             {
 
-                 updateCount = _sqlSugar.Updateable<Crm_ClientDataAndUser>()
 
-                           .Where(x => x.usersId == 302 && clients_ids.Contains(x.NewClientDataId) && x.IsDel == 0)
 
-                           .SetColumns(x => new Crm_ClientDataAndUser
 
-                           {
 
-                               usersId = 21
 
-                           })
 
-                           .ExecuteCommand();
 
-             }
 
-             if (updateCount == clients.Count)
 
-             {
 
-                 _sqlSugar.CommitTran();
 
-             }
 
-             else
 
-             {
 
-                 _sqlSugar.RollbackTran();
 
-             }
 
-             return Ok(new
 
-             {
 
-                 count = clients.Count,
 
-                 updateCount,
 
-             });
 
-         }
 
-         [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
 
-             {
 
-                 NewClientDataId = x,
 
-                 usersId = 327,
 
-                 CreateTime = DateTime.Now,
 
-                 CreateUserId = 235,
 
-                 IsDel = 0,
 
-             }).ToList();
 
-             var insertCount = _sqlSugar.Insertable(arr).ExecuteCommand();
 
-             return Ok(insertCount);
 
-         }
 
-         [HttpPost]
 
-         public IActionResult InsertDataGu()
 
-         {
 
-             string sql = @"SELECT  *  FROM  Crm_NewClientData cncd  WHERE  IsDel  = 0 
 
- 	                      AND  Lvlid in (
 
- 		                      select Id  from Sys_SetData where STid = 33 and isdel = 0 
 
- 		                      and (Name like '%云%南%' or Name like '%昆%明%')
 
- 	                      )";
 
-             var list = _sqlSugar.SqlQueryable<Crm_NewClientData>(sql).Select(x => x.Id).ToList();
 
-             var toUserList = new List<Crm_ClientDataAndUser>();
 
-             foreach (var item in list)
 
-             {
 
-                 toUserList.Add(new Crm_ClientDataAndUser
 
-                 {
 
-                     CreateTime = DateTime.Now,
 
-                     CreateUserId = 235,
 
-                     NewClientDataId = item,
 
-                     usersId = 364,
 
-                     IsDel = 0,
 
-                 });
 
-             }
 
-             var updateCount = 0;
 
-             if (toUserList.Count == 327)
 
-             {
 
-                 updateCount = _sqlSugar.Insertable(toUserList).ExecuteCommand();
 
-             }
 
-             return Ok(new
 
-             {
 
-                 updateCount
 
-             });
 
-         }
 
-         [HttpPost]
 
-         public IActionResult CloneUserClient(CloneUserClientDto dto)
 
-         {
 
-             var list = _sqlSugar.Queryable<Crm_ClientDataAndUser>()
 
-                                  .Where(x => x.IsDel == 0 && x.usersId == dto.UserId)
 
-                                  .ToList();
 
-             foreach (var item in list)
 
-             {
 
-                 item.usersId = dto.ToUserId;
 
-             }
 
-             var count = _sqlSugar.Insertable<Crm_ClientDataAndUser>(list).ExecuteCommand();
 
-             return Ok(new
 
-             {
 
-                 count,
 
-             });
 
-         }
 
-         #endregion
 
-         /// <summary>
 
-         /// 客户资料 操作记录记录查询
 
-         /// </summary>
 
-         /// <param name="userId"></param>
 
-         /// <returns></returns>
 
-         [HttpGet]
 
-         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
 
-         public async Task<IActionResult> NewClientDataOperatingRrecord(int userId)
 
-         {
 
-             var datas = await _sqlSugar.Queryable<Crm_TableOperationRecord, Crm_NewClientData, Sys_Users>((tor, ncd, u) =>
 
-              new JoinQueryInfos(
 
-                 JoinType.Left, tor.DataId == ncd.Id,
 
-                 JoinType.Left, tor.CreateUserId == u.Id
 
-                 ))
 
-                 .Where((tor, ncd, u) => tor.TableName == "Crm_NewClientData" && tor.CreateUserId == userId && (int)tor.OperationItem > 1)
 
-                 .Select((tor, ncd, u) => new
 
-                 {
 
-                     tor.PortType,
 
-                     tor.OperationItem,
 
-                     tor.DataId,
 
-                     ncd.Client,
 
-                     u.CnName,
 
-                     tor.CreateTime
 
-                 }).ToListAsync();
 
-             var view = new List<dynamic>();
 
-             if (datas.Any())
 
-             {
 
-                 datas = datas.OrderByDescending(x => x.CreateTime).ToList();
 
-                 foreach (var item in datas)
 
-                 {
 
-                     var text = item.OperationItem.GetDescription();
 
-                     view.Add(new
 
-                     {
 
-                         Client = AesEncryptionHelper.Decrypt(item.Client),
 
-                         item.PortType,
 
-                         item.OperationItem,
 
-                         text = text,
 
-                         item.DataId,
 
-                         item.CnName,
 
-                         item.CreateTime
 
-                     });
 
-                 }
 
-             }
 
-             return Ok(JsonView(view));
 
-         }
 
-         [HttpPost]
 
-         public async Task<IActionResult> SearchClientByKeyword(SearchClientByKeywordDto dto)
 
-         {
 
-             var jw = JsonView(true);
 
-             var expression = Expressionable.Create<Crm_NewClientData>()
 
-                                            .And(x => x.IsDel == 0);
 
-             this.keyName += "_" + dto.UserId;
 
-             //获取个人的客户
 
-             if (dto.UserId != 21)
 
-             {
 
-                 var userList = _clientDataRepository.GetNewExistClient(dto.UserId).Select(x => x.Id);
 
-                 var newClientData = _sqlSugar.Queryable<Crm_ClientDataAndUser>()
 
-                          .Where(x => x.IsDel == 0 && userList.Contains(x.usersId))
 
-                          .Select(x => x.NewClientDataId)
 
-                          .Distinct()
 
-                          .ToList();
 
-                 expression = expression.And(x => newClientData.Contains(x.Id));
 
-             }
 
-             var exists = false;
 
-             //var exists = await RedisFactory.CreateRedisRepository().KeyExistsAsync(keyName);
 
-             //if (exists) exists = await RedisFactory.CreateRedisRepository().HashFieldExistAsync(keyName, dto.Keyword);
 
-             if (!exists)
 
-             {
 
-                 string field = "Id,Client";
 
-                 var newClitnData = _sqlSugar.Queryable<Crm_NewClientData>()
 
-                                             .Where(expression.ToExpression())
 
-                                             .Select(field)
 
-                                             .ToList();
 
-                 foreach (var item in newClitnData)
 
-                 {
 
-                     EncryptionProcessor.DecryptProperties(item);
 
-                 }
 
-                 var keywordArray = dto.Keyword.ToCharArray();
 
-                 var matches = newClitnData
 
-                         .Where(fullString => !string.IsNullOrWhiteSpace(fullString.Client) &&
 
-                              keywordArray.All(keyword => fullString.Client.Contains(keyword)))
 
-                         .Select(x => new
 
-                         {
 
-                             x.Client,
 
-                             x.Id
 
-                         })
 
-                         .DistinctBy(x => x.Client)
 
-                         .ToList();
 
-                 if (matches.Any())
 
-                 {
 
-                     //await RedisFactory.CreateRedisRepository().HashSetAsync(keyName, dto.Keyword, matches);
 
-                     //await RedisFactory.CreateRedisRepository().KeyExpireInAsync(keyName, new TimeSpan(0,1,0));
 
-                     jw.Data = matches;
 
-                 }
 
-                 else
 
-                 {
 
-                     jw.Code = 201;
 
-                     jw.Msg = "empty list";
 
-                     jw.Data = new List<string>(1);
 
-                 }
 
-             }
 
-             else
 
-             {
 
-                 jw.Data = await RedisFactory.CreateRedisRepository().HashGetAsync<List<string>>(keyName, dto.Keyword);
 
-             }
 
-             return Ok(jw);
 
-         }
 
-         [HttpPost]
 
-         public async Task<IActionResult> QueryUnlockDropList()
 
-         {
 
-             var jw = JsonView(true);
 
-             var userList = await _sqlSugar.Queryable<Sys_SetData>().FirstAsync
 
-                 (x => x.Id == 1434 && x.IsDel == 0);
 
-             try
 
-             {
 
-                 if (userList != null)
 
-                 {
 
-                     var result = JsonConvert.DeserializeObject<List<int>>(userList.Remark);
 
-                     jw.Data = result;
 
-                 }
 
-             }
 
-             catch (Exception)
 
-             {
 
-                 jw.Code = 500;
 
-                 jw.Msg = "数据源错误!";
 
-                 jw.Data = new List<int>(1);
 
-             }
 
-             return Ok(jw);
 
-         }
 
-         [HttpPost]
 
-         public IActionResult InsertDataExcel(InsertDataExcelDto dto)
 
-         {
 
-             //string client = dto.Client;
 
-             int toUser = dto.ToUser;
 
-             var clietnArr = dto.Client;
 
-             var count = 0;
 
-             //var notClentUser = new List<int>() { 21, 95  , 327 };
 
-             var notClentUser = new List<int>() { 213, 327 };
 
-             var insertList = new List<Crm_ClientDataAndUser>();
 
-             if (clietnArr.Count > 0)
 
-             {
 
-                 _sqlSugar.BeginTran();
 
-                 //检索相关客户数据
 
-                 var newClientArr = _sqlSugar.Queryable<Crm_NewClientData>()
 
-                     .Where(x => x.IsDel == 0)
 
-                     .Select(x => new Crm_NewClientData
 
-                     {
 
-                         Client = x.Client,
 
-                         Id = x.Id
 
-                     })
 
-                     .ToList()
 
-                     .Select(x => new
 
-                     {
 
-                         Client = AesEncryptionHelper.Decrypt(x.Client),
 
-                         Id = x.Id
 
-                     });
 
-                 foreach (var item in clietnArr)
 
-                 {
 
-                     var searchClient = newClientArr.Where(x => x.Client == item).ToList();
 
-                     foreach (var clientData in searchClient)
 
-                     {
 
-                         var clientDataAndUser = _sqlSugar.Queryable<Crm_ClientDataAndUser>()
 
-                                                 .Where(x => x.NewClientDataId == clientData.Id && x.IsDel == 0)
 
-                                                 .ToList();
 
-                         if (clientDataAndUser.Count > 0)
 
-                         {
 
-                             //清除关联表数据
 
-                             _sqlSugar.Updateable<Crm_ClientDataAndUser>()
 
-                                 .Where(x => !notClentUser.Contains(x.usersId)
 
-                                 && x.NewClientDataId == clientData.Id && x.IsDel == 0)
 
-                                 .SetColumns(x => new Crm_ClientDataAndUser
 
-                                 {
 
-                                     IsDel = 1,
 
-                                     DeleteTime = DateTime.Now.ToString(),
 
-                                     DeleteUserId = 235
 
-                                 })
 
-                                 .ExecuteCommand();
 
-                         }
 
-                         insertList.Add(new Crm_ClientDataAndUser
 
-                         {
 
-                             usersId = toUser,
 
-                             NewClientDataId = clientData.Id,
 
-                             CreateTime = DateTime.Now,
 
-                             CreateUserId = 235,
 
-                         });
 
-                     }
 
-                 }
 
-                 count = _sqlSugar.Insertable(insertList).ExecuteCommand();
 
-                 _sqlSugar.CommitTran();
 
-             }
 
-             return Ok(new
 
-             {
 
-                 count,
 
-             });
 
-         }
 
-         /// <summary>
 
-         /// 客户资料分配(按照数据ID) - UserId
 
-         /// </summary>
 
-         /// <param name="file"></param>
 
-         /// <returns></returns>
 
-         [HttpPost]
 
-         public IActionResult InsertDataExcel1(IFormFile file)
 
-         {
 
-             // 检查文件是否为空
 
-             if (file == null || file.Length == 0)
 
-             {
 
-                 return BadRequest("No file uploaded.");
 
-             }
 
-             // 保存文件到服务器
 
-             var uploadsFolder = Path.Combine(Directory.GetCurrentDirectory(), "File");
 
-             if (!Directory.Exists(uploadsFolder))
 
-             {
 
-                 Directory.CreateDirectory(uploadsFolder);
 
-             }
 
-             var filePath = Path.Combine(uploadsFolder, file.FileName);
 
-             using (var stream = new FileStream(filePath, FileMode.Create))
 
-             {
 
-                 file.CopyToAsync(stream);
 
-             }
 
-             Workbook workbook = new Workbook(filePath);
 
-             // 获取第一个工作表
 
-             Worksheet worksheet = workbook.Worksheets[0];
 
-             // 获取表头(第一行作为列名)
 
-             int headerRowIndex = 0; // 假设第一行是表头
 
-             Row headerRow = worksheet.Cells.Rows[headerRowIndex];
 
-             int colCount = worksheet.Cells.MaxDataColumn + 1;
 
-             // 动态存储列名
 
-             var clients = new List<Crm_ClientDataAndUser>();
 
-             // 遍历数据行(从第二行开始)
 
-             int rowCount = worksheet.Cells.MaxDataRow + 1;
 
-             for (int row = headerRowIndex + 1; row < rowCount; row++)
 
-             {
 
-                 var cellVal1 = worksheet.Cells[row, 0].Value;  //序号
 
-                 var cellVal2 = worksheet.Cells[row, 1].Value;  //数据Id
 
-                 var cellVal3 = worksheet.Cells[row, 2].Value;  //userId
 
-                 int parentId = !string.IsNullOrEmpty(cellVal2?.ToString()) ? int.Parse(cellVal2?.ToString()) : 0;
 
-                 int userId = !string.IsNullOrEmpty(cellVal3?.ToString()) ? int.Parse(cellVal3?.ToString()) : 0;
 
-                 var rowData = new Crm_ClientDataAndUser()
 
-                 {
 
-                     usersId = userId,
 
-                     NewClientDataId = parentId
 
-                 };
 
-                 clients.Add(rowData); // 将当前行数据添加到集合中
 
-             }
 
-             var count = 0;
 
-             //var notClentUser = new List<int>() { 21, 95  , 327 };
 
-             var notClentUser = new List<int>() { 21, 95, 327, 213 };
 
-             var insertList = new List<Crm_ClientDataAndUser>();
 
-             if (clients.Count > 0)
 
-             {
 
-                 _sqlSugar.BeginTran();
 
-                 //检索相关客户数据
 
-                 var newClientArr = _sqlSugar.Queryable<Crm_NewClientData>()
 
-                     .Where(x => x.IsDel == 0)
 
-                     .Select(x => new Crm_NewClientData
 
-                     {
 
-                         Client = x.Client,
 
-                         Id = x.Id
 
-                     })
 
-                     .ToList();
 
-                 foreach (var item in clients)
 
-                 {
 
-                     var searchClient = newClientArr.Where(x => x.Id == item.NewClientDataId).ToList();
 
-                     foreach (var clientData in searchClient)
 
-                     {
 
-                         var clientDataAndUser = _sqlSugar.Queryable<Crm_ClientDataAndUser>()
 
-                                                 .Where(x => x.NewClientDataId == clientData.Id && x.IsDel == 0)
 
-                                                 .ToList();
 
-                         if (clientDataAndUser.Count > 0)
 
-                         {
 
-                             //清除关联表数据
 
-                             _sqlSugar.Updateable<Crm_ClientDataAndUser>()
 
-                                 .Where(x => !notClentUser.Contains(x.usersId)
 
-                                 && x.NewClientDataId == clientData.Id && x.IsDel == 0)
 
-                                 .SetColumns(x => new Crm_ClientDataAndUser
 
-                                 {
 
-                                     IsDel = 1,
 
-                                     DeleteTime = DateTime.Now.ToString(),
 
-                                     DeleteUserId = 235
 
-                                 })
 
-                                 .ExecuteCommand();
 
-                         }
 
-                         insertList.Add(new Crm_ClientDataAndUser
 
-                         {
 
-                             usersId = item.usersId,
 
-                             NewClientDataId = clientData.Id,
 
-                             CreateTime = DateTime.Now,
 
-                             CreateUserId = 235,
 
-                         });
 
-                     }
 
-                 }
 
-                 count = _sqlSugar.Insertable(insertList).ExecuteCommand();
 
-                 _sqlSugar.CommitTran();
 
-             }
 
-             return Ok(new
 
-             {
 
-                 count,
 
-             });
 
-         }
 
-         [HttpPost]
 
-         public IActionResult SchoolAllocation()
 
-         {
 
-             var clients = _sqlSugar.Queryable<Crm_NewClientData>()
 
-                .Where(x => x.IsDel == 0)
 
-                .Select(x => new Crm_NewClientData { Id = x.Id, Client = x.Client })
 
-                .ToList();
 
-             var keys = new List<string>()
 
-             {
 
-                 "大学", "学院", "中学", "教育", "学校", "一中", "二中", "七中", "十五中", "二十五中","高校"
 
-             };
 
-             var count = 0;
 
-             var insertArr = new List<Crm_ClientDataAndBusiness>();
 
-             // --368  教育
 
-             foreach (var item in clients)
 
-             {
 
-                 EncryptionProcessor.DecryptProperties(item);
 
-                 foreach (var key in keys)
 
-                 {
 
-                     if (!string.IsNullOrWhiteSpace(item.Client) && item.Client.Contains(key))
 
-                     {
 
-                         insertArr.Add(new Crm_ClientDataAndBusiness
 
-                         {
 
-                             NewClientDataId = item.Id,
 
-                             SetDataId = 368, // 教育
 
-                             CreateTime = DateTime.Now,
 
-                             CreateUserId = 235,
 
-                             IsDel = 0
 
-                         });
 
-                     }
 
-                 }
 
-             }
 
-             count = _sqlSugar.Insertable(insertArr)
 
-                  .ExecuteCommand();
 
-             return count > 0 ? Ok(JsonView(true, "分配成功!", count)) : Ok(JsonView(false, "分配失败!"));
 
-         }
 
-         /// <summary>
 
-         /// 获取IP信息
 
-         /// </summary>
 
-         /// <param name="ip">ipv4 or ipv6</param>
 
-         /// <returns></returns>
 
-         private async Task<(string ip, string local)> GetIpInfo(string ip)
 
-         {
 
-             string local = string.Empty;
 
-             if (IPAddress.TryParse(ip, out _))
 
-             {
 
-                 using HttpClient _httpClient = new HttpClient();
 
-                 var response = await _httpClient.GetAsync($"https://api.vore.top/api/IPdata?ip={ip}");
 
-                 response.EnsureSuccessStatusCode();
 
-                 var json = await response.Content.ReadAsStringAsync();
 
-                 var ipInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(json);
 
-                 if (ipInfo.code == 200)
 
-                 {
 
-                     ip = ipInfo.ipinfo.text;
 
-                     local = $"{ipInfo.adcode.o}";
 
-                 }
 
-             }
 
-             return (ip, local);
 
-         }
 
-         #region 回滚数据记录
 
-         //[HttpPost]
 
-         //public async Task<IActionResult> actionResult()
 
-         //{
 
-         //    var jw = JsonView(true);
 
-         //    var sql = @" SELECT * FROM OA2023DB.dbo.Crm_TableOperationRecord 
 
-         //                 WHERE TableName ='Crm_NewClientData' 
 
-         //                 AND OperationItem IN(4) AND  CreateTime > '2025-02-03' AND  CreateTime < '2025-03-06' 
 
-         //                 AND ReturnResult LIKE '%修改成功%'	";
 
-         //    var list = _sqlSugar.SqlQueryable<Crm_TableOperationRecord>(sql).Select(x=>new Crm_TableOperationRecord
 
-         //    {
 
-         //        RequestParam = x.RequestParam
 
-         //    }).ToList();
 
-         //    foreach (var item in list)
 
-         //    {
 
-         //        var string1 = item.RequestParam.Trim('"').Replace("\\", "");
 
-         //        //if (!string.IsNullOrEmpty(item.RequestParam))
 
-         //        //{
 
-         //        //    var req = item.RequestParam;
 
-         //        //    if (CommonFun.IsValidJson(item.RequestParam))
 
-         //        //    {
 
-         //        //        var res1 = JToken.Parse(item.RequestParam);
 
-         //        //    }
 
-         //        //    NewClientOpDto dto = JsonConvert.DeserializeObject<NewClientOpDto>(JsonConvert.DeserializeObject<string>(item.RequestParam));
 
-         //            NewClientOpDto dto1 = JsonConvert.DeserializeObject<NewClientOpDto>(string1);
 
-         //            var result = await this.NewClientOp(dto1);
 
-         //        //}
 
-         //    }
 
-         //    return Ok(jw);
 
-         //}
 
-         #endregion
 
-     }
 
- }
 
 
  |