添加打印机api补全

This commit is contained in:
suyl
2021-07-13 14:57:55 +08:00
parent 49e72ab6bf
commit 3ab96bce79

View File

@@ -9,6 +9,7 @@ import (
"git.rosy.net.cn/jx-callback/business/model/dao" "git.rosy.net.cn/jx-callback/business/model/dao"
"net" "net"
"os" "os"
"regexp"
"time" "time"
) )
@@ -27,6 +28,19 @@ type PrintInfo struct {
AppID int AppID int
} }
var (
regexpMobile = regexp.MustCompile("^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\\d{8}$")
soundMap = map[string]string{
"sounda": "sounda",
"soundb": "soundb",
"soundc": "soundc",
"soundd": "soundd",
"sounde": "sounde",
"soundf": "soundf",
"soundg": "soundg",
}
)
func AddPrinter(appID int, printers []*model.Printer) (err error) { func AddPrinter(appID int, printers []*model.Printer) (err error) {
var ( var (
db = dao.GetDB() db = dao.GetDB()
@@ -40,6 +54,25 @@ func AddPrinter(appID int, printers []*model.Printer) (err error) {
errs = append(errs, fmt.Errorf("此应用已经绑定了该打印机print_no : %v ", v.PrintNo)) errs = append(errs, fmt.Errorf("此应用已经绑定了该打印机print_no : %v ", v.PrintNo))
continue continue
} }
//验证手机号
if v.SIM != "" {
if regexpMobile.FindString(v.SIM) == "" {
errs = append(errs, fmt.Errorf("请输入正确的sim卡号码print_no : %v ", v.PrintNo))
continue
}
}
if v.Volume != 0 {
if v.Volume < 0 || v.Volume > 5 {
errs = append(errs, fmt.Errorf("请输入正确的音量print_no : %v ", v.PrintNo))
continue
}
}
if v.Sound != "" {
if soundMap[v.Sound] == "" {
errs = append(errs, fmt.Errorf("请输入正确的提示音print_no : %v ", v.PrintNo))
continue
}
}
printer := &model.Printer{ printer := &model.Printer{
AppID: appID, AppID: appID,
PrintNo: v.PrintNo, PrintNo: v.PrintNo,