NoticeService.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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.App.Middle;
  16. using GxPress.Request.Notice;
  17. using GxPress.Result;
  18. using GxPress.Result.Notice;
  19. using GxPress.Service.Interface.Analyze;
  20. using GxPress.Service.Interface.Middle;
  21. using GxPress.Service.Interface.Notice;
  22. using GxPress.Service.Interface.Visit;
  23. using Newtonsoft.Json;
  24. using GxPress.Service.Interface.UserMiddle;
  25. namespace GxPress.Service.Implement.Notice
  26. {
  27. public partial class NoticeService : INoticeService
  28. {
  29. private readonly IUserRepository _userRepository;
  30. private readonly INoticeRepository _noticeRepository;
  31. private readonly INoticeCcRepository _noticeCcRepository;
  32. private readonly INoticeAddresseeRepository _noticeAddresseeRepository;
  33. private readonly IDepartmentRepository _departmentRepository;
  34. private readonly IMiddleService _middleService;
  35. private readonly IMiddleRepository _middleRepository;
  36. private readonly IMapper _mapper;
  37. private readonly IAnalyzeService _analyzeService;
  38. private readonly IVisitService _visitService;
  39. private readonly ICommentRepository _commentRepository;
  40. private readonly IUserMiddleService _userMiddleService;
  41. public NoticeService(IUserRepository userRepository, IMapper mapper, INoticeRepository noticeRepository,
  42. INoticeCcRepository noticeCcRepository, INoticeAddresseeRepository noticeAddresseeRepository,
  43. IDepartmentRepository departmentRepository, IMiddleService middleService,
  44. IMiddleRepository middleRepository, IAnalyzeService analyzeService, ICommentRepository commentRepository, IVisitService visitService, IUserMiddleService userMiddleService)
  45. {
  46. _noticeRepository = noticeRepository;
  47. _userRepository = userRepository;
  48. _noticeAddresseeRepository = noticeAddresseeRepository;
  49. _noticeCcRepository = noticeCcRepository;
  50. _departmentRepository = departmentRepository;
  51. _mapper = mapper;
  52. _middleService = middleService;
  53. _middleRepository = middleRepository;
  54. _analyzeService = analyzeService;
  55. _commentRepository = commentRepository;
  56. _visitService = visitService;
  57. _userMiddleService = userMiddleService;
  58. }
  59. /// <summary>
  60. /// 获取通知的点赞列表
  61. /// </summary>
  62. /// <param name="id"></param>
  63. /// <param name="userId"></param>
  64. /// <returns></returns>
  65. public async Task<NoticeDetailResult> GetNoticeDetailAsync(int id, int userId)
  66. {
  67. var notice = await _noticeRepository.GetAsync(id);
  68. if (notice == null)
  69. throw new BusinessException("通知不存在");
  70. var noticeDetailResult = new Result.Notice.NoticeDetailResult();
  71. var result = _mapper.Map<Result.Notice.NoticeDetailResult>(notice);
  72. //获取新版
  73. result.AddresseeUserMiddles = await _userMiddleService.FindUserMiddlesAsync(10, id);
  74. result.CcUserMiddles = await _userMiddleService.FindUserMiddlesAsync(20, id);
  75. //json
  76. var contentJsonData = JsonConvert.DeserializeObject<List<ContentJsonData>>(result.Content);
  77. foreach (var item in contentJsonData)
  78. item.File = StringUtils.AddDomain(item.File);
  79. result.Data = contentJsonData;
  80. //获取用户
  81. var user = await _userRepository.GetAsync(result.UserId);
  82. result.UserName = user.Name;
  83. result.AllCount = await _noticeAddresseeRepository.CountAsync(Q.Where(nameof(NoticeAddressee.NoticeId), id));
  84. result.ReadCount = await _noticeAddresseeRepository.CountAsync(Q.Where(nameof(NoticeAddressee.NoticeId), id).Where(nameof(NoticeAddressee.IsRead), true));
  85. //获取收件人
  86. var noticeAddresseeList =
  87. await _noticeAddresseeRepository.GetUserByNoticeIdAsync(id);
  88. result.NoticeAddresseeNames = noticeAddresseeList.Select(n => n.Name).ToList();
  89. var IsRead = await _noticeAddresseeRepository.ExistsAsync(Q.Where(nameof(Entity.Middle.Middle.IsRead), true)
  90. .Where(nameof(NoticeAddressee.NoticeId), id)
  91. .Where(nameof(NoticeAddressee.UserId), userId));
  92. //修改阅读量
  93. if (IsRead == false)
  94. {
  95. if (await _noticeAddresseeRepository.UpdateAsync(Q.Set(nameof(Entity.Middle.Middle.IsRead), true)
  96. .Where(nameof(NoticeAddressee.NoticeId), id)
  97. .Where(nameof(NoticeAddressee.UserId), userId)))
  98. result.ReadCount++;
  99. }
  100. //修改访问量
  101. await _visitService.AddVisit(userId, 5, id);
  102. //修改middle的阅读
  103. // 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));
  104. var analyzeRequest = new Request.App.Analyze.AnalyzeRequest();
  105. analyzeRequest.TypeValue = 2;
  106. analyzeRequest.AnalyzeType = 1;
  107. analyzeRequest.SourceId = id;
  108. analyzeRequest.UserId = userId;
  109. //点赞数量
  110. result.PraiseCount = await _analyzeService.CountAsync(analyzeRequest);
  111. //获取话题的评论数量
  112. var commentCount =
  113. await _commentRepository.CountAsync(Q.Where(nameof(Entity.Comment.ArticleId), id).Where(nameof(Entity.Comment.TypeValue), analyzeRequest.TypeValue).Where(nameof(Entity.Comment.Pid), 0));
  114. result.CommentCount = commentCount;
  115. //获取话题的转发数量
  116. analyzeRequest.AnalyzeType = 4;
  117. var retransmissionCount = await _analyzeService.CountAsync(analyzeRequest);
  118. result.RetransmissionCount = retransmissionCount;
  119. result.IsRetransmission = await _analyzeService.ExistsAsync(analyzeRequest);
  120. //获取话题的收藏数量
  121. analyzeRequest.AnalyzeType = 3;
  122. var collectCount = await _analyzeService.CountAsync(analyzeRequest);
  123. result.CollectCount = collectCount;
  124. //是否收藏
  125. result.IsCollect = await _analyzeService.ExistsAsync(analyzeRequest);
  126. //获取话题的点赞数量
  127. analyzeRequest.AnalyzeType = 1;
  128. var praiseCount = await _analyzeService.CountAsync(analyzeRequest);
  129. result.PraiseCount = praiseCount;
  130. //是否点赞
  131. result.IsPraise = await _analyzeService.ExistsAsync(analyzeRequest);
  132. var request = new PraisePageSearchRequest { SourceId = id, TypeValue = 2, Page = 1, PerPage = 3 };
  133. result.NoticePraisePagedList = await _analyzeService.GetPraisePageAsync(request);
  134. //是否是当前用户创建
  135. result.IsAdmin = notice.UserId == userId;
  136. return result;
  137. }
  138. /// <summary>
  139. /// 根据通知ID获取通知详情
  140. /// </summary>
  141. /// <param name="request"></param>
  142. /// <returns></returns>
  143. public async Task<NoticeEditDetailResult> NoticeEditDetailAsync(int id)
  144. {
  145. var notice = await _noticeRepository.GetAsync(id);
  146. var result = _mapper.Map<NoticeEditDetailResult>(notice);
  147. //抄送人
  148. var noticeCcList = await _noticeCcRepository.GetNoticeCcByNoticeIdAsync(id);
  149. //收件人
  150. var noticeAddressee = await _noticeAddresseeRepository.GetNoticeAddresseeByNoticeIdAsync(id);
  151. //获取新版
  152. result.AddresseeUserMiddles = await _userMiddleService.FindUserMiddlesAsync(10, id);
  153. result.CcUserMiddles = await _userMiddleService.FindUserMiddlesAsync(20, id);
  154. var noticeAddresseeUsers =
  155. await _userRepository.UserListInsAsync(noticeAddressee.Select(n => n.UserId).ToList());
  156. result.NoticeAddresseeUsers =
  157. noticeAddresseeUsers.Select(n => _mapper.Map<NoticeAddresseeUser>(n)).ToList();
  158. var noticeCcUsers = await _userRepository.UserListInsAsync(noticeCcList.Select(n => n.UserId).ToList());
  159. result.NoticeCcUsers = noticeCcUsers.Select(n => _mapper.Map<NoticeCcUser>(n)).ToList();
  160. foreach (var noticeAddresseeUser in result.NoticeAddresseeUsers)
  161. {
  162. noticeAddresseeUser.AvatarUrl = StringUtils.AddDomainMin(noticeAddresseeUser.AvatarUrl);
  163. }
  164. foreach (var noticeCcUser in result.NoticeCcUsers)
  165. {
  166. noticeCcUser.AvatarUrl = StringUtils.AddDomainMin(noticeCcUser.AvatarUrl);
  167. }
  168. var jsonData = JsonConvert.DeserializeObject<List<ContentJsonData>>(result.Content);
  169. foreach (var item in jsonData)
  170. item.File = StringUtils.AddDomain(item.File);
  171. result.Data = jsonData;
  172. return result;
  173. }
  174. /// <summary>
  175. /// 获取通知详情
  176. /// </summary>
  177. /// <param name="request"></param>
  178. /// <returns></returns>
  179. public async Task<Result.Notice.NoticeDetailResult> GetNoticeDetailResultAsync(int id, int userId)
  180. {
  181. var notice = await _noticeRepository.GetAsync(id);
  182. if (notice == null)
  183. throw new BusinessException("通知不存在");
  184. var noticeDetailResult = new Result.Notice.NoticeDetailResult();
  185. var result = _mapper.Map<Result.Notice.NoticeDetailResult>(notice);
  186. //获取新版
  187. result.AddresseeUserMiddles = await _userMiddleService.FindUserMiddlesAsync(10, id);
  188. result.CcUserMiddles = await _userMiddleService.FindUserMiddlesAsync(20, id);
  189. //json
  190. var contentJsonData = JsonConvert.DeserializeObject<List<ContentJsonData>>(result.Content);
  191. foreach (var item in contentJsonData)
  192. item.File = StringUtils.AddDomain(item.File);
  193. result.Data = contentJsonData;
  194. //获取用户
  195. var user = await _userRepository.GetAsync(result.UserId);
  196. result.UserName = user.Name;
  197. result.AllCount =
  198. await _noticeAddresseeRepository.CountAsync(Q.Where(nameof(NoticeAddressee.NoticeId), id));
  199. result.ReadCount = await _noticeAddresseeRepository.CountAsync(Q
  200. .Where(nameof(NoticeAddressee.NoticeId), id).Where(nameof(NoticeAddressee.IsRead), true));
  201. //获取收件人
  202. var noticeAddresseeList =
  203. await _noticeAddresseeRepository.GetAllAsync(Q.Where(nameof(NoticeAddressee.NoticeId), id)
  204. .Where(nameof(Entity.Middle.Middle.IsAdmin), false));
  205. result.NoticeAddresseeNames = noticeAddresseeList.Select(n => n.UserName).ToList();
  206. //修改阅读量
  207. await _noticeAddresseeRepository.UpdateAsync(Q.Set(nameof(Entity.Middle.Middle.IsRead), true)
  208. .Where(nameof(NoticeAddressee.NoticeId), id)
  209. .Where(nameof(NoticeAddressee.UserId), userId));
  210. //修改middle的阅读
  211. 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));
  212. var analyzeRequest = new Request.App.Analyze.AnalyzeRequest();
  213. analyzeRequest.TypeValue = 2;
  214. analyzeRequest.AnalyzeType = 1;
  215. analyzeRequest.SourceId = id;
  216. analyzeRequest.UserId = userId;
  217. //点赞数量
  218. result.PraiseCount = await _analyzeService.CountAsync(analyzeRequest);
  219. //获取话题的评论数量
  220. var commentCount =
  221. await _commentRepository.CountAsync(Q.Where(nameof(Entity.Comment.ArticleId), id).Where(nameof(Entity.Comment.TypeValue), 1));
  222. result.CommentCount = commentCount;
  223. //获取话题的转发数量
  224. analyzeRequest.AnalyzeType = 4;
  225. var retransmissionCount = await _analyzeService.CountAsync(analyzeRequest);
  226. result.RetransmissionCount = retransmissionCount;
  227. result.IsRetransmission = await _analyzeService.ExistsAsync(analyzeRequest);
  228. //获取话题的收藏数量
  229. analyzeRequest.AnalyzeType = 3;
  230. var collectCount = await _analyzeService.CountAsync(analyzeRequest);
  231. result.CollectCount = collectCount;
  232. //是否收藏
  233. result.IsCollect = await _analyzeService.ExistsAsync(analyzeRequest);
  234. //获取话题的点赞数量
  235. analyzeRequest.AnalyzeType = 1;
  236. var praiseCount = await _analyzeService.CountAsync(analyzeRequest);
  237. result.PraiseCount = praiseCount;
  238. //是否点赞
  239. result.IsPraise = await _analyzeService.ExistsAsync(analyzeRequest);
  240. return result;
  241. }
  242. /// <summary>
  243. /// 编辑通知
  244. /// </summary>
  245. /// <param name="request"></param>
  246. /// <returns></returns>
  247. public async Task<bool> NoticeUpAsync(NoticeUpRequest request)
  248. {
  249. try
  250. {
  251. using (TransactionScope transactionScope = new TransactionScope())
  252. {
  253. var notice = await _noticeRepository.GetAsync(request.Id);
  254. if (notice == null)
  255. throw new BusinessException("通知不存在");
  256. var noticeInRequest = new NoticeInRequest();
  257. noticeInRequest.Content = request.Content;
  258. noticeInRequest.HtmlContent = request.HtmlContent;
  259. noticeInRequest.NoticeType = request.NoticeType;
  260. noticeInRequest.AddresseeUserMiddles = request.AddresseeUserMiddles;
  261. noticeInRequest.CcUserMiddles = request.CcUserMiddles;
  262. noticeInRequest.Title = request.Title;
  263. noticeInRequest.UserId = request.UserId;
  264. noticeInRequest.SoureId = 0;
  265. noticeInRequest.Id = request.Id;
  266. if (request.NoticeType == NoticeTypeConst.Send)
  267. {
  268. if (notice.NoticeType == NoticeTypeConst.Draft)
  269. {
  270. //删除
  271. await _noticeRepository.DeleteAsync(Q.Where(nameof(Entity.Notice.Id), notice.Id));
  272. //删除middle
  273. await _middleRepository.DeleteAsync(Q.Where(nameof(Entity.Middle.Middle.MiddleId), notice.Id).Where(nameof(Entity.Middle.Middle.FolderType), 1));
  274. if (notice.SourceId > 0)
  275. {
  276. var noticeSource = await _noticeRepository.GetAsync(notice.SourceId);
  277. if (noticeSource != null)
  278. noticeInRequest.Id = noticeSource.Id;
  279. else
  280. noticeInRequest.Id = 0;
  281. }
  282. else
  283. noticeInRequest.Id = 0;
  284. }
  285. }
  286. else
  287. {
  288. if (notice.NoticeType == NoticeTypeConst.Draft)
  289. noticeInRequest.Id = request.Id;
  290. else
  291. {
  292. noticeInRequest.SoureId = notice.Id;
  293. var noticeSource = await _noticeRepository.GetAsync(Q.Where(nameof(Entity.Notice.SourceId), notice.Id));
  294. if (noticeSource != null)
  295. noticeInRequest.Id = noticeSource.Id;
  296. else noticeInRequest.Id = 0;
  297. }
  298. }
  299. await InsertAsync(noticeInRequest);
  300. transactionScope.Complete();
  301. }
  302. }
  303. catch (Exception e)
  304. {
  305. Console.WriteLine(e);
  306. throw;
  307. }
  308. return true;
  309. }
  310. /// <summary>
  311. /// 发送通知
  312. /// </summary>
  313. /// <param name="request"></param>
  314. /// <returns></returns>
  315. public async Task<bool> SendNoticeAsync(NoticeUpRequest request)
  316. {
  317. if (request.AddresseeUserMiddles.Count > 0)
  318. {
  319. await _userMiddleService.DeleteAsync(Q.Where(nameof(Entity.UserMiddle.UserMiddle.MiddleType), 10).Where(nameof(Entity.UserMiddle.UserMiddle.DataSourceId), request.Id));
  320. foreach (var item in request.AddresseeUserMiddles)
  321. {
  322. item.DataSourceId = request.Id;
  323. item.MiddleType = 10;
  324. }
  325. await _userMiddleService.AddUserMiddleAsync(request.AddresseeUserMiddles);
  326. var users = await _userMiddleService.FindUsersAsync(request.AddresseeUserMiddles, request.UserId);
  327. request.NoticeAddresseeUserIds = users.Select(n => n.Id).ToList();
  328. request.NoticeAddresseeUserIds.Remove(request.UserId);
  329. }
  330. if (request.CcUserMiddles.Count > 0)
  331. {
  332. await _userMiddleService.DeleteAsync(Q.Where(nameof(Entity.UserMiddle.UserMiddle.MiddleType), 20).Where(nameof(Entity.UserMiddle.UserMiddle.DataSourceId), request.Id));
  333. foreach (var item in request.CcUserMiddles)
  334. {
  335. item.DataSourceId = request.Id;
  336. item.MiddleType = 20;
  337. }
  338. await _userMiddleService.AddUserMiddleAsync(request.CcUserMiddles);
  339. var users = await _userMiddleService.FindUsersAsync(request.CcUserMiddles, request.UserId);
  340. request.NoticeCcUserIds = users.Select(n => n.Id).ToList();
  341. request.NoticeCcUserIds.Remove(request.UserId);
  342. }
  343. if (request.NoticeAddresseeUserIds.Count > 0)
  344. {
  345. //删除接收人
  346. await _noticeAddresseeRepository.DeleteAsync(request.Id);
  347. //删除middle
  348. await _middleRepository.DeleteAsync(Q.Where(nameof(Entity.Middle.Middle.MiddleId), request.Id).Where(nameof(Entity.Middle.Middle.FolderType), 1));
  349. if (request.NoticeType == NoticeTypeConst.Send)
  350. {
  351. var userEntity = await _userRepository.GetAsync(request.UserId);
  352. //创建人
  353. var noticeAddresseeEntity = new NoticeAddressee
  354. {
  355. NoticeId = request.Id,
  356. UserId = request.UserId,
  357. UserName = userEntity.Name,
  358. IsAdmin = true,
  359. NoticeAddresseeType = request.NoticeType,
  360. IsTop = false
  361. };
  362. var noticeAddresseeId = await _noticeAddresseeRepository.InsertAsync(noticeAddresseeEntity);
  363. //添加文件
  364. var middleInsertTypes = new MiddleInsertTypeRequest
  365. {
  366. FolderId = 0,
  367. MiddleId = request.Id,
  368. FolderType = 1,
  369. UserId = request.UserId,
  370. MiddleSonId = noticeAddresseeId,
  371. NoticeAddresseeType = request.NoticeType,
  372. AttributeValue = 1,
  373. IsAdmin = true
  374. };
  375. await _middleService.InsertAsync(middleInsertTypes);
  376. }
  377. //收件人
  378. foreach (var noticeAddresseeUserId in request.NoticeAddresseeUserIds)
  379. {
  380. var user = await _userRepository.GetAsync(noticeAddresseeUserId);
  381. if (user.Id == request.UserId)
  382. continue;
  383. var noticeAddressee = new NoticeAddressee
  384. {
  385. NoticeId = request.Id,
  386. UserId = noticeAddresseeUserId,
  387. UserName = user.Name,
  388. NoticeAddresseeType = request.NoticeType
  389. };
  390. var noticeAddresseeId = await _noticeAddresseeRepository.InsertAsync(noticeAddressee);
  391. if (request.NoticeType == NoticeTypeConst.Send)
  392. {
  393. //添加文件
  394. var middleInsertType = new MiddleInsertTypeRequest
  395. {
  396. FolderId = 0,
  397. MiddleId = request.Id,
  398. FolderType = 1,
  399. UserId = noticeAddresseeUserId,
  400. MiddleSonId = noticeAddresseeId,
  401. AttributeValue = 1
  402. };
  403. await _middleService.InsertAsync(middleInsertType);
  404. }
  405. }
  406. }
  407. if (request.NoticeCcUserIds.Count > 0)
  408. {
  409. //删除抄送人
  410. await _noticeCcRepository.DeleteAsync(request.Id);
  411. //创建
  412. //抄送
  413. foreach (var noticeCcUserId in request.NoticeCcUserIds)
  414. {
  415. var user = await _userRepository.GetAsync(noticeCcUserId);
  416. var noticeCc = new NoticeCc
  417. {
  418. UserId = noticeCcUserId,
  419. NoticeId = request.Id,
  420. UserName = user.Name,
  421. NoticeCcType = request.NoticeType
  422. };
  423. await _noticeCcRepository.InsertAsync(noticeCc);
  424. }
  425. }
  426. return true;
  427. }
  428. /// <summary>
  429. /// 根据已读未读查询通知数据
  430. /// </summary>
  431. /// <param name="request"></param>
  432. /// <returns></returns>
  433. public async Task<IEnumerable<NoticeReadListResult>> NoticeReadListAsync(NoticeReadListRequest request)
  434. {
  435. var noticeReadListResults = await _noticeAddresseeRepository.GetNoticeAddresseeByUserIdIdAsync(request);
  436. return noticeReadListResults;
  437. }
  438. /// <summary>
  439. /// 获取通知列表
  440. /// </summary>
  441. /// <param name="request"></param>
  442. /// <returns></returns>
  443. public async Task<PagedList<NoticeListPageResult>> GetNoticeListPageAsync(NoticePageSearchRequest request)
  444. {
  445. var result = await _noticeRepository.GetNoticeListPageAsync(request);
  446. foreach (var item in result.Items)
  447. {
  448. // var userMiddles = await _userMiddleService.FindUserMiddlesAsync(10, item.MiddleId);
  449. // item.EnjoyUser = StringUtils.ObjectCollectionToString(userMiddles.Select(n => n.SourceName).ToList(), "、");
  450. //分析title
  451. if (string.IsNullOrWhiteSpace(item.Title))
  452. {
  453. var data = JsonConvert.DeserializeObject<List<ContentJsonData>>(item.Content);
  454. if (data.Count > 0)
  455. {
  456. var first = data.First();
  457. if (first.TypeValue == OldTextEditorTypeConst.Text.GetHashCode() && !string.IsNullOrWhiteSpace(first.Text))
  458. item.Title = first.Text;
  459. else
  460. {
  461. foreach (var contentJsonData in data)
  462. {
  463. //是否是文本
  464. if (contentJsonData.TypeValue == OldTextEditorTypeConst.Text.GetHashCode())
  465. continue;
  466. else if (contentJsonData.TypeValue == OldTextEditorTypeConst.Image.GetHashCode())
  467. {
  468. item.Title = "[图片]";
  469. break;
  470. }
  471. else if (contentJsonData.TypeValue == OldTextEditorTypeConst.File.GetHashCode())
  472. {
  473. item.Title = "[附件]";
  474. break;
  475. }
  476. else
  477. {
  478. item.Title = "[附件]";
  479. break;
  480. }
  481. }
  482. // //图片 文件类型
  483. // var typeList = new List<int> { OldTextEditorTypeConst.Image.GetHashCode(), OldTextEditorTypeConst.File.GetHashCode() };
  484. // if (data.Any(n => (n.TypeValue == OldTextEditorTypeConst.Image.GetHashCode() && n.TypeValue == OldTextEditorTypeConst.File.GetHashCode())))
  485. // item.Title = "[图片][附件]";
  486. // else
  487. // {
  488. // if (data.Any(n => n.TypeValue == OldTextEditorTypeConst.Image.GetHashCode()))
  489. // item.Title = "[图片]";
  490. // else if (data.Any(n => n.TypeValue == OldTextEditorTypeConst.File.GetHashCode()))
  491. // item.Title = "[附件]";
  492. // else
  493. // {
  494. // if (data.Any(n => !typeList.Contains(n.TypeValue)))
  495. // item.Title = "[附件]";
  496. // }
  497. // }
  498. }
  499. }
  500. }
  501. if (item.IsDelete == true)
  502. item.NoticeStatus = 0;
  503. else if (item.NoticeAddresseeType == NoticeTypeConst.Draft)
  504. item.NoticeStatus = 2;
  505. else
  506. item.NoticeStatus = 1;
  507. }
  508. return result;
  509. }
  510. /// <summary>
  511. /// 撤销通知
  512. /// </summary>
  513. /// <param name="id"></param>
  514. /// <returns></returns>
  515. public async Task<bool> RecallAsync(int id)
  516. {
  517. try
  518. {
  519. using (TransactionScope transactionScope = new TransactionScope())
  520. {
  521. //删除middle
  522. await _middleRepository.DeleteAsync(Q.Where(nameof(Entity.Middle.Middle.MiddleId), id).Where(nameof(Entity.Middle.Middle.FolderType), 1).Where(nameof(Entity.Middle.Middle.IsAdmin), false));
  523. //修改为草稿箱
  524. await _middleRepository.UpdateAsync(Q.Where(nameof(Entity.Middle.Middle.MiddleId), id).Where(nameof(Entity.Middle.Middle.FolderType), 1).Where(nameof(Entity.Middle.Middle.IsAdmin), true).Set(nameof(Entity.Middle.Middle.NoticeAddresseeType), 2));
  525. //修改
  526. await _noticeRepository.UpdateAsync(Q.Where(nameof(Entity.Notice.Id), id).Set(nameof(Entity.Notice.NoticeType), NoticeTypeConst.Draft.GetHashCode()));
  527. transactionScope.Complete();
  528. }
  529. }
  530. catch (System.Exception ex)
  531. {
  532. throw new BusinessException(ex.Message);
  533. }
  534. return true;
  535. }
  536. }
  537. }