flow
This commit is contained in:
@@ -12,7 +12,9 @@ import (
|
|||||||
//每日流量卡流量结算
|
//每日流量卡流量结算
|
||||||
func SimFlowDaySettle(ctx *jxcontext.Context) {
|
func SimFlowDaySettle(ctx *jxcontext.Context) {
|
||||||
var (
|
var (
|
||||||
db = dao.GetDB()
|
db = dao.GetDB()
|
||||||
|
monthBegin = utils.Str2Time(utils.Int2Str(time.Now().Year()) + "-" + utils.Int2Str(int(time.Now().Month())) + "-01 00:00:00")
|
||||||
|
monthEnd = monthBegin.AddDate(0, 0, -1).AddDate(0, 1, 0)
|
||||||
)
|
)
|
||||||
//找出所有状态不为 超流量的打印机(iccid卡)
|
//找出所有状态不为 超流量的打印机(iccid卡)
|
||||||
printers, _ := dao.GetPrinters(db, 0, "", 0, model.PrinterStatusNoFlow)
|
printers, _ := dao.GetPrinters(db, 0, "", 0, model.PrinterStatusNoFlow)
|
||||||
@@ -25,9 +27,10 @@ func SimFlowDaySettle(ctx *jxcontext.Context) {
|
|||||||
//先查当月用的总的, 减去当月已经用的总的,就是昨天用的
|
//先查当月用的总的, 减去当月已经用的总的,就是昨天用的
|
||||||
if getCardInfoResultMonth, err2 := api.TibiotAPI.IotDataMonth(v.IccID); err2 == nil {
|
if getCardInfoResultMonth, err2 := api.TibiotAPI.IotDataMonth(v.IccID); err2 == nil {
|
||||||
//表示当月用的总的也还没同步。只有去查卡信息中的总流量使用,减去所有总使用,就是昨天用的。。先不写
|
//表示当月用的总的也还没同步。只有去查卡信息中的总流量使用,减去所有总使用,就是昨天用的。。先不写
|
||||||
if getCardInfoResultMonth == nil || getCardInfoResultMonth.CardFlow == "" {
|
if getCardInfoResultMonth == nil || getCardInfoResultMonth.CardFlow == "" || getCardInfoResultMonth.CardFlow == "0KB" {
|
||||||
//api.TibiotAPI.BatchQueryCardInfo(1)
|
//api.TibiotAPI.BatchQueryCardInfo(1)
|
||||||
} else if getCardInfoResultMonth.CardFlow != "" {
|
} else if getCardInfoResultMonth.CardFlow != "" {
|
||||||
|
sumExpend, _ := dao.GetSimFlowExpendSum(db, v.IccID, monthBegin, monthEnd)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ var (
|
|||||||
}
|
}
|
||||||
|
|
||||||
letterBytes = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
letterBytes = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
|
|
||||||
|
flowUnitMap = map[string]string{}
|
||||||
)
|
)
|
||||||
|
|
||||||
const fileExt = ".xlsx"
|
const fileExt = ".xlsx"
|
||||||
@@ -675,3 +677,7 @@ func BuildErr(errs []error) (err error) {
|
|||||||
}
|
}
|
||||||
return fmt.Errorf(errStr.String())
|
return fmt.Errorf(errStr.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SplitFlowAndUnit(flowStr string) (flow float64, unit string) {
|
||||||
|
return flow, unit
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package dao
|
package dao
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -10,7 +11,31 @@ func GetSimFlowExpend(db *DaoDB, iccid string, createdAtBegin, createdAtEnd time
|
|||||||
return simFlowExpnd, err
|
return simFlowExpnd, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSimFlowExpendSum(db *DaoDB, iccid string, createdAtBegin, createdAtEnd time.Time) (simFlowExpnd []*model.SimFlowExpend, err error) {
|
func GetSimFlowExpendSum(db *DaoDB, iccid string, createdAtBegin, createdAtEnd time.Time) (simFlowExpnd *model.SimFlowExpend, err error) {
|
||||||
|
sql := `
|
||||||
|
SELECT SUM(
|
||||||
|
IF(flow_unit = 'KB', flow,
|
||||||
|
IF(flow_unit = 'MB', ROUND(flow * 1024)),
|
||||||
|
IF(flow_unit = "GB", ROUND(flow * 1024 * 1024), 0)
|
||||||
|
)
|
||||||
|
), icc_id, 'KB' flow_unit
|
||||||
|
FROM sim_flow_expend
|
||||||
|
WHERE 1 = 1
|
||||||
|
`
|
||||||
|
sqlParams := []interface{}{}
|
||||||
|
if iccid != "" {
|
||||||
|
sql += " AND icc_id = ?"
|
||||||
|
sqlParams = append(sqlParams, iccid)
|
||||||
|
}
|
||||||
|
if !utils.IsTimeZero(createdAtBegin) {
|
||||||
|
sql += " AND created_at > ?"
|
||||||
|
sqlParams = append(sqlParams, createdAtBegin)
|
||||||
|
}
|
||||||
|
if !utils.IsTimeZero(createdAtEnd) {
|
||||||
|
sql += " AND created_at < ?"
|
||||||
|
sqlParams = append(sqlParams, createdAtEnd)
|
||||||
|
}
|
||||||
|
sql += " GROUP BY 2, 3"
|
||||||
|
err = GetRow(db, &simFlowExpnd, sql, sqlParams)
|
||||||
return simFlowExpnd, err
|
return simFlowExpnd, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user