flow
This commit is contained in:
52
business/jxstore/cms/sim.go
Normal file
52
business/jxstore/cms/sim.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package cms
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"time"
|
||||
)
|
||||
|
||||
//每日流量卡流量结算
|
||||
func SimFlowDaySettle(ctx *jxcontext.Context) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
//找出所有状态不为 超流量的打印机(iccid卡)
|
||||
printers, _ := dao.GetPrinters(db, 0, "", 0, model.PrinterStatusNoFlow)
|
||||
for _, v := range printers {
|
||||
//查询前一日使用的流量数
|
||||
if v.IccID != "" {
|
||||
if getCardInfoResult, err := api.TibiotAPI.IotData(v.IccID, utils.Time2Str(utils.Time2Date(time.Now().AddDate(0, 0, -1)))); err == nil {
|
||||
//表示还没有同步前一天的流量,只能自己算了
|
||||
if getCardInfoResult == nil || getCardInfoResult.SyncStatus == "1" || getCardInfoResult.CardFlow == "0KB" { //未同步
|
||||
//先查当月用的总的, 减去当月已经用的总的,就是昨天用的
|
||||
if getCardInfoResultMonth, err2 := api.TibiotAPI.IotDataMonth(v.IccID); err2 == nil {
|
||||
//表示当月用的总的也还没同步。只有去查卡信息中的总流量使用,减去所有总使用,就是昨天用的。。先不写
|
||||
if getCardInfoResultMonth == nil || getCardInfoResultMonth.CardFlow == "" {
|
||||
//api.TibiotAPI.BatchQueryCardInfo(1)
|
||||
} else if getCardInfoResultMonth.CardFlow != "" {
|
||||
|
||||
}
|
||||
}
|
||||
} else if getCardInfoResult.CardFlow != "" {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//每月流量卡流量结算
|
||||
func SimFlowMonthSettle(ctx *jxcontext.Context) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
//..每月1号结算上月
|
||||
if time.Now().Day() != 1 {
|
||||
return
|
||||
}
|
||||
dao.GetSimFlowExpend(db, "", utils.ZeroTimeValue, utils.ZeroTimeValue)
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package misc
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
@@ -9,7 +11,12 @@ import (
|
||||
)
|
||||
|
||||
func Init() {
|
||||
|
||||
ScheduleTimerFunc("SimFlowDaySettle", func() {
|
||||
cms.SimFlowDaySettle(jxcontext.AdminCtx)
|
||||
cms.SimFlowMonthSettle(jxcontext.AdminCtx)
|
||||
}, []string{
|
||||
"00:05:00",
|
||||
})
|
||||
}
|
||||
|
||||
// 按时间序列循环
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
)
|
||||
|
||||
func GetPrinters(db *DaoDB, appID int, printNo string) (printers []*model.Printer, err error) {
|
||||
func GetPrinters(db *DaoDB, appID int, printNo string, status, statusNeq int) (printers []*model.Printer, err error) {
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM printer
|
||||
@@ -22,6 +22,14 @@ func GetPrinters(db *DaoDB, appID int, printNo string) (printers []*model.Printe
|
||||
sql += " AND print_no = ?"
|
||||
sqlParams = append(sqlParams, printNo)
|
||||
}
|
||||
if status != 0 {
|
||||
sql += " AND status = ?"
|
||||
sqlParams = append(sqlParams, status)
|
||||
}
|
||||
if statusNeq != 0 {
|
||||
sql += " AND status <> ?"
|
||||
sqlParams = append(sqlParams, statusNeq)
|
||||
}
|
||||
err = GetRows(db, &printers, sql, sqlParams)
|
||||
return printers, err
|
||||
}
|
||||
|
||||
16
business/model/dao/dao_sim.go
Normal file
16
business/model/dao/dao_sim.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetSimFlowExpend(db *DaoDB, iccid string, createdAtBegin, createdAtEnd time.Time) (simFlowExpnd []*model.SimFlowExpend, err error) {
|
||||
|
||||
return simFlowExpnd, err
|
||||
}
|
||||
|
||||
func GetSimFlowExpendSum(db *DaoDB, iccid string, createdAtBegin, createdAtEnd time.Time) (simFlowExpnd []*model.SimFlowExpend, err error) {
|
||||
|
||||
return simFlowExpnd, err
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
package model
|
||||
|
||||
const (
|
||||
PrinterStatusOnlineWithoutPaper = 2 //在线正常缺纸
|
||||
PrinterStatusOnlineWithoutPaper = 2 //在线缺纸
|
||||
PrinterStatusOnline = 1 //在线正常
|
||||
PrinterStatusOffline = -1 //离线
|
||||
PrinterStatusNoFlow = -2 //当月流量超30m了
|
||||
|
||||
PrintMsgAlreadySend = 2 //已经发出打印消息
|
||||
PrintMsgSuccess = 1 //打印成功
|
||||
@@ -54,9 +55,9 @@ func (v *PrintMsg) TableIndex() [][]string {
|
||||
type SimFlowExpend struct {
|
||||
ModelIDCUL
|
||||
|
||||
IccID string `orm:"column(icc_id)" json:"iccID"` //sim卡iccid
|
||||
Flow int `json:"flow"` //流量数
|
||||
FlowUnit string `json:"flowUnit"` //流量单位
|
||||
IccID string `orm:"column(icc_id)" json:"iccID"` //sim卡iccid
|
||||
Flow float64 `json:"flow"` //流量数
|
||||
FlowUnit string `json:"flowUnit"` //流量单位
|
||||
}
|
||||
|
||||
func (v *SimFlowExpend) TableIndex() [][]string {
|
||||
@@ -69,9 +70,9 @@ func (v *SimFlowExpend) TableIndex() [][]string {
|
||||
type SimFlowIncome struct {
|
||||
ModelIDCUL
|
||||
|
||||
IccID string `orm:"column(icc_id)" json:"iccID"` //sim卡iccid
|
||||
Flow int `json:"flow"` //流量数
|
||||
FlowUnit string `json:"flowUnit"` //流量单位
|
||||
IccID string `orm:"column(icc_id)" json:"iccID"` //sim卡iccid
|
||||
Flow float64 `json:"flow"` //流量数
|
||||
FlowUnit string `json:"flowUnit"` //流量单位
|
||||
}
|
||||
|
||||
func (v *SimFlowIncome) TableIndex() [][]string {
|
||||
|
||||
@@ -17,4 +17,7 @@ addEvent = true
|
||||
aliKey = "LTAI4FwZN7pp4dACQHoapkZQ"
|
||||
aliSecret = "NTegceUFX0FdfMovqCDzqcIKmhcoOu"
|
||||
|
||||
tibiotUserName = "ruoxikeji"
|
||||
tibiotPassword = "Ruoxi@369"
|
||||
|
||||
dbConnectStr = "root:WebServer@1@tcp(127.0.0.1:3306)/api?charset=utf8mb4&loc=Local&parseTime=true"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/tibiotapi"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/cache"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/cache/redis"
|
||||
aliyunsmsclient "github.com/KenmyZhang/aliyun-communicate"
|
||||
@@ -11,6 +12,8 @@ import (
|
||||
var (
|
||||
SMSClient *aliyunsmsclient.SmsClient
|
||||
Cacher cache.ICacher
|
||||
|
||||
TibiotAPI *tibiotapi.API
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -19,6 +22,7 @@ func init() {
|
||||
|
||||
// 这样写的原因是在测试时,可以重新读取配置文件
|
||||
func Init() {
|
||||
TibiotAPI = tibiotapi.New(web.AppConfig.DefaultString("tibiotUserName", ""), web.AppConfig.DefaultString("tibiotPassword", ""))
|
||||
SMSClient = aliyunsmsclient.New("http://dysmsapi.aliyuncs.com/")
|
||||
Cacher = redis.New(web.AppConfig.DefaultString("redisHost", "localhost"), beego.AppConfig.DefaultInt("redisPort", 0), beego.AppConfig.DefaultString("redisPassword", ""))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user