fix(homepage): 修复数据统计图表索引错误并优化上传逻辑

1. 修正每日/每周/每月/年度统计图表的索引偏移问题,正确匹配数据下标
2. 将灭蚊数据上传改为分批上传,避免单次上传数据量过大
3. 更新上传完成的日志和提示文案,显示实际上传的数量
This commit is contained in:
“虞渠成” 2026-07-27 14:07:06 +08:00
parent f9ac8a931b
commit 4c253a419e
2 changed files with 33 additions and 21 deletions

View File

@ -49,8 +49,8 @@ namespace Kill.UI.Pages
List<int> daily = new List<int>();
for (int i = 0; i <24; i++)
{
if(data.data.stats.Count>i+1)
daily.Add(data.data.stats[i+1].count);
if(data.data.stats.Count>0)
daily.Add(data.data.stats[i].count);
else
daily.Add(0);
}
@ -60,8 +60,8 @@ namespace Kill.UI.Pages
List<int> weekly = new List<int>();
for (int i = 0; i <7; i++)
{
if(data.data.stats.Count>i+1)
weekly.Add(data.data.stats[i+1].count);
if(data.data.stats.Count>0)
weekly.Add(data.data.stats[i].count);
else
weekly.Add(0);
}
@ -71,8 +71,8 @@ namespace Kill.UI.Pages
List<int> monthly = new List<int>();
for (int i = 0; i <31; i++)
{
if(data.data.stats.Count>i+1)
monthly.Add(data.data.stats[i+1].count);
if(data.data.stats.Count>0)
monthly.Add(data.data.stats[i].count);
else
monthly.Add(0);
}
@ -82,8 +82,8 @@ namespace Kill.UI.Pages
List<int> annual = new List<int>();
for (int i = 0; i <12; i++)
{
if(data.data.stats.Count>i+1)
annual.Add(data.data.stats[i+1].count);
if(data.data.stats.Count>0)
annual.Add(data.data.stats[i].count);
else
annual.Add(0);
}

View File

@ -1463,22 +1463,34 @@ namespace Kill.UI.Pages
}
async void PostMosquitoDatas()
{
List<PostRecordData> postRecordDatas=new List<PostRecordData>();
foreach(var a in mosquitoDatas)
const int batchSize = 500;
int total = mosquitoDatas.Count;
int uploadedCount = 0;
// 分批上传每500条一次
for (int i = 0; i < total; i += batchSize)
{
var b=new PostRecordData
int end = Mathf.Min(i + batchSize, total);
List<PostRecordData> batch = new List<PostRecordData>();
for (int j = i; j < end; j++)
{
device_sn=selectedDevice.ble_mac,
record_time=a.GetTimeString(),
angle=a.GetActualAngle(),
distance=a.GetActualDis()
};
postRecordDatas.Add(b);
var a = mosquitoDatas[j];
batch.Add(new PostRecordData
{
device_sn = selectedDevice.ble_mac,
record_time = a.GetTimeString(),
angle = a.GetActualAngle(),
distance = a.GetActualDis()
});
}
var response = await NetworkCtrl.Instance.Post<NoDataResponse>("/api/v1/stats/device/records", batch);
ResponseCodeHandler.HandleResponse(response, null, null);
uploadedCount += batch.Count;
}
Debug.Log("发送灭蚊数据:"+JsonUtility.ToJson(postRecordDatas));
var response = await NetworkCtrl.Instance.Post<NoDataResponse>("/api/v1/stats/device/records", postRecordDatas);
ResponseCodeHandler.HandleResponse(response, null, null);
ToastUI.ShowText(LanguageManager.Instance.GetLanguage("100310").Replace("{0}",mosquitoDatas.Count.ToString()));
Debug.Log($"灭蚊数据上传完成,共 {uploadedCount} 条");
ToastUI.ShowText(LanguageManager.Instance.GetLanguage("100310").Replace("{0}", uploadedCount.ToString()));
}
/// <summary>
/// 获取所有蚊虫数据 (0xA4)