完善增量源码生成器
This commit is contained in:
parent
c47ee94469
commit
f71ce3bacb
@ -452,7 +452,7 @@ namespace JiShe.CollectBus.IncrementalGenerator
|
|||||||
Compilation compilation,
|
Compilation compilation,
|
||||||
INamedTypeSymbol classSymbol)
|
INamedTypeSymbol classSymbol)
|
||||||
{
|
{
|
||||||
code.AppendLine(" public List<string> PropertyList {get;} = new List<string>()");
|
code.AppendLine(" public List<string> PropertyNameList {get;} = new List<string>()");
|
||||||
code.AppendLine(" {");
|
code.AppendLine(" {");
|
||||||
List<string> tempPropList = new List<string>();
|
List<string> tempPropList = new List<string>();
|
||||||
foreach (var prop in propList)
|
foreach (var prop in propList)
|
||||||
@ -477,39 +477,53 @@ namespace JiShe.CollectBus.IncrementalGenerator
|
|||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 生成当前类属性信息集合
|
/// 生成当前类属性信息集合(支持嵌套元组)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="propList">属性集合</param>
|
|
||||||
/// <param name="code"></param>
|
|
||||||
/// <param name="compilation"></param>
|
|
||||||
/// <param name="classSymbol"></param>
|
|
||||||
private static void GeneratePropertyInfoListForSourceEntity(
|
private static void GeneratePropertyInfoListForSourceEntity(
|
||||||
IEnumerable<IPropertySymbol> propList,
|
IEnumerable<IPropertySymbol> propList,
|
||||||
StringBuilder code,
|
StringBuilder code,
|
||||||
Compilation compilation,
|
Compilation compilation,
|
||||||
INamedTypeSymbol classSymbol)
|
INamedTypeSymbol classSymbol)
|
||||||
{
|
{
|
||||||
code.AppendLine(" public List<string> PropertyList {get;} = new List<string>()");
|
code.AppendLine(" public List<System.Reflection.PropertyInfo> PropertyInfoList { get; } = new List<System.Reflection.PropertyInfo>");
|
||||||
code.AppendLine(" {");
|
code.AppendLine(" {");
|
||||||
List<string> tempPropList = new List<string>();
|
|
||||||
|
var initializerLines = new List<string>();
|
||||||
|
|
||||||
foreach (var prop in propList)
|
foreach (var prop in propList)
|
||||||
{
|
{
|
||||||
|
// 主属性
|
||||||
|
AddPropertyInitializer(classSymbol, prop, initializerLines);
|
||||||
|
|
||||||
|
// 处理元组嵌套属性
|
||||||
if (prop.Type is INamedTypeSymbol { IsTupleType: true } tupleType)
|
if (prop.Type is INamedTypeSymbol { IsTupleType: true } tupleType)
|
||||||
{
|
{
|
||||||
foreach (var element in tupleType.TupleElements)
|
foreach (var element in tupleType.TupleElements)
|
||||||
{
|
{
|
||||||
tempPropList.Add($"\"{prop.Name}.{element.Name}\"");
|
// 生成形如:typeof(ValueTuple<string,T>).GetProperty("Item1")
|
||||||
|
var tupleTypeName = tupleType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
|
||||||
|
initializerLines.Add(
|
||||||
|
$"typeof({tupleTypeName}).GetProperty(\"{element.Name}\") ?? " +
|
||||||
|
$"throw new InvalidOperationException(\"Tuple element {element.Name} not found\")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
tempPropList.Add($"\"{prop.Name}\"");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
code.Append(string.Join(",", tempPropList));
|
code.AppendLine(string.Join(",\n", initializerLines));
|
||||||
|
|
||||||
code.AppendLine(" };");
|
code.AppendLine(" };");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void AddPropertyInitializer(
|
||||||
|
INamedTypeSymbol classSymbol,
|
||||||
|
IPropertySymbol prop,
|
||||||
|
List<string> initializerLines)
|
||||||
|
{
|
||||||
|
var classType = classSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
|
||||||
|
initializerLines.Add(
|
||||||
|
$"typeof({classType}).GetProperty(\"{prop.Name}\", " +
|
||||||
|
"System.Reflection.BindingFlags.Public | " +
|
||||||
|
"System.Reflection.BindingFlags.Instance) ?? " +
|
||||||
|
$"throw new InvalidOperationException(\"Property {prop.Name} not found\")");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,77 +0,0 @@
|
|||||||
// <auto-generated/>
|
|
||||||
#nullable enable
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using JiShe.CollectBus.Analyzers.Shared;
|
|
||||||
namespace JiShe.CollectBus.IoTDB.Model;
|
|
||||||
|
|
||||||
public sealed class TableModelSingleMeasuringEntityAccessor3<T> : ISourceEntityAccessor<global::JiShe.CollectBus.IoTDB.Model.TableModelSingleMeasuringEntity<T>>
|
|
||||||
{
|
|
||||||
public static string GetSingleColumn_Item1(global::JiShe.CollectBus.IoTDB.Model.TableModelSingleMeasuringEntity<T> obj) => obj.SingleColumn.Item1;
|
|
||||||
public static void SetSingleColumn_Item1(global::JiShe.CollectBus.IoTDB.Model.TableModelSingleMeasuringEntity<T> obj, string value) => obj.SingleColumn = (value, obj.SingleColumn.Item2);
|
|
||||||
public static T GetSingleColumn_Item2(global::JiShe.CollectBus.IoTDB.Model.TableModelSingleMeasuringEntity<T> obj) => obj.SingleColumn.Item2;
|
|
||||||
public static void SetSingleColumn_Item2(global::JiShe.CollectBus.IoTDB.Model.TableModelSingleMeasuringEntity<T> obj, T value) => obj.SingleColumn = (obj.SingleColumn.Item1, value);
|
|
||||||
public static string GetSystemName(JiShe.CollectBus.IoTDB.Model.IoTEntity obj) => obj.SystemName;
|
|
||||||
public static void SetSystemName(JiShe.CollectBus.IoTDB.Model.IoTEntity obj, string value) => obj.SystemName = value;
|
|
||||||
public static string GetProjectId(JiShe.CollectBus.IoTDB.Model.IoTEntity obj) => obj.ProjectId;
|
|
||||||
public static void SetProjectId(JiShe.CollectBus.IoTDB.Model.IoTEntity obj, string value) => obj.ProjectId = value;
|
|
||||||
public static string GetDeviceType(JiShe.CollectBus.IoTDB.Model.IoTEntity obj) => obj.DeviceType;
|
|
||||||
public static void SetDeviceType(JiShe.CollectBus.IoTDB.Model.IoTEntity obj, string value) => obj.DeviceType = value;
|
|
||||||
public static string GetDeviceId(JiShe.CollectBus.IoTDB.Model.IoTEntity obj) => obj.DeviceId;
|
|
||||||
public static void SetDeviceId(JiShe.CollectBus.IoTDB.Model.IoTEntity obj, string value) => obj.DeviceId = value;
|
|
||||||
public static long GetTimestamps(JiShe.CollectBus.IoTDB.Model.IoTEntity obj) => obj.Timestamps;
|
|
||||||
public static void SetTimestamps(JiShe.CollectBus.IoTDB.Model.IoTEntity obj, long value) => obj.Timestamps = value;
|
|
||||||
public List<string> PropertyNameList { get; } = new List<string>()
|
|
||||||
{
|
|
||||||
"SingleColumn.Item1","SingleColumn.Item2","SystemName","ProjectId","DeviceType","DeviceId","Timestamps" };
|
|
||||||
public object GetPropertyValue(JiShe.CollectBus.IoTDB.Model.TableModelSingleMeasuringEntity<T> targetEntity, string propertyName)
|
|
||||||
{
|
|
||||||
return propertyName switch
|
|
||||||
{
|
|
||||||
"SingleColumn.Item1" => GetSingleColumn_Item1(targetEntity),
|
|
||||||
"SingleColumn.Item2" => GetSingleColumn_Item2(targetEntity),
|
|
||||||
"SystemName" => GetSystemName(targetEntity),
|
|
||||||
"ProjectId" => GetProjectId(targetEntity),
|
|
||||||
"DeviceType" => GetDeviceType(targetEntity),
|
|
||||||
"DeviceId" => GetDeviceId(targetEntity),
|
|
||||||
"Timestamps" => GetTimestamps(targetEntity),
|
|
||||||
_ => throw new ArgumentException($"Unknown property: {propertyName}")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
public void SetPropertyValue(JiShe.CollectBus.IoTDB.Model.TableModelSingleMeasuringEntity<T> targetEntity, string propertyName, object value)
|
|
||||||
{
|
|
||||||
switch (propertyName)
|
|
||||||
{
|
|
||||||
case "SingleColumn.Item1":
|
|
||||||
SetSingleColumn_Item1(
|
|
||||||
targetEntity, (string)value);
|
|
||||||
break;
|
|
||||||
case "SingleColumn.Item2":
|
|
||||||
SetSingleColumn_Item2(
|
|
||||||
targetEntity, (T)value);
|
|
||||||
break;
|
|
||||||
case "SystemName":
|
|
||||||
SetSystemName(
|
|
||||||
targetEntity, (string)value);
|
|
||||||
break;
|
|
||||||
case "ProjectId":
|
|
||||||
SetProjectId(
|
|
||||||
targetEntity, (string)value);
|
|
||||||
break;
|
|
||||||
case "DeviceType":
|
|
||||||
SetDeviceType(
|
|
||||||
targetEntity, (string)value);
|
|
||||||
break;
|
|
||||||
case "DeviceId":
|
|
||||||
SetDeviceId(
|
|
||||||
targetEntity, (string)value);
|
|
||||||
break;
|
|
||||||
case "Timestamps":
|
|
||||||
SetTimestamps(
|
|
||||||
targetEntity, (long)value);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new ArgumentException($"Unknown property: {propertyName}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -715,10 +715,10 @@ namespace JiShe.CollectBus.Protocol.T37612012
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual List<string> Generate_DataUnit(DataTimeMark timeMark)
|
public virtual List<string> Generate_DataUnit(DataTimeMark timeMark)
|
||||||
{
|
{
|
||||||
List<string> values = new List<string>
|
List<string> values = new List<string>();
|
||||||
{
|
|
||||||
SplitDataTime(timeMark.DataTime)//数据时间
|
values.AddRange(SplitDataTime(timeMark.DataTime));//数据时间
|
||||||
};
|
|
||||||
if (timeMark.Density > 0)
|
if (timeMark.Density > 0)
|
||||||
values.Add(timeMark.Density.HexToDecStr().PadLeft(2, '0'));//密度
|
values.Add(timeMark.Density.HexToDecStr().PadLeft(2, '0'));//密度
|
||||||
if (timeMark.Point > 0)
|
if (timeMark.Point > 0)
|
||||||
@ -727,13 +727,13 @@ namespace JiShe.CollectBus.Protocol.T37612012
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private string SplitDataTime(DateTime dataTime)
|
private List<string> SplitDataTime(DateTime dataTime)
|
||||||
{
|
{
|
||||||
//2101060815
|
//2101060815
|
||||||
List<string> values = new List<string>() { $"{dataTime}:YY", $"{dataTime}:MM", $"{dataTime}:dd", $"{dataTime}:HH", $"{dataTime}:mm", };
|
List<string> values = new List<string>() { $"{dataTime:yy}", $"{dataTime:MM}", $"{dataTime:dd}", $"{dataTime:HH}", $"{dataTime:mm}", };
|
||||||
|
|
||||||
values.Reverse();
|
values.Reverse();
|
||||||
return string.Join("", values);
|
return values;
|
||||||
|
//return string.Join("", values);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@ -125,13 +125,13 @@ namespace JiShe.CollectBus.DataChannels
|
|||||||
// 批量写入数据库
|
// 批量写入数据库
|
||||||
await _dbProvider.BatchInsertAsync(metadata, records);
|
await _dbProvider.BatchInsertAsync(metadata, records);
|
||||||
|
|
||||||
// 限流推送Kafka
|
//// 限流推送Kafka
|
||||||
await DeviceGroupBalanceControl.ProcessWithThrottleAsync(
|
//await DeviceGroupBalanceControl.ProcessWithThrottleAsync(
|
||||||
items: records,
|
// items: records,
|
||||||
deviceIdSelector: data => data.DeviceId,
|
// deviceIdSelector: data => data.DeviceId,
|
||||||
processor: async (data, groupIndex) =>
|
// processor: async (data, groupIndex) =>
|
||||||
await KafkaProducerIssuedMessageAction(topicName, data, groupIndex)
|
// await KafkaProducerIssuedMessageAction(topicName, data, groupIndex)
|
||||||
);
|
//);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -336,47 +336,47 @@ namespace JiShe.CollectBus.ScheduledMeterReading
|
|||||||
|
|
||||||
//此处代码不要删除
|
//此处代码不要删除
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
//var timeDensity = "15";
|
var timeDensity = "15";
|
||||||
//var serverTagName = "JiSheCollectBus2";
|
var serverTagName = "JiSheCollectBus2";
|
||||||
//var redisCacheMeterInfoHashKeyTemp = $"{string.Format(RedisConst.CacheMeterInfoHashKey, SystemType, serverTagName, MeterTypeEnum.Ammeter, timeDensity)}";
|
var redisCacheMeterInfoHashKeyTemp = $"{string.Format(RedisConst.CacheMeterInfoHashKey, SystemType, serverTagName, MeterTypeEnum.Ammeter, timeDensity)}";
|
||||||
//var redisCacheMeterInfoSetIndexKeyTemp = $"{string.Format(RedisConst.CacheMeterInfoSetIndexKey, SystemType, serverTagName, MeterTypeEnum.Ammeter, timeDensity)}";
|
var redisCacheMeterInfoSetIndexKeyTemp = $"{string.Format(RedisConst.CacheMeterInfoSetIndexKey, SystemType, serverTagName, MeterTypeEnum.Ammeter, timeDensity)}";
|
||||||
//var redisCacheMeterInfoZSetScoresIndexKeyTemp = $"{string.Format(RedisConst.CacheMeterInfoZSetScoresIndexKey, SystemType, serverTagName, MeterTypeEnum.Ammeter, timeDensity)}";
|
var redisCacheMeterInfoZSetScoresIndexKeyTemp = $"{string.Format(RedisConst.CacheMeterInfoZSetScoresIndexKey, SystemType, serverTagName, MeterTypeEnum.Ammeter, timeDensity)}";
|
||||||
|
|
||||||
List<AmmeterInfo> meterInfos = new List<AmmeterInfo>();
|
List<AmmeterInfo> meterInfos = new List<AmmeterInfo>();
|
||||||
//List<string> focusAddressDataLista = new List<string>();
|
List<string> focusAddressDataLista = new List<string>();
|
||||||
//var timer1 = Stopwatch.StartNew();
|
var timer1 = Stopwatch.StartNew();
|
||||||
|
|
||||||
//var allIds = new HashSet<string>();
|
var allIds = new HashSet<string>();
|
||||||
//decimal? score = null;
|
decimal? score = null;
|
||||||
//string member = null;
|
string member = null;
|
||||||
|
|
||||||
//while (true)
|
while (true)
|
||||||
//{
|
{
|
||||||
// var page = await _redisDataCacheService.GetAllPagedData<AmmeterInfo>(
|
var page = await _redisDataCacheService.GetAllPagedData<AmmeterInfo>(
|
||||||
// redisCacheMeterInfoHashKeyTemp,
|
redisCacheMeterInfoHashKeyTemp,
|
||||||
// redisCacheMeterInfoZSetScoresIndexKeyTemp,
|
redisCacheMeterInfoZSetScoresIndexKeyTemp,
|
||||||
// pageSize: 1000,
|
pageSize: 1000,
|
||||||
// lastScore: score,
|
lastScore: score,
|
||||||
// lastMember: member);
|
lastMember: member);
|
||||||
|
|
||||||
// meterInfos.AddRange(page.Items);
|
meterInfos.AddRange(page.Items);
|
||||||
// focusAddressDataLista.AddRange(page.Items.Select(d => $"{d.MeterId}"));
|
focusAddressDataLista.AddRange(page.Items.Select(d => $"{d.MeterId}"));
|
||||||
// foreach (var item in page.Items)
|
foreach (var item in page.Items)
|
||||||
// {
|
{
|
||||||
// if (!allIds.Add(item.MemberId))
|
if (!allIds.Add(item.MemberId))
|
||||||
// {
|
{
|
||||||
// _logger.LogError($"{item.MemberId}Duplicate data found!");
|
_logger.LogError($"{item.MemberId}Duplicate data found!");
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// if (!page.HasNext) break;
|
if (!page.HasNext) break;
|
||||||
// score = page.NextScore;
|
score = page.NextScore;
|
||||||
// member = page.NextMember;
|
member = page.NextMember;
|
||||||
//}
|
}
|
||||||
|
|
||||||
|
|
||||||
//timer1.Stop();
|
timer1.Stop();
|
||||||
//_logger.LogError($"电表初始化读取数据总共花费时间{timer1.ElapsedMilliseconds}毫秒");
|
_logger.LogError($"电表初始化读取数据总共花费时间{timer1.ElapsedMilliseconds}毫秒");
|
||||||
//DeviceGroupBalanceControl.InitializeCache(focusAddressDataLista, _kafkaOptions.NumPartitions);
|
DeviceGroupBalanceControl.InitializeCache(focusAddressDataLista, _kafkaOptions.NumPartitions);
|
||||||
return;
|
return;
|
||||||
#else
|
#else
|
||||||
var meterInfos = await GetAmmeterInfoList(gatherCode);
|
var meterInfos = await GetAmmeterInfoList(gatherCode);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user