You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.6 KiB

using GDZZ.Core;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System.Linq;
using System.Threading.Tasks;
using GDZZ.Application.Entity;
using GDZZ.Core.Entity;
using System.Collections.Generic;
namespace GDZZ.Application
{
/// <summary>
/// 课程表服务
/// </summary>
[ApiDescriptionSettings("Application", Name = "Course", Order = 1)]
public class CourseService : ICourseService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<Course> _rep;
private readonly SqlSugarRepository<SysFile> sysFileRep;
public CourseService(SqlSugarRepository<Course> rep, SqlSugarRepository<SysFile> sysFileRep)
{
_rep = rep;
this.sysFileRep = sysFileRep;
}
/// <summary>
/// 分页查询课程表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/Mini/Course/page")]
public async Task<dynamic> Page([FromQuery] CourseInput input)
{
var entities = await _rep.AsQueryable()
.Includes(x=>x.SysFiles)
.Where(x=>x.SysFiles.Any(z=>z.FileSuffix == "mp4"))
.WhereIF(!UserManager.IsTenantAdmin, n => n.CreatedUserId == UserManager.UserId)
.WhereIF(!string.IsNullOrWhiteSpace(input.Tags), n => n.Tags == input.Tags)
.WhereIF(!string.IsNullOrWhiteSpace(input.Title), n => n.Title == input.Title)
.ToPagedListAsync(input.PageNo, input.PageSize);
return entities.XnPagedResult();
}
/// <summary>
/// 增加课程表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/Mini/Course/add")]
public async Task Add(AddCourseInput input)
{
var entity = input.Adapt<Course>();
await _rep.InsertAsync(entity);
}
/// <summary>
/// 删除课程表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/Course/delete")]
public async Task Delete(DeleteCourseInput input)
{
var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
await _rep.DeleteAsync(entity);
}
/// <summary>
/// 更新课程表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/Course/edit")]
public async Task Update(UpdateCourseInput input)
{
var entity = input.Adapt<Course>();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
/// <summary>
/// 获取课程表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/Course/Detail")]
public async Task<Course> Get([FromQuery] QueryeCourseInput input)
{
return await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
}
/// <summary>
/// 获取课程表列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/Course/list")]
public async Task<dynamic> List([FromQuery] CourseInput input)
{
return await _rep.ToListAsync();
}
}
}