作者 yangfu

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/allied-creat…

…ion-manufacture into dev
@@ -12,6 +12,8 @@ var ( @@ -12,6 +12,8 @@ var (
12 REPOSITORY_CACHE_EXPIRE = 30 * 60 12 REPOSITORY_CACHE_EXPIRE = 30 * 60
13 13
14 REDIS_ADDRESS = "" 14 REDIS_ADDRESS = ""
  15 + // redis 考勤机打卡消息队列
  16 + REDIS_ZKTECO_KEY = "allied-creation-zkteco"
15 ) 17 )
16 18
17 func init() { 19 func init() {
  1 +package domain
  2 +
  3 +import "time"
  4 +
  5 +type DeviceZkTeco struct {
  6 + Sn string `json:"sn"` // 设备号
  7 + UserNo string `json:"userNo"` // 用户编码
  8 + ActionTime time.Time `json:"actionTime"` // 操作时间
  9 +}
  1 +package controllers
  2 +
  3 +import (
  4 + "encoding/json"
  5 + "github.com/linmadan/egglib-go/web/beego"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/redis"
  9 + "strings"
  10 + "time"
  11 +)
  12 +
  13 +type DeviceZKTecoController struct {
  14 + beego.BaseController
  15 +}
  16 +
  17 +func (controller *DeviceZKTecoController) PostCdata() {
  18 + body := controller.Ctx.Input.RequestBody
  19 + sn := controller.Ctx.Input.Query("SN")
  20 + //table := controller.Ctx.Input.Query("table")
  21 + bodyList := strings.Split(string(body), "\t")
  22 + data := &domain.DeviceZkTeco{
  23 + Sn: sn,
  24 + }
  25 + if len(bodyList) > 2 {
  26 + data.UserNo = bodyList[0]
  27 + //转成时间格式
  28 + mTime, err := time.ParseInLocation("2006-01-02 15:04:05", bodyList[1], time.Local)
  29 + if err == nil {
  30 + data.ActionTime = mTime
  31 + mBytes, _ := json.Marshal(data)
  32 + redis.GetRedis().LPush(constant.REDIS_ZKTECO_KEY, mBytes)
  33 + }
  34 + }
  35 + controller.Response(data, nil)
  36 +}
  37 +
  38 +func (controller *DeviceZKTecoController) GetCdata() {
  39 + //sn := controller.Ctx.Input.Query("SN")
  40 +
  41 +}
  42 +
  43 +func (controller *DeviceZKTecoController) GetRequest() {
  44 +
  45 +}
  46 +
  47 +func (controller *DeviceZKTecoController) Ping() {
  48 + controller.Ctx.WriteString("OK")
  49 +}
@@ -14,4 +14,10 @@ func init() { @@ -14,4 +14,10 @@ func init() {
14 web.Router("/devices/", &controllers.DeviceController{}, "Get:ListDevice") 14 web.Router("/devices/", &controllers.DeviceController{}, "Get:ListDevice")
15 web.Router("/devices/search", &controllers.DeviceController{}, "Post:SearchDevice") 15 web.Router("/devices/search", &controllers.DeviceController{}, "Post:SearchDevice")
16 web.Router("/devices/batch-add", &controllers.DeviceController{}, "Post:BatchAddDevice") 16 web.Router("/devices/batch-add", &controllers.DeviceController{}, "Post:BatchAddDevice")
  17 +
  18 + //考勤机
  19 + web.Router("/zkteco/iclock/cdata", &controllers.DeviceZKTecoController{}, "Post:PostCdata")
  20 + web.Router("/zkteco/iclock/cdata", &controllers.DeviceZKTecoController{}, "Get:GetCdata")
  21 + web.Router("/zkteco/iclock/getrequest", &controllers.DeviceZKTecoController{}, "Get:GetRequest")
  22 + web.Router("/zkteco/iclock/ping",&controllers.DeviceZKTecoController{},"Get:Ping")
17 } 23 }