IndustryApplication.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. using DocumentFormat.OpenXml.Office2010.Excel;
  2. using Hotline.Caching.Interfaces;
  3. using Hotline.File;
  4. using Hotline.Repository.SqlSugar.Extensions;
  5. using Hotline.Share.Dtos;
  6. using Hotline.Share.Dtos.Snapshot;
  7. using Hotline.Share.Tools;
  8. using Hotline.Snapshot;
  9. using Hotline.Snapshot.Interfaces;
  10. using Hotline.Tools;
  11. using Mapster;
  12. using SqlSugar;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using System.Text;
  17. using System.Threading;
  18. using System.Threading.Tasks;
  19. using XF.Domain.Dependency;
  20. using XF.Domain.Exceptions;
  21. namespace Hotline.Application.Snapshot;
  22. public class IndustryApplication : IIndustryApplication, IScopeDependency
  23. {
  24. private readonly IIndustryRepository _industryRepository;
  25. private readonly IFileRepository _fileRepository;
  26. private readonly ISystemSettingCacheManager _sysSetting;
  27. private readonly IIndustryCaseRepository _industryCaseRepository;
  28. private readonly ISnapshotSMSTemplateRepository _snapshotSMSTemplateRepository;
  29. public IndustryApplication(IIndustryRepository industryRepository, IFileRepository fileRepository, ISystemSettingCacheManager sysSetting, IIndustryCaseRepository industryCaseRepository, ISnapshotSMSTemplateRepository snapshotSMSTemplateRepository)
  30. {
  31. _industryRepository = industryRepository;
  32. _fileRepository = fileRepository;
  33. _sysSetting = sysSetting;
  34. _industryCaseRepository = industryCaseRepository;
  35. _snapshotSMSTemplateRepository = snapshotSMSTemplateRepository;
  36. }
  37. /// <summary>
  38. /// 新增行业
  39. /// </summary>
  40. /// <param name="dto"></param>
  41. /// <returns></returns>
  42. /// <exception cref="NotImplementedException"></exception>
  43. public async Task<string> AddIndustryAsync(AddIndustryDto dto, CancellationToken cancellationToken)
  44. {
  45. var entity = dto.Adapt<Industry>();
  46. var id = await _industryRepository.AddAsync(entity, cancellationToken);
  47. if (dto.Files.NotNullOrEmpty())
  48. {
  49. var fileEntities = dto.Files.Adapt<List<Hotline.File.File>>();
  50. fileEntities.ForEach(m => m.Key = id);
  51. await _fileRepository.AddRangeAsync(fileEntities, cancellationToken);
  52. }
  53. return id;
  54. }
  55. public ISugarQueryable<IndustryItemsOutDto> GetIndustres(IndustryListInDto dto)
  56. {
  57. var query = _industryRepository.Queryable()
  58. .WhereIF(dto.Name.NotNullOrEmpty(), m => m.Name.Contains(dto.Name))
  59. .WhereIF(dto.ApproveOrgName.NotNullOrEmpty(), m => m.ApproveOrgName.Contains(dto.ApproveOrgName))
  60. .Select<IndustryItemsOutDto>();
  61. return query;
  62. }
  63. public async Task<IndustryDetailOutDto> GetIndustryDetailAsync(string id)
  64. {
  65. var fileServiceUrl = _sysSetting.FileServerUrl;
  66. var fileDownloadApi = fileServiceUrl + _sysSetting.FileDownloadApi;
  67. var industry = await _industryRepository.GetAsync(id);
  68. var files = await _fileRepository.GetByKeyAsync(id, CancellationToken.None);
  69. var outDto = industry.Adapt<IndustryDetailOutDto>();
  70. outDto.Files = files.Adapt<IList<IndustryFileDto>>();
  71. if (outDto.BackgroundImgUrl.NotNullOrEmpty())
  72. outDto.BackgroundImgUrl = fileDownloadApi + outDto.BackgroundImgUrl;
  73. if (outDto.BannerImgUrl.NotNullOrEmpty())
  74. outDto.BannerImgUrl = fileDownloadApi + outDto.BannerImgUrl;
  75. if (outDto.CareCellImgUrl.NotNullOrEmpty())
  76. outDto.CareCellImgUrl = fileDownloadApi + outDto.CareCellImgUrl;
  77. if (outDto.CellImgUrl.NotNullOrEmpty())
  78. outDto.CellImgUrl = fileDownloadApi + outDto.CellImgUrl;
  79. return outDto;
  80. }
  81. /// <summary>
  82. /// 修改行业
  83. /// </summary>
  84. /// <param name="dto"></param>
  85. /// <param name="requestAborted"></param>
  86. /// <returns></returns>
  87. /// <exception cref="NotImplementedException"></exception>
  88. public async Task UpdateIndustryAsync(UpdateIndustryInDto dto, CancellationToken requestAborted)
  89. {
  90. dto.ValidateObject();
  91. var entity = await _industryRepository.GetAsync(dto.Id) ?? throw UserFriendlyException.SameMessage($"行业不存在 {dto.Id}");
  92. if (dto.Files.NotNullOrEmpty())
  93. {
  94. var fileEntities = dto.Files.Adapt<List<File.File>>();
  95. fileEntities.ForEach(m => m.Key = entity.Id);
  96. await _fileRepository.Removeable().Where(m => m.Key == entity.Id).ExecuteCommandAsync(requestAborted);
  97. await _fileRepository.AddRangeAsync(fileEntities, requestAborted);
  98. }
  99. dto.Adapt(entity);
  100. await _industryRepository.UpdateAsync(entity, requestAborted);
  101. }
  102. #region 行业线索
  103. public ISugarQueryable<IndustryCaseItemOutDto> GetIndustryCaseItems(IndustryCaseItemInDto dto)
  104. {
  105. var query = _industryCaseRepository.Queryable()
  106. .LeftJoin<Industry>((c, i) => c.IndustryId == i.Id)
  107. .WhereIF(dto.IndustryName.NotNullOrEmpty(), (c, i) => i.Name.Contains(dto.IndustryName))
  108. .WhereIF(dto.CaseName.NotNullOrEmpty(), (c, i) => c.Name.Contains(dto.CaseName))
  109. .Select<IndustryCaseItemOutDto>((c, i) =>
  110. new IndustryCaseItemOutDto {
  111. Id = c.Id,
  112. Name = c.Name,
  113. IndustryId = i.Id,
  114. IndustryName = i.Name}, true);
  115. return query;
  116. }
  117. /// <summary>
  118. /// 添加行业线索
  119. /// </summary>
  120. /// <param name="dto"></param>
  121. /// <returns></returns>
  122. public async Task<string> AddIndustryCaseAsync(AddIndustryCaseDto dto)
  123. {
  124. dto.ValidateObject();
  125. var entity = dto.Adapt<IndustryCase>();
  126. entity.CitizenReadPackAmount = entity.CitizenReadPackAmount * 100;
  127. entity.GuiderReadPackAmount = entity.GuiderReadPackAmount * 100;
  128. return await _industryCaseRepository.AddAsync(entity);
  129. }
  130. /// <summary>
  131. /// 修改行业线索
  132. /// </summary>
  133. /// <param name="dto"></param>
  134. /// <returns></returns>
  135. public async Task UpdateIndustryCaseAsync(UpdateIndustryCaseDto dto)
  136. {
  137. dto.ValidateObject();
  138. var entity = await _industryCaseRepository.GetAsync(dto.Id)
  139. ?? throw UserFriendlyException.SameMessage($"行业线索不存在 {dto.Id}");
  140. dto.Adapt(entity);
  141. await _industryCaseRepository.UpdateAsync(entity);
  142. }
  143. public async Task<IndustryCase> GetIndustryCaseAsync(string caseId)
  144. {
  145. return await _industryCaseRepository.GetAsync(caseId);
  146. }
  147. #endregion
  148. #region 行业短信模板
  149. /// <summary>
  150. /// 行业模板集合
  151. /// </summary>
  152. /// <param name="dto"></param>
  153. /// <returns></returns>
  154. public ISugarQueryable<SnapshotSMSTemplateItemsOutDto> GetSMSTemplates(SnapshotSMSTemplateItemsInDto dto)
  155. {
  156. var query = _snapshotSMSTemplateRepository.Queryable()
  157. .LeftJoin<Industry>((s, i) => s.IndustryId == i.Id)
  158. .WhereIF(dto.IndustryName.NotNullOrEmpty(), (s, i) => i.Name.Contains(dto.IndustryName))
  159. .Select<SnapshotSMSTemplateItemsOutDto>();
  160. return query;
  161. }
  162. /// <summary>
  163. /// 添加行业模板
  164. /// </summary>
  165. /// <param name="dto"></param>
  166. /// <returns></returns>
  167. public async Task<string> AddSMSTemplateAsync(AddSnapshotSMSTemplateInDto dto)
  168. {
  169. dto.ValidateObject();
  170. var entity = dto.Adapt<SnapshotSMSTemplate>();
  171. return await _snapshotSMSTemplateRepository.AddAsync(entity);
  172. }
  173. #endregion
  174. }