Files
jx-print/services/print.go
2021-07-08 14:53:20 +08:00

56 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package services
import (
"fmt"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-print/dao"
"git.rosy.net.cn/jx-print/globals"
"git.rosy.net.cn/jx-print/model"
putils "git.rosy.net.cn/jx-print/utils"
"github.com/gin-gonic/gin"
"time"
)
func AddPrinters(c *gin.Context, userID string, appID int, printInfos []*model.PrintInfo) (err error) {
var (
db = globals.GetDB()
errs []error
now = time.Now()
)
if len(printInfos) > 50 {
return fmt.Errorf("每次最多添加50台")
}
if apps, _ := dao.GetApps(db, appID, userID, ""); len(apps) == 0 {
return fmt.Errorf("未查询到此应用app_id:%d", appID)
}
for _, v := range printInfos {
printers, _ := dao.GetPrinters(db, appID, v.PrintNo)
if len(printers) > 0 {
errs = append(errs, fmt.Errorf("此打印机已被其他应用绑定print_no :%s 。", v.PrintNo))
continue
}
printer := &model.Printer{
CreatedAt: &now,
UpdatedAt: &now,
DeletedAt: &utils.DefaultTimeValue,
AppID: appID,
PrintNo: v.PrintNo,
Name: v.Name,
SIM: v.SIM,
Status: model.PrinterStatusNormal,
IsOnline: model.PrinterOffline,
}
if err = dao.Insert(db, printer); err != nil {
errs = append(errs, err)
}
}
if len(errs) > 0 {
err = putils.BuildErr(errs)
}
return err
}
func GetPrinters(c *gin.Context, appID int, printNo, name string, status, isOnline, offset, pageSize int) (page *model.PagedInfo, err error) {
return dao.GetPrintersPage(globals.GetDB(), appID, printNo, name, status, isOnline, offset, pageSize)
}