NewClientDataRepository.cs 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723
  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. var newClientDataEncrypted = newClientDataUnEncrypted;
  909. EncryptionProcessor.EncryptProperties(newClientDataEncrypted); //加密
  910. try
  911. {
  912. BeginTran();
  913. if (dto.Status == 1)//添加
  914. {
  915. string selectSql = string.Format(@"select * from Crm_NewClientData where Client='{0}' And Contact='{1}' And IsDel={2}"
  916. , newClientDataEncrypted.Client, newClientDataEncrypted.Contact, 0);
  917. var NewClientData = await _sqlSugar.SqlQueryable<Crm_NewClientData>(selectSql).FirstAsync();//查询是否存在
  918. if (NewClientData != null)
  919. {
  920. result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
  921. }
  922. int id = await AddAsyncReturnId(newClientDataEncrypted); //添加市场客户资料表数据
  923. if (id == 0)
  924. {
  925. result = new Result() { Code = -1, Msg = "添加失败!" };
  926. }
  927. else
  928. {
  929. result = new Result() { Code = 0, Msg = "添加成功!", Data = id };
  930. istrue = true;
  931. AddReturnId = id;
  932. newClientDataUnEncrypted.Id = id;
  933. }
  934. }
  935. else if (dto.Status == 2)//修改
  936. {
  937. //DateTime? PassportDate = null;
  938. //try
  939. //{
  940. // PassportDate = DateTime.Parse(dto.PassportDate);
  941. //}
  942. //catch (Exception)
  943. //{
  944. // PassportDate = null;
  945. //}
  946. var res = await _sqlSugar.Updateable(newClientDataEncrypted).IgnoreColumns(x => new { x.DeleteTime, x.DeleteUserId, x.CreateTime, x.CreateUserId }).ExecuteCommandAsync();
  947. if (res > 0)
  948. {
  949. istrue = true;
  950. AddReturnId = dto.Id == 0 ? -1 : dto.Id;
  951. if (AddReturnId != -1)
  952. {
  953. await _sqlSugar.Updateable<Crm_ClientDataAndUser>().Where(x=>x.NewClientDataId == AddReturnId).SetColumns(a => new Crm_ClientDataAndUser()
  954. {
  955. IsDel = 1,
  956. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  957. }).ExecuteCommandAsync();
  958. await _sqlSugar.Updateable<Crm_ClientDataAndBusiness>().Where(x => x.NewClientDataId == AddReturnId).SetColumns(a => new Crm_ClientDataAndBusiness()
  959. {
  960. IsDel = 1,
  961. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  962. }).ExecuteCommandAsync();
  963. }
  964. newClientDataUnEncrypted.Id = AddReturnId;
  965. result = new Result() { Code = 0, Msg = "修改成功!" };
  966. }
  967. else
  968. {
  969. result = new Result() { Code = -1, Msg = "修改失败!" };
  970. }
  971. }
  972. else
  973. {
  974. result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  975. }
  976. if (istrue)
  977. {
  978. Adds<Crm_ClientDataAndUser>(dto.AscribedUser.Select(x => new Crm_ClientDataAndUser
  979. {
  980. CreateTime = DateTime.Now,
  981. CreateUserId = dto.CreateUserId,
  982. IsDel = 0,
  983. NewClientDataId = AddReturnId,
  984. usersId = x
  985. }).ToList());
  986. Adds<Crm_ClientDataAndBusiness>(dto.AscribedDepartment.Select(x => new Crm_ClientDataAndBusiness
  987. {
  988. CreateUserId = dto.CreateUserId,
  989. IsDel = 0,
  990. CreateTime = DateTime.Now,
  991. NewClientDataId = AddReturnId,
  992. SetDataId = x,
  993. }).ToList());
  994. CommitTran();
  995. ////缓存添加信息
  996. //var optype = 0;
  997. //if (dto.Status == 1) optype = 3;
  998. //else if (dto.Status == 2) optype = 4;
  999. ////操作缓存(未加密数据)
  1000. //await NewClientDataRedis(optype, newClientDataUnEncrypted);
  1001. result.Data = AddReturnId;
  1002. }
  1003. else
  1004. {
  1005. RollbackTran();
  1006. }
  1007. }
  1008. catch (Exception)
  1009. {
  1010. RollbackTran();
  1011. result = new Result() { Code = -2, Msg = "未知错误" };
  1012. }
  1013. return result;
  1014. }
  1015. public async Task<Result> QueryNumberGroups()
  1016. {
  1017. Result result = new Result();
  1018. //preDeleAll 预计总量
  1019. //finlishedDeleAll 已出总量
  1020. DataTable preDeleAndfinlishedDeleAll = await GetDataTableAsync("select SUM(PreDele) as PreDeleAll ,SUM(FinlishedDele) as FinlishedDeleAll from Crm_NewClientData");
  1021. var preDeleAll = preDeleAndfinlishedDeleAll.Rows[0]["PreDeleAll"].ToString();
  1022. var finlishedDeleAll = preDeleAndfinlishedDeleAll.Rows[0]["finlishedDeleAll"].ToString();
  1023. result.Code = 0;
  1024. result.Msg = "成功!";
  1025. result.Data = new
  1026. {
  1027. preDeleAll,
  1028. finlishedDeleAll
  1029. };
  1030. return result;
  1031. }
  1032. /// <summary>
  1033. /// 获取下拉列表数据和单条数据信息
  1034. /// </summary>
  1035. /// <param name="dto"></param>
  1036. public async Task<Result> QuerySelectAndSingleData(QuerySingleDto dto)
  1037. {
  1038. Result rest = new Result();
  1039. //var QueryData1 = await NewClientDataRedis(2, new Crm_NewClientData() { Id = dto.Id });
  1040. //var QueryData = QueryData1.FirstOrDefault();
  1041. var QueryData = await _sqlSugar.Queryable<Crm_NewClientData>().Where(x => x.IsDel == 0 && x.Id == dto.Id).FirstAsync();
  1042. NewClientDataView MapQueryData = null;
  1043. if (QueryData != null)
  1044. {
  1045. EncryptionProcessor.DecryptProperties(QueryData);
  1046. MapQueryData = _mapper.Map<NewClientDataView>(QueryData);
  1047. MapQueryData.AscribedUser = await _sqlSugar.SqlQueryable<AscribedUser>
  1048. ("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();
  1049. MapQueryData.AscribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>
  1050. ("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();
  1051. }
  1052. #region 下拉框初始化数据
  1053. //负责人下拉框
  1054. List<dynamic> _Users = new List<dynamic>();
  1055. List<Sys_Users> users = _sqlSugar.Queryable<Sys_Users>()
  1056. .Where(u => u.IsDel == 0).ToList();
  1057. foreach (Sys_Users user in users)
  1058. {
  1059. var data = new
  1060. {
  1061. Id = user.Id,
  1062. Name = user.CnName
  1063. };
  1064. _Users.Add(data);
  1065. };
  1066. //客户级别数据
  1067. List<dynamic> _level = new List<dynamic>();
  1068. List<Sys_SetData> level = _sqlSugar.Queryable<Sys_SetData>()
  1069. .Where(u => u.STid == 33 && u.IsDel == 0).ToList();
  1070. foreach (Sys_SetData item in level)
  1071. {
  1072. var data = new
  1073. {
  1074. Id = item.Id,
  1075. Name = item.Name
  1076. };
  1077. _level.Add(data);
  1078. };
  1079. //客户类别
  1080. ArrayList _CustomerClass = new ArrayList();
  1081. List<Sys_SetData> CustomerClass = _sqlSugar.Queryable<Sys_SetData>()
  1082. .Where(u => u.STid == 37 && u.IsDel == 0).ToList();
  1083. foreach (Sys_SetData item in CustomerClass)
  1084. {
  1085. var data = new
  1086. {
  1087. Id = item.Id,
  1088. Name = item.Name,
  1089. item.Remark
  1090. };
  1091. _CustomerClass.Add(data);
  1092. };
  1093. // 创建比较器实例
  1094. IComparer remakeComparer = new RemakeComparer();
  1095. _CustomerClass.Sort(remakeComparer);
  1096. //业务分类
  1097. List<dynamic> _ServiceClass = new List<dynamic>();
  1098. List<Sys_SetData> ServiceClass = _sqlSugar.Queryable<Sys_SetData>()
  1099. .Where(u => u.STid == 36 && u.IsDel == 0).ToList();
  1100. foreach (Sys_SetData item in ServiceClass)
  1101. {
  1102. var data = new
  1103. {
  1104. Id = item.Id,
  1105. Name = item.Name
  1106. };
  1107. _ServiceClass.Add(data);
  1108. };
  1109. #endregion
  1110. rest.Code = 0;
  1111. rest.Data = new
  1112. {
  1113. data = MapQueryData,
  1114. Users = _Users,
  1115. level = _level,
  1116. CustomerClass = _CustomerClass,
  1117. ServiceClass = _ServiceClass,
  1118. };
  1119. rest.Msg = "获取成功!";
  1120. return rest;
  1121. }
  1122. /// <summary>
  1123. /// 删除市场客户资料数据
  1124. /// </summary>
  1125. /// <param name="dto"></param>
  1126. /// <returns></returns>
  1127. public async Task<Result> DelNewClientData(DelBaseDto dto)
  1128. {
  1129. Result AcrionResult = new Result();
  1130. BeginTran();
  1131. var DBresult = await SoftDeleteByIdAsync<Crm_NewClientData>(dto.Id.ToString(), dto.DeleteUserId);
  1132. try
  1133. {
  1134. if (DBresult)
  1135. {
  1136. AcrionResult.Code = 0;
  1137. string sqlSet = $"isdel = 1, DeleteUserId = {dto.DeleteUserId} ,DeleteTime = '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}'";
  1138. string sql = $" update Crm_ClientDataAndUser set {sqlSet} where NewClientDataId = {dto.Id} ";
  1139. await ExecuteCommandAsync(sql);
  1140. sql = $" update Crm_ClientDataAndBusiness set {sqlSet} where NewClientDataId = {dto.Id} ";
  1141. await ExecuteCommandAsync(sql);
  1142. CommitTran();
  1143. //await NewClientDataRedis(5, new Crm_NewClientData() { Id = dto.Id });
  1144. AcrionResult.Code = 0;
  1145. }
  1146. }
  1147. catch (Exception ex)
  1148. {
  1149. RollbackTran();
  1150. AcrionResult.Msg = ex.Message;
  1151. AcrionResult.Code = -1;
  1152. }
  1153. return AcrionResult;
  1154. }
  1155. /// <summary>
  1156. /// 市场客户资料数据
  1157. /// 批量指派
  1158. /// </summary>
  1159. /// <param name="dto"></param>
  1160. /// <returns></returns>
  1161. public async Task<Result> _BatchAssignment(BatchAssignmentDto dto)
  1162. {
  1163. Result AcrionResult = new Result() { Code = -1,Msg="操作失败"};
  1164. if (dto.UserIdItem == null || dto.UserIdItem.Count < 1)
  1165. {
  1166. AcrionResult.Msg = "用户ID集合不能为空!";
  1167. return AcrionResult;
  1168. }
  1169. if (dto.ClientDataIdItem == null || dto.ClientDataIdItem.Count < 1)
  1170. {
  1171. AcrionResult.Msg = "客户资料ID集合不能为空!";
  1172. return AcrionResult;
  1173. }
  1174. List<Crm_ClientDataAndUser> _ClientDataAndUsers = new List<Crm_ClientDataAndUser>();
  1175. List<Crm_ClientDataAndUser> _ClientDataAndUsers1 = await _sqlSugar.Queryable<Crm_ClientDataAndUser>()
  1176. .Where(it =>
  1177. it.IsDel == 0 &&
  1178. dto.ClientDataIdItem.Contains(it.NewClientDataId) &&
  1179. dto.UserIdItem.Contains(it.usersId)
  1180. )
  1181. .ToListAsync();
  1182. var existsCount = 0;
  1183. foreach (var clientDataId in dto.ClientDataIdItem)
  1184. {
  1185. foreach (var userId1 in dto.UserIdItem)
  1186. {
  1187. Crm_ClientDataAndUser _ClientDataAndUsers2 = _ClientDataAndUsers1.Where(it => it.NewClientDataId == clientDataId &&
  1188. it.usersId == userId1
  1189. ).FirstOrDefault();
  1190. if (_ClientDataAndUsers2 == null)
  1191. {
  1192. _ClientDataAndUsers.Add(new Crm_ClientDataAndUser()
  1193. {
  1194. CreateUserId = dto.UserId,
  1195. NewClientDataId = clientDataId,
  1196. usersId = userId1
  1197. });
  1198. }
  1199. else
  1200. {
  1201. existsCount++;
  1202. }
  1203. }
  1204. }
  1205. if (_ClientDataAndUsers.Count > 0)
  1206. {
  1207. var adds = await _sqlSugar.Insertable(_ClientDataAndUsers).ExecuteCommandAsync();
  1208. if (adds > 0)
  1209. {
  1210. #region 客户资料表操作记录 批量添加
  1211. //List<Crm_TableOperationRecord> _TableOperationRecords = new List<Crm_TableOperationRecord>();
  1212. //foreach (var item in _ClientDataAndUsers)
  1213. //{
  1214. // _TableOperationRecords.Add(
  1215. // new Crm_TableOperationRecord() {
  1216. // TableName = "Crm_TableOperationRecord",
  1217. // PortType = dto.PortType,
  1218. // OperationItem = OperationEnum.BatchAssignment,
  1219. // DataId = item.NewClientDataId,
  1220. // CreateUserId = dto.UserId,
  1221. // CreateTime = DateTime.Now,
  1222. // Remark = "",
  1223. // IsDel = 0
  1224. // });
  1225. //}
  1226. //if (_TableOperationRecords.Count > 0)
  1227. //{
  1228. // await _sqlSugar.Insertable(_TableOperationRecords).ExecuteCommandAsync();
  1229. //}
  1230. #endregion
  1231. AcrionResult.Code = 0;
  1232. return AcrionResult;
  1233. }
  1234. }
  1235. else
  1236. {
  1237. if(existsCount > 0)
  1238. AcrionResult.Msg += $" {existsCount}条数据已被指派,无法重复指派!";
  1239. }
  1240. return AcrionResult;
  1241. }
  1242. public List<Sys_Users> GetNewExistClient(int userid)
  1243. {
  1244. 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";
  1245. var userArr = _sqlSugar.SqlQueryable<Sys_Users>(sql).ToList();
  1246. var dic = new Dictionary<int, int[]>()
  1247. {
  1248. { 95, new int []{ 95 , 337 , 302, 350, 355, 357, 353 } }
  1249. };
  1250. if (dic.Keys.Contains(userid))
  1251. {
  1252. return userArr.Where(x=> dic[userid].Contains(x.Id)).ToList();
  1253. }
  1254. return userArr;
  1255. }
  1256. /// <summary>
  1257. /// 客户资料
  1258. /// excel download
  1259. /// </summary>
  1260. /// <param name="dto"></param>
  1261. /// <returns></returns>
  1262. public async Task<List<NewClientDataExcelDownloadView>> NewClientDataExcelDownload(NewClientDataExcelDownloadDto dto)
  1263. {
  1264. var dt = new List<NewClientDataExcelDownloadView>();
  1265. try
  1266. {
  1267. #region 交集
  1268. List<int> NewClientDataId1 = new List<int>();
  1269. List<int> NewClientDataId2 = new List<int>();
  1270. int state = 0;
  1271. #region 负责人
  1272. if (dto.OperationUserId != 21)
  1273. {
  1274. if (string.IsNullOrWhiteSpace(dto.Userid))
  1275. {
  1276. dto.Userid = dto.OperationUserId.ToString();
  1277. }
  1278. }
  1279. if (!string.IsNullOrWhiteSpace(dto.Userid))
  1280. {
  1281. 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);
  1282. List<AscribedUser> ascribedUsers = await _sqlSugar.SqlQueryable<AscribedUser>(sql).ToListAsync();
  1283. if (ascribedUsers.Count != 0)
  1284. {
  1285. foreach (var ascribedUser1 in ascribedUsers)
  1286. {
  1287. if (ascribedUser1.NewClientDataId != 0)
  1288. {
  1289. NewClientDataId1.Add(ascribedUser1.NewClientDataId);
  1290. }
  1291. }
  1292. }
  1293. else
  1294. {
  1295. dt = null;
  1296. }
  1297. state = -1;
  1298. }
  1299. #endregion
  1300. #region 业务归属
  1301. if (!string.IsNullOrWhiteSpace(dto.Business))
  1302. {
  1303. 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);
  1304. List<AscribedDepartment> AscribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>(sql).ToListAsync();
  1305. if (AscribedDepartment.Count != 0)
  1306. {
  1307. foreach (var item in AscribedDepartment)
  1308. {
  1309. if (item.NewClientDataId != 0)
  1310. {
  1311. NewClientDataId2.Add(item.NewClientDataId);
  1312. }
  1313. }
  1314. }
  1315. else
  1316. {
  1317. dt = null;
  1318. }
  1319. state = -1;
  1320. }
  1321. #endregion
  1322. List<int> intList = new List<int>();
  1323. if (NewClientDataId1.Count != 0 && NewClientDataId2.Count != 0)
  1324. {
  1325. intList = NewClientDataId1.Intersect(NewClientDataId2).ToList();
  1326. }
  1327. else if (NewClientDataId1.Count != 0)
  1328. {
  1329. intList = NewClientDataId1;
  1330. }
  1331. else if (NewClientDataId2.Count != 0)
  1332. {
  1333. if (dto.OperationUserId == 21)
  1334. {
  1335. intList = NewClientDataId2;
  1336. }
  1337. }
  1338. if (state == -1)
  1339. {
  1340. if (intList.Count < 1) intList.Add(-1);
  1341. }
  1342. #endregion
  1343. #region 省域条件
  1344. var rangeSetDataList = new List<int>();
  1345. if (dto.Range != 0)
  1346. {
  1347. string setDataSql = "select * from Sys_SetData where STid = 33 and isdel = 0 ";
  1348. switch (dto.Range)
  1349. {
  1350. case 419:
  1351. setDataSql += " and (Name like '%四%川%' or Name like '%成%都%')";
  1352. break;
  1353. case 421:
  1354. setDataSql += " and (Name like '%贵%州%' or Name like '%贵%阳%')";
  1355. break;
  1356. case 420:
  1357. setDataSql += " and (Name like '%云%南%' or Name like '%昆%明%')";
  1358. break;
  1359. case 423:
  1360. setDataSql += " and (Name like '%重庆%')";
  1361. break;
  1362. case 422:
  1363. setDataSql += " and (Name like '%西%藏%' or Name like '%拉%萨%')";
  1364. break;
  1365. case 578:
  1366. setDataSql += " and (Name like '%青%海%' or Name like '%西%宁%')";
  1367. break;
  1368. case 605:
  1369. setDataSql += " and (Name like '%陕%西%' or Name like '%西%安%')";
  1370. break;
  1371. case 606:
  1372. setDataSql += " and (Name like '%宁%夏%' or Name like '%银%川%')";
  1373. break;
  1374. case 625:
  1375. setDataSql += " and (Name like '%甘%肃%' or Name like '%兰%州%')";
  1376. break;
  1377. case 634:
  1378. setDataSql += " and (Name like '%新%疆%' or Name like '%乌%鲁%木%齐%')";
  1379. break;
  1380. }
  1381. rangeSetDataList = _sqlSugar.SqlQueryable<Sys_SetData>(setDataSql).Select(x => x.Id).ToList();
  1382. }
  1383. #endregion
  1384. var NewClientDataView = new List<NewClientDataExcelDownloadView>();
  1385. //var count = 0;
  1386. string contact = dto.Contact, location = dto.Location, clientDto = dto.Client;
  1387. var isSelectSearch = false;
  1388. var searchDataIds = new List<int>();
  1389. if (string.IsNullOrEmpty(contact) || string.IsNullOrEmpty(location) || string.IsNullOrEmpty(clientDto))
  1390. {
  1391. isSelectSearch = true;
  1392. var searchClientDatas = await _sqlSugar.Queryable<Crm_NewClientData>()
  1393. .Where(x => x.IsDel == 0)
  1394. .Select(x => new Crm_NewClientData() { Id = x.Id, Client = x.Client, Location = x.Location, Contact = x.Contact })
  1395. .ToListAsync();
  1396. foreach (var item in searchClientDatas) EncryptionProcessor.DecryptProperties(item);
  1397. if (dto.PortType == 1)
  1398. {
  1399. searchDataIds = searchClientDatas
  1400. .WhereIF(!string.IsNullOrEmpty(contact), x => !string.IsNullOrEmpty(x.Contact) && x.Contact.Contains(contact)) //联系人条件
  1401. .WhereIF(!string.IsNullOrEmpty(location), x => !string.IsNullOrEmpty(x.Location) && x.Location.Contains(location)) //地区条件
  1402. .WhereIF(!string.IsNullOrEmpty(clientDto), x => !string.IsNullOrEmpty(x.Client) && x.Client.Contains(clientDto)) //单位条件
  1403. .Select(x => x.Id)
  1404. .ToList();
  1405. }
  1406. else if (dto.PortType == 2 || dto.PortType == 3)
  1407. {
  1408. searchDataIds = searchClientDatas
  1409. .Where(x => (!string.IsNullOrEmpty(x.Contact) && x.Contact.Contains(clientDto)) ||
  1410. (!string.IsNullOrEmpty(x.Location) && x.Location.Contains(clientDto)) ||
  1411. (!string.IsNullOrEmpty(x.Client) && x.Client.Contains(clientDto)))
  1412. .Select(x => x.Id)
  1413. .ToList();
  1414. }
  1415. if (searchDataIds.Count < 1) searchDataIds.Add(0);
  1416. }
  1417. var clientDatas = await _sqlSugar.Queryable<Crm_NewClientData>()
  1418. .Where(x => x.IsDel == 0)
  1419. .WhereIF(state == -1 && intList.Count > 0, x => intList.Contains(x.Id))
  1420. .WhereIF(dto.Lvlid != 0, x => x.Lvlid == dto.Lvlid) //地市州条件
  1421. .WhereIF(rangeSetDataList.Count > 0, x => rangeSetDataList.Contains(x.Lvlid)) //省域条件
  1422. .WhereIF(dto.Category > 0, x => x.Category == dto.Category) //客户类别
  1423. .WhereIF(isSelectSearch && searchDataIds.Count > 0, x => searchDataIds.Contains(x.Id)) //条件模糊查询
  1424. .OrderByDescending(x => x.CreateTime)
  1425. .ToListAsync();
  1426. NewClientDataView = _mapper.Map<List<NewClientDataExcelDownloadView>>(clientDatas);
  1427. if (!NewClientDataView.Any()) return dt;
  1428. var userDatas = await _sqlSugar.Queryable<Sys_Users>().ToListAsync();
  1429. var setDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0).ToListAsync();
  1430. var ascribedUser = await _sqlSugar.SqlQueryable<AscribedUser>
  1431. ("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();
  1432. var ascribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>
  1433. ("select d2.Id,d2.Name,d1.NewClientDataId from Crm_ClientDataAndBusiness d1,Sys_SetData d2 where d1.SetDataId=d2.Id AND d1.ISDEL = 0").ToListAsync();
  1434. int index = 1;
  1435. foreach (var item in NewClientDataView)
  1436. {
  1437. EncryptionProcessor.DecryptProperties(item); //解密
  1438. item.RowNumber = index;
  1439. item.CreateUserName = userDatas.Find(x => x.Id == item.CreateUserId)?.CnName ?? "-";
  1440. item.CategoryStr = setDatas.Find(x => x.Id == item.Category)?.Name ?? "-";
  1441. item.LvlidStr = setDatas.Find(x => x.Id == item.Lvlid)?.Name ?? "-";
  1442. var currAscribedUser = ascribedUser.Where(x => x.NewClientDataId == item.Id).ToList();
  1443. if (currAscribedUser.Any()) item.AscribedUserLable = string.Join("、", currAscribedUser.Select(x => x.CnName).ToList());
  1444. var currAscribedDepartment = ascribedDepartment.Where(x => x.NewClientDataId == item.Id).ToList();
  1445. if (currAscribedDepartment.Any()) item.AscribedDepartmentLable = string.Join("、", currAscribedDepartment.Select(x => x.Name).ToList());
  1446. index++;
  1447. }
  1448. return NewClientDataView;
  1449. }
  1450. catch (Exception ex)
  1451. {
  1452. return dt;
  1453. }
  1454. }
  1455. /// <summary>
  1456. /// 客户资料操作记录
  1457. /// </summary>
  1458. /// <param name="dto"></param>
  1459. /// <returns></returns>
  1460. public async Task<JsonView> NewClientDataRecord(NewClientDataRecordDto dto)
  1461. {
  1462. var jsonView = new JsonView();
  1463. string whereSql = string.Empty;
  1464. if (dto.UserId != 21) whereSql += string.Format(" AND tor.CreateUserId = '{0}'", dto.UserId);
  1465. else
  1466. {
  1467. if (!string.IsNullOrEmpty(dto.OpUserLabel))
  1468. {
  1469. var userIdArray = dto.OpUserLabel.Split(',')
  1470. .Select(userId =>
  1471. {
  1472. if (int.TryParse(userId, out int id)) return id;
  1473. else return -1;
  1474. })
  1475. .ToArray();
  1476. if (userIdArray.Any(x => x != -1)) whereSql += string.Format(" AND tor.CreateUserId IN ({0})", string.Join(",", userIdArray.Where(x => x != -1).ToList()));
  1477. }
  1478. }
  1479. if (!string.IsNullOrEmpty(dto.OpTypeLabel))
  1480. {
  1481. var enumArray = dto.OpTypeLabel.Split(',')
  1482. .Select(status =>
  1483. {
  1484. if (Enum.TryParse(status, out OperationEnum result)) return result;
  1485. else return default;
  1486. })
  1487. .ToList();
  1488. if (enumArray.Any())
  1489. {
  1490. if (enumArray.Contains(OperationEnum.List)) enumArray.Add(OperationEnum.NoOperation);
  1491. if (enumArray.Any()) whereSql += string.Format(" AND tor.OperationItem IN ({0})", string.Join(",", enumArray.Select(status => ((int)status).ToString())));
  1492. }
  1493. }
  1494. bool beginDateBool = DateTime.TryParse(dto.BeginTime,out _),
  1495. endDateBool = DateTime.TryParse(dto.EndTime,out _);
  1496. if (beginDateBool && endDateBool)
  1497. {
  1498. string beginLable = $"{dto.BeginTime} 00:00:00",
  1499. endLable = $"{dto.EndTime} 23:59:59";
  1500. whereSql += string.Format(" AND tor.CreateTime BETWEEN '{0}' AND '{1}'", beginLable, endLable);
  1501. }
  1502. string sql = string.Format(@"SELECT
  1503. row_number() OVER (
  1504. ORDER BY
  1505. tor.CreateTime DESC
  1506. ) 'RowNum',
  1507. tor.Id,
  1508. tor.PortType,
  1509. tor.OperationItem,
  1510. tor.DataId,
  1511. ncd.Client,
  1512. tor.CreateUserId,
  1513. u.CnName 'CreateUserName',
  1514. tor.CreateTime,
  1515. tor.UpdatePreData,
  1516. tor.UpdateBefData
  1517. FROM
  1518. OA2023DB.dbo.Crm_TableOperationRecord tor
  1519. LEFT JOIN sys_users u On tor.CreateUserId = u.Id
  1520. LEFT JOIN Crm_NewClientData ncd On tor.DataId = ncd.Id
  1521. Where
  1522. TableName = 'Crm_NewClientData'
  1523. {0}", whereSql);
  1524. RefAsync<int> total = 0;
  1525. var datas = await _sqlSugar.SqlQueryable<NewClientDataRecordInfoView>(sql).ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  1526. var viewData = datas.Select(x => new NewClientDataRecordView() { RowIndex = x.RowIndex, Label = x.Label, CreateTime = x.CreateTime }).ToList();
  1527. jsonView.Data = viewData;
  1528. jsonView.Code = 200;
  1529. jsonView.Count = total;
  1530. jsonView.Msg = "查询成功!";
  1531. return jsonView;
  1532. }
  1533. }
  1534. }