2026-02-24 20:44:16 +00:00
|
|
|
|
using System;
|
2026-08-21 19:27:59 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2026-02-24 20:44:16 +00:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2026-08-21 19:27:59 +00:00
|
|
|
|
using Sozsoft.Platform.Entities;
|
2026-02-24 20:44:16 +00:00
|
|
|
|
using Volo.Abp.Application.Dtos;
|
|
|
|
|
|
using Volo.Abp.Application.Services;
|
|
|
|
|
|
using Volo.Abp.Domain.Repositories;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Sozsoft.Platform.AiBots;
|
|
|
|
|
|
|
|
|
|
|
|
[Authorize]
|
|
|
|
|
|
public class AiBotAppService : CrudAppService<
|
|
|
|
|
|
AiBot,
|
|
|
|
|
|
AiBotDto,
|
|
|
|
|
|
Guid,
|
|
|
|
|
|
PagedAndSortedResultRequestDto>
|
|
|
|
|
|
{
|
|
|
|
|
|
public AiBotAppService(IRepository<AiBot, Guid> repo) : base(repo)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2026-06-23 17:30:19 +00:00
|
|
|
|
|
|
|
|
|
|
public override async Task<PagedResultDto<AiBotDto>> GetListAsync(PagedAndSortedResultRequestDto input)
|
|
|
|
|
|
{
|
|
|
|
|
|
await CheckGetListPolicyAsync();
|
|
|
|
|
|
|
|
|
|
|
|
if (CurrentTenant.IsAvailable && !string.IsNullOrWhiteSpace(CurrentTenant.Name))
|
|
|
|
|
|
{
|
|
|
|
|
|
var tenantName = CurrentTenant.Name;
|
2026-07-13 13:51:13 +00:00
|
|
|
|
List<AiBot> tenantEntities;
|
|
|
|
|
|
|
|
|
|
|
|
using (CurrentTenant.Change(null))
|
|
|
|
|
|
{
|
|
|
|
|
|
var hostQuery = await CreateFilteredQueryAsync(input);
|
|
|
|
|
|
tenantEntities = await AsyncExecuter.ToListAsync(hostQuery);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var filteredQuery = tenantEntities
|
|
|
|
|
|
.Where(aiBot => IsAvailableForTenant(aiBot.Tenants, tenantName))
|
|
|
|
|
|
.AsQueryable();
|
|
|
|
|
|
|
|
|
|
|
|
var tenantTotalCount = filteredQuery.LongCount();
|
|
|
|
|
|
filteredQuery = ApplySorting(filteredQuery, input);
|
|
|
|
|
|
filteredQuery = ApplyPaging(filteredQuery, input);
|
|
|
|
|
|
|
|
|
|
|
|
var tenantDtos = await MapToGetListOutputDtosAsync(filteredQuery.ToList());
|
|
|
|
|
|
|
|
|
|
|
|
return new PagedResultDto<AiBotDto>(tenantTotalCount, tenantDtos);
|
2026-06-23 17:30:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-13 13:51:13 +00:00
|
|
|
|
var query = await CreateFilteredQueryAsync(input);
|
2026-06-23 17:30:19 +00:00
|
|
|
|
var totalCount = await AsyncExecuter.CountAsync(query);
|
|
|
|
|
|
query = ApplySorting(query, input);
|
|
|
|
|
|
query = ApplyPaging(query, input);
|
|
|
|
|
|
|
|
|
|
|
|
var entities = await AsyncExecuter.ToListAsync(query);
|
|
|
|
|
|
var dtos = await MapToGetListOutputDtosAsync(entities);
|
|
|
|
|
|
|
|
|
|
|
|
return new PagedResultDto<AiBotDto>(totalCount, dtos);
|
|
|
|
|
|
}
|
2026-07-13 13:51:13 +00:00
|
|
|
|
|
|
|
|
|
|
private static bool IsAvailableForTenant(string tenants, string tenantName)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(tenants))
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return tenants
|
|
|
|
|
|
.Split('|', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
|
|
|
|
|
|
.Any(name => string.Equals(name, tenantName, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
}
|
2026-02-24 20:44:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|