You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
3.7 KiB
93 lines
3.7 KiB
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Shentun.WebPeis.AppointSchedules;
|
|
using Shentun.WebPeis.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Volo.Abp;
|
|
using Volo.Abp.Application.Services;
|
|
using Volo.Abp.Domain.Repositories;
|
|
|
|
namespace Shentun.WebPeis.AppointScheduleTimes
|
|
{
|
|
/// <summary>
|
|
/// 预约计划明细
|
|
/// </summary>
|
|
[ApiExplorerSettings(GroupName = "Work")]
|
|
[Authorize]
|
|
public class AppointScheduleTimeAppService : ApplicationService
|
|
{
|
|
|
|
private readonly IRepository<AppointScheduleTime> _appointScheduleTimeRepository;
|
|
private readonly CacheService _cacheService;
|
|
|
|
public AppointScheduleTimeAppService(
|
|
IRepository<AppointScheduleTime> appointScheduleTimeRepository,
|
|
CacheService cacheService
|
|
)
|
|
{
|
|
_appointScheduleTimeRepository = appointScheduleTimeRepository;
|
|
_cacheService = cacheService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取预约计划明细
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost("api/app/AppointScheduleTime/GetAppointScheduleTimeListByAppointScheduleId")]
|
|
public async Task<List<AppointScheduleTimeDto>> GetAppointScheduleTimeListByAppointScheduleIdAsync(AppointScheduleIdInputDto input)
|
|
{
|
|
var entList = (await _appointScheduleTimeRepository.GetQueryableAsync())
|
|
.Where(m => m.AppointScheduleId == input.AppointScheduleId)
|
|
.OrderBy(o => o.StartTime);
|
|
var entListDto = entList.Select(s => new AppointScheduleTimeDto
|
|
{
|
|
AppointScheduleId = s.AppointScheduleId,
|
|
CreationTime = s.CreationTime,
|
|
CreatorId = s.CreatorId,
|
|
LastModificationTime = s.LastModificationTime,
|
|
LastModifierId = s.LastModifierId,
|
|
CreatorName = _cacheService.GetSurnameAsync(s.CreatorId).Result,
|
|
LastModifierName = _cacheService.GetSurnameAsync(s.LastModifierId).Result,
|
|
AppointNumber = s.AppointNumber,
|
|
AppointScheduleTimeId = s.AppointScheduleTimeId,
|
|
NumberLimit = s.NumberLimit,
|
|
CanAppointNumber = s.NumberLimit - s.AppointNumber,
|
|
StartTime = DataHelper.ConvertTimeOnlyToString(s.StartTime),
|
|
StopTime = DataHelper.ConvertTimeOnlyToString(s.StopTime)
|
|
}).ToList();
|
|
return entListDto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改预约计划明细人数限制
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("api/app/AppointScheduleTime/UpdateAppointScheduleTimeNumberLimit")]
|
|
public async Task UpdateAppointScheduleTimeNumberLimitAsync(List<UpdateAppointScheduleTimeNumberLimitInputDto> input)
|
|
{
|
|
if (input.Any())
|
|
{
|
|
foreach (var item in input)
|
|
{
|
|
var appointScheduleTimeEnt = await _appointScheduleTimeRepository.FirstOrDefaultAsync(f => f.AppointScheduleTimeId == item.AppointScheduleTimeId);
|
|
|
|
if (appointScheduleTimeEnt == null)
|
|
throw new UserFriendlyException("预约计划明细ID不正确");
|
|
|
|
if (appointScheduleTimeEnt.AppointNumber > item.NumberLimit)
|
|
throw new UserFriendlyException("人数限制不能小于当前已预约数量");
|
|
|
|
appointScheduleTimeEnt.NumberLimit = item.NumberLimit;
|
|
|
|
await _appointScheduleTimeRepository.UpdateAsync(appointScheduleTimeEnt);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|