CollectionService.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using AutoMapper;
  5. using Datory;
  6. using GxPress.Common.Exceptions;
  7. using GxPress.Common.Page;
  8. using GxPress.Common.Tools;
  9. using GxPress.Entity.WorkMeeting;
  10. using GxPress.EnumConst;
  11. using GxPress.Repository.Interface;
  12. using GxPress.Repository.Interface.Collection;
  13. using GxPress.Repository.Interface.Missive;
  14. using GxPress.Repository.Interface.Note;
  15. using GxPress.Repository.Interface.WorkMeeting;
  16. using GxPress.Request.App.Analyze;
  17. using GxPress.Request.App.Collection;
  18. using GxPress.Request.App.Middle;
  19. using GxPress.Result;
  20. using GxPress.Result.App.Collection;
  21. using GxPress.Service.Interface.Analyze;
  22. using GxPress.Service.Interface.Article;
  23. using GxPress.Service.Interface.Collection;
  24. using GxPress.Service.Interface.Middle;
  25. using GxPress.Service.Interface.UserMiddle;
  26. using GxPress.Repository.Interface.Media;
  27. using Newtonsoft.Json;
  28. namespace GxPress.Service.Implement.Collection
  29. {
  30. public class CollectionService : ICollectionService
  31. {
  32. private readonly ICollectionRepository _collectionRepository;
  33. private readonly IMiddleService _middleService;
  34. private readonly IArticleRepository _articleRepository;
  35. private readonly ITopicRepository _topicRepository;
  36. private readonly IMiddleRepository _middleRepository;
  37. private readonly INoteRepository _noteRepository;
  38. private readonly IUserRepository _userRepository;
  39. private readonly IArticleService _articleService;
  40. private readonly INoticeRepository _noticeRepository;
  41. private readonly IMissiveRepository _missiveRepository;
  42. private readonly IGroupRepository _groupRepository;
  43. private readonly IMeetingSummaryRepository _meetingSummaryRepository;
  44. private readonly IMeetingRepository meetingRepository;
  45. private readonly IMapper _mapper;
  46. private readonly IFolderUserRepository _folderUserRepository;
  47. private readonly IAnalyzeService _analyzeService;
  48. private readonly IFileLibraryRepository fileLibraryRepository;
  49. private readonly IUserMiddleService _userMiddleService;
  50. private readonly IMediaRepository mediaRepository;
  51. public CollectionService(ICollectionRepository collectionRepository, IMiddleService middleService,
  52. IArticleRepository articleRepository, ITopicRepository topicRepository, IMiddleRepository middleRepository,
  53. INoteRepository noteRepository, IUserRepository userRepository, IArticleService articleService, INoticeRepository noticeRepository,
  54. IMissiveRepository missiveRepository, IMapper mapper,
  55. IGroupRepository groupRepository, IMeetingSummaryRepository meetingSummaryRepository, IFolderUserRepository folderUserRepository, IAnalyzeService analyzeService, IFileLibraryRepository fileLibraryRepository, IUserMiddleService userMiddleService, IMediaRepository mediaRepository, IMeetingRepository meetingRepository)
  56. {
  57. _collectionRepository = collectionRepository;
  58. _middleService = middleService;
  59. _articleRepository = articleRepository;
  60. _topicRepository = topicRepository;
  61. _middleRepository = middleRepository;
  62. _noteRepository = noteRepository;
  63. _userRepository = userRepository;
  64. _articleService = articleService;
  65. _noticeRepository = noticeRepository;
  66. _missiveRepository = missiveRepository;
  67. _mapper = mapper;
  68. _groupRepository = groupRepository;
  69. _meetingSummaryRepository = meetingSummaryRepository;
  70. _folderUserRepository = folderUserRepository;
  71. _analyzeService = analyzeService;
  72. this.fileLibraryRepository = fileLibraryRepository;
  73. _userMiddleService = userMiddleService;
  74. this.mediaRepository = mediaRepository;
  75. this.meetingRepository = meetingRepository;
  76. }
  77. /// <summary>
  78. /// 插入
  79. /// </summary>
  80. /// <param name="request"></param>
  81. /// <returns></returns>
  82. public async Task<bool> Insert(CollectionInRequest request)
  83. {
  84. var collection = new Entity.Collection
  85. {
  86. CollectionDataId = request.CollectionDataId,
  87. CollectionType = request.CollectionType,
  88. UserId = request.UserId,
  89. SourceUserId = request.SourceUserId,
  90. EndCollectionDataId = request.CollectionDataId,
  91. EndCollectionType = request.CollectionType
  92. };
  93. var query = new SqlKata.Query();
  94. query.Where(nameof(Entity.Collection.UserId), request.UserId)
  95. .Where(nameof(Entity.Collection.CollectionType), request.CollectionType)
  96. .Where(nameof(Entity.Collection.CollectionDataId), request.CollectionDataId);
  97. if (request.SourceUserId > 0)
  98. query.Where(nameof(Entity.Collection.SourceUserId), request.SourceUserId);
  99. //查询是否存在
  100. var findCollection = await _collectionRepository.GetAsync(query);
  101. var analyzeRequest = new AnalyzeRequest
  102. {
  103. UserId = request.UserId,
  104. AnalyzeType = 3,
  105. SourceId = request.CollectionDataId,
  106. TypeValue = request.CollectionType,// 10 会议纪要 0 文章 1 话题 2 通知 3 笔记 4站内信 12 收藏文件夹 13 笔记文件夹
  107. SourceUserId = request.SourceUserId
  108. };
  109. if (findCollection != null)
  110. {
  111. await _collectionRepository.DeleteAsync(findCollection.Id);
  112. await _middleRepository.DeleteAsync(Q.Where(nameof(Entity.Middle.Middle.FolderType), 3).Where(nameof(Entity.Middle.Middle.MiddleId), findCollection.Id).Where(nameof(Entity.Middle.Middle.UserId), request.UserId));
  113. var analyze = await _analyzeService.GetAnalyzeAsync(analyzeRequest);
  114. if (analyze != null)
  115. await _analyzeService.DeleteAsync(analyze.Id);
  116. return true;
  117. }
  118. //收藏媒体
  119. if (request.CollectionType == AllTypeConst.Book.GetHashCode() || request.CollectionType == AllTypeConst.Curriculum.GetHashCode() || request.CollectionType == AllTypeConst.Audio.GetHashCode() || request.CollectionType == AllTypeConst.Video.GetHashCode())
  120. {
  121. var media = await mediaRepository.GetAsync(request.CollectionDataId);
  122. collection.Title = media.Title;
  123. analyzeRequest.TypeValue = request.CollectionType;
  124. await _analyzeService.SetAnalyzeAsync(analyzeRequest);
  125. }
  126. //收藏文章
  127. if (request.CollectionType == AllTypeConst.Article.GetHashCode())
  128. {
  129. var article = await _articleRepository.GetArticleAsync(request.CollectionDataId);
  130. collection.Title = article.Title;
  131. analyzeRequest.TypeValue = request.CollectionType;
  132. await _analyzeService.SetAnalyzeAsync(analyzeRequest);
  133. }
  134. //话题
  135. else if (request.CollectionType == AllTypeConst.Topic.GetHashCode())
  136. {
  137. var topic = await _topicRepository.GetAsync(request.CollectionDataId);
  138. collection.Title = topic.Title;
  139. if (string.IsNullOrEmpty(collection.Title))
  140. collection.Title = GetCollctionTitle(topic.Content);
  141. //收藏
  142. analyzeRequest.TypeValue = request.CollectionType;
  143. await _analyzeService.SetAnalyzeAsync(analyzeRequest);
  144. }
  145. //收藏收藏
  146. else if (request.CollectionType == AllTypeConst.Collect.GetHashCode())
  147. {
  148. //获取
  149. var collectionEntity = await _collectionRepository.GetAsync(request.CollectionDataId);
  150. collection.EndCollectionDataId = collectionEntity.EndCollectionDataId;
  151. collection.EndCollectionType = collectionEntity.EndCollectionType;
  152. }
  153. //笔记
  154. else if (request.CollectionType == AllTypeConst.Note.GetHashCode() || request.CollectionType == AllTypeConst.TopicNote.GetHashCode())
  155. {
  156. //收藏
  157. analyzeRequest.TypeValue = request.CollectionType;
  158. await _analyzeService.SetAnalyzeAsync(analyzeRequest);
  159. var note = await _noteRepository.GetAsync(request.CollectionDataId);
  160. collection.Title = note.Title;
  161. if (string.IsNullOrEmpty(collection.Title))
  162. collection.Title = GetCollctionTitle(note.Content);
  163. }
  164. //通知
  165. else if (request.CollectionType == AllTypeConst.Notice.GetHashCode())
  166. {
  167. //通知
  168. analyzeRequest.TypeValue = request.CollectionType;
  169. await _analyzeService.SetAnalyzeAsync(analyzeRequest);
  170. var notice = await _noticeRepository.GetAsync(request.CollectionDataId);
  171. collection.Title = notice.Title;
  172. if (string.IsNullOrEmpty(collection.Title))
  173. collection.Title = GetCollctionTitle(notice.Content);
  174. }
  175. //站内信
  176. else if (request.CollectionType == AllTypeConst.Missive.GetHashCode())
  177. {
  178. var notice = await _noticeRepository.GetAsync(request.CollectionDataId);
  179. collection.Title = notice.Title;
  180. //站内信
  181. analyzeRequest.TypeValue = request.CollectionType;
  182. await _analyzeService.SetAnalyzeAsync(analyzeRequest);
  183. if (string.IsNullOrEmpty(collection.Title))
  184. collection.Title = GetCollctionTitle(notice.Content);
  185. }
  186. //收藏会议
  187. if (request.CollectionType == AllTypeConst.Meeting.GetHashCode())
  188. {
  189. var meeting = await meetingRepository.GetAsync(request.CollectionDataId);
  190. if (meeting == null)
  191. throw new BusinessException("会议无效");
  192. collection.Title = meeting.Name;
  193. //收藏会议
  194. analyzeRequest.TypeValue = request.CollectionType;
  195. await _analyzeService.SetAnalyzeAsync(analyzeRequest);
  196. }
  197. //文件
  198. if (request.CollectionType == AllTypeConst.File.GetHashCode())
  199. {
  200. //获取文件信息
  201. var fileLibrary = await fileLibraryRepository.GetFileLibraryByIdAsync(collection.CollectionDataId);
  202. if (fileLibrary == null)
  203. throw new BusinessException("文件不存在");
  204. collection.Title = fileLibrary.FileName;
  205. }
  206. //会议纪要
  207. if (request.CollectionType == AllTypeConst.MeetingSummary.GetHashCode())
  208. {
  209. var meetingSummary = await _meetingSummaryRepository.GetAsync(Q.Where(nameof(MeetingSummary.Id), request.CollectionDataId));
  210. if (meetingSummary == null)
  211. throw new BusinessException("会议纪要无效");
  212. collection.Title = meetingSummary.Title;
  213. //会议纪要
  214. analyzeRequest.TypeValue = request.CollectionType;
  215. await _analyzeService.SetAnalyzeAsync(analyzeRequest);
  216. }
  217. //收藏、笔记文件
  218. if (request.CollectionType == AllTypeConst.NoteFolder.GetHashCode() || request.CollectionType == AllTypeConst.CollectFolder.GetHashCode())
  219. {
  220. if (request.CollectionDataId > 0)
  221. {
  222. var middle = await _middleRepository.GetMiddleAsync(request.CollectionDataId);
  223. if (middle == null)
  224. throw new BusinessException("文件夹无效");
  225. collection.Title = middle.FolderName;
  226. }
  227. else
  228. {
  229. var user = await _userRepository.GetAsync(request.SourceUserId);
  230. if (user == null)
  231. throw new BusinessException("用户不存在!");
  232. collection.Title = $"{user.Name}的";
  233. collection.Title += request.CollectionType == AllTypeConst.CollectFolder.GetHashCode() ? "收藏" : "笔记";
  234. }
  235. //笔记文件
  236. analyzeRequest.TypeValue = request.CollectionType;
  237. await _analyzeService.SetAnalyzeAsync(analyzeRequest);
  238. }
  239. var collectionId = await _collectionRepository.InsertAsync(collection);
  240. //添加收藏信息
  241. var middleInsertTypeRequest = new MiddleInsertTypeRequest
  242. {
  243. AttributeValue = 1,
  244. FolderId = request.FolderId,
  245. FolderType = AllTypeConst.Collect.GetHashCode(),
  246. MiddleId = collectionId,
  247. MiddleSonId = 0,
  248. UserId = request.UserId
  249. };
  250. return await _middleService.AddOrUpdateAsync(middleInsertTypeRequest);
  251. }
  252. /// <summary>
  253. /// 收藏无文件夹分页列表
  254. /// </summary>
  255. /// <param name="request"></param>
  256. /// <returns></returns>
  257. public async Task<PagedList<CollectionNoFolderResult>> GetCollectionNoFolderPageListAsync(CollectionPageSearchRequest request)
  258. {
  259. var result = await _collectionRepository.GetCollectionNoFolderPageListAsync(request);
  260. if (result == null || result.Items == null)
  261. return new PagedList<CollectionNoFolderResult>();
  262. foreach (var item in result.Items)
  263. {
  264. if (string.IsNullOrEmpty(item.FolderName))
  265. item.FolderName = "根目录";
  266. item.Data = await StructCollectionData(item.CollectionDataId, item.CollectionType, item.SourceUserId);
  267. if (string.IsNullOrWhiteSpace(item.Title))
  268. {
  269. item.Title = "";
  270. if (item.Data.Type == AllTypeConst.Article.GetHashCode())
  271. item.Title = item.Data.Title;
  272. else if (item.Data.Type == AllTypeConst.Text.GetHashCode())
  273. item.Title = item.Data.Title;
  274. else if (item.Data.Type == AllTypeConst.MeetingSummary.GetHashCode())
  275. item.Title = item.Data.Title;
  276. else
  277. {
  278. if (item.Data.Data != null)
  279. {
  280. if (item.Data.Type == AllTypeConst.Text.GetHashCode())
  281. item.Title = item.Data.Text;
  282. else if (item.Data.Data.Type == AllTypeConst.Text.GetHashCode())
  283. item.Title = item.Data.Data.Text;
  284. else if (item.Data.Data.Type == AllTypeConst.Image.GetHashCode())
  285. item.Data.Title = "[图片]";
  286. else
  287. item.Data.Title = "[附件]";
  288. item.Title = item.Data.Text;
  289. }
  290. }
  291. }
  292. }
  293. return result;
  294. }
  295. /// <summary>
  296. /// 查询结果
  297. /// </summary>
  298. /// <param name="request"></param>
  299. /// <returns></returns>
  300. public async Task<PagedList<CollectionListPageResult>> PageListAsync(CollectionPageSearchRequest request)
  301. {
  302. var result = await _collectionRepository.PageListAsync(request);
  303. if (request.FolderId > 0)
  304. {
  305. var middle = await _middleRepository.GetMiddleAsync(request.FolderId);
  306. result.RoleId = middle != null ? middle.RoleId : 0;
  307. }
  308. //是否收藏和转发数量
  309. if (request.VisitUserId > 0)
  310. {
  311. var user = await _userRepository.GetAsync(request.VisitUserId);
  312. result.Author = user.Name;
  313. var analyzeRequest = new AnalyzeRequest();
  314. analyzeRequest.SourceUserId = request.VisitUserId;
  315. analyzeRequest.AnalyzeType = 3;
  316. analyzeRequest.CommentId = 0;
  317. analyzeRequest.SourceId = request.FolderId;
  318. analyzeRequest.UserId = request.UserId;
  319. analyzeRequest.TypeValue = AllTypeConst.CollectFolder.GetHashCode();
  320. result.IsCollect = await _analyzeService.ExistsSourceUserAsync(analyzeRequest);
  321. analyzeRequest.AnalyzeType = 4;
  322. result.RetransmissionCount = await _analyzeService.RetransmissionCountAsync(analyzeRequest);
  323. }
  324. foreach (var item in result.Items)
  325. {
  326. item.Data = await StructCollectionData(item.CollectionDataId, item.CollectionType, item.SourceUserId);
  327. if (string.IsNullOrWhiteSpace(item.Title))
  328. {
  329. item.Title = "";
  330. if (item.Data.Type == AllTypeConst.Text.GetHashCode())
  331. item.Title = item.Data.Title;
  332. else if (item.Data.Type == AllTypeConst.MeetingSummary.GetHashCode())
  333. item.Title = item.Data.Title;
  334. else
  335. {
  336. if (item.Data.Data != null)
  337. {
  338. if (item.Data.Type == AllTypeConst.Text.GetHashCode())
  339. item.Title = item.Data.Text;
  340. else if (item.Data.Data.Type == AllTypeConst.Text.GetHashCode())
  341. item.Title = item.Data.Data.Text;
  342. else if (item.Data.Data.Type == AllTypeConst.Image.GetHashCode())
  343. item.Title = "[图片]";
  344. else
  345. item.Title = "[附件]";
  346. }
  347. }
  348. }
  349. }
  350. return result;
  351. }
  352. /// <summary>
  353. /// 递归获取不是收藏的数据
  354. /// </summary>
  355. /// <param name="middleId"></param>
  356. /// <returns></returns>
  357. public async Task<Entity.Collection> GetCollectionRecursion(int middleId)
  358. {
  359. //var middle = await _middleRepository.GetMiddleAsync(middleId);
  360. var collection = await _collectionRepository.GetAsync(middleId);
  361. if (collection.CollectionType == AllTypeConst.Collect.GetHashCode())
  362. await GetCollectionRecursion(collection.CollectionType);
  363. return collection;
  364. }
  365. /// <summary>
  366. /// 笔记解析
  367. /// </summary>
  368. /// <param name="data"></param>
  369. /// <returns></returns>
  370. public async Task<CollectionContentJsonData> AnalyzeAsync(List<CollectionContentJsonData> data)
  371. {
  372. var result = new CollectionContentJsonData();
  373. var fileCount = data.Count(n => n.Type == AllTypeConst.File.GetHashCode());
  374. //提取图片
  375. if (data.Any(n => n.Type == AllTypeConst.Image.GetHashCode()))
  376. {
  377. var contentJsonData = new CollectionContentJsonData { FileCount = fileCount, Type = AllTypeConst.Image.GetHashCode() };
  378. //获取图片
  379. var imgList = data.Where(n => n.Type == AllTypeConst.Image.GetHashCode());
  380. contentJsonData.ArticleImgUrl = imgList.Select(n => StringUtils.AddDomain(n.File)).ToList();
  381. result = (contentJsonData);
  382. return result;
  383. }
  384. //提取文字
  385. if (data.Any(n => n.Type == AllTypeConst.Text.GetHashCode()))
  386. {
  387. var contentJsonData = new CollectionContentJsonData { FileCount = fileCount, Type = AllTypeConst.Text.GetHashCode() };
  388. //获取图片
  389. var textList = data.Where(n => n.Type == AllTypeConst.Text.GetHashCode());
  390. contentJsonData.Text = textList.FirstOrDefault().Text;
  391. result = (contentJsonData);
  392. return result;
  393. }
  394. //获取
  395. foreach (var item in data.Where(n => n.Type != AllTypeConst.Text.GetHashCode() && n.Type != AllTypeConst.File.GetHashCode()))
  396. {
  397. return await StructCollectionData(item.Id, item.Type, 0);
  398. }
  399. return result;
  400. }
  401. /// <summary>
  402. /// 构造收藏Data 收藏类型 1文章 2话题 3 收藏 4笔记 5通知 6站内信 7小组 8会议
  403. /// </summary>
  404. /// <param name="collectionDataId"></param>
  405. /// <param name="collectionType"></param>
  406. /// <param name="isReturn"></param>
  407. /// <returns></returns>
  408. public async Task<CollectionContentJsonData> StructCollectionData(int collectionDataId, int collectionType, int sourceUserId, bool isReturn = false)
  409. {
  410. var list = new CollectionContentJsonData();
  411. //1文章 2话题 3 收藏 4笔记 5通知 6站内信 7小组 8会议 14工作流审核 300 文件 400会议纪要
  412. //文章类型
  413. if (collectionType == GxPress.EnumConst.AllTypeConst.Article.GetHashCode())
  414. {
  415. var articleResult = await _articleService.GetAsync(collectionDataId, 0);
  416. if (articleResult == null)
  417. return new CollectionContentJsonData();
  418. var articleImgUrl = new List<string>();
  419. if (articleResult.ImageUrls != null)
  420. foreach (var block in articleResult.ImageUrls)
  421. articleImgUrl.Add(StringUtils.AddDomain(block));
  422. list = new CollectionContentJsonData
  423. {
  424. Author = articleResult.Author,
  425. Title = articleResult.Title,
  426. CreatedData = articleResult.AddDate,
  427. Type = collectionType,
  428. Id = articleResult.Id,
  429. ArticleImgUrl = articleImgUrl,
  430. ReadCount = articleResult.ReadCount
  431. };
  432. }
  433. if (collectionType == GxPress.EnumConst.AllTypeConst.TopicNoteAll.GetHashCode())
  434. {
  435. var user = await _userRepository.GetAsync(sourceUserId);
  436. if (user == null)
  437. return new CollectionContentJsonData();
  438. list = new CollectionContentJsonData
  439. {
  440. Name = user.Name,
  441. Title = "",
  442. Type = collectionType,
  443. Id = user.Id,
  444. SourceUserId = sourceUserId
  445. };
  446. }
  447. if (collectionType == GxPress.EnumConst.AllTypeConst.TopicNoteFolder.GetHashCode())
  448. {
  449. var middle = await _middleRepository.GetMiddleAsync(collectionDataId);
  450. if (middle == null)
  451. return new CollectionContentJsonData();
  452. var user = await _userRepository.GetAsync(sourceUserId);
  453. if (user == null)
  454. return new CollectionContentJsonData();
  455. list = new CollectionContentJsonData
  456. {
  457. Name = middle.FolderName,
  458. Title = "",
  459. Type = collectionType,
  460. Id = middle.Id,
  461. Author = user.Name,
  462. SourceUserId = sourceUserId
  463. };
  464. }
  465. //话题类型
  466. if (collectionType == GxPress.EnumConst.AllTypeConst.Topic.GetHashCode())
  467. {
  468. var topic = await _topicRepository.GetAsync(collectionDataId);
  469. if (topic == null)
  470. return new CollectionContentJsonData();
  471. //获取是否存在小组
  472. var group = new Entity.Group();
  473. if (topic.GroupId > 0)
  474. {
  475. group = await _groupRepository.GetAsync(topic.GroupId);
  476. if (group == null)
  477. return new CollectionContentJsonData();
  478. }
  479. //查询ID
  480. var user = await _userRepository.GetAsync(topic.UserId);
  481. if (user == null)
  482. return new CollectionContentJsonData();
  483. list = new CollectionContentJsonData
  484. {
  485. Author = user.Name,
  486. Title = topic.Title,
  487. CreatedData = topic.CreatedDate,
  488. Type = collectionType,
  489. Id = topic.Id,
  490. File = StringUtils.AddDomain(user.AvatarUrl),
  491. ReadCount = topic.ReadCount,
  492. Name = user.Name,
  493. AvatarUrl = StringUtils.AddDomain(user.AvatarUrl),
  494. Data = await GetCollectionContentJsonData(topic.Content),
  495. NickName = user.Nick,
  496. IsGroup = group.Id > 0,
  497. GroupId = group.Id > 0 ? group.Id : 0,
  498. GroupName = group.Id > 0 ? group.Name : ""
  499. };
  500. }
  501. //收藏
  502. if (collectionType == GxPress.EnumConst.AllTypeConst.Collect.GetHashCode())
  503. {
  504. var collection = await GetCollectionRecursion(collectionDataId);
  505. list = await StructCollectionData(collection.EndCollectionDataId, collection.EndCollectionType, collection.SourceUserId);
  506. //list.Type = 8;
  507. }
  508. //笔记
  509. if (collectionType == GxPress.EnumConst.AllTypeConst.Note.GetHashCode() || collectionType == GxPress.EnumConst.AllTypeConst.TopicNote.GetHashCode())
  510. {
  511. var note = await _noteRepository.GetAsync(collectionDataId);
  512. if (note != null)
  513. {
  514. var user = await _userRepository.GetAsync(note.UserId);
  515. if (user == null)
  516. return new CollectionContentJsonData();
  517. list = (new CollectionContentJsonData
  518. {
  519. Author = user.Name,
  520. NickName = user.Nick,
  521. Name = user.Name,
  522. Title = note.Title,
  523. CreatedData = note.CreatedDate,
  524. Type = collectionType,
  525. Id = note.Id,
  526. File = "",
  527. AvatarUrl = StringUtils.AddDomain(user.AvatarUrl),
  528. Data = await GetCollectionContentJsonData(note.Content)
  529. });
  530. }
  531. }
  532. //通知
  533. if (collectionType == GxPress.EnumConst.AllTypeConst.Notice.GetHashCode() || collectionType == GxPress.EnumConst.AllTypeConst.Missive.GetHashCode() || collectionType == GxPress.EnumConst.AllTypeConst.Anonymity.GetHashCode())
  534. {
  535. var notice = await _noticeRepository.GetAsync(collectionDataId);
  536. if (notice == null)
  537. return new CollectionContentJsonData();
  538. var user = await _userRepository.GetAsync(notice.UserId);
  539. if (user == null)
  540. return new CollectionContentJsonData();
  541. list = (new CollectionContentJsonData
  542. {
  543. Author = user.Name,
  544. Title = notice.Title,
  545. CreatedData = notice.CreatedDate,
  546. Type = collectionType,
  547. Id = notice.Id,
  548. File = "",
  549. AvatarUrl = StringUtils.AddDomain(user.AvatarUrl),
  550. Name = user.Name,
  551. Data = await GetCollectionContentJsonData(notice.Content),
  552. NickName = user.Nick
  553. });
  554. }
  555. // //站内信
  556. // if (collectionType == GxPress.EnumConst.AllTypeConst.Missive.GetHashCode())
  557. // {
  558. // var missive = await _missiveRepository.GetAsync(collectionDataId);
  559. // if (missive == null)
  560. // return new CollectionContentJsonData();
  561. // var user = await _userRepository.GetAsync(missive.UserId);
  562. // if (user == null)
  563. // return new CollectionContentJsonData();
  564. // list = new CollectionContentJsonData
  565. // {
  566. // Author = user.Name,
  567. // Title = missive.Title,
  568. // CreatedData = missive.CreatedDate,
  569. // Type = collectionType,
  570. // Id = missive.Id,
  571. // File = "",
  572. // AvatarUrl = StringUtils.AddDomain(user.AvatarUrl),
  573. // Name = user.Name,
  574. // Data = await GetCollectionContentJsonData(missive.Content),
  575. // NickName = user.Nick,
  576. // MissiveType = missive.MissiveType
  577. // };
  578. // }
  579. //小组
  580. if (collectionType == GxPress.EnumConst.AllTypeConst.Group.GetHashCode())
  581. {
  582. var group = await _groupRepository.GetAsync(collectionDataId);
  583. if (group == null)
  584. return new CollectionContentJsonData();
  585. var user = await _userRepository.GetAsync(group.UserId);
  586. if (user == null)
  587. return new CollectionContentJsonData();
  588. list = new CollectionContentJsonData
  589. {
  590. Author = user.Name,
  591. Title = group.Name,
  592. CreatedData = group.CreatedDate,
  593. Type = collectionType,
  594. Id = group.Id,
  595. File = StringUtils.AddDomain(group.AvatarUrl),
  596. Name = user.Name,
  597. NickName = user.Nick
  598. };
  599. }
  600. //会议
  601. if (collectionType == GxPress.EnumConst.AllTypeConst.Meeting.GetHashCode())
  602. {
  603. var meetingSummary = await _meetingSummaryRepository.GetAsync(Q.Where(nameof(MeetingSummary.MeetingId), collectionDataId));
  604. if (meetingSummary == null)
  605. return new CollectionContentJsonData();
  606. var user = await _userRepository.GetAsync(meetingSummary.UserId);
  607. if (user == null)
  608. return new CollectionContentJsonData();
  609. list = new CollectionContentJsonData
  610. {
  611. Author = "",
  612. Title = meetingSummary.Title,
  613. CreatedData = meetingSummary.CreatedDate,
  614. Type = collectionType,
  615. Id = meetingSummary.Id,
  616. File = "",
  617. Name = user.Name,
  618. NickName = user.Nick
  619. };
  620. }
  621. //工作流
  622. //300 文件
  623. if (collectionType == GxPress.EnumConst.AllTypeConst.Flow.GetHashCode())
  624. {
  625. var fileLibrary = await fileLibraryRepository.GetFileLibraryByIdAsync(collectionDataId);
  626. if (fileLibrary == null)
  627. return new CollectionContentJsonData();
  628. // var user = await _userRepository.GetAsync(fileLibrary.UserId);
  629. list = new CollectionContentJsonData
  630. {
  631. Author = "",
  632. Title = fileLibrary.FileName,
  633. CreatedData = fileLibrary.CreatedData,
  634. Type = collectionType,
  635. Id = fileLibrary.Id,
  636. File = StringUtils.AddDomain(fileLibrary.FileUrl),
  637. MinFile = fileLibrary.FileType == "image" ? StringUtils.AddDomainMin(fileLibrary.FileUrl) : "",
  638. AvatarUrl = "",
  639. FileName = fileLibrary.FileName,
  640. Name = "",
  641. Data = new CollectionContentJsonData(),
  642. NickName = "",
  643. FileSize = fileLibrary.Size
  644. };
  645. }
  646. //400 会议纪要
  647. if (collectionType == GxPress.EnumConst.AllTypeConst.MeetingSummary.GetHashCode())
  648. {
  649. var meetingSummary = await _meetingSummaryRepository.GetAsync(collectionDataId);
  650. if (meetingSummary == null)
  651. return new CollectionContentJsonData();
  652. var user = await _userRepository.GetAsync(meetingSummary.UserId);
  653. if (user == null)
  654. return new CollectionContentJsonData();
  655. list = new CollectionContentJsonData
  656. {
  657. Author = user.Name,
  658. Title = meetingSummary.Title,
  659. CreatedData = meetingSummary.CreatedDate,
  660. Type = collectionType,
  661. Id = meetingSummary.Id,
  662. File = "",
  663. MinFile = "",
  664. AvatarUrl = "",
  665. FileName = "",
  666. Name = "",
  667. Data = new CollectionContentJsonData(),
  668. NickName = user.Nick,
  669. FileSize = 0
  670. };
  671. }
  672. //收藏笔记文件夹
  673. if (collectionType == GxPress.EnumConst.AllTypeConst.NoteFolder.GetHashCode() || collectionType == GxPress.EnumConst.AllTypeConst.CollectFolder.GetHashCode())
  674. {
  675. if (sourceUserId == 0)
  676. return new CollectionContentJsonData();
  677. var user = await _userRepository.GetAsync(sourceUserId);
  678. if (user == null)
  679. return new CollectionContentJsonData();
  680. list = new CollectionContentJsonData
  681. {
  682. Author = user.Name,
  683. Title = "",
  684. Type = collectionType,
  685. Id = 0,
  686. File = "",
  687. MinFile = "",
  688. AvatarUrl = "",
  689. FileName = "",
  690. Name = "",
  691. Data = new CollectionContentJsonData(),
  692. NickName = user.Nick,
  693. FileSize = 0
  694. };
  695. }
  696. return list;
  697. }
  698. /// <summary>
  699. /// 获取收藏详情
  700. /// </summary>
  701. /// <param name="id"></param>
  702. /// <returns></returns>
  703. public async Task<CollectionResult> GetCollectionDetailAsync(int id)
  704. {
  705. var collection = await _collectionRepository.GetAsync(id);
  706. if (collection == null)
  707. throw new BusinessException("收藏不存在");
  708. var result = _mapper.Map<CollectionResult>(collection);
  709. result.Data = await StructCollectionData(result.CollectionDataId, result.CollectionType, 0);
  710. return result;
  711. }
  712. public async Task<CollectionContentJsonData> GetCollectionContentJsonData(string json)
  713. {
  714. var data = JsonConvert.DeserializeObject<List<CollectionContentJsonData>>(json);
  715. return await AnalyzeAsync(data);
  716. }
  717. /// <summary>
  718. ///
  719. /// </summary>
  720. /// <param name="content"></param>
  721. /// <returns></returns>
  722. public string GetCollctionTitle(string content)
  723. {
  724. if (!string.IsNullOrEmpty(content))
  725. {
  726. var forCount = 1;
  727. var contentJsonData = JsonConvert.DeserializeObject<List<ContentJsonData>>(content);
  728. foreach (var jsonData in contentJsonData)
  729. {
  730. if (jsonData.TypeValue == AllTypeConst.Text.GetHashCode() && forCount == 1)
  731. //文本
  732. return jsonData.Text;
  733. else
  734. break;
  735. }
  736. }
  737. return "";
  738. }
  739. }
  740. }