using Amazon.Runtime.Internal.Transform;
using Hotline.Application.Snapshot;
using Hotline.Caching.Interfaces;
using Hotline.Configurations;
using Hotline.Repository.SqlSugar.Extensions;
using Hotline.Settings;
using Hotline.Share.Dtos;
using Hotline.Share.Dtos.Snapshot;
using Hotline.Share.Tools;
using Hotline.Snapshot;
using Hotline.Snapshot.Interfaces;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
namespace Hotline.Api.Controllers.Snapshot;
///
/// 随手拍行业管理接口
///
public class IndustryController : BaseController
{
private readonly IIndustryRepository _industryRepository;
private readonly ISystemDicDataCacheManager _systemDicDataCacheManager;
private readonly IIndustryApplication _industryApplication;
private readonly ISystemAreaDomainService _systemAreaDomainService;
private readonly IOptionsSnapshot _appOptions;
public IndustryController(IIndustryRepository industryRepository, IIndustryApplication industryApplication, ISystemDicDataCacheManager systemDicDataCacheManager, ISystemAreaDomainService systemAreaDomainService, IOptionsSnapshot appOptions)
{
_industryRepository = industryRepository;
_industryApplication = industryApplication;
_systemDicDataCacheManager = systemDicDataCacheManager;
_systemAreaDomainService = systemAreaDomainService;
_appOptions = appOptions;
}
///
/// 添加行业页面基础数据
///
///
[HttpGet("basedata")]
public Dictionary GetBaseData()
{
return new Dictionary
{
{ "department", _systemDicDataCacheManager.SnapshotDepartment },
{ "acceptType", _systemDicDataCacheManager.AcceptType},
{ "bulletinType", _systemDicDataCacheManager.SnapshotBulletinType}
};
}
///
/// 新增行业
///
///
[HttpPost]
public async Task AddIndustry([FromBody] AddIndustryDto dto)
=> await _industryApplication.AddIndustryAsync(dto, HttpContext.RequestAborted);
///
/// 行业详情
///
///
///
[HttpGet("{id}")]
public async Task GetIndustryDetailAsync(string id)
=> await _industryApplication.GetIndustryDetailAsync(id);
///
/// 获取行业集合
///
///
[HttpGet("industry")]
public async Task> GetIndustryAsync([FromQuery] IndustryListInDto dto)
=> (await _industryApplication.GetIndustres(dto).ToPagedListAsync(dto, HttpContext.RequestAborted)).ToPaged();
///
/// 修改行业
///
///
///
[HttpPut]
public async Task UpdateIndustry([FromBody] UpdateIndustryInDto dto)
=> await _industryApplication.UpdateIndustryAsync(dto, HttpContext.RequestAborted);
#region 行业线索
///
/// 行业线索集合
///
///
///
[HttpGet("case")]
public async Task> GetIndustryCaseItemAsync([FromQuery] IndustryCaseItemInDto dto)
=> (await _industryApplication.GetIndustryCaseItems(dto).ToPagedListAsync(dto, HttpContext.RequestAborted)).ToPaged();
///
/// 添加行业线索
///
///
///
[HttpPost("case")]
public async Task AddIndustryCaseAsync([FromBody] AddIndustryCaseDto dto)
=> await _industryApplication.AddIndustryCaseAsync(dto);
///
/// 更新行业线索
///
///
///
[HttpPut("case")]
public async Task UpdateIndustryCaseAsync([FromBody]UpdateIndustryCaseDto dto)
=> await _industryApplication.UpdateIndustryCaseAsync(dto);
///
/// 获取行业线索详情
///
///
///
[HttpGet("case/{id}")]
public async Task GetIndustryCaseDetailAsync(string id)
=> await _industryApplication.GetIndustryCaseAsync(id);
///
/// 页面基础数据
///
///
[HttpGet("case/database")]
public async Task> GetIndustryCaseDataBaseAsync()
{
var items = await _industryRepository.Queryable()
.Select(m => new { m.Id, m.Name })
.ToListAsync();
return new Dictionary
{
{ "industry", items }
};
}
#endregion
#region 行业短信模板
///
/// 行业短信模板集合
///
///
///
[HttpGet("sms_template")]
public async Task> GetSmsTemplateItemsAsync([FromQuery]SnapshotSMSTemplateItemsInDto dto)
=> (await _industryApplication.GetSMSTemplates(dto).ToPagedListAsync(dto, HttpContext.RequestAborted)).ToPaged();
///
/// 添加行业短信模板
///
///
///
[HttpPost("sms_template")]
public async Task AddSmsTemplateAsync([FromBody] AddSnapshotSMSTemplateInDto dto)
=> await _industryApplication.AddSMSTemplateAsync(dto);
///
/// 修改行业短信模板
///
///
///
[HttpPut("sms_template")]
public async Task UpdateSmsTemplateAsync([FromBody] UpdateSnapshotSMSTemplateInDto dto)
=> await _industryApplication.UpdateSMSTemplateAsync(dto);
///
/// 短信详情
///
///
///
[HttpGet("sms_template/{id}")]
public async Task GetSMSTemplateDetailAsync(string id)
=> await _industryApplication.GetSMSTemplateDetailAsync(id);
#endregion
#region 区域从业人员
///
/// 区域从业人员集合
///
///
[HttpGet("practitioner")]
public async Task> GetPractitionerItemsAsync([FromQuery] PractitionerItemsInDto dto)
=> (await _industryApplication.GetPractitionerItemsAsync(dto).ToPagedListAsync(dto, HttpContext.RequestAborted)).ToPaged();
///
/// 添加区域从业人员
///
///
///
[HttpPost("practitioner")]
public async Task AddPractitionerAsync([FromBody]AddBatchPractitionerInDto dto)
=> await _industryApplication.AddPractitionerAsync(dto);
///
/// 删除区域从业人员
///
///
///
[HttpDelete("practitioner")]
public async Task DeletePractitionerAsync([FromBody]IList ids)
=> await _industryApplication.DeletePractitionerAsync(ids);
///
/// 从业人员详情
///
///
///
[HttpGet("practitioner/{id}")]
public async Task GetPractitionerAsync(string id)
=> await _industryApplication.GetPractitionerAsync(id);
///
/// 添加从业人员基础数据
///
///
[HttpGet("practitioner/basedata")]
public async Task> GetPractitionerDataBaseAsync()
{
var parentId = "";
if (_appOptions.Value.IsZiGong) parentId = _appOptions.Value.ZiGong.AreaCode;
return new Dictionary
{
{ "area", await _systemAreaDomainService.GetAreaTree(parentId: parentId)}
};
}
#endregion
}