This commit is contained in:
邹宗楠
2022-07-29 11:56:29 +08:00
parent 940fc2cfe6
commit 01b70c1f0a

View File

@@ -45,49 +45,50 @@ func GetPrinters(db *sqlx.DB, appID int, printNo string, status, statusNeq, flow
func GetPrintersPage(db *sqlx.DB, appID int, printNo, name string, status, isOnline, offset, pageSize int, userId string) (page *model.PagedInfo, err error) {
fmt.Println("print======================================")
globals.SugarLogger.Debug("print=============", "========")
sqlCount := `SELECT COUNT(id) count `
sql := `SELECT * `
sqlOther := ` FROM printer WHERE 1 = 1 AND deleted_at = ?`
sqlParams := []interface{}{utils.DefaultTimeValue}
if appID != 0 {
sqlOther += " AND app_id = ?"
sqlParams = append(sqlParams, appID)
}
if printNo != "" {
sqlOther += " AND print_no = ?"
sqlParams = append(sqlParams, printNo)
}
if name != "" {
sqlOther += " AND name LIKE ?"
sqlParams = append(sqlParams, "%"+name+"%")
}
if status != model.StatusAll {
sqlOther += " AND status = ?"
sqlParams = append(sqlParams, status)
}
if isOnline != model.StatusAll {
sqlOther += " AND is_online = ?"
sqlParams = append(sqlParams, isOnline)
}
if userId != "" {
sqlOther += " AND user_id = ?"
sqlParams = append(sqlParams, userId)
}
//查总数
count := 0
row := db.DB.QueryRow(sqlCount+sqlOther, sqlParams...)
if err = row.Scan(&count); err != nil {
return page, err
}
sqlOther += " LIMIT ? OFFSET ?"
sqlParams = append(sqlParams, pageSize, offset)
var printers []model.Printer
if err = db.Select(&printers, sql+sqlOther, sqlParams...); err != nil {
return nil, err
}
return &model.PagedInfo{TotalCount: count, Data: printers}, err
//sqlCount := `SELECT COUNT(id) count `
//sql := `SELECT * `
//sqlOther := ` FROM printer WHERE 1 = 1 AND deleted_at = ?`
//sqlParams := []interface{}{utils.DefaultTimeValue}
//if appID != 0 {
// sqlOther += " AND app_id = ?"
// sqlParams = append(sqlParams, appID)
//}
//if printNo != "" {
// sqlOther += " AND print_no = ?"
// sqlParams = append(sqlParams, printNo)
//}
//if name != "" {
// sqlOther += " AND name LIKE ?"
// sqlParams = append(sqlParams, "%"+name+"%")
//}
//if status != model.StatusAll {
// sqlOther += " AND status = ?"
// sqlParams = append(sqlParams, status)
//}
//if isOnline != model.StatusAll {
// sqlOther += " AND is_online = ?"
// sqlParams = append(sqlParams, isOnline)
//}
//if userId != "" {
// sqlOther += " AND user_id = ?"
// sqlParams = append(sqlParams, userId)
//}
////查总数
//count := 0
//row := db.DB.QueryRow(sqlCount+sqlOther, sqlParams...)
//if err = row.Scan(&count); err != nil {
// return page, err
//}
//sqlOther += " LIMIT ? OFFSET ?"
//sqlParams = append(sqlParams, pageSize, offset)
//
//var printers []model.Printer
//if err = db.Select(&printers, sql+sqlOther, sqlParams...); err != nil {
// return nil, err
//}
//
//return &model.PagedInfo{TotalCount: count, Data: printers}, err
return nil, err
}
func GetPrintMessagesPage(db *sqlx.DB, printNo, msgID, beginAt, endAt string, offset, pageSize int) (page *model.PagedInfo, err error) {