feat(zltx_statistics): 按日期排序并返回JSON格式统计数据
- 添加 sort 包以支持数据排序功能- 对最近三天和最近一个月的数据按日期升序排列 - 将响应内容从原始文本改为序列化后的 JSON 字符串 - 确保通过 channel 返回的响应类型为 ResponseJson
This commit is contained in:
parent
7a1662943e
commit
6c812efc3f
|
@ -5,6 +5,7 @@ import (
|
|||
"ai_scheduler/internal/entitys"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"gitea.cdlsxd.cn/self-tools/l_request"
|
||||
"github.com/gofiber/websocket/v2"
|
||||
|
@ -102,9 +103,20 @@ func (z ZltxOrderStatisticsTool) getZltxOrderStatistics(channel chan entitys.Res
|
|||
if resData.Code != 200 {
|
||||
return fmt.Errorf("zltx order statistics error: %s", resData.Error)
|
||||
}
|
||||
//按照日期排序
|
||||
sort.Slice(resData.Data.RecentThreeDays, func(i, j int) bool {
|
||||
return resData.Data.RecentThreeDays[i].Date < resData.Data.RecentThreeDays[j].Date
|
||||
})
|
||||
sort.Slice(resData.Data.RecentOneMonth, func(i, j int) bool {
|
||||
return resData.Data.RecentOneMonth[i].Date < resData.Data.RecentOneMonth[j].Date
|
||||
})
|
||||
jsonByte, err := json.Marshal(resData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
channel <- entitys.Response{
|
||||
Index: z.Name(),
|
||||
Content: res.Text,
|
||||
Content: string(jsonByte),
|
||||
Type: entitys.ResponseJson,
|
||||
}
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue