2025-04-17 14:39:14 +08:00
|
|
|
|
using JiShe.CollectBus.Common.Consts;
|
|
|
|
|
|
using JiShe.CollectBus.Common.Enums;
|
2025-04-08 23:15:46 +08:00
|
|
|
|
using JiShe.CollectBus.Common.Extensions;
|
|
|
|
|
|
using System;
|
2025-04-02 09:42:04 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
2025-04-17 14:39:14 +08:00
|
|
|
|
namespace JiShe.CollectBus.Common.Extensions
|
2025-04-02 09:42:04 +08:00
|
|
|
|
{
|
|
|
|
|
|
public class ProtocolConstExtensions
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2025-04-08 23:15:46 +08:00
|
|
|
|
/// 自动获取 ProtocolConst 类中所有下行 Kafka 主题名称
|
2025-04-02 09:42:04 +08:00
|
|
|
|
/// (通过反射筛选 public const string 且字段名以 "EventName" 结尾的常量)
|
|
|
|
|
|
/// </summary>
|
2025-04-10 14:12:14 +08:00
|
|
|
|
public static List<string> GetAllTopicNamesByIssued()
|
2025-04-02 09:42:04 +08:00
|
|
|
|
{
|
2025-04-09 14:31:48 +08:00
|
|
|
|
List<string> topics = typeof(ProtocolConst)
|
2025-04-02 09:42:04 +08:00
|
|
|
|
.GetFields(BindingFlags.Public | BindingFlags.Static)
|
|
|
|
|
|
.Where(f =>
|
|
|
|
|
|
f.IsLiteral &&
|
|
|
|
|
|
!f.IsInitOnly &&
|
|
|
|
|
|
f.FieldType == typeof(string) &&
|
2025-04-08 23:15:46 +08:00
|
|
|
|
f.Name.EndsWith("IssuedEventName")) // 通过命名规则过滤主题字段
|
2025-04-02 09:42:04 +08:00
|
|
|
|
.Select(f => (string)f.GetRawConstantValue()!)
|
|
|
|
|
|
.ToList();
|
2025-04-09 14:31:48 +08:00
|
|
|
|
|
|
|
|
|
|
return topics;
|
2025-04-02 09:42:04 +08:00
|
|
|
|
}
|
2025-04-08 23:15:46 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 自动获取 ProtocolConst 类中所有下行 Kafka 主题名称
|
|
|
|
|
|
/// (通过反射筛选 public const string 且字段名以 "EventName" 结尾的常量)
|
|
|
|
|
|
/// </summary>
|
2025-04-10 14:12:14 +08:00
|
|
|
|
public static List<string> GetAllTopicNamesByReceived()
|
2025-04-08 23:15:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
//固定的上报主题
|
|
|
|
|
|
var topicList = typeof(ProtocolConst)
|
|
|
|
|
|
.GetFields(BindingFlags.Public | BindingFlags.Static)
|
|
|
|
|
|
.Where(f =>
|
|
|
|
|
|
f.IsLiteral &&
|
|
|
|
|
|
!f.IsInitOnly &&
|
|
|
|
|
|
f.FieldType == typeof(string) &&
|
|
|
|
|
|
f.Name.EndsWith("ReceivedEventName")) // 通过命名规则过滤主题字段
|
|
|
|
|
|
.Select(f => (string)f.GetRawConstantValue()!)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
//动态上报主题,需根据协议的AFN功能码动态获取
|
|
|
|
|
|
var afnList = EnumExtensions.ToNameValueDictionary<AFN>();
|
2025-04-10 14:12:14 +08:00
|
|
|
|
//需要排除的AFN功能码
|
|
|
|
|
|
var excludeItems = new List<int>() { 6, 7, 8,15 };
|
|
|
|
|
|
|
2025-04-08 23:15:46 +08:00
|
|
|
|
foreach (var item in afnList)
|
|
|
|
|
|
{
|
2025-04-10 14:12:14 +08:00
|
|
|
|
if (excludeItems.Contains(item.Value))
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-08 23:15:46 +08:00
|
|
|
|
topicList.Add(string.Format(ProtocolConst.AFNTopicNameFormat, item.Value.ToString().PadLeft(2, '0')));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return topicList;
|
|
|
|
|
|
}
|
2025-04-02 09:42:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|