AppMeetingController.cs 33 KB

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