NewClientDataRepository.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. using AutoMapper;
  2. using AutoMapper.Execution;
  3. using MySqlX.XDevAPI.Relational;
  4. using OASystem.Domain;
  5. using OASystem.Domain.Dtos;
  6. using OASystem.Domain.Dtos.CRM;
  7. using OASystem.Domain.Entities.Customer;
  8. using OASystem.Domain.Entities.Resource;
  9. using OASystem.Domain.ViewModels.CRM;
  10. using SqlSugar;
  11. using System;
  12. using System.Collections;
  13. using System.Collections.Generic;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using System.Xml.Linq;
  18. using static OASystem.Domain.Dtos.CRM.NewClientDataQueryDto;
  19. namespace OASystem.Infrastructure.Repositories.CRM
  20. {
  21. public class NewClientDataRepository : BaseRepository<Crm_NewClientData, NewClientDataView>
  22. {
  23. private readonly IMapper _mapper;
  24. public NewClientDataRepository(SqlSugarClient sqlSugar, IMapper mapper) :
  25. base(sqlSugar)
  26. {
  27. _mapper = mapper;
  28. }
  29. /// <summary>
  30. /// 客户资料初识初始化
  31. /// </summary>
  32. /// <param name="dto"></param>
  33. /// <returns></returns>
  34. public async Task<Result> QueryNewClientData(NewClientDataQueryDto dto)
  35. {
  36. Result result = new Result() { Code = -2, Msg = "未知错误" };
  37. try
  38. {
  39. #region 交集
  40. List<int> NewClientDataId1 = new List<int>();
  41. List<int> NewClientDataId2 = new List<int>();
  42. string NewClientDataId = "";
  43. int state = 0;
  44. #region 负责人
  45. if (!string.IsNullOrWhiteSpace(dto.Userid))
  46. {
  47. 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);
  48. List<AscribedUser> ascribedUsers = await _sqlSugar.SqlQueryable<AscribedUser>(sql).ToListAsync();
  49. if (ascribedUsers.Count != 0)
  50. {
  51. foreach (var ascribedUser in ascribedUsers)
  52. {
  53. if (ascribedUser.NewClientDataId != 0)
  54. {
  55. NewClientDataId1.Add(ascribedUser.NewClientDataId);
  56. }
  57. }
  58. }
  59. else
  60. {
  61. result = new Result() { Code = -1, Msg = "暂无数据" };
  62. }
  63. state = -1;
  64. }
  65. #endregion
  66. #region 业务归属
  67. if (!string.IsNullOrWhiteSpace(dto.Business))
  68. {
  69. 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);
  70. List<AscribedDepartment> AscribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>(sql).ToListAsync();
  71. if (AscribedDepartment.Count != 0)
  72. {
  73. foreach (var item in AscribedDepartment)
  74. {
  75. if (item.NewClientDataId != 0)
  76. {
  77. NewClientDataId2.Add(item.NewClientDataId);
  78. }
  79. }
  80. }
  81. else
  82. {
  83. result = new Result() { Code = -1, Msg = "暂无数据" };
  84. }
  85. state = -1;
  86. }
  87. #endregion
  88. List<int> intList = new List<int>();
  89. if (NewClientDataId1.Count != 0 && NewClientDataId2.Count != 0)
  90. {
  91. intList = NewClientDataId1.Intersect(NewClientDataId2).ToList();
  92. }
  93. else if (NewClientDataId1.Count != 0)
  94. {
  95. intList = NewClientDataId1;
  96. }
  97. else if (NewClientDataId2.Count != 0)
  98. {
  99. intList = NewClientDataId2;
  100. }
  101. #endregion
  102. foreach (var item in intList)
  103. {
  104. NewClientDataId += item + ",";
  105. }
  106. if (!string.IsNullOrWhiteSpace(NewClientDataId))
  107. {
  108. NewClientDataId = NewClientDataId.Substring(0, NewClientDataId.Length - 1);
  109. }
  110. string sqlWhere = string.Empty;
  111. #region 联系人条件
  112. if (!string.IsNullOrWhiteSpace(dto.Contact))
  113. {
  114. sqlWhere += string.Format(@" And s.Contact like '%{0}%'", dto.Contact);
  115. }
  116. #endregion
  117. #region 地区条件
  118. if (!string.IsNullOrWhiteSpace(dto.Location))
  119. {
  120. sqlWhere += string.Format(@" And s.Location like '%{0}%'", dto.Location);
  121. }
  122. #endregion
  123. #region 单位条件
  124. if (!string.IsNullOrWhiteSpace(dto.Client))
  125. {
  126. sqlWhere += string.Format(@" And s.Client like '%{0}%'", dto.Client);
  127. }
  128. #endregion
  129. if (state == -1)
  130. {
  131. if (string.IsNullOrWhiteSpace(NewClientDataId))
  132. {
  133. NewClientDataId = "0";
  134. }
  135. sqlWhere += string.Format(@" And s.Id in({0})", NewClientDataId);
  136. }
  137. #region 地市州条件
  138. if (dto.Lvlid != 0)
  139. {
  140. sqlWhere += string.Format(@" And s.Lvlid={0}", dto.Lvlid);
  141. }
  142. #endregion
  143. #region 省域条件
  144. if (dto.Range != 0)
  145. {
  146. string setDataSql = "select * from Sys_SetData where STid = 33 and isdel = 0 ";
  147. switch (dto.Range)
  148. {
  149. case 419:
  150. setDataSql += " and (Name like '%四%川%' or Name like '%成%都%')";
  151. break;
  152. case 421:
  153. setDataSql += " and (Name like '%贵%州%' or Name like '%贵%阳%')";
  154. break;
  155. case 420:
  156. setDataSql += " and (Name like '%云%南%' or Name like '%昆%明%')";
  157. break;
  158. case 423:
  159. setDataSql += " and (Name like '%重庆%')";
  160. break;
  161. case 422:
  162. setDataSql += " and (Name like '%西%藏%' or Name like '%拉%萨%')";
  163. break;
  164. case 578:
  165. setDataSql += " and (Name like '%青%海%' or Name like '%西%宁%')";
  166. break;
  167. case 605:
  168. setDataSql += " and (Name like '%陕%西%' or Name like '%西%安%')";
  169. break;
  170. case 606:
  171. setDataSql += " and (Name like '%宁%夏%' or Name like '%银%川%')";
  172. break;
  173. case 625:
  174. setDataSql += " and (Name like '%甘%肃%' or Name like '%兰%州%')";
  175. break;
  176. case 634:
  177. setDataSql += " and (Name like '%新%疆%' or Name like '%乌%鲁%木%齐%')";
  178. break;
  179. }
  180. var RangeSetDataList = _sqlSugar.SqlQueryable<Sys_SetData>(setDataSql).Select(x => x.Id).ToList();
  181. string lvlds = string.Join(',', RangeSetDataList).TrimEnd(',');
  182. if (!string.IsNullOrEmpty(lvlds))
  183. {
  184. sqlWhere += string.Format(@" And s.Lvlid in ({0}) ", lvlds);
  185. }
  186. }
  187. #endregion
  188. #region 客户类别
  189. if (dto.Category != 0)
  190. {
  191. sqlWhere += string.Format(@" And s.Category = {0}", dto.Category);
  192. }
  193. #endregion
  194. sqlWhere += string.Format(@" And s.Lvlid=s1.Id And s.IsDel={0} ", 0);
  195. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  196. {
  197. Regex r = new Regex("And");
  198. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  199. }
  200. int pIndex = dto.PageIndex * dto.PageSize - dto.PageSize + 1;
  201. int pSize = dto.PageIndex * dto.PageSize;
  202. 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()
  203. 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
  204. RowNumber between {1} and {2} ", sqlWhere, pIndex, pSize);
  205. List<NewClientDataView> NewClientDataView = await _sqlSugar.SqlQueryable<NewClientDataView>(sqlNew).ToListAsync();
  206. foreach (var item in NewClientDataView)
  207. {
  208. Sys_SetData CategoryStr = _sqlSugar.Queryable<Sys_SetData>().Single(it => it.Id == item.Category);
  209. item.CategoryStr = CategoryStr != null ? CategoryStr.Name : null;
  210. Sys_SetData lvlStr = _sqlSugar.Queryable<Sys_SetData>().Single(it => it.Id == item.Lvlid);
  211. item.LvlidStr = lvlStr != null ? lvlStr.Name : null;
  212. }
  213. if (NewClientDataView.Count > 0)
  214. {
  215. int count = NewClientDataView[0].countPage;
  216. float totalPage = (float)count / dto.PageSize;//总页数
  217. if (totalPage == 0) totalPage = 1;
  218. else totalPage = (int)Math.Ceiling((double)totalPage);
  219. if (dto.PortType == 1)
  220. {
  221. #region 下拉框初始化数据
  222. //负责人下拉框
  223. List<dynamic> _Users = new List<dynamic>();
  224. List<Sys_Users> users = _sqlSugar.Queryable<Sys_Users>()
  225. .Where(u => (u.CnName == "张海麟" || u.CnName == "安宁" || u.CnName == "李彩娟" || u.CnName == "舒庆" || u.CnName == "李媛媛") && u.IsDel == 0).ToList();
  226. foreach (Sys_Users user in users)
  227. {
  228. var data = new
  229. {
  230. Id = user.Id,
  231. Name = user.CnName
  232. };
  233. _Users.Add(data);
  234. };
  235. //省域数据
  236. List<dynamic> _Province = new List<dynamic>();
  237. List<Sys_SetData> province = _sqlSugar.Queryable<Sys_SetData>()
  238. .Where(u => u.STid == 42 && u.IsDel == 0).ToList();
  239. foreach (Sys_SetData item in province)
  240. {
  241. var data = new
  242. {
  243. Id = item.Id,
  244. Name = item.Name
  245. };
  246. _Province.Add(data);
  247. };
  248. //客户级别数据
  249. List<dynamic> _level = new List<dynamic>();
  250. List<Sys_SetData> level = _sqlSugar.Queryable<Sys_SetData>()
  251. .Where(u => u.STid == 33 && u.IsDel == 0).ToList();
  252. foreach (Sys_SetData item in level)
  253. {
  254. var data = new
  255. {
  256. Id = item.Id,
  257. Name = item.Name
  258. };
  259. _level.Add(data);
  260. };
  261. //客户类别
  262. List<dynamic> _CustomerClass = new List<dynamic>();
  263. List<Sys_SetData> CustomerClass = _sqlSugar.Queryable<Sys_SetData>()
  264. .Where(u => u.STid == 37 && u.IsDel == 0).ToList();
  265. foreach (Sys_SetData item in CustomerClass)
  266. {
  267. var data = new
  268. {
  269. Id = item.Id,
  270. Name = item.Name
  271. };
  272. _CustomerClass.Add(data);
  273. };
  274. //业务分类
  275. List<dynamic> _ServiceClass = new List<dynamic>();
  276. List<Sys_SetData> ServiceClass = _sqlSugar.Queryable<Sys_SetData>()
  277. .Where(u => u.STid == 36 && u.IsDel == 0).ToList();
  278. foreach (Sys_SetData item in ServiceClass)
  279. {
  280. var data = new
  281. {
  282. Id = item.Id,
  283. Name = item.Name
  284. };
  285. _ServiceClass.Add(data);
  286. };
  287. #endregion
  288. foreach (var item in NewClientDataView)
  289. {
  290. List<AscribedUser> AscribedUser = await _sqlSugar.SqlQueryable<AscribedUser>
  291. ("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();
  292. item.AscribedUser = AscribedUser;
  293. List<AscribedDepartment> AscribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>
  294. ("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();
  295. item.AscribedDepartment = AscribedDepartment;
  296. }
  297. var groupNumber = await QueryNumberGroups();
  298. var Data = new
  299. {
  300. ClientTableData = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = NewClientDataView },
  301. Users = _Users,
  302. Province = _Province,
  303. level = _level,
  304. CustomerClass = _CustomerClass,
  305. ServiceClass = _ServiceClass,
  306. groupNumber = groupNumber.Data,
  307. };
  308. return result = new Result()
  309. {
  310. Code = 0,
  311. Msg = "查询成功",
  312. Data = Data
  313. };
  314. }
  315. else if (dto.PortType == 2)
  316. {
  317. result = new Result()
  318. {
  319. Code = 0,
  320. Msg = "查询成功",
  321. Data = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = NewClientDataView },
  322. };
  323. }
  324. }
  325. else
  326. {
  327. result = new Result() { Code = -1, Msg = "暂无数据!" };
  328. }
  329. }
  330. catch (Exception ex)
  331. {
  332. result = new Result() { Code = -2, Msg = "未知错误" };
  333. }
  334. return result;
  335. }
  336. public Result QueryUserSelect()
  337. {
  338. Result result = new Result() { Code = -2, Msg = "未知错误" };
  339. try
  340. {
  341. //负责人下拉框
  342. List<dynamic> _Users = new List<dynamic>();
  343. List<Sys_Users> users = _sqlSugar.Queryable<Sys_Users>()
  344. .Where(u => (u.CnName == "张海麟" || u.CnName == "安宁" || u.CnName == "李彩娟" || u.CnName == "舒庆" || u.CnName == "李媛媛") && u.IsDel == 0).ToList();
  345. foreach (Sys_Users user in users)
  346. {
  347. var data = new
  348. {
  349. Id = user.Id,
  350. Name = user.CnName
  351. };
  352. _Users.Add(data);
  353. };
  354. if (_Users.Count == 0)
  355. {
  356. result = new Result() { Code = -1, Msg = "暂无数据" };
  357. }
  358. result = new Result() { Code = 0, Msg = "查询成功!", Data = _Users };
  359. }
  360. catch (Exception)
  361. {
  362. result = new Result() { Code = -2, Msg = "未知错误" };
  363. }
  364. return result;
  365. }
  366. public async Task<Result> NewClientOp(NewClientOpDto dto)
  367. {
  368. Result result = new Result() { Code = -2, Msg = "未知错误" };
  369. bool istrue = false;
  370. int AddReturnId = -1;
  371. try
  372. {
  373. BeginTran();
  374. if (dto.Status == 1)//添加
  375. {
  376. string selectSql = string.Format(@"select * from Crm_NewClientData where Client='{0}' And Contact='{1}' And IsDel={2}"
  377. , dto.Client, dto.Contact, 0);
  378. var NewClientData = await _sqlSugar.SqlQueryable<Crm_NewClientData>(selectSql).FirstAsync();//查询是否存在
  379. if (NewClientData == null)
  380. {
  381. Crm_NewClientData _NewClientData = _mapper.Map<Crm_NewClientData>(dto);
  382. int id = await AddAsyncReturnId(_NewClientData); //添加市场客户资料表数据
  383. if (id == 0)
  384. {
  385. result = new Result() { Code = -1, Msg = "添加失败!" };
  386. }
  387. else
  388. {
  389. result = new Result() { Code = 0, Msg = "添加成功!"};
  390. istrue = true;
  391. AddReturnId = id;
  392. CommitTran();
  393. }
  394. }
  395. else
  396. {
  397. result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
  398. }
  399. }
  400. else if (dto.Status == 2)//修改
  401. {
  402. DateTime? PassportDate = null;
  403. try
  404. {
  405. PassportDate = DateTime.Parse(dto.PassportDate);
  406. }
  407. catch (Exception)
  408. {
  409. PassportDate = null;
  410. }
  411. DateTime Birthday = new DateTime();
  412. var isParse = DateTime.TryParse(dto.Birthday,out Birthday);
  413. string BirthdayStr = isParse ? Birthday.ToString("yyyy-MM-dd") : "";
  414. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Crm_NewClientData
  415. {
  416. Number = dto.Number,
  417. Lvlid = dto.Lvlid,
  418. Client = dto.Client,
  419. Weight = dto.Weight,
  420. ClientShort = dto.Clientshort,
  421. Contact = dto.Contact,
  422. Gender = dto.Gender,
  423. Passport = dto.Passport,
  424. PassportDate = PassportDate,
  425. Job = dto.Job,
  426. Telephone = dto.Telephone,
  427. Phone = dto.Phone,
  428. Email = dto.Email,
  429. Location = dto.Location,
  430. Address = dto.Address,
  431. Birthday = BirthdayStr,
  432. OtherInfo = dto.Otherinfo,
  433. Wechat = dto.Wechat,
  434. Category = dto.Category,
  435. PreDele = dto.Predele,
  436. FinlishedDele = dto.FinlishedDele,
  437. Remark = dto.Remark,
  438. });
  439. if (res)
  440. {
  441. istrue = true;
  442. AddReturnId = dto.Id == 0 ? -1 : dto.Id;
  443. if (AddReturnId != -1)
  444. {
  445. await _sqlSugar.Updateable<Crm_ClientDataAndUser>().Where(x=>x.NewClientDataId == AddReturnId).SetColumns(a => new Crm_ClientDataAndUser()
  446. {
  447. IsDel = 1,
  448. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  449. }).ExecuteCommandAsync();
  450. await _sqlSugar.Updateable<Crm_ClientDataAndBusiness>().Where(x => x.NewClientDataId == AddReturnId).SetColumns(a => new Crm_ClientDataAndBusiness()
  451. {
  452. IsDel = 1,
  453. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  454. }).ExecuteCommandAsync();
  455. }
  456. result = new Result() { Code = 0, Msg = "修改成功!" };
  457. }
  458. else
  459. {
  460. result = new Result() { Code = -1, Msg = "修改失败!" };
  461. }
  462. }
  463. else
  464. {
  465. result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  466. }
  467. if (istrue)
  468. {
  469. Adds<Crm_ClientDataAndUser>(dto.AscribedUser.Select(x => new Crm_ClientDataAndUser
  470. {
  471. CreateTime = DateTime.Now,
  472. CreateUserId = dto.CreateUserId,
  473. IsDel = 0,
  474. NewClientDataId = AddReturnId,
  475. usersId = x
  476. }).ToList());
  477. Adds<Crm_ClientDataAndBusiness>(dto.AscribedDepartment.Select(x => new Crm_ClientDataAndBusiness
  478. {
  479. CreateUserId = dto.CreateUserId,
  480. IsDel = 0,
  481. CreateTime = DateTime.Now,
  482. NewClientDataId = AddReturnId,
  483. SetDataId = x,
  484. }).ToList());
  485. CommitTran();
  486. result.Data = new { Id = AddReturnId };
  487. }
  488. else
  489. {
  490. RollbackTran();
  491. }
  492. }
  493. catch (Exception)
  494. {
  495. RollbackTran();
  496. result = new Result() { Code = -2, Msg = "未知错误" };
  497. }
  498. return result;
  499. }
  500. public async Task<Result> QueryNumberGroups()
  501. {
  502. Result result = new Result();
  503. //preDeleAll 预计总量
  504. //finlishedDeleAll 已出总量
  505. DataTable preDeleAndfinlishedDeleAll = await GetDataTableAsync("select SUM(PreDele) as PreDeleAll ,SUM(FinlishedDele) as FinlishedDeleAll from Crm_NewClientData");
  506. var preDeleAll = preDeleAndfinlishedDeleAll.Rows[0]["PreDeleAll"].ToString();
  507. var finlishedDeleAll = preDeleAndfinlishedDeleAll.Rows[0]["finlishedDeleAll"].ToString();
  508. result.Code = 0;
  509. result.Msg = "成功!";
  510. result.Data = new
  511. {
  512. preDeleAll,
  513. finlishedDeleAll
  514. };
  515. return result;
  516. }
  517. /// <summary>
  518. /// 获取下拉列表数据和单条数据信息
  519. /// </summary>
  520. /// <param name="dto"></param>
  521. public async Task<Result> QuerySelectAndSingleData(QuerySingleDto dto)
  522. {
  523. Result rest = new Result();
  524. var QueryData = await GetAsync<Crm_NewClientData>(x => x.Id == dto.Id);
  525. NewClientDataView MapQueryData = null;
  526. if (QueryData != null)
  527. {
  528. MapQueryData = _mapper.Map<NewClientDataView>(QueryData);
  529. MapQueryData.AscribedUser = await _sqlSugar.SqlQueryable<AscribedUser>
  530. ("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();
  531. MapQueryData.AscribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>
  532. ("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();
  533. }
  534. #region 下拉框初始化数据
  535. //负责人下拉框
  536. List<dynamic> _Users = new List<dynamic>();
  537. List<Sys_Users> users = _sqlSugar.Queryable<Sys_Users>()
  538. .Where(u => (u.CnName == "张海麟" || u.CnName == "安宁" || u.CnName == "李彩娟" || u.CnName == "舒庆" || u.CnName == "李媛媛") && u.IsDel == 0).ToList();
  539. foreach (Sys_Users user in users)
  540. {
  541. var data = new
  542. {
  543. Id = user.Id,
  544. Name = user.CnName
  545. };
  546. _Users.Add(data);
  547. };
  548. //客户级别数据
  549. List<dynamic> _level = new List<dynamic>();
  550. List<Sys_SetData> level = _sqlSugar.Queryable<Sys_SetData>()
  551. .Where(u => u.STid == 33 && u.IsDel == 0).ToList();
  552. foreach (Sys_SetData item in level)
  553. {
  554. var data = new
  555. {
  556. Id = item.Id,
  557. Name = item.Name
  558. };
  559. _level.Add(data);
  560. };
  561. //客户类别
  562. List<dynamic> _CustomerClass = new List<dynamic>();
  563. List<Sys_SetData> CustomerClass = _sqlSugar.Queryable<Sys_SetData>()
  564. .Where(u => u.STid == 37 && u.IsDel == 0).ToList();
  565. foreach (Sys_SetData item in CustomerClass)
  566. {
  567. var data = new
  568. {
  569. Id = item.Id,
  570. Name = item.Name
  571. };
  572. _CustomerClass.Add(data);
  573. };
  574. //业务分类
  575. List<dynamic> _ServiceClass = new List<dynamic>();
  576. List<Sys_SetData> ServiceClass = _sqlSugar.Queryable<Sys_SetData>()
  577. .Where(u => u.STid == 36 && u.IsDel == 0).ToList();
  578. foreach (Sys_SetData item in ServiceClass)
  579. {
  580. var data = new
  581. {
  582. Id = item.Id,
  583. Name = item.Name
  584. };
  585. _ServiceClass.Add(data);
  586. };
  587. #endregion
  588. rest.Code = 0;
  589. rest.Data = new
  590. {
  591. data = MapQueryData,
  592. Users = _Users,
  593. level = _level,
  594. CustomerClass = _CustomerClass,
  595. ServiceClass = _ServiceClass,
  596. };
  597. rest.Msg = "获取成功!";
  598. return rest;
  599. }
  600. /// <summary>
  601. /// 删除市场客户资料数据
  602. /// </summary>
  603. /// <param name="dto"></param>
  604. /// <returns></returns>
  605. public async Task<Result> DelNewClientData(DelBaseDto dto)
  606. {
  607. Result AcrionResult = new Result();
  608. BeginTran();
  609. var DBresult = await SoftDeleteByIdAsync<Crm_NewClientData>(dto.Id.ToString(), dto.DeleteUserId);
  610. try
  611. {
  612. if (DBresult)
  613. {
  614. AcrionResult.Code = 0;
  615. string sqlSet = $"isdel = 1, DeleteUserId = {dto.DeleteUserId} ,DeleteTime = '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}'";
  616. string sql = $" update Crm_ClientDataAndUser set {sqlSet} where NewClientDataId = {dto.Id} ";
  617. await ExecuteCommandAsync(sql);
  618. sql = $" update Crm_ClientDataAndBusiness set {sqlSet} where NewClientDataId = {dto.Id} ";
  619. await ExecuteCommandAsync(sql);
  620. CommitTran();
  621. AcrionResult.Code = 0;
  622. }
  623. }
  624. catch (Exception ex)
  625. {
  626. RollbackTran();
  627. AcrionResult.Msg = ex.Message;
  628. AcrionResult.Code = -1;
  629. }
  630. return AcrionResult;
  631. }
  632. }
  633. }