This commit is contained in:
suyl
2021-07-20 17:21:38 +08:00
parent 0fd6aa4207
commit d750bfe18d
10 changed files with 374 additions and 16 deletions

View File

@@ -7,7 +7,7 @@ import (
"time"
)
func GetPrinters(db *sqlx.DB, appID int, printNo string) (printers []*model.Printer, err error) {
func GetPrinters(db *sqlx.DB, appID int, printNo string, status int, statusNeq int) (printers []*model.Printer, err error) {
sql := `
SELECT *
FROM printer
@@ -22,6 +22,14 @@ func GetPrinters(db *sqlx.DB, appID int, printNo string) (printers []*model.Prin
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)
}
if err = db.Select(&printers, sql, sqlParams...); err == nil {
return printers, err
}

81
dao/sim_dao.go Normal file
View File

@@ -0,0 +1,81 @@
package dao
import (
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-print/model"
"github.com/jmoiron/sqlx"
"time"
)
func GetSimFlowExpend(db *sqlx.DB, iccid string, createdAtBegin, createdAtEnd time.Time) (simFlowExpnd []*model.SimFlowExpend, err error) {
return simFlowExpnd, err
}
func GetSimFlowExpendSum(db *sqlx.DB, iccid string, createdAtBegin, createdAtEnd time.Time) (simFlowExpnd *model.SimFlowExpend, err error) {
var (
simFlowExpnds []*model.SimFlowExpend
)
sql := `
SELECT SUM(
IF(flow_unit = 'KB', flow,
IF(flow_unit = 'MB', ROUND(flow * 1024)),
IF(flow_unit = "GB", ROUND(flow * 1024 * 1024), 0)
)
) flow, 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"
if err = db.Select(&simFlowExpnds, sql, sqlParams); err == nil && len(simFlowExpnds) > 0 {
return simFlowExpnds[0], err
}
return simFlowExpnd, err
}
func GetSimFlowIncomeSum(db *sqlx.DB, iccid string, createdAtBegin, createdAtEnd time.Time) (simFlowIncome *model.SimFlowIncome, err error) {
var (
simFlowIncomes []*model.SimFlowIncome
)
sql := `
SELECT SUM(
IF(flow_unit = 'KB', flow,
IF(flow_unit = 'MB', ROUND(flow * 1024)),
IF(flow_unit = "GB", ROUND(flow * 1024 * 1024), 0)
)
) flow, icc_id, 'KB' flow_unit
FROM sim_flow_income
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"
if err = db.Select(&simFlowIncomes, sql, sqlParams); err == nil && len(simFlowIncomes) > 0 {
return simFlowIncomes[0], err
}
return simFlowIncome, err
}