track/src/TrackCenter.Repository/Repositories/TrackFlagRepository.cs
2025-11-03 20:09:14 +08:00

67 lines
2.7 KiB
C#

using TrackCenter.Domain.Aggregates.TrackFlagAggregate;
using TrackCenter.Domain.Dtos.TrackFlags;
using TrackCenter.Domain.VEntities;
namespace TrackCenter.Repository.Repositories;
public class TrackFlagRepository : BasicRepository<TrackFlagEntity>, ITrackFlagRepository, IScopedDependency
{
/// <summary>
/// 获取轨迹标记明细
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<GetTrackFlagDetailVO?> GetDetailAsync(int id)
{
var detail = await Context.Queryable<TrackFlagEntity>()
.LeftJoin<VAppEntity>((a, b) => a.AppKey == b.AppKey && b.IsDeleted == false)
.Where((a, b) => a.Id == id)
.Select((a, b) => new GetTrackFlagDetailVO
{
Id = a.Id,
AppKey = a.AppKey,
AppName = b.Name,
Code = a.Code,
Flag = a.Name,
IsToMq = a.IsToMq
})
.FirstAsync();
return detail;
}
/// <summary>
/// 分页获取轨迹标记
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<PagedResult<GetTrackFlagListVO>> GetPageTrackFlag(GetPageTrackFlagVO input)
{
PagedResult<GetTrackFlagListVO> pagedList = new PagedResult<GetTrackFlagListVO>();
pagedList = await Context.Queryable<TrackFlagEntity>()
.LeftJoin<VAppEntity>((a, b) => a.AppKey == b.AppKey && b.IsDeleted == false)
.LeftJoin<VUserEntity>((a, b, c) => a.CreateUserId == c.UserId && c.IsDelete == false)
.LeftJoin<VUserEntity>((a, b, c, d) => a.UpdateUserId == d.UserId && d.IsDelete == false)
.WhereIF(!input.AppKey.IsNullOrWhiteSpace(), (a, b, c, d) => a.AppKey == input.AppKey)
.WhereIF(!input.Keywords.IsNullOrWhiteSpace(), (a, b, c, d) => SqlFunc.Contains(a.Code, input.Keywords))
.OrderByIF(input.SelectIds.IsNullOrEmpty(), (a, b, c, d) => a.CreateTime, OrderByType.Desc)
.OrderByIF(!input.SelectIds.IsNullOrEmpty(),
(a, b, c, d) => SqlFunc.IIF(input.SelectIds!.Contains(a.Id), SqlFunc.DateAdd(SqlFunc.GetDate(), 1),
a.CreateTime), OrderByType.Desc)
.Select((a, b, c, d) => new GetTrackFlagListVO
{
Id = a.Id,
App = b.Name,
Code = a.Code,
Flag = a.Name,
IsToMq = a.IsToMq,
CreateTime = a.CreateTime,
CreateUser = c.Name,
UpdateTime = a.UpdateTime,
UpdateUser = d.Name
})
.ToPagedListAsync(input.PageIndex, input.PageSize);
return pagedList;
}
}