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

View File

@ -1463,22 +1463,34 @@ namespace Kill.UI.Pages
} }
async void PostMosquitoDatas() async void PostMosquitoDatas()
{ {
List<PostRecordData> postRecordDatas=new List<PostRecordData>(); const int batchSize = 500;
foreach(var a in mosquitoDatas) 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, var a = mosquitoDatas[j];
record_time=a.GetTimeString(), batch.Add(new PostRecordData
angle=a.GetActualAngle(), {
distance=a.GetActualDis() device_sn = selectedDevice.ble_mac,
}; record_time = a.GetTimeString(),
postRecordDatas.Add(b); 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); Debug.Log($"灭蚊数据上传完成,共 {uploadedCount} 条");
ResponseCodeHandler.HandleResponse(response, null, null); ToastUI.ShowText(LanguageManager.Instance.GetLanguage("100310").Replace("{0}", uploadedCount.ToString()));
ToastUI.ShowText(LanguageManager.Instance.GetLanguage("100310").Replace("{0}",mosquitoDatas.Count.ToString()));
} }
/// <summary> /// <summary>
/// 获取所有蚊虫数据 (0xA4) /// 获取所有蚊虫数据 (0xA4)