Files
jx-print/services/print_server/app_server/print_bind_store.go
邹宗楠 66db5867a4 1
2022-08-25 16:10:01 +08:00

92 lines
2.4 KiB
Go

package app_server
import (
"fmt"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-print/dao"
storeModel "git.rosy.net.cn/jx-print/model/app_model"
"io/ioutil"
"net/http"
"time"
)
type PrintBindStore struct {
}
var PrintBindStoreServer = new(PrintBindStore)
// AddStoreBind 添加打印机门店绑定
func (p *PrintBindStore) AddStoreBind(userId string, store *storeModel.AddBindStore) error {
// 查询打印机绑定门店数量
count, err := dao.QueryBindNumber(userId, store.PrintNo)
if err != nil {
return err
}
if count >= 5 {
return fmt.Errorf("同一打印机最多可绑定五个门店")
}
// 查询打印机是否属于用户
have, _, err := dao.GetPrintById(userId, store.PrintNo)
if err != nil {
return err
}
if !have {
return fmt.Errorf("打印机未绑定在用户下")
}
param := &storeModel.PrintBindStore{
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
StoreID: store.StoreID,
StoreName: store.StoreName,
StoreVendor: store.StoreVendor,
PrintNo: store.PrintNo,
StoreStatus: store.StoreStatus,
UserId: userId,
BindStatus: storeModel.StoreBindPrintSuccess,
}
return dao.CreatePrintStoreBind(param)
}
// QueryStoreAndUser 查询门店/打印机/用户之间的关联关系
func (p *PrintBindStore) QueryStoreAndUser(param *storeModel.RelieveStore) (bool, error) {
return dao.QueryStoreAndUserManager(param.UserId, param.PrintNo, param.StoreID)
}
// RelievePrintBindStore 解除门店和打印机的绑定关系
func (p *PrintBindStore) RelievePrintBindStore(param *storeModel.RelieveStore) error {
if err := dao.RelieveToken(param.UserId, param.PrintNo, param.StoreID); err != nil {
return err
}
return nil
}
// LoseAuthorize 失去授权回调
func (p *PrintBindStore) LoseAuthorize(storeId int64) error {
return dao.UpdateStoreAuthorize(storeId)
}
// AnalysisStore 解析门店授权
func (p *PrintBindStore) AnalysisStore(request *http.Request) (string, error) {
data, err := ioutil.ReadAll(request.Body)
if err != nil {
return "", err
}
fmt.Println(string(data))
values, err := utils.HTTPBody2Values(data, false)
if err != nil {
return "", err
}
mapData := utils.URLValues2Map(values)
callParam := &call{}
if err := utils.Map2StructByJson(mapData, &callParam, false); err != nil {
return "", err
}
return callParam.StoreId, err
}
type call struct {
StoreId string `json:"storeId" form:"storeId"`
}