|
@@ -0,0 +1,140 @@
|
|
|
+using Hotline.Repository.SqlSugar.Extensions;
|
|
|
+using Hotline.Schedulings;
|
|
|
+using Hotline.Share.Dtos.File;
|
|
|
+using Hotline.Share.Dtos;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
+using XF.Domain.Authentications;
|
|
|
+using XF.Domain.Exceptions;
|
|
|
+using XF.Domain.Repository;
|
|
|
+using Hotline.Share.Dtos.Schedulings;
|
|
|
+using MapsterMapper;
|
|
|
+
|
|
|
+namespace Hotline.Api.Controllers
|
|
|
+{
|
|
|
+ public class SchedulingController : BaseController
|
|
|
+ {
|
|
|
+ private readonly IRepository<Scheduling> _schedulingRepository;
|
|
|
+ private readonly IRepository<SchedulingShift> _schedulingShiftRepository;
|
|
|
+ private readonly IRepository<SchedulingUser> _schedulingUserRepository;
|
|
|
+ private readonly IMapper _mapper;
|
|
|
+
|
|
|
+ public SchedulingController(
|
|
|
+ IRepository<Scheduling> schedulingRepository,
|
|
|
+ IRepository<SchedulingShift> schedulingShiftRepository,
|
|
|
+ IRepository<SchedulingUser> schedulingUserRepository,
|
|
|
+ IMapper mapper
|
|
|
+ ) {
|
|
|
+ _schedulingRepository = schedulingRepository;
|
|
|
+ _schedulingShiftRepository = schedulingShiftRepository;
|
|
|
+ _schedulingUserRepository = schedulingUserRepository;
|
|
|
+ _mapper= mapper;
|
|
|
+ }
|
|
|
+ #region 排班人员
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 新增排班人员
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dtos"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("user")]
|
|
|
+ public async Task Add([FromBody] List<SchedulingUserDto> dtos)
|
|
|
+ {
|
|
|
+ List<SchedulingUser> user = new List<SchedulingUser>();
|
|
|
+ foreach (var dto in dtos)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(dto.UserId))
|
|
|
+ throw UserFriendlyException.SameMessage("请上传附件关联Key");
|
|
|
+
|
|
|
+ var model = _mapper.Map<SchedulingUser>(dto);
|
|
|
+ user.Add(model);
|
|
|
+ }
|
|
|
+ await _schedulingUserRepository.AddRangeAsync(user, HttpContext.RequestAborted);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 删除排班人员
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpDelete("user")]
|
|
|
+ public async Task Delete([FromBody] UserDeleteDto dto)
|
|
|
+ {
|
|
|
+ foreach (var Id in dto.Ids)
|
|
|
+ {
|
|
|
+ await _schedulingUserRepository.RemoveAsync(x => x.Id == Id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 更新排班人员
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPut("user")]
|
|
|
+ public async Task Update([FromBody] UserUpdateDto dto)
|
|
|
+ {
|
|
|
+ var user = await _schedulingUserRepository.GetAsync(dto.Id, HttpContext.RequestAborted);
|
|
|
+ if (user is null)
|
|
|
+ throw UserFriendlyException.SameMessage("无效附件");
|
|
|
+ _mapper.Map(dto, user);
|
|
|
+ await _schedulingUserRepository.UpdateAsync(user, HttpContext.RequestAborted);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 批量更新排班人员
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPut("batch_user")]
|
|
|
+ public async Task Update([FromBody] List<UserUpdateDto> dto)
|
|
|
+ {
|
|
|
+ List<SchedulingUser> users = new List<SchedulingUser>();
|
|
|
+ foreach (var item in dto)
|
|
|
+ {
|
|
|
+ var user = await _schedulingUserRepository.GetAsync(item.Id, HttpContext.RequestAborted);
|
|
|
+ if (user is null)
|
|
|
+ throw UserFriendlyException.SameMessage("无效附件");
|
|
|
+ _mapper.Map(dto, user);
|
|
|
+ users.Add(user);
|
|
|
+ }
|
|
|
+ await _schedulingUserRepository.UpdateRangeAsync(users, HttpContext.RequestAborted);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取附件列表
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet("user_list")]
|
|
|
+ public async Task<PagedDto<SchedulingUser>> List([FromQuery] UserListDto dto)
|
|
|
+ {
|
|
|
+ var (total, items) = await _schedulingUserRepository.Queryable()
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.Keyword), x => x.UserName.Contains(dto.Keyword!))
|
|
|
+ .OrderByDescending(x => x.CreationTime)
|
|
|
+ .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
|
|
|
+ return new PagedDto<SchedulingUser>(total, items);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取附件实体
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet("user/{id}")]
|
|
|
+ public async Task<SchedulingUser> Entity(string id)
|
|
|
+ {
|
|
|
+ return await _schedulingUserRepository.Queryable()
|
|
|
+ .FirstAsync(x => x.Id == id);
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 班次管理
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 排班管理
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ }
|
|
|
+}
|