-
Notifications
You must be signed in to change notification settings - Fork 13
/
conversion.go
73 lines (63 loc) · 2.3 KB
/
conversion.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package tools
import (
"China_Telecom_Monitor/models"
"github.com/golang-module/carbon/v2"
"strconv"
"strings"
)
func ToSummary(qryImportantData *models.Result[models.ImportantData], username string, time carbon.Carbon) models.Summary {
var ds models.Summary
if qryImportantData == nil || qryImportantData.HeaderInfos.Code != "0000" || qryImportantData.ResponseData.ResultCode != "0000" {
return ds
}
data := qryImportantData.ResponseData.Data
useFlow, _ := strconv.ParseInt(data.FlowInfo.TotalAmount.Used, 10, 64)
balanceFlow, _ := strconv.ParseInt(data.FlowInfo.TotalAmount.Balance, 10, 64)
totalFlow := useFlow + balanceFlow
generalUse, _ := strconv.ParseInt(data.FlowInfo.TotalAmount.Used, 10, 64)
generalBalance, _ := strconv.ParseInt(data.FlowInfo.TotalAmount.Balance, 10, 64)
generalTotal := generalUse + generalBalance
specialUse, _ := strconv.ParseInt(data.FlowInfo.SpecialAmount.Used, 10, 64)
specialBalance, _ := strconv.ParseInt(data.FlowInfo.SpecialAmount.Balance, 10, 64)
specialTotal := specialUse + specialBalance
voiceUsage, _ := strconv.ParseInt(data.VoiceInfo.VoiceDataInfo.Used, 10, 64)
voiceAmount, _ := strconv.ParseInt(data.VoiceInfo.VoiceDataInfo.Total, 10, 64)
balanceFloat, _ := strconv.ParseFloat(data.BalanceInfo.IndexBalanceDataInfo.Balance, 64)
balance := int64(balanceFloat * 100)
var items []models.SummaryItems
flowLists := data.FlowInfo.FlowList
if flowLists != nil && len(flowLists) > 0 {
items = make([]models.SummaryItems, len(flowLists))
for i, flowList := range flowLists {
if !strings.Contains(flowList.Title, "流量") {
continue
}
var use, balanceF int64
if strings.Contains(flowList.LeftTitle, "已用") {
use, _ = ToInt64(flowList.LeftTitleHh)
}
if strings.Contains(flowList.RightTitle, "剩余") {
balanceF, _ = ToInt64(flowList.RightTitleHh)
}
items[i] = models.SummaryItems{
Name: flowList.Title,
Use: use,
Total: use + balanceF,
}
}
}
return models.Summary{
Username: username,
Use: useFlow,
Total: totalFlow,
Balance: balance,
VoiceUsage: voiceUsage,
VoiceAmount: voiceAmount,
GeneralUse: generalUse,
GeneralTotal: generalTotal,
SpecialUse: specialUse,
SpecialTotal: specialTotal,
CreateTime: carbon.DateTime{Carbon: time},
Items: items,
}
}