You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Txgy.EWS.Client/docs/report-energy-and-auth-migr...

233 lines
6.0 KiB
Markdown

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 鉴权服务器与报表能量显示迁移说明
更新时间2026-06-25
这份文档记录两项未必已经提交到仓库的手工修改,后续迁移到另一个版本项目时按这里的内容对照修改。
## 1. 鉴权服务器地址
新的鉴权/API 服务器地址:
```text
http://8.141.12.31:80/api/v1/
```
迁移时检查启动项目配置文件:
```text
Txgy.EWS.Client.Start/App.config
```
确认 `api_domain` 使用新地址:
```xml
<add key="api_domain" value="http://8.141.12.31:80/api/v1/" />
```
登录接口仍按现有代码拼接:
```text
{api_domain}login/login
```
也就是:
```text
http://8.141.12.31:80/api/v1/login/login
```
注意WPF 编译后运行时实际读取的是输出目录中的 `Txgy.EWS.Client.Start.exe.config`。如果只改源码 `App.config`,需要重新编译,确保输出配置同步更新。
## 2. 报表页能量显示
目标:在报表页面查询结果区域显示:
- 事件总数
- 中等能量事件数
- 总能量
- 平均能量
- 最大能量
涉及文件:
```text
Txgy.EWS.Client.PageModule/ViewModels/ReportViewModel.cs
Txgy.EWS.Client.PageModule/Views/ReportView.xaml
```
### 2.1 ReportViewModel 增加绑定属性
`SearchCount` 属性附近增加三个属性:
```csharp
private double _totalEnergy = 0;
public double TotalEnergy
{
get { return _totalEnergy; }
set
{
SetProperty(ref _totalEnergy, value);
}
}
private double _averageEnergy = 0;
public double AverageEnergy
{
get { return _averageEnergy; }
set
{
SetProperty(ref _averageEnergy, value);
}
}
private double _maxEnergy = 0;
public double MaxEnergy
{
get { return _maxEnergy; }
set
{
SetProperty(ref _maxEnergy, value);
}
}
```
### 2.2 查询后更新能量统计
`SearchEvents(...)` 方法中,查询结果列表全部构建完成后,原来通常会有:
```csharp
SearchCount = results.Count;
return results;
```
改成:
```csharp
SearchCount = results.Count;
UpdateEnergyStats(results);
return results;
```
然后在 `SearchEvents(...)` 方法后增加:
```csharp
private void UpdateEnergyStats(List<GridItemEventResult> results)
{
if (results == null || results.Count == 0)
{
TotalEnergy = 0;
AverageEnergy = 0;
MaxEnergy = 0;
return;
}
TotalEnergy = Math.Round(results.Sum(rs => rs.Energy), 2);
AverageEnergy = Math.Round(results.Average(rs => rs.Energy), 2);
MaxEnergy = Math.Round(results.Max(rs => rs.Energy), 2);
}
```
前提:`ReportViewModel.cs` 已经有 `using System.Linq;``using System;`。当前项目已有这两个引用。
### 2.3 ReportView.xaml 增加显示区域
原页面查询按钮区域下方已有“事件总数 / 中等能量事件”显示。迁移时可以把那段替换为下面这段,或者在原有区域后追加三个能量字段。
推荐替换片段:
```xml
<StackPanel Grid.Row="1"
Grid.ColumnSpan="3"
VerticalAlignment="Center"
Orientation="Horizontal">
<TextBlock VerticalAlignment="Center"
Text="事件总数:"
FontSize="16" />
<TextBlock VerticalAlignment="Center"
d:Text="11142"
Foreground="Black"
Text="{Binding SearchCount}"
FontSize="16" />
<TextBlock Margin="10,0,0,0"
Text="中等能量事件:"
FontSize="16" />
<TextBlock d:Text="1000"
Foreground="Black"
FontSize="16"
Text="{Binding MiddleEventCount}" />
<TextBlock Margin="20,0,0,0"
Text="总能量:"
FontSize="16" />
<TextBlock Foreground="Black"
FontSize="16"
FontWeight="SemiBold"
Text="{Binding TotalEnergy, StringFormat={}{0:F0}J}" />
<TextBlock Margin="20,0,0,0"
Text="平均能量:"
FontSize="16" />
<TextBlock Foreground="Black"
FontSize="16"
FontWeight="SemiBold"
Text="{Binding AverageEnergy, StringFormat={}{0:F0}J}" />
<TextBlock Margin="20,0,0,0"
Text="最大能量:"
FontSize="16" />
<TextBlock Foreground="Black"
FontSize="16"
FontWeight="SemiBold"
Text="{Binding MaxEnergy, StringFormat={}{0:F0}J}" />
</StackPanel>
```
如果目标版本页面布局空间不足,可以使用 `WrapPanel` 避免文字挤出:
```xml
<WrapPanel Grid.Row="1"
Grid.ColumnSpan="3"
VerticalAlignment="Center">
<TextBlock Text="事件总数:" FontSize="16" />
<TextBlock Width="60"
Foreground="Black"
FontWeight="SemiBold"
Text="{Binding SearchCount}"
FontSize="16" />
<TextBlock Text="中等能量事件:" FontSize="16" />
<TextBlock Width="60"
Foreground="Black"
FontWeight="SemiBold"
Text="{Binding MiddleEventCount}"
FontSize="16" />
<TextBlock Text="总能量:" FontSize="16" />
<TextBlock Width="80"
Foreground="Black"
FontWeight="SemiBold"
Text="{Binding TotalEnergy, StringFormat={}{0:F0}J}"
FontSize="16" />
<TextBlock Text="平均能量:" FontSize="16" />
<TextBlock Width="80"
Foreground="Black"
FontWeight="SemiBold"
Text="{Binding AverageEnergy, StringFormat={}{0:F0}J}"
FontSize="16" />
<TextBlock Text="最大能量:" FontSize="16" />
<TextBlock Width="80"
Foreground="Black"
FontWeight="SemiBold"
Text="{Binding MaxEnergy, StringFormat={}{0:F0}J}"
FontSize="16" />
</WrapPanel>
```
### 2.4 验证点
迁移后至少验证:
1. 项目能通过 MSBuild 编译。
2. 报表页点击“查询”后,`事件总数` 正常变化。
3. `总能量 / 平均能量 / 最大能量` 能随查询结果更新。
4. 查询结果为空时,三个能量统计显示为 `0J`