|
@@ -8,6 +8,7 @@ using XF.Domain.Exceptions;
|
|
|
using XF.Domain.Repository;
|
|
|
using Hotline.Share.Dtos.Schedulings;
|
|
|
using MapsterMapper;
|
|
|
+using Hotline.Users;
|
|
|
|
|
|
namespace Hotline.Api.Controllers
|
|
|
{
|
|
@@ -43,7 +44,7 @@ namespace Hotline.Api.Controllers
|
|
|
foreach (var dto in dtos)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(dto.UserId))
|
|
|
- throw UserFriendlyException.SameMessage("请上传附件关联Key");
|
|
|
+ throw UserFriendlyException.SameMessage("请带上用户信息");
|
|
|
|
|
|
var model = _mapper.Map<SchedulingUser>(dto);
|
|
|
user.Add(model);
|
|
@@ -75,7 +76,7 @@ namespace Hotline.Api.Controllers
|
|
|
{
|
|
|
var user = await _schedulingUserRepository.GetAsync(dto.Id, HttpContext.RequestAborted);
|
|
|
if (user is null)
|
|
|
- throw UserFriendlyException.SameMessage("无效附件");
|
|
|
+ throw UserFriendlyException.SameMessage("无效排班人员");
|
|
|
_mapper.Map(dto, user);
|
|
|
await _schedulingUserRepository.UpdateAsync(user, HttpContext.RequestAborted);
|
|
|
}
|
|
@@ -93,7 +94,7 @@ namespace Hotline.Api.Controllers
|
|
|
{
|
|
|
var user = await _schedulingUserRepository.GetAsync(item.Id, HttpContext.RequestAborted);
|
|
|
if (user is null)
|
|
|
- throw UserFriendlyException.SameMessage("无效附件");
|
|
|
+ throw UserFriendlyException.SameMessage("无效排班人员");
|
|
|
_mapper.Map(dto, user);
|
|
|
users.Add(user);
|
|
|
}
|
|
@@ -102,7 +103,7 @@ namespace Hotline.Api.Controllers
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 获取附件列表
|
|
|
+ /// 获取排班人员列表
|
|
|
/// </summary>
|
|
|
/// <param name="dto"></param>
|
|
|
/// <returns></returns>
|
|
@@ -117,12 +118,12 @@ namespace Hotline.Api.Controllers
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 获取附件实体
|
|
|
+ /// 获取排班人员实体
|
|
|
/// </summary>
|
|
|
/// <param name="id"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpGet("user/{id}")]
|
|
|
- public async Task<SchedulingUser> Entity(string id)
|
|
|
+ public async Task<SchedulingUser> UserEntity(string id)
|
|
|
{
|
|
|
return await _schedulingUserRepository.Queryable()
|
|
|
.FirstAsync(x => x.Id == id);
|
|
@@ -131,9 +132,178 @@ namespace Hotline.Api.Controllers
|
|
|
#endregion
|
|
|
|
|
|
#region 班次管理
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 新增班次管理
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dtos"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("shift")]
|
|
|
+ public async Task Add([FromBody] SchedulingShiftDto dto)
|
|
|
+ {
|
|
|
+ var model = _mapper.Map<SchedulingShift>(dto);
|
|
|
+ await _schedulingShiftRepository.AddAsync(model, HttpContext.RequestAborted);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 删除班次管理
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpDelete("shift")]
|
|
|
+ public async Task Delete([FromBody] ShiftDeleteDto dto)
|
|
|
+ {
|
|
|
+ foreach (var Id in dto.Ids)
|
|
|
+ {
|
|
|
+ await _schedulingShiftRepository.RemoveAsync(x => x.Id == Id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 更新班次管理
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPut("shift")]
|
|
|
+ public async Task Update([FromBody] ShiftUpdateDto dto)
|
|
|
+ {
|
|
|
+ var user = await _schedulingShiftRepository.GetAsync(dto.Id, HttpContext.RequestAborted);
|
|
|
+ if (user is null)
|
|
|
+ throw UserFriendlyException.SameMessage("无效班次信息");
|
|
|
+ _mapper.Map(dto, user);
|
|
|
+ await _schedulingShiftRepository.UpdateAsync(user, HttpContext.RequestAborted);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取班次管理列表
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet("shift_list")]
|
|
|
+ public async Task<PagedDto<SchedulingShift>> List([FromQuery] ShiftListDto dto)
|
|
|
+ {
|
|
|
+ var (total, items) = await _schedulingShiftRepository.Queryable()
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.Keyword), x => x.Name.Contains(dto.Keyword!))
|
|
|
+ .OrderByDescending(x => x.CreationTime)
|
|
|
+ .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
|
|
|
+ return new PagedDto<SchedulingShift>(total, items);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取班次管理实体
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet("shift/{id}")]
|
|
|
+ public async Task<SchedulingShift> ShiftEntity(string id)
|
|
|
+ {
|
|
|
+ return await _schedulingShiftRepository.Queryable()
|
|
|
+ .FirstAsync(x => x.Id == id);
|
|
|
+ }
|
|
|
#endregion
|
|
|
|
|
|
#region 排班管理
|
|
|
+ /// <summary>
|
|
|
+ /// 新增排班人员
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dtos"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost]
|
|
|
+ public async Task Add([FromBody] List<SchedulingDto> dtos)
|
|
|
+ {
|
|
|
+ List<Scheduling> schedulings = new List<Scheduling>();
|
|
|
+ foreach (var dto in dtos)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(dto.SchedulingUserId))
|
|
|
+ throw UserFriendlyException.SameMessage("请传入排班用户信息");
|
|
|
+ if (string.IsNullOrEmpty(dto.ShiftId))
|
|
|
+ throw UserFriendlyException.SameMessage("请传入排班班次信息");
|
|
|
+
|
|
|
+ var scheduling = _mapper.Map<Scheduling>(dto);
|
|
|
+ schedulings.Add(scheduling);
|
|
|
+ }
|
|
|
+ await _schedulingRepository.AddRangeAsync(schedulings, HttpContext.RequestAborted);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 删除排班人员
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpDelete]
|
|
|
+ public async Task Delete([FromBody] DeleteDto dto)
|
|
|
+ {
|
|
|
+ foreach (var Id in dto.Ids)
|
|
|
+ {
|
|
|
+ await _schedulingRepository.RemoveAsync(x => x.Id == Id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 更新排班人员
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPut]
|
|
|
+ public async Task Update([FromBody] UpdateDto dto)
|
|
|
+ {
|
|
|
+ var scheduling = await _schedulingRepository.GetAsync(dto.Id, HttpContext.RequestAborted);
|
|
|
+ if (scheduling is null)
|
|
|
+ throw UserFriendlyException.SameMessage("无效排班信息");
|
|
|
+ _mapper.Map(dto, scheduling);
|
|
|
+ await _schedulingRepository.UpdateAsync(scheduling, HttpContext.RequestAborted);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 批量更新排班人员
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPut("batch")]
|
|
|
+ public async Task Update([FromBody] List<UpdateDto> dto)
|
|
|
+ {
|
|
|
+ List<Scheduling> schedulings = new List<Scheduling>();
|
|
|
+ foreach (var item in dto)
|
|
|
+ {
|
|
|
+ var scheduling = await _schedulingRepository.GetAsync(item.Id, HttpContext.RequestAborted);
|
|
|
+ if (scheduling is null)
|
|
|
+ throw UserFriendlyException.SameMessage("无效排班信息");
|
|
|
+ _mapper.Map(dto, scheduling);
|
|
|
+ schedulings.Add(scheduling);
|
|
|
+ }
|
|
|
+ await _schedulingRepository.UpdateRangeAsync(schedulings, HttpContext.RequestAborted);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取排班人员列表
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet("list")]
|
|
|
+ public async Task<PagedDto<Scheduling>> List([FromQuery] ListDto dto)
|
|
|
+ {
|
|
|
+ var (total, items) = await _schedulingRepository.Queryable()
|
|
|
+ .Includes(x => x.SchedulingUser)
|
|
|
+ .Includes(x => x.SchedulingShift)
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.Keyword), x => x.ShiftName.Contains(dto.Keyword!))
|
|
|
+ .OrderByDescending(x => x.CreationTime)
|
|
|
+ .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
|
|
|
+ return new PagedDto<Scheduling>(total, items);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取排班人员实体
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet("{id}")]
|
|
|
+ public async Task<Scheduling> Entity(string id)
|
|
|
+ {
|
|
|
+ return await _schedulingRepository.Queryable()
|
|
|
+ .FirstAsync(x => x.Id == id);
|
|
|
+ }
|
|
|
#endregion
|
|
|
|
|
|
}
|