using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using ZhonTai.Admin.Core.Dto;
using ZhonTai.Admin.Services;
using NPP.SmartSchedue.Api.Contracts.Services.Time;
using NPP.SmartSchedue.Api.Contracts.Services.Time.Input;
using NPP.SmartSchedue.Api.Contracts.Services.Time.Output;
using NPP.SmartSchedue.Api.Repositories.Time;
using NPP.SmartSchedue.Api.Contracts.Domain.Time;
using ZhonTai.DynamicApi;
using ZhonTai.DynamicApi.Attributes;
using Mapster;
using Microsoft.Extensions.Logging;
namespace NPP.SmartSchedue.Api.Services.Time;
///
/// 班次规则服务
///
[DynamicApi(Area = "app")]
public class ShiftRuleService : BaseService, IShiftRuleService, IDynamicApi
{
private readonly ShiftRuleRepository _shiftRuleRepository;
private readonly ShiftRuleMappingRepository _shiftRuleMappingRepository;
private readonly ILogger _logger;
public ShiftRuleService(
ShiftRuleRepository shiftRuleRepository,
ShiftRuleMappingRepository shiftRuleMappingRepository,
ILogger logger)
{
_shiftRuleRepository = shiftRuleRepository;
_shiftRuleMappingRepository = shiftRuleMappingRepository;
_logger = logger;
}
///
/// 根据ID获取班次规则详细信息
///
/// 规则ID
/// 班次规则详细信息
public async Task GetAsync(long id)
{
var entity = await _shiftRuleRepository.GetAsync(id);
if (entity == null)
{
return null;
}
return entity.Adapt();
}
///
/// 获取班次规则分页列表
///
/// 查询条件
/// 分页结果
[HttpPost]
public async Task> GetPageAsync(PageInput input)
{
var filter = input.Filter;
var query = _shiftRuleRepository.Select
.WhereIf(!string.IsNullOrWhiteSpace(filter?.RuleName), a => a.RuleName.Contains(filter.RuleName))
.WhereIf(!string.IsNullOrWhiteSpace(filter?.RuleType), a => a.RuleType == filter.RuleType)
.WhereIf(filter?.IsEnabled.HasValue == true, a => a.IsEnabled == filter.IsEnabled.Value)
.OrderBy(a => a.Id);
var list = await query.Count(out var total).Page(input.CurrentPage, input.PageSize).ToListAsync();
var data = list.Adapt>();
return new PageOutput()
{
List = data,
Total = total
};
}
}