|
|
|
@ -1,8 +1,10 @@ |
|
|
|
using System; |
|
|
|
using Shentun.Peis.Models; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Text; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp.Auditing; |
|
|
|
using Volo.Abp.Domain.Entities; |
|
|
|
using Volo.Abp.Domain.Repositories; |
|
|
|
|
|
|
|
@ -16,11 +18,101 @@ namespace Shentun.Peis |
|
|
|
/// <typeparam name="TEntity"></typeparam>
|
|
|
|
/// <param name="repository"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static async Task<int> CreateMaxDisplayOrder<TEntity>(IRepository<TEntity> repository) |
|
|
|
where TEntity: class, IEntity,IDisplayOrder |
|
|
|
public static async Task<int> CreateMaxDisplayOrder<TEntity>(IRepository<TEntity> repository) |
|
|
|
where TEntity : class, IEntity, IDisplayOrder |
|
|
|
{ |
|
|
|
int? maxDisplayOrder = await repository.MaxAsync(o => (int?)o.DisplayOrder); |
|
|
|
return (maxDisplayOrder ?? 0) + 1; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 修改排序,相邻之间修改
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="TEntity"></typeparam>
|
|
|
|
/// <param name="repository"></param>
|
|
|
|
/// <param name="id">当前ID</param>
|
|
|
|
/// <param name="targetid">目标ID</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static async Task UpdateSort<TEntity>(IRepository<TEntity, Guid> repository, Guid id, Guid targetid) |
|
|
|
where TEntity : class, IEntity<Guid>, IDisplayOrder |
|
|
|
{ |
|
|
|
var entity = await repository.GetAsync(id); |
|
|
|
var targetentity = await repository.GetAsync(targetid); |
|
|
|
|
|
|
|
int olddisplaynum = entity.DisplayOrder; |
|
|
|
entity.DisplayOrder = targetentity.DisplayOrder; |
|
|
|
targetentity.DisplayOrder = olddisplaynum; |
|
|
|
|
|
|
|
List<TEntity> entlist = new List<TEntity>(); |
|
|
|
entlist.Add(entity); |
|
|
|
entlist.Add(targetentity); |
|
|
|
|
|
|
|
await repository.UpdateManyAsync(entlist); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 修改排序 置顶,置底
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="TEntity"></typeparam>
|
|
|
|
/// <param name="repository"></param>
|
|
|
|
/// <param name="id">需要修改的ID</param>
|
|
|
|
/// <param name="SortType">修改方式:1 置顶 2 置底</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public static async Task UpdateManySortAsync<TEntity>(IRepository<TEntity, Guid> repository, Guid id, int SortType) |
|
|
|
where TEntity : class, IEntity<Guid>, IDisplayOrder |
|
|
|
{ |
|
|
|
var entity = await repository.GetAsync(id); |
|
|
|
|
|
|
|
List<TEntity> UptList = new List<TEntity>(); |
|
|
|
|
|
|
|
if (SortType == 1) |
|
|
|
{ |
|
|
|
UptList = (await repository.GetListAsync(o => o.DisplayOrder > entity.DisplayOrder)).OrderBy(o => o.DisplayOrder).ToList(); |
|
|
|
|
|
|
|
if (UptList.Count > 0) |
|
|
|
{ |
|
|
|
|
|
|
|
int indexnum = entity.DisplayOrder; //原有值
|
|
|
|
|
|
|
|
entity.DisplayOrder = UptList[UptList.Count - 1].DisplayOrder; //修改当前排序值为最大
|
|
|
|
|
|
|
|
//置顶操作,往上一行开始,逐渐替换
|
|
|
|
foreach (var item in UptList) |
|
|
|
{ |
|
|
|
int dqnum = item.DisplayOrder; |
|
|
|
item.DisplayOrder = indexnum; |
|
|
|
indexnum = dqnum; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
UptList = (await repository.GetListAsync(o => o.DisplayOrder < entity.DisplayOrder)).OrderByDescending(o => o.DisplayOrder).ToList(); ; |
|
|
|
|
|
|
|
int indexnum = entity.DisplayOrder; //原有值
|
|
|
|
|
|
|
|
entity.DisplayOrder = UptList[UptList.Count - 1].DisplayOrder; //修改当前排序值为最小
|
|
|
|
|
|
|
|
//置底操作,往下一行开始,逐渐替换
|
|
|
|
foreach (var item in UptList) |
|
|
|
{ |
|
|
|
int dqnum = item.DisplayOrder; |
|
|
|
item.DisplayOrder = indexnum; |
|
|
|
indexnum = dqnum; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
UptList.Add(entity); |
|
|
|
|
|
|
|
|
|
|
|
await repository.UpdateManyAsync(UptList); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |