158 lines
6.1 KiB
C#
158 lines
6.1 KiB
C#
using Admin.NET.Core;
|
|
using Furion.DatabaseAccessor;
|
|
|
|
using Furion.DependencyInjection;
|
|
using Furion.DynamicApiController;
|
|
using Furion.FriendlyException;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Dynamic.Core;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Admin.NET.Application
|
|
{
|
|
/// <summary>
|
|
/// 量表描述服务
|
|
/// </summary>
|
|
[ApiDescriptionSettings("测评服务", Name = "BusScaleDescription", Order = 100)]
|
|
[Route("api/[Controller]")]
|
|
public class BusScaleDescriptionService : IDynamicApiController, ITransient
|
|
{
|
|
private readonly SqlSugarRepository<BusScaleDescription> _busScaleDescriptionRep;
|
|
private readonly UserManager _userManager;
|
|
public BusScaleDescriptionService(
|
|
SqlSugarRepository<BusScaleDescription> busScaleDescriptionRep,
|
|
UserManager userManager
|
|
)
|
|
{
|
|
_busScaleDescriptionRep = busScaleDescriptionRep;
|
|
_userManager = userManager;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分页查询量表描述
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("page")]
|
|
public async Task<SqlSugarPagedList<BusScaleDescriptionOutput>> Page([FromQuery] BusScaleDescriptionInput input)
|
|
{
|
|
var busScaleDescriptions = await _busScaleDescriptionRep.AsQueryable()
|
|
.Where(u => u.ScaleId == input.ScaleId)
|
|
.WhereIF(!string.IsNullOrEmpty(input.Introduce), u => u.Introduce == input.Introduce)
|
|
.WhereIF(!string.IsNullOrEmpty(input.Application), u => u.Application == input.Application)
|
|
.WhereIF(!string.IsNullOrEmpty(input.Notice), u => u.Notice == input.Notice)
|
|
.Where(u => u.Sort == input.Sort)
|
|
.OrderBy(u => u.CreateTime, OrderByType.Desc)
|
|
.OrderBuilder(input)
|
|
.Select(s => new BusScaleDescriptionOutput()
|
|
{
|
|
Introduce = s.Introduce,
|
|
Application = s.Application,
|
|
Notice = s.Notice,
|
|
Sort = s.Sort,
|
|
Id = s.Id
|
|
})
|
|
.ToPagedListAsync(input.Page, input.PageSize);
|
|
|
|
return busScaleDescriptions;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 增加量表描述
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("add")]
|
|
public async Task Add(AddBusScaleDescriptionInput input)
|
|
{
|
|
var busScaleDescription = input.Adapt<BusScaleDescription>();
|
|
await _busScaleDescriptionRep.InsertAsync(busScaleDescription);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除量表描述
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("delete")]
|
|
public async Task Delete(DeleteBusScaleDescriptionInput input)
|
|
{
|
|
var busScaleDescription = await _busScaleDescriptionRep.AsQueryable().FirstAsync(u => u.Id == input.Id);
|
|
await _busScaleDescriptionRep.FakeDeleteAsync(busScaleDescription);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新量表描述
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("edit")]
|
|
public async Task Update(UpdateBusScaleDescriptionInput input)
|
|
{
|
|
var isExist = await _busScaleDescriptionRep.AsQueryable().AnyAsync(u => u.Id == input.Id);
|
|
if (!isExist) throw Oops.Oh(ErrorCodeEnum.D3000);
|
|
|
|
var busScaleDescription = input.Adapt<BusScaleDescription>();
|
|
await _busScaleDescriptionRep.UpdateAsync(busScaleDescription);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取量表描述
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("detail")]
|
|
public async Task<BusScaleDescriptionOutput> Get([FromQuery] QueryeBusScaleDescriptionInput input)
|
|
{
|
|
return (await _busScaleDescriptionRep.AsQueryable().FirstAsync(u => u.Id == input.Id)).Adapt<BusScaleDescriptionOutput>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取量表描述列表
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("list")]
|
|
public async Task<List<BusScaleDescriptionOutput>> List([FromQuery] BusScaleDescriptionInput input)
|
|
{
|
|
return await _busScaleDescriptionRep.AsQueryable().Select<BusScaleDescriptionOutput>().ToListAsync();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 数据导入
|
|
/// </summary>
|
|
/// <param name="file"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("import")]
|
|
public async Task Imports(IFormFile file)
|
|
{
|
|
var scaledescription = new List<BusScaleDescription>();
|
|
var list = InputExcelUtil<ImportScaleDescriptionDTO>.InputExcel(file);
|
|
for (int i = 0; i < list.Count(); i++)
|
|
{
|
|
var input = list[i];
|
|
scaledescription.Add(new BusScaleDescription()
|
|
{
|
|
Application = input.Application,
|
|
CreateTime = DateTime.Now,
|
|
CreateUserId = _userManager.UserId,
|
|
CreateUserName = _userManager.Account,
|
|
Introduce = input.Introduce,
|
|
Notice = input.Notice,
|
|
UsesTime = input.UserTime,
|
|
ScaleId = input.ScaleId,
|
|
Sort = input.Sort,
|
|
IsDelete = false
|
|
});
|
|
}
|
|
await _busScaleDescriptionRep.InsertRangeAsync(scaledescription);
|
|
}
|
|
}
|
|
}
|