81 lines
2.7 KiB
C#
81 lines
2.7 KiB
C#
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;
|
|
|
|
/// <summary>
|
|
/// 班次规则服务
|
|
/// </summary>
|
|
[DynamicApi(Area = "app")]
|
|
public class ShiftRuleService : BaseService, IShiftRuleService, IDynamicApi
|
|
{
|
|
private readonly ShiftRuleRepository _shiftRuleRepository;
|
|
private readonly ShiftRuleMappingRepository _shiftRuleMappingRepository;
|
|
private readonly ILogger<ShiftRuleService> _logger;
|
|
|
|
public ShiftRuleService(
|
|
ShiftRuleRepository shiftRuleRepository,
|
|
ShiftRuleMappingRepository shiftRuleMappingRepository,
|
|
ILogger<ShiftRuleService> logger)
|
|
{
|
|
_shiftRuleRepository = shiftRuleRepository;
|
|
_shiftRuleMappingRepository = shiftRuleMappingRepository;
|
|
_logger = logger;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据ID获取班次规则详细信息
|
|
/// </summary>
|
|
/// <param name="id">规则ID</param>
|
|
/// <returns>班次规则详细信息</returns>
|
|
public async Task<ShiftRuleGetOutput> GetAsync(long id)
|
|
{
|
|
var entity = await _shiftRuleRepository.GetAsync(id);
|
|
if (entity == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return entity.Adapt<ShiftRuleGetOutput>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取班次规则分页列表
|
|
/// </summary>
|
|
/// <param name="input">查询条件</param>
|
|
/// <returns>分页结果</returns>
|
|
[HttpPost]
|
|
public async Task<PageOutput<ShiftRuleGetPageOutput>> GetPageAsync(PageInput<ShiftRuleGetPageInput> 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<List<ShiftRuleGetPageOutput>>();
|
|
|
|
return new PageOutput<ShiftRuleGetPageOutput>()
|
|
{
|
|
List = data,
|
|
Total = total
|
|
};
|
|
}
|
|
} |