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; namespace @Model.NameSpace { /// /// @(@Model.BusName)服务 /// [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; } /// /// 分页查询@(@Model.BusName) /// /// /// [HttpGet("/@Model.ClassName/page")] public async Task 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(); } /// /// 增加@(@Model.BusName) /// /// /// [HttpPost("/@Model.ClassName/add")] public async Task Add(Add@(@Model.ClassName)Input input) { var entity = input.Adapt<@(@Model.ClassName)>(); await _rep.InsertAsync(entity); } /// /// 删除@(@Model.BusName) /// /// /// [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); } /// /// 更新@(@Model.BusName) /// /// /// [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(); } /// /// 获取@(@Model.BusName) /// /// /// [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)); } } } /// /// 获取@(@Model.BusName)列表 /// /// /// [HttpGet("/@Model.ClassName/list")] public async Task List([FromQuery] @(@Model.ClassName)Input input) { return await _rep.ToListAsync(); } } }