NoticeService.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using System.Transactions;
  6. using AutoMapper;
  7. using Datory;
  8. using GxPress.Common.Exceptions;
  9. using GxPress.Common.Page;
  10. using GxPress.Common.Tools;
  11. using GxPress.Entity;
  12. using GxPress.EnumConst;
  13. using GxPress.Repository.Interface;
  14. using GxPress.Request.Analyze;
  15. using GxPress.Request.Notice;
  16. using GxPress.Result;
  17. using GxPress.Result.Notice;
  18. using GxPress.Service.Interface.Analyze;
  19. using GxPress.Service.Interface.Middle;
  20. using GxPress.Service.Interface.Notice;
  21. using GxPress.Service.Interface.Visit;
  22. using Newtonsoft.Json;
  23. using GxPress.Service.Interface.UserMiddle;
  24. using GxPress.Service.Interface.ContentJson;
  25. using GxPress.Service.Interface.CommonSqlKata;
  26. namespace GxPress.Service.Implement.Notice
  27. {
  28. public partial class NoticeService : INoticeService
  29. {
  30. private readonly IUserRepository _userRepository;
  31. private readonly INoticeRepository _noticeRepository;
  32. private readonly ICcRepository _ccRepository;
  33. private readonly IAddresseeRepository _addresseeRepository;
  34. private readonly IDepartmentRepository _departmentRepository;
  35. private readonly IMiddleService _middleService;
  36. private readonly IMiddleRepository _middleRepository;
  37. private readonly IMapper _mapper;
  38. private readonly IAnalyzeService _analyzeService;
  39. private readonly IVisitService _visitService;
  40. private readonly ICommentRepository _commentRepository;
  41. private readonly IUserMiddleService _userMiddleService;
  42. private readonly IContentJsonService _contentJsonService;
  43. private readonly ICommonSqlKataService commonSqlKataService;
  44. public NoticeService(IUserRepository userRepository, IMapper mapper, INoticeRepository noticeRepository,
  45. ICcRepository ccRepository, IAddresseeRepository addresseeRepository,
  46. IDepartmentRepository departmentRepository, IMiddleService middleService,
  47. IMiddleRepository middleRepository, IAnalyzeService analyzeService,
  48. ICommentRepository commentRepository, IVisitService visitService,
  49. IUserMiddleService userMiddleService,
  50. IContentJsonService contentJsonService,
  51. ICommonSqlKataService commonSqlKataService)
  52. {
  53. _noticeRepository = noticeRepository;
  54. _userRepository = userRepository;
  55. _addresseeRepository = addresseeRepository;
  56. _ccRepository = ccRepository;
  57. _departmentRepository = departmentRepository;
  58. _mapper = mapper;
  59. _middleService = middleService;
  60. _middleRepository = middleRepository;
  61. _analyzeService = analyzeService;
  62. _commentRepository = commentRepository;
  63. _visitService = visitService;
  64. _userMiddleService = userMiddleService;
  65. _contentJsonService = contentJsonService;
  66. this.commonSqlKataService = commonSqlKataService;
  67. }
  68. /// <summary>
  69. /// 获取通知的点赞列表
  70. /// </summary>
  71. /// <param name="id"></param>
  72. /// <param name="userId"></param>
  73. /// <returns></returns>
  74. public async Task<NoticeDetailResult> GetNoticeDetailAsync(int id, int userId)
  75. {
  76. var notice = await _noticeRepository.GetAsync(id);
  77. if (notice == null)
  78. throw new BusinessException("通知不存在");
  79. var noticeDetailResult = new Result.Notice.NoticeDetailResult();
  80. var result = _mapper.Map<Result.Notice.NoticeDetailResult>(notice);
  81. //获取新版
  82. result.AddresseeUserMiddles = await _userMiddleService.FindUserMiddlesAsync(10, id);
  83. result.CcUserMiddles = await _userMiddleService.FindUserMiddlesAsync(20, id);
  84. //json
  85. var contentJsonData = JsonConvert.DeserializeObject<List<ContentJsonData>>(result.Content);
  86. foreach (var item in contentJsonData)
  87. item.File = StringUtils.AddDomain(item.File);
  88. result.Data = contentJsonData;
  89. //获取用户
  90. var user = await _userRepository.GetAsync(result.UserId);
  91. result.UserName = user.Name;
  92. result.AllCount = await _addresseeRepository.CountAsync(Q.Where(nameof(Addressee.SourceId), id));
  93. result.ReadCount = await _addresseeRepository.CountAsync(Q.Where(nameof(Addressee.SourceId), id).Where(nameof(Addressee.IsRead), true));
  94. //获取收件人
  95. var noticeAddresseeList =
  96. await _addresseeRepository.GetUserByNoticeIdAsync(id);
  97. result.NoticeAddresseeNames = noticeAddresseeList.Select(n => n.Name).ToList();
  98. var IsRead = await _addresseeRepository.ExistsAsync(Q.Where(nameof(Entity.Middle.Middle.IsRead), true)
  99. .Where(nameof(Addressee.SourceId), id)
  100. .Where(nameof(Addressee.UserId), userId));
  101. //修改阅读量
  102. if (IsRead == false)
  103. {
  104. if (await _addresseeRepository.UpdateAsync(Q.Set(nameof(Entity.Middle.Middle.IsRead), true)
  105. .Where(nameof(Addressee.SourceId), id)
  106. .Where(nameof(Addressee.UserId), userId)))
  107. result.ReadCount++;
  108. }
  109. //修改访问量
  110. await _visitService.AddVisit(userId, 5, id);
  111. //修改middle的阅读
  112. // await _middleRepository.UpdateAsync(Q.Set(nameof(Entity.Middle.Middle.IsRead), true).Where(nameof(Entity.Middle.Middle.UserId), userId).Where(nameof(Entity.Middle.Middle.MiddleId), id).Where(nameof(Entity.Middle.Middle.FolderType), 1));
  113. var analyzeRequest = new Request.App.Analyze.AnalyzeRequest();
  114. analyzeRequest.TypeValue = GxPress.EnumConst.AllTypeConst.Notice.GetHashCode();
  115. analyzeRequest.AnalyzeType = 1;
  116. analyzeRequest.SourceId = id;
  117. analyzeRequest.UserId = userId;
  118. //点赞数量
  119. result.PraiseCount = await _analyzeService.CountAsync(analyzeRequest);
  120. //获取话题的评论数量
  121. var commentCount =
  122. await _commentRepository.CountAsync(Q.Where(nameof(Entity.Comment.ArticleId), id).Where(nameof(Entity.Comment.TypeValue), analyzeRequest.TypeValue).Where(nameof(Entity.Comment.Pid), 0));
  123. result.CommentCount = commentCount;
  124. //获取话题的转发数量
  125. analyzeRequest.AnalyzeType = 4;
  126. var retransmissionCount = await _analyzeService.CountAsync(analyzeRequest);
  127. result.RetransmissionCount = retransmissionCount;
  128. result.IsRetransmission = await _analyzeService.ExistsAsync(analyzeRequest);
  129. //获取话题的收藏数量
  130. analyzeRequest.AnalyzeType = 3;
  131. var collectCount = await _analyzeService.CountAsync(analyzeRequest);
  132. result.CollectCount = collectCount;
  133. //是否收藏
  134. result.IsCollect = await _analyzeService.ExistsAsync(analyzeRequest);
  135. //获取话题的点赞数量
  136. analyzeRequest.AnalyzeType = 1;
  137. var praiseCount = await _analyzeService.CountAsync(analyzeRequest);
  138. result.PraiseCount = praiseCount;
  139. //是否点赞
  140. result.IsPraise = await _analyzeService.ExistsAsync(analyzeRequest);
  141. var request = new PraisePageSearchRequest { SourceId = id, TypeValue = AllTypeConst.Notice.GetHashCode(), Page = 1, PerPage = 3 };
  142. result.NoticePraisePagedList = await _analyzeService.GetPraisePageAsync(request);
  143. //是否是当前用户创建
  144. result.IsAdmin = notice.UserId == userId;
  145. return result;
  146. }
  147. /// <summary>
  148. /// 根据通知ID获取通知详情
  149. /// </summary>
  150. /// <param name="request"></param>
  151. /// <returns></returns>
  152. public async Task<NoticeEditDetailResult> NoticeEditDetailAsync(int id)
  153. {
  154. var notice = await _noticeRepository.GetAsync(id);
  155. var result = _mapper.Map<NoticeEditDetailResult>(notice);
  156. //抄送人
  157. var noticeCcList = await _ccRepository.GetNoticeCcByNoticeIdAsync(id, GxPress.EnumConst.FolderTypeConst.Notice.GetHashCode());
  158. //收件人
  159. var noticeAddressee = await _addresseeRepository.GetNoticeAddresseeByNoticeIdAsync(id);
  160. //获取新版
  161. result.AddresseeUserMiddles = await _userMiddleService.FindUserMiddlesAsync(10, id);
  162. result.CcUserMiddles = await _userMiddleService.FindUserMiddlesAsync(20, id);
  163. var noticeAddresseeUsers =
  164. await _userRepository.UserListInsAsync(noticeAddressee.Select(n => n.UserId).ToList());
  165. result.NoticeAddresseeUsers =
  166. noticeAddresseeUsers.Select(n => _mapper.Map<NoticeAddresseeUser>(n)).ToList();
  167. var noticeCcUsers = await _userRepository.UserListInsAsync(noticeCcList.Select(n => n.UserId).ToList());
  168. result.NoticeCcUsers = noticeCcUsers.Select(n => _mapper.Map<NoticeCcUser>(n)).ToList();
  169. foreach (var noticeAddresseeUser in result.NoticeAddresseeUsers)
  170. {
  171. noticeAddresseeUser.AvatarUrl = StringUtils.AddDomainMin(noticeAddresseeUser.AvatarUrl);
  172. }
  173. foreach (var noticeCcUser in result.NoticeCcUsers)
  174. {
  175. noticeCcUser.AvatarUrl = StringUtils.AddDomainMin(noticeCcUser.AvatarUrl);
  176. }
  177. var jsonData = JsonConvert.DeserializeObject<List<ContentJsonData>>(result.Content);
  178. foreach (var item in jsonData)
  179. item.File = StringUtils.AddDomain(item.File);
  180. result.Data = jsonData;
  181. return result;
  182. }
  183. /// <summary>
  184. /// 获取通知详情
  185. /// </summary>
  186. /// <param name="request"></param>
  187. /// <returns></returns>
  188. public async Task<Result.Notice.NoticeDetailResult> GetNoticeDetailResultAsync(int id, int userId)
  189. {
  190. var notice = await _noticeRepository.GetAsync(id);
  191. if (notice == null)
  192. throw new BusinessException("通知不存在");
  193. var noticeDetailResult = new Result.Notice.NoticeDetailResult();
  194. var result = _mapper.Map<Result.Notice.NoticeDetailResult>(notice);
  195. //获取新版
  196. result.AddresseeUserMiddles = await _userMiddleService.FindUserMiddlesAsync(10, id);
  197. result.CcUserMiddles = await _userMiddleService.FindUserMiddlesAsync(20, id);
  198. //json
  199. var contentJsonData = JsonConvert.DeserializeObject<List<ContentJsonData>>(result.Content);
  200. foreach (var item in contentJsonData)
  201. item.File = StringUtils.AddDomain(item.File);
  202. result.Data = contentJsonData;
  203. //获取用户
  204. var user = await _userRepository.GetAsync(result.UserId);
  205. result.UserName = user.Name;
  206. result.AllCount =
  207. await _addresseeRepository.CountAsync(Q.Where(nameof(Addressee.SourceId), id));
  208. result.ReadCount = await _addresseeRepository.CountAsync(Q
  209. .Where(nameof(Addressee.SourceId), id).Where(nameof(Addressee.IsRead), true));
  210. //获取收件人
  211. var noticeAddresseeList =
  212. await _addresseeRepository.GetAllAsync(Q.Where(nameof(Addressee.SourceId), id)
  213. .Where(nameof(Entity.Middle.Middle.IsAdmin), false));
  214. result.NoticeAddresseeNames = noticeAddresseeList.Select(n => n.UserName).ToList();
  215. //修改阅读量
  216. await _addresseeRepository.UpdateAsync(Q.Set(nameof(Entity.Middle.Middle.IsRead), true)
  217. .Where(nameof(Addressee.SourceId), id)
  218. .Where(nameof(Addressee.UserId), userId));
  219. //修改middle的阅读
  220. await _middleRepository.UpdateAsync(Q.Set(nameof(Entity.Middle.Middle.IsRead), true).Where(nameof(Entity.Middle.Middle.UserId), userId).Where(nameof(Entity.Middle.Middle.MiddleId), id).Where(nameof(Entity.Middle.Middle.FolderType), 1));
  221. var analyzeRequest = new Request.App.Analyze.AnalyzeRequest();
  222. analyzeRequest.TypeValue = 2;
  223. analyzeRequest.AnalyzeType = 1;
  224. analyzeRequest.SourceId = id;
  225. analyzeRequest.UserId = userId;
  226. //点赞数量
  227. result.PraiseCount = await _analyzeService.CountAsync(analyzeRequest);
  228. //获取话题的评论数量
  229. var commentCount =
  230. await _commentRepository.CountAsync(Q.Where(nameof(Entity.Comment.ArticleId), id).Where(nameof(Entity.Comment.TypeValue), 1));
  231. result.CommentCount = commentCount;
  232. //获取话题的转发数量
  233. analyzeRequest.AnalyzeType = 4;
  234. var retransmissionCount = await _analyzeService.CountAsync(analyzeRequest);
  235. result.RetransmissionCount = retransmissionCount;
  236. result.IsRetransmission = await _analyzeService.ExistsAsync(analyzeRequest);
  237. //获取话题的收藏数量
  238. analyzeRequest.AnalyzeType = 3;
  239. var collectCount = await _analyzeService.CountAsync(analyzeRequest);
  240. result.CollectCount = collectCount;
  241. //是否收藏
  242. result.IsCollect = await _analyzeService.ExistsAsync(analyzeRequest);
  243. //获取话题的点赞数量
  244. analyzeRequest.AnalyzeType = 1;
  245. var praiseCount = await _analyzeService.CountAsync(analyzeRequest);
  246. result.PraiseCount = praiseCount;
  247. //是否点赞
  248. result.IsPraise = await _analyzeService.ExistsAsync(analyzeRequest);
  249. return result;
  250. }
  251. /// <summary>
  252. /// 编辑通知
  253. /// </summary>
  254. /// <param name="request"></param>
  255. /// <returns></returns>
  256. public async Task<bool> NoticeUpAsync(NoticeUpRequest request)
  257. {
  258. try
  259. {
  260. using (TransactionScope transactionScope = new TransactionScope())
  261. {
  262. var notice = await _noticeRepository.GetAsync(request.Id);
  263. if (notice == null)
  264. throw new BusinessException("通知不存在");
  265. var noticeInRequest = new NoticeInRequest();
  266. noticeInRequest.Content = request.Content;
  267. noticeInRequest.HtmlContent = request.HtmlContent;
  268. noticeInRequest.NoticeType = request.NoticeType;
  269. noticeInRequest.AddresseeUserMiddles = request.AddresseeUserMiddles;
  270. noticeInRequest.CcUserMiddles = request.CcUserMiddles;
  271. noticeInRequest.Title = request.Title;
  272. noticeInRequest.UserId = request.UserId;
  273. noticeInRequest.SoureId = 0;
  274. noticeInRequest.Id = request.Id;
  275. if (request.NoticeType == NoticeTypeConst.Send)
  276. {
  277. if (notice.NoticeType == NoticeTypeConst.Draft)
  278. {
  279. //删除
  280. await _noticeRepository.DeleteAsync(Q.Where(nameof(Entity.Notice.Id), notice.Id));
  281. //删除middle
  282. await _middleRepository.DeleteAsync(notice.Id, GxPress.EnumConst.FolderTypeConst.Notice.GetHashCode());
  283. if (notice.SourceId > 0)
  284. {
  285. var noticeSource = await _noticeRepository.GetAsync(notice.SourceId);
  286. if (noticeSource != null)
  287. noticeInRequest.Id = noticeSource.Id;
  288. else
  289. noticeInRequest.Id = 0;
  290. }
  291. else
  292. noticeInRequest.Id = 0;
  293. }
  294. }
  295. else
  296. {
  297. if (notice.NoticeType == NoticeTypeConst.Draft)
  298. noticeInRequest.Id = request.Id;
  299. else
  300. {
  301. noticeInRequest.SoureId = notice.Id;
  302. var noticeSource = await _noticeRepository.GetAsync(Q.Where(nameof(Entity.Notice.SourceId), notice.Id));
  303. if (noticeSource != null)
  304. noticeInRequest.Id = noticeSource.Id;
  305. else noticeInRequest.Id = 0;
  306. }
  307. }
  308. await InsertAsync(noticeInRequest);
  309. transactionScope.Complete();
  310. }
  311. }
  312. catch (Exception e)
  313. {
  314. Console.WriteLine(e);
  315. throw;
  316. }
  317. return true;
  318. }
  319. /// <summary>
  320. /// 根据已读未读查询通知数据
  321. /// </summary>
  322. /// <param name="request"></param>
  323. /// <returns></returns>
  324. public async Task<IEnumerable<NoticeReadListResult>> NoticeReadListAsync(NoticeReadListRequest request)
  325. {
  326. var noticeReadListResults = await _addresseeRepository.GetNoticeAddresseeByUserIdIdAsync(request);
  327. return noticeReadListResults;
  328. }
  329. /// <summary>
  330. /// 获取通知列表
  331. /// </summary>
  332. /// <param name="request"></param>
  333. /// <returns></returns>
  334. public async Task<PagedList<NoticeListPageResult>> GetNoticeListPageAsync(NoticePageSearchRequest request)
  335. {
  336. var noticeTypeValue = GxPress.EnumConst.AllTypeConst.Inbox.GetHashCode();
  337. var query = new SqlKata.Query("tede_middle");
  338. query.LeftJoin("tede_notice", "tede_notice.Id", "tede_middle.MiddleId");
  339. query.LeftJoin("tede_user", "tede_user.Id", "tede_notice.UserId");
  340. query.LeftJoin("tede_addressee", "tede_addressee.Id", "tede_middle.MiddleSonId");
  341. if (request.SearchType == 1)
  342. {
  343. query.Where("tede_middle.IsAdmin", true);
  344. query.Where("tede_middle.NoticeAddresseeType", 1);
  345. query.Where("tede_middle.IsDelete", false);
  346. }
  347. else if (request.SearchType == 2)
  348. {
  349. query.Where("tede_middle.AttributeValue", 1);
  350. query.Where("tede_middle.NoticeAddresseeType", 2);
  351. query.Where("tede_middle.IsDelete", false);
  352. }
  353. else if (request.SearchType == 3)
  354. {
  355. query.Where("tede_middle.AttributeValue", 1);
  356. query.Where("tede_middle.IsDelete", true);
  357. }
  358. else if (request.SearchType > 3)
  359. {
  360. if (request.SearchType == 16)
  361. {
  362. query.WhereIn("tede_notice.TypeValue", new List<int> { AllTypeConst.Notice.GetHashCode(), AllTypeConst.Missive.GetHashCode(), request.SearchType, AllTypeConst.Anonymity.GetHashCode() });
  363. query.Where("tede_middle.IsAdmin", true);
  364. }
  365. else
  366. query.Where("tede_notice.TypeValue", request.SearchType);
  367. query.WhereNot("tede_middle.NoticeAddresseeType", 2);
  368. query.Where("tede_middle.IsDelete", false);
  369. }
  370. else
  371. {
  372. query.WhereNot("tede_middle.NoticeAddresseeType", 2);
  373. query.Where("tede_middle.IsDelete", false);
  374. }
  375. if (!string.IsNullOrEmpty(request.Keyword))
  376. {
  377. if (request.NoticeFolderId > 0)
  378. query.Where("tede_middle.ParentId", request.NoticeFolderId);
  379. var sourceIdQuery = new SqlKata.Query("tede_addressee");
  380. sourceIdQuery.Join("tede_user", "tede_user.Id", "tede_addressee.UserId");
  381. sourceIdQuery.WhereColumns("tede_addressee.SourceId", "=", "tede_middle.MiddleId");
  382. sourceIdQuery.WhereLike("tede_user.Name", $"%{request.Keyword}%");
  383. sourceIdQuery.Select("tede_addressee.SourceId");
  384. query.WhereNot("tede_middle.AttributeValue", 2);
  385. query.Where(n => n.OrWhereLike("tede_notice.Title", $"%{request.Keyword}%").OrWhereLike("tede_notice.Content", $"%{request.Keyword}%")
  386. .OrWhere(n => n.WhereIn("tede_middle.MiddleId", sourceIdQuery)));
  387. }
  388. else
  389. {
  390. var searchList = new List<int> { 1, 2, 3 };
  391. if (!searchList.Contains(request.SearchType))
  392. query.Where("tede_middle.ParentId", request.NoticeFolderId);
  393. }
  394. query.Where("tede_middle.IsRecall", false);
  395. query.Where("tede_middle.UserId", request.UserId);
  396. query.Where("tede_middle.FolderType", noticeTypeValue);
  397. //条数
  398. var countQuery = query;
  399. //收件箱
  400. query = commonSqlKataService.NoticeQueryAsync(query, request.UserId);
  401. //通用
  402. query = commonSqlKataService.GetCommonQueryAsync(noticeTypeValue, request.UserId, query);
  403. query.OrderByDesc("tede_middle.AttributeValue");
  404. query.OrderByDesc("tede_middle.IsTop");
  405. query.OrderByDesc("tede_middle.LastModifiedDate");
  406. //query.OrderByDesc("tede_middle.Sort");
  407. query.ForPage(request.Page, request.PerPage);
  408. query.Select(
  409. "tede_middle.Id", "tede_middle.MiddleId", "tede_middle.IsTop", "tede_middle.AttributeValue", "tede_middle.FolderName", "tede_middle.CreatedDate"
  410. , "tede_notice.{UserId,UserName,SourceId,Title,Content,TypeValue,IsRecall}"
  411. , "tede_user.{AvatarUrl}"
  412. , "tede_addressee.{Id as NoticeAddresseeId, SourceId as NoticeId}");
  413. var result = await _noticeRepository.GetNoticeListPageAsync(query, countQuery);
  414. foreach (var item in result.Items)
  415. {
  416. item.IsAdmin = item.UserId == request.UserId;
  417. var typeValueIds = new List<int>{AllTypeConst.MyChecked.GetHashCode()
  418. ,AllTypeConst.MyCc.GetHashCode(),AllTypeConst.MySubmitted.GetHashCode()};
  419. if (typeValueIds.Contains(item.TypeValue))
  420. {
  421. item.IsAdmin = item.IsFlowAdmin;
  422. item.TodoId = item.SonId;
  423. item.MiddleId = item.SourceId;
  424. //item.UserName = item.SendUserName;
  425. item.ReadCount = item.CheckedCount + 1;
  426. item.AllCount = item.UCheckedCount + 1;
  427. item.EnjoyUser = item.FlowUserName;
  428. //我发起的
  429. if (item.TypeValue == AllTypeConst.MySubmitted.GetHashCode())
  430. item.IsRead = true;
  431. //我抄送
  432. if (item.TypeValue == AllTypeConst.MyCc.GetHashCode())
  433. item.IsRead = true;
  434. //我审批
  435. if (item.TypeValue == AllTypeConst.MyChecked.GetHashCode())
  436. item.IsRead = item.IsFlowChecked;
  437. if (item.IsDone && item.IsChecked)
  438. item.FlowState = FlowState.Checked;
  439. else if (item.IsDone && !item.IsChecked)
  440. {
  441. if (item.DoneType == 1)
  442. item.FlowState = FlowState.Meeting;
  443. else if (item.DoneType == 2)
  444. item.FlowState = FlowState.Wait;
  445. else
  446. item.FlowState = FlowState.Denied;
  447. }
  448. else if (item.IsDone && !item.IsChecked)
  449. item.FlowState = FlowState.Denied;
  450. else
  451. {
  452. item.FlowState = FlowState.Checking;
  453. }
  454. }
  455. item.Title = _contentJsonService.GetTitile(item.Title, item.Content);
  456. if (request.SearchType == 3)
  457. item.NoticeStatus = 0;
  458. else if (request.SearchType == 2)
  459. item.NoticeStatus = 2;
  460. else
  461. item.NoticeStatus = 1;
  462. }
  463. return result;
  464. }
  465. /// <summary>
  466. /// 撤销通知
  467. /// </summary>
  468. /// <param name="id"></param>
  469. /// <returns></returns>
  470. public async Task<bool> RecallAsync(int id)
  471. {
  472. try
  473. {
  474. using (TransactionScope transactionScope = new TransactionScope())
  475. {
  476. var query = Q.NewQuery();
  477. //修改通知
  478. await _noticeRepository.UpdateAsync(Q.Where(nameof(Entity.Notice.Id), id).Set(nameof(Entity.Notice.IsRecall), true));
  479. //删除middle
  480. query.Where(nameof(Entity.Middle.Middle.MiddleId), id);
  481. query.Where(nameof(Entity.Middle.Middle.FolderType), GxPress.EnumConst.AllTypeConst.Inbox.GetHashCode());
  482. query.Where(nameof(Entity.Middle.Middle.IsAdmin), false);
  483. //query.Set(nameof(Entity.Middle.Middle.IsRecall), true);
  484. await _middleRepository.DeleteAsync(query);
  485. // //修改middle
  486. // query = Q.NewQuery();
  487. // query.Where(nameof(Entity.Middle.Middle.MiddleId), id);
  488. // query.Where(nameof(Entity.Middle.Middle.FolderType), GxPress.EnumConst.AllTypeConst.Inbox.GetHashCode());
  489. // query.Where(nameof(Entity.Middle.Middle.IsAdmin), true);
  490. // query.Set(nameof(Entity.Middle.Middle.IsRecall), true);
  491. // await _middleRepository.UpdateAsync(query);
  492. // //修改为草稿箱
  493. // query = Q.NewQuery();
  494. // query.Where(nameof(Entity.Middle.Middle.MiddleId), id);
  495. // query.Where(nameof(Entity.Middle.Middle.FolderType), GxPress.EnumConst.FolderTypeConst.Notice.GetHashCode());
  496. // query.Where(nameof(Entity.Middle.Middle.IsAdmin), true);
  497. // query.Set(nameof(Entity.Middle.Middle.NoticeAddresseeType), 2);
  498. // await _middleRepository.UpdateAsync(query);
  499. //修改未撤回状态
  500. await _noticeRepository.UpdateAsync(Q.Where(nameof(Entity.Notice.Id), id).Set(nameof(Entity.Notice.NoticeType), NoticeTypeConst.Draft.GetHashCode()));
  501. transactionScope.Complete();
  502. }
  503. }
  504. catch (System.Exception ex)
  505. {
  506. throw new BusinessException(ex.Message);
  507. }
  508. return true;
  509. }
  510. }
  511. }