diff --git a/model/model.go b/model/model.go index fb36de5..299fdcf 100644 --- a/model/model.go +++ b/model/model.go @@ -54,7 +54,7 @@ type TokenInfo struct { type PrintInfo struct { PrintNo string `json:"print_no" form:"print_no" binding:"required"` //打印机编号 Name string `json:"name" form:"name"` //打印机备注 - SIM string `json:"sim" form:"sim"` //流量卡号码 + //SIM string `json:"sim" form:"sim"` //流量卡号码 } type PagedInfo struct { diff --git a/services/sim.go b/services/sim.go index e9d1093..c9278ba 100644 --- a/services/sim.go +++ b/services/sim.go @@ -59,7 +59,8 @@ func SimFlowDaySettle() (err error) { flowExpend.Flow, flowExpend.FlowUnit = putils.SplitFlowAndUnit(getCardInfoResult.CardFlow) } } - if flowExpend.Flow > 0 && flowExpend.FlowUnit != "" { + //可能有精度误差 + if flowExpend.Flow > 0.1 && flowExpend.FlowUnit != "" { err = dao.Insert(db, flowExpend) } //算是否超了一个月的流量了 diff --git a/utils/utils.go b/utils/utils.go index cc5ac24..16b54d7 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -35,10 +35,10 @@ var ( letterBytes = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" letterBytesNum = "0123456789" - flowUnitMap = map[string]string{ - "KB": "KB", - "MB": "MB", - "GB": "GB", + flowUnitMap = map[string]struct{}{ + "KB": struct{}{}, + "MB": struct{}{}, + "GB": struct{}{}, } ) @@ -216,8 +216,8 @@ func GetNextTimeFromList(now time.Time, timeList []string) (snapshotAt time.Time } func SplitFlowAndUnit(flowStr string) (flow float64, unit string) { - for _, v := range flowUnitMap { - if strings.Contains(flowStr, v) { + for k, _ := range flowUnitMap { + if strings.Contains(flowStr, k) { return utils.Str2Float64WithDefault(flowStr[:len(flowStr)-2], 0), flowStr[len(flowStr)-2:] } }