161 lines
5.8 KiB
C#
161 lines
5.8 KiB
C#
using Admin.NET.Core;
|
|
using Furion.DatabaseAccessor;
|
|
using Furion.DependencyInjection;
|
|
using Furion.DynamicApiController;
|
|
using Furion.FriendlyException;
|
|
using Mapster;
|
|
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 = "BusScaleQuestions", Order = 100)]
|
|
public class BusScaleQuestionsService : IDynamicApiController, ITransient
|
|
{
|
|
private readonly SqlSugarRepository<BusScaleQuestions> _busScaleQuestionsRep;
|
|
private readonly SqlSugarRepository<BusScale> _busScaleRep;
|
|
private readonly UserManager _userManager;
|
|
public BusScaleQuestionsService(
|
|
SqlSugarRepository<BusScale> busScaleRep,
|
|
SqlSugarRepository<BusScaleQuestions> busScaleQuestionsRep,
|
|
UserManager userManager
|
|
)
|
|
{
|
|
_busScaleRep = busScaleRep;
|
|
_busScaleQuestionsRep = busScaleQuestionsRep;
|
|
_userManager = userManager;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分页查询量表试题
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("page")]
|
|
public async Task<SqlSugarPagedList<BusScaleQuestionsOutput>> Page([FromQuery] BusScaleQuestionsInput input)
|
|
{
|
|
var busScaleQuestionss = await _busScaleQuestionsRep.AsQueryable()
|
|
.WhereIF(input.ScaleId > 0, u => u.ScaleId == input.ScaleId)
|
|
.WhereIF(!string.IsNullOrEmpty(input.Context), u => u.Context == input.Context)
|
|
//.Where(u => u.Sort == input.Sort)
|
|
.OrderBy(u => u.CreateTime, OrderByType.Desc)
|
|
.OrderBuilder(input)
|
|
.Select(s => new BusScaleQuestionsOutput()
|
|
{
|
|
Context = s.Context,
|
|
Sort = s.Sort,
|
|
Id = s.Id
|
|
})
|
|
.ToPagedListAsync(input.Page, input.PageSize);
|
|
|
|
return busScaleQuestionss;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 增加量表试题
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("add")]
|
|
public async Task Add(AddBusScaleQuestionsInput input)
|
|
{
|
|
var busScaleQuestions = input.Adapt<BusScaleQuestions>();
|
|
await _busScaleQuestionsRep.InsertAsync(busScaleQuestions);
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 批量导入量表数据
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("Buadd")]
|
|
public async Task BuAdd(BusAddScaleQuestionsInput input)
|
|
{
|
|
var busScaleQuestions = new List<BusScaleQuestions>();
|
|
input.Contexts.ForEach(c =>
|
|
{
|
|
busScaleQuestions.Add(new BusScaleQuestions()
|
|
{
|
|
Context = c.Contexts,
|
|
CreateTime = DateTime.Now,
|
|
CreateUserId = _userManager.UserId,
|
|
CreateUserName = _userManager.Account,
|
|
ScaleId = input.ScaleId,
|
|
Sort = c.Sort
|
|
});
|
|
});
|
|
await _busScaleQuestionsRep.InsertRangeAsync(busScaleQuestions);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除量表试题
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("delete")]
|
|
public async Task Delete(DeleteBusScaleQuestionsInput input)
|
|
{
|
|
var busScaleQuestions = await _busScaleQuestionsRep.AsQueryable().FirstAsync(u => u.Id == input.Id);
|
|
await _busScaleQuestionsRep.FakeDeleteAsync(busScaleQuestions);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新量表试题
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("edit")]
|
|
public async Task Update(UpdateBusScaleQuestionsInput input)
|
|
{
|
|
var isExist = await _busScaleQuestionsRep.AsQueryable().AnyAsync(u => u.Id == input.Id);
|
|
if (!isExist) throw Oops.Oh(ErrorCodeEnum.D3000);
|
|
|
|
var busScaleQuestions = input.Adapt<BusScaleQuestions>();
|
|
await _busScaleQuestionsRep.UpdateAsync(busScaleQuestions);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取量表试题
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("detail")]
|
|
public async Task<BusScaleQuestionsOutput> Get([FromQuery] QueryeBusScaleQuestionsInput input)
|
|
{
|
|
return (await _busScaleQuestionsRep.AsQueryable().FirstAsync(u => u.Id == input.Id)).Adapt<BusScaleQuestionsOutput>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取量表试题列表
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("list")]
|
|
public async Task<List<BusScaleQuestionsOutput>> List([FromQuery] BusScaleQuestionsInput input)
|
|
{
|
|
return await _busScaleQuestionsRep.AsQueryable().Select<BusScaleQuestionsOutput>().ToListAsync();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取BusScale列表
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("fkBusScale")]
|
|
public async Task<dynamic> FkBusScaleList()
|
|
{
|
|
var list = await _busScaleRep.AsQueryable().ToListAsync();
|
|
return list.Select(e => new { Code = e.Id, Name = e.Name });
|
|
}
|
|
|
|
}
|
|
}
|