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.
116 lines
3.9 KiB
116 lines
3.9 KiB
2 years ago
|
using Magic.Core;
|
||
|
using Furion.DependencyInjection;
|
||
|
using Furion.DynamicApiController;
|
||
|
using Mapster;
|
||
|
using Microsoft.AspNetCore.Mvc;
|
||
|
using SqlSugar;
|
||
|
using System.Linq;
|
||
|
using System.Threading.Tasks;
|
||
|
using Magic.Application.Entity;
|
||
|
namespace @Model.NameSpace
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// @(@Model.BusName)服务
|
||
|
/// </summary>
|
||
|
[ApiDescriptionSettings("Application",Name = "@Model.ClassName", Order = 1)]
|
||
|
public class @(@Model.ClassName)Service : I@(@Model.ClassName)Service, IDynamicApiController, ITransient
|
||
|
{
|
||
|
private readonly SqlSugarRepository<@(@Model.ClassName)> _rep;
|
||
|
|
||
|
public @(@Model.ClassName)Service(SqlSugarRepository<@(@Model.ClassName)> rep)
|
||
|
{
|
||
|
_rep = rep;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 分页查询@(@Model.BusName)
|
||
|
/// </summary>
|
||
|
/// <param name="input"></param>
|
||
|
/// <returns></returns>
|
||
|
[HttpGet("/@Model.ClassName/page")]
|
||
|
public async Task<dynamic> Page([FromQuery] @(@Model.ClassName)Input input)
|
||
|
{
|
||
|
var entities = await _rep.AsQueryable()
|
||
|
@foreach (var column in Model.TableField){
|
||
|
if (@column.QueryWhether == "Y"){
|
||
|
if (@column.NetType == "string"){
|
||
|
if(@column.QueryType == "like"){
|
||
|
@:.WhereIF(!string.IsNullOrWhiteSpace(input.@column.ColumnName), u => u.@(@column.ColumnName).Contains(input.@(@column.ColumnName).Trim()))
|
||
|
}else{
|
||
|
@:.WhereIF(!string.IsNullOrWhiteSpace(input.@column.ColumnName), u => u.@(@column.ColumnName) @column.QueryType input.@(@column.ColumnName))
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
.ToPagedListAsync(input.PageNo, input.PageSize);
|
||
|
return entities.XnPagedResult();
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 增加@(@Model.BusName)
|
||
|
/// </summary>
|
||
|
/// <param name="input"></param>
|
||
|
/// <returns></returns>
|
||
|
[HttpPost("/@Model.ClassName/add")]
|
||
|
public async Task Add(Add@(@Model.ClassName)Input input)
|
||
|
{
|
||
|
var entity = input.Adapt<@(@Model.ClassName)>();
|
||
|
await _rep.InsertAsync(entity);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 删除@(@Model.BusName)
|
||
|
/// </summary>
|
||
|
/// <param name="input"></param>
|
||
|
/// <returns></returns>
|
||
|
[HttpPost("/@Model.ClassName/delete")]
|
||
|
public async Task Delete(Delete@(@Model.ClassName)Input input)
|
||
|
{
|
||
|
@foreach (var column in Model.TableField){
|
||
|
if (@column.ColumnKey == "True"){
|
||
|
@:var entity = await _rep.FirstOrDefaultAsync(u => u.@(@column.ColumnName) == input.@(@column.ColumnName));
|
||
|
}
|
||
|
}
|
||
|
await _rep.DeleteAsync(entity);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 更新@(@Model.BusName)
|
||
|
/// </summary>
|
||
|
/// <param name="input"></param>
|
||
|
/// <returns></returns>
|
||
|
[HttpPost("/@Model.ClassName/edit")]
|
||
|
public async Task Update(Update@(@Model.ClassName)Input input)
|
||
|
{
|
||
|
var entity = input.Adapt<@(@Model.ClassName)>();
|
||
|
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns:true).ExecuteCommandAsync();
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取@(@Model.BusName)
|
||
|
/// </summary>
|
||
|
/// <param name="input"></param>
|
||
|
/// <returns></returns>
|
||
|
[HttpGet("/@Model.ClassName/detail")]
|
||
|
public async Task<@(@Model.ClassName)> Get([FromQuery] Querye@(@Model.ClassName)Input input)
|
||
|
{
|
||
|
@foreach (var column in Model.TableField){
|
||
|
if (@column.ColumnKey == "True"){
|
||
|
@:return await _rep.FirstOrDefaultAsync(u => u.@(@column.ColumnName) == input.@(@column.ColumnName));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取@(@Model.BusName)列表
|
||
|
/// </summary>
|
||
|
/// <param name="input"></param>
|
||
|
/// <returns></returns>
|
||
|
[HttpGet("/@Model.ClassName/list")]
|
||
|
public async Task<dynamic> List([FromQuery] @(@Model.ClassName)Input input)
|
||
|
{
|
||
|
return await _rep.ToListAsync();
|
||
|
}
|
||
|
}
|
||
|
}
|