UserRepository.cs 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net.Http;
  5. using System.Threading.Tasks;
  6. using AutoMapper;
  7. using GxPress.Common.Extensions;
  8. using GxPress.Common.AppOptions;
  9. using GxPress.Common.Exceptions;
  10. using GxPress.Common.Page;
  11. using GxPress.Common.Tools;
  12. using GxPress.Entity;
  13. using GxPress.EnumConst;
  14. using GxPress.Repository.Interface;
  15. using GxPress.Request.User;
  16. using GxPress.Result.User;
  17. using Microsoft.AspNetCore.Hosting;
  18. using Microsoft.Extensions.Options;
  19. using Newtonsoft.Json;
  20. using SqlKata;
  21. using SS.Mail.Core;
  22. using Datory;
  23. using Microsoft.Extensions.Caching.Distributed;
  24. using Dapper;
  25. using GxPress.Result.App.User;
  26. using GxPress.Result.Job;
  27. using GxPress.Common.Http;
  28. using GxPress.Repository.Interface.DepartmentUser;
  29. namespace GxPress.Repository.Implement
  30. {
  31. public class UserRepository : IUserRepository
  32. {
  33. private readonly Repository<User> _repository;
  34. private readonly Repository<Department> _departmentRepository;
  35. private readonly Repository<Role> _roleRepository;
  36. private readonly IMapper _mapper;
  37. private readonly IWebHostEnvironment _environment;
  38. private readonly IDistributedCache _cache;
  39. //private readonly string _connectionString;
  40. //private readonly string _databaseTypestr;
  41. private readonly string _connectionString;
  42. private readonly string _databaseTypeStr;
  43. private readonly IDepartmentUserRepository departmentUserRepository;
  44. public UserRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor, IMapper mapper,
  45. IWebHostEnvironment environment, IDistributedCache cache, IDepartmentUserRepository departmentUserRepository)
  46. {
  47. _databaseTypeStr = dbOptionsAccessor.CurrentValue.DatabaseType;
  48. _connectionString = dbOptionsAccessor.CurrentValue.ConnectionString;
  49. // _databaseType
  50. // str = dbOptionsAccessor.CurrentValue.DatabaseType;
  51. var databaseType =
  52. StringUtils.ToEnum<DatabaseType>(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql);
  53. //_connectionString = dbOptionsAccessor.CurrentValue.ConnectionString;
  54. var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
  55. _repository = new Repository<User>(database);
  56. _environment = environment;
  57. _departmentRepository = new Repository<Department>(database);
  58. _roleRepository = new Repository<Role>(database);
  59. _mapper = mapper;
  60. _cache = cache;
  61. this.departmentUserRepository = departmentUserRepository;
  62. }
  63. public IDatabase Database => _repository.Database;
  64. public string TableName => _repository.TableName;
  65. public List<TableColumn> TableColumns => _repository.TableColumns;
  66. /// <summary>
  67. /// 根据id集合查询用户
  68. /// </summary>
  69. /// <param name="ids"></param>
  70. /// <returns></returns>
  71. public async Task<IEnumerable<User>> UserListInsAsync(List<int> ids)
  72. {
  73. return await _repository.GetAllAsync(Q.WhereIn(nameof(User.Id), ids).Where(nameof(User.IsDelete), false));
  74. }
  75. /// <summary>
  76. /// 根据姓名查询用户
  77. /// </summary>
  78. /// <param name="name"></param>
  79. /// <returns></returns>
  80. public async Task<IEnumerable<UserInfoResult>> UserByNameAsync(string name)
  81. {
  82. var result = await _repository.GetAllAsync(Q.WhereLike(nameof(User.Name), $"%{name}%").Where(nameof(User.IsDelete), false));
  83. foreach (var item in result)
  84. item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
  85. return result.Select(n => _mapper.Map<UserInfoResult>(n));
  86. }
  87. public async Task<UserDetail> GetDetailAsync(int id)
  88. {
  89. var user = await GetAsync(id);
  90. user.QRCoder = StringUtils.AddDomain(user.QRCoder);
  91. user.AvatarUrl = StringUtils.AddDomainMin(user.AvatarUrl);
  92. if (!string.IsNullOrEmpty(user.HistoryAvatarUrl))
  93. user.HistoryAvatarUrl = StringUtils.AddDomain(user.HistoryAvatarUrl);
  94. var userDetail = _mapper.Map<UserDetail>(user);
  95. // if (user.DepartmentId > 0)
  96. // {
  97. // var department = await _departmentRepository.GetAsync(user.DepartmentId);
  98. // userDetail.DepartmentName = department.Name;
  99. // }
  100. return userDetail;
  101. }
  102. public async Task<int> GetUserCount(string beginTime, string endTime)
  103. {
  104. return await _repository.CountAsync(Q.WhereDate(nameof(User.CreatedDate), ">=", beginTime).WhereDate(nameof(User.CreatedDate), "<=", endTime).Where(nameof(User.IsDelete), false));
  105. }
  106. public async Task<User> GetAsync(int id)
  107. {
  108. var user = await _repository.GetAsync(Q.Where(nameof(User.Id), id).Where(nameof(User.IsDelete), false));
  109. return user;
  110. }
  111. public async Task<UserInfoResult> GetUserInfoAsync(int id)
  112. {
  113. var user = await _repository.GetAsync<UserInfoResult>(Q.Where(nameof(User.Id), id).Where(nameof(User.IsDelete), false));
  114. return user;
  115. }
  116. public async Task<User> GetAsync(SqlKata.Query query)
  117. {
  118. var user = await _repository.GetAsync(query.Where(nameof(User.IsDelete), false));
  119. return user;
  120. }
  121. public async Task<string> GetNameAsync(int id)
  122. {
  123. if (id <= 0) return string.Empty;
  124. return await _repository.GetAsync<string>(Q
  125. .Select(nameof(User.Name))
  126. .Where(nameof(User.Id), id).Where(nameof(User.IsDelete), false)
  127. );
  128. }
  129. public async Task<string> GetAvatarUrlAsync(int id)
  130. {
  131. if (id <= 0) return string.Empty;
  132. var avatarUrl = await _repository.GetAsync<string>(Q
  133. .Select(nameof(User.AvatarUrl))
  134. .Where(nameof(User.Id), id).Where(nameof(User.IsDelete), false)
  135. );
  136. return StringUtils.AddDomainMin(avatarUrl);
  137. }
  138. public string GetAvatarUrl(User user)
  139. {
  140. if (user == null) return string.Empty;
  141. return StringUtils.AddDomainMin(user.AvatarUrl);
  142. }
  143. public async Task<User> GetByPhoneAsync(string phone)
  144. {
  145. return await _repository.GetAsync(Q.Where(nameof(User.Phone), phone).Where(nameof(User.IsDelete), false));
  146. }
  147. /// <summary>
  148. /// openId微信认证
  149. /// </summary>
  150. /// <param name="openId"></param>
  151. /// /// <returns></returns>
  152. public async Task<User> GetByOpenIdAsync(string openId)
  153. {
  154. return await _repository.GetAsync(Q.Where(nameof(User.OpenId), openId).Where(nameof(User.IsDelete), false));
  155. }
  156. /// <summary>
  157. /// 绑定微信
  158. /// </summary>
  159. /// <param name="request"></param>
  160. /// <returns></returns>
  161. public async Task<bool> UpdateByOpendIdAsync(UserSignInRequest request)
  162. {
  163. var key = $"login:{request.Phone}";
  164. var user = new User();
  165. var code = _cache.GetString(key).Replace("\"", "");
  166. if (string.IsNullOrEmpty(code)) throw new BusinessException("验证码已过期");
  167. if (!request.Code.Equals(code, StringComparison.OrdinalIgnoreCase)) throw new BusinessException("验证码错误");
  168. user = await GetByPhoneAsync(request.Phone);
  169. //用户不存在,自动注册
  170. if (user == null)
  171. throw new BusinessException("用户不存在");
  172. return await _repository.UpdateAsync(Q.Where(nameof(User.Phone), request.Phone).Set(nameof(User.OpenId), request.OpenId)) > 0;
  173. }
  174. public async Task<bool> DeleteUsersAsync(IEnumerable<int> userIds)
  175. {
  176. return await _repository.UpdateAsync(Q.WhereIn(nameof(User.Id), userIds).Set(nameof(User.IsDelete), true)) > 0;
  177. }
  178. public async Task<bool> ChangeRoleAsync(IEnumerable<int> userIds, int roleId)
  179. {
  180. return await _repository.UpdateAsync(Q
  181. .Set(nameof(User.RoleId), roleId)
  182. .WhereIn(nameof(User.Id), userIds)
  183. ) > 0;
  184. }
  185. public async Task<bool> ChangeDepartmentAsync(IEnumerable<int> userIds, int departmentId)
  186. {
  187. return await _repository.UpdateAsync(Q
  188. .Set(nameof(User.DepartmentId), departmentId)
  189. .WhereIn(nameof(User.Id), userIds)
  190. ) > 0;
  191. }
  192. public async Task<bool> UpdateAsync(User user)
  193. {
  194. return await _repository.UpdateAsync(user);
  195. }
  196. public async Task<bool> UpdateDisableAsync(UserUpdateDisableRequest request)
  197. {
  198. return await _repository.UpdateAsync(Q.WhereIn(nameof(User.Id), request.Ids).Set(nameof(User.IsDisable), request.IsDisable)) > 0;
  199. }
  200. public async Task<int> GetCountAsync(int departmentId, int roleId, string keyword)
  201. {
  202. var query = Q.NewQuery();
  203. if (departmentId > 0)
  204. {
  205. query.Where(nameof(User.DepartmentId), departmentId);
  206. }
  207. if (roleId > 0)
  208. {
  209. query.Where(nameof(User.RoleId), roleId);
  210. }
  211. if (!string.IsNullOrEmpty(keyword))
  212. {
  213. keyword = "%" + keyword + "%";
  214. query.Where(q =>
  215. q.WhereLike(nameof(User.Name), keyword)
  216. .OrWhereLike(nameof(User.Email), keyword)
  217. .OrWhereLike(nameof(User.Phone), keyword)
  218. );
  219. }
  220. return await _repository.CountAsync(query.Where(nameof(User.IsDelete), false));
  221. }
  222. /// <summary>
  223. /// Set the limit and offset for a given page.
  224. /// </summary>
  225. /// <param name="page"></param>
  226. /// <param name="perPage"></param>
  227. /// <param name="departmentId"></param>
  228. /// <param name="roleId"></param>
  229. /// <param name="keyword"></param>
  230. /// <returns></returns>
  231. public async Task<IEnumerable<User>> GetPageListAsync(int page, int perPage, int departmentId, int roleId,
  232. string keyword)
  233. {
  234. var query = Q.ForPage(page, perPage);
  235. if (departmentId > 0)
  236. {
  237. query.Where(nameof(User.DepartmentId), departmentId);
  238. }
  239. if (roleId > 0)
  240. {
  241. query.Where(nameof(User.RoleId), roleId);
  242. }
  243. if (!string.IsNullOrEmpty(keyword))
  244. {
  245. keyword = "%" + keyword + "%";
  246. query.Where(q =>
  247. q.WhereLike(nameof(User.Name), keyword)
  248. .OrWhereLike(nameof(User.Email), keyword)
  249. .OrWhereLike(nameof(User.Phone), keyword)
  250. );
  251. }
  252. return await _repository.GetAllAsync(query.Where(nameof(User.IsDelete), false));
  253. }
  254. public async Task<IEnumerable<User>> GetListAsync(int departmentId, int roleId, string keyword)
  255. {
  256. var query = Q.NewQuery();
  257. if (departmentId > 0)
  258. {
  259. query.Where(nameof(User.DepartmentId), departmentId);
  260. }
  261. if (roleId > 0)
  262. {
  263. query.Where(nameof(User.RoleId), roleId);
  264. }
  265. if (!string.IsNullOrEmpty(keyword))
  266. {
  267. query.Where(q =>
  268. q.WhereLike(nameof(User.Name), keyword)
  269. .OrWhereLike(nameof(User.Email), keyword)
  270. .OrWhereLike(nameof(User.Phone), keyword)
  271. );
  272. }
  273. return await _repository.GetAllAsync(query.Where(nameof(User.IsDelete), false));
  274. }
  275. /// <summary>
  276. /// 登录
  277. /// </summary>
  278. /// <param name="request"></param>
  279. /// <returns></returns>
  280. public async Task<UserSignInResult> SignInAsync(UserSignInRequest request)
  281. {
  282. var result = new UserSignInResult();
  283. var key = $"login:{request.Phone}";
  284. try
  285. {
  286. var user = new User();
  287. if (string.IsNullOrWhiteSpace(request.OpenId))
  288. {
  289. var code = _cache.GetString(key).Replace("\"", "");
  290. if (string.IsNullOrEmpty(code)) throw new BusinessException("验证码已过期");
  291. if (!request.Code.Equals(code, StringComparison.OrdinalIgnoreCase)) throw new BusinessException("验证码错误");
  292. user = await GetByPhoneAsync(request.Phone);
  293. //用户不存在,自动注册
  294. if (user == null)
  295. throw new BusinessException("用户不存在");
  296. }
  297. else
  298. user = await GetByOpenIdAsync(request.OpenId);
  299. result.UserId = user.Id;
  300. result.DepartmentId = user.DepartmentId;
  301. result.User = _mapper.Map<UserResult>(user);
  302. if (result.User != null)
  303. result.User.AvatarUrl = StringUtils.AddDomain(result.User.AvatarUrl);
  304. //修改登录时间
  305. user.LoginTime = DateTime.Now;
  306. await _repository.UpdateAsync(user);
  307. return result;
  308. }
  309. catch (System.Exception)
  310. {
  311. throw new BusinessException("验证码或手机号错误");
  312. }
  313. }
  314. public async Task<int> InsertAsync(User user)
  315. {
  316. if (user == null) throw new Exception("用户不能为空");
  317. if (string.IsNullOrEmpty(user.Name)) throw new Exception("用户不能为空");
  318. if (!string.IsNullOrEmpty(user.Phone) &&
  319. await _repository.ExistsAsync(Q.Where(nameof(User.Phone), user.Phone)))
  320. {
  321. throw new Exception("用户手机号已存在,请更换手机号");
  322. }
  323. //头像处理
  324. user.AvatarUrl = StringUtils.RemoveDomain(user.AvatarUrl);
  325. user.IsUpload = false;
  326. user.Id = await _repository.InsertAsync(user);
  327. user = await _repository.GetAsync(user.Id);
  328. //创建二维码
  329. var qrCodeData = new { key = QRCodeTypeConst.UserInfo, value = user.Guid };
  330. var resultPath =
  331. FileHelper.SaveQRCodeFile(StringUtils.GetWebRootPath(_environment.WebRootPath),
  332. JsonConvert.SerializeObject(qrCodeData));
  333. user.QRCoder = resultPath.RelativePath;
  334. await _repository.UpdateAsync(user);
  335. return user.Id;
  336. }
  337. /// <summary>
  338. /// 删除用户
  339. /// </summary>
  340. /// <param name="id"></param>
  341. /// <returns></returns>
  342. public async Task<bool> DeleteAsync(int id)
  343. {
  344. var user = await GetAsync(id);
  345. if (user == null) throw new BusinessException("该用户不存在");
  346. return await DeleteAsync(id);
  347. }
  348. /// <summary>
  349. /// 删除用户
  350. /// </summary>
  351. /// <param name="ids"></param>
  352. /// <returns></returns>
  353. public async Task<bool> DeleteAsync(List<int> ids)
  354. {
  355. return await _repository.UpdateAsync(Q.WhereIn(nameof(User.Id), ids).Set(nameof(User.IsDelete), true)) > 0;
  356. }
  357. /// <summary>
  358. /// 更新用户信息
  359. /// </summary>
  360. /// <param name="id"></param>
  361. /// <param name="request"></param>
  362. /// <returns></returns>
  363. public async Task<bool> UpdateAsync(int id, UserInfoRequest request)
  364. {
  365. var user = await GetAsync(id);
  366. if (user == null) throw new BusinessException("该用户不存在");
  367. if (request.DepartmentId.Count() > 0)
  368. {
  369. await departmentUserRepository.AddDepartmentUserAsync(request.DepartmentId, id);
  370. }
  371. if (!string.IsNullOrEmpty(request.Nick))
  372. user.Nick = request.Nick;
  373. if (!string.IsNullOrEmpty(request.Description))
  374. user.Description = request.Description;
  375. if (!string.IsNullOrEmpty(request.Gender))
  376. user.Gender = request.Gender;
  377. if (!string.IsNullOrEmpty(request.Name))
  378. user.Name = request.Name;
  379. if (!string.IsNullOrEmpty(request.Position))
  380. user.Position = request.Position;
  381. if (request.RoleId > 0)
  382. user.RoleId = request.RoleId;
  383. if (!string.IsNullOrEmpty(request.Signature))
  384. user.Signature = request.Signature;
  385. //修改部门
  386. if (!string.IsNullOrEmpty(request.DepartmentName))
  387. user.DepartmentName = request.DepartmentName;
  388. //用户头像
  389. if (!string.IsNullOrEmpty(request.AvatarUrl))
  390. {
  391. user.HistoryAvatarUrl = user.AvatarUrl;
  392. user.AvatarUrl = StringUtils.RemoveDomain(request.AvatarUrl);
  393. }
  394. user.Email = request.Email;
  395. if (!string.IsNullOrWhiteSpace(request.Phone))
  396. user.Phone = request.Phone;
  397. user.QRCoder = StringUtils.RemoveDomain(user.QRCoder);
  398. if (request.IsDisable > 0)
  399. user.IsDisable = request.IsDisable == 1;
  400. if (request.IsFreeze > 0)
  401. user.IsFreeze = request.IsFreeze == 1;
  402. if (request.IsVip > 0)
  403. user.IsVip = request.IsVip == 1;
  404. if (request.IsLeader > 0)
  405. user.IsLeader = request.IsLeader == 1;
  406. if (request.IsMute > 0)
  407. user.IsMute = request.IsMute == 1;
  408. if (!string.IsNullOrWhiteSpace(request.DisableTiem))
  409. user.DisableTiem = Convert.ToDateTime(request.DisableTiem);
  410. return await UpdateAsync(user);
  411. }
  412. /// <summary>
  413. /// 用户分页列表
  414. /// </summary>
  415. /// <param name="request"></param>
  416. /// <returns></returns>
  417. public async Task<PagedList<UserResult>> GetPagedListAsync(UserPageSearchRequest request)
  418. {
  419. var pagedList = new PagedList<UserResult>
  420. {
  421. Total = await GetCountAsync(request.DepartmentId, request.RoleId, request.Keyword)
  422. };
  423. var list = await GetPageListAsync(request.Page, request.PerPage, request.DepartmentId, request.RoleId,
  424. request.Keyword);
  425. var items = list.Select(user => _mapper.Map<UserResult>(user)).ToList();
  426. foreach (var item in items)
  427. {
  428. //获取部门
  429. // var department = await _departmentRepository.GetAsync(item.DepartmentId);
  430. // if (department != null)
  431. // item.DepartmentName = department.Name;
  432. var role = await _roleRepository.GetAsync(item.RoleId);
  433. if (role != null)
  434. item.RoleName = role.Name;
  435. }
  436. pagedList.Items = items;
  437. return pagedList;
  438. }
  439. public async Task<List<UserResult>> GetListAsync(ArticleSearchRequest request)
  440. {
  441. var list = await GetListAsync(request.DepartmentId, request.RoleId, request.Keyword);
  442. var allList = new List<UserResult>();
  443. foreach (var user in list)
  444. {
  445. var result = _mapper.Map<UserResult>(user);
  446. allList.Add(result);
  447. }
  448. return allList;
  449. }
  450. /// <summary>
  451. /// 更新excel用户数据
  452. /// </summary>
  453. /// <param name="request"></param>
  454. /// <returns></returns>
  455. public async Task<bool> UpdateUserExcelAsync(List<User> request)
  456. {
  457. try
  458. {
  459. foreach (var item in request)
  460. {
  461. var user = await _repository.GetAsync(Q.Where(nameof(User.Phone), item.Phone));
  462. if (user != null)
  463. {
  464. continue;
  465. }
  466. var userId = await _repository.InsertAsync(item);
  467. //
  468. user = await _repository.GetAsync(userId);
  469. var resultPath =
  470. FileHelper.SaveQRCodeFile(StringUtils.GetWebRootPath(_environment.WebRootPath), item.Guid);
  471. user.QRCoder = resultPath.RelativePath;
  472. await _repository.UpdateAsync(user);
  473. await CreateMiUserAsync(item);
  474. }
  475. }
  476. catch (Exception e)
  477. {
  478. throw new BusinessException(e.Message);
  479. }
  480. return true;
  481. }
  482. /// <summary>
  483. /// 私信
  484. /// </summary>
  485. /// <param name="request"></param>
  486. /// <returns></returns>
  487. public async Task<bool> UpdateUserPrivateLetterAsync(UserPrivateLetterRequest request)
  488. {
  489. var user = await _repository.GetAsync(request.Id);
  490. if (user == null)
  491. throw new BusinessException("该用户不存在");
  492. user.IsPrivateLetter = !user.IsPrivateLetter;
  493. return await _repository.UpdateAsync(user);
  494. }
  495. /// <summary>
  496. /// 通知
  497. /// </summary>
  498. /// <param name="request"></param>
  499. /// <returns></returns>
  500. public async Task<bool> UpdateUserNoticeAsync(UserNoticeRequest request)
  501. {
  502. var user = await _repository.GetAsync(request.Id);
  503. if (user == null)
  504. throw new BusinessException("该用户不存在");
  505. user.IsNotice = !user.IsNotice;
  506. return await _repository.UpdateAsync(user);
  507. }
  508. /// <summary>
  509. /// 回复
  510. /// </summary>
  511. /// <param name="request"></param>
  512. /// <returns></returns>
  513. public async Task<bool> UpdateUserReplyAsync(UserReplyRequest request)
  514. {
  515. var user = await _repository.GetAsync(request.Id);
  516. if (user == null)
  517. throw new BusinessException("该用户不存在");
  518. user.IsReply = !user.IsReply;
  519. return await _repository.UpdateAsync(user);
  520. }
  521. /// <summary>
  522. /// 静音
  523. /// </summary>
  524. /// <param name="request"></param>
  525. /// <returns></returns>
  526. public async Task<bool> UpdateUserMuteAsync(UserMuteRequest request)
  527. {
  528. var user = await _repository.GetAsync(request.Id);
  529. if (user == null)
  530. throw new BusinessException("该用户不存在");
  531. user.IsMute = !user.IsMute;
  532. return await _repository.UpdateAsync(user);
  533. }
  534. /// <summary>
  535. /// 震动
  536. /// </summary>
  537. /// <param name="request"></param>
  538. /// <returns></returns>
  539. public async Task<bool> UpdateUserShakeAsync(UserShakeRequest request)
  540. {
  541. var user = await _repository.GetAsync(request.Id);
  542. if (user == null)
  543. throw new BusinessException("该用户不存在");
  544. user.IsShake = !user.IsShake;
  545. return await _repository.UpdateAsync(user);
  546. }
  547. /// <summary>
  548. /// 用户修改密码
  549. /// </summary>
  550. /// <param name="request"></param>
  551. /// <returns></returns>
  552. public async Task<bool> UpdateUserPhoneAsync(UserUpdatePhoneRequest request)
  553. {
  554. var key = $"login:{request.Phone}";
  555. var code = await _cache.GetStringAsync(key);
  556. if (string.IsNullOrEmpty(code)) throw new BusinessException("验证码已过期");
  557. if (!request.Code.Equals(code, StringComparison.OrdinalIgnoreCase)) throw new BusinessException("验证码错误");
  558. var user = await GetAsync(request.UserId);
  559. //用户不存在,自动注册
  560. if (user == null)
  561. {
  562. throw new BusinessException("该用户不存在");
  563. }
  564. user.Phone = request.Phone;
  565. return await _repository.UpdateAsync(user);
  566. }
  567. /// <summary>
  568. /// 用户邮箱验证
  569. /// </summary>
  570. /// <param name="request"></param>
  571. /// <returns></returns>
  572. public async Task<bool> SendEmailVerifyCodeAsync(UserEmailVerifyCodeRequest request)
  573. {
  574. //默认配置
  575. ConfigInfo configInfo = new ConfigInfo();
  576. var code = RandomGenerator.GetNumberString(6);
  577. var key = $"email:{request.Email}";
  578. //if (await RedisHelper.ExistsAsync(key)) throw new BusinessException("发送太频繁");
  579. MailManager.Send(configInfo, request.Email, "邮箱验证", "邮箱验证", $"验证号码:{code}", out var message);
  580. if (!string.IsNullOrEmpty(message))
  581. {
  582. throw new BusinessException(message);
  583. }
  584. //保存验证码
  585. await _cache.SetAsync(key, code, new DistributedCacheEntryOptions
  586. {
  587. AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(300)
  588. });
  589. return true;
  590. }
  591. /// <summary>
  592. /// 用户修改密码
  593. /// </summary>
  594. /// <param name="request"></param>
  595. /// <returns></returns>
  596. public async Task<bool> UpdateUserEmailAsync(UserUpdateEmailRequest request)
  597. {
  598. var key = $"email:{request.Email}";
  599. var code = await _cache.GetStringAsync(key);
  600. if (string.IsNullOrEmpty(code)) throw new BusinessException("验证码已过期");
  601. if (!request.Code.Equals(code, StringComparison.OrdinalIgnoreCase)) throw new BusinessException("验证码错误");
  602. var user = await _repository.GetAsync(request.UserId);
  603. //用户不存在,自动注册
  604. if (user == null)
  605. {
  606. throw new BusinessException("该用户不存在");
  607. }
  608. user.Email = request.Email;
  609. return await _repository.UpdateAsync(user);
  610. }
  611. /// <summary>
  612. /// 根据部门ID获取用户
  613. /// </summary>
  614. /// <param name="departmentId"></param>
  615. /// <returns></returns>
  616. public async Task<IEnumerable<User>> GetUserByDepartmentIdAsync(int departmentId)
  617. {
  618. var userIds = await departmentUserRepository.GetUserIdsByDepartmentIdsAsync(new List<int>() { departmentId });
  619. return await _repository.GetAllAsync(Q.WhereIn(nameof(User.Id), userIds).Where(nameof(User.IsDelete), false));
  620. }
  621. public async Task<IEnumerable<int>> GetUserIdListByDepartmentIdAsync(int departmentId)
  622. {
  623. return await _repository.GetAllAsync<int>(Q
  624. .Select(nameof(User.Id))
  625. .Where(nameof(User.DepartmentId), departmentId)
  626. );
  627. }
  628. public async Task<IEnumerable<int>> GetUserIdListByRoleIdAsync(int roleId)
  629. {
  630. return await _repository.GetAllAsync<int>(Q
  631. .Select(nameof(User.Id))
  632. .Where(nameof(User.RoleId), roleId).Where(nameof(User.IsDelete), false)
  633. );
  634. }
  635. /// <summary>
  636. /// 创建环信用户
  637. /// </summary>
  638. /// <param name="request"></param>
  639. /// <returns></returns>
  640. public async Task<bool> CreateMiUserAsync(User request)
  641. {
  642. try
  643. {
  644. var imServiceUrl = ConfigHelper.GetValue("ServiceAddress:ImUrl");
  645. HttpClient httpClient = new HttpClient(); //http对象
  646. HttpResponseMessage response = await httpClient.PostAsync(
  647. $"{imServiceUrl}/users",
  648. new JsonContent(new { username = request.Phone, password = "123456", nickname = request.Name }));
  649. if (response.IsSuccessStatusCode)
  650. {
  651. string result = await response.Content.ReadAsStringAsync();
  652. //成功后修改用户
  653. var userEntity = await GetByPhoneAsync(request.Phone);
  654. userEntity.ImId = request.Phone;
  655. await _repository.UpdateAsync(userEntity);
  656. }
  657. else
  658. {
  659. //出现请求环信失败
  660. // throw new BusinessException("创建用户失败");
  661. }
  662. }
  663. catch (Exception e)
  664. {
  665. throw new BusinessException(e.Message);
  666. }
  667. return true;
  668. }
  669. /// <summary>
  670. /// 用户模糊查询
  671. /// </summary>
  672. /// <param name="request"></param>
  673. /// <returns></returns>
  674. public async Task<IEnumerable<UserInfoResult>> SearchUserNameAsync(SearchUserNameRequest request)
  675. {
  676. var departments = new List<Department>();
  677. var notInUserIds = "";
  678. if (request.UserIds.Count > 0)
  679. {
  680. if (!request.IsShow)
  681. {
  682. notInUserIds = "and Id not in(";
  683. if (request.SearchType == 2 && !string.IsNullOrWhiteSpace(request.Key) && request.DepartmentId > 0)
  684. notInUserIds = "and a.Id not in(";
  685. if (request.SearchType == 1 && !string.IsNullOrWhiteSpace(request.Key) && request.DepartmentId > 0)
  686. notInUserIds = "and Id not in(";
  687. foreach (var userId in request.UserIds)
  688. {
  689. notInUserIds += $"{userId},";
  690. }
  691. notInUserIds = notInUserIds.Remove(notInUserIds.Length - 1, 1);
  692. notInUserIds += ")";
  693. }
  694. }
  695. var sql = $"select * from tede_user where 1=1 and IsDelete=0 (Name like '%{request.Key}%' or Phone like '%{request.Key}%' or Email like '%{request.Key}%') {notInUserIds}";
  696. if (request.SearchType == 2 && !string.IsNullOrWhiteSpace(request.Key) && request.DepartmentId > 0)
  697. sql = $@"select a.* from tede_user a inner join tede_address_book_group_user c on a.Id=c.UserId
  698. where 1=1 and a.IsDelete=0 and c.AddressBookGroupId={request.DepartmentId}
  699. and (a.Name like '%{request.Key}%' or a.Phone like '%{request.Key}%' or a.Email like '%{request.Key}%') {notInUserIds}";
  700. if (request.SearchType == 1 && !string.IsNullOrWhiteSpace(request.Key) && request.DepartmentId > 0)
  701. {
  702. //递归获取部门Id
  703. departments = await GetDepartmentAsync(request.DepartmentId, departments);
  704. var departmentValue = $"({request.DepartmentId},";
  705. foreach (var item in departments)
  706. departmentValue += $"{item.Id},";
  707. departmentValue = departmentValue.Remove(departmentValue.Length - 1, 1);
  708. departmentValue += ")";
  709. sql = $"select * from tede_user where 1=1 and IsDelete=0 and DepartmentId in {departmentValue} and (Name like '%{request.Key}%' or Phone like '%{request.Key}%' or Email like '%{request.Key}%') {notInUserIds}";
  710. }
  711. var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
  712. var database = new Database(databaseType, _connectionString);
  713. var connection = database.GetConnection();
  714. var result = await connection.QueryAsync<UserInfoResult>(sql);
  715. foreach (var item in result)
  716. {
  717. item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
  718. //获取上级
  719. departments = new List<Department>();
  720. departments = await GetUpDepartmentAsync(item.DepartmentId, departments);
  721. foreach (var department in departments)
  722. item.DepartmentName = "-" + department.Name + item.DepartmentName;
  723. if (!string.IsNullOrWhiteSpace(item.DepartmentName))
  724. item.DepartmentName = item.DepartmentName.Remove(0, 1);
  725. if (request.IsShow)
  726. if (request.UserIds.Contains(item.Id))
  727. item.IsDisable = true;
  728. }
  729. return result;
  730. }
  731. public async Task<List<Entity.Department>> GetUpDepartmentAsync(int id, List<Department> departments)
  732. {
  733. var sql = $"select * from tede_department where Id={id}";
  734. var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
  735. var database = new Database(databaseType, _connectionString);
  736. var connection = database.GetConnection();
  737. var result = await connection.QueryFirstOrDefaultAsync<Department>(sql);
  738. if (result == null)
  739. return departments;
  740. departments.Add(result);
  741. await GetUpDepartmentAsync(result.ParentId, departments);
  742. return departments;
  743. }
  744. public async Task<List<Entity.Department>> GetDepartmentAsync(int pid, List<Department> departments)
  745. {
  746. var sql = $"select * from tede_department where ParentId={pid}";
  747. var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
  748. var database = new Database(databaseType, _connectionString);
  749. var connection = database.GetConnection();
  750. var result = await connection.QueryAsync<Department>(sql);
  751. if (result.Count() == 0)
  752. return departments;
  753. departments.AddRange(result);
  754. foreach (var item in result)
  755. await GetDepartmentAsync(item.Id, departments);
  756. return departments;
  757. }
  758. /// <summary>
  759. /// 查询所有用户
  760. /// </summary>
  761. /// <returns></returns>
  762. public async Task<IEnumerable<User>> FindAllUserAsync(SqlKata.Query query)
  763. {
  764. return await _repository.GetAllAsync(query.Where(nameof(User.IsDelete), false));
  765. }
  766. /// <summary>
  767. /// 根据Guid获取用户数据
  768. /// </summary>
  769. /// <param name="guid"></param>
  770. /// <returns></returns>
  771. public async Task<UserDetail> GetGuidAsync(string guid)
  772. {
  773. var user = await _repository.GetAsync(Q.Where(nameof(User.Guid), guid));
  774. user.AvatarUrl = StringUtils.AddDomainMin(user.AvatarUrl);
  775. user.QRCoder = StringUtils.AddDomain(user.QRCoder);
  776. return _mapper.Map<UserDetail>(user);
  777. }
  778. public async Task<int> CountAsync(Query query)
  779. {
  780. return await _repository.CountAsync(query.Where(nameof(User.IsDelete), false));
  781. }
  782. public async Task<IEnumerable<User>> GetAllAsync(Query query)
  783. {
  784. return await _repository.GetAllAsync(query.Where(nameof(User.IsDelete), false));
  785. }
  786. public async Task<IEnumerable<int>> GetAllIntsAsync(Query query)
  787. {
  788. return await _repository.GetAllAsync<int>(query.Where(nameof(User.IsDelete), false));
  789. }
  790. public Task<IEnumerable<User>> FindAllUserAsync()
  791. {
  792. throw new NotImplementedException();
  793. }
  794. /// <summary>
  795. /// 获取用户未读数据
  796. /// </summary>
  797. /// <param name="userId"></param>
  798. /// <returns></returns>
  799. public async Task<UserCountResult> GetUserCountAsync(int userId)
  800. {
  801. var result = new UserCountResult();
  802. var noticeConstValue = AllTypeConst.Notice.GetHashCode();
  803. var missiveConstValue = AllTypeConst.Missive.GetHashCode();
  804. var anonymityConstValue = AllTypeConst.Anonymity.GetHashCode();
  805. string sql = $@"select count(1) from tede_middle where FolderType={AllTypeConst.Inbox.GetHashCode()}
  806. and UserId={userId} and IsDelete=0 and
  807. MiddleId in (select SourceId from tede_addressee where UserId={userId} and IsRead=0 and IsDelete=0 and SourceType in({noticeConstValue},{missiveConstValue},{anonymityConstValue}))";
  808. var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
  809. var database = new Database(databaseType, _connectionString);
  810. var connection = database.GetConnection();
  811. var noticeCount = await connection.ExecuteScalarAsync<int>(sql);
  812. // sql = $"select count(1) from tede_middle where FolderType={AllTypeConst.Inbox.GetHashCode()} and UserId={userId} and MiddleId in (select SourceId from tede_addressee where UserId={userId} and SourceType={AllTypeConst.Missive.GetHashCode()} and IsDelete=0 and IsRead=0)";
  813. // var missiveCount = await connection.ExecuteScalarAsync<int>(sql);
  814. // //sql = $"SELECT count(1) FROM tede_admin_verify where AdminId={userId} and DisposeType=0";
  815. // // noticeCount += await connection.ExecuteScalarAsync<int>(sql);
  816. // result.noticeCount = noticeCount;
  817. result.noticeCount = noticeCount;
  818. return result;
  819. }
  820. /// <summary>
  821. /// 获取工作用户选择审核和抄送人
  822. /// </summary>
  823. /// <param name="userIds"></param>
  824. /// <param name="flowId"></param>
  825. /// <returns></returns>
  826. public async Task<List<Entity.User>> GeFlowUsers(List<int> userIds, int flowId, string type)
  827. {
  828. string strSql = "";
  829. if (userIds.Count > 0)
  830. {
  831. strSql = "and UserId not in(";
  832. foreach (var item in userIds)
  833. {
  834. strSql += $"{item},";
  835. }
  836. strSql = strSql.Remove(strSql.Length - 1, 1);
  837. strSql += ")";
  838. }
  839. string sql = $" select * from tede_user where 1=1 and IsDelete=0 and Id in( SELECT UserId FROM tede_flow_todo where FlowId={flowId} and Type='{type}' {strSql})";
  840. var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
  841. var database = new Database(databaseType, _connectionString);
  842. var connection = database.GetConnection();
  843. var result = await connection.QueryAsync<User>(sql);
  844. foreach (var item in result)
  845. item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
  846. return result.ToList();
  847. }
  848. public async Task<List<JobUserResult>> ElasticSearchUser()
  849. {
  850. var sql = "select * from tede_user where IsUpload=0 limit 0,100";
  851. var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
  852. var database = new Database(databaseType, _connectionString);
  853. var connection = database.GetConnection();
  854. var items = await connection.QueryAsync<JobUserResult>(sql);
  855. return items.ToList();
  856. }
  857. public async Task<bool> UpdateAsync(SqlKata.Query query)
  858. {
  859. return await _repository.UpdateAsync(query) > 0;
  860. }
  861. //public async Task<UserDetail> GetUserDetailJoinAsync(int userId)
  862. //{
  863. // var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypestr, DatabaseType.MySql);
  864. // var database = new Database(databaseType, _connectionString);
  865. // var connection = database.GetConnection();
  866. // var result = connection.Query<UserDetail, Department, UserDetail>(
  867. // "SELECT a.*,b.Name FROM tede_user a inner join tede_department b on a.DepartmentId=b.Id where a.id=@Id;",
  868. // (userDetail,department) =>
  869. // {
  870. // userDetail.DepartmentName = department.Name;
  871. // return userDetail;
  872. // }, new {Id = userId}, splitOn: "Name");
  873. // return result.ToList()[0];
  874. //}
  875. /// <summary>
  876. /// vip用户
  877. /// </summary>
  878. /// <param name="request"></param>
  879. /// <returns></returns>
  880. public async Task<PagedList<UserDetail>> GetUserVipDetail(UserSearchVipRequest request)
  881. {
  882. var result = new PagedList<UserDetail>();
  883. var query = Q.NewQuery();
  884. query.Where(nameof(User.IsDelete), false);
  885. if (!string.IsNullOrEmpty(request.KeyWord))
  886. query.WhereLike(nameof(User.Name), $"%{request.KeyWord}%");
  887. if (request.VipPort > 0)
  888. query.Where(nameof(User.Port), request.VipPort);
  889. if (request.VipTypeId > 0)
  890. query.Where(nameof(User.TypeId), request.VipTypeId);
  891. if (request.IsDisable > 0)
  892. query.Where(nameof(User.IsDisable), request.IsDisable == 1);
  893. if (request.IsFreeze > 0)
  894. query.Where(nameof(User.IsFreeze), request.IsFreeze == 1);
  895. if (request.IsVip > 0)
  896. query.Where(nameof(User.IsVip), request.IsVip == 1);
  897. if (request.BeginAccumulativePrice > 0 || request.EndAccumulativePrice > 0)
  898. {
  899. query.Where(nameof(User.AccumulativePrice), ">=", request.BeginAccumulativePrice);
  900. query.Where(nameof(User.AccumulativePrice), "<=", request.EndAccumulativePrice);
  901. }
  902. if (request.RenewalCount > 0)
  903. query.Where(nameof(User.RenewalCount), request.RenewalCount);
  904. result.Total = await _repository.CountAsync(query);
  905. if (!string.IsNullOrEmpty(request.Sort) && request.Sort.Equals("AccumulativePrice"))
  906. query.OrderByDesc(nameof(User.AccumulativePrice));
  907. else
  908. query.OrderByDesc(nameof(User.CreatedDate));
  909. var items = await _repository.GetAllAsync(query.ForPage(request.Page, request.PerPage));
  910. result.Items = items.Select(n => _mapper.Map<UserDetail>(n));
  911. return result;
  912. }
  913. /// <summary>
  914. /// 根据用户ID获取用户信息
  915. /// </summary>
  916. /// <param name="userIds"></param>
  917. /// <returns></returns>
  918. public async Task<IEnumerable<UserInfoResult>> GetUserInfoResultsAsync(IEnumerable<int> userIds, string keyWord = "")
  919. {
  920. userIds = userIds.Distinct();
  921. if (userIds.Count() == 0)
  922. return new List<UserInfoResult>();
  923. var sqlStr = "";
  924. foreach (var item in userIds)
  925. sqlStr += $"{item},";
  926. sqlStr = sqlStr.Remove(sqlStr.Length - 1, 1);
  927. var sql = $@"select * from tede_user where 1=1 and IsDelete=0 and id in({sqlStr})";
  928. if (!string.IsNullOrEmpty(keyWord))
  929. sql += $@" and (Name like '%{keyWord}%' or phone like '%{keyWord}%' or Email like '%{keyWord}%')";
  930. var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
  931. var database = new Database(databaseType, _connectionString);
  932. var connection = database.GetConnection();
  933. var result = await connection.QueryAsync<UserInfoResult>(sql);
  934. foreach (var item in result)
  935. item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
  936. return result;
  937. }
  938. /// <summary>
  939. /// 获取不是好友的用户 排除部门
  940. /// </summary>
  941. /// <param name="keyword"></param>
  942. /// <param name="userIds"></param>
  943. /// <returns></returns>
  944. public async Task<IEnumerable<UserInfoResult>> GetUserInfoNoFriendsResults(string keyword, IEnumerable<int> userIds)
  945. {
  946. userIds = userIds.Distinct();
  947. var sqlStr = "";
  948. foreach (var item in userIds)
  949. sqlStr += $"{item},";
  950. sqlStr = !string.IsNullOrEmpty(sqlStr) ? sqlStr.Remove(sqlStr.Length - 1, 1) : "";
  951. var sql = $@"select * from tede_user where 1=1 and IsDelete=0 ";
  952. if (!string.IsNullOrEmpty(sqlStr))
  953. sql += $@" and id not in({sqlStr})";
  954. if (!string.IsNullOrEmpty(keyword))
  955. sql += $@" and (Name like '%{keyword}%' or phone like '%{keyword}%' or Email like '%{keyword}%')";
  956. var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
  957. var database = new Database(databaseType, _connectionString);
  958. var connection = database.GetConnection();
  959. var result = await connection.QueryAsync<UserInfoResult>(sql);
  960. foreach (var item in result)
  961. item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
  962. return result;
  963. }
  964. /// <summary>
  965. /// 搜索好友部门用户
  966. /// </summary>
  967. /// <param name="keyword"></param>
  968. /// <param name="userIds"></param>
  969. /// <returns></returns>
  970. public async Task<IEnumerable<UserInfoResult>> GetSearchUserInfoResults(string keyword, IEnumerable<int> userIds)
  971. {
  972. userIds = userIds.Distinct();
  973. var sqlStr = "";
  974. foreach (var item in userIds)
  975. sqlStr += $"{item},";
  976. sqlStr = string.IsNullOrEmpty(sqlStr) ? "" : sqlStr.Remove(sqlStr.Length - 1, 1);
  977. var sql = $@"select * from tede_user where 1=1 and IsDelete=0 ";
  978. if (!string.IsNullOrEmpty(sqlStr))
  979. sql += $@" and id in({sqlStr})";
  980. if (!string.IsNullOrEmpty(keyword))
  981. sql += $@" and (Name like '%{keyword}%' or phone like '%{keyword}%' or Email like '%{keyword}%')";
  982. var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
  983. var database = new Database(databaseType, _connectionString);
  984. var connection = database.GetConnection();
  985. var result = await connection.QueryAsync<UserInfoResult>(sql);
  986. foreach (var item in result)
  987. item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
  988. return result;
  989. }
  990. /// <summary>
  991. /// 获取用户工作我的审批未读数量
  992. /// </summary>
  993. /// <param name="userId"></param>
  994. /// <returns></returns>
  995. public async Task<int> GetUserUReadFlowTodoCountAsync(int userId)
  996. {
  997. string sql = $@"SELECT
  998. count(1)
  999. FROM
  1000. tede_flow_todo
  1001. WHERE
  1002. FlowId IN (SELECT
  1003. SonId
  1004. FROM
  1005. tede_notice
  1006. WHERE
  1007. userId ={userId} AND TypeValue = 15
  1008. AND IsDelete = 0)
  1009. AND Type = 'ApproverCheck' and IsRead=0";
  1010. var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
  1011. var database = new Database(databaseType, _connectionString);
  1012. var connection = database.GetConnection();
  1013. var result = await connection.ExecuteScalarAsync<int>(sql);
  1014. return result;
  1015. }
  1016. }
  1017. }