using IRaCIS.Application.Interfaces; using IRaCIS.Application.Contracts; using IRaCIS.Core.Infra.EFCore; using Microsoft.AspNetCore.Mvc; using Panda.DynamicWebApi.Attributes; namespace IRaCIS.Application.Services { [ ApiExplorerSettings(GroupName = "Reviewer")] public class VacationService : BaseService, IVacationService { private readonly IRepository _vacationRepository; public VacationService(IRepository vacationRepository) { _vacationRepository = vacationRepository; } /// /// 添加休假时间段 /// /// 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 _repository.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(pageIndex, pageSize, "StartDate"); } [NonDynamicMethod] public async Task OnVacation(Guid doctorId) { var count = await _vacationRepository.CountAsync(u => u.DoctorId == doctorId && u.EndDate >= DateTime.Now && u.StartDate <= DateTime.Now); return ResponseOutput.Result(count > 0); } } }