NoticeRepository.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using System.Transactions;
  5. using AutoMapper;
  6. using Dapper;
  7. using GxPress.Common.AppOptions;
  8. using GxPress.Common.Exceptions;
  9. using GxPress.Common.Page;
  10. using GxPress.Common.Tools;
  11. using GxPress.Entity;
  12. using GxPress.Entity.Middle;
  13. using GxPress.EnumConst;
  14. using GxPress.Repository.Interface;
  15. using GxPress.Request.Notice;
  16. using GxPress.Result.Notice;
  17. using Microsoft.Extensions.Options;
  18. using Datory;
  19. using SqlKata;
  20. using GxPress.Result.Job;
  21. using System.Linq;
  22. namespace GxPress.Repository.Implement
  23. {
  24. public class NoticeRepository : INoticeRepository
  25. {
  26. private readonly Repository<Notice> _repository;
  27. private readonly Repository<Addressee> _noticeAddresseeRepository;
  28. private readonly Repository<Cc> _noticeCcRepository;
  29. private readonly Repository<User> _userRepository;
  30. private readonly Repository<Middle> _middleRepository;
  31. private readonly Repository<Entity.AdminVerify> _adminVerifyRepository;
  32. private readonly IMapper _mapper;
  33. private readonly string _connectionString;
  34. private readonly string _databaseTypeStr;
  35. public NoticeRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor, IMapper mapper)
  36. {
  37. _databaseTypeStr = dbOptionsAccessor.CurrentValue.DatabaseType;
  38. _connectionString = dbOptionsAccessor.CurrentValue.ConnectionString;
  39. var databaseType =
  40. StringUtils.ToEnum<DatabaseType>(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql);
  41. var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
  42. _repository = new Repository<Notice>(database);
  43. _noticeAddresseeRepository = new Repository<Addressee>(database);
  44. _noticeCcRepository = new Repository<Cc>(database);
  45. _userRepository = new Repository<User>(database);
  46. _middleRepository = new Repository<Middle>(database);
  47. _adminVerifyRepository = new Repository<Entity.AdminVerify>(database);
  48. _mapper = mapper;
  49. }
  50. public IDatabase Database => _repository.Database;
  51. public string TableName => _repository.TableName;
  52. public List<TableColumn> TableColumns => _repository.TableColumns;
  53. public async Task<Notice> GetAsync(int id)
  54. {
  55. return await _repository.GetAsync(id);
  56. }
  57. public async Task<Notice> GetAsync(SqlKata.Query query)
  58. {
  59. return await _repository.GetAsync(query);
  60. }
  61. /// <summary>
  62. /// 添加通知
  63. /// </summary>
  64. /// <param name="request"></param>
  65. /// <returns></returns>
  66. public async Task<int> InsertAsync(NoticeInRequest request)
  67. {
  68. var noticeId = 0;
  69. try
  70. {
  71. using (TransactionScope transactionScope = new TransactionScope())
  72. {
  73. var userEntity = await _userRepository.GetAsync(request.UserId);
  74. if (userEntity == null)
  75. throw new BusinessException("用户不存在");
  76. //通知
  77. var notice = new Notice
  78. {
  79. NoticeType = request.NoticeType.GetHashCode() == 0 ? NoticeTypeConst.Send : request.NoticeType,
  80. UserId = request.UserId,
  81. TypeValue = request.TypeValue,
  82. Content = request.Content,
  83. Title = request.Title,
  84. ParentId = request.ParentId,
  85. UserName = userEntity.Name,
  86. HtmlContent = request.HtmlContent,
  87. SourceId = request.SoureId,
  88. IsDelete = false,
  89. IsTop = false,
  90. SonId = request.SonId
  91. };
  92. noticeId = await _repository.InsertAsync(notice);
  93. transactionScope.Complete();
  94. }
  95. }
  96. catch (Exception e)
  97. {
  98. throw new BusinessException(e.Message);
  99. }
  100. return noticeId;
  101. }
  102. /// <summary>
  103. /// 根据用户ID查询
  104. /// </summary>
  105. /// <param name="request"></param>
  106. /// <returns></returns>
  107. public async Task<PagedList<Notice>> GetNoticeByUserIdAsync(NoticePageSearchRequest request)
  108. {
  109. var query = Q.NewQuery();
  110. if (request.UserId > 0)
  111. {
  112. query.Where(nameof(Addressee.UserId), request.UserId);
  113. }
  114. if (request.SearchType == 0)
  115. {
  116. query.Where(nameof(Addressee.UserId), request.UserId);
  117. }
  118. if (request.SearchType == 1)
  119. {
  120. query.Where(nameof(Addressee.IsAdmin), true);
  121. }
  122. if (request.SearchType == 2)
  123. {
  124. query.Where(nameof(Addressee.NoticeAddresseeType), NoticeTypeConst.Draft);
  125. }
  126. if (request.SearchType == 3)
  127. {
  128. query.Where(nameof(Addressee.IsDelete), true);
  129. }
  130. if (!string.IsNullOrEmpty(request.Keyword))
  131. {
  132. var like = $"%{request.Keyword}%";
  133. query.WhereLike(nameof(Notice.Title), like);
  134. }
  135. var pagedList = new PagedList<Notice>
  136. {
  137. Total = await _repository.CountAsync(query)
  138. };
  139. var list = await _repository.GetAllAsync(query.ForPage(request.Page, request.PerPage));
  140. pagedList.Items = list;
  141. return pagedList;
  142. }
  143. /// <summary>
  144. /// admin根据用户ID查询
  145. /// </summary>
  146. /// <param name="request"></param>
  147. /// <returns></returns>
  148. public async Task<PagedList<NoticeListPageResult>> GetAdminNoticeByUserIdAsync(NoticePageSearchRequest request)
  149. {
  150. //用户收件人
  151. var noticeQuery = Q.NewQuery();
  152. if (request.SearchType == 2)
  153. {
  154. noticeQuery.Where(nameof(Notice.NoticeType), NoticeTypeConst.Draft);
  155. }
  156. noticeQuery.Where(nameof(Notice.IsDelete), request.SearchType == 3);
  157. if (!string.IsNullOrEmpty(request.Keyword))
  158. {
  159. noticeQuery.WhereLike(nameof(Notice.Title), $"%{request.Keyword}%");
  160. }
  161. var noticeList = await _repository.GetAllAsync(noticeQuery);
  162. var result = new PagedList<NoticeListPageResult>();
  163. result.Total = await _repository.CountAsync(noticeQuery);
  164. var notices = await _repository.GetAllAsync(noticeQuery.OrderByDesc(nameof(Notice.CreatedDate)).ForPage(request.Page, request.PerPage));
  165. var noticeListPageResults = new List<NoticeListPageResult>();
  166. foreach (var notice in notices)
  167. {
  168. var noticeListPageResultEntity = _mapper.Map<NoticeListPageResult>(notice);
  169. var user = await _userRepository.GetAsync(notice.UserId);
  170. if (user != null)
  171. {
  172. noticeListPageResultEntity.AvatarUrl = StringUtils.AddDomain(user.AvatarUrl);
  173. }
  174. //阅读数量
  175. noticeListPageResultEntity.ReadCount = await _noticeAddresseeRepository.CountAsync(
  176. Q.Where(nameof(Addressee.SourceId), notice.Id)
  177. .Where(nameof(Addressee.IsRead), true).Where(nameof(Addressee.IsAdmin), false));
  178. //收件人数量
  179. noticeListPageResultEntity.AllCount = await _noticeAddresseeRepository.CountAsync(
  180. Q.Where(nameof(Addressee.SourceId), notice.Id)
  181. .Where(nameof(Addressee.IsAdmin), false));
  182. noticeListPageResults.Add(noticeListPageResultEntity);
  183. }
  184. result.Items = noticeListPageResults;
  185. return result;
  186. }
  187. /// <summary>
  188. /// 管理员删除
  189. /// </summary>
  190. /// <param name="id"></param>
  191. /// <returns></returns>
  192. public async Task<bool> AdminDeleteAsync(int id)
  193. {
  194. try
  195. {
  196. var notice = await _repository.GetAsync(id);
  197. if (notice == null)
  198. throw new BusinessException("通知不存在");
  199. using (TransactionScope transactionScope = new TransactionScope())
  200. {
  201. //通知
  202. await _repository.DeleteAsync(id);
  203. //抄送
  204. await _noticeCcRepository.DeleteAsync(Q.Where(nameof(Cc.SourceId), id));
  205. //收件人
  206. await _noticeAddresseeRepository.DeleteAsync(Q.Where(nameof(Addressee.SourceId), id));
  207. transactionScope.Complete();
  208. }
  209. }
  210. catch (Exception e)
  211. {
  212. throw new BusinessException(e.Message);
  213. }
  214. return true;
  215. }
  216. /// <summary>
  217. /// 自己删除
  218. /// </summary>
  219. /// <param name="request"></param>
  220. /// <returns></returns>
  221. public async Task<bool> DeleteAsync(NoticeDeRequest request)
  222. {
  223. try
  224. {
  225. using (TransactionScope transactionScope = new TransactionScope())
  226. {
  227. //var notice = await _repository.GetAsync(request.NoticeId);
  228. //if (notice == null)
  229. // throw new BusinessException("通知不存在");
  230. //notice.IsDelete = true;
  231. //await _repository.UpdateAsync(notice);
  232. //
  233. await _noticeAddresseeRepository.UpdateAsync(Q.Set(nameof(Addressee.IsDelete), true)
  234. .WhereIn(nameof(Addressee.Id), request.MiddleIds));
  235. transactionScope.Complete();
  236. }
  237. }
  238. catch (Exception e)
  239. {
  240. throw new BusinessException(e.Message);
  241. }
  242. return true;
  243. }
  244. /// <summary>
  245. /// 恢复删除通知
  246. /// </summary>
  247. /// <param name="request"></param>
  248. /// <returns></returns>
  249. public async Task<bool> RecoverDeleteAsync(NoticeDeRequest request)
  250. {
  251. try
  252. {
  253. using (TransactionScope transactionScope = new TransactionScope())
  254. {
  255. //
  256. await _noticeAddresseeRepository.UpdateAsync(Q.Set(nameof(Addressee.IsDelete), false)
  257. .Where(nameof(Addressee.Id), request.MiddleIds));
  258. transactionScope.Complete();
  259. }
  260. }
  261. catch (Exception e)
  262. {
  263. throw new BusinessException(e.Message);
  264. }
  265. return true;
  266. }
  267. /// <summary>
  268. /// 通知修改
  269. /// </summary>
  270. /// <param name="id"></param>
  271. /// <param name="request"></param>
  272. /// <returns></returns>
  273. public async Task<bool> UpdateNoticeAsync(Notice notice)
  274. {
  275. return await _repository.UpdateAsync(notice);
  276. }
  277. /// <summary>
  278. /// 通知修改
  279. /// </summary>
  280. /// <param name="id"></param>
  281. /// <param name="request"></param>
  282. /// <returns></returns>
  283. public async Task<bool> UpdateAsync(SqlKata.Query query)
  284. {
  285. return await _repository.UpdateAsync(query) > 0;
  286. }
  287. /// <summary>
  288. /// 获取通知列表
  289. /// </summary>
  290. /// <param name="request"></param>
  291. /// <returns></returns>
  292. public async Task<PagedList<NoticeListPageResult>> GetNoticeListPageAsync(NoticePageSearchRequest request)
  293. {
  294. //用户收件人
  295. string sb = "";
  296. if (request.SearchType == 1)
  297. sb += " AND a.IsAdmin = 1 and a.NoticeAddresseeType=1 AND a.IsDelete = 0";
  298. else if (request.SearchType == 2)
  299. sb += " and a.NoticeAddresseeType=2 AND a.AttributeValue=1 AND a.IsDelete = 0";
  300. else if (request.SearchType == 3)
  301. sb += " AND a.IsDelete = 1 AND a.AttributeValue=1";
  302. else if (request.SearchType > 3)
  303. sb += $" AND b.TypeValue={request.SearchType} AND a.IsDelete = 0";
  304. else
  305. sb += " AND a.IsDelete = 0 AND a.NoticeAddresseeType != 2";
  306. if (!string.IsNullOrEmpty(request.Keyword))
  307. {
  308. if (request.NoticeFolderId > 0)
  309. sb += $@" AND a.ParentId ={request.NoticeFolderId} AND a.AttributeValue != 2 and (b.Title LIKE '%{request.Keyword}%'
  310. OR b.Content LIKE '%{request.Keyword}%'
  311. OR c.Name LIKE '%{request.Keyword}%'
  312. OR d.UserName LIKE '%{request.Keyword}%'
  313. OR a.CreatedDate LIKE '%{request.Keyword}%' or a.MiddleId in (SELECT
  314. g.NoticeId
  315. FROM
  316. tede_addressee g
  317. INNER JOIN
  318. tede_user h ON g.UserId = h.Id
  319. WHERE
  320. g.SourceId =a.MiddleId AND h.Name LIKE '%{request.Keyword}%'))";
  321. else
  322. sb += $@" AND a.AttributeValue != 2 AND (b.Title LIKE '%{request.Keyword}%'
  323. OR b.Content LIKE '%{request.Keyword}%'
  324. OR c.Name LIKE '%{request.Keyword}%'
  325. OR d.UserName LIKE '%{request.Keyword}%'
  326. OR a.CreatedDate LIKE '%{request.Keyword}%' or a.MiddleId in (SELECT
  327. g.NoticeId
  328. FROM
  329. tede_addressee g
  330. INNER JOIN
  331. tede_user h ON g.UserId = h.Id
  332. WHERE
  333. g.SourceId =a.MiddleId AND h.Name LIKE '%{request.Keyword}%'))";
  334. }
  335. else
  336. {
  337. var searchList = new List<int> { 1, 2, 3 };
  338. if (!searchList.Contains(request.SearchType))
  339. sb += " AND a.ParentId = " + request.NoticeFolderId;
  340. }
  341. var noticeTypeValue = GxPress.EnumConst.AllTypeConst.Inbox.GetHashCode();
  342. var sql = $@"SELECT a.*,(SELECT GROUP_CONCAT(SourceName Separator'、') from tede_user_middle where MiddleType=10 and DataSourceId=a.MiddleId) as EnjoyUser,(SELECT
  343. GROUP_CONCAT(Name
  344. SEPARATOR '、')
  345. FROM
  346. tede_user
  347. WHERE
  348. Id IN (SELECT
  349. UserId
  350. FROM
  351. tede_flow_todo
  352. WHERE
  353. FlowId = b.SourceId
  354. AND type = 'ApproverCheck')) AS FlowUserName,
  355. (SELECT
  356. COUNT(1)
  357. FROM
  358. tede_flow_todo
  359. WHERE
  360. FlowId = b.SourceId
  361. AND type = 'ApproverCheck') AS UCheckedCount,
  362. (SELECT
  363. COUNT(1)
  364. FROM
  365. tede_flow_todo
  366. WHERE
  367. FlowId = b.SourceId
  368. AND type = 'ApproverCheck'
  369. AND IsDone = 1
  370. AND IsChecked = 1) AS CheckedCount,
  371. (SELECT
  372. IsRead
  373. FROM
  374. tede_flow_todo
  375. WHERE
  376. UserId = a.UserId
  377. AND FlowId = b.SourceId
  378. AND Type = 'CarbonCopy'
  379. LIMIT 1) AS IsFlowRead,
  380. (SELECT
  381. IsRead
  382. FROM
  383. tede_flow_todo
  384. WHERE
  385. UserId = b.UserId
  386. AND FlowId = b.SourceId
  387. AND Type = 'ApproverCheck'
  388. LIMIT 1) AS IsFlowChecked,
  389. (SELECT
  390. IsRead
  391. FROM
  392. tede_flow
  393. WHERE
  394. id = b.SourceId AND UserId = b.UserId) AS IsMyFlowRead,
  395. (select IsRecall from tede_notice where id=a.MiddleId) as IsRecall,
  396. (SELECT
  397. IsDone
  398. FROM
  399. tede_flow_todo
  400. WHERE
  401. type = 'ApproverCheck'
  402. AND UserId = a.UserId
  403. LIMIT 1) AS IsDone,
  404. (SELECT
  405. IsChecked
  406. FROM
  407. tede_flow_todo
  408. WHERE
  409. type = 'ApproverCheck'
  410. AND UserId = a.UserId
  411. LIMIT 1) AS IsChecked,
  412. (SELECT
  413. DoneType
  414. FROM
  415. tede_flow_todo
  416. WHERE
  417. type = 'ApproverCheck'
  418. AND UserId = a.UserId
  419. LIMIT 1) AS DoneType,
  420. (SELECT
  421. COUNT(1)
  422. FROM
  423. tede_analyze
  424. WHERE
  425. TypeValue = {noticeTypeValue}
  426. AND SourceId = a.MiddleId
  427. AND AnalyzeType = 1) AS PraiseCount,
  428. (SELECT
  429. COUNT(1)
  430. FROM
  431. tede_analyze
  432. WHERE
  433. UserId = {request.UserId} AND TypeValue = {noticeTypeValue}
  434. AND SourceId = a.MiddleId
  435. AND AnalyzeType = 1
  436. LIMIT 0 , 1) AS IsLaud,
  437. (SELECT
  438. COUNT(1)
  439. FROM
  440. tede_comment
  441. WHERE
  442. ArticleId = a.MiddleId and pid=0
  443. AND TypeValue = {noticeTypeValue}) AS CommentCount,
  444. (SELECT
  445. COUNT(1)
  446. FROM
  447. tede_analyze
  448. WHERE
  449. UserId = {request.UserId} AND TypeValue = {noticeTypeValue}
  450. AND SourceId = a.MiddleId
  451. AND AnalyzeType = 4) AS RetransmissionCount,
  452. (SELECT
  453. COUNT(1)
  454. FROM
  455. tede_analyze
  456. WHERE
  457. UserId = {request.UserId} AND TypeValue = {noticeTypeValue}
  458. AND SourceId = a.MiddleId
  459. AND AnalyzeType = 4
  460. LIMIT 0 , 1) AS IsRetransmission,
  461. (SELECT
  462. COUNT(1)
  463. FROM
  464. tede_analyze
  465. WHERE
  466. UserId = {request.UserId} AND TypeValue = {noticeTypeValue}
  467. AND SourceId = a.MiddleId
  468. AND AnalyzeType = 4
  469. LIMIT 0 , 1) AS IsCollect,
  470. (SELECT
  471. COUNT(1)
  472. FROM
  473. tede_analyze
  474. WHERE
  475. UserId = {request.UserId} AND TypeValue = {noticeTypeValue}
  476. AND SourceId = a.MiddleId
  477. AND AnalyzeType = 4) AS CollectCount,
  478. (SELECT
  479. COUNT(1)
  480. FROM
  481. tede_middle
  482. WHERE
  483. ParentId = a.Id and IsDelete=0 and NoticeAddresseeType<>2) as FileCount,(SELECT
  484. COUNT(1)
  485. FROM
  486. tede_addressee
  487. WHERE
  488. SourceId = a.MiddleId AND IsRead = 1) as ReadCount,(SELECT
  489. COUNT(1)
  490. FROM
  491. tede_addressee
  492. WHERE
  493. SourceId = a.MiddleId ) as AllCount,(SELECT
  494. COUNT(1)
  495. FROM
  496. tede_addressee
  497. WHERE
  498. SourceId = a.MiddleId AND IsRead = 1 and UserId={request.UserId} limit 0,1) as IsRead, b.*, c.Name, c.AvatarUrl, d.Id,d.SourceId
  499. FROM
  500. tede_middle a
  501. left JOIN
  502. tede_notice b ON a.MiddleId = b.Id
  503. left JOIN
  504. tede_user c ON b.UserId = c.Id
  505. left JOIN
  506. tede_addressee d ON d.Id = a.MiddleSonId
  507. WHERE a.IsRecall=0 and
  508. a.UserId = {request.UserId} and a.FolderType={noticeTypeValue}
  509. {sb}
  510. ORDER BY a.IsTop desc,a.LastModifiedDate desc,a.AttributeValue desc
  511. LIMIT {(request.Page - 1) * request.PerPage},{request.PerPage}";
  512. var countSql = string.Format(@"SELECT
  513. count(1)
  514. FROM
  515. tede_middle a
  516. left JOIN
  517. tede_notice b ON a.MiddleId = b.Id
  518. left JOIN
  519. tede_user c ON a.UserId = c.Id
  520. left JOIN
  521. tede_addressee d ON d.Id = a.MiddleSonId
  522. WHERE a.IsRecall=0 and
  523. a.UserId = {1} and a.FolderType={2}
  524. {0}", sb, request.UserId, noticeTypeValue);
  525. var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
  526. var database = new Database(databaseType, _connectionString);
  527. var connection = database.GetConnection();
  528. var items = await connection
  529. .QueryAsync<NoticeListPageResult, Notice, User, Addressee, NoticeListPageResult>(sql,
  530. (noticeListPageResult, notice, user, noticeAddressee) =>
  531. {
  532. noticeListPageResult.Title = notice != null ? notice.Title : "";
  533. noticeListPageResult.TypeValue = notice != null ? notice.TypeValue : 0;
  534. noticeListPageResult.SonId = notice != null ? notice.SonId : 0;
  535. noticeListPageResult.Content = notice != null ? notice.Content : "[]";
  536. noticeListPageResult.UserName = user != null ? user.Name : "";
  537. noticeListPageResult.SourceId = notice != null ? notice.SourceId : 0;
  538. noticeListPageResult.AvatarUrl = user != null ? StringUtils.AddDomainMin(user.AvatarUrl) : "";
  539. noticeListPageResult.NoticeAddresseeId = noticeAddressee?.Id ?? 0;
  540. noticeListPageResult.NoticeId = noticeAddressee?.SourceId ?? 0;
  541. return noticeListPageResult;
  542. },
  543. splitOn: "Id,Id,Name,Id");
  544. foreach (var item in items)
  545. {
  546. if (item.AttributeValue == 3)
  547. item.UReadCount = await _adminVerifyRepository.CountAsync(Q.Where(nameof(Entity.AdminVerify.AdminId), request.UserId).Where(nameof(Entity.AdminVerify.DisposeType), AdminVerifyTypeConst.UDispose.GetHashCode()));
  548. }
  549. PagedList<NoticeListPageResult> result = new PagedList<NoticeListPageResult>
  550. {
  551. Total = await CountAsync(countSql),
  552. Items = items
  553. };
  554. return result;
  555. }
  556. public async Task<int> CountAsync(string sql)
  557. {
  558. var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
  559. var database = new Database(databaseType, _connectionString);
  560. var connection = database.GetConnection();
  561. return await connection.ExecuteScalarAsync<int>(sql);
  562. }
  563. public async Task<IEnumerable<Notice>> GetAllAsync()
  564. {
  565. return await _repository.GetAllAsync();
  566. }
  567. public async Task<bool> DeleteAsync(Query query)
  568. {
  569. return await _repository.DeleteAsync(query) > 0;
  570. }
  571. /// <summary>
  572. ///
  573. /// </summary>
  574. /// <returns></returns>
  575. public async Task<List<JobNoticeResult>> ElasticSearchNotice()
  576. {
  577. var sql = "select a.Id,a.UserId,a.GuId,a.CreatedDate,b.Id,b.Title,b.Content,b.CreatedDate,c.Name,c.AvatarUrl from tede_middle a inner join tede_notice b on a.MiddleId=b.Id inner join tede_user c on c.Id=b.UserId where a.FolderType=1 and a.IsUpload=0 order by a.CreatedDate desc limit 0,100";
  578. var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypeStr, DatabaseType.MySql);
  579. var database = new Database(databaseType, _connectionString);
  580. var connection = database.GetConnection();
  581. var items = await connection
  582. .QueryAsync<JobNoticeResult, Notice, User, JobNoticeResult>(sql,
  583. (jobNoticeResult, notice, user) =>
  584. {
  585. jobNoticeResult.MiddleId = jobNoticeResult.Id;
  586. jobNoticeResult.Id = notice.Id;
  587. jobNoticeResult.Title = notice != null ? notice.Title : "";
  588. jobNoticeResult.Content = notice != null ? notice.Content : "";
  589. jobNoticeResult.AvatarUrl = user != null ? user.AvatarUrl : "";
  590. jobNoticeResult.Name = user != null ? user.Name : "";
  591. return jobNoticeResult;
  592. },
  593. splitOn: "Id,Id,Name");
  594. return items.ToList();
  595. }
  596. }
  597. }