NewClientDataRepository.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  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. if (string.IsNullOrWhiteSpace(dto.PassportDate))
  382. {
  383. dto.PassportDate = null;
  384. }
  385. Crm_NewClientData _NewClientData = _mapper.Map<Crm_NewClientData>(dto);
  386. int id = await AddAsyncReturnId(_NewClientData); //添加市场客户资料表数据
  387. if (id == 0)
  388. {
  389. result = new Result() { Code = -1, Msg = "添加失败!" };
  390. }
  391. else
  392. {
  393. result = new Result() { Code = 0, Msg = "添加成功!"};
  394. istrue = true;
  395. AddReturnId = id;
  396. CommitTran();
  397. }
  398. }
  399. else
  400. {
  401. result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
  402. }
  403. }
  404. else if (dto.Status == 2)//修改
  405. {
  406. DateTime? PassportDate = null;
  407. try
  408. {
  409. PassportDate = DateTime.Parse(dto.PassportDate);
  410. }
  411. catch (Exception)
  412. {
  413. PassportDate = null;
  414. }
  415. DateTime Birthday = new DateTime();
  416. var isParse = DateTime.TryParse(dto.Birthday,out Birthday);
  417. string BirthdayStr = isParse ? Birthday.ToString("yyyy-MM-dd") : "";
  418. bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Crm_NewClientData
  419. {
  420. Number = dto.Number,
  421. Lvlid = dto.Lvlid,
  422. Client = dto.Client,
  423. Weight = dto.Weight,
  424. ClientShort = dto.Clientshort,
  425. Contact = dto.Contact,
  426. Gender = dto.Gender,
  427. Passport = dto.Passport,
  428. PassportDate = PassportDate,
  429. Job = dto.Job,
  430. Telephone = dto.Telephone,
  431. Phone = dto.Phone,
  432. Email = dto.Email,
  433. Location = dto.Location,
  434. Address = dto.Address,
  435. Birthday = BirthdayStr,
  436. OtherInfo = dto.Otherinfo,
  437. Wechat = dto.Wechat,
  438. Category = dto.Category,
  439. PreDele = dto.Predele,
  440. FinlishedDele = dto.FinlishedDele,
  441. Remark = dto.Remark,
  442. });
  443. if (res)
  444. {
  445. istrue = true;
  446. AddReturnId = dto.Id == 0 ? -1 : dto.Id;
  447. if (AddReturnId != -1)
  448. {
  449. await _sqlSugar.Updateable<Crm_ClientDataAndUser>().Where(x=>x.NewClientDataId == AddReturnId).SetColumns(a => new Crm_ClientDataAndUser()
  450. {
  451. IsDel = 1,
  452. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  453. }).ExecuteCommandAsync();
  454. await _sqlSugar.Updateable<Crm_ClientDataAndBusiness>().Where(x => x.NewClientDataId == AddReturnId).SetColumns(a => new Crm_ClientDataAndBusiness()
  455. {
  456. IsDel = 1,
  457. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  458. }).ExecuteCommandAsync();
  459. }
  460. result = new Result() { Code = 0, Msg = "修改成功!" };
  461. }
  462. else
  463. {
  464. result = new Result() { Code = -1, Msg = "修改失败!" };
  465. }
  466. }
  467. else
  468. {
  469. result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
  470. }
  471. if (istrue)
  472. {
  473. Adds<Crm_ClientDataAndUser>(dto.AscribedUser.Select(x => new Crm_ClientDataAndUser
  474. {
  475. CreateTime = DateTime.Now,
  476. CreateUserId = dto.CreateUserId,
  477. IsDel = 0,
  478. NewClientDataId = AddReturnId,
  479. usersId = x
  480. }).ToList());
  481. Adds<Crm_ClientDataAndBusiness>(dto.AscribedDepartment.Select(x => new Crm_ClientDataAndBusiness
  482. {
  483. CreateUserId = dto.CreateUserId,
  484. IsDel = 0,
  485. CreateTime = DateTime.Now,
  486. NewClientDataId = AddReturnId,
  487. SetDataId = x,
  488. }).ToList());
  489. CommitTran();
  490. result.Data = new { Id = AddReturnId };
  491. }
  492. else
  493. {
  494. RollbackTran();
  495. }
  496. }
  497. catch (Exception)
  498. {
  499. RollbackTran();
  500. result = new Result() { Code = -2, Msg = "未知错误" };
  501. }
  502. return result;
  503. }
  504. public async Task<Result> QueryNumberGroups()
  505. {
  506. Result result = new Result();
  507. //preDeleAll 预计总量
  508. //finlishedDeleAll 已出总量
  509. DataTable preDeleAndfinlishedDeleAll = await GetDataTableAsync("select SUM(PreDele) as PreDeleAll ,SUM(FinlishedDele) as FinlishedDeleAll from Crm_NewClientData");
  510. var preDeleAll = preDeleAndfinlishedDeleAll.Rows[0]["PreDeleAll"].ToString();
  511. var finlishedDeleAll = preDeleAndfinlishedDeleAll.Rows[0]["finlishedDeleAll"].ToString();
  512. result.Code = 0;
  513. result.Msg = "成功!";
  514. result.Data = new
  515. {
  516. preDeleAll,
  517. finlishedDeleAll
  518. };
  519. return result;
  520. }
  521. /// <summary>
  522. /// 获取下拉列表数据和单条数据信息
  523. /// </summary>
  524. /// <param name="dto"></param>
  525. public async Task<Result> QuerySelectAndSingleData(QuerySingleDto dto)
  526. {
  527. Result rest = new Result();
  528. var QueryData = await GetAsync<Crm_NewClientData>(x => x.Id == dto.Id);
  529. NewClientDataView MapQueryData = null;
  530. if (QueryData != null)
  531. {
  532. MapQueryData = _mapper.Map<NewClientDataView>(QueryData);
  533. MapQueryData.AscribedUser = await _sqlSugar.SqlQueryable<AscribedUser>
  534. ("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();
  535. MapQueryData.AscribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>
  536. ("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();
  537. }
  538. #region 下拉框初始化数据
  539. //负责人下拉框
  540. List<dynamic> _Users = new List<dynamic>();
  541. List<Sys_Users> users = _sqlSugar.Queryable<Sys_Users>()
  542. .Where(u => (u.CnName == "张海麟" || u.CnName == "安宁" || u.CnName == "李彩娟" || u.CnName == "舒庆" || u.CnName == "李媛媛") && u.IsDel == 0).ToList();
  543. foreach (Sys_Users user in users)
  544. {
  545. var data = new
  546. {
  547. Id = user.Id,
  548. Name = user.CnName
  549. };
  550. _Users.Add(data);
  551. };
  552. //客户级别数据
  553. List<dynamic> _level = new List<dynamic>();
  554. List<Sys_SetData> level = _sqlSugar.Queryable<Sys_SetData>()
  555. .Where(u => u.STid == 33 && u.IsDel == 0).ToList();
  556. foreach (Sys_SetData item in level)
  557. {
  558. var data = new
  559. {
  560. Id = item.Id,
  561. Name = item.Name
  562. };
  563. _level.Add(data);
  564. };
  565. //客户类别
  566. List<dynamic> _CustomerClass = new List<dynamic>();
  567. List<Sys_SetData> CustomerClass = _sqlSugar.Queryable<Sys_SetData>()
  568. .Where(u => u.STid == 37 && u.IsDel == 0).ToList();
  569. foreach (Sys_SetData item in CustomerClass)
  570. {
  571. var data = new
  572. {
  573. Id = item.Id,
  574. Name = item.Name
  575. };
  576. _CustomerClass.Add(data);
  577. };
  578. //业务分类
  579. List<dynamic> _ServiceClass = new List<dynamic>();
  580. List<Sys_SetData> ServiceClass = _sqlSugar.Queryable<Sys_SetData>()
  581. .Where(u => u.STid == 36 && u.IsDel == 0).ToList();
  582. foreach (Sys_SetData item in ServiceClass)
  583. {
  584. var data = new
  585. {
  586. Id = item.Id,
  587. Name = item.Name
  588. };
  589. _ServiceClass.Add(data);
  590. };
  591. #endregion
  592. rest.Code = 0;
  593. rest.Data = new
  594. {
  595. data = MapQueryData,
  596. Users = _Users,
  597. level = _level,
  598. CustomerClass = _CustomerClass,
  599. ServiceClass = _ServiceClass,
  600. };
  601. rest.Msg = "获取成功!";
  602. return rest;
  603. }
  604. /// <summary>
  605. /// 删除市场客户资料数据
  606. /// </summary>
  607. /// <param name="dto"></param>
  608. /// <returns></returns>
  609. public async Task<Result> DelNewClientData(DelBaseDto dto)
  610. {
  611. Result AcrionResult = new Result();
  612. BeginTran();
  613. var DBresult = await SoftDeleteByIdAsync<Crm_NewClientData>(dto.Id.ToString(), dto.DeleteUserId);
  614. try
  615. {
  616. if (DBresult)
  617. {
  618. AcrionResult.Code = 0;
  619. string sqlSet = $"isdel = 1, DeleteUserId = {dto.DeleteUserId} ,DeleteTime = '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}'";
  620. string sql = $" update Crm_ClientDataAndUser set {sqlSet} where NewClientDataId = {dto.Id} ";
  621. await ExecuteCommandAsync(sql);
  622. sql = $" update Crm_ClientDataAndBusiness set {sqlSet} where NewClientDataId = {dto.Id} ";
  623. await ExecuteCommandAsync(sql);
  624. CommitTran();
  625. AcrionResult.Code = 0;
  626. }
  627. }
  628. catch (Exception ex)
  629. {
  630. RollbackTran();
  631. AcrionResult.Msg = ex.Message;
  632. AcrionResult.Code = -1;
  633. }
  634. return AcrionResult;
  635. }
  636. }
  637. }