209 lines
6.3 KiB
Go
209 lines
6.3 KiB
Go
package app
|
|
|
|
import (
|
|
"git.rosy.net.cn/jx-print/controllers"
|
|
"git.rosy.net.cn/jx-print/model"
|
|
print "git.rosy.net.cn/jx-print/model/app_model"
|
|
"git.rosy.net.cn/jx-print/putils"
|
|
printServer "git.rosy.net.cn/jx-print/services/print_server/app_server"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type Print struct{}
|
|
|
|
var PrintController = new(Print)
|
|
|
|
// AddPrinters 添加打印机 POST
|
|
// @Title 添加打印机
|
|
// @Description 添加打印机
|
|
// @Param token cookie string true "用户登录token"
|
|
// @Param data body app_model.AddPrintReq true "请求参数"
|
|
// @Success 200 {object} controllers.CallResult
|
|
// @Failure 200 {object} controllers.CallResult
|
|
// @router /addPrinters [post]
|
|
func (p *Print) AddPrinters(c *gin.Context) {
|
|
var (
|
|
err error
|
|
tokenInfo *model.TokenInfo
|
|
param = print.AddPrintReq{}
|
|
printInfo []*model.PrintInfo
|
|
)
|
|
|
|
if err = c.ShouldBind(¶m); err != nil {
|
|
controllers.BuildErrJson(c, err)
|
|
return
|
|
}
|
|
if tokenInfo = controllers.CheckToken(c); tokenInfo == nil {
|
|
return
|
|
}
|
|
if err = putils.UnmarshalUseNumber([]byte(param.Prints), &printInfo); err != nil {
|
|
controllers.BuildErrJson(c, err)
|
|
return
|
|
}
|
|
|
|
controllers.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
|
err = printServer.AddPrinters(tokenInfo, param.AppID, printInfo)
|
|
return retVal, "", err
|
|
})
|
|
|
|
}
|
|
|
|
// GetPrinters 查询打印机 GET
|
|
// @Title 查询打印机
|
|
// @Description 查询打印机
|
|
// @Param token cookie string true "用户登录token"
|
|
// @Param data body app_model.QueryPrintReq true "请求参数"
|
|
// @Success 200 {object} controllers.CallResult
|
|
// @Failure 200 {object} controllers.CallResult
|
|
// @router /getPrinters [get]
|
|
func (p *Print) GetPrinters(c *gin.Context) {
|
|
var (
|
|
err error
|
|
tokenInfo *model.TokenInfo
|
|
param = print.QueryPrintReq{}
|
|
)
|
|
if err = c.ShouldBind(¶m); err != nil {
|
|
controllers.BuildErrJson(c, err)
|
|
return
|
|
}
|
|
if tokenInfo = controllers.CheckToken(c); tokenInfo == nil {
|
|
return
|
|
}
|
|
|
|
controllers.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
|
retVal, err = printServer.GetPrinters(param.AppID, param.PrintNo, param.Name, param.Status, param.IsOnline, param.Offset, param.PageSize, tokenInfo.User.UserID)
|
|
return retVal, "", err
|
|
})
|
|
}
|
|
|
|
// DelPrinters 删除打印机 POST
|
|
// @Title 删除打印机
|
|
// @Description 删除打印机
|
|
// @Param token cookie string true "用户登录token"
|
|
// @Param data body app_model.QueryPrintReq true "请求参数"
|
|
// @Success 200 {object} controllers.CallResult
|
|
// @Failure 200 {object} controllers.CallResult
|
|
// @router /delPrinters [post]
|
|
func (p *Print) DelPrinters(c *gin.Context) {
|
|
var (
|
|
err error
|
|
tokenInfo *model.TokenInfo
|
|
param = print.DeletePrintReq{}
|
|
printNos []string
|
|
)
|
|
if err = c.ShouldBind(¶m); err != nil {
|
|
controllers.BuildErrJson(c, err)
|
|
return
|
|
}
|
|
if tokenInfo = controllers.CheckToken(c); tokenInfo == nil {
|
|
return
|
|
}
|
|
if err = putils.UnmarshalUseNumber([]byte(param.PrintNos), &printNos); err != nil {
|
|
controllers.BuildErrJson(c, err)
|
|
return
|
|
}
|
|
controllers.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
|
err = printServer.DelPrinters(param.AppID, tokenInfo, printNos)
|
|
return retVal, "", err
|
|
})
|
|
}
|
|
|
|
// UpdatePrinter 更新打印机 POST
|
|
// @Title 查询打印机
|
|
// @Description 查询打印机
|
|
// @Param token cookie string true "用户登录token"
|
|
// @Param data body app_model.UpdatePrintReq true "请求参数"
|
|
// @Success 200 {object} controllers.CallResult
|
|
// @Failure 200 {object} controllers.CallResult
|
|
// @router /updatePrinter [post]
|
|
func (p *Print) UpdatePrinter(c *gin.Context) {
|
|
var (
|
|
err error
|
|
tokenInfo *model.TokenInfo
|
|
param = print.UpdatePrintReq{}
|
|
)
|
|
if err = c.ShouldBind(¶m); err != nil {
|
|
controllers.BuildErrJson(c, err)
|
|
return
|
|
}
|
|
if tokenInfo = controllers.CheckToken(c); tokenInfo == nil {
|
|
return
|
|
}
|
|
if !controllers.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
|
err = printServer.UpdatePrinter(param.AppID, tokenInfo, param.PrintNo, param.Name, param.Sound, param.Volume)
|
|
return retVal, "", err
|
|
}) {
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// TestPrint 测试打印 POST
|
|
// @Title 测试打印
|
|
// @Description 测试打印
|
|
// @Param token cookie string true "用户登录token"
|
|
// @Param data body app_model.UpdatePrintReq true "请求参数"
|
|
// @Success 200 {object} controllers.CallResult
|
|
// @Failure 200 {object} controllers.CallResult
|
|
// @router /testPrinter [post]
|
|
func (p *Print) TestPrint(c *gin.Context) {
|
|
var (
|
|
err error
|
|
tokenInfo *model.TokenInfo
|
|
param = print.TestPrintReq{}
|
|
)
|
|
if err = c.ShouldBind(¶m); err != nil {
|
|
controllers.BuildErrJson(c, err)
|
|
return
|
|
}
|
|
if tokenInfo = controllers.CheckToken(c); tokenInfo == nil {
|
|
return
|
|
}
|
|
controllers.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
|
retVal, err = printServer.TestPrint(param.AppID, tokenInfo, param.PrintNo, param.OrderNo, param.Content)
|
|
return retVal, "", err
|
|
})
|
|
}
|
|
|
|
// GetPrintMessages 获取打印机消息 POST
|
|
// @Title 获取打印机消息
|
|
// @Description 获取打印机消息
|
|
// @Param token cookie string true "用户登录token"
|
|
// @Param data body app_model.UpdatePrintReq true "请求参数"
|
|
// @Success 200 {object} controllers.CallResult
|
|
// @Failure 200 {object} controllers.CallResult
|
|
// @router /getPrintMessages [get]
|
|
func (p *Print) GetPrintMessages(c *gin.Context) {
|
|
var (
|
|
err error
|
|
tokenInfo *model.TokenInfo
|
|
param = print.GetPrintMsg{}
|
|
)
|
|
if err = c.ShouldBind(¶m); err != nil {
|
|
controllers.BuildErrJson(c, err)
|
|
return
|
|
}
|
|
if tokenInfo = controllers.CheckToken(c); tokenInfo == nil {
|
|
return
|
|
}
|
|
|
|
controllers.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
|
retVal, err = printServer.GetPrintMessages(param.AppID, tokenInfo, param.PrintNo, param.MsgID, param.BeginAt, param.EndAt, param.Offset, param.PageSize)
|
|
return retVal, "", err
|
|
})
|
|
}
|
|
|
|
// StatPrinterReport 查询打印统计(首页) GET
|
|
func (p *Print) StatPrinterReport(c *gin.Context) {
|
|
var (
|
|
tokenInfo *model.TokenInfo
|
|
)
|
|
if tokenInfo = controllers.CheckToken(c); tokenInfo == nil {
|
|
return
|
|
}
|
|
controllers.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
|
retVal, err = printServer.GetPrinterReport(tokenInfo)
|
|
return retVal, "", err
|
|
})
|
|
}
|