1
This commit is contained in:
19
business/dao/print_activation.go
Normal file
19
business/dao/print_activation.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package dao
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CheckHeard(printNo string) (bool, error) {
|
||||||
|
var data *model.PrintActivation
|
||||||
|
err := GetRow(GetDB(), &data, `SELECT * FROM printer_activation WHERE print_no = ?`, []interface{}{printNo}...)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if data == nil {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
@@ -15,7 +15,7 @@ func QueryPrintBindStore(printNo string) ([]*model.PrintBindStore, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BindStoreList 绑定门店信息
|
// BindStoreList 绑定门店信息
|
||||||
func BindStoreList(req *model.AddPrinterParam) error {
|
func BindStoreList(req *model.AddPrinterParam, userId string) error {
|
||||||
param := &model.PrintBindStore{
|
param := &model.PrintBindStore{
|
||||||
CreatedAt: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
UpdatedAt: time.Now(),
|
UpdatedAt: time.Now(),
|
||||||
@@ -23,9 +23,13 @@ func BindStoreList(req *model.AddPrinterParam) error {
|
|||||||
StoreName: req.Name,
|
StoreName: req.Name,
|
||||||
StoreVendor: 9, // 绑定平台,全平台
|
StoreVendor: 9, // 绑定平台,全平台
|
||||||
PrintNo: req.PrintNo,
|
PrintNo: req.PrintNo,
|
||||||
UserId: "system", // 所属用户
|
|
||||||
StoreStatus: 1, // 门店开启
|
StoreStatus: 1, // 门店开启
|
||||||
BindStatus: 1, // 绑定状态
|
BindStatus: 1, // 绑定状态
|
||||||
}
|
}
|
||||||
|
if userId != "" {
|
||||||
|
param.UserId = userId
|
||||||
|
} else {
|
||||||
|
param.UserId = "system"
|
||||||
|
}
|
||||||
return CreateEntity(GetDB(), param)
|
return CreateEntity(GetDB(), param)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,13 +62,15 @@ func AddPrinter(appID int, printers []*model.AddPrinterParam) (err error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
have := false
|
have := false
|
||||||
|
userId := ""
|
||||||
for _, bsl := range bindStoreList {
|
for _, bsl := range bindStoreList {
|
||||||
if bsl.StoreID == v.StoreId {
|
if bsl.StoreID == v.StoreId {
|
||||||
have = true
|
have = true
|
||||||
|
userId = bsl.UserId
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !have {
|
if !have {
|
||||||
if err := dao.BindStoreList(printers[0]); err != nil {
|
if err := dao.BindStoreList(printers[0], userId); err != nil {
|
||||||
errs = append(errs, fmt.Errorf("BindStoreList err : %v ", err))
|
errs = append(errs, fmt.Errorf("BindStoreList err : %v ", err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -81,6 +83,16 @@ func AddPrinter(appID int, printers []*model.AddPrinterParam) (err error) {
|
|||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// 检查心跳
|
||||||
|
exits, err := dao.CheckHeard(v.PrintNo)
|
||||||
|
if err != nil {
|
||||||
|
errs = append(errs, fmt.Errorf("CheckHeard err : %v ", err))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !exits {
|
||||||
|
errs = append(errs, fmt.Errorf("打印机未激活,请激活后在绑定"))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
printer := &model.Printer{
|
printer := &model.Printer{
|
||||||
AppID: appID,
|
AppID: appID,
|
||||||
@@ -159,7 +171,7 @@ func InitPrint(printer *model.Printer, printParam *model.AddPrinterParam) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 初始化绑定信息
|
// 初始化绑定信息
|
||||||
if err := dao.BindStoreList(printParam); err != nil {
|
if err := dao.BindStoreList(printParam, ""); err != nil {
|
||||||
txDb.Rollback()
|
txDb.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user