|
@@ -12,6 +12,7 @@ using Hotline.Share.Enums.Article;
|
|
|
using MapsterMapper;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using Microsoft.OpenApi.Writers;
|
|
|
+using XF.Domain.Authentications;
|
|
|
using XF.Domain.Exceptions;
|
|
|
using XF.Domain.Repository;
|
|
|
using XF.Utility.EnumExtensions;
|
|
@@ -26,16 +27,160 @@ namespace Hotline.Api.Controllers
|
|
|
private readonly ISystemDomainService _systemDomainService;
|
|
|
private readonly ISystemOrganizeRepository _organizeRepository;
|
|
|
private readonly IWorkflowApplication _workflowApplication;
|
|
|
+ private readonly IRepository<Circular> _circularRepository;
|
|
|
+ private readonly ISessionContext _sessionContext;
|
|
|
+ private readonly IRepository<CircularRecord> _circularRecordRepository;
|
|
|
|
|
|
- public ArticleController(IRepository<Bulletin> bulletinRepository,IMapper mapper, ISystemDomainService systemDomainService, ISystemOrganizeRepository organizeRepository, IWorkflowApplication workflowApplication)
|
|
|
+ public ArticleController(IRepository<Bulletin> bulletinRepository,IMapper mapper, ISystemDomainService systemDomainService, ISystemOrganizeRepository organizeRepository, IWorkflowApplication workflowApplication, IRepository<Circular> circularRepository,ISessionContext sessionContext,IRepository<CircularRecord> circularRecordRepository)
|
|
|
{
|
|
|
_bulletinRepository = bulletinRepository;
|
|
|
_mapper = mapper;
|
|
|
_systemDomainService = systemDomainService;
|
|
|
_organizeRepository = organizeRepository;
|
|
|
_workflowApplication = workflowApplication;
|
|
|
+ _circularRepository = circularRepository;
|
|
|
+ _sessionContext = sessionContext;
|
|
|
+ _circularRecordRepository = circularRecordRepository;
|
|
|
+ }
|
|
|
+ #region 通知
|
|
|
+ /// <summary>
|
|
|
+ /// 查询通知列表
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [Permission(EPermission.QueryCircularList)]
|
|
|
+ [HttpGet("circular/query")]
|
|
|
+ public async Task<PagedDto<CircularDto>> QueryCircularList([FromQuery] QueryCircularListRequestDto dto)
|
|
|
+ {
|
|
|
+ var (total,items) = await _circularRepository.Queryable()
|
|
|
+ .Includes(x=>x.CircularReadGroups)
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.CircularTypeId), d => d.CircularTypeId == dto.CircularTypeId)
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.Title), d => d.Title.Contains(dto.Title))
|
|
|
+ .WhereIF(dto.CircularTimeStart.HasValue, d => d.CircularTime >= dto.CircularTimeStart)
|
|
|
+ .WhereIF(dto.CircularTimeEnd.HasValue, d => d.CircularTime <= dto.CircularTimeEnd)
|
|
|
+ .OrderByDescending(d => d.CreationTime)
|
|
|
+ .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
|
|
|
+ return new PagedDto<CircularDto>(total, _mapper.Map<IReadOnlyList<CircularDto>>(items));
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 通知详情(内部)
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [Permission(EPermission.CircularEntity)]
|
|
|
+ [HttpGet("circular/entity/{id}")]
|
|
|
+ public async Task<CircularDto> CircularEntity(string id)
|
|
|
+ {
|
|
|
+ var model = await _circularRepository.Queryable()
|
|
|
+ .Includes(x => x.CircularReadGroups)
|
|
|
+ .FirstAsync(x => x.Id == id, HttpContext.RequestAborted);
|
|
|
+ return _mapper.Map<CircularDto>(model);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 新增通知
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [Permission(EPermission.AddCircular)]
|
|
|
+ [HttpPost("circular/add")]
|
|
|
+ public async Task AddCircular([FromBody] CircularFlowDto dto)
|
|
|
+ {
|
|
|
+ var model = _mapper.Map<Circular>(dto.Data);
|
|
|
+ model.CircularState = ECircularState.InReview;
|
|
|
+ model.ReadedNum = 0;
|
|
|
+ model.NeedReadNum = model.CircularReadGroups.Count;
|
|
|
+ var id = await _circularRepository.AddAsync(model, HttpContext.RequestAborted);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var startDto = _mapper.Map<StartWorkflowDto>(dto.Workflow);
|
|
|
+ startDto.DefinitionModuleCode = WorkflowModuleConsts.CircularApply;
|
|
|
+ startDto.Title = model.Title;
|
|
|
+ await _workflowApplication.StartWorkflowAsync(startDto, id, HttpContext.RequestAborted);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _circularRepository.RemoveAsync(id, false, HttpContext.RequestAborted);
|
|
|
+ throw new UserFriendlyException($"新增通知流程失败!,{ex.Message}", "新增通知流程失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 列表页面基础信息
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet("circular/listbasedata")]
|
|
|
+ public async Task<object> CircularBaseData()
|
|
|
+ {
|
|
|
+ var rsp = new
|
|
|
+ {
|
|
|
+ CircularType = _systemDomainService.GetSysDicDataByCodeAsync(SysDicTypeConsts.CircularType)
|
|
|
+ };
|
|
|
+ return rsp;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 新增页面基础数据
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet("circular/addbasedata")]
|
|
|
+ public async Task<object> CircularAddBaseData()
|
|
|
+ {
|
|
|
+ var rsp = new
|
|
|
+ {
|
|
|
+ CircularType = _systemDomainService.GetSysDicDataByCodeAsync(SysDicTypeConsts.CircularType),
|
|
|
+ OrgsOptions = await _organizeRepository.GetOrgJson(),
|
|
|
+ };
|
|
|
+ return rsp;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 通知阅读(内部)
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet("circular/read/{id}")]
|
|
|
+ public async Task<CircularDto> CircularRead(string id)
|
|
|
+ {
|
|
|
+ var model = await _circularRepository.Queryable()
|
|
|
+ .Includes(x => x.CircularReadGroups)
|
|
|
+ .FirstAsync(x => x.Id == id, HttpContext.RequestAborted);
|
|
|
+
|
|
|
+ //更新阅读信息
|
|
|
+ if (model.CircularType == ECircularType.Person)
|
|
|
+ {
|
|
|
+ //个人阅读
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //部门阅读
|
|
|
+ }
|
|
|
+
|
|
|
+ return _mapper.Map<CircularDto>(model);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取小红点计数
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet("megcount")]
|
|
|
+ public async Task<CircularRecordDto> QueryMegCount()
|
|
|
+ {
|
|
|
+ var list = await _circularRecordRepository.Queryable().Where(x => x.UserId == _sessionContext.UserId || x.OrgId == _sessionContext.OrgId).ToListAsync();
|
|
|
+ if (list!=null && list.Count>0)
|
|
|
+ {
|
|
|
+ var rsp = new CircularRecordDto();
|
|
|
+ rsp.OrgCount = list.FirstOrDefault(x => x.CircularType == ECircularType.Org)?.RecordCount ?? 0;
|
|
|
+ rsp.PersonCount = list.FirstOrDefault(x => x.CircularType == ECircularType.Person)?.RecordCount ?? 0;
|
|
|
+ rsp.SumCount = rsp.OrgCount + rsp.PersonCount;
|
|
|
+ }
|
|
|
+ return new CircularRecordDto() { SumCount = 0, OrgCount = 0, PersonCount = 0 };
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+
|
|
|
#region 公告
|
|
|
|
|
|
/// <summary>
|
|
@@ -81,7 +226,6 @@ namespace Hotline.Api.Controllers
|
|
|
[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;
|
|
@@ -114,6 +258,7 @@ namespace Hotline.Api.Controllers
|
|
|
return rsp;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 新增页面基础数据
|
|
|
/// </summary>
|
|
@@ -133,10 +278,7 @@ namespace Hotline.Api.Controllers
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
- #region 通知
|
|
|
-
|
|
|
-
|
|
|
- #endregion
|
|
|
+
|
|
|
|
|
|
}
|
|
|
}
|