|
|
package controllers
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/beego/beego/v2/server/web/context"
|
|
|
"github.com/linmadan/egglib-go/web/beego"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/allied-lib/gateway/allied_creation_user"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
|
|
|
"strings"
|
|
|
"time"
|
|
|
"unicode/utf8"
|
|
|
)
|
|
|
|
|
|
type DeviceZKTecoController struct {
|
...
|
...
|
@@ -21,7 +27,8 @@ func (controller *DeviceZKTecoController) PostCdata() { |
|
|
data := &domain.DeviceZkTeco{
|
|
|
Sn: sn,
|
|
|
}
|
|
|
if len(bodyList) > 2 {
|
|
|
table := controller.Ctx.Input.Query("table")
|
|
|
if len(bodyList) > 2 && table == "ATTLOG" {
|
|
|
data.UserNo = bodyList[0]
|
|
|
//转成时间格式
|
|
|
mTime, err := time.ParseInLocation("2006-01-02 15:04:05", bodyList[1], time.Local)
|
...
|
...
|
@@ -36,6 +43,7 @@ func (controller *DeviceZKTecoController) PostCdata() { |
|
|
log.Logger.Debug(err.Error() + "data:" + bodyList[1])
|
|
|
}
|
|
|
}
|
|
|
RedirectToUserModule(controller.Ctx, false)
|
|
|
controller.Response(data, nil)
|
|
|
}
|
|
|
|
...
|
...
|
@@ -46,9 +54,72 @@ func (controller *DeviceZKTecoController) GetCdata() { |
|
|
|
|
|
func (controller *DeviceZKTecoController) GetRequest() {
|
|
|
//controller.Ctx.WriteString("C:11:DATA\tQUERY\tUSERINFO\tPIN=10086")
|
|
|
controller.Ctx.WriteString("OK")
|
|
|
//controller.Ctx.WriteString("C:7EceWxtHB6:DATA QUERY USERINFO PIN=3")
|
|
|
//controller.Ctx.WriteString("OK")
|
|
|
RedirectToUserModule(controller.Ctx, true)
|
|
|
}
|
|
|
|
|
|
func (controller *DeviceZKTecoController) Ping() {
|
|
|
controller.Ctx.WriteString("OK")
|
|
|
}
|
|
|
|
|
|
func RedirectToUserModule(ctx *context.Context, useResult bool) {
|
|
|
var svr = allied_creation_user.NewHttpLibAlliedCreationUser(constant.ALLIED_CREATION_USER_HOST)
|
|
|
data := ctx.Input.RequestBody
|
|
|
uri := ctx.Request.URL.Path
|
|
|
sn := ctx.Input.Query("SN")
|
|
|
table := ""
|
|
|
cmd := uri
|
|
|
switch uri {
|
|
|
case "/zkteco/iclock/getrequest": // 获取下行命令
|
|
|
cmd = "getrequest"
|
|
|
case "/zkteco/iclock/cdata": // 上报数据
|
|
|
cmd = "cdata"
|
|
|
table = ctx.Input.Query("table")
|
|
|
case "/zkteco/iclock/devicecmd":
|
|
|
cmd = "devicecmd"
|
|
|
}
|
|
|
content := string(data)
|
|
|
if !utf8.Valid(data) {
|
|
|
utf8Content, _ := utils.GbkToUtf8(data) //ConvertToString(content, "gbk", "utf-8")
|
|
|
content = string(utf8Content)
|
|
|
}
|
|
|
param := allied_creation_user.ReqTerminalReport{
|
|
|
TerminalType: "zkteco",
|
|
|
TerminalId: sn,
|
|
|
Command: cmd,
|
|
|
CompanyId: int64(constant.MANUFACTURE_DEFAULT_COMPANYID),
|
|
|
OrgId: int64(constant.MANUFACTURE_DEFAULT_ORGID),
|
|
|
Table: table,
|
|
|
Content: content,
|
|
|
}
|
|
|
if !useResult {
|
|
|
log.Logger.Debug(fmt.Sprintf("命令透传(sn:%v)-命令:%v 命令(内容):%v 成功", sn, cmd, content))
|
|
|
go func() {
|
|
|
defer func() {
|
|
|
if p := recover(); p != nil {
|
|
|
log.Logger.Error(fmt.Sprintf("%v", p))
|
|
|
}
|
|
|
}()
|
|
|
svr.TerminalReport(param)
|
|
|
}()
|
|
|
return
|
|
|
}
|
|
|
response, err := svr.TerminalReport(param)
|
|
|
if err != nil {
|
|
|
log.Logger.Debug(fmt.Sprintf("命令透传(sn:%v)-命令:%v 命令(内容):%v 应答:%v 错误:%v", sn, cmd, string(data), response.Response, err.Error()))
|
|
|
ctx.WriteString("OK")
|
|
|
return
|
|
|
}
|
|
|
log.Logger.Debug(fmt.Sprintf("命令透传(sn:%v)-命令:%v 命令(内容):%v 应答:%v 成功", sn, cmd, string(data), response.Response))
|
|
|
gbkData, _ := utils.Utf8ToGbk([]byte(response.Response))
|
|
|
ctx.Output.Header("Content-Type", "text/plain;charset=gbk")
|
|
|
ack := string(gbkData)
|
|
|
ctx.WriteString(ack)
|
|
|
}
|
|
|
|
|
|
func (controller *DeviceZKTecoController) DeviceCmd() {
|
|
|
//sn := controller.Ctx.Input.Query("SN")
|
|
|
RedirectToUserModule(controller.Ctx, false)
|
|
|
controller.Ctx.WriteString("OK")
|
|
|
} |
...
|
...
|
|