track/src/SJZY.Track.Repository/Repositories/TrackStatusRepository.cs

70 lines
2.9 KiB
C#

using SJZY.Track.Domain.Aggregates.TrackStatusAggregate;
using SJZY.Track.Domain.Dtos.TrackStatus;
using SJZY.Track.Domain.VEntities;
namespace SJZY.Track.Repository.Repositories;
public class TrackStatusRepository : BasicRepository<TrackStatusEntity>, ITrackStatusRepository, IScopedDependency
{
/// <summary>
/// 获取轨迹状态明细
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<GetTrackStatusDetailVO?> GetDetailAsync(int id)
{
var detail = await Context.Queryable<TrackStatusEntity>()
.LeftJoin<VSystemEntity>((a, b) => a.SubSystemId == b.Id)
.Where((a, b) => a.Id == id)
.Select((a, b) => new GetTrackStatusDetailVO
{
Id = a.Id,
SubSystemId = a.SubSystemId,
SubSystem = b.CnName,
Code = a.Code,
EntrackStatus = a.EnStatus,
NodeId = a.Node,
TrackStatus = a.Status
})
.FirstAsync();
return detail;
}
/// <summary>
/// 分页获取轨迹状态
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<UnifyPageResultDto<GetTrackStatusListVO>> GetPageTrackStatus(GetPageTrackStatusVO input)
{
UnifyPageResultDto<GetTrackStatusListVO> pagedList = await Context.Queryable<TrackStatusEntity>()
.LeftJoin<VSystemEntity>((a, b) => a.SubSystemId == b.Id)
.LeftJoin<VUserEntity>((a, b, c) => a.CreateUserId == c.Id)
.LeftJoin<VUserEntity>((a, b, c, d) => a.UpdateUserId == d.Id)
.WhereIF(input.SubSystemId > 0, (a, b, c, d) => a.SubSystemId == input.SubSystemId)
.WhereIF(!input.Keywords.IsNullOrWhiteSpace(),
(a, b, c, d) => a.Status.Contains(input.Keywords) || a.EnStatus.Contains(input.Keywords) ||
a.Code.Contains(input.Keywords))
.OrderByIF(!input.SelectIds.IsNullOrEmpty(), (a, b) => SqlFunc.IIF(input.SelectIds.Contains(a.Id), SqlFunc.DateAdd(SqlFunc.GetDate(), 1), a.CreateTime), OrderByType.Desc)
.Select((a, b, c, d) => new GetTrackStatusListVO
{
Id = a.Id,
Code = a.Code,
EntrackStatus = a.EnStatus,
TrackStatus = a.Status,
NodeId = a.Node,
Node = SqlFunc.IF(a.Node == 1).Return("揽收").ElseIF(a.Node == 2).Return("干线").ElseIF(a.Node == 3)
.Return("清关")
.ElseIF(a.Node == 4).Return("中转").ElseIF(a.Node == 5).Return("派送")
.End(""),
CreateTime = a.CreateTime,
CreateUser = c.Name,
UpdateTime = a.UpdateTime,
UpdateUser = d.Name,
SubSystem = b.CnName
})
.ToPagedListAsync(input.PageIndex, input.PageSize);
return pagedList;
}
}