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.

156 lines
5.6 KiB

using System.ComponentModel;
using Autofac;
using Common.Enum;
using Entity.Base;
using Entity.DbModel.System.SysBaseObject;
using Entity.Dto.Req;
using HybirdFrameworkCore.Autofac;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Redis;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Repository.System;
using SqlSugar;
namespace Service.System
{
[Scope("SingleInstance")]
public class SysConfigService : BaseServices<SysConfig>
{
private readonly SysConfigRepository _sysConfigRep;
public SysConfigService(SysConfigRepository sysConfigRep)
{
_sysConfigRep = sysConfigRep;
}
RedisHelper redisHelper = AppInfo.Container.Resolve<RedisHelper>();
/// <summary>
/// 获取参数配置分页列表 🔖
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task<SqlSugarPagedList<SysConfig>> Page(PageConfigReq input)
{
RefAsync<int> total = 0;
var items = await _sysConfigRep.QueryPageAsync(
!string.IsNullOrEmpty(input.Name), u => u.Name.Contains(input.Name),
!string.IsNullOrEmpty(input.Code), u => u.Code.Contains(input.Code),
!string.IsNullOrEmpty(input.GroupCode), u => u.GroupCode.Equals(input.GroupCode),
input.Page, input.PageSize, total, input);
return SqlSugarPagedExtensions.CreateSqlSugarPagedList(items, total, input.Page, input.PageSize);
}
/// <summary>
/// 获取参数配置列表 🔖
/// </summary>
/// <returns></returns>
[DisplayName("获取参数配置列表")]
public async Task<List<SysConfig>> GetList()
{
return await _sysConfigRep.QueryAsync();
}
/// <summary>
/// 获取分组列表 🔖
/// </summary>
/// <returns></returns>
public async Task<List<string>> GetGroupList()
{
return await _sysConfigRep.QueryByGroupByAsync<string>(u => u.GroupCode, u => u.GroupCode);
}
/// <summary>
/// 增加参数配置 🔖
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
//[ApiDescriptionSettings(Name = "Add"), HttpPost]
public async Task<string> AddConfig(AddConfigReq input)
{
string result = "";
var isExist = await _sysConfigRep.QueryByClauseAsync(u => u.Name == input.Name || u.Code == input.Code);
if (isExist != null)
result = "已存在同名或同编码参数配置";
int insertSesult = await _sysConfigRep.InsertAsync(input.Adapt<SysConfig>());
if (insertSesult > 0)
result = "增加参数配置成功";
return result;
}
/// <summary>
/// 更新参数配置 🔖
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
// [ApiDescriptionSettings(Name = "Update"), HttpPost]
[DisplayName("更新参数配置")]
public async Task<string> UpdateConfig(UpdateConfigReq input)
{
string result = "";
var isExist = await _sysConfigRep.QueryByClauseAsync(u => (u.Name == input.Name || u.Code == input.Code) && u.Id != input.Id);
if (isExist != null)
result = "已存在同名或同编码参数配置";
var config = input.Adapt<SysConfig>();
int updateResult = await _sysConfigRep.UpdateAsync(config,true);
if (updateResult > 0)
result = "更新参数配置成功";
redisHelper.Remove(config.Code);
return result;
}
/// <summary>
/// 删除参数配置 🔖
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
//[ApiDescriptionSettings(Name = "Delete"), HttpPost]
[DisplayName("删除参数配置")]
public async Task<string> DeleteConfig(DeleteConfigReq input)
{
string result = "";
var config = await _sysConfigRep.QueryByClauseAsync(u => u.Id == input.Id);
if (config.SysFlag == YesNoEnum.Y) // 禁止删除系统参数
result = "禁止删除系统参数";
bool deleteResult = await _sysConfigRep.DeleteAsync(config);
if (deleteResult)
result = "删除参数配置成功";
redisHelper.Remove(config.Code);
return result;
}
/// <summary>
/// 批量删除参数配置 🔖
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
// [ApiDescriptionSettings(Name = "BatchDelete"), HttpPost]
[DisplayName("批量删除参数配置")]
public async Task BatchDeleteConfig(List<long> ids)
{
foreach (var id in ids)
{
var config = await _sysConfigRep.QueryByClauseAsync(u => u.Id == id);
if (config.SysFlag == YesNoEnum.Y) // 禁止删除系统参数
continue;
await _sysConfigRep.DeleteAsync(config);
redisHelper.Remove(config.Code);
}
}
/// <summary>
/// 获取参数配置详情 🔖
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[DisplayName("获取参数配置详情")]
public async Task<SysConfig> GetDetail([FromQuery] ConfigReq input)
{
return await _sysConfigRep.QueryByClauseAsync(u => u.Id == input.Id);
}
}
}