完善基础数据
This commit is contained in:
+92
@@ -0,0 +1,92 @@
|
||||
using FreeSql;
|
||||
using F9WebAiTest.Application.Common;
|
||||
using F9WebAiTest.Application.Dtos.SYS.Gongyingshangs;
|
||||
using F9WebAiTest.Application.Interfaces.Repositories.SYS.Gongyingshangs;
|
||||
using F9WebAiTest.Domain.Entities.SYS.Gongyingshangs;
|
||||
using F9WebAiTest.Domain.Enums.SYS.Gongyingshangs;
|
||||
using F9WebAiTest.Domain.Interfaces.SYS.Gongyingshangs;
|
||||
|
||||
namespace F9WebAiTest.Infrastructure.FreeSqls.Repositories.SYS.Gongyingshangs;
|
||||
|
||||
internal class GongyingshangWriteRepository : F9RepositoryBase, IGongyingshangWriteRepository
|
||||
{
|
||||
public GongyingshangWriteRepository(IFreeSql fsql) : base(fsql) { }
|
||||
|
||||
public async Task<Gongyingshang> GetByIdAsync(long id, CancellationToken cancellationToken)
|
||||
=> await Orm.Select<Gongyingshang>().Where(x => x.Id == id && x.DeletedAt == null).FirstAsync(cancellationToken);
|
||||
|
||||
public async Task<bool> AddAsync(Gongyingshang entity)
|
||||
{
|
||||
entity.CreatedAt = DateTime.Now;
|
||||
return await Orm.Insert(entity).ExecuteAffrowsAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateAsync(Gongyingshang entity)
|
||||
{
|
||||
entity.UpdatedAt = DateTime.Now;
|
||||
return await Orm.Update<Gongyingshang>().SetSource(entity).ExecuteAffrowsAsync() > 0;
|
||||
}
|
||||
|
||||
public async Task<bool> SoftDeleteAsync(long id)
|
||||
=> await Orm.Update<Gongyingshang>()
|
||||
.Set(x => x.IsDeleted, true)
|
||||
.Set(x => x.DeletedAt, DateTime.Now)
|
||||
.Where(x => x.Id == id)
|
||||
.ExecuteAffrowsAsync() > 0;
|
||||
}
|
||||
|
||||
internal class GongyingshangReadRepository : F9RepositoryBase, IGongyingshangReadRepository
|
||||
{
|
||||
public GongyingshangReadRepository(IFreeSql fsql) : base(fsql) { }
|
||||
|
||||
public async Task<PageResult<GongyingshangReadDto_View>> GetPagedAsync(Gys_Type_Enum type, Gys_SaleType_Enum? saleType,
|
||||
string keyword, int pageIndex, int pageSize)
|
||||
{
|
||||
if (pageIndex <= 0) pageIndex = 1;
|
||||
if (pageSize <= 0) pageSize = 20;
|
||||
|
||||
var query = Orm.Select<Gongyingshang>().Where(x => x.DeletedAt == null && x.Type == type);
|
||||
if (saleType.HasValue) query = query.Where(x => x.SaleType == saleType.Value);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(keyword))
|
||||
{
|
||||
var kw = keyword.Trim();
|
||||
query = query.Where(x => x.Name.Contains(kw) || x.Pinyin.Contains(kw) || x.Lianxiren.Contains(kw)
|
||||
|| x.Phone.Contains(kw) || x.Address.Contains(kw));
|
||||
}
|
||||
|
||||
var total = await query.CountAsync();
|
||||
var items = await query
|
||||
.OrderBy(x => x.Name)
|
||||
.Page(pageIndex, pageSize)
|
||||
.ToListAsync(x => new GongyingshangReadDto_View(x.Id, x.Name, x.Type, "", x.BusinessGroup, "",
|
||||
x.SaleType, "", x.Lianxiren, x.Phone, x.Address, x.Pinyin));
|
||||
|
||||
var list = items
|
||||
.Select(x => x with
|
||||
{
|
||||
TypeName = x.Type.ToString(),
|
||||
Grouname = x.Group.ToString(),
|
||||
SaleTypeName = SaleTypeText(x.SaleType)
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return new PageResult<GongyingshangReadDto_View>
|
||||
{
|
||||
Items = list,
|
||||
Total = total,
|
||||
PageIndex = pageIndex,
|
||||
PageSize = pageSize
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<GongyingshangDto_Edit> GetByIdForEditAsync(long id)
|
||||
=> await Orm.Select<Gongyingshang>()
|
||||
.Where(x => x.Id == id && x.DeletedAt == null)
|
||||
.FirstAsync(x => new GongyingshangDto_Edit(x.Id, x.Name, x.Type, x.BusinessGroup, x.SaleType,
|
||||
x.Lianxiren, x.Phone, x.Address, x.Pinyin));
|
||||
|
||||
/// <summary>销售类型显示文本(0 等非枚举值视为未设置)</summary>
|
||||
internal static string SaleTypeText(Gys_SaleType_Enum saleType)
|
||||
=> Enum.IsDefined(typeof(Gys_SaleType_Enum), saleType) ? saleType.ToString() : "未设置";
|
||||
}
|
||||
Reference in New Issue
Block a user