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.
BookingHeChuan/Myshipping.Core/Service/DjyTenantConfig/DjyTenantConfigService.cs

125 lines
4.4 KiB
C#

2 years ago
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
{
/// <summary>
/// 公司默认值
2 years ago
/// </summary>
[ApiDescriptionSettings(Name = "DjyTenantConfig", Order = 1)]
public class DjyTenantConfigService : IDjyTenantConfigService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<DjyTenantConfig> _rep;
public DjyTenantConfigService(SqlSugarRepository<DjyTenantConfig> rep)
{
_rep = rep;
}
/// <summary>
/// 分页查询用户自定义配置
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/DjyTenantConfig/page")]
public async Task<dynamic> 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();
}
/// <summary>
/// 增加用户自定义配置(同用户、同类型的会更新)
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[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<DjyTenantConfig>();
await _rep.InsertAsync(entity);
}
else
{
entity.ConfigJson = input.ConfigJson;
await _rep.UpdateAsync(entity);
}
}
/// <summary>
/// 更新用户自定义配置
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/DjyTenantConfig/edit")]
public async Task Update(UpdateDjyTenantConfigInput input)
{
var entity = input.Adapt<DjyTenantConfig>();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
2 years ago
/// <summary>
/// 新增编辑接口
/// </summary>
/// <returns></returns>
[HttpPost("/DjyTenantConfig/Save")]
public async Task Save(UpdateDjyTenantConfigInput input) {
if (input.Id==0) {
2 years ago
2 years ago
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<DjyTenantConfig>();
await _rep.InsertAsync(entity);
}
else
{
entity.ConfigJson = input.ConfigJson;
await _rep.UpdateAsync(entity);
}
2 years ago
2 years ago
} else {
var entity = input.Adapt<DjyTenantConfig>();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
}
2 years ago
/// <summary>
/// 删除用户自定义配置
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[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);
}
/// <summary>
/// 获取用户自定义配置
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
[HttpGet("/DjyTenantConfig/get")]
public async Task<DjyTenantConfig> Get([FromQuery] string type)
{
return await _rep.AsQueryable().Filter(null, true).Where(u => u.CreatedUserId == UserManager.UserId && u.Type == type).FirstAsync();
}
}
}