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.Core.Entity; namespace Myshipping.Core.Service { /// /// 公司默认值 /// [ApiDescriptionSettings(Name = "DjyTenantConfig", Order = 1)] public class DjyTenantConfigService : IDjyTenantConfigService, IDynamicApiController, ITransient { private readonly SqlSugarRepository _rep; public DjyTenantConfigService(SqlSugarRepository rep) { _rep = rep; } /// /// 分页查询用户自定义配置 /// /// /// [HttpGet("/DjyTenantConfig/page")] public async Task Page([FromQuery] QueryDjyTenantConfigInput input) { var entities = await _rep.AsQueryable().Filter(null, true) .WhereIF(!string.IsNullOrWhiteSpace(input.Type), u => u.Type == input.Type) .WhereIF(!string.IsNullOrWhiteSpace(input.ConfigJson), u => u.ConfigJson == input.ConfigJson) .ToPagedListAsync(input.PageNo, input.PageSize); return entities.XnPagedResult(); } /// /// 增加用户自定义配置(同用户、同类型的会更新) /// /// /// [HttpPost("/DjyTenantConfig/add")] public async Task Add(AddDjyTenantConfigInput input) { var entity = _rep.AsQueryable().Filter(null, true).Where(x => x.Type == input.Type && x.CreatedUserId == UserManager.UserId).FirstAsync().Result; if (entity == null) { entity = input.Adapt(); await _rep.InsertAsync(entity); } else { entity.ConfigJson = input.ConfigJson; await _rep.UpdateAsync(entity); } } /// /// 更新用户自定义配置 /// /// /// [HttpPost("/DjyTenantConfig/edit")] public async Task Update(UpdateDjyTenantConfigInput input) { var entity = input.Adapt(); await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); } /// /// 删除用户自定义配置 /// /// /// [HttpPost("/DjyTenantConfig/delete")] public async Task Delete(GetDjyTenantConfigInput input) { var entity = await _rep.AsQueryable().Filter(null, true).Where(u => u.Id == input.Id).FirstAsync(); await _rep.DeleteAsync(entity); } /// /// 获取用户自定义配置 /// /// /// [HttpGet("/DjyTenantConfig/get")] public async Task Get([FromQuery] string type) { return await _rep.AsQueryable().Filter(null, true).Where(u => u.CreatedUserId == UserManager.UserId && u.Type == type).FirstAsync(); } } }