1
|
package controllers
|
1
|
package controllers
|
2
|
|
2
|
|
3
|
import (
|
3
|
import (
|
|
|
4
|
+ "fmt"
|
|
|
5
|
+ "github.com/beego/beego/v2/server/web/context"
|
4
|
"github.com/linmadan/egglib-go/web/beego"
|
6
|
"github.com/linmadan/egglib-go/web/beego"
|
|
|
7
|
+ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
|
5
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
|
8
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
|
|
|
9
|
+ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/allied-lib/gateway/allied_creation_user"
|
6
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
|
10
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
|
|
|
11
|
+ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/utils"
|
7
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
|
12
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
|
8
|
"strings"
|
13
|
"strings"
|
9
|
"time"
|
14
|
"time"
|
|
|
15
|
+ "unicode/utf8"
|
10
|
)
|
16
|
)
|
11
|
|
17
|
|
12
|
type DeviceZKTecoController struct {
|
18
|
type DeviceZKTecoController struct {
|
|
@@ -21,7 +27,8 @@ func (controller *DeviceZKTecoController) PostCdata() { |
|
@@ -21,7 +27,8 @@ func (controller *DeviceZKTecoController) PostCdata() { |
21
|
data := &domain.DeviceZkTeco{
|
27
|
data := &domain.DeviceZkTeco{
|
22
|
Sn: sn,
|
28
|
Sn: sn,
|
23
|
}
|
29
|
}
|
24
|
- if len(bodyList) > 2 {
|
30
|
+ table := controller.Ctx.Input.Query("table")
|
|
|
31
|
+ if len(bodyList) > 2 && table == "ATTLOG" {
|
25
|
data.UserNo = bodyList[0]
|
32
|
data.UserNo = bodyList[0]
|
26
|
//转成时间格式
|
33
|
//转成时间格式
|
27
|
mTime, err := time.ParseInLocation("2006-01-02 15:04:05", bodyList[1], time.Local)
|
34
|
mTime, err := time.ParseInLocation("2006-01-02 15:04:05", bodyList[1], time.Local)
|
|
@@ -36,6 +43,7 @@ func (controller *DeviceZKTecoController) PostCdata() { |
|
@@ -36,6 +43,7 @@ func (controller *DeviceZKTecoController) PostCdata() { |
36
|
log.Logger.Debug(err.Error() + "data:" + bodyList[1])
|
43
|
log.Logger.Debug(err.Error() + "data:" + bodyList[1])
|
37
|
}
|
44
|
}
|
38
|
}
|
45
|
}
|
|
|
46
|
+ RedirectToUserModule(controller.Ctx, false)
|
39
|
controller.Response(data, nil)
|
47
|
controller.Response(data, nil)
|
40
|
}
|
48
|
}
|
41
|
|
49
|
|
|
@@ -46,9 +54,72 @@ func (controller *DeviceZKTecoController) GetCdata() { |
|
@@ -46,9 +54,72 @@ func (controller *DeviceZKTecoController) GetCdata() { |
46
|
|
54
|
|
47
|
func (controller *DeviceZKTecoController) GetRequest() {
|
55
|
func (controller *DeviceZKTecoController) GetRequest() {
|
48
|
//controller.Ctx.WriteString("C:11:DATA\tQUERY\tUSERINFO\tPIN=10086")
|
56
|
//controller.Ctx.WriteString("C:11:DATA\tQUERY\tUSERINFO\tPIN=10086")
|
49
|
- controller.Ctx.WriteString("OK")
|
57
|
+ //controller.Ctx.WriteString("C:7EceWxtHB6:DATA QUERY USERINFO PIN=3")
|
|
|
58
|
+ //controller.Ctx.WriteString("OK")
|
|
|
59
|
+ RedirectToUserModule(controller.Ctx, true)
|
50
|
}
|
60
|
}
|
51
|
|
61
|
|
52
|
func (controller *DeviceZKTecoController) Ping() {
|
62
|
func (controller *DeviceZKTecoController) Ping() {
|
53
|
controller.Ctx.WriteString("OK")
|
63
|
controller.Ctx.WriteString("OK")
|
54
|
}
|
64
|
}
|
|
|
65
|
+
|
|
|
66
|
+func RedirectToUserModule(ctx *context.Context, useResult bool) {
|
|
|
67
|
+ var svr = allied_creation_user.NewHttpLibAlliedCreationUser(constant.ALLIED_CREATION_USER_HOST)
|
|
|
68
|
+ data := ctx.Input.RequestBody
|
|
|
69
|
+ uri := ctx.Request.URL.Path
|
|
|
70
|
+ sn := ctx.Input.Query("SN")
|
|
|
71
|
+ table := ""
|
|
|
72
|
+ cmd := uri
|
|
|
73
|
+ switch uri {
|
|
|
74
|
+ case "/zkteco/iclock/getrequest": // 获取下行命令
|
|
|
75
|
+ cmd = "getrequest"
|
|
|
76
|
+ case "/zkteco/iclock/cdata": // 上报数据
|
|
|
77
|
+ cmd = "cdata"
|
|
|
78
|
+ table = ctx.Input.Query("table")
|
|
|
79
|
+ case "/zkteco/iclock/devicecmd":
|
|
|
80
|
+ cmd = "devicecmd"
|
|
|
81
|
+ }
|
|
|
82
|
+ content := string(data)
|
|
|
83
|
+ if !utf8.Valid(data) {
|
|
|
84
|
+ utf8Content, _ := utils.GbkToUtf8(data) //ConvertToString(content, "gbk", "utf-8")
|
|
|
85
|
+ content = string(utf8Content)
|
|
|
86
|
+ }
|
|
|
87
|
+ param := allied_creation_user.ReqTerminalReport{
|
|
|
88
|
+ TerminalType: "zkteco",
|
|
|
89
|
+ TerminalId: sn,
|
|
|
90
|
+ Command: cmd,
|
|
|
91
|
+ CompanyId: int64(constant.MANUFACTURE_DEFAULT_COMPANYID),
|
|
|
92
|
+ OrgId: int64(constant.MANUFACTURE_DEFAULT_ORGID),
|
|
|
93
|
+ Table: table,
|
|
|
94
|
+ Content: content,
|
|
|
95
|
+ }
|
|
|
96
|
+ if !useResult {
|
|
|
97
|
+ log.Logger.Debug(fmt.Sprintf("命令透传(sn:%v)-命令:%v 命令(内容):%v 成功", sn, cmd, content))
|
|
|
98
|
+ go func() {
|
|
|
99
|
+ defer func() {
|
|
|
100
|
+ if p := recover(); p != nil {
|
|
|
101
|
+ log.Logger.Error(fmt.Sprintf("%v", p))
|
|
|
102
|
+ }
|
|
|
103
|
+ }()
|
|
|
104
|
+ svr.TerminalReport(param)
|
|
|
105
|
+ }()
|
|
|
106
|
+ return
|
|
|
107
|
+ }
|
|
|
108
|
+ response, err := svr.TerminalReport(param)
|
|
|
109
|
+ if err != nil {
|
|
|
110
|
+ log.Logger.Debug(fmt.Sprintf("命令透传(sn:%v)-命令:%v 命令(内容):%v 应答:%v 错误:%v", sn, cmd, string(data), response.Response, err.Error()))
|
|
|
111
|
+ ctx.WriteString("OK")
|
|
|
112
|
+ return
|
|
|
113
|
+ }
|
|
|
114
|
+ log.Logger.Debug(fmt.Sprintf("命令透传(sn:%v)-命令:%v 命令(内容):%v 应答:%v 成功", sn, cmd, string(data), response.Response))
|
|
|
115
|
+ gbkData, _ := utils.Utf8ToGbk([]byte(response.Response))
|
|
|
116
|
+ ctx.Output.Header("Content-Type", "text/plain;charset=gbk")
|
|
|
117
|
+ ack := string(gbkData)
|
|
|
118
|
+ ctx.WriteString(ack)
|
|
|
119
|
+}
|
|
|
120
|
+
|
|
|
121
|
+func (controller *DeviceZKTecoController) DeviceCmd() {
|
|
|
122
|
+ //sn := controller.Ctx.Input.Query("SN")
|
|
|
123
|
+ RedirectToUserModule(controller.Ctx, false)
|
|
|
124
|
+ controller.Ctx.WriteString("OK")
|
|
|
125
|
+} |