wxd 3 years ago
parent
commit
f81a0f7d38
  1. 38
      src/Shentun.Peis.Application/GuideTypes/GuideTypeAppService.cs
  2. 29
      src/Shentun.Peis.Application/MedicalReportTypes/MedicalReportTypeAppService.cs
  3. 12
      src/Shentun.Peis.Application/Sexs/SexAppService.cs
  4. 98
      src/Shentun.Peis.Domain/EntityHelper.cs

38
src/Shentun.Peis.Application/GuideTypes/GuideTypeAppService.cs

@ -1,4 +1,5 @@
using Shentun.Peis.Books;
using Microsoft.AspNetCore.Mvc;
using Shentun.Peis.Books;
using Shentun.Peis.GuidTypes;
using Shentun.Peis.Models;
using System;
@ -15,6 +16,10 @@ using Volo.Abp.ObjectMapping;
namespace Shentun.Peis.GuideTypes
{
/// <summary>
/// 指引类别
/// </summary>
[ApiExplorerSettings(GroupName = "Work")]
public class GuideTypeAppService : CrudAppService<
GuideType, //The Book entity
GuideTypeDto, //Used to show books
@ -23,6 +28,7 @@ namespace Shentun.Peis.GuideTypes
CreateGuideTypeDto,
UpdateGuideTypeDto>
{
private readonly GuideTypeManager _manager;
public GuideTypeAppService(
IRepository<GuideType, Guid> repository,
@ -38,7 +44,7 @@ namespace Shentun.Peis.GuideTypes
/// <returns></returns>
public override async Task<GuideTypeDto> GetAsync(Guid id)
{
var entity = await Repository.FindAsync(o=>o.Id == id);
var entity = await Repository.FindAsync(o => o.Id == id);
//throw new Exception("标准异常测试");
//throw new BusinessException("业务异常测试");
//throw new UserFriendlyException("友好异常测试");
@ -47,7 +53,7 @@ namespace Shentun.Peis.GuideTypes
if (entity == null)
return null;
return ObjectMapper.Map<GuideType, GuideTypeDto>(entity);
}
/// <summary>
/// 获取列表
@ -81,7 +87,7 @@ namespace Shentun.Peis.GuideTypes
{
var entity = await Repository.GetAsync(id);
var sourceEntity = ObjectMapper.Map<UpdateGuideTypeDto, GuideType>(input);
await _manager.UpdateAsync(sourceEntity,entity);
await _manager.UpdateAsync(sourceEntity, entity);
entity = await Repository.UpdateAsync(entity);
return ObjectMapper.Map<GuideType, GuideTypeDto>(entity);
}
@ -95,5 +101,29 @@ namespace Shentun.Peis.GuideTypes
return base.DeleteAsync(id);
}
/// <summary>
/// 修改排序 相邻之间
/// </summary>
/// <param name="id">需要修改的ID</param>
/// <param name="targetid">目标ID</param>
[HttpPut("api/app/guidetype/updatesort")]
public async Task UpdateSortAsync(Guid id, Guid targetid)
{
await EntityHelper.UpdateSort(Repository, id, targetid);
}
/// <summary>
/// 修改排序 置顶,置底
/// </summary>
/// <param name="id">需要修改的ID</param>
/// <param name="SortType">修改方式:1 置顶 2 置底</param>
/// <returns></returns>
[HttpPut("api/app/guidetype/updatemanysort")]
public async Task UpdateManySortAsync(Guid id, int SortType)
{
await EntityHelper.UpdateManySortAsync(Repository, id, SortType);
}
}
}

29
src/Shentun.Peis.Application/MedicalReportTypes/MedicalReportTypeAppService.cs

@ -1,4 +1,5 @@
using Shentun.Peis.Books;
using Microsoft.AspNetCore.Mvc;
using Shentun.Peis.Books;
using Shentun.Peis.GuidTypes;
using Shentun.Peis.Models;
using System;
@ -15,6 +16,10 @@ using Volo.Abp.ObjectMapping;
namespace Shentun.Peis.MedicalReportTypes
{
/// <summary>
/// 体检报告类别
/// </summary>
[ApiExplorerSettings(GroupName = "Work")]
public class MedicalReportTypeAppService : CrudAppService<
MedicalReportType, //The Book entity
MedicalReportTypeDto, //Used to show books
@ -95,5 +100,27 @@ namespace Shentun.Peis.MedicalReportTypes
return base.DeleteAsync(id);
}
/// <summary>
/// 修改排序 相邻之间
/// </summary>
/// <param name="id">需要修改的ID</param>
/// <param name="targetid">目标ID</param>
[HttpPut("api/app/medicalreporttype/updatesort")]
public async Task UpdateSortAsync(Guid id, Guid targetid)
{
await EntityHelper.UpdateSort(Repository, id, targetid);
}
/// <summary>
/// 修改排序 置顶,置底
/// </summary>
/// <param name="id">需要修改的ID</param>
/// <param name="SortType">修改方式:1 置顶 2 置底</param>
/// <returns></returns>
[HttpPut("api/app/medicalreporttype/updatemanysort")]
public async Task UpdateManySortAsync(Guid id, int SortType)
{
await EntityHelper.UpdateManySortAsync(Repository, id, SortType);
}
}
}

12
src/Shentun.Peis.Application/Sexs/SexAppService.cs

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Shentun.Peis.Sexs
{
public class SexAppService
{
}
}

98
src/Shentun.Peis.Domain/EntityHelper.cs

@ -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);
}
}
}
Loading…
Cancel
Save