修改打印模板
This commit is contained in:
120
controllers/app/print_temp.go
Normal file
120
controllers/app/print_temp.go
Normal file
@@ -0,0 +1,120 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-print/controllers/controller"
|
||||
"git.rosy.net.cn/jx-print/model"
|
||||
tempModel "git.rosy.net.cn/jx-print/model/app_model"
|
||||
printServer "git.rosy.net.cn/jx-print/services/print_server/app_server"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// AddOrUpdateTemp 模板添加 POST
|
||||
// @Title 模板添加
|
||||
// @Description 模板添加
|
||||
// @Param token cookie string true "用户登录token"
|
||||
// @Param data body app_model.AddTemp true "请求参数"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /addOrUpdateTemp [post]
|
||||
func (p *Print) AddOrUpdateTemp(c *gin.Context) {
|
||||
var (
|
||||
err error
|
||||
tokenInfo *model.TokenInfo
|
||||
param = tempModel.AddTemp{}
|
||||
tempServer = printServer.TempServer{}
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
param.UserId = tokenInfo.User.UserID
|
||||
|
||||
controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
err = tempServer.AddOrUpdateTemp(¶m)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteTemp 删除用户自定义模板
|
||||
// @Title 删除用户自定义模板
|
||||
// @Description 删除用户自定义模板
|
||||
// @Param token cookie string true "用户登录token"
|
||||
// @Param data body app_model.DeleteTemp true "请求参数"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /deleteTemp [delete]
|
||||
func (p *Print) DeleteTemp(c *gin.Context) {
|
||||
var (
|
||||
err error
|
||||
tokenInfo *model.TokenInfo
|
||||
param = tempModel.DeleteTemp{}
|
||||
tempServer = printServer.TempServer{}
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
err = tempServer.DeleteTemp(param.ID, tokenInfo.User.UserID)
|
||||
return "", "", err
|
||||
})
|
||||
}
|
||||
|
||||
// GetUserTempList 获取用户模板,模板不足时填充系统模板
|
||||
// @Title 获取用户模板
|
||||
// @Description 获取用户模板
|
||||
// @Param token cookie string true "用户登录token"
|
||||
// @Param data body app_model.DeleteTemp true "请求参数"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /getUserTempList [get]
|
||||
func (p *Print) GetUserTempList(c *gin.Context) {
|
||||
var (
|
||||
err error
|
||||
tokenInfo *model.TokenInfo
|
||||
param = tempModel.DeleteTemp{}
|
||||
tempServer = printServer.TempServer{}
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = tempServer.QueryTempList(tokenInfo.User.UserID)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// SwitchTemp 切换模板打印模板
|
||||
// @Title 切换模板
|
||||
// @Description 切换模板
|
||||
// @Param token cookie string true "用户登录token"
|
||||
// @Param data body app_model.DeleteTemp true "请求参数"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /switchTemp [get]
|
||||
func (p *Print) SwitchTemp(c *gin.Context) {
|
||||
var (
|
||||
err error
|
||||
tokenInfo *model.TokenInfo
|
||||
param = tempModel.DeleteTemp{}
|
||||
tempServer = printServer.TempServer{}
|
||||
)
|
||||
if err = c.ShouldBind(¶m); err != nil {
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
err = tempServer.SwitchTemp(tokenInfo.User.UserID, param.ID)
|
||||
return "", "", err
|
||||
})
|
||||
}
|
||||
85
controllers/app/wx_login.go
Normal file
85
controllers/app/wx_login.go
Normal file
@@ -0,0 +1,85 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-print/controllers/controller"
|
||||
"git.rosy.net.cn/jx-print/model"
|
||||
"git.rosy.net.cn/jx-print/model/app_model"
|
||||
"git.rosy.net.cn/jx-print/services/print_server/app_server"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Auth2Controller struct{}
|
||||
|
||||
var Auth2ControllerController = new(Auth2Controller)
|
||||
|
||||
// Login 登录接口
|
||||
// @Title 登录接口
|
||||
// @Description 登录接口(微信与公众号登录不能直接调用此接口)
|
||||
// @Param data body app_model.WxLoginReq true "请求参数"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /Login [post]
|
||||
func (a *Auth2Controller) Login(c *gin.Context) {
|
||||
// 参数绑定
|
||||
var (
|
||||
err error
|
||||
params *app_model.WxLoginReq
|
||||
service = app_server.UserLogin{}
|
||||
)
|
||||
|
||||
if err = c.ShouldBind(¶ms); err != nil {
|
||||
c.JSON(http.StatusOK, &model.CallBack{
|
||||
Code: model.ErrCodeNormal,
|
||||
Desc: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
user, err := service.WxLogin(c, params.Code, params.Phone)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
// 获取token
|
||||
token, err := controller.SetToken(user)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
return map[string]interface{}{"token": token, "user": user}, "", nil
|
||||
})
|
||||
}
|
||||
|
||||
// GetUserPhoneByWeChat 获取用户电话号码
|
||||
// @Title 获取用户电话号码
|
||||
// @Description 获取用户电话号码
|
||||
// @Param data body app_model.WeChatPhoneNumberParam true "请求参数"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /GetUserPhone [post]
|
||||
func (a *Auth2Controller) GetUserPhoneByWeChat(c *gin.Context) {
|
||||
// 参数绑定
|
||||
var (
|
||||
err error
|
||||
params *app_model.WeChatPhoneNumberParam
|
||||
service = app_server.UserLogin{}
|
||||
)
|
||||
|
||||
if err = c.ShouldBind(¶ms); err != nil {
|
||||
c.JSON(http.StatusOK, &model.CallBack{
|
||||
Code: model.ErrCodeNormal,
|
||||
Desc: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
phone, err := service.GetUserPhoneNum(params)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
return map[string]interface{}{"phone": phone}, "", nil
|
||||
})
|
||||
}
|
||||
208
controllers/app/wx_print.go
Normal file
208
controllers/app/wx_print.go
Normal file
@@ -0,0 +1,208 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-print/controllers/controller"
|
||||
"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 {
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
if err = putils.UnmarshalUseNumber([]byte(param.Prints), &printInfo); err != nil {
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
controller.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 {
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
|
||||
controller.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 {
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
if err = putils.UnmarshalUseNumber([]byte(param.PrintNos), &printNos); err != nil {
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
controller.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 {
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
if !controller.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 {
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
controller.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 {
|
||||
controller.BuildErrJson(c, err)
|
||||
return
|
||||
}
|
||||
if tokenInfo = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
|
||||
controller.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 = controller.CheckToken(c); tokenInfo == nil {
|
||||
return
|
||||
}
|
||||
controller.CallFunc(c, func() (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = printServer.GetPrinterReport(tokenInfo)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user