NewClientDataRepository.cs 74 KB

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