123 lines
3.9 KiB
C#
123 lines
3.9 KiB
C#
using Admin.NET.Core.Service;
|
|
using Admin.NET.Application.Const;
|
|
using Admin.NET.Application.Entity;
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
namespace Admin.NET.Application;
|
|
/// <summary>
|
|
/// 单位组服务
|
|
/// </summary>
|
|
[ApiDescriptionSettings(ApplicationConst.GroupName, Order = 100)]
|
|
public class SysUnitGroupService : IDynamicApiController, ITransient
|
|
{
|
|
private readonly SqlSugarRepository<SysUnitGroup> _rep;
|
|
|
|
private readonly SysUnitService _sysUnitService;
|
|
|
|
public SysUnitGroupService(SqlSugarRepository<SysUnitGroup> rep,
|
|
SysUnitService sysUnitService )
|
|
{
|
|
_rep = rep;
|
|
_sysUnitService = sysUnitService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分页查询单位组
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[ApiDescriptionSettings(Name = "Page")]
|
|
public async Task<SqlSugarPagedList<SysUnitGroupOutput>> Page(SysUnitGroupInput input)
|
|
{
|
|
var query = _rep.AsQueryable().Where(a => !a.IsDelete)
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.SearchKey), u =>
|
|
u.CreateOrgName.Contains(input.SearchKey.Trim())
|
|
|| u.Name.Contains(input.SearchKey.Trim())
|
|
)
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.CreateOrgName), u => u.CreateOrgName.Contains(input.CreateOrgName.Trim()))
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Name), u => u.Name.Contains(input.Name.Trim()))
|
|
.Select<SysUnitGroupOutput>();
|
|
return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 增加单位组
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[ApiDescriptionSettings(Name = "Add")]
|
|
public async Task<long> Add(AddSysUnitGroupInput input)
|
|
{
|
|
var entity = input.Adapt<SysUnitGroup>();
|
|
await _rep.InsertAsync(entity);
|
|
return entity.Id;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除单位组
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[ApiDescriptionSettings(Name = "Delete")]
|
|
public async Task Delete(DeleteSysUnitGroupInput input)
|
|
{
|
|
var entity = await _rep.GetFirstAsync(u => u.Id == input.Id) ?? throw Oops.Oh(ErrorCodeEnum.D1002);
|
|
await _rep.FakeDeleteAsync(entity); //假删除
|
|
//await _rep.DeleteAsync(entity); //真删除
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新单位组
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[ApiDescriptionSettings(Name = "Update")]
|
|
public async Task Update(UpdateSysUnitGroupInput input)
|
|
{
|
|
var entity = input.Adapt<SysUnitGroup>();
|
|
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取单位组
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[ApiDescriptionSettings(Name = "Detail")]
|
|
public async Task<SysUnitGroup> Detail([FromQuery] QueryByIdSysUnitGroupInput input)
|
|
{
|
|
return await _rep.GetFirstAsync(u => u.Id == input.Id);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取单位组列表
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[ApiDescriptionSettings(Name = "List")]
|
|
public async Task<List<SysUnitGroupOutput>> List()
|
|
{
|
|
return await _rep.AsQueryable().Where(a => !a.IsDelete).Select<SysUnitGroupOutput>().ToListAsync();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 检查单位是否存在数据
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[ApiDescriptionSettings(Name = "CheckUnitList")]
|
|
public async Task<bool> CheckUnitList(CheckSysUnitGroupInput input)
|
|
{
|
|
var sysUnits = await _sysUnitService.ListByGroupId(input.Id);
|
|
return sysUnits.Any();
|
|
}
|
|
}
|
|
|