NewClientDataRepository.cs 74 KB

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