using IRaCIS.Application.Contracts; using IRaCIS.Application.Interfaces; using Microsoft.AspNetCore.Mvc; using Panda.DynamicWebApi.Attributes; namespace IRaCIS.Core.Application.Service { [ApiExplorerSettings(GroupName = "Reviewer")] public class VacationService(IRepository _vacationRepository, IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer) : BaseService, IVacationService { /// /// 添加休假时间段 /// /// Status不传 /// [HttpPost] public async Task AddOrUpdateVacation(VacationCommand param) { if (param.Id == Guid.Empty || param.Id == null) { var result = await _vacationRepository.AddAsync(_mapper.Map(param)); var success = await _vacationRepository.SaveChangesAsync(); return ResponseOutput.Result(success, result.Id); } else { var success = await _vacationRepository.BatchUpdateNoTrackingAsync(u => u.Id == param.Id, h => new Vacation { StartDate = param.StartDate, EndDate = param.EndDate }); return ResponseOutput.Result(success); } } /// /// 删除休假时间段 /// /// 记录Id /// [HttpDelete("{holidayId:guid}")] public async Task DeleteVacation(Guid holidayId) { var success = await _vacationRepository.BatchDeleteNoTrackingAsync(u => u.Id == holidayId); return ResponseOutput.Result(success); } /// /// 获取休假时间段列表 /// /// [HttpGet("{doctorId:guid}/{pageIndex:int}/{pageSize:int}")] public async Task> GetVacationList(Guid doctorId, int pageIndex, int pageSize) { var query = _vacationRepository.Where(u => u.DoctorId == doctorId) .ProjectTo(_mapper.ConfigurationProvider); return await query.ToPagedListAsync(new PageInput() { PageIndex = pageIndex, PageSize = pageSize }, nameof(VacationCommand.StartDate)); } /// /// 获取是否休假 /// /// /// [HttpPost] public async Task GetIsVacation(GetIsVacationInDto inDto) { var query = await _vacationRepository.Where(u => u.DoctorId == inDto.DoctorId).ToListAsync(); bool isVacation = false; var now = DateTime.Now; foreach (var item in query) { if (item.StartDate <= now && now <= item.EndDate) { isVacation = true; break; } } return new GetIsVacationOutDto() { IsVacation= isVacation }; } [NonDynamicMethod] public async Task OnVacation(Guid doctorId) { //防止生成sql生成GETDATE() 时区导致的问题 var appDateTimeNow = DateTime.Now; var count = await _vacationRepository.CountAsync(u => u.DoctorId == doctorId && u.EndDate >= appDateTimeNow && u.StartDate <= appDateTimeNow); return ResponseOutput.Result(count > 0); } } }