添加打印机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()
|
||||
@@ -37,9 +51,28 @@ func AddPrinter(appID int, printers []*model.Printer) (err error) {
|
||||
}
|
||||
for _, v := range printers {
|
||||
if printers2, _ := dao.GetPrinters(db, appID, v.PrintNo); len(printers2) > 0 {
|
||||
errs = append(errs, fmt.Errorf("此应用已经绑定了该打印机!print_no : %v", v.PrintNo))
|
||||
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,
|
||||
@@ -70,7 +103,7 @@ func DelPrinter(appID int, printNos []string) (err error) {
|
||||
)
|
||||
for _, v := range printNos {
|
||||
if printers, _ := dao.GetPrinters(db, appID, v); len(printers) == 0 {
|
||||
errs = append(errs, fmt.Errorf("该应用下未找到该打印机!print_no : %v", v))
|
||||
errs = append(errs, fmt.Errorf("该应用下未找到该打印机!print_no : %v ", v))
|
||||
continue
|
||||
} else {
|
||||
printers[0].DeletedAt = time.Now()
|
||||
|
||||
Reference in New Issue
Block a user