WebMeetingController.cs 34 KB

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