- 新增 Finance 模块应收应付分页查询及订单费用联查 - 为 DataPerm、Xhs 等缺失接口补充中文 summary 接口名称 - 优化微信公众号验签 Swagger 命名并补充路由集成测试 Co-authored-by: Cursor <cursoragent@cursor.com>
145 lines
5.5 KiB
C#
145 lines
5.5 KiB
C#
using System.Linq.Expressions;
|
|
using Fake.Application;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Oms.Application.Dtos.Channels;
|
|
using Oms.Application.Dtos.Shared;
|
|
using Oms.Application.Shared;
|
|
using Oms.Domain.ChannelsAggregate.Entities;
|
|
using Oms.Domain.ChannelsAggregate.Repositories;
|
|
|
|
namespace Oms.Application.Services.Channels;
|
|
|
|
/// <summary>
|
|
/// 自动触发规则 API 服务。
|
|
/// </summary>
|
|
[ApiExplorerSettings(GroupName = "OMS-Channel")]
|
|
public class AutoTriggerService : ApplicationService
|
|
{
|
|
private IAutoTriggerRepository AutoTriggerRepository => LazyServiceProvider.GetRequiredService<IAutoTriggerRepository>();
|
|
|
|
/// <summary>
|
|
/// 查询自动触发规则列表。
|
|
/// </summary>
|
|
/// <param name="input">入参:自动触发规则列表查询条件。</param>
|
|
/// <returns>自动触发规则分页结果,包含列表数据和总记录数。</returns>
|
|
[HttpGet("/channel/auto-trigger/list")]
|
|
public async Task<OmsPageResult<AutoTriggerOutput>> GetListAsync([FromQuery] AutoTriggerListInput input)
|
|
{
|
|
var predicate = BuildListPredicate(input);
|
|
var pageIndex = OmsDocHelper.NormalizePage(input.Page);
|
|
var pageSize = OmsDocHelper.NormalizePageSize(input.PageSize);
|
|
var entities = await AutoTriggerRepository.GetPagedListAsync(
|
|
predicate,
|
|
pageIndex,
|
|
pageSize,
|
|
new Dictionary<string, bool> { [nameof(AutoTrigger.UpdateTime)] = false, [nameof(AutoTrigger.Id)] = false });
|
|
var total = await AutoTriggerRepository.CountAsync(predicate);
|
|
var items = entities.Select(MapOutput).ToList();
|
|
return new OmsPageResult<AutoTriggerOutput> { Items = items, Total = total };
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新增自动触发规则。
|
|
/// </summary>
|
|
/// <param name="input">入参:自动触发规则保存参数。</param>
|
|
/// <returns>无返回体,仅完成新增自动触发规则。</returns>
|
|
[HttpPost("/channel/auto-trigger/create")]
|
|
public async Task CreateAsync(AutoTriggerSaveInput input)
|
|
{
|
|
var entity = new AutoTrigger
|
|
{
|
|
Status = input.Status,
|
|
Operation = input.Operation,
|
|
TriggerTiming = input.TriggerTiming,
|
|
TriggerCondition = input.TriggerCondition,
|
|
PromptMessage = input.PromptMessage,
|
|
Notifier = input.Notifier
|
|
};
|
|
await AutoTriggerRepository.InsertAsync(entity);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新自动触发规则。
|
|
/// </summary>
|
|
/// <param name="input">入参:自动触发规则保存参数。</param>
|
|
/// <returns>无返回体,仅完成更新自动触发规则。</returns>
|
|
[HttpPost("/channel/auto-trigger/update")]
|
|
public async Task UpdateAsync(AutoTriggerSaveInput input)
|
|
{
|
|
var entity = await GetEntityOrThrowAsync(input.Id);
|
|
entity.Status = input.Status;
|
|
entity.Operation = input.Operation;
|
|
entity.TriggerTiming = input.TriggerTiming;
|
|
entity.TriggerCondition = input.TriggerCondition;
|
|
entity.PromptMessage = input.PromptMessage;
|
|
entity.Notifier = input.Notifier;
|
|
await AutoTriggerRepository.UpdateAsync(entity);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除自动触发规则。
|
|
/// </summary>
|
|
/// <param name="input">入参:目标主键。</param>
|
|
/// <returns>无返回体,仅完成删除自动触发规则。</returns>
|
|
[HttpPost("/channel/auto-trigger/delete")]
|
|
public async Task DeleteAsync(IdInput input)
|
|
{
|
|
var entity = await GetEntityOrThrowAsync(input.Id);
|
|
await AutoTriggerRepository.DeleteAsync(entity);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 切换自动触发规则状态。
|
|
/// </summary>
|
|
/// <param name="input">入参:目标主键和状态值。</param>
|
|
/// <returns>无返回体,仅完成切换自动触发规则状态。</returns>
|
|
[HttpPost("/channel/auto-trigger/toggleStatus")]
|
|
public async Task ToggleStatusAsync(ToggleStatusInput input)
|
|
{
|
|
var entity = await GetEntityOrThrowAsync(input.Id);
|
|
entity.Status = input.Status;
|
|
await AutoTriggerRepository.UpdateAsync(entity);
|
|
}
|
|
|
|
private static Expression<Func<AutoTrigger, bool>> BuildListPredicate(AutoTriggerListInput input)
|
|
{
|
|
var operation = input.Operation?.Trim();
|
|
var triggerTiming = input.TriggerTiming?.Trim();
|
|
return entity =>
|
|
(string.IsNullOrWhiteSpace(operation) || entity.Operation == operation) &&
|
|
(string.IsNullOrWhiteSpace(triggerTiming) || entity.TriggerTiming == triggerTiming);
|
|
}
|
|
|
|
private async Task<AutoTrigger> GetEntityOrThrowAsync(int? id)
|
|
{
|
|
if (!id.HasValue || id.Value <= 0)
|
|
{
|
|
throw new BusinessException("自动触发不存在");
|
|
}
|
|
|
|
var entity = await AutoTriggerRepository.FirstOrDefaultAsync(x => x.Id == id.Value);
|
|
if (entity == null)
|
|
{
|
|
throw new BusinessException("自动触发不存在");
|
|
}
|
|
|
|
return entity;
|
|
}
|
|
|
|
private static AutoTriggerOutput MapOutput(AutoTrigger entity)
|
|
{
|
|
return new AutoTriggerOutput
|
|
{
|
|
Id = entity.Id,
|
|
Status = (byte)entity.Status,
|
|
Operation = entity.Operation,
|
|
TriggerTiming = entity.TriggerTiming,
|
|
TriggerCondition = entity.TriggerCondition,
|
|
PromptMessage = entity.PromptMessage,
|
|
Notifier = entity.Notifier,
|
|
CreateTime = entity.CreateTime,
|
|
UpdateTime = OmsDocHelper.NullIfDefault(entity.UpdateTime)
|
|
};
|
|
}
|
|
}
|