SysConfigController.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. using Microsoft.AspNetCore.Mvc;
  2. using SqlSugar;
  3. using ZR.Model.System;
  4. using ZR.Model.System.Dto;
  5. namespace ZR.Admin.WebApi.Controllers
  6. {
  7. /// <summary>
  8. /// 参数配置Controller
  9. /// </summary>
  10. [Route("system/config")]
  11. [ApiExplorerSettings(GroupName = "sys")]
  12. public class SysConfigController : BaseController
  13. {
  14. /// <summary>
  15. /// 参数配置接口
  16. /// </summary>
  17. private readonly ISysConfigService _SysConfigService;
  18. public SysConfigController(ISysConfigService SysConfigService)
  19. {
  20. _SysConfigService = SysConfigService;
  21. }
  22. /// <summary>
  23. /// 查询参数配置列表
  24. /// </summary>
  25. /// <returns></returns>
  26. [HttpGet("list")]
  27. [ActionPermissionFilter(Permission = "system:config:list")]
  28. public IActionResult QuerySysConfig([FromQuery] SysConfigQueryDto parm)
  29. {
  30. var predicate = Expressionable.Create<SysConfig>();
  31. predicate = predicate.AndIF(!parm.ConfigType.IsEmpty(), m => m.ConfigType == parm.ConfigType);
  32. predicate = predicate.AndIF(!parm.ConfigName.IsEmpty(), m => m.ConfigName.Contains(parm.ConfigType));
  33. predicate = predicate.AndIF(!parm.ConfigKey.IsEmpty(), m => m.ConfigKey.Contains(parm.ConfigKey));
  34. predicate = predicate.AndIF(!parm.BeginTime.IsEmpty(), m => m.Create_time >= parm.BeginTime);
  35. predicate = predicate.AndIF(!parm.BeginTime.IsEmpty(), m => m.Create_time <= parm.EndTime);
  36. var response = _SysConfigService.GetPages(predicate.ToExpression(), parm);
  37. return SUCCESS(response);
  38. }
  39. /// <summary>
  40. /// 查询参数配置详情
  41. /// </summary>
  42. /// <param name="ConfigId"></param>
  43. /// <returns></returns>
  44. [HttpGet("{ConfigId}")]
  45. [ActionPermissionFilter(Permission = "system:config:query")]
  46. public IActionResult GetSysConfig(int ConfigId)
  47. {
  48. var response = _SysConfigService.GetId(ConfigId);
  49. return SUCCESS(response);
  50. }
  51. /// <summary>
  52. /// 根据参数键名查询参数值
  53. /// </summary>
  54. /// <param name="configKey"></param>
  55. /// <returns></returns>
  56. [HttpGet("configKey/{configKey}")]
  57. [AllowAnonymous]
  58. public IActionResult GetConfigKey(string configKey)
  59. {
  60. var response = _SysConfigService.Queryable().First(f => f.ConfigKey == configKey);
  61. return SUCCESS(response?.ConfigValue);
  62. }
  63. /// <summary>
  64. /// 添加参数配置
  65. /// </summary>
  66. /// <returns></returns>
  67. [HttpPost]
  68. [ActionPermissionFilter(Permission = "system:config:add")]
  69. [Log(Title = "参数配置添加", BusinessType = BusinessType.INSERT)]
  70. public IActionResult AddSysConfig([FromBody] SysConfigDto parm)
  71. {
  72. if (parm == null)
  73. {
  74. throw new CustomException("请求参数错误");
  75. }
  76. var model = parm.Adapt<SysConfig>().ToCreate(HttpContext);
  77. return SUCCESS(_SysConfigService.Insert(model, it => new
  78. {
  79. it.ConfigName,
  80. it.ConfigKey,
  81. it.ConfigValue,
  82. it.ConfigType,
  83. it.Create_by,
  84. it.Create_time,
  85. it.Remark,
  86. }));
  87. }
  88. /// <summary>
  89. /// 更新参数配置
  90. /// </summary>
  91. /// <returns></returns>
  92. [HttpPut]
  93. [ActionPermissionFilter(Permission = "system:config:update")]
  94. [Log(Title = "参数配置修改", BusinessType = BusinessType.UPDATE)]
  95. public IActionResult UpdateSysConfig([FromBody] SysConfigDto parm)
  96. {
  97. if (parm == null)
  98. {
  99. throw new CustomException("请求实体不能为空");
  100. }
  101. var model = parm.Adapt<SysConfig>().ToUpdate(HttpContext);
  102. var response = _SysConfigService.Update(w => w.ConfigId == model.ConfigId, it => new SysConfig()
  103. {
  104. ConfigName = model.ConfigName,
  105. ConfigKey = model.ConfigKey,
  106. ConfigValue = model.ConfigValue,
  107. ConfigType = model.ConfigType,
  108. Update_by = model.Update_by,
  109. Update_time = model.Update_time,
  110. Remark = model.Remark
  111. });
  112. return SUCCESS(response);
  113. }
  114. /// <summary>
  115. /// 删除参数配置
  116. /// </summary>
  117. /// <returns></returns>
  118. [HttpDelete("{ids}")]
  119. [ActionPermissionFilter(Permission = "system:config:remove")]
  120. [Log(Title = "参数配置删除", BusinessType = BusinessType.DELETE)]
  121. public IActionResult DeleteSysConfig(string ids)
  122. {
  123. int[] idsArr = Tools.SpitIntArrary(ids);
  124. if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
  125. int sysCount = _SysConfigService.Count(s => s.ConfigType == "Y" && idsArr.Contains(s.ConfigId));
  126. if (sysCount > 0) { return ToResponse(ApiResult.Error($"删除失败Id: 系统内置参数不能删除!")); }
  127. var response = _SysConfigService.Delete(idsArr);
  128. return SUCCESS(response);
  129. }
  130. }
  131. }