|
@@ -1,9 +1,14 @@
|
|
|
-using Hotline.Caching.Interfaces;
|
|
|
+using Google.Protobuf.WellKnownTypes;
|
|
|
+using Hotline.Caching.Interfaces;
|
|
|
using Hotline.CallCenter.Manage;
|
|
|
using Hotline.Permissions;
|
|
|
+using Hotline.Repository.SqlSugar.Extensions;
|
|
|
using Hotline.Settings;
|
|
|
using Hotline.Settings.TimeLimits;
|
|
|
+using Hotline.Share.Dtos;
|
|
|
+using Hotline.Share.Dtos.Order;
|
|
|
using Hotline.Share.Requests;
|
|
|
+using MapsterMapper;
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using XF.Domain.Exceptions;
|
|
@@ -20,14 +25,16 @@ namespace Hotline.Api.Controllers
|
|
|
private readonly ISystemSettingGroupRepository _systemSettingGroupRepository;
|
|
|
private readonly ISystemSettingCacheManager _systemSettingCacheManager;
|
|
|
private readonly IDaySettingRepository _daysettingRepository;
|
|
|
+ private readonly IMapper _mapper;
|
|
|
|
|
|
- public SettingController(IVoiceFileDomainService voiceFileDomainService, ISystemSettingRepository systemSettingsRepository, ISystemSettingGroupRepository systemSettingGroupRepository,ISystemSettingCacheManager systemSettingCacheManager,IDaySettingRepository daySettingRepository)
|
|
|
+ public SettingController(IVoiceFileDomainService voiceFileDomainService, ISystemSettingRepository systemSettingsRepository, ISystemSettingGroupRepository systemSettingGroupRepository,ISystemSettingCacheManager systemSettingCacheManager,IDaySettingRepository daySettingRepository, IMapper mapper)
|
|
|
{
|
|
|
_voiceFileDomainService = voiceFileDomainService;
|
|
|
_systemSettingsRepository = systemSettingsRepository;
|
|
|
_systemSettingGroupRepository = systemSettingGroupRepository;
|
|
|
_systemSettingCacheManager = systemSettingCacheManager;
|
|
|
_daysettingRepository = daySettingRepository;
|
|
|
+ _mapper = mapper;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -59,39 +66,62 @@ namespace Hotline.Api.Controllers
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
[Permission(EPermission.GetSysSettingsAsync)]
|
|
|
- [HttpGet("getsyssettings")]
|
|
|
- public async Task<List<SystemSettingGroup>> GetSysSettingsAsync()
|
|
|
+ [HttpPost("getsyssettings")]
|
|
|
+ public async Task<PagedDto<SystemSetting>> GetSysSettingsAsync([FromQuery]SettingsQueryDto dto)
|
|
|
{
|
|
|
- //return await _systemSettingsRepository.QueryAsync(x => true);
|
|
|
+ //return await _systemSettingsRepository.QueryAsync(x => true);
|
|
|
|
|
|
- return await _systemSettingGroupRepository.QueryExtAsync(
|
|
|
- x => true,
|
|
|
- x => x.Includes(d => d.SystemSettings.OrderBy(x=>x.Sort).ToList()),
|
|
|
- x => x.OrderBy(d=>d.Sort));
|
|
|
+ var (total,items) = await _systemSettingsRepository.Queryable()
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.settingName), d => d.SettingName.Contains(dto.settingName))
|
|
|
+ .WhereIF(!string.IsNullOrEmpty(dto.code),d=>d.Code.Contains(dto.code))
|
|
|
+ .OrderBy(d => d.Sort)
|
|
|
+ .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted);
|
|
|
|
|
|
+ return new PagedDto<SystemSetting>(total, _mapper.Map<IReadOnlyList<SystemSetting>>(items));
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 更新配置
|
|
|
+ /// 获取系统参数
|
|
|
/// </summary>
|
|
|
- /// <param name="request"></param>
|
|
|
+ /// <param name="id"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [Permission(EPermission.GetSettingEntityAsync)]
|
|
|
+ [HttpGet("getsetting-entity/{id}")]
|
|
|
+ public async Task<SystemSetting?> GetSettingEntityAsync(string id)
|
|
|
+ {
|
|
|
+ return await _systemSettingsRepository.GetAsync(id, HttpContext.RequestAborted);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 新增系统参数
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [Permission(EPermission.AddSettingAsync)]
|
|
|
+ [HttpPost("setting-add")]
|
|
|
+ public async Task AddSettingAsync([FromBody]AddSettingDto dto)
|
|
|
+ {
|
|
|
+ var setting = _mapper.Map<SystemSetting>(dto);
|
|
|
+
|
|
|
+ await _systemSettingsRepository.AddAsync(setting, HttpContext.RequestAborted);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 修改配置
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
/// <returns></returns>
|
|
|
- /// <exception cref="UserFriendlyException"></exception>
|
|
|
[Permission(EPermission.ModifySettings)]
|
|
|
[HttpPost("modifysettings")]
|
|
|
- public async Task ModifySettings([FromBody] ModifySettingsRequest request)
|
|
|
+ public async Task ModifySettingsAsync([FromBody]ModifySettingDto dto)
|
|
|
{
|
|
|
- for (int i = 0; i < request.list.Count; i++)
|
|
|
- {
|
|
|
- var model = await _systemSettingsRepository.GetAsync(x => x.Id == request.list[i].id,HttpContext.RequestAborted);
|
|
|
- if (model != null)
|
|
|
- {
|
|
|
- model.SettingValue = request.list[i].value;
|
|
|
- await _systemSettingsRepository.UpdateAsync(model, HttpContext.RequestAborted);
|
|
|
- //清除缓存
|
|
|
- _systemSettingCacheManager.DelSystemSetting(model.Code);
|
|
|
- }
|
|
|
- }
|
|
|
+ var model = await _systemSettingsRepository.GetAsync(dto.Id, HttpContext.RequestAborted);
|
|
|
+ if (model is null)
|
|
|
+ throw UserFriendlyException.SameMessage("未知配置,请刷新界面");
|
|
|
+
|
|
|
+ model = _mapper.Map<SystemSetting>(dto);
|
|
|
+ await _systemSettingsRepository.UpdateAsync(model, HttpContext.RequestAborted);
|
|
|
}
|
|
|
|
|
|
#endregion
|