NewClientDataRepository.cs 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724
  1. using AutoMapper;
  2. using AutoMapper.Execution;
  3. using EyeSoft.Extensions;
  4. using MySqlX.XDevAPI.Relational;
  5. using Newtonsoft.Json;
  6. using NPOI.OpenXmlFormats.Dml.Diagram;
  7. using NPOI.SS.Formula.Functions;
  8. using NPOI.SS.UserModel;
  9. using OASystem.Domain;
  10. using OASystem.Domain.AesEncryption;
  11. using OASystem.Domain.AutoMappers;
  12. using OASystem.Domain.Dtos;
  13. using OASystem.Domain.Dtos.CRM;
  14. using OASystem.Domain.Entities.Customer;
  15. using OASystem.Domain.Entities.Resource;
  16. using OASystem.Domain.Enums;
  17. using OASystem.Domain.ViewModels.CRM;
  18. using OASystem.Domain.ViewModels.JuHeExchangeRate;
  19. using OASystem.Domain.ViewModels.QiYeWeChat;
  20. using OASystem.Infrastructure.Tools;
  21. using SqlSugar;
  22. using System;
  23. using System.Collections;
  24. using System.Collections.Generic;
  25. using System.ComponentModel.Design;
  26. using System.Diagnostics;
  27. using System.Diagnostics.Contracts;
  28. using System.Linq;
  29. using System.Reflection.Metadata;
  30. using System.Runtime.Intrinsics.Arm;
  31. using System.Text;
  32. using System.Threading.Tasks;
  33. using System.Xml.Linq;
  34. using XAct;
  35. using static Google.Protobuf.Reflection.SourceCodeInfo.Types;
  36. using static OASystem.Domain.Dtos.CRM.NewClientDataQueryDto;
  37. namespace OASystem.Infrastructure.Repositories.CRM
  38. {
  39. public class NewClientDataRepository : BaseRepository<Crm_NewClientData, NewClientDataView>
  40. {
  41. private readonly IMapper _mapper;
  42. public NewClientDataRepository(SqlSugarClient sqlSugar, IMapper mapper) :
  43. base(sqlSugar)
  44. {
  45. _mapper = mapper;
  46. }
  47. /// <summary>
  48. /// 客户资料
  49. /// 基础数据源
  50. /// </summary>
  51. /// <param name="dto"></param>
  52. /// <returns></returns>
  53. public async Task<Result> _Init(MarketCustomerInitDto Dto)
  54. {
  55. Result result = new Result() { Code = -2, Msg = "未知错误" };
  56. var portType = Dto.PortType;
  57. if (portType == 1 || portType == 2 || portType == 3)
  58. {
  59. #region 下拉框初始化数据
  60. //负责人下拉框
  61. //List<dynamic> _Users = new List<dynamic>();
  62. //var _Users = _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0).Select(x => new
  63. //{
  64. // x.Id,
  65. // Name = x.CnName
  66. //}).ToList();
  67. var _Users = GetNewExistClient(Dto.UserId)
  68. .Select(x => new
  69. {
  70. x.Id,
  71. Name = x.CnName
  72. }).ToList();
  73. //List<Sys_Users> users = GetNewExistClient();
  74. //foreach (Sys_Users user in users)
  75. //{
  76. // var data = new
  77. // {
  78. // Id = user.Id,
  79. // Name = user.CnName
  80. // };
  81. // _Users.Add(data);
  82. //};
  83. List<Sys_SetData> initData = _sqlSugar.Queryable<Sys_SetData>().Where(it => it.IsDel == 0).ToList();
  84. //客户级别数据
  85. List<dynamic> _level = new List<dynamic>();
  86. List<Sys_SetData> level = initData.Where(u => u.STid == 33 && u.IsDel == 0).ToList();
  87. foreach (Sys_SetData item in level)
  88. {
  89. var data = new
  90. {
  91. Id = item.Id,
  92. Name = item.Name
  93. };
  94. _level.Add(data);
  95. };
  96. //客户类别
  97. ArrayList _CustomerClass = new ArrayList();
  98. List<Sys_SetData> CustomerClass = initData.Where(u => u.STid == 37 && u.IsDel == 0).ToList();
  99. foreach (Sys_SetData item in CustomerClass)
  100. {
  101. var data = new
  102. {
  103. Id = item.Id,
  104. Name = item.Name,
  105. item.Remark
  106. };
  107. _CustomerClass.Add(data);
  108. };
  109. // 创建比较器实例
  110. IComparer remakeComparer = new RemakeComparer();
  111. _CustomerClass.Sort(remakeComparer);
  112. //业务分类
  113. List<dynamic> _ServiceClass = new List<dynamic>();
  114. List<Sys_SetData> ServiceClass = initData.Where(u => u.STid == 36 && u.IsDel == 0).ToList();
  115. foreach (Sys_SetData item in ServiceClass)
  116. {
  117. var data = new
  118. {
  119. Id = item.Id,
  120. Name = item.Name
  121. };
  122. _ServiceClass.Add(data);
  123. };
  124. //身份分类
  125. List<dynamic> _ProvinceClass = new List<dynamic>();
  126. List<Sys_SetData> ProvinceClass = initData.Where(u => u.STid == 42 && u.IsDel == 0).ToList();
  127. foreach (Sys_SetData item in ProvinceClass)
  128. {
  129. var data = new
  130. {
  131. Id = item.Id,
  132. Name = item.Name
  133. };
  134. _ProvinceClass.Add(data);
  135. };
  136. #endregion
  137. var data1 = new {
  138. Users = _Users,
  139. Level = _level,
  140. CustomerClass = _CustomerClass,
  141. ServiceClass= _ServiceClass,
  142. ProvinceClass = _ProvinceClass
  143. };
  144. return result = new Result()
  145. {
  146. Code = 0,
  147. Msg = "查询成功",
  148. Data = data1
  149. };
  150. }
  151. else
  152. {
  153. result.Msg = string.Format("请传入有效的PortType参数!");
  154. }
  155. return result;
  156. }
  157. /// <summary>
  158. /// 市场客户资料数据
  159. /// 详情
  160. /// </summary>
  161. /// <param name="dto"></param>
  162. /// <returns></returns>
  163. public async Task<Result> _Details(int portType,int id)
  164. {
  165. Result result = new Result() { Code = -2, Msg = "未知错误" };
  166. if (portType == 1 || portType == 2 || portType == 3)
  167. {
  168. if (id < 0)
  169. {
  170. result.Msg = string.Format("请传入有效的Id参数!");
  171. return result;
  172. }
  173. string infoSql = string.Format(@" Select * From Crm_NewClientData Where Isdel = 0 And Id = {0}", id);
  174. var info = await _sqlSugar.SqlQueryable<DetailsView>(infoSql).FirstAsync();
  175. if (info != null)
  176. {
  177. EncryptionProcessor.DecryptProperties(info);
  178. List<AscribedUser> AscribedUser = await _sqlSugar.SqlQueryable<AscribedUser>
  179. ("select u1.UsersId as UserId ,u2.CnName,u1.NewClientDataId from Crm_ClientDataAndUser u1,Sys_Users u2 where u1.UsersId=u2.Id and NewClientDataId=" + info.Id + " AND u1.ISDEL = 0").ToListAsync();
  180. info.AscribedUser = AscribedUser.Select(it => it.UserId).ToList();
  181. List<AscribedDepartment> AscribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>
  182. ("select d2.Id,d2.Name,d1.NewClientDataId from Crm_ClientDataAndBusiness d1,Sys_SetData d2 where d1.SetDataId=d2.Id and NewClientDataId=" + info.Id + " AND d1.ISDEL = 0").ToListAsync();
  183. info.AscribedDepartment = AscribedDepartment.Select(it => it.Id).ToList();
  184. result.Code = 0;
  185. result.Data = info;
  186. }
  187. }
  188. else result.Msg = MsgTips.Port;
  189. return result;
  190. }
  191. /// <summary>
  192. /// 客户资料初识初始化
  193. /// </summary>
  194. /// <param name="dto"></param>
  195. /// <returns></returns>
  196. public async Task<Result> QueryNewClientData(NewClientDataQueryDto dto)
  197. {
  198. Stopwatch stopwatch = Stopwatch.StartNew();
  199. Result result = new Result() { Code = -2, Msg = "未知错误" };
  200. int pageIndex = dto.PageIndex, pageSize = dto.PageSize;
  201. try
  202. {
  203. #region 交集
  204. List<int> NewClientDataId1 = new List<int>();
  205. List<int> NewClientDataId2 = new List<int>();
  206. int state = 0;
  207. #region 负责人
  208. if (dto.OperationUserId != 21)
  209. {
  210. if (string.IsNullOrWhiteSpace(dto.Userid))
  211. {
  212. dto.Userid = dto.OperationUserId.ToString();
  213. }
  214. }
  215. if (!string.IsNullOrWhiteSpace(dto.Userid))
  216. {
  217. string sql = string.Format(@"select u1.UsersId as UserId,u2.CnName,u1.NewClientDataId from Crm_ClientDataAndUser u1,Sys_Users u2 where u1.UsersId=u2.Id and u1.UsersId in ({0}) and u1.IsDel = 0", dto.Userid);
  218. List<AscribedUser> ascribedUsers = await _sqlSugar.SqlQueryable<AscribedUser>(sql).ToListAsync();
  219. if (ascribedUsers.Count != 0)
  220. {
  221. foreach (var ascribedUser in ascribedUsers)
  222. {
  223. if (ascribedUser.NewClientDataId != 0)
  224. {
  225. NewClientDataId1.Add(ascribedUser.NewClientDataId);
  226. }
  227. }
  228. }
  229. else
  230. {
  231. result = new Result() { Code = -1, Msg = "暂无数据" };
  232. }
  233. state = -1;
  234. }
  235. #endregion
  236. #region 业务归属
  237. if (!string.IsNullOrWhiteSpace(dto.Business))
  238. {
  239. string sql = string.Format(@"select d2.Id,d2.Name,d1.NewClientDataId from Crm_ClientDataAndBusiness d1,Sys_SetData d2 where d1.SetDataId=d2.Id and d1.SetDataId in ({0}) and d1.isdel = 0", dto.Business);
  240. List<AscribedDepartment> AscribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>(sql).ToListAsync();
  241. if (AscribedDepartment.Count != 0)
  242. {
  243. foreach (var item in AscribedDepartment)
  244. {
  245. if (item.NewClientDataId != 0)
  246. {
  247. NewClientDataId2.Add(item.NewClientDataId);
  248. }
  249. }
  250. }
  251. else
  252. {
  253. result = new Result() { Code = -1, Msg = "暂无数据" };
  254. }
  255. state = -1;
  256. }
  257. #endregion
  258. List<int> intList = new List<int>();
  259. if (NewClientDataId1.Count != 0 && NewClientDataId2.Count != 0)
  260. {
  261. intList = NewClientDataId1.Intersect(NewClientDataId2).ToList();
  262. }
  263. else if (NewClientDataId1.Count != 0)
  264. {
  265. intList = NewClientDataId1;
  266. }
  267. else if (NewClientDataId2.Count != 0)
  268. {
  269. if (dto.OperationUserId == 21)
  270. {
  271. intList = NewClientDataId2;
  272. }
  273. }
  274. if (state == -1)
  275. {
  276. if (intList.Count < 1) intList.Add(-1);
  277. }
  278. #endregion
  279. #region 省域条件
  280. var rangeSetDataList = new List<int>();
  281. if (dto.Range != 0)
  282. {
  283. string setDataSql = "select * from Sys_SetData where STid = 33 and isdel = 0 ";
  284. switch (dto.Range)
  285. {
  286. case 419:
  287. setDataSql += " and (Name like '%四%川%' or Name like '%成%都%')";
  288. break;
  289. case 421:
  290. setDataSql += " and (Name like '%贵%州%' or Name like '%贵%阳%')";
  291. break;
  292. case 420:
  293. setDataSql += " and (Name like '%云%南%' or Name like '%昆%明%')";
  294. break;
  295. case 423:
  296. setDataSql += " and (Name like '%重庆%')";
  297. break;
  298. case 422:
  299. setDataSql += " and (Name like '%西%藏%' or Name like '%拉%萨%')";
  300. break;
  301. case 578:
  302. setDataSql += " and (Name like '%青%海%' or Name like '%西%宁%')";
  303. break;
  304. case 605:
  305. setDataSql += " and (Name like '%陕%西%' or Name like '%西%安%')";
  306. break;
  307. case 606:
  308. setDataSql += " and (Name like '%宁%夏%' or Name like '%银%川%')";
  309. break;
  310. case 625:
  311. setDataSql += " and (Name like '%甘%肃%' or Name like '%兰%州%')";
  312. break;
  313. case 634:
  314. setDataSql += " and (Name like '%新%疆%' or Name like '%乌%鲁%木%齐%')";
  315. break;
  316. }
  317. rangeSetDataList = _sqlSugar.SqlQueryable<Sys_SetData>(setDataSql).Select(x => x.Id).ToList();
  318. }
  319. #endregion
  320. var NewClientDataView = new List<NewClientDataView>();
  321. var count = 0;
  322. string contact = dto.Contact, location = dto.Location, clientDto = dto.Client;
  323. var isSelectSearch = false;
  324. var searchDataIds = new List<int>();
  325. if (string.IsNullOrEmpty(contact) || string.IsNullOrEmpty(location) || string.IsNullOrEmpty(clientDto))
  326. {
  327. isSelectSearch = true;
  328. var searchClientDatas = await _sqlSugar.Queryable<Crm_NewClientData>()
  329. .Where(x => x.IsDel == 0)
  330. .Select(x => new Crm_NewClientData() { Id = x.Id, Client = x.Client, Location = x.Location, Contact = x.Contact })
  331. .ToListAsync();
  332. foreach (var item in searchClientDatas) EncryptionProcessor.DecryptProperties(item);
  333. if (dto.PortType == 1)
  334. {
  335. searchDataIds = searchClientDatas
  336. .WhereIF(!string.IsNullOrEmpty(contact), x => !string.IsNullOrEmpty(x.Contact) && x.Contact.Contains(contact)) //联系人条件
  337. .WhereIF(!string.IsNullOrEmpty(location), x => !string.IsNullOrEmpty(x.Location) && x.Location.Contains(location)) //地区条件
  338. .WhereIF(!string.IsNullOrEmpty(clientDto), x => !string.IsNullOrEmpty(x.Client) && x.Client.Contains(clientDto)) //单位条件
  339. .Select(x => x.Id)
  340. .ToList();
  341. }
  342. else if (dto.PortType == 2 || dto.PortType == 3)
  343. {
  344. searchDataIds = searchClientDatas
  345. .Where(x => (!string.IsNullOrEmpty(x.Contact) && x.Contact.Contains(clientDto)) ||
  346. (!string.IsNullOrEmpty(x.Location) && x.Location.Contains(clientDto)) ||
  347. (!string.IsNullOrEmpty(x.Client) && x.Client.Contains(clientDto)))
  348. .Select(x => x.Id)
  349. .ToList();
  350. }
  351. if (searchDataIds.Count < 1) searchDataIds.Add(0);
  352. }
  353. RefAsync<int> total = 0;
  354. var clientDatas = await _sqlSugar.Queryable<Crm_NewClientData>()
  355. .Where(x => x.IsDel == 0)
  356. .WhereIF(state == -1 && intList.Count > 0, x => intList.Contains(x.Id))
  357. .WhereIF(dto.Lvlid != 0, x => x.Lvlid == dto.Lvlid) //地市州条件
  358. .WhereIF(rangeSetDataList.Count > 0, x => rangeSetDataList.Contains(x.Lvlid)) //省域条件
  359. .WhereIF(dto.Category > 0, x => x.Category == dto.Category) //客户类别
  360. .WhereIF(isSelectSearch && searchDataIds.Count > 0 , x => searchDataIds.Contains(x.Id)) //条件模糊查询
  361. .OrderByDescending(x => x.CreateTime)
  362. .ToPageListAsync(pageIndex, pageSize, total);
  363. NewClientDataView = _mapper.Map<List<NewClientDataView>>(clientDatas);
  364. count = total;
  365. var setDatas = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0).ToList();
  366. #region 下拉框初始化数据
  367. //负责人下拉框
  368. var _Users = GetNewExistClient(dto.OperationUserId).Select(x => new { x.Id, Name = x.CnName }).ToList();
  369. //省域数据
  370. var _Province = setDatas.Where(u => u.STid == 42).Select(x => new { x.Id, x.Name }).ToList();
  371. //客户级别数据
  372. var _level = setDatas.Where(u => u.STid == 33).Select(x => new { x.Id, x.Name }).ToList();
  373. //客户类别
  374. ArrayList _CustomerClass = new ArrayList();
  375. List<Sys_SetData> CustomerClass = setDatas.Where(u => u.STid == 37 && u.IsDel == 0).ToList();
  376. foreach (Sys_SetData item in CustomerClass)
  377. {
  378. var data = new
  379. {
  380. Id = item.Id,
  381. Name = item.Name,
  382. item.Remark
  383. };
  384. _CustomerClass.Add(data);
  385. };
  386. // 创建比较器实例
  387. IComparer remakeComparer = new RemakeComparer();
  388. _CustomerClass.Sort(remakeComparer);
  389. //业务分类
  390. var _ServiceClass = setDatas.Where(u => u.STid == 36).Select(x => new { x.Id, x.Name }).ToList();
  391. #endregion
  392. var groupNumber = await QueryNumberGroups();
  393. if (NewClientDataView.Count > 0)
  394. {
  395. float totalPage = (float)count / dto.PageSize;//总页数
  396. if (totalPage == 0) totalPage = 1;
  397. else totalPage = (int)Math.Ceiling((double)totalPage);
  398. if (dto.PortType == 1)
  399. {
  400. int index = 1;
  401. foreach (var item in NewClientDataView)
  402. {
  403. //EncryptionProcessor.DecryptProperties(item); //解密
  404. item.Weight = AesEncryptionHelper.Decrypt(item.Weight);
  405. item.Client = AesEncryptionHelper.Decrypt(item.Client);
  406. item.Contact = AesEncryptionHelper.Decrypt(item.Contact);
  407. item.Job = AesEncryptionHelper.Decrypt(item.Job);
  408. item.Telephone = AesEncryptionHelper.Decrypt(item.Telephone);
  409. item.Phone = AesEncryptionHelper.Decrypt(item.Phone);
  410. item.Location = AesEncryptionHelper.Decrypt(item.Location);
  411. item.Remark = AesEncryptionHelper.Decrypt(item.Remark);
  412. item.RowNumber = index;
  413. item.CategoryStr = setDatas.Find(x => x.Id == item.Category)?.Name ?? "-";
  414. item.LvlidStr = setDatas.Find(x => x.Id == item.Lvlid)?.Name ?? "-";
  415. List<AscribedUser> AscribedUser = await _sqlSugar.SqlQueryable<AscribedUser>
  416. ("select u1.UsersId as UserId ,u2.CnName,u1.NewClientDataId from Crm_ClientDataAndUser u1,Sys_Users u2 where u1.UsersId=u2.Id and NewClientDataId=" + item.Id + " AND u1.ISDEL = 0").ToListAsync();
  417. item.AscribedUser = AscribedUser;
  418. List<AscribedDepartment> AscribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>
  419. ("select d2.Id,d2.Name,d1.NewClientDataId from Crm_ClientDataAndBusiness d1,Sys_SetData d2 where d1.SetDataId=d2.Id and NewClientDataId=" + item.Id + " AND d1.ISDEL = 0").ToListAsync();
  420. item.AscribedDepartment = AscribedDepartment;
  421. index++;
  422. }
  423. var Data = new
  424. {
  425. ClientTableData = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = NewClientDataView },
  426. Users = _Users,
  427. Province = _Province,
  428. level = _level,
  429. CustomerClass = _CustomerClass,
  430. ServiceClass = _ServiceClass,
  431. groupNumber = groupNumber.Data,
  432. };
  433. return result = new Result()
  434. {
  435. Code = 0,
  436. Msg = $"查询成功!解密耗时: {stopwatch.ElapsedMilliseconds} 毫秒",
  437. Data = Data
  438. };
  439. }
  440. else if (dto.PortType == 2 || dto.PortType == 3)
  441. {
  442. List<NewClientDataAndroidIOSView> newClientDataIOSViews = new List<NewClientDataAndroidIOSView>();
  443. int index = 1;
  444. foreach (var item in NewClientDataView)
  445. {
  446. newClientDataIOSViews.Add(new NewClientDataAndroidIOSView()
  447. {
  448. RowNumber = index,
  449. Id = item.Id,
  450. Client = AesEncryptionHelper.Decrypt(item.Client),
  451. Contact = AesEncryptionHelper.Decrypt(item.Contact),
  452. Job = AesEncryptionHelper.Decrypt(item.Job),
  453. Telephone = AesEncryptionHelper.Decrypt(item.Telephone),
  454. Location = AesEncryptionHelper.Decrypt(item.Location),
  455. });
  456. index++;
  457. }
  458. result = new Result()
  459. {
  460. Code = 0,
  461. Msg = $"查询成功!解密耗时: {stopwatch.ElapsedMilliseconds} 毫秒",
  462. Data = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = newClientDataIOSViews },
  463. };
  464. }
  465. }
  466. else
  467. {
  468. if (dto.PortType == 2 || dto.PortType == 3)
  469. {
  470. var Data = new { pageCount = 0, totalPage = 0, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = NewClientDataView };
  471. result = new Result() { Code = 0, Msg = "获取成功!", Data = Data };
  472. }
  473. else
  474. {
  475. var Data = new
  476. {
  477. ClientTableData = new { pageCount = 0, totalPage = 0, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = NewClientDataView },
  478. Users = _Users,
  479. Province = _Province,
  480. level = _level,
  481. CustomerClass = _CustomerClass,
  482. ServiceClass = _ServiceClass,
  483. groupNumber = groupNumber.Data,
  484. };
  485. result = new Result() { Code = 0, Msg = "获取成功!", Data = Data };
  486. }
  487. }
  488. }
  489. catch (Exception ex)
  490. {
  491. result = new Result() { Code = -2, Msg = "未知错误" };
  492. }
  493. stopwatch.Stop();
  494. result.Msg = $"耗时: {stopwatch.ElapsedMilliseconds} 毫秒";
  495. return result;
  496. }
  497. /// <summary>
  498. /// 客户资料初识初始化
  499. /// </summary>
  500. /// <param name="dto"></param>
  501. /// <returns></returns>
  502. public async Task<Result> QueryNewClientData1(NewClientDataQueryDto dto)
  503. {
  504. Result result = new Result() { Code = -2, Msg = "未知错误" };
  505. try
  506. {
  507. #region 交集
  508. List<int> NewClientDataId1 = new List<int>();
  509. List<int> NewClientDataId2 = new List<int>();
  510. string NewClientDataId = "";
  511. int state = 0;
  512. #region 负责人
  513. if (dto.OperationUserId != 21)
  514. {
  515. if (string.IsNullOrWhiteSpace(dto.Userid))
  516. {
  517. dto.Userid = dto.OperationUserId.ToString();
  518. }
  519. }
  520. if (!string.IsNullOrWhiteSpace(dto.Userid))
  521. {
  522. string sql = string.Format(@"select u1.UsersId as UserId,u2.CnName,u1.NewClientDataId from Crm_ClientDataAndUser u1,Sys_Users u2 where u1.UsersId=u2.Id and u1.UsersId in ({0}) and u1.IsDel = 0", dto.Userid);
  523. List<AscribedUser> ascribedUsers = await _sqlSugar.SqlQueryable<AscribedUser>(sql).ToListAsync();
  524. if (ascribedUsers.Count != 0)
  525. {
  526. foreach (var ascribedUser in ascribedUsers)
  527. {
  528. if (ascribedUser.NewClientDataId != 0)
  529. {
  530. NewClientDataId1.Add(ascribedUser.NewClientDataId);
  531. }
  532. }
  533. }
  534. else
  535. {
  536. result = new Result() { Code = -1, Msg = "暂无数据" };
  537. }
  538. state = -1;
  539. }
  540. #endregion
  541. #region 业务归属
  542. if (!string.IsNullOrWhiteSpace(dto.Business))
  543. {
  544. string sql = string.Format(@"select d2.Id,d2.Name,d1.NewClientDataId from Crm_ClientDataAndBusiness d1,Sys_SetData d2 where d1.SetDataId=d2.Id and d1.SetDataId in ({0}) and d1.isdel = 0", dto.Business);
  545. List<AscribedDepartment> AscribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>(sql).ToListAsync();
  546. if (AscribedDepartment.Count != 0)
  547. {
  548. foreach (var item in AscribedDepartment)
  549. {
  550. if (item.NewClientDataId != 0)
  551. {
  552. NewClientDataId2.Add(item.NewClientDataId);
  553. }
  554. }
  555. }
  556. else
  557. {
  558. result = new Result() { Code = -1, Msg = "暂无数据" };
  559. }
  560. state = -1;
  561. }
  562. #endregion
  563. List<int> intList = new List<int>();
  564. if (NewClientDataId1.Count != 0 && NewClientDataId2.Count != 0)
  565. {
  566. intList = NewClientDataId1.Intersect(NewClientDataId2).ToList();
  567. }
  568. else if (NewClientDataId1.Count != 0)
  569. {
  570. intList = NewClientDataId1;
  571. }
  572. else if (NewClientDataId2.Count != 0)
  573. {
  574. intList = NewClientDataId2;
  575. }
  576. #endregion
  577. foreach (var item in intList)
  578. {
  579. NewClientDataId += item + ",";
  580. }
  581. if (!string.IsNullOrWhiteSpace(NewClientDataId))
  582. {
  583. NewClientDataId = NewClientDataId.Substring(0, NewClientDataId.Length - 1);
  584. }
  585. string sqlWhere = string.Empty;
  586. if (dto.PortType == 1)
  587. {
  588. #region 联系人条件
  589. if (!string.IsNullOrWhiteSpace(dto.Contact))
  590. {
  591. sqlWhere += string.Format(@" And s.Contact like '%{0}%'", dto.Contact);
  592. }
  593. #endregion
  594. #region 地区条件
  595. if (!string.IsNullOrWhiteSpace(dto.Location))
  596. {
  597. sqlWhere += string.Format(@" And s.Location like '%{0}%'", dto.Location);
  598. }
  599. #endregion
  600. #region 单位条件
  601. if (!string.IsNullOrWhiteSpace(dto.Client))
  602. {
  603. sqlWhere += string.Format(@" And s.Client like '%{0}%'", dto.Client);
  604. }
  605. #endregion
  606. }
  607. else if (dto.PortType == 2 || dto.PortType == 3)
  608. {
  609. sqlWhere += string.Format("And (Contact like '%{0}%' or Location like '%{0}%' or Client like '%{0}%' )", dto.Client);
  610. }
  611. if (state == -1)
  612. {
  613. if (string.IsNullOrWhiteSpace(NewClientDataId))
  614. {
  615. NewClientDataId = "0";
  616. }
  617. sqlWhere += string.Format(@" And s.Id in({0})", NewClientDataId);
  618. }
  619. #region 地市州条件
  620. if (dto.Lvlid != 0)
  621. {
  622. sqlWhere += string.Format(@" And s.Lvlid={0}", dto.Lvlid);
  623. }
  624. #endregion
  625. #region 省域条件
  626. if (dto.Range != 0)
  627. {
  628. string setDataSql = "select * from Sys_SetData where STid = 33 and isdel = 0 ";
  629. switch (dto.Range)
  630. {
  631. case 419:
  632. setDataSql += " and (Name like '%四%川%' or Name like '%成%都%')";
  633. break;
  634. case 421:
  635. setDataSql += " and (Name like '%贵%州%' or Name like '%贵%阳%')";
  636. break;
  637. case 420:
  638. setDataSql += " and (Name like '%云%南%' or Name like '%昆%明%')";
  639. break;
  640. case 423:
  641. setDataSql += " and (Name like '%重庆%')";
  642. break;
  643. case 422:
  644. setDataSql += " and (Name like '%西%藏%' or Name like '%拉%萨%')";
  645. break;
  646. case 578:
  647. setDataSql += " and (Name like '%青%海%' or Name like '%西%宁%')";
  648. break;
  649. case 605:
  650. setDataSql += " and (Name like '%陕%西%' or Name like '%西%安%')";
  651. break;
  652. case 606:
  653. setDataSql += " and (Name like '%宁%夏%' or Name like '%银%川%')";
  654. break;
  655. case 625:
  656. setDataSql += " and (Name like '%甘%肃%' or Name like '%兰%州%')";
  657. break;
  658. case 634:
  659. setDataSql += " and (Name like '%新%疆%' or Name like '%乌%鲁%木%齐%')";
  660. break;
  661. }
  662. var RangeSetDataList = _sqlSugar.SqlQueryable<Sys_SetData>(setDataSql).Select(x => x.Id).ToList();
  663. string lvlds = string.Join(',', RangeSetDataList).TrimEnd(',');
  664. if (!string.IsNullOrEmpty(lvlds))
  665. {
  666. sqlWhere += string.Format(@" And s.Lvlid in ({0}) ", lvlds);
  667. }
  668. }
  669. #endregion
  670. #region 客户类别
  671. if (dto.Category != 0)
  672. {
  673. sqlWhere += string.Format(@" And s.Category = {0}", dto.Category);
  674. }
  675. #endregion
  676. sqlWhere += string.Format(@" And s.Lvlid=s1.Id And s.IsDel={0} ", 0);
  677. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  678. {
  679. Regex r = new Regex("And");
  680. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  681. }
  682. int pIndex = dto.PageIndex * dto.PageSize - dto.PageSize + 1;
  683. int pSize = dto.PageIndex * dto.PageSize;
  684. string sqlNew = string.Format(@"select (SELECT COUNT(1) FROM Crm_NewClientData s left Join Sys_SetData s1 On s.Lvlid=s1.Id {0}) AS countPage,* from (select ROW_NUMBER()
  685. over(order by s.CreateTime desc) RowNumber,s.*,s1.Name as 'LvlName' from Crm_NewClientData s left Join Sys_SetData s1 On s.Lvlid=s1.Id {0}) as co where
  686. RowNumber between {1} and {2} ", sqlWhere, pIndex, pSize);
  687. List<NewClientDataView> NewClientDataView = await _sqlSugar.SqlQueryable<NewClientDataView>(sqlNew).ToListAsync();
  688. foreach (var item in NewClientDataView)
  689. {
  690. Sys_SetData CategoryStr = _sqlSugar.Queryable<Sys_SetData>().Single(it => it.Id == item.Category);
  691. if (CategoryStr != null)
  692. {
  693. item.CategoryStr = CategoryStr != null ? CategoryStr.Name : null;
  694. }
  695. Sys_SetData lvlStr = _sqlSugar.Queryable<Sys_SetData>().Single(it => it.Id == item.Lvlid);
  696. if (lvlStr != null)
  697. {
  698. item.LvlidStr = lvlStr != null ? lvlStr.Name : null;
  699. }
  700. }
  701. #region 下拉框初始化数据
  702. //负责人下拉框
  703. List<dynamic> _Users = new List<dynamic>();
  704. List<Sys_Users> users = GetNewExistClient(dto.OperationUserId);
  705. foreach (Sys_Users user in users)
  706. {
  707. var data = new
  708. {
  709. Id = user.Id,
  710. Name = user.CnName
  711. };
  712. _Users.Add(data);
  713. };
  714. //省域数据
  715. List<dynamic> _Province = new List<dynamic>();
  716. List<Sys_SetData> province = _sqlSugar.Queryable<Sys_SetData>()
  717. .Where(u => u.STid == 42 && u.IsDel == 0).ToList();
  718. foreach (Sys_SetData item in province)
  719. {
  720. var data = new
  721. {
  722. Id = item.Id,
  723. Name = item.Name
  724. };
  725. _Province.Add(data);
  726. };
  727. //客户级别数据
  728. List<dynamic> _level = new List<dynamic>();
  729. List<Sys_SetData> level = _sqlSugar.Queryable<Sys_SetData>()
  730. .Where(u => u.STid == 33 && u.IsDel == 0).ToList();
  731. foreach (Sys_SetData item in level)
  732. {
  733. var data = new
  734. {
  735. Id = item.Id,
  736. Name = item.Name
  737. };
  738. _level.Add(data);
  739. };
  740. //客户类别
  741. ArrayList _CustomerClass = new ArrayList();
  742. List<Sys_SetData> CustomerClass = _sqlSugar.Queryable<Sys_SetData>()
  743. .Where(u => u.STid == 37 && u.IsDel == 0).ToList();
  744. foreach (Sys_SetData item in CustomerClass)
  745. {
  746. var data = new
  747. {
  748. Id = item.Id,
  749. Name = item.Name,
  750. item.Remark
  751. };
  752. _CustomerClass.Add(data);
  753. };
  754. // 创建比较器实例
  755. IComparer remakeComparer = new RemakeComparer();
  756. _CustomerClass.Sort(remakeComparer);
  757. //业务分类
  758. List<dynamic> _ServiceClass = new List<dynamic>();
  759. List<Sys_SetData> ServiceClass = _sqlSugar.Queryable<Sys_SetData>()
  760. .Where(u => u.STid == 36 && u.IsDel == 0).ToList();
  761. foreach (Sys_SetData item in ServiceClass)
  762. {
  763. var data = new
  764. {
  765. Id = item.Id,
  766. Name = item.Name
  767. };
  768. _ServiceClass.Add(data);
  769. };
  770. #endregion
  771. var groupNumber = await QueryNumberGroups();
  772. if (NewClientDataView.Count > 0)
  773. {
  774. int count = NewClientDataView[0].countPage;
  775. float totalPage = (float)count / dto.PageSize;//总页数
  776. if (totalPage == 0) totalPage = 1;
  777. else totalPage = (int)Math.Ceiling((double)totalPage);
  778. if (dto.PortType == 1)
  779. {
  780. foreach (var item in NewClientDataView)
  781. {
  782. List<AscribedUser> AscribedUser = await _sqlSugar.SqlQueryable<AscribedUser>
  783. ("select u1.UsersId as UserId ,u2.CnName,u1.NewClientDataId from Crm_ClientDataAndUser u1,Sys_Users u2 where u1.UsersId=u2.Id and NewClientDataId=" + item.Id + " AND u1.ISDEL = 0").ToListAsync();
  784. item.AscribedUser = AscribedUser;
  785. List<AscribedDepartment> AscribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>
  786. ("select d2.Id,d2.Name,d1.NewClientDataId from Crm_ClientDataAndBusiness d1,Sys_SetData d2 where d1.SetDataId=d2.Id and NewClientDataId=" + item.Id + " AND d1.ISDEL = 0").ToListAsync();
  787. item.AscribedDepartment = AscribedDepartment;
  788. }
  789. var Data = new
  790. {
  791. ClientTableData = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = NewClientDataView },
  792. Users = _Users,
  793. Province = _Province,
  794. level = _level,
  795. CustomerClass = _CustomerClass,
  796. ServiceClass = _ServiceClass,
  797. groupNumber = groupNumber.Data,
  798. };
  799. return result = new Result()
  800. {
  801. Code = 0,
  802. Msg = "查询成功",
  803. Data = Data
  804. };
  805. }
  806. else if (dto.PortType == 2 || dto.PortType == 3)
  807. {
  808. List<NewClientDataAndroidIOSView> newClientDataIOSViews = new List<NewClientDataAndroidIOSView>();
  809. foreach (var item in NewClientDataView)
  810. {
  811. newClientDataIOSViews.Add(new NewClientDataAndroidIOSView()
  812. {
  813. RowNumber = item.RowNumber,
  814. Id = item.Id,
  815. Client = item.Client,
  816. Contact = item.Contact,
  817. Job = item.Job,
  818. Telephone = item.Telephone,
  819. Location = item.Location,
  820. });
  821. }
  822. result = new Result()
  823. {
  824. Code = 0,
  825. Msg = "查询成功",
  826. Data = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = newClientDataIOSViews },
  827. };
  828. }
  829. }
  830. else
  831. {
  832. if (dto.PortType == 2 || dto.PortType == 3)
  833. {
  834. var Data = new { pageCount = 0, totalPage = 0, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = NewClientDataView };
  835. result = new Result() { Code = 0, Msg = "获取成功!", Data = Data };
  836. }
  837. else
  838. {
  839. var Data = new
  840. {
  841. ClientTableData = new { pageCount = 0, totalPage = 0, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = NewClientDataView },
  842. Users = _Users,
  843. Province = _Province,
  844. level = _level,
  845. CustomerClass = _CustomerClass,
  846. ServiceClass = _ServiceClass,
  847. groupNumber = groupNumber.Data,
  848. };
  849. result = new Result() { Code = 0, Msg = "获取成功!", Data = Data };
  850. }
  851. }
  852. }
  853. catch (Exception ex)
  854. {
  855. result = new Result() { Code = -2, Msg = "未知错误" };
  856. }
  857. return result;
  858. }
  859. public Result QueryUserSelect()
  860. {
  861. Result result = new Result() { Code = -2, Msg = "未知错误" };
  862. try
  863. {
  864. //负责人下拉框
  865. List<dynamic> _Users = new List<dynamic>();
  866. List<Sys_Users> users = _sqlSugar.Queryable<Sys_Users>()
  867. .Where(u => u.IsDel == 0).ToList();
  868. foreach (Sys_Users user in users)
  869. {
  870. var data = new
  871. {
  872. Id = user.Id,
  873. Name = user.CnName
  874. };
  875. _Users.Add(data);
  876. };
  877. if (_Users.Count == 0)
  878. {
  879. result = new Result() { Code = -1, Msg = "暂无数据" };
  880. }
  881. result = new Result() { Code = 0, Msg = "查询成功!", Data = _Users };
  882. }
  883. catch (Exception)
  884. {
  885. result = new Result() { Code = -2, Msg = "未知错误" };
  886. }
  887. return result;
  888. }
  889. public async Task<Result> NewClientOp(NewClientOpDto dto)
  890. {
  891. Result result = new Result() { Code = -2, Msg = "未知错误" };
  892. bool istrue = false;
  893. int AddReturnId = -1;
  894. string BirthdayStr = string.Empty;
  895. if (!string.IsNullOrWhiteSpace(dto.Birthday))
  896. {
  897. DateTime Birthday = new DateTime();
  898. var isParse = DateTime.TryParse(dto.Birthday, out Birthday);
  899. BirthdayStr = isParse ? Birthday.ToString("yyyy-MM-dd") : "";
  900. }
  901. //if (string.IsNullOrWhiteSpace(dto.PassportDate))
  902. //{
  903. // dto.PassportDate = string.Empty;
  904. //}
  905. var newClientDataUnEncrypted = _mapper.Map<Crm_NewClientData>(dto);
  906. newClientDataUnEncrypted.Birthday = BirthdayStr;
  907. if (newClientDataUnEncrypted.PassportDate == DateTime.MinValue) newClientDataUnEncrypted.PassportDate = null;
  908. newClientDataUnEncrypted.LastUpdateTime = DateTime.Now;
  909. newClientDataUnEncrypted.LastUpdateUserId = dto.CreateUserId;
  910. var newClientDataEncrypted = newClientDataUnEncrypted;
  911. EncryptionProcessor.EncryptProperties(newClientDataEncrypted); //加密
  912. try
  913. {
  914. BeginTran();
  915. if (dto.Status == 1)//添加
  916. {
  917. string selectSql = string.Format(@"select * from Crm_NewClientData where Client='{0}' And Contact='{1}' And IsDel={2}"
  918. , newClientDataEncrypted.Client, newClientDataEncrypted.Contact, 0);
  919. var NewClientData = await _sqlSugar.SqlQueryable<Crm_NewClientData>(selectSql).FirstAsync();//查询是否存在
  920. if (NewClientData != null)
  921. {
  922. result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
  923. }
  924. int id = await AddAsyncReturnId(newClientDataEncrypted); //添加市场客户资料表数据
  925. if (id == 0)
  926. {
  927. result = new Result() { Code = -1, Msg = "添加失败!" };
  928. }
  929. else
  930. {
  931. result = new Result() { Code = 0, Msg = "添加成功!", Data = id };
  932. istrue = true;
  933. AddReturnId = id;
  934. newClientDataUnEncrypted.Id = id;
  935. }
  936. }
  937. else if (dto.Status == 2)//修改
  938. {
  939. //DateTime? PassportDate = null;
  940. //try
  941. //{
  942. // PassportDate = DateTime.Parse(dto.PassportDate);
  943. //}
  944. //catch (Exception)
  945. //{
  946. // PassportDate = null;
  947. //}
  948. var res = await _sqlSugar.Updateable(newClientDataEncrypted).IgnoreColumns(x => new { x.DeleteTime, x.DeleteUserId, x.CreateTime, x.CreateUserId }).ExecuteCommandAsync();
  949. if (res > 0)
  950. {
  951. istrue = true;
  952. AddReturnId = dto.Id == 0 ? -1 : dto.Id;
  953. if (AddReturnId != -1)
  954. {
  955. await _sqlSugar.Updateable<Crm_ClientDataAndUser>().Where(x=>x.NewClientDataId == AddReturnId).SetColumns(a => new Crm_ClientDataAndUser()
  956. {
  957. IsDel = 1,
  958. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  959. }).ExecuteCommandAsync();
  960. await _sqlSugar.Updateable<Crm_ClientDataAndBusiness>().Where(x => x.NewClientDataId == AddReturnId).SetColumns(a => new Crm_ClientDataAndBusiness()
  961. {
  962. IsDel = 1,
  963. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  964. }).ExecuteCommandAsync();
  965. }
  966. newClientDataUnEncrypted.Id = AddReturnId;
  967. result = new Result() { Code = 0, Msg = "修改成功!" };
  968. }
  969. else
  970. {
  971. result = new Result() { Code = -1, Msg = "修改失败!" };
  972. }
  973. }
  974. else
  975. {
  976. result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  977. }
  978. if (istrue)
  979. {
  980. Adds<Crm_ClientDataAndUser>(dto.AscribedUser.Select(x => new Crm_ClientDataAndUser
  981. {
  982. CreateTime = DateTime.Now,
  983. CreateUserId = dto.CreateUserId,
  984. IsDel = 0,
  985. NewClientDataId = AddReturnId,
  986. usersId = x
  987. }).ToList());
  988. Adds<Crm_ClientDataAndBusiness>(dto.AscribedDepartment.Select(x => new Crm_ClientDataAndBusiness
  989. {
  990. CreateUserId = dto.CreateUserId,
  991. IsDel = 0,
  992. CreateTime = DateTime.Now,
  993. NewClientDataId = AddReturnId,
  994. SetDataId = x,
  995. }).ToList());
  996. CommitTran();
  997. ////缓存添加信息
  998. //var optype = 0;
  999. //if (dto.Status == 1) optype = 3;
  1000. //else if (dto.Status == 2) optype = 4;
  1001. ////操作缓存(未加密数据)
  1002. //await NewClientDataRedis(optype, newClientDataUnEncrypted);
  1003. result.Data = AddReturnId;
  1004. }
  1005. else
  1006. {
  1007. RollbackTran();
  1008. }
  1009. }
  1010. catch (Exception)
  1011. {
  1012. RollbackTran();
  1013. result = new Result() { Code = -2, Msg = "未知错误" };
  1014. }
  1015. return result;
  1016. }
  1017. public async Task<Result> QueryNumberGroups()
  1018. {
  1019. Result result = new Result();
  1020. //preDeleAll 预计总量
  1021. //finlishedDeleAll 已出总量
  1022. DataTable preDeleAndfinlishedDeleAll = await GetDataTableAsync("select SUM(PreDele) as PreDeleAll ,SUM(FinlishedDele) as FinlishedDeleAll from Crm_NewClientData");
  1023. var preDeleAll = preDeleAndfinlishedDeleAll.Rows[0]["PreDeleAll"].ToString();
  1024. var finlishedDeleAll = preDeleAndfinlishedDeleAll.Rows[0]["finlishedDeleAll"].ToString();
  1025. result.Code = 0;
  1026. result.Msg = "成功!";
  1027. result.Data = new
  1028. {
  1029. preDeleAll,
  1030. finlishedDeleAll
  1031. };
  1032. return result;
  1033. }
  1034. /// <summary>
  1035. /// 获取下拉列表数据和单条数据信息
  1036. /// </summary>
  1037. /// <param name="dto"></param>
  1038. public async Task<Result> QuerySelectAndSingleData(QuerySingleDto dto)
  1039. {
  1040. Result rest = new Result();
  1041. //var QueryData1 = await NewClientDataRedis(2, new Crm_NewClientData() { Id = dto.Id });
  1042. //var QueryData = QueryData1.FirstOrDefault();
  1043. var QueryData = await _sqlSugar.Queryable<Crm_NewClientData>().Where(x => x.IsDel == 0 && x.Id == dto.Id).FirstAsync();
  1044. NewClientDataView MapQueryData = null;
  1045. if (QueryData != null)
  1046. {
  1047. EncryptionProcessor.DecryptProperties(QueryData);
  1048. MapQueryData = _mapper.Map<NewClientDataView>(QueryData);
  1049. MapQueryData.AscribedUser = await _sqlSugar.SqlQueryable<AscribedUser>
  1050. ("select u1.UsersId as UserId,u2.CnName,u1.NewClientDataId from Crm_ClientDataAndUser u1,Sys_Users u2 where u1.UsersId=u2.Id and NewClientDataId=" + dto.Id + " and u1.isdel = 0").ToListAsync();
  1051. MapQueryData.AscribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>
  1052. ("select d2.Id,d2.Name,d1.NewClientDataId from Crm_ClientDataAndBusiness d1,Sys_SetData d2 where d1.SetDataId=d2.Id and NewClientDataId=" + dto.Id + " and d1.isdel = 0").ToListAsync();
  1053. }
  1054. #region 下拉框初始化数据
  1055. //负责人下拉框
  1056. List<dynamic> _Users = new List<dynamic>();
  1057. List<Sys_Users> users = _sqlSugar.Queryable<Sys_Users>()
  1058. .Where(u => u.IsDel == 0).ToList();
  1059. foreach (Sys_Users user in users)
  1060. {
  1061. var data = new
  1062. {
  1063. Id = user.Id,
  1064. Name = user.CnName
  1065. };
  1066. _Users.Add(data);
  1067. };
  1068. //客户级别数据
  1069. List<dynamic> _level = new List<dynamic>();
  1070. List<Sys_SetData> level = _sqlSugar.Queryable<Sys_SetData>()
  1071. .Where(u => u.STid == 33 && u.IsDel == 0).ToList();
  1072. foreach (Sys_SetData item in level)
  1073. {
  1074. var data = new
  1075. {
  1076. Id = item.Id,
  1077. Name = item.Name
  1078. };
  1079. _level.Add(data);
  1080. };
  1081. //客户类别
  1082. ArrayList _CustomerClass = new ArrayList();
  1083. List<Sys_SetData> CustomerClass = _sqlSugar.Queryable<Sys_SetData>()
  1084. .Where(u => u.STid == 37 && u.IsDel == 0).ToList();
  1085. foreach (Sys_SetData item in CustomerClass)
  1086. {
  1087. var data = new
  1088. {
  1089. Id = item.Id,
  1090. Name = item.Name,
  1091. item.Remark
  1092. };
  1093. _CustomerClass.Add(data);
  1094. };
  1095. // 创建比较器实例
  1096. IComparer remakeComparer = new RemakeComparer();
  1097. _CustomerClass.Sort(remakeComparer);
  1098. //业务分类
  1099. List<dynamic> _ServiceClass = new List<dynamic>();
  1100. List<Sys_SetData> ServiceClass = _sqlSugar.Queryable<Sys_SetData>()
  1101. .Where(u => u.STid == 36 && u.IsDel == 0).ToList();
  1102. foreach (Sys_SetData item in ServiceClass)
  1103. {
  1104. var data = new
  1105. {
  1106. Id = item.Id,
  1107. Name = item.Name
  1108. };
  1109. _ServiceClass.Add(data);
  1110. };
  1111. #endregion
  1112. rest.Code = 0;
  1113. rest.Data = new
  1114. {
  1115. data = MapQueryData,
  1116. Users = _Users,
  1117. level = _level,
  1118. CustomerClass = _CustomerClass,
  1119. ServiceClass = _ServiceClass,
  1120. };
  1121. rest.Msg = "获取成功!";
  1122. return rest;
  1123. }
  1124. /// <summary>
  1125. /// 删除市场客户资料数据
  1126. /// </summary>
  1127. /// <param name="dto"></param>
  1128. /// <returns></returns>
  1129. public async Task<Result> DelNewClientData(DelBaseDto dto)
  1130. {
  1131. Result AcrionResult = new Result();
  1132. BeginTran();
  1133. var DBresult = await SoftDeleteByIdAsync<Crm_NewClientData>(dto.Id.ToString(), dto.DeleteUserId);
  1134. try
  1135. {
  1136. if (DBresult)
  1137. {
  1138. AcrionResult.Code = 0;
  1139. string sqlSet = $"isdel = 1, DeleteUserId = {dto.DeleteUserId} ,DeleteTime = '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}'";
  1140. string sql = $" update Crm_ClientDataAndUser set {sqlSet} where NewClientDataId = {dto.Id} ";
  1141. await ExecuteCommandAsync(sql);
  1142. sql = $" update Crm_ClientDataAndBusiness set {sqlSet} where NewClientDataId = {dto.Id} ";
  1143. await ExecuteCommandAsync(sql);
  1144. CommitTran();
  1145. //await NewClientDataRedis(5, new Crm_NewClientData() { Id = dto.Id });
  1146. AcrionResult.Code = 0;
  1147. }
  1148. }
  1149. catch (Exception ex)
  1150. {
  1151. RollbackTran();
  1152. AcrionResult.Msg = ex.Message;
  1153. AcrionResult.Code = -1;
  1154. }
  1155. return AcrionResult;
  1156. }
  1157. /// <summary>
  1158. /// 市场客户资料数据
  1159. /// 批量指派
  1160. /// </summary>
  1161. /// <param name="dto"></param>
  1162. /// <returns></returns>
  1163. public async Task<Result> _BatchAssignment(BatchAssignmentDto dto)
  1164. {
  1165. Result AcrionResult = new Result() { Code = -1,Msg="操作失败"};
  1166. if (dto.UserIdItem == null || dto.UserIdItem.Count < 1)
  1167. {
  1168. AcrionResult.Msg = "用户ID集合不能为空!";
  1169. return AcrionResult;
  1170. }
  1171. if (dto.ClientDataIdItem == null || dto.ClientDataIdItem.Count < 1)
  1172. {
  1173. AcrionResult.Msg = "客户资料ID集合不能为空!";
  1174. return AcrionResult;
  1175. }
  1176. List<Crm_ClientDataAndUser> _ClientDataAndUsers = new List<Crm_ClientDataAndUser>();
  1177. List<Crm_ClientDataAndUser> _ClientDataAndUsers1 = await _sqlSugar.Queryable<Crm_ClientDataAndUser>()
  1178. .Where(it =>
  1179. it.IsDel == 0 &&
  1180. dto.ClientDataIdItem.Contains(it.NewClientDataId) &&
  1181. dto.UserIdItem.Contains(it.usersId)
  1182. )
  1183. .ToListAsync();
  1184. var existsCount = 0;
  1185. foreach (var clientDataId in dto.ClientDataIdItem)
  1186. {
  1187. foreach (var userId1 in dto.UserIdItem)
  1188. {
  1189. Crm_ClientDataAndUser _ClientDataAndUsers2 = _ClientDataAndUsers1.Where(it => it.NewClientDataId == clientDataId &&
  1190. it.usersId == userId1
  1191. ).FirstOrDefault();
  1192. if (_ClientDataAndUsers2 == null)
  1193. {
  1194. _ClientDataAndUsers.Add(new Crm_ClientDataAndUser()
  1195. {
  1196. CreateUserId = dto.UserId,
  1197. NewClientDataId = clientDataId,
  1198. usersId = userId1
  1199. });
  1200. }
  1201. else
  1202. {
  1203. existsCount++;
  1204. }
  1205. }
  1206. }
  1207. if (_ClientDataAndUsers.Count > 0)
  1208. {
  1209. var adds = await _sqlSugar.Insertable(_ClientDataAndUsers).ExecuteCommandAsync();
  1210. if (adds > 0)
  1211. {
  1212. #region 客户资料表操作记录 批量添加
  1213. //List<Crm_TableOperationRecord> _TableOperationRecords = new List<Crm_TableOperationRecord>();
  1214. //foreach (var item in _ClientDataAndUsers)
  1215. //{
  1216. // _TableOperationRecords.Add(
  1217. // new Crm_TableOperationRecord() {
  1218. // TableName = "Crm_TableOperationRecord",
  1219. // PortType = dto.PortType,
  1220. // OperationItem = OperationEnum.BatchAssignment,
  1221. // DataId = item.NewClientDataId,
  1222. // CreateUserId = dto.UserId,
  1223. // CreateTime = DateTime.Now,
  1224. // Remark = "",
  1225. // IsDel = 0
  1226. // });
  1227. //}
  1228. //if (_TableOperationRecords.Count > 0)
  1229. //{
  1230. // await _sqlSugar.Insertable(_TableOperationRecords).ExecuteCommandAsync();
  1231. //}
  1232. #endregion
  1233. AcrionResult.Code = 0;
  1234. return AcrionResult;
  1235. }
  1236. }
  1237. else
  1238. {
  1239. if(existsCount > 0)
  1240. AcrionResult.Msg += $" {existsCount}条数据已被指派,无法重复指派!";
  1241. }
  1242. return AcrionResult;
  1243. }
  1244. public List<Sys_Users> GetNewExistClient(int userid)
  1245. {
  1246. string sql = "SELECT * FROM Sys_Users su where su.id in (\r\n\t select distinct usersid from Crm_ClientDataAndUser WHERE IsDel = 0 \r\n) \r\n";
  1247. var userArr = _sqlSugar.SqlQueryable<Sys_Users>(sql).ToList();
  1248. var dic = new Dictionary<int, int[]>()
  1249. {
  1250. { 95, new int []{ 95 , 337 , 302, 350, 355, 357, 353 } }
  1251. };
  1252. if (dic.Keys.Contains(userid))
  1253. {
  1254. return userArr.Where(x=> dic[userid].Contains(x.Id)).ToList();
  1255. }
  1256. return userArr;
  1257. }
  1258. /// <summary>
  1259. /// 客户资料
  1260. /// excel download
  1261. /// </summary>
  1262. /// <param name="dto"></param>
  1263. /// <returns></returns>
  1264. public async Task<List<NewClientDataExcelDownloadView>> NewClientDataExcelDownload(NewClientDataExcelDownloadDto dto)
  1265. {
  1266. var dt = new List<NewClientDataExcelDownloadView>();
  1267. try
  1268. {
  1269. #region 交集
  1270. List<int> NewClientDataId1 = new List<int>();
  1271. List<int> NewClientDataId2 = new List<int>();
  1272. int state = 0;
  1273. #region 负责人
  1274. if (dto.OperationUserId != 21)
  1275. {
  1276. if (string.IsNullOrWhiteSpace(dto.Userid))
  1277. {
  1278. dto.Userid = dto.OperationUserId.ToString();
  1279. }
  1280. }
  1281. if (!string.IsNullOrWhiteSpace(dto.Userid))
  1282. {
  1283. string sql = string.Format(@"select u1.UsersId as UserId,u2.CnName,u1.NewClientDataId from Crm_ClientDataAndUser u1,Sys_Users u2 where u1.UsersId=u2.Id and u1.UsersId in ({0}) and u1.IsDel = 0", dto.Userid);
  1284. List<AscribedUser> ascribedUsers = await _sqlSugar.SqlQueryable<AscribedUser>(sql).ToListAsync();
  1285. if (ascribedUsers.Count != 0)
  1286. {
  1287. foreach (var ascribedUser1 in ascribedUsers)
  1288. {
  1289. if (ascribedUser1.NewClientDataId != 0)
  1290. {
  1291. NewClientDataId1.Add(ascribedUser1.NewClientDataId);
  1292. }
  1293. }
  1294. }
  1295. else
  1296. {
  1297. dt = null;
  1298. }
  1299. state = -1;
  1300. }
  1301. #endregion
  1302. #region 业务归属
  1303. if (!string.IsNullOrWhiteSpace(dto.Business))
  1304. {
  1305. string sql = string.Format(@"select d2.Id,d2.Name,d1.NewClientDataId from Crm_ClientDataAndBusiness d1,Sys_SetData d2 where d1.SetDataId=d2.Id and d1.SetDataId in ({0}) and d1.isdel = 0", dto.Business);
  1306. List<AscribedDepartment> AscribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>(sql).ToListAsync();
  1307. if (AscribedDepartment.Count != 0)
  1308. {
  1309. foreach (var item in AscribedDepartment)
  1310. {
  1311. if (item.NewClientDataId != 0)
  1312. {
  1313. NewClientDataId2.Add(item.NewClientDataId);
  1314. }
  1315. }
  1316. }
  1317. else
  1318. {
  1319. dt = null;
  1320. }
  1321. state = -1;
  1322. }
  1323. #endregion
  1324. List<int> intList = new List<int>();
  1325. if (NewClientDataId1.Count != 0 && NewClientDataId2.Count != 0)
  1326. {
  1327. intList = NewClientDataId1.Intersect(NewClientDataId2).ToList();
  1328. }
  1329. else if (NewClientDataId1.Count != 0)
  1330. {
  1331. intList = NewClientDataId1;
  1332. }
  1333. else if (NewClientDataId2.Count != 0)
  1334. {
  1335. if (dto.OperationUserId == 21)
  1336. {
  1337. intList = NewClientDataId2;
  1338. }
  1339. }
  1340. if (state == -1)
  1341. {
  1342. if (intList.Count < 1) intList.Add(-1);
  1343. }
  1344. #endregion
  1345. #region 省域条件
  1346. var rangeSetDataList = new List<int>();
  1347. if (dto.Range != 0)
  1348. {
  1349. string setDataSql = "select * from Sys_SetData where STid = 33 and isdel = 0 ";
  1350. switch (dto.Range)
  1351. {
  1352. case 419:
  1353. setDataSql += " and (Name like '%四%川%' or Name like '%成%都%')";
  1354. break;
  1355. case 421:
  1356. setDataSql += " and (Name like '%贵%州%' or Name like '%贵%阳%')";
  1357. break;
  1358. case 420:
  1359. setDataSql += " and (Name like '%云%南%' or Name like '%昆%明%')";
  1360. break;
  1361. case 423:
  1362. setDataSql += " and (Name like '%重庆%')";
  1363. break;
  1364. case 422:
  1365. setDataSql += " and (Name like '%西%藏%' or Name like '%拉%萨%')";
  1366. break;
  1367. case 578:
  1368. setDataSql += " and (Name like '%青%海%' or Name like '%西%宁%')";
  1369. break;
  1370. case 605:
  1371. setDataSql += " and (Name like '%陕%西%' or Name like '%西%安%')";
  1372. break;
  1373. case 606:
  1374. setDataSql += " and (Name like '%宁%夏%' or Name like '%银%川%')";
  1375. break;
  1376. case 625:
  1377. setDataSql += " and (Name like '%甘%肃%' or Name like '%兰%州%')";
  1378. break;
  1379. case 634:
  1380. setDataSql += " and (Name like '%新%疆%' or Name like '%乌%鲁%木%齐%')";
  1381. break;
  1382. }
  1383. rangeSetDataList = _sqlSugar.SqlQueryable<Sys_SetData>(setDataSql).Select(x => x.Id).ToList();
  1384. }
  1385. #endregion
  1386. var NewClientDataView = new List<NewClientDataExcelDownloadView>();
  1387. //var count = 0;
  1388. string contact = dto.Contact, location = dto.Location, clientDto = dto.Client;
  1389. var isSelectSearch = false;
  1390. var searchDataIds = new List<int>();
  1391. if (string.IsNullOrEmpty(contact) || string.IsNullOrEmpty(location) || string.IsNullOrEmpty(clientDto))
  1392. {
  1393. isSelectSearch = true;
  1394. var searchClientDatas = await _sqlSugar.Queryable<Crm_NewClientData>()
  1395. .Where(x => x.IsDel == 0)
  1396. .Select(x => new Crm_NewClientData() { Id = x.Id, Client = x.Client, Location = x.Location, Contact = x.Contact })
  1397. .ToListAsync();
  1398. foreach (var item in searchClientDatas) EncryptionProcessor.DecryptProperties(item);
  1399. if (dto.PortType == 1)
  1400. {
  1401. searchDataIds = searchClientDatas
  1402. .WhereIF(!string.IsNullOrEmpty(contact), x => !string.IsNullOrEmpty(x.Contact) && x.Contact.Contains(contact)) //联系人条件
  1403. .WhereIF(!string.IsNullOrEmpty(location), x => !string.IsNullOrEmpty(x.Location) && x.Location.Contains(location)) //地区条件
  1404. .WhereIF(!string.IsNullOrEmpty(clientDto), x => !string.IsNullOrEmpty(x.Client) && x.Client.Contains(clientDto)) //单位条件
  1405. .Select(x => x.Id)
  1406. .ToList();
  1407. }
  1408. else if (dto.PortType == 2 || dto.PortType == 3)
  1409. {
  1410. searchDataIds = searchClientDatas
  1411. .Where(x => (!string.IsNullOrEmpty(x.Contact) && x.Contact.Contains(clientDto)) ||
  1412. (!string.IsNullOrEmpty(x.Location) && x.Location.Contains(clientDto)) ||
  1413. (!string.IsNullOrEmpty(x.Client) && x.Client.Contains(clientDto)))
  1414. .Select(x => x.Id)
  1415. .ToList();
  1416. }
  1417. if (searchDataIds.Count < 1) searchDataIds.Add(0);
  1418. }
  1419. var clientDatas = await _sqlSugar.Queryable<Crm_NewClientData>()
  1420. .Where(x => x.IsDel == 0)
  1421. .WhereIF(state == -1 && intList.Count > 0, x => intList.Contains(x.Id))
  1422. .WhereIF(dto.Lvlid != 0, x => x.Lvlid == dto.Lvlid) //地市州条件
  1423. .WhereIF(rangeSetDataList.Count > 0, x => rangeSetDataList.Contains(x.Lvlid)) //省域条件
  1424. .WhereIF(dto.Category > 0, x => x.Category == dto.Category) //客户类别
  1425. .WhereIF(isSelectSearch && searchDataIds.Count > 0, x => searchDataIds.Contains(x.Id)) //条件模糊查询
  1426. .OrderByDescending(x => x.CreateTime)
  1427. .ToListAsync();
  1428. NewClientDataView = _mapper.Map<List<NewClientDataExcelDownloadView>>(clientDatas);
  1429. if (!NewClientDataView.Any()) return dt;
  1430. var userDatas = await _sqlSugar.Queryable<Sys_Users>().ToListAsync();
  1431. var setDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0).ToListAsync();
  1432. var ascribedUser = await _sqlSugar.SqlQueryable<AscribedUser>
  1433. ("select u1.UsersId as UserId ,u2.CnName,u1.NewClientDataId from Crm_ClientDataAndUser u1,Sys_Users u2 where u1.UsersId=u2.Id AND u1.ISDEL = 0").ToListAsync();
  1434. var ascribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>
  1435. ("select d2.Id,d2.Name,d1.NewClientDataId from Crm_ClientDataAndBusiness d1,Sys_SetData d2 where d1.SetDataId=d2.Id AND d1.ISDEL = 0").ToListAsync();
  1436. int index = 1;
  1437. foreach (var item in NewClientDataView)
  1438. {
  1439. EncryptionProcessor.DecryptProperties(item); //解密
  1440. item.RowNumber = index;
  1441. item.CreateUserName = userDatas.Find(x => x.Id == item.CreateUserId)?.CnName ?? "-";
  1442. item.CategoryStr = setDatas.Find(x => x.Id == item.Category)?.Name ?? "-";
  1443. item.LvlidStr = setDatas.Find(x => x.Id == item.Lvlid)?.Name ?? "-";
  1444. var currAscribedUser = ascribedUser.Where(x => x.NewClientDataId == item.Id).ToList();
  1445. if (currAscribedUser.Any()) item.AscribedUserLable = string.Join("、", currAscribedUser.Select(x => x.CnName).ToList());
  1446. var currAscribedDepartment = ascribedDepartment.Where(x => x.NewClientDataId == item.Id).ToList();
  1447. if (currAscribedDepartment.Any()) item.AscribedDepartmentLable = string.Join("、", currAscribedDepartment.Select(x => x.Name).ToList());
  1448. index++;
  1449. }
  1450. return NewClientDataView;
  1451. }
  1452. catch (Exception ex)
  1453. {
  1454. return dt;
  1455. }
  1456. }
  1457. /// <summary>
  1458. /// 客户资料操作记录
  1459. /// </summary>
  1460. /// <param name="dto"></param>
  1461. /// <returns></returns>
  1462. public async Task<JsonView> NewClientDataRecord(NewClientDataRecordDto dto)
  1463. {
  1464. var jsonView = new JsonView();
  1465. string whereSql = string.Empty;
  1466. if (dto.UserId != 21) whereSql += string.Format(" AND tor.CreateUserId = '{0}'", dto.UserId);
  1467. else
  1468. {
  1469. if (!string.IsNullOrEmpty(dto.OpUserLabel))
  1470. {
  1471. var userIdArray = dto.OpUserLabel.Split(',')
  1472. .Select(userId =>
  1473. {
  1474. if (int.TryParse(userId, out int id)) return id;
  1475. else return -1;
  1476. })
  1477. .ToArray();
  1478. if (userIdArray.Any(x => x != -1)) whereSql += string.Format(" AND tor.CreateUserId IN ({0})", string.Join(",", userIdArray.Where(x => x != -1).ToList()));
  1479. }
  1480. }
  1481. if (!string.IsNullOrEmpty(dto.OpTypeLabel))
  1482. {
  1483. var enumArray = dto.OpTypeLabel.Split(',')
  1484. .Select(status =>
  1485. {
  1486. if (Enum.TryParse(status, out OperationEnum result)) return result;
  1487. else return default;
  1488. })
  1489. .ToList();
  1490. if (enumArray.Any())
  1491. {
  1492. if (enumArray.Contains(OperationEnum.List)) enumArray.Add(OperationEnum.NoOperation);
  1493. if (enumArray.Any()) whereSql += string.Format(" AND tor.OperationItem IN ({0})", string.Join(",", enumArray.Select(status => ((int)status).ToString())));
  1494. }
  1495. }
  1496. bool beginDateBool = DateTime.TryParse(dto.BeginTime,out _),
  1497. endDateBool = DateTime.TryParse(dto.EndTime,out _);
  1498. if (beginDateBool && endDateBool)
  1499. {
  1500. string beginLable = $"{dto.BeginTime} 00:00:00",
  1501. endLable = $"{dto.EndTime} 23:59:59";
  1502. whereSql += string.Format(" AND tor.CreateTime BETWEEN '{0}' AND '{1}'", beginLable, endLable);
  1503. }
  1504. string sql = string.Format(@"SELECT
  1505. row_number() OVER (
  1506. ORDER BY
  1507. tor.CreateTime DESC
  1508. ) 'RowNum',
  1509. tor.Id,
  1510. tor.PortType,
  1511. tor.OperationItem,
  1512. tor.DataId,
  1513. ncd.Client,
  1514. tor.CreateUserId,
  1515. u.CnName 'CreateUserName',
  1516. tor.CreateTime,
  1517. tor.UpdatePreData,
  1518. tor.UpdateBefData
  1519. FROM
  1520. OA2023DB.dbo.Crm_TableOperationRecord tor
  1521. LEFT JOIN sys_users u On tor.CreateUserId = u.Id
  1522. LEFT JOIN Crm_NewClientData ncd On tor.DataId = ncd.Id
  1523. Where
  1524. TableName = 'Crm_NewClientData'
  1525. {0}", whereSql);
  1526. RefAsync<int> total = 0;
  1527. var datas = await _sqlSugar.SqlQueryable<NewClientDataRecordInfoView>(sql).ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  1528. var viewData = datas.Select(x => new NewClientDataRecordView() { RowIndex = x.RowIndex, Label = x.Label, CreateTime = x.CreateTime }).ToList();
  1529. jsonView.Data = viewData;
  1530. jsonView.Code = 200;
  1531. jsonView.Count = total;
  1532. jsonView.Msg = "查询成功!";
  1533. return jsonView;
  1534. }
  1535. }
  1536. }