AppMeetingController.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Datory;
  6. using GxPress.Auth;
  7. using GxPress.Common.Tools;
  8. using GxPress.Entity.WorkMeeting;
  9. using GxPress.Repository.Interface;
  10. using GxPress.Repository.Interface.WorkMeeting;
  11. using GxPress.Request.App.WorkMeeting;
  12. using GxPress.Result;
  13. using Microsoft.AspNetCore.Authorization;
  14. using Microsoft.AspNetCore.Mvc;
  15. using GxPress.Service.Interface.Meeting;
  16. using GxPress.Repository.Interface.MeetingSummaryTodo;
  17. using GxPress.Repository.Interface.FlowAttachment;
  18. using GxPress.Service.Interface.UserMiddle;
  19. using GxPress.Service.Interface.Analyze;
  20. using GxPress.Request.Analyze;
  21. namespace GxPress.Api.AppControllers
  22. {
  23. /// <summary>
  24. /// 会议
  25. /// </summary>
  26. [Route("api/app/meeting")]
  27. [ApiController]
  28. [Authorize]
  29. public class AppMeetingController : ControllerBase
  30. {
  31. private readonly ILoginContext _loginContext;
  32. private readonly IMeetingLocationRepository _meetingLocationRepository;
  33. private readonly IMeetingOrderRepository _meetingOrderRepository;
  34. private readonly IMeetingRepository _meetingRepository;
  35. private readonly IMeetingRoomRepository _meetingRoomRepository;
  36. private readonly IMeetingSummaryRepository _meetingSummaryRepository;
  37. private readonly IUserRepository _userRepository;
  38. private readonly IMeetingService meetingService;
  39. private readonly IMeetingSummaryTodoRepository meetingSummaryTodoRepository;
  40. private readonly IFlowAttachmentRepository flowAttachmentRepository;
  41. private readonly IUserMiddleService _userMiddleService;
  42. private readonly IAnalyzeService _analyzeService;
  43. private readonly ICommentRepository _commentRepository;
  44. public AppMeetingController(ILoginContext loginContext,
  45. IMeetingLocationRepository meetingLocationRepository,
  46. IMeetingOrderRepository meetingOrderRepository,
  47. IMeetingRepository meetingRepository,
  48. IMeetingRoomRepository meetingRoomRepository,
  49. IMeetingSummaryRepository meetingSummaryRepository,
  50. IUserRepository userRepository,
  51. IMeetingService meetingService,
  52. IMeetingSummaryTodoRepository meetingSummaryTodoRepository,
  53. IFlowAttachmentRepository flowAttachmentRepository,
  54. IUserMiddleService userMiddleService,
  55. IAnalyzeService analyzeService,
  56. ICommentRepository commentRepository)
  57. {
  58. _loginContext = loginContext;
  59. _meetingLocationRepository = meetingLocationRepository;
  60. _meetingOrderRepository = meetingOrderRepository;
  61. _meetingRepository = meetingRepository;
  62. _meetingRoomRepository = meetingRoomRepository;
  63. _meetingSummaryRepository = meetingSummaryRepository;
  64. _userRepository = userRepository;
  65. this.meetingService = meetingService;
  66. this.meetingSummaryTodoRepository = meetingSummaryTodoRepository;
  67. this.flowAttachmentRepository = flowAttachmentRepository;
  68. _userMiddleService = userMiddleService;
  69. _analyzeService = analyzeService;
  70. _commentRepository = commentRepository;
  71. }
  72. /// <summary>
  73. /// 获取会议室列表
  74. /// </summary>
  75. /// <returns></returns>
  76. [HttpGet("rooms")]
  77. [AllowAnonymous]
  78. public async Task<MeetingRoomsResult> ListRoom([FromQuery] MeetingRoomRequest request)
  79. {
  80. var locations = await _meetingLocationRepository.GetListAsync();
  81. var rooms = await _meetingRoomRepository.GetListAsync(request);
  82. foreach (var room in rooms)
  83. {
  84. room.Address = await _meetingLocationRepository.GetAddress(room.LocationId);
  85. }
  86. return new MeetingRoomsResult
  87. {
  88. Locations = locations,
  89. Rooms = rooms
  90. };
  91. }
  92. /// <summary>
  93. /// 获取会议室
  94. /// </summary>
  95. /// <returns></returns>
  96. [HttpGet("rooms/{id}")]
  97. public async Task<MeetingRoomResult> RoomGet([FromRoute] int id)
  98. {
  99. var room = await _meetingRoomRepository.GetAsync(id);
  100. room.Address = await _meetingLocationRepository.GetAddress(room.LocationId);
  101. var orderList = await _meetingOrderRepository.GetListAsyncSinceNow(room.Id);
  102. var orders = new SortedDictionary<string, List<int>>();
  103. foreach (var meetingOrder in orderList)
  104. {
  105. var data = meetingOrder.Date.ToString().Insert(4, "-").Insert(7, "-");
  106. var key = StringUtils.GetDate(Convert.ToDateTime(data)).ToString();
  107. // var key = StringUtils.GetDate(meetingOrder.CreatedDate).ToString();
  108. if (orders.TryGetValue(key, out var hourList))
  109. {
  110. hourList.Add(meetingOrder.Hour);
  111. }
  112. else
  113. {
  114. orders[key] = new List<int>
  115. {
  116. meetingOrder.Hour
  117. };
  118. }
  119. }
  120. var orderLists = new List<TimeDictionary>();
  121. //新版
  122. foreach (var item in orderList)
  123. {
  124. if (orderLists.Any(n => n.TimeKey == item.Date.ToString()))
  125. continue;
  126. var timeDictionary = new TimeDictionary()
  127. {
  128. TimeKey = item.Date.ToString(),
  129. };
  130. foreach (var data in orderList.Where(n => n.Date == Convert.ToInt32(item.Date)).Distinct().ToList())
  131. {
  132. timeDictionary.TimeValues.Add(data.Hour);
  133. timeDictionary.NewTimeValues.Add(new TimeValue { Key = data.Hour, Value = data.UserName });
  134. }
  135. orderLists.Add(timeDictionary);
  136. }
  137. // foreach (var item in orderLists)
  138. // {
  139. // foreach (var data in orderList.Where(n => n.Date == Convert.ToInt32(item.TimeKey)).Distinct().ToList())
  140. // item.TimeValues.Add(new TimeValue { Key = data.Hour, Value = data.UserName });
  141. // }
  142. return new MeetingRoomResult
  143. {
  144. RoomName = room.Name,
  145. Disabled = room.Disabled,
  146. Orders = orders,
  147. OrderList = orderLists.Distinct().ToList()
  148. };
  149. }
  150. /// <summary>
  151. /// 预定会议室 添加/编辑
  152. /// </summary>
  153. /// <returns></returns>
  154. [HttpPost("rooms/{id}/actions/order")]
  155. public async Task<DefaultResult> Order([FromRoute] int id, [FromBody] MeetingOrderRequest request)
  156. {
  157. var room = await _meetingRoomRepository.GetAsync(id);
  158. var meeting = new Meeting();
  159. if (request.MeetingId == 0)
  160. {
  161. meeting = new Meeting
  162. {
  163. Name = request.Name,
  164. LocationId = room.LocationId,
  165. RoomId = room.Id,
  166. Description = request.Description,
  167. UserId = _loginContext.AccountId,
  168. FileIds = request.FileIds,
  169. UserIds = request.UserIds
  170. };
  171. meeting.Id = await _meetingRepository.InsertAsync(meeting);
  172. }
  173. else
  174. {
  175. meeting = await _meetingRepository.GetAsync(request.MeetingId);
  176. if (!string.IsNullOrWhiteSpace(request.Name))
  177. meeting.Name = request.Name;
  178. if (!string.IsNullOrWhiteSpace(request.Description))
  179. meeting.Description = request.Description;
  180. //删除参会人员
  181. var query = Q.NewQuery();
  182. query.Where(nameof(Entity.WorkMeeting.MeetingSummaryTodo.TypeId), 1);
  183. query.Where(nameof(Entity.WorkMeeting.MeetingSummaryTodo.MeetingSummaryId), request.MeetingId);
  184. await meetingSummaryTodoRepository.DeleteAsync(query);
  185. //删除附件
  186. await flowAttachmentRepository.DeleteAsync(Q.Where(nameof(Entity.WorkFlow.FlowAttachment.TypeId), 2).Where(nameof(Entity.WorkFlow.FlowAttachment.FlowId), request.MeetingId));
  187. //删除会议时间
  188. if (request.Orders.Count > 0)
  189. await _meetingOrderRepository.DeleteAsync(Q.Where(nameof(Entity.WorkMeeting.MeetingOrder.MeetingId), request.MeetingId));
  190. }
  191. //创建附件
  192. foreach (var item in request.flowAttachments)
  193. {
  194. item.FlowId = meeting.Id;
  195. item.TypeId = 2;
  196. }
  197. await flowAttachmentRepository.InsertsAsync(request.flowAttachments);
  198. //新增关联
  199. var meetingSummaryTodos = new List<Entity.WorkMeeting.MeetingSummaryTodo>();
  200. var meetingSummaryTodo = new MeetingSummaryTodo();
  201. meetingSummaryTodo.UserId = _loginContext.AccountId;
  202. meetingSummaryTodo.TypeId = 1;
  203. meetingSummaryTodo.IsAdmin = true;
  204. meetingSummaryTodo.MeetingSummaryId = meeting.Id;
  205. meetingSummaryTodos.Add(meetingSummaryTodo);
  206. foreach (var item in request.UserIds)
  207. {
  208. meetingSummaryTodo = new MeetingSummaryTodo();
  209. meetingSummaryTodo.UserId = item;
  210. meetingSummaryTodo.IsAdmin = false;
  211. meetingSummaryTodo.TypeId = 1;
  212. meetingSummaryTodo.MeetingSummaryId = meeting.Id;
  213. meetingSummaryTodos.Add(meetingSummaryTodo);
  214. }
  215. await meetingSummaryTodoRepository.InsertsAsync(meetingSummaryTodos);
  216. DateTime? startDate = null;
  217. DateTime? endDate = null;
  218. foreach (var requestOrder in request.Orders)
  219. {
  220. if (startDate.HasValue)
  221. {
  222. if (requestOrder < startDate)
  223. {
  224. startDate = requestOrder;
  225. }
  226. }
  227. else
  228. {
  229. startDate = requestOrder;
  230. }
  231. if (endDate.HasValue)
  232. {
  233. if (requestOrder > endDate)
  234. {
  235. endDate = requestOrder;
  236. }
  237. }
  238. else
  239. {
  240. endDate = requestOrder;
  241. }
  242. var order = new MeetingOrder
  243. {
  244. RoomId = room.Id,
  245. MeetingId = meeting.Id,
  246. Date = StringUtils.GetDate(requestOrder),
  247. Hour = requestOrder.Hour
  248. };
  249. await _meetingOrderRepository.InsertAsync(order);
  250. }
  251. meeting.StartDateTime = startDate;
  252. meeting.EndDateTime = endDate;
  253. await _meetingRepository.UpdateAsync(meeting);
  254. return new DefaultResult
  255. {
  256. Value = true
  257. };
  258. }
  259. /// <summary>
  260. /// 删除会议纪要
  261. /// </summary>
  262. /// <param name="id"></param>
  263. /// <returns></returns>
  264. [HttpDelete("summary/{id}")]
  265. public async Task<bool> DeleteSummary(int id)
  266. {
  267. return await _meetingSummaryRepository.DeleteAsync(id);
  268. }
  269. /// <summary>
  270. /// 新增会议纪要
  271. /// </summary>
  272. /// <returns></returns>
  273. [HttpPost("summary")]
  274. public async Task<MeetingSummary> AddSummary([FromBody] MeetingSummaryRequest request)
  275. {
  276. var meeting = await _meetingRepository.GetAsync(request.MeetingId);
  277. var summary = new MeetingSummary
  278. {
  279. MeetingId = meeting.Id,
  280. RoomId = meeting.RoomId,
  281. UserId = _loginContext.AccountId,
  282. Title = request.Title,
  283. Content = request.Content,
  284. UserIds = request.UserIds
  285. };
  286. summary.Id = await _meetingSummaryRepository.InsertAsync(summary);
  287. //判断是不是新版通知
  288. if (request.AddresseeUserMiddles.Count > 0)
  289. {
  290. foreach (var item in request.AddresseeUserMiddles)
  291. {
  292. item.DataSourceId = summary.Id;
  293. item.MiddleType = GxPress.EnumConst.AllTypeConst.MeetingSummary.GetHashCode();
  294. }
  295. await _userMiddleService.AddUserMiddleAsync(request.AddresseeUserMiddles);
  296. //获取用户
  297. var users = await _userMiddleService.FindUsersAsync(request.AddresseeUserMiddles, _loginContext.AccountId);
  298. request.UserIds = users.Select(n => n.Id).ToList();
  299. }
  300. //新增关联
  301. var meetingSummaryTodos = new List<Entity.WorkMeeting.MeetingSummaryTodo>();
  302. var meetingSummaryTodo = new MeetingSummaryTodo();
  303. meetingSummaryTodo.UserId = _loginContext.AccountId;
  304. meetingSummaryTodo.IsAdmin = true;
  305. meetingSummaryTodo.TypeId = 2;
  306. meetingSummaryTodo.MeetingSummaryId = summary.Id;
  307. meetingSummaryTodos.Add(meetingSummaryTodo);
  308. foreach (var item in request.UserIds)
  309. {
  310. if (_loginContext.AccountId == item)
  311. continue;
  312. meetingSummaryTodo = new MeetingSummaryTodo();
  313. meetingSummaryTodo.UserId = item;
  314. meetingSummaryTodo.IsAdmin = false;
  315. meetingSummaryTodo.TypeId = 2;
  316. meetingSummaryTodo.MeetingSummaryId = summary.Id;
  317. meetingSummaryTodos.Add(meetingSummaryTodo);
  318. }
  319. await meetingSummaryTodoRepository.InsertsAsync(meetingSummaryTodos);
  320. return summary;
  321. }
  322. /// <summary>
  323. /// 获取会议纪要
  324. /// </summary>
  325. /// <param name="keyword"></param>
  326. /// <param name="typeId">0 是全部 1我发起 2 别人 </param>
  327. /// <param name="meetingId">会议ID</param>
  328. /// <param name="page">页码数</param>
  329. /// <param name="perPage">数量</param>
  330. /// <returns></returns>
  331. [HttpGet("summary/list")]
  332. [AllowAnonymous]
  333. public async Task<IEnumerable<MeetingSummaryResult>> ListSummary(string keyword, int typeId, int meetingId, int page = 1, int perPage = 10)
  334. {
  335. // var summaries = await _meetingSummaryRepository.GetListAsync(keyword, _loginContext.AccountId, typeId, meetingId, page, perPage);
  336. // var userId = _loginContext.AccountId;
  337. // var list = new List<MeetingSummaryResult>();
  338. // foreach (var summary in summaries)
  339. // {
  340. // var meeting = await _meetingRepository.GetAsync(summary.MeetingId);
  341. // if (meeting == null) continue;
  342. // var address = await _meetingLocationRepository.GetAddress(meeting.LocationId);
  343. // if (address == null) continue;
  344. // var userName = await _userRepository.GetNameAsync(summary.UserId);
  345. // if (!string.IsNullOrEmpty(keyword))
  346. // {
  347. // if (!summary.Title.Contains(keyword) && !summary.Content.Contains(keyword) &&
  348. // !userName.Contains(keyword) && !address.Contains(keyword))
  349. // {
  350. // continue;
  351. // }
  352. // }
  353. // var orderList = await _meetingOrderRepository.GetListByMeetingIdAsync(meeting.Id);
  354. // var meetingTimeDictionary = meetingService.GetMeetingTimeDictionary(orderList);
  355. // var meetingSummaryResult = new MeetingSummaryResult()
  356. // {
  357. // Id = summary.Id,
  358. // UserId = summary.UserId,
  359. // UserName = userName,
  360. // Title = summary.Title,
  361. // Content = summary.Content,
  362. // MeetingId = summary.MeetingId,
  363. // UserIds = summary.UserIds,
  364. // MeetingName = meeting.Name,
  365. // Address = address,
  366. // CreatedDate = summary.CreatedDate,
  367. // MeetingTimes = meetingTimeDictionary.Values.First()
  368. // };
  369. // list.Add(meetingSummaryResult);
  370. // }
  371. var summaries = await _meetingSummaryRepository.GetListMeetingSummaryResultAsync(keyword, _loginContext.AccountId, typeId, meetingId, page, perPage);
  372. foreach (var item in summaries)
  373. {
  374. var orderList = await _meetingOrderRepository.GetListByMeetingIdAsync(item.MeetingId);
  375. var meetingTimeDictionary = meetingService.GetMeetingTimeDictionary(orderList);
  376. item.MeetingTimes = meetingTimeDictionary.Values.First();
  377. }
  378. return summaries;
  379. }
  380. /// <summary>
  381. /// 修改会议纪要
  382. /// </summary>
  383. /// <returns></returns>
  384. [HttpPut("summary/{id}")]
  385. public async Task<MeetingSummary> EditSummary([FromRoute] int id, [FromBody] MeetingSummaryRequest request)
  386. {
  387. var summary = await _meetingSummaryRepository.GetAsync(id);
  388. summary.Title = request.Title;
  389. summary.Content = request.Content;
  390. summary.UserIds = request.UserIds;
  391. var query = Q.NewQuery();
  392. //获取新版
  393. if (request.AddresseeUserMiddles.Count > 0)
  394. {
  395. query = Q.NewQuery();
  396. query.Where(nameof(Entity.UserMiddle.UserMiddle.MiddleType), GxPress.EnumConst.AllTypeConst.MeetingSummary.GetHashCode());
  397. query.Where(nameof(Entity.UserMiddle.UserMiddle.DataSourceId), id);
  398. await _userMiddleService.DeleteAsync(query);
  399. foreach (var item in request.AddresseeUserMiddles)
  400. {
  401. item.DataSourceId = id;
  402. item.MiddleType = GxPress.EnumConst.AllTypeConst.MeetingSummary.GetHashCode();
  403. }
  404. await _userMiddleService.AddUserMiddleAsync(request.AddresseeUserMiddles);
  405. var users = await _userMiddleService.FindUsersAsync(request.AddresseeUserMiddles, summary.UserId);
  406. request.UserIds = users.Select(n => n.Id).ToList();
  407. request.UserIds.Remove(summary.UserId);
  408. }
  409. //删除会议纪要关联用户
  410. query = Q.NewQuery();
  411. query.Where(nameof(Entity.WorkMeeting.MeetingSummaryTodo.TypeId), 2);
  412. query.Where(nameof(Entity.WorkMeeting.MeetingSummaryTodo.MeetingSummaryId), id);
  413. await meetingSummaryTodoRepository.DeleteAsync(query);
  414. //新增关联
  415. var meetingSummaryTodos = new List<Entity.WorkMeeting.MeetingSummaryTodo>();
  416. var meetingSummaryTodo = new MeetingSummaryTodo();
  417. meetingSummaryTodo.UserId = _loginContext.AccountId;
  418. meetingSummaryTodo.IsAdmin = true;
  419. meetingSummaryTodo.TypeId = 2;
  420. meetingSummaryTodo.MeetingSummaryId = summary.Id;
  421. meetingSummaryTodos.Add(meetingSummaryTodo);
  422. foreach (var item in request.UserIds)
  423. {
  424. meetingSummaryTodo = new MeetingSummaryTodo();
  425. meetingSummaryTodo.UserId = item;
  426. meetingSummaryTodo.IsAdmin = false;
  427. meetingSummaryTodo.TypeId = 2;
  428. meetingSummaryTodo.MeetingSummaryId = summary.Id;
  429. meetingSummaryTodos.Add(meetingSummaryTodo);
  430. }
  431. await meetingSummaryTodoRepository.InsertsAsync(meetingSummaryTodos);
  432. await _meetingSummaryRepository.UpdateAsync(summary);
  433. return summary;
  434. }
  435. /// <summary>
  436. /// 获取会议纪要详情
  437. /// </summary>
  438. /// <returns></returns>
  439. [HttpGet("summary/{id}")]
  440. public async Task<MeetingSummaryResult> GetSummary([FromRoute] int id)
  441. {
  442. var summary = await _meetingSummaryRepository.GetAsync(id);
  443. if (summary == null)
  444. throw new Common.Exceptions.BusinessException("会议纪要不存在");
  445. var meeting = await _meetingRepository.GetAsync(summary.MeetingId);
  446. var address = await _meetingLocationRepository.GetAddress(meeting.LocationId);
  447. //获取新版
  448. var addresseeUserMiddles = await _userMiddleService.FindUserMiddlesAsync(GxPress.EnumConst.AllTypeConst.MeetingSummary.GetHashCode(), id);
  449. var meetingSummaryResult = new MeetingSummaryResult
  450. {
  451. Id = summary.Id,
  452. UserId = summary.UserId,
  453. UserName = await _userRepository.GetNameAsync(summary.UserId),
  454. Title = summary.Title,
  455. Content = summary.Content,
  456. MeetingId = summary.MeetingId,
  457. UserIds = summary.UserIds,
  458. MeetingName = meeting.Name,
  459. Address = address,
  460. CreatedDate = summary.CreatedDate,
  461. AddresseeUserMiddles = addresseeUserMiddles.ToList()
  462. };
  463. //是否是自己创建
  464. meetingSummaryResult.IsAdmin = _loginContext.AccountId == summary.UserId;
  465. var analyzeRequest = new Request.App.Analyze.AnalyzeRequest();
  466. analyzeRequest.TypeValue = GxPress.EnumConst.AllTypeConst.MeetingSummary.GetHashCode();
  467. analyzeRequest.AnalyzeType = 1;
  468. analyzeRequest.SourceId = meetingSummaryResult.Id;
  469. analyzeRequest.UserId = _loginContext.AccountId;
  470. //点赞数量
  471. meetingSummaryResult.PraiseCount = await _analyzeService.CountAsync(analyzeRequest);
  472. //获取话题的评论数量
  473. var query = Q.NewQuery();
  474. query.Where(nameof(Entity.Comment.ArticleId), meetingSummaryResult.Id);
  475. query.Where(nameof(Entity.Comment.TypeValue), analyzeRequest.TypeValue);
  476. query.Where(nameof(Entity.Comment.Pid), 0);
  477. meetingSummaryResult.CommentCount = await _commentRepository.CountAsync(query); ;
  478. //获取话题的转发数量
  479. analyzeRequest.AnalyzeType = 4;
  480. var retransmissionCount = await _analyzeService.CountAsync(analyzeRequest);
  481. meetingSummaryResult.RetransmissionCount = retransmissionCount;
  482. meetingSummaryResult.IsRetransmission = await _analyzeService.ExistsAsync(analyzeRequest);
  483. //获取话题的收藏数量
  484. analyzeRequest.AnalyzeType = 3;
  485. var collectCount = await _analyzeService.CountAsync(analyzeRequest);
  486. meetingSummaryResult.CollectCount = collectCount;
  487. //是否收藏
  488. meetingSummaryResult.IsCollect = await _analyzeService.ExistsAsync(analyzeRequest);
  489. //获取话题的点赞数量
  490. analyzeRequest.AnalyzeType = 1;
  491. var praiseCount = await _analyzeService.CountAsync(analyzeRequest);
  492. meetingSummaryResult.PraiseCount = praiseCount;
  493. //是否点赞
  494. meetingSummaryResult.IsPraise = await _analyzeService.ExistsAsync(analyzeRequest);
  495. //获取点赞数据
  496. var request = new PraisePageSearchRequest { SourceId = id, TypeValue = analyzeRequest.TypeValue, Page = 1, PerPage = 3 };
  497. meetingSummaryResult.PraisePagedList = await _analyzeService.GetPraisePageAsync(request);
  498. return meetingSummaryResult;
  499. }
  500. /// <summary>
  501. /// 获取会议纪要详情 web专属
  502. /// </summary>
  503. /// <returns></returns>
  504. [HttpGet("summary/web/{id}")]
  505. [AllowAnonymous]
  506. public async Task<MeetingSummaryResult> GetWebSummary([FromRoute] int id)
  507. {
  508. var summary = await _meetingSummaryRepository.GetAsync(id);
  509. var meeting = await _meetingRepository.GetAsync(summary.MeetingId);
  510. var address = await _meetingLocationRepository.GetAddress(meeting.LocationId);
  511. //获取新版
  512. var addresseeUserMiddles = await _userMiddleService.FindUserMiddlesAsync(400, id);
  513. var meetingSummaryResult = new MeetingSummaryResult
  514. {
  515. Id = summary.Id,
  516. UserId = summary.UserId,
  517. UserName = await _userRepository.GetNameAsync(summary.UserId),
  518. Title = summary.Title,
  519. Content = summary.Content,
  520. MeetingId = summary.MeetingId,
  521. UserIds = summary.UserIds,
  522. MeetingName = meeting.Name,
  523. Address = address,
  524. CreatedDate = summary.CreatedDate,
  525. AddresseeUserMiddles = addresseeUserMiddles.ToList()
  526. };
  527. var analyzeRequest = new Request.App.Analyze.AnalyzeRequest();
  528. return meetingSummaryResult;
  529. }
  530. /// <summary>
  531. /// 获取我的会议
  532. /// </summary>
  533. /// <param name="keyword"></param>
  534. /// <returns></returns>
  535. [HttpGet("current")]
  536. public async Task<IEnumerable<MeetingResult>> ListCurrentMeeting([FromQuery] string keyword)
  537. {
  538. var meetings = await _meetingRepository.GetCurrentListAsync(_loginContext.AccountId, keyword);
  539. var list = new List<MeetingResult>();
  540. foreach (var meeting in meetings)
  541. {
  542. //获取会议房间
  543. var room = await _meetingRoomRepository.GetAsync(meeting.RoomId);
  544. var address = await _meetingLocationRepository.GetAddress(meeting.LocationId);
  545. var orderList = await _meetingOrderRepository.GetListByMeetingIdAsync(meeting.Id);
  546. var orders = new SortedDictionary<string, List<int>>();
  547. foreach (var meetingOrder in orderList)
  548. {
  549. var data = meetingOrder.Date.ToString().Insert(4, "-").Insert(7, "-");
  550. var key = StringUtils.GetDate(Convert.ToDateTime(data)).ToString();
  551. if (orders.TryGetValue(key, out var hourList))
  552. {
  553. hourList.Add(meetingOrder.Hour);
  554. }
  555. else
  556. {
  557. orders[key] = new List<int>
  558. {
  559. meetingOrder.Hour
  560. };
  561. }
  562. }
  563. var meetingTimeDictionary = meetingService.GetMeetingTimeDictionary(orderList);
  564. //状态
  565. var status = 0;
  566. var meetingTimeList = meetingTimeDictionary.Keys.First();
  567. if (meetingTimeList.Count > 0)
  568. {
  569. var meetingTime = meetingTimeList.FirstOrDefault();
  570. var TimeValuelast = meetingTime.TimeValues.Last();
  571. var data = meetingTime.TimeKey.ToString().Insert(4, "-").Insert(7, "-");
  572. var key = Convert.ToDateTime(data).AddHours(TimeValuelast);
  573. if (key < DateTime.Now)
  574. status = 1;
  575. }
  576. list.Add(new MeetingResult
  577. {
  578. Id = meeting.Id,
  579. UserId = meeting.UserId,
  580. UserName = await _userRepository.GetNameAsync(meeting.UserId),
  581. Name = meeting.Name,
  582. Description = meeting.Description,
  583. UserIds = meeting.UserIds,
  584. Address = address,
  585. OrderList = meetingTimeDictionary.Keys.First(),
  586. MeetingTimes = meetingTimeDictionary.Values.First(),
  587. Status = status,
  588. CreatedDate = meeting.CreatedDate,
  589. RoomName = room == null ? "" : room.Name,
  590. Orders = orders
  591. });
  592. }
  593. return list;
  594. }
  595. /// <summary>
  596. /// 获取历史会议
  597. /// </summary>
  598. /// <returns></returns>
  599. [HttpGet("history")]
  600. public async Task<IEnumerable<MeetingResult>> ListHistoryMeeting([FromQuery] string keyword, int page = 1, int perPage = 10)
  601. {
  602. var meetings = await _meetingRepository.GetHistoryListAsync(_loginContext.AccountId, keyword, page, perPage);
  603. var list = new List<MeetingResult>();
  604. foreach (var meeting in meetings)
  605. {
  606. var address = await _meetingLocationRepository.GetAddress(meeting.LocationId);
  607. //获取会议房间
  608. var room = await _meetingRoomRepository.GetAsync(meeting.RoomId);
  609. var orderList = await _meetingOrderRepository.GetListByMeetingIdAsync(meeting.Id);
  610. var orders = new SortedDictionary<string, List<int>>();
  611. foreach (var meetingOrder in orderList)
  612. {
  613. var key = StringUtils.GetDate(meetingOrder.CreatedDate).ToString();
  614. if (orders.TryGetValue(key, out var hourList))
  615. {
  616. hourList.Add(meetingOrder.Hour);
  617. }
  618. else
  619. {
  620. orders[key] = new List<int>
  621. {
  622. meetingOrder.Hour
  623. };
  624. }
  625. }
  626. var meetingTimeDictionary = meetingService.GetMeetingTimeDictionary(orderList);
  627. var meetingTimes = meetingTimeDictionary.Values.First();
  628. //状态
  629. var status = 0;
  630. var meetingTimeList = meetingTimeDictionary.Keys.First();
  631. if (meetingTimeList.Count > 0)
  632. {
  633. var meetingTime = meetingTimeList.FirstOrDefault();
  634. var TimeValuelast = meetingTime.TimeValues.Last();
  635. var data = meetingTime.TimeKey.ToString().Insert(4, "-").Insert(7, "-");
  636. var key = Convert.ToDateTime(data).AddHours(TimeValuelast);
  637. if (key < DateTime.Now)
  638. status = 1;
  639. }
  640. list.Add(new MeetingResult
  641. {
  642. Id = meeting.Id,
  643. UserId = meeting.UserId,
  644. UserName = await _userRepository.GetNameAsync(meeting.UserId),
  645. Name = meeting.Name,
  646. Description = meeting.Description,
  647. UserIds = meeting.UserIds,
  648. Address = address,
  649. CreatedDate = meeting.CreatedDate,
  650. MeetingTimes = meetingTimes,
  651. RoomName = room == null ? "" : room.Name,
  652. Orders = orders,
  653. Status = 1
  654. });
  655. }
  656. return list;
  657. }
  658. /// <summary>
  659. /// 获取会议详情
  660. /// </summary>
  661. /// <returns></returns>
  662. [HttpGet("{id}")]
  663. [AllowAnonymous]
  664. public async Task<MeetingResult> GetMeeting([FromRoute] int id)
  665. {
  666. var meeting = await _meetingRepository.GetAsync(id);
  667. var room = await _meetingRoomRepository.GetAsync(meeting.RoomId);
  668. var address = await _meetingLocationRepository.GetAddress(meeting.LocationId);
  669. //获取当前会议时间段
  670. var orderList = await _meetingOrderRepository.GetListByMeetingIdAsync(id);
  671. var orders = new SortedDictionary<string, List<int>>();
  672. foreach (var meetingOrder in orderList)
  673. {
  674. var key = StringUtils.GetDate(meetingOrder.CreatedDate).ToString();
  675. if (orders.TryGetValue(key, out var hourList))
  676. {
  677. hourList.Add(meetingOrder.Hour);
  678. }
  679. else
  680. {
  681. orders[key] = new List<int>
  682. {
  683. meetingOrder.Hour
  684. };
  685. }
  686. }
  687. //获取会议上传的文件流
  688. var flowAttachments = await flowAttachmentRepository.GetAllAsync(Q.Where(nameof(Entity.WorkFlow.FlowAttachment.TypeId), 2).Where(nameof(Entity.WorkFlow.FlowAttachment.FlowId), id).OrderByDesc(nameof(Entity.WorkFlow.FlowAttachment.CreatedDate)));
  689. var meetingTimeDictionary = meetingService.GetMeetingTimeDictionary(orderList);
  690. #region //获取当前房间的所有时间
  691. var orderLists = new List<TimeDictionary>();
  692. var orderAllList = await _meetingOrderRepository.GetListAsyncSinceNow(room.Id);
  693. //新版
  694. foreach (var item in orderAllList)
  695. {
  696. if (orderLists.Any(n => n.TimeKey == item.Date.ToString()))
  697. continue;
  698. var timeDictionary = new TimeDictionary();
  699. timeDictionary.TimeKey = item.Date.ToString();
  700. foreach (var date in orderAllList.Where(n => n.Date == item.Date).OrderBy(n => n.Hour).Select(n => n.Hour).Distinct().ToList())
  701. {
  702. timeDictionary.TimeValues.Add(date);
  703. timeDictionary.NewTimeValues.Add(new TimeValue { Key = date, Value = item.UserName });
  704. }
  705. orderLists.Add(timeDictionary);
  706. }
  707. #endregion
  708. #region 参会人员
  709. var meetingUsersRequest = new MeetingUsersRequest();
  710. meetingUsersRequest.MeetingId = id;
  711. var meetingUserResults = await _meetingRepository.GetUserByMeeting(meetingUsersRequest);
  712. #endregion
  713. return new MeetingResult
  714. {
  715. Id = meeting.Id,
  716. UserId = meeting.UserId,
  717. UserName = await _userRepository.GetNameAsync(meeting.UserId),
  718. Name = meeting.Name,
  719. Description = meeting.Description,
  720. UserIds = meeting.UserIds,
  721. Address = address,
  722. CreatedDate = meeting.CreatedDate,
  723. ImageUrl = room.ImageUrl,
  724. OrderList = meetingTimeDictionary.Keys.First(),
  725. OrderAllList = orderLists,
  726. Orders = orders,
  727. MeetingRoom = room,
  728. FlowAttachments = flowAttachments.ToList(),
  729. MeetingTimes = meetingTimeDictionary.Values.First(),
  730. MeetingUserResults = meetingUserResults,
  731. Disabled = room.Disabled,
  732. Status = meeting.EndDateTime < DateTime.Now ? 1 : 0
  733. };
  734. }
  735. /// <summary>
  736. /// 取消预定
  737. /// </summary>
  738. /// <returns></returns>
  739. [HttpPost("{id}/actions/cancel")]
  740. public async Task<DefaultResult> Cancel([FromRoute] int id)
  741. {
  742. await _meetingRepository.DeleteAsync(id);
  743. return new DefaultResult
  744. {
  745. Value = true
  746. };
  747. }
  748. /// <summary>
  749. /// 获取用户
  750. /// </summary>
  751. /// <returns></returns>
  752. [HttpPost("actions/users")]
  753. public async Task<IEnumerable<MeetingUserResult>> GetUsers([FromBody] MeetingUsersRequest request)
  754. {
  755. return await _meetingRepository.GetUserByMeeting(request);
  756. }
  757. }
  758. }