添加打印机api补全
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"net"
|
||||
"os"
|
||||
"regexp"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -27,6 +28,19 @@ type PrintInfo struct {
|
||||
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) {
|
||||
var (
|
||||
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))
|
||||
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{
|
||||
AppID: appID,
|
||||
PrintNo: v.PrintNo,
|
||||
|
||||
Reference in New Issue
Block a user