114 lines
3.8 KiB
C#
114 lines
3.8 KiB
C#
using MiaoYu.Repository.ChatAI.Admin.Entities.Apps;
|
|
namespace MiaoYu.Api.Admin.ApplicationServices.Apps;
|
|
|
|
/// <summary>
|
|
/// 模型配置表 服务 T_Model_ConfigService
|
|
/// </summary>
|
|
public class T_Model_ConfigService : ApplicationService<IRepository<T_Model_Config>>
|
|
{
|
|
public T_Model_ConfigService(IRepository<T_Model_Config> defaultRepository)
|
|
: base(defaultRepository)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取列表数据
|
|
/// </summary>
|
|
/// <param name="pagingSearchInput"></param>
|
|
/// <returns></returns>
|
|
public async Task<PagingView> FindListAsync(PagingSearchInput<T_Model_Config> pagingSearchInput)
|
|
{
|
|
var query = this._defaultRepository.Select
|
|
|
|
//项目
|
|
.WhereIf(pagingSearchInput.Search?.TenantId!=null,
|
|
w => w.TenantId==pagingSearchInput.Search.TenantId)
|
|
|
|
|
|
|
|
//模型名称
|
|
.WhereIf(!string.IsNullOrWhiteSpace(pagingSearchInput.Search?.ModelName),
|
|
w => w.ModelName.Contains(pagingSearchInput.Search.ModelName ?? ""))
|
|
|
|
|
|
.OrderByDescending(w => w.Id)
|
|
.Select(w => new
|
|
{
|
|
w.Id,
|
|
w.ModelName,w.Model,w.MaxTokens,w.ApiKey,w.Url,w.AnthropicVersion,w.CreateTime,w.UpdateTime,w.TenantId,
|
|
// w.LastModificationTime,
|
|
// w.CreationTime
|
|
})
|
|
;
|
|
|
|
var result = await _defaultRepository.AsPagingViewAsync(query, pagingSearchInput);
|
|
// result
|
|
// .FormatValue(query, w => w.CreationTime, (oldValue) => oldValue.ToString("yyyy-MM-dd"))
|
|
// .FormatValue(query, w => w.LastModificationTime, (oldValue) => oldValue?.ToString("yyyy-MM-dd"))
|
|
// ;
|
|
// 设置列
|
|
//result.GetColumn(query, w => w.OperatorName).SetColumn("操作人");
|
|
//result.GetColumn(query, w => w.OperatorName!).SetColumn<SysUser>(w => w.Name!);
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据id数组删除
|
|
/// </summary>
|
|
/// <param name="ids">ids</param>
|
|
/// <returns></returns>
|
|
public async Task DeleteListAsync(List<int> ids)
|
|
{
|
|
await this._defaultRepository.DeleteByIdsAsync(ids);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询表单数据
|
|
/// </summary>
|
|
/// <param name="id">id</param>
|
|
/// <returns></returns>
|
|
public async Task<Dictionary<string,object>> FindFormAsync(int id)
|
|
{
|
|
var res = new Dictionary<string, object>();
|
|
var form = await this._defaultRepository.FindByIdAsync(id);
|
|
form = form.NullSafe();
|
|
//if (form.CreateTime == null || form.CreateTime == DateTime.MinValue)
|
|
//{
|
|
// form.CreateTime = DateTime.Now;
|
|
//}
|
|
//if (form.UpdateTime == null || form.UpdateTime == DateTime.MinValue)
|
|
//{
|
|
// form.UpdateTime = DateTime.Now;
|
|
//}
|
|
res[nameof(id)] = id;
|
|
res[nameof(form)] = form;
|
|
return res;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存数据
|
|
/// </summary>
|
|
/// <param name="form">form</param>
|
|
/// <returns></returns>
|
|
public Task SaveFormAsync(T_Model_Config form)
|
|
{
|
|
return this._defaultRepository.InsertOrUpdateAsync(form);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导出Excel
|
|
/// </summary>
|
|
/// <param name="pagingSearchInput"></param>
|
|
/// <returns></returns>
|
|
public async Task<byte[]> ExportExcelAsync(PagingSearchInput<T_Model_Config> pagingSearchInput)
|
|
{
|
|
pagingSearchInput.Page = -1;
|
|
var tableViewModel = await this.FindListAsync(pagingSearchInput);
|
|
return ExcelUtil.ExportExcelByPagingView(tableViewModel, null, "Id");
|
|
}
|
|
|
|
|
|
|
|
} |