chore: 并入 iotlcm-upstream-chan 历史到 upstream-chan/(原提交 1e74497)
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package upstreamapi
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
historicalMonthLayout = "200601"
|
||||
historicalDailyLayout = "20060102"
|
||||
historicalMonthFormatError = "queryDate格式错误,应为yyyyMM"
|
||||
historicalMonthRangeError = "月流量仅支持查询已结束月份;本月累计流量请调用 /sim/query/sim-datausage"
|
||||
historicalDailyFormatError = "queryDate格式错误,应为yyyyMMdd"
|
||||
historicalDailyRangeError = "日流量仅支持查询已结束日期,不支持当天或未来日期"
|
||||
)
|
||||
|
||||
var historicalPeriodLocation = time.FixedZone("UTC+8", 8*60*60)
|
||||
|
||||
const currentBatchMonthRangeError = "电信月批量接口仅支持当月;历史月份请调用 /sim/query/sim-datausage-monthly"
|
||||
|
||||
func validateCurrentBatchMonth(queryDate string, now time.Time) string {
|
||||
queryDate = strings.TrimSpace(queryDate)
|
||||
if _, err := time.ParseInLocation(historicalMonthLayout, queryDate, historicalPeriodLocation); err != nil {
|
||||
return historicalMonthFormatError
|
||||
}
|
||||
if queryDate != now.In(historicalPeriodLocation).Format(historicalMonthLayout) {
|
||||
return currentBatchMonthRangeError
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func validateHistoricalMonth(queryDate string, now time.Time) string {
|
||||
queryDate = strings.TrimSpace(queryDate)
|
||||
if len(queryDate) != len(historicalMonthLayout) {
|
||||
return historicalMonthFormatError
|
||||
}
|
||||
if _, err := time.ParseInLocation(historicalMonthLayout, queryDate, historicalPeriodLocation); err != nil {
|
||||
return historicalMonthFormatError
|
||||
}
|
||||
if queryDate >= now.In(historicalPeriodLocation).Format(historicalMonthLayout) {
|
||||
return historicalMonthRangeError
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func validateHistoricalDay(queryDate string, now time.Time) string {
|
||||
queryDate = strings.TrimSpace(queryDate)
|
||||
if len(queryDate) != len(historicalDailyLayout) {
|
||||
return historicalDailyFormatError
|
||||
}
|
||||
if _, err := time.ParseInLocation(historicalDailyLayout, queryDate, historicalPeriodLocation); err != nil {
|
||||
return historicalDailyFormatError
|
||||
}
|
||||
if queryDate >= now.In(historicalPeriodLocation).Format(historicalDailyLayout) {
|
||||
return historicalDailyRangeError
|
||||
}
|
||||
return ""
|
||||
}
|
||||
Reference in New Issue
Block a user