|
@@ -0,0 +1,142 @@
|
|
|
+using Hotline.Application.FlowEngine;
|
|
|
+using Hotline.Article;
|
|
|
+using Hotline.FlowEngine.WfModules;
|
|
|
+using Hotline.Permissions;
|
|
|
+using Hotline.Repository.SqlSugar.Extensions;
|
|
|
+using Hotline.Settings;
|
|
|
+using Hotline.Share.Dtos;
|
|
|
+using Hotline.Share.Dtos.Article;
|
|
|
+using Hotline.Share.Dtos.FlowEngine;
|
|
|
+using Hotline.Share.Dtos.Order;
|
|
|
+using Hotline.Share.Enums.Article;
|
|
|
+using MapsterMapper;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
+using Microsoft.OpenApi.Writers;
|
|
|
+using XF.Domain.Exceptions;
|
|
|
+using XF.Domain.Repository;
|
|
|
+using XF.Utility.EnumExtensions;
|
|
|
+
|
|
|
+namespace Hotline.Api.Controllers
|
|
|
+{
|
|
|
+
|
|
|
+ public class ArticleController: BaseController
|
|
|
+ {
|
|
|
+ private readonly IRepository<Bulletin> _bulletinRepository;
|
|
|
+ private readonly IMapper _mapper;
|
|
|
+ private readonly ISystemDomainService _systemDomainService;
|
|
|
+ private readonly ISystemOrganizeRepository _organizeRepository;
|
|
|
+ private readonly IWorkflowApplication _workflowApplication;
|
|
|
+
|
|
|
+ public ArticleController(IRepository<Bulletin> bulletinRepository,IMapper mapper, ISystemDomainService systemDomainService, ISystemOrganizeRepository organizeRepository, IWorkflowApplication workflowApplication)
|
|
|
+ {
|
|
|
+ _bulletinRepository = bulletinRepository;
|
|
|
+ _mapper = mapper;
|
|
|
+ _systemDomainService = systemDomainService;
|
|
|
+ _organizeRepository = organizeRepository;
|
|
|
+ _workflowApplication = workflowApplication;
|
|
|
+ }
|
|
|
+
|
|
|
+ #region 公告
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 查询公告列表
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [Permission(EPermission.QueryBulletinList)]
|
|
|
+ [HttpGet("bulletin/query")]
|
|
|
+ public async Task<PagedDto<BulletinDto>> QueryBulletinList([FromQuery]QueryBulletinListRequestDto dto)
|
|
|
+ {
|
|
|
+ var (total,items) = await _bulletinRepository.Queryable()
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.BulletinTypeId), d => d.BulletinTypeId == dto.BulletinTypeId)
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.Title), d => d.Title.Contains(dto.Title))
|
|
|
+ .WhereIF(dto.BulletinTimeStart.HasValue, d => d.BulletinTime >= dto.BulletinTimeStart)
|
|
|
+ .WhereIF(dto.BulletinTimeEnd.HasValue, d => d.BulletinTime <= dto.BulletinTimeEnd)
|
|
|
+ .OrderByDescending(d => d.CreationTime)
|
|
|
+ .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
|
|
|
+
|
|
|
+ return new PagedDto<BulletinDto>(total, _mapper.Map<IReadOnlyList<BulletinDto>>(items));
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 公告详情(内部)
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [Permission(EPermission.BulletinEntity)]
|
|
|
+ [HttpGet("bulletin/entity/{id}")]
|
|
|
+ public async Task<BulletinDto> BulletinEntity(string id)
|
|
|
+ {
|
|
|
+ var model = await _bulletinRepository.Queryable()
|
|
|
+ .FirstAsync(x=>x.Id == id, HttpContext.RequestAborted);
|
|
|
+ return _mapper.Map<BulletinDto>(model);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 新增公告
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [Permission(EPermission.AddBulletin)]
|
|
|
+ [HttpPost("bulletin/add")]
|
|
|
+ public async Task AddBulletin([FromBody]BulletinFlowDto dto)
|
|
|
+ {
|
|
|
+
|
|
|
+ var model = _mapper.Map<Bulletin>(dto.Data);
|
|
|
+ model.BulletinState = Share.Enums.Article.EBulletinState.InReview;
|
|
|
+ model.ReadedNum = 0;
|
|
|
+ var id = await _bulletinRepository.AddAsync(model, HttpContext.RequestAborted);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var startDto = _mapper.Map<StartWorkflowDto>(dto.Workflow);
|
|
|
+ startDto.DefinitionModuleCode = WorkflowModuleConsts.BulletinApply;
|
|
|
+ startDto.Title = model.Title;
|
|
|
+ await _workflowApplication.StartWorkflowAsync(startDto, id, HttpContext.RequestAborted);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _bulletinRepository.RemoveAsync(id, false, HttpContext.RequestAborted);
|
|
|
+ throw new UserFriendlyException($"新增公告流程失败!,{ex.Message}", "新增公告流程失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 列表页面基础数据
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet("bulletin/listbasedata")]
|
|
|
+ public async Task<object> BulletinListBaseData()
|
|
|
+ {
|
|
|
+ var rsp = new
|
|
|
+ {
|
|
|
+ BulletinType = _systemDomainService.GetSysDicDataByCodeAsync(SysDicTypeConsts.BulletinType)
|
|
|
+ };
|
|
|
+ return rsp;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 新增页面基础数据
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet("bulletin/addbasedata")]
|
|
|
+ public async Task<object> BulletinAddBaseData()
|
|
|
+ {
|
|
|
+ var rsp = new
|
|
|
+ {
|
|
|
+ BulletinType = _systemDomainService.GetSysDicDataByCodeAsync(SysDicTypeConsts.BulletinType),
|
|
|
+ PushRanges = EnumExts.GetDescriptions<EPushRange>(),
|
|
|
+ OrgsOptions = await _organizeRepository.GetOrgJson(),
|
|
|
+ };
|
|
|
+ return rsp;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 通知
|
|
|
+
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ }
|
|
|
+}
|