using Hotline.Caching.Interfaces; using Hotline.Caching.Services; using Hotline.CallCenter.Manage; using Hotline.Orders; using Hotline.Permissions; using Hotline.Repository.SqlSugar.Extensions; using Hotline.Repository.SqlSugar.Ts; using Hotline.Settings; using Hotline.Settings.TimeLimits; using Hotline.Share.Dtos; using Hotline.Share.Dtos.Order; using Hotline.Share.Dtos.Settings; using Hotline.Share.Enums.Settings; using Hotline.Share.Requests; using MapsterMapper; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using XF.Domain.Exceptions; using XF.Domain.Repository; using XF.Utility.EnumExtensions; namespace Hotline.Api.Controllers { /// /// 系统参数相关接口 /// public class SettingController : BaseController { private readonly IVoiceFileDomainService _voiceFileDomainService; private readonly IRepository _systemSettingsRepository; private readonly ISystemSettingCacheManager _systemSettingCacheManager; private readonly IDaySettingRepository _daysettingRepository; private readonly IMapper _mapper; private readonly IBusinessTagRepository _businessTag; private readonly IRepositoryTextSearch _repositoryts; public SettingController( IVoiceFileDomainService voiceFileDomainService, IRepository systemSettingsRepository, ISystemSettingCacheManager systemSettingCacheManager, IDaySettingRepository daySettingRepository, IMapper mapper, IBusinessTagRepository businessTag, IRepositoryTextSearch repositoryts ) { _voiceFileDomainService = voiceFileDomainService; _systemSettingsRepository = systemSettingsRepository; _systemSettingCacheManager = systemSettingCacheManager; _daysettingRepository = daySettingRepository; _mapper = mapper; _businessTag = businessTag; _repositoryts = repositoryts; } /// /// 查询语音文件 /// /// [HttpGet("voicequerylist")] public async Task> VoiceQueryList() { return await _voiceFileDomainService.VoiceQueryListAsync(HttpContext.RequestAborted); } /// /// 删除语音文件 /// /// /// [HttpPost("removevoicefile")] public async Task RemoveVoiceFile(string voiceFileName) { await _voiceFileDomainService.RemoveVoiceFileAsync(new RemoveVoiceFileRequest(voiceFileName), HttpContext.RequestAborted); } #region 系统参数 /// /// 获取系统参数列表 /// /// [HttpGet("getsyssettings")] public async Task> GetSysSettings([FromQuery]SettingsQueryDto dto) { //return await _systemSettingsRepository.QueryAsync(x => true); var (total,items) = await _systemSettingsRepository.Queryable() .Includes(d=>d.Creator) .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.CreationTime) .OrderBy(d => d.Sort) .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted); return new PagedDto(total, items); } /// /// 获取系统参数 /// /// /// [HttpGet("getsetting-entity/{id}")] public async Task GetSettingEntity(string id) { return await _systemSettingsRepository.GetAsync(id, HttpContext.RequestAborted); } /// /// 通过code获取系统参数 /// /// /// [AllowAnonymous] [HttpGet("getsetting-code/{code}")] public async Task GetSettingByCode(string code) { return _systemSettingCacheManager.GetSetting(code); } /// /// 新增系统参数 /// /// /// [HttpPost("setting-add")] public async Task AddSetting([FromBody]AddSettingDto dto) { var setting = _mapper.Map(dto); await _systemSettingsRepository.AddAsync(setting, HttpContext.RequestAborted); } /// /// 修改配置 /// /// /// [HttpPost("modifysettings")] public async Task ModifySettingsAsync([FromBody]ModifySettingDto dto) { var model = await _systemSettingsRepository.GetAsync(dto.Id, HttpContext.RequestAborted); if (model is null) throw UserFriendlyException.SameMessage("未知配置,请刷新界面"); model.SettingValue = dto.SettingValue; model.Sort = dto.Sort; model.Remark = dto.Remark; _systemSettingCacheManager.DelSystemSetting(model.Code); await _systemSettingsRepository.UpdateAsync(model, HttpContext.RequestAborted); } #endregion #region 日期类型设置 /// /// 获取月份的日期设置 /// /// /// /// [HttpGet("getdaysettings-month/{year}/{month}")] public async Task> GetDaySettingsByMonth(int year,int month) { return await _daysettingRepository.GetDaySettingsByMonth(year,month); } /// /// 设置日期 /// /// /// ` [HttpPost("setdaysettings")] public async Task SetDaySettings([FromBody]SetDaySettingsRequest request) { foreach (var item in request.list) { var day = await _daysettingRepository.GetAsync(x => x.Day.Date == item.Date, HttpContext.RequestAborted); if (day != null) { day.IsWorkDay = request.isWorkDay; await _daysettingRepository.UpdateAsync(day, HttpContext.RequestAborted); } else { await _daysettingRepository.AddAsync(new DaySetting() { Day = item, IsWorkDay = request.isWorkDay },HttpContext.RequestAborted); } } } #endregion #region 标签 /// /// 业务标签列表 /// /// /// [HttpGet("businessTag")] public async Task> BusinessTagList([FromQuery] BusinessTagListDto dto) { var (total, items) = await _businessTag.Queryable() .WhereIF(!string.IsNullOrEmpty(dto.Keyword), d => d.Name.Contains(dto.Keyword!)) .WhereIF(dto.Type> 0, d => d.Type == dto.Type) .WhereIF(dto.BusinessType > 0, d => d.BusinessType == dto.BusinessType) .OrderByDescending(x => x.CreationTime) .ToPagedListAsync(dto.PageIndex, dto.PageSize, HttpContext.RequestAborted); return new PagedDto(total, _mapper.Map>(items)); } /// /// 新增标签(支持批量) /// /// /// [HttpPost("businessTag")] public async Task AddBusinessTag([FromBody] List dtos) { List tags = new List(); foreach (var dto in dtos) { var model = _mapper.Map(dto); tags.Add(model); } await _businessTag.AddRangeAsync(tags, HttpContext.RequestAborted); } /// /// 删除标签 /// /// /// [HttpDelete("businessTag")] public async Task DeleteBusinessTag([FromBody] DeleteBusinessTagDto dto) { foreach (var Id in dto.Ids) { await _businessTag.RemoveAsync(x => x.Id == Id); } } /// /// 更新标签 /// /// /// [HttpPut("businessTag")] public async Task UpdateBusinessTag([FromBody] UpdateBusinessTagDto dto) { //验证工单是否可以申请 var tag = await _businessTag.GetAsync(dto.Id, HttpContext.RequestAborted); if (tag is null) throw UserFriendlyException.SameMessage("无效标签"); _mapper.Map(dto, tag); await _businessTag.UpdateAsync(tag, HttpContext.RequestAborted); } /// /// 获取标签实体 /// /// /// [HttpGet("businessTag/{id}")] public async Task BusinessTagEntity(string id) { return await _businessTag.Queryable() .FirstAsync(x => x.Id == id); } /// /// 获取标签基本数据 /// /// [HttpGet("businessTag/baseData")] public async Task TagBaseData() { var rsp = new { TagType = EnumExts.GetDescriptions(), BusinessTagType = EnumExts.GetDescriptions(), }; return rsp; } /// /// 绑定标签 /// /// /// [HttpPut("businessTag/binding")] public async Task BusinessTagBinding([FromBody]BusinessTagBindingDto dto) { await _businessTag.BindingAsync(dto, HttpContext.RequestAborted); } #endregion } }