SnapshotBulletinController.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. using Hotline.Share.Dtos;
  2. using Hotline.Share.Dtos.Article;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Hotline.Repository.SqlSugar.Extensions;
  5. using Mapster;
  6. using XF.Domain.Exceptions;
  7. using Hotline.Share.Enums.Article;
  8. using XF.Domain.Authentications;
  9. using Hotline.Caching.Interfaces;
  10. using Hotline.Settings;
  11. using Hotline.Article;
  12. using Hotline.Snapshot;
  13. using Hotline.Share.Dtos.Snapshot;
  14. using Hotline.Share.Tools;
  15. using XF.Utility.EnumExtensions;
  16. using Hotline.Snapshot.IRepository;
  17. using Hotline.Application.Snapshot.Contracts;
  18. using Hotline.Share.Dtos.Settings;
  19. namespace Hotline.Api.Controllers.Snapshot;
  20. public class SnapshotBulletinController : BaseController
  21. {
  22. private readonly ISnapshotBulletinRepository _bulletinRepository;
  23. private readonly ISnapshotBulletinApplication _bulletinApplication;
  24. private readonly ISystemDicDataCacheManager _systemDicDataCacheManager;
  25. private readonly ISystemOrganizeRepository _organizeRepository;
  26. private readonly ISafetyTypeRepository _safetyTypeRepository;
  27. public SnapshotBulletinController(ISnapshotBulletinRepository bulletinRepository, ISystemDicDataCacheManager systemDicDataCacheManager, ISystemOrganizeRepository organizeRepository, ISnapshotBulletinApplication bulletinApplication, ISafetyTypeRepository safetyTypeRepository)
  28. {
  29. _bulletinRepository = bulletinRepository;
  30. _systemDicDataCacheManager = systemDicDataCacheManager;
  31. _organizeRepository = organizeRepository;
  32. _bulletinApplication = bulletinApplication;
  33. _safetyTypeRepository = safetyTypeRepository;
  34. }
  35. #region 公告
  36. /// <summary>
  37. /// 查询公告列表
  38. /// </summary>
  39. /// <param name="dto"></param>
  40. /// <returns></returns>
  41. [HttpGet("bulletin/query")]
  42. public async Task<PagedDto<SnapshotBulletinItemsOutDto>> QueryBulletinItems([FromQuery] SnapshotBulletinItemsInDto dto)
  43. => (await _bulletinApplication.QueryBulletinItems(dto).ToPagedListAsync(dto)).ToPaged();
  44. /// <summary>
  45. /// 公告详情(内部)
  46. /// </summary>
  47. /// <param name="id"></param>
  48. /// <returns></returns>
  49. [HttpGet("bulletin/entity/{id}")]
  50. public async Task<SnapshotBulletinDetailOutDto> BulletinEntity(string id)
  51. {
  52. var model = await _bulletinRepository.Queryable()
  53. .Includes(x => x.ExaminMan)
  54. .FirstAsync(x => x.Id == id, HttpContext.RequestAborted)
  55. ?? throw UserFriendlyException.SameMessage("公告不存在");
  56. if (model != null && !string.IsNullOrEmpty(model.Content))
  57. model.Content = _bulletinApplication.GetSiteUrls(model.Content);
  58. var outDto = model.Adapt<SnapshotBulletinDetailOutDto>();
  59. if (outDto.SafetyTypeId.NotNullOrEmpty())
  60. {
  61. outDto.SafetyTypeNames = await _safetyTypeRepository.Queryable()
  62. .Where(m => outDto.SafetyTypeId.Contains(m.Id))
  63. .Select(m => m.Name)
  64. .ToListAsync();
  65. }
  66. return outDto;
  67. }
  68. /// <summary>
  69. /// 公告上架或者下架
  70. /// </summary>
  71. /// <param name="dto"></param>
  72. /// <returns></returns>
  73. [HttpPost("bulletin-arrive")]
  74. public async Task BulletinArrive([FromBody] BulletinArriveDto dto)
  75. {
  76. var bulletin = await _bulletinRepository.GetAsync(dto.Id, HttpContext.RequestAborted);
  77. if (bulletin == null)
  78. throw UserFriendlyException.SameMessage("无效数据");
  79. if (bulletin.BulletinState != EBulletinState.ReviewPass)
  80. throw UserFriendlyException.SameMessage("当前状态不能操作上架或下架");
  81. bulletin.IsArrive = dto.IsArrive;
  82. if (bulletin.IsArrive == false)
  83. {
  84. bulletin.ExaminTime = null;
  85. bulletin.ExaminManId = null;
  86. bulletin.ExaminOpinion = null;
  87. bulletin.CommitTime = null;
  88. bulletin.BulletinState = EBulletinState.Draft;
  89. }
  90. await _bulletinRepository.UpdateAsync(bulletin, HttpContext.RequestAborted);
  91. }
  92. /// <summary>
  93. /// 公告审核
  94. /// </summary>
  95. /// <param name="dto"></param>
  96. /// <returns></returns>
  97. [HttpPost("bulletin/examine")]
  98. public async Task ExamineBulletin([FromBody] ExamineBulletinDto dto)
  99. => await _bulletinApplication.ExamineBulletinAsync(dto, HttpContext.RequestAborted);
  100. /// <summary>
  101. /// 提交公告
  102. /// </summary>
  103. /// <param name="id"></param>
  104. /// <returns></returns>
  105. [HttpGet("bulletin/commit")]
  106. public async Task CommitBulletin(string id)
  107. => await _bulletinApplication.CommitBulletinAsync(id, HttpContext.RequestAborted);
  108. /// <summary>
  109. /// 修改公告
  110. /// </summary>
  111. /// <param name="dto"></param>
  112. /// <returns></returns>
  113. [HttpPost("bulletin/update")]
  114. public async Task UpdateBulletin([FromBody] UpdateSnapshotBulletinInDto dto)
  115. {
  116. var bulletin = await _bulletinRepository.GetAsync(dto.Id, HttpContext.RequestAborted);
  117. if (bulletin == null)
  118. throw UserFriendlyException.SameMessage("无效数据");
  119. if (bulletin.BulletinState != EBulletinState.Draft && bulletin.BulletinState != EBulletinState.ReviewNoPass)
  120. throw UserFriendlyException.SameMessage("当前状态不能修改");
  121. dto.Adapt(bulletin);
  122. await _bulletinRepository.UpdateAsync(bulletin, HttpContext.RequestAborted);
  123. }
  124. /// <summary>
  125. /// 删除公告
  126. /// </summary>
  127. /// <param name="id"></param>
  128. /// <returns></returns>
  129. [HttpGet("bulletin/del/{id}")]
  130. public async Task DelBulletin(string id)
  131. {
  132. var bulletin = await _bulletinRepository.GetAsync(id, HttpContext.RequestAborted);
  133. if (bulletin == null)
  134. throw UserFriendlyException.SameMessage("无效数据");
  135. if (bulletin.BulletinState != EBulletinState.Draft)
  136. throw UserFriendlyException.SameMessage("当前状态不能删除");
  137. await _bulletinRepository.RemoveAsync(x => x.Id == id, false, HttpContext.RequestAborted);
  138. }
  139. /// <summary>
  140. /// 新增公告
  141. /// </summary>
  142. /// <param name="dto"></param>
  143. /// <returns></returns>
  144. [HttpPost("bulletin/add")]
  145. public async Task AddBulletin([FromBody] AddSnapshotBulletinInDto dto)
  146. => await _bulletinApplication.AddBulletinAsync(dto, HttpContext.RequestAborted);
  147. /// <summary>
  148. /// 列表页面基础数据
  149. /// </summary>
  150. /// <returns></returns>
  151. [HttpGet("bulletin/listbasedata")]
  152. public async Task<object> BulletinListBaseData()
  153. {
  154. var rsp = new
  155. {
  156. BulletinType = _systemDicDataCacheManager.SnapshotBulletinType,
  157. BulletinSource = _systemDicDataCacheManager.SnapshotBulletinSource,
  158. BulletinState = EnumExts.GetDescriptions<EBulletinState>()
  159. };
  160. return rsp;
  161. }
  162. /// <summary>
  163. /// 新增页面基础数据
  164. /// </summary>
  165. /// <returns></returns>
  166. [HttpGet("bulletin/addbasedata")]
  167. public async Task<object> BulletinAddBaseData()
  168. {
  169. var safetyTypes = await _safetyTypeRepository.Queryable()
  170. .Select(m => new SystemDicDataOutDto { Id = m.Id, DicDataName = m.Name, DicDataValue = m.Id })
  171. .ToListAsync(HttpContext.RequestAborted);
  172. var rsp = new
  173. {
  174. BulletinType = _systemDicDataCacheManager.SnapshotBulletinType,
  175. BulletinSource = _systemDicDataCacheManager.SnapshotBulletinSource,
  176. OrgsOptions = await _organizeRepository.GetOrgJson(),
  177. SafetyTypes = safetyTypes
  178. };
  179. return rsp;
  180. }
  181. #endregion
  182. }