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

118 lines
4.1 KiB
Plaintext

using Myshipping.Core;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System.Linq;
using System.Threading.Tasks;
using Myshipping.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;
private readonly ILogger<@(@Model.ClassName)> _logger;
public @(@Model.ClassName)Service(SqlSugarRepository<@(@Model.ClassName)> rep, ILogger<@(@Model.ClassName)> logger)
{
_rep = rep;
_logger = logger;
}
/// <summary>
/// 分页查询@(@Model.BusName)
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/@Model.ClassName/page")]
public async Task<dynamic> Page([FromQuery] Query@(@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/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>
[HttpPost("/@Model.ClassName/delete")]
public async Task Delete(Get@(@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>
[HttpGet("/@Model.ClassName/detail")]
public async Task<@(@Model.ClassName)> Get([FromQuery] Get@(@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] Query@(@Model.ClassName)Input input)
//{
// return await _rep.ToListAsync();
//}
}
}