BaseDataApplication.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using Hotline.Caching.Interfaces;
  2. using Hotline.Repository.SqlSugar.System;
  3. using Hotline.Settings;
  4. using Hotline.Share.Dtos.Order;
  5. using Hotline.Share.Enums.CallCenter;
  6. using Hotline.Share.Enums.Order;
  7. using J2N.Collections.ObjectModel;
  8. using System;
  9. using System.Collections.Concurrent;
  10. using System.Collections.Generic;
  11. using System.Diagnostics;
  12. using System.Linq;
  13. using System.Reflection;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using XF.Domain.Authentications;
  17. using XF.Domain.Dependency;
  18. using XF.Utility.EnumExtensions;
  19. namespace Hotline.Application.Systems;
  20. public class BaseDataApplication : IScopeDependency
  21. {
  22. private readonly ISystemDicDataCacheManager _sysDicDataCacheManager;
  23. private readonly ISystemOrganizeRepository _systemOrganizeRepository;
  24. public BaseDataApplication(ISystemDicDataCacheManager sysDicDataCacheManager, ISystemOrganizeRepository systemOrganizeRepository)
  25. {
  26. _sysDicDataCacheManager = sysDicDataCacheManager;
  27. _systemOrganizeRepository = systemOrganizeRepository;
  28. }
  29. private ConcurrentDictionary<string, dynamic> _baseData = new ConcurrentDictionary<string, dynamic>();
  30. //private ConcurrentDictionary<string, int> _baseType = new ConcurrentDictionary<string, int>();
  31. //private ConcurrentDictionary<string, int> _enumType = new ConcurrentDictionary<string, int>();
  32. #region 内部方法
  33. private void Add(Type type)
  34. {
  35. var name = new StackTrace().GetFrame(1).GetMethod().Name;
  36. var method = typeof(EnumExts).GetMethod("GetDescriptions", BindingFlags.Static | BindingFlags.Public);
  37. var genericMethod = method.MakeGenericMethod(type);
  38. var result = genericMethod.Invoke(null, null);
  39. _baseData.TryAdd(name, result);
  40. }
  41. private void Add(string key)
  42. {
  43. var name = new StackTrace().GetFrame(1).GetMethod().Name;
  44. var result = _sysDicDataCacheManager
  45. .GetSysDicDataCache(key)
  46. .Where(x => x.DicDataValue != "-1")
  47. .Select(m => new { m.Id, m.DicDataName, m.DicDataValue });
  48. _baseData.TryAdd(name, result);
  49. }
  50. #endregion
  51. public BaseDataApplication Source()
  52. {
  53. Add(typeof(ESource));
  54. return this;
  55. }
  56. public BaseDataApplication VisitType()
  57. {
  58. Add(typeof(EVisitType));
  59. return this;
  60. }
  61. public Dictionary<string, dynamic> Build()
  62. {
  63. return new Dictionary<string, dynamic>(_baseData);
  64. }
  65. public BaseDataApplication VoiceEvaluate()
  66. {
  67. Add(typeof(EVoiceEvaluate));
  68. return this;
  69. }
  70. public BaseDataApplication SeatEvaluate()
  71. {
  72. Add(typeof(ESeatEvaluate));
  73. return this;
  74. }
  75. public BaseDataApplication VisitSatisfaction()
  76. {
  77. Add(SysDicTypeConsts.VisitSatisfaction);
  78. return this;
  79. }
  80. public BaseDataApplication VisitManner()
  81. {
  82. Add(SysDicTypeConsts.VisitManner);
  83. return this;
  84. }
  85. public BaseDataApplication VisitStateQuery()
  86. {
  87. Add(typeof(EVisitStateQuery));
  88. return this;
  89. }
  90. public BaseDataApplication DissatisfiedReason()
  91. {
  92. Add(SysDicTypeConsts.DissatisfiedReason);
  93. return this;
  94. }
  95. public BaseDataApplication CallForwardingSource()
  96. {
  97. Add(SysDicTypeConsts.CallForwardingSource);
  98. return this;
  99. }
  100. public BaseDataApplication CallForwardingType()
  101. {
  102. Add(SysDicTypeConsts.CallForwardingType);
  103. return this;
  104. }
  105. public BaseDataApplication EndBy()
  106. {
  107. Add(typeof(EEndBy));
  108. return this;
  109. }
  110. public BaseDataApplication OrgsOptions(ISessionContext sessionContext)
  111. {
  112. IReadOnlyList<SystemOrganize> items;
  113. if (sessionContext.OrgIsCenter)
  114. items = _systemOrganizeRepository.GetOrgJson().GetAwaiter().GetResult();
  115. else
  116. items = _systemOrganizeRepository.GetOrgJsonForUser(sessionContext.RequiredOrgId).GetAwaiter().GetResult();
  117. _baseData.TryAdd("OrgsOptions", items);
  118. return this;
  119. }
  120. public BaseDataApplication AttitudeType()
  121. {
  122. Add(typeof(EAttitudeType));
  123. return this;
  124. }
  125. }