@model GenDbTableDto @{ var className = Model.EntityName; var classNameRemark = Model.DisplayName; var ignores = new string[] { "Id", "CreationTime", "CreatorUserId", "LastModificationTime", "LastModifierUserId", "DeletionTime", "DeleterUserId", "IsDeleted" }; var tableInfos = Model.TableInfos .Where(w => !ignores.Contains(w.ColumnName)) .OrderBy(w => w.Position) .ToList() ; var searchKeyWords = new[] { "Title", "Name", "Phone", "Address", "Email" }; var searchKeyWord = string.Empty; foreach (var item in searchKeyWords) { if (tableInfos.Any(w => w.ColumnName == item)) { searchKeyWord = item; break; } } }
using @(Model.Namespace).@(Model.DataBase == "MiaoYuChat" ? "Repository.ChatAI.Admin.Entities.Apps;" : "Repository.EntityFramework.Admin.Entities.Apps;")
namespace @(Model.Namespace).Api.Admin.ApplicationServices.Apps;

/// 
/// @(classNameRemark) 服务 @(className)Service
/// 
public class @(className)Service : ApplicationService<@("IRepository")<@(className)>>
{
    public @(className)Service(IRepository<@(className)> defaultRepository)
        : base(defaultRepository)
    {

    }

    /// 
    /// 获取列表数据
    /// 
    /// 
    /// 
    public async Task<@("PagingView")> FindListAsync(PagingSearchInput<@(className)> pagingSearchInput)
    {
        var query = this._defaultRepository.Select
                    @if (!string.IsNullOrWhiteSpace(searchKeyWord))
                    {
                        
.WhereIf(!string.IsNullOrWhiteSpace(pagingSearchInput.Search?.@(searchKeyWord)), w => w.@(searchKeyWord).Contains(pagingSearchInput.Search.@(searchKeyWord) ?? ""))
} @if (!string.IsNullOrWhiteSpace(searchKeyWord)) {
 .OrderByDescending(w => w.Id)
} @if (!string.IsNullOrWhiteSpace(searchKeyWord)) {
 .OrderByDescending(w => w.CreationTime)
} .Select(w => new { w.Id, @(string.Join(',', tableInfos.Select(w => "w." + w.ColumnName)))@(",") w.LastModificationTime, w.CreationTime }) ; var result = await _defaultRepository.AsPagingViewAsync(query, pagingSearchInput); @if (Model.DataBase != "MiaoYuChat") { // 覆盖值
  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; } /// /// 根据id数组删除 /// /// ids /// public async Task DeleteListAsync(List<@("Guid")> ids) { await this._defaultRepository.DeleteByIdsAsync(ids); } /// /// 查询表单数据 /// /// id /// public async Task<@("Dictionary")<@("string,object")>> FindFormAsync(Guid id) { var res = new Dictionary<@("string, object")>(); var form = await this._defaultRepository.FindByIdAsync(id); form = form.NullSafe(); res[nameof(id)] = id == Guid.Empty ? "" : id; res[nameof(form)] = form; return res; } /// /// 保存数据 /// /// form /// public Task SaveFormAsync(@className form) { return this._defaultRepository.InsertOrUpdateAsync(form); } /// /// 导出Excel /// /// /// public async Task<@("byte[]")> ExportExcelAsync(PagingSearchInput<@(className)> pagingSearchInput) { pagingSearchInput.Page = -1; var tableViewModel = await this.FindListAsync(pagingSearchInput); return ExcelUtil.ExportExcelByPagingView(tableViewModel, null, "Id"); } }