add:添加.editorconfig

This commit is contained in:
xiaolipro 2024-08-19 15:02:55 +08:00
parent 4d70ee8d07
commit ac56f3ecab
6 changed files with 227 additions and 95 deletions

140
.editorconfig Normal file
View File

@ -0,0 +1,140 @@
# EditorConfig is awesome: https://EditorConfig.org
# Please feel free to update it (by considering the code style of ABP Team).
# top-most EditorConfig file
root = true
[*.cs]
#Namespace设置
# noinspection EditorConfigKeyCorrectness
csharp_style_namespace_declarations = file_scoped
# noinspection EditorConfigKeyCorrectness
dotnet_diagnostic.IDE0161.severity = warning
#Core editorconfig formatting - indentation
#使用制表符进行缩进
# noinspection EditorConfigValueCorrectness
indent_style = tabs
#Formatting - indentation options
#缩进switch case内容
csharp_indent_case_contents = true
#缩进switch标签
csharp_indent_switch_labels = true
#Formatting - new line options
#在新行上放置catch语句
csharp_new_line_before_catch = true
#在新行上放置else语句
csharp_new_line_before_else = true
#要求对象初始化器的成员在单独的行上
csharp_new_line_before_members_in_object_initializers = true
#要求在对象集合数组初始化器、方法、控制块、类型和lambda表达式的花括号前换行(也称为“Allman”风格)
csharp_new_line_before_open_brace = object_collection_array_initializers, methods, control_blocks, types, lambdas
#Formatting - organize using options
#按字母顺序排序System.*using指令,并将它们放在其他using指令之前
dotnet_sort_system_directives_first = true
#Formatting - spacing options
#要求在类型转换和值之间不留空格
csharp_space_after_cast = false
#在类型声明中要求在基类或接口的冒号前留空格
csharp_space_after_colon_in_inheritance_clause = true
#在控制流语句(如for循环)中的关键字后要求留空格
csharp_space_after_keywords_in_control_flow_statements = true
#在类型声明中要求在基类或接口的冒号前留空格
csharp_space_before_colon_in_inheritance_clause = true
#删除空参数列表括号内的空格
csharp_space_between_method_call_empty_parameter_list_parentheses = false
#删除方法调用名称和左括号之间的空格
csharp_space_between_method_call_name_and_opening_parenthesis = false
#在方法调用的左括号后和右括号前不要留空格
csharp_space_between_method_call_parameter_list_parentheses = false
#删除方法声明中空参数列表括号内的空格
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
#在方法声明参数列表的左括号后和右括号前留空格
csharp_space_between_method_declaration_parameter_list_parentheses = false
#Formatting - wrapping options
#将代码块留在单行上
csharp_preserve_single_line_blocks = true
#Style - Code block preferences
#即使是单行代码也使用花括号
csharp_prefer_braces = true:suggestion
#Style - expression bodied member options
#构造函数使用块体
csharp_style_expression_bodied_constructors = false:suggestion
#方法使用块体
csharp_style_expression_bodied_methods = false:suggestion
#属性使用表达式体
csharp_style_expression_bodied_properties = true:suggestion
#Style - expression level options
#尽可能在方法调用的参数列表中内联声明out变量
csharp_style_inlined_variable_declaration = true:suggestion
#对于有关键字表示的类型,成员访问表达式使用语言关键字而不是类型名
dotnet_style_predefined_type_for_member_access = true:suggestion
#Style - Expression-level preferences
#使用default而不是default(T)
csharp_prefer_simple_default_expression = true:suggestion
#尽可能使用对象初始化器初始化对象
dotnet_style_object_initializer = true:suggestion
#使用推断的元组元素名称
dotnet_style_prefer_inferred_tuple_names = true:suggestion
#Style - implicit and explicit types
#在所有情况下都使用var代替显式类型,除非被其他代码样式规则覆盖
csharp_style_var_elsewhere = true:suggestion
#使用var声明内置系统类型(如int)的变量
csharp_style_var_for_built_in_types = true:suggestion
#当类型已经在声明表达式的右侧提及时,使用var
csharp_style_var_when_type_is_apparent = true:suggestion
#Style - language keyword and framework type options
#对于有关键字表示的类型,局部变量、方法参数和类成员使用语言关键字而不是类型名
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
#Style - Miscellaneous preferences
#使用局部函数而不是匿名函数
csharp_style_pattern_local_over_anonymous_function = true:suggestion
#Style - modifier options
#除了公共接口成员外,偏好声明访问修饰符。这目前不会与“总是”不同,并且将在C#添加默认接口方法时作为未来的保护措施。
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion
#Style - Modifier preferences
#当此规则设置为修饰符列表时,偏好指定的顺序。
csharp_preferred_modifier_order = public, protected, private, virtual, async, readonly, static, override, abstract:suggestion
#Style - Pattern matching
#使用模式匹配而不是带有类型转换的is表达式
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
#Style - qualification options
#偏好字段前不加this. 或 Me.(在Visual Basic中)
dotnet_style_qualification_for_field = false:suggestion
#偏好方法前不加this. 或 Me.(在Visual Basic中)
dotnet_style_qualification_for_method = false:suggestion
#偏好属性前不加this. 或 Me.(在Visual Basic中)
dotnet_style_qualification_for_property = false:suggestion

View File

@ -23,6 +23,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "solution items", "solution
common.props = common.props
NuGet.Config = NuGet.Config
.gitignore = .gitignore
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SJZY.Track.Shared", "src\SJZY.Track.Shared\SJZY.Track.Shared.csproj", "{CB860739-8617-48C2-80E3-9F1FBC8D6980}"

View File

@ -13,8 +13,8 @@ namespace SJZY.Track.Application.CAP.EventHandlers;
public class TrackPushCompletedEventHandler : ITransientDependency, ICapSubscribe
{
private readonly ITrackPushRecordsRepository _trackPushRecordsRepository;
private readonly IOrderRepository _orderRepository;
private readonly ITrackPushRecordsRepository _trackPushRecordsRepository;
public TrackPushCompletedEventHandler(ITrackPushRecordsRepository trackPushRecordsRepository,
IOrderRepository orderRepository)
@ -68,10 +68,7 @@ public class TrackPushCompletedEventHandler : ITransientDependency, ICapSubscrib
// tips:只有新增会影响推送进度?
if (log.OptionType != OptionType.新增.ToString()) return;
var order = new OrderEntity
{
Id = log.OrderId
};
var order = new OrderEntity { Id = log.OrderId };
/*
* 异常:最近一条推送是失败
@ -80,10 +77,7 @@ public class TrackPushCompletedEventHandler : ITransientDependency, ICapSubscrib
{
order.QuestionType = (int)TrackProblemType.Error;
order.LatestPushError = log.Message;
await _orderRepository.UpdateColumnAsync(order, x => new
{
x.QuestionType, x.LatestPushError
});
await _orderRepository.UpdateColumnAsync(order, x => new { x.QuestionType, x.LatestPushError });
}
else
{
@ -92,10 +86,8 @@ public class TrackPushCompletedEventHandler : ITransientDependency, ICapSubscrib
order.LatestPushError = null;
order.LatestPushTrackCode = log.TrackCode;
order.LatestPushTime = log.CreateTime;
await _orderRepository.UpdateColumnAsync(order, x => new
{
x.LatestPushTrackCode, x.LatestPushTime, x.QuestionType, x.LatestPushError
});
await _orderRepository.UpdateColumnAsync(order,
x => new { x.LatestPushTrackCode, x.LatestPushTime, x.QuestionType, x.LatestPushError });
}
}
}

View File

@ -6,7 +6,7 @@ using SJZY.Track.Domain.Dtos.Forewarning;
namespace SJZY.Track.Application.HostServices;
public class RedisHostService:IHostedService
public class RedisHostService : IHostedService
{
readonly IForewarningCacheService _forewarningCacheService;
@ -28,15 +28,17 @@ public class RedisHostService:IHostedService
return Task.CompletedTask;
}
private void Subscribe(string message,object value)
private void Subscribe(string message, object value)
{
if (value is string)
if (value is string str)
{
// 暂时只处理一个事件,不做反序列化
//var instance = Newtonsoft.Json.JsonConvert.DeserializeObject<ModifyWarningEvent>(value as string);
var instance = Newtonsoft.Json.JsonConvert.DeserializeObject<ClearRulCacheEvent>(value as string);
if(instance!=null)
var instance = Newtonsoft.Json.JsonConvert.DeserializeObject<ClearRulCacheEvent>(str);
if (instance != null)
{
_forewarningCacheService.Clear(instance);
}
}
}

View File

@ -7,10 +7,6 @@
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<None Include="..\..\.editorconfig" Link=".editorconfig" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="BSI.Stack.Rabbit" Version="2.0.9" />
<PackageReference Include="SJZY.InterfaceRelay.Application.Contracts" Version="7.2.2"/>

View File

@ -18,9 +18,9 @@ namespace SJZY.Track.Application.Services.TrackOrders;
public class TrackOrderService : ApplicationService
{
private readonly IOrderRepository _orderRepository;
private readonly ITrackOrderQueries _trackOrderQueries;
private readonly ITrackDetailsRepository _trackDetailsRepository;
private readonly ITrackContentRepository _trackContentRepository;
private readonly ITrackDetailsRepository _trackDetailsRepository;
private readonly ITrackOrderQueries _trackOrderQueries;
private readonly ITrackPushRecordsRepository _trackPushRecordsRepository;
public TrackOrderService(
@ -38,6 +38,77 @@ public class TrackOrderService : ApplicationService
_trackPushRecordsRepository = trackPushRecordsRepository;
}
#region 轨迹订单列表
/// <summary>
/// 获取分页的轨迹订单
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("GetTrackOrderList")]
public async Task<UnifyPageResultDto<TrackOrderDto>> GetPageTrackOrder(GetPageTrackOrderInput input)
{
var vo = ObjectMapper.Map<GetPageTrackOrderInput, GetPageTrackOrderInputVO>(input);
var pageList = await _trackOrderQueries.GetPageTrackOrder(vo);
var pageResultDto =
ObjectMapper.Map<UnifyPageResultDto<TrackOrderVO>, UnifyPageResultDto<TrackOrderDto>>(pageList);
return pageResultDto;
}
#endregion
[HttpPost("UpdateOrderStatus")]
public async Task<bool> UpdateOrderStatus(UpdateOrderStatusInput input)
{
var order = await _orderRepository.GetFirstAsync(x => x.Id == input.OrderId);
if (order == default) throw new BusinessException(message: "订单不存在");
order.IsCompleted = input.IsCompleted;
return await _orderRepository.UpdateColumnAsync(order, x => new { x.IsCompleted });
}
/// <summary>
/// 获取轨迹计数器
/// </summary>
/// <returns></returns>
[HttpGet("GetTrackCounter")]
public async Task<GetTrackCounterOutput> GetTrackCounterAsync()
{
var counts = await _trackOrderQueries.GetTrackProblemCountsAsync();
return new GetTrackCounterOutput
{
TotalCount = counts.Sum(x => x.Count),
ErrorCount = counts.FirstOrDefault(x => x.ProblemType == (int)TrackProblemType.Error)?.Count ?? 0,
WarnCount = counts.FirstOrDefault(x => x.ProblemType == (int)TrackProblemType.Warn)?.Count ?? 0,
};
}
/// <summary>
/// 获取轨迹推送记录
/// </summary>
/// <returns></returns>
/// <param name="orderId">订单id</param>
[HttpGet("GetTrackPushRecords")]
public async Task<List<TrackPushRecordOutput>> GetTrackPushRecordsAsync(int orderId)
{
var records = await _trackPushRecordsRepository.GetTrackPushRecordsAsync(orderId);
var res = ObjectMapper.Map<List<TrackPushRecordIndex>, List<TrackPushRecordOutput>>(records);
res.ForEach(x =>
{
int hours = (int)x.TrackTimeZone; // 提取整数部分作为小时
int minutes = (int)((x.TrackTimeZone - hours) * 60); // 将小数部分乘以 60 转换为分钟
x.TrackGTMTimeZone =
$"GTM {(x.TrackTimeZone >= 0 ? "+" : "-")}{new TimeSpan(hours, minutes, 0).ToString().RemovePostFix(":00")}";
});
return res;
}
#region 轨迹订单明细
/// <summary>
@ -124,80 +195,10 @@ public class TrackOrderService : ApplicationService
{
throw new BusinessException(message: "轨迹不存在!");
}
await _trackDetailsRepository.DeleteTrackByIdAsync(trackId, track.IndexName);
return true;
}
#endregion
#region 轨迹订单列表
/// <summary>
/// 获取分页的轨迹订单
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("GetTrackOrderList")]
public async Task<UnifyPageResultDto<TrackOrderDto>> GetPageTrackOrder(GetPageTrackOrderInput input)
{
var vo = ObjectMapper.Map<GetPageTrackOrderInput, GetPageTrackOrderInputVO>(input);
var pageList = await _trackOrderQueries.GetPageTrackOrder(vo);
var pageResultDto =
ObjectMapper.Map<UnifyPageResultDto<TrackOrderVO>, UnifyPageResultDto<TrackOrderDto>>(pageList);
return pageResultDto;
}
#endregion
[HttpPost("UpdateOrderStatus")]
public async Task<bool> UpdateOrderStatus(UpdateOrderStatusInput input)
{
var order = await _orderRepository.GetFirstAsync(x => x.Id == input.OrderId);
if (order == default) throw new BusinessException(message: "订单不存在");
order.IsCompleted = input.IsCompleted;
return await _orderRepository.UpdateColumnAsync(order, x => new { x.IsCompleted });
}
/// <summary>
/// 获取轨迹计数器
/// </summary>
/// <returns></returns>
[HttpGet("GetTrackCounter")]
public async Task<GetTrackCounterOutput> GetTrackCounterAsync()
{
var counts = await _trackOrderQueries.GetTrackProblemCountsAsync();
return new GetTrackCounterOutput
{
TotalCount = counts.Sum(x => x.Count),
ErrorCount = counts.FirstOrDefault(x => x.ProblemType == (int)TrackProblemType.Error)?.Count ?? 0,
WarnCount = counts.FirstOrDefault(x => x.ProblemType == (int)TrackProblemType.Warn)?.Count ?? 0,
};
}
/// <summary>
/// 获取轨迹推送记录
/// </summary>
/// <returns></returns>
/// <param name="orderId">订单id</param>
[HttpGet("GetTrackPushRecords")]
public async Task<List<TrackPushRecordOutput>> GetTrackPushRecordsAsync(int orderId)
{
var records = await _trackPushRecordsRepository.GetTrackPushRecordsAsync(orderId);
var res = ObjectMapper.Map<List<TrackPushRecordIndex>, List<TrackPushRecordOutput>>(records);
res.ForEach(x =>
{
int hours = (int)x.TrackTimeZone; // 提取整数部分作为小时
int minutes = (int)((x.TrackTimeZone - hours) * 60); // 将小数部分乘以 60 转换为分钟
x.TrackGTMTimeZone =
$"GTM {(x.TrackTimeZone >= 0 ? "+" : "-")}{new TimeSpan(hours, minutes, 0).ToString().RemovePostFix(":00")}";
});
return res;
}
}