refactor: 轨迹明细弃用IsVisibility字段,新增IsExternal字段替代 轨迹内容上的是否对外作用:创建轨迹时如果是否对外字段留null,则以轨迹内容上的【是否对外】值做为默认值填充。IsExternal作用:在查询轨迹时判断如果是外部子系统,则过滤掉是否对外为false的轨迹
277 lines
14 KiB
C#
277 lines
14 KiB
C#
using System.Linq.Expressions;
|
|
using SJZY.Track.Domain.Aggregates.TrackContentAggregate;
|
|
using SJZY.Track.Domain.Aggregates.TrackFlagAggregate;
|
|
using SJZY.Track.Domain.Aggregates.TrackStatusAggregate;
|
|
using SJZY.Track.Domain.Aggregates.TrackTemplateAggregate;
|
|
using SJZY.Track.Domain.Dtos.TrackContents;
|
|
using SJZY.Track.Domain.VEntities;
|
|
|
|
namespace SJZY.Track.Repository.Repositories;
|
|
|
|
public class TrackContentRepository : BasicRepository<TrackContentEntity>, ITrackContentRepository, IScopedDependency
|
|
{
|
|
/// <summary>
|
|
/// 获取轨迹内容明细
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
public async Task<GetTrackContentDetailVO?> GetDetailAsync(int id)
|
|
{
|
|
var detail = await Context.Queryable<TrackContentEntity>()
|
|
.LeftJoin<TrackStatusEntity>((a, b) => a.TrackStatusId == b.Id && b.IsDeleted == false)
|
|
.LeftJoin<VSystemEntity>((a, b, d) => a.SubSystemId == d.Id && d.IsDeleted == false)
|
|
.Where((a, b, d) => a.Id == id)
|
|
.Select((a, b, d) => new GetTrackContentDetailVO
|
|
{
|
|
Id = a.Id,
|
|
SubSystemId = a.SubSystemId,
|
|
SubSystem = d.CnName,
|
|
TrackStatusId = a.TrackStatusId,
|
|
TrackStatus = b.Status,
|
|
Code = a.Code,
|
|
Content = a.Content,
|
|
EnContent = a.EnContent,
|
|
TrackFlagId = a.TrackFlagId,
|
|
IsExternal = a.IsExternal,
|
|
IsRepeatable = a.IsRepeatable,
|
|
IsAllowManuallyUpdate = a.IsAllowManuallyUpdate,
|
|
IsAllowManuallyCreate = a.IsAllowManuallyCreate
|
|
})
|
|
.Mapper(x => { x.TrackFlagIds = x.TrackFlagId?.Split(',').Select(int.Parse).ToList(); })
|
|
.FirstAsync();
|
|
return detail;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分页获取轨迹内容
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
public async Task<UnifyPageResultDto<GetTrackContentListVO>> GetPageTrackContent(GetPageTrackContentVO input)
|
|
{
|
|
var pagedList = await Context.Queryable<TrackContentEntity>()
|
|
.LeftJoin<TrackStatusEntity>((a, b) => a.TrackStatusId == b.Id && b.IsDeleted == false)
|
|
.LeftJoin<VSystemEntity>((a, b, d) => a.SubSystemId == d.Id && d.IsDeleted == false)
|
|
.LeftJoin<VUserEntity>((a, b, d, e) => a.CreateUserId == e.Id && e.IsDeleted == false)
|
|
.LeftJoin<VUserEntity>((a, b, d, e, f) => a.UpdateUserId == f.Id && f.IsDeleted == false)
|
|
.WhereIF(input.SubSystemId > 0, (a, b, d, e, f) => a.SubSystemId == input.SubSystemId)
|
|
.WhereIF(!input.Keywords.IsNullOrWhiteSpace(),
|
|
(a, b, d, e, f) => a.Code.Contains(input.Keywords) || a.Content.Contains(input.Keywords)
|
|
|| a.EnContent.Contains(input.Keywords))
|
|
.WhereIF(input.TrackStatusId > 0, (a, b, d, e, f) => a.TrackStatusId == input.TrackStatusId)
|
|
.OrderByIF(input.SelectIds.IsNullOrEmpty(), (a, b, d, e, f) => a.CreateTime, OrderByType.Desc)
|
|
.OrderByIF(!input.SelectIds.IsNullOrEmpty(),
|
|
(a, b, d, e, f) => SqlFunc.IIF(input.SelectIds.Contains(a.Id), SqlFunc.DateAdd(SqlFunc.GetDate(), 1),
|
|
a.CreateTime), OrderByType.Desc)
|
|
.Select((a, b, d, e, f) => new GetTrackContentListVO
|
|
{
|
|
Id = a.Id,
|
|
SubSystem = d.CnName,
|
|
Code = a.Code,
|
|
Content = a.Content,
|
|
EnContent = a.EnContent,
|
|
TrackStatus = b.Status,
|
|
IsExternal = a.IsExternal,
|
|
Node = SqlFunc.IF(b.Node == 1).Return("揽收").ElseIF(b.Node == 2).Return("清关").ElseIF(b.Node == 3)
|
|
.Return("干线")
|
|
.ElseIF(b.Node == 4).Return("派送").ElseIF(b.Node == 5).Return("其他")
|
|
.End(""),
|
|
TrackFlag = SqlFunc.Subqueryable<TrackFlagEntity>()
|
|
.Where(x => SqlFunc.SplitIn(a.TrackFlagId, x.Id.ToString()))
|
|
.SelectStringJoin(x => x.Name, ","),
|
|
CreateTime = a.CreateTime,
|
|
CreateUser = e.Name,
|
|
UpdateTime = a.UpdateTime,
|
|
UpdateUser = f.Name,
|
|
IsRepeatable = a.IsRepeatable,
|
|
IsAllowManuallyUpdate = a.IsAllowManuallyUpdate,
|
|
IsAllowManuallyCreate = a.IsAllowManuallyCreate
|
|
})
|
|
.ToPagedListAsync(input.PageIndex, input.PageSize);
|
|
|
|
return pagedList;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取轨迹模版是否存在
|
|
/// </summary>
|
|
/// <param name="trackContentId"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> GetTemplateIsExist(int trackContentId)
|
|
{
|
|
//var trackTemplateContents = await _trackTemplateContentBasicQuery.GetListAsync(a => a.TrackContentId == input.Id);
|
|
var trackContentEntities = await Context.Queryable<TrackContentEntity>()
|
|
.LeftJoin<TrackTemplateContentEntity>((a, b) => a.Id == b.TrackContentId && b.IsDeleted == false)
|
|
.LeftJoin<TrackTemplateEntity>((a, b, c) => b.TrackTemplateId == c.Id && c.IsDeleted == false)
|
|
.Where((a, b, c) => a.Id == trackContentId)
|
|
.Select((a, b, c) => new
|
|
{
|
|
TrackContentId = a.Id,
|
|
TemplateId = c.Id
|
|
})
|
|
.ToListAsync();
|
|
|
|
if (trackContentEntities.Any(a => a.TemplateId > 0))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public async Task<UnifyPageResultDto<GetTrackContentMapPageOutputVO>> GetMapPageAsync(
|
|
GetTrackContentMapPageInputVO input)
|
|
{
|
|
return await Context.Queryable<TrackContentMapEntity>()
|
|
.InnerJoin<TrackContentEntity>((contentMap, sourceContent) =>
|
|
contentMap.TrackContentId == sourceContent.Id && !sourceContent.IsDeleted)
|
|
.InnerJoin<TrackContentEntity>((contentMap, sourceContent, targetContent) =>
|
|
contentMap.MapTrackContentId == targetContent.Id && !targetContent.IsDeleted)
|
|
.LeftJoin<VSystemEntity>((contentMap, sourceContent, targetContent, sourceSystem) =>
|
|
contentMap.SubSystemId == sourceSystem.Id && !sourceSystem.IsDeleted)
|
|
.LeftJoin<VSystemEntity>((contentMap, sourceContent, targetContent, sourceSystem, targetSystem) =>
|
|
contentMap.MapSubSystemId == targetSystem.Id && !targetSystem.IsDeleted)
|
|
.LeftJoin<TrackStatusEntity>(
|
|
(contentMap, sourceContent, targetContent, sourceSystem, targetSystem, sourceStatus) =>
|
|
sourceContent.TrackStatusId == sourceStatus.Id && !sourceStatus.IsDeleted)
|
|
.LeftJoin<TrackStatusEntity>(
|
|
(contentMap, sourceContent, targetContent, sourceSystem, targetSystem, sourceStatus, targetStatus) =>
|
|
targetContent.TrackStatusId == targetStatus.Id && !targetStatus.IsDeleted)
|
|
.Filter(null, true)
|
|
.Where(contentMap => !contentMap.IsDeleted)
|
|
.WhereIF(input.SubSystemId.HasValue, contentMap => contentMap.SubSystemId == input.SubSystemId)
|
|
.WhereIF(input.MapSubSystemId.HasValue, contentMap => contentMap.MapSubSystemId == input.MapSubSystemId)
|
|
.WhereIF(!input.Keywords.IsNullOrWhiteSpace(),
|
|
(contentMap, sourceContent) => sourceContent.Code.Contains(input.Keywords) ||
|
|
sourceContent.Content.Contains(input.Keywords) ||
|
|
sourceContent.EnContent.Contains(input.Keywords))
|
|
.OrderByDescending(contentMap => contentMap.CreateTime)
|
|
.Select(
|
|
(contentMap, sourceContent, targetContent, sourceSystem, targetSystem, sourceStatus, targetStatus) =>
|
|
new GetTrackContentMapPageOutputVO
|
|
{
|
|
Id = contentMap.Id,
|
|
SubSystem = sourceSystem.CnName,
|
|
Code = contentMap.TrackContentCode,
|
|
TrackStatus = sourceStatus.Status,
|
|
Content = sourceContent.Content,
|
|
EnContent = sourceContent.EnContent,
|
|
MapSubSystem = targetSystem.CnName,
|
|
MapCode = contentMap.MapTrackContentCode,
|
|
MapTrackStatus = targetStatus.Status,
|
|
MapContent = targetContent.Content,
|
|
MapEnContent = targetContent.EnContent
|
|
})
|
|
.ToPagedListAsync(input.PageIndex, input.PageSize);
|
|
}
|
|
|
|
public async Task<GetTrackContentMapDetailOutputVO> GetMapDetailAsync(int id)
|
|
{
|
|
return await Context.Queryable<TrackContentMapEntity>()
|
|
.InnerJoin<TrackContentEntity>((contentMap, sourceContent) =>
|
|
contentMap.TrackContentId == sourceContent.Id && !sourceContent.IsDeleted)
|
|
.InnerJoin<TrackContentEntity>((contentMap, sourceContent, targetContent) =>
|
|
contentMap.MapTrackContentId == targetContent.Id && !targetContent.IsDeleted)
|
|
.LeftJoin<VSystemEntity>((contentMap, sourceContent, targetContent, sourceSystem) =>
|
|
contentMap.SubSystemId == sourceSystem.Id && !sourceSystem.IsDeleted)
|
|
.LeftJoin<VSystemEntity>((contentMap, sourceContent, targetContent, sourceSystem, targetSystem) =>
|
|
contentMap.MapSubSystemId == targetSystem.Id && !targetSystem.IsDeleted)
|
|
.Filter(null, true)
|
|
.Where(contentMap => contentMap.Id == id && !contentMap.IsDeleted)
|
|
.Select((contentMap, sourceContent, targetContent, sourceSystem, targetSystem) =>
|
|
new GetTrackContentMapDetailOutputVO
|
|
{
|
|
Id = contentMap.Id,
|
|
SubSystemId = contentMap.SubSystemId,
|
|
SubSystem = sourceSystem.CnName,
|
|
TrackContent = contentMap.TrackContentCode + "-" + sourceContent.Content,
|
|
MapSubSystem = targetSystem.CnName,
|
|
MapTrackContent = contentMap.MapTrackContentCode + "-" + targetContent.Content
|
|
}, true)
|
|
.SingleAsync();
|
|
}
|
|
|
|
public async Task<bool> IsMapAnyAsync(Expression<Func<TrackContentMapEntity, bool>> whereExpression)
|
|
{
|
|
return await Context.Queryable<TrackContentMapEntity>().Where(whereExpression).AnyAsync();
|
|
}
|
|
|
|
public async Task<bool> InsertMapAsync(TrackContentMapEntity insertObj)
|
|
{
|
|
return await Context.Insertable(insertObj).ExecuteCommandAsync() > 0;
|
|
}
|
|
|
|
public async Task<TrackContentMapEntity> GetMapByIdAsync(int id)
|
|
{
|
|
return await Context.Queryable<TrackContentMapEntity>().InSingleAsync(id);
|
|
}
|
|
|
|
public async Task<bool> UpdateMapAsync(TrackContentMapEntity updateObj)
|
|
{
|
|
return await Context.Updateable(updateObj).ExecuteCommandHasChangeAsync();
|
|
}
|
|
|
|
public async Task<bool> SoftDeleteMapAsync(Expression<Func<TrackContentMapEntity, bool>> whereExpression)
|
|
{
|
|
return await Context.Updateable<TrackContentMapEntity>()
|
|
.Where(whereExpression)
|
|
.SetColumns(nameof(ISoftDeleteBasicEntity.IsDeleted), true)
|
|
.ExecuteCommandHasChangeAsync();
|
|
}
|
|
|
|
public async Task<bool> UpdateMapAsync(Expression<Func<TrackContentMapEntity, TrackContentMapEntity>> columns,
|
|
Expression<Func<TrackContentMapEntity, bool>> whereExpression)
|
|
{
|
|
return await Context.Updateable<TrackContentMapEntity>().SetColumns(columns).Where(whereExpression)
|
|
.ExecuteCommandAsync() > 0;
|
|
}
|
|
|
|
public Task<TrackContentEntity> GetByCodeAsync(int systemId, string code)
|
|
{
|
|
return Context.Queryable<TrackContentEntity>().FirstAsync(m => m.SubSystemId == systemId && m.Code == code);
|
|
}
|
|
|
|
public Task<List<TrackContentEntity>> GetListBySystemIdAsync(int systemId)
|
|
{
|
|
return Context.Queryable<TrackContentEntity>()
|
|
.Where(content => content.SubSystemId == systemId && !content.IsDeleted)
|
|
.Select((content) => new TrackContentEntity
|
|
{
|
|
Id = content.Id,
|
|
Code = content.Code,
|
|
IsExternal = content.IsExternal,
|
|
EnContent = content.EnContent,
|
|
Content = content.Content,
|
|
IsRepeatable = content.IsRepeatable,
|
|
IsAllowManuallyCreate = content.IsAllowManuallyCreate,
|
|
IsAllowManuallyUpdate = content.IsAllowManuallyUpdate,
|
|
})
|
|
.ToListAsync();
|
|
}
|
|
|
|
public Task<List<TrackContentVO>> GetTrackContentBySyetemIdAsync(int subSystemId)
|
|
{
|
|
return Context.Queryable<TrackContentEntity>()
|
|
.LeftJoin<TrackStatusEntity>((x, y) => x.TrackStatusId == y.Id)
|
|
.LeftJoin<VSystemEntity>((x, y, z) => x.SubSystemId == z.Id)
|
|
.Where(x => x.SubSystemId == subSystemId)
|
|
.Select((x, y, z) => new TrackContentVO
|
|
{
|
|
SubSystemCode = z.Key,
|
|
TrackStatusId = x.TrackStatusId,
|
|
TrackStatus = y.Status,
|
|
TrackStatusCode = y.Code,
|
|
TrackContentId = x.Id,
|
|
TrackContent = x.Content,
|
|
TrackContentCode = x.Code,
|
|
TrackEnContent = x.EnContent,
|
|
IsCompleted = y.IsCompleted,
|
|
IsRepeatable = x.IsRepeatable,
|
|
IsAllowManuallyUpdate = x.IsAllowManuallyUpdate,
|
|
IsAllowManuallyCreate = x.IsAllowManuallyCreate,
|
|
IsToMq = y.IsToMq,
|
|
IsExternal = x.IsExternal
|
|
}).ToListAsync();
|
|
}
|
|
}
|