device_zkteco_controller.go 1.6 KB
package controllers

import (
	"github.com/linmadan/egglib-go/web/beego"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/domain"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/infrastructure/domainService"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/log"
	"strings"
	"time"
)

type DeviceZKTecoController struct {
	beego.BaseController
}

func (controller *DeviceZKTecoController) PostCdata() {
	body := controller.Ctx.Input.RequestBody
	sn := controller.Ctx.Input.Query("SN")
	//table := controller.Ctx.Input.Query("table")
	bodyList := strings.Split(string(body), "\t")
	data := &domain.DeviceZkTeco{
		Sn: sn,
	}
	if len(bodyList) > 2 {
		data.UserNo = bodyList[0]
		//转成时间格式
		mTime, err := time.ParseInLocation("2006-01-02 15:04:05", bodyList[1], time.Local)
		if err == nil {
			data.ActionTime = mTime
			//mBytes, _ := json.Marshal(data)
			//redis.GetRedis().LPush(domain.TaskDeviceZkTecoReport(), mBytes)
			domainService.SendDeviceZkTecoReportJob(data)
		} else {
			data.ActionTime = time.Now()
			domainService.SendDeviceZkTecoReportJob(data)
			log.Logger.Debug(err.Error() + "data:" + bodyList[1])
		}
	}
	controller.Response(data, nil)
}

func (controller *DeviceZKTecoController) GetCdata() {
	//sn := controller.Ctx.Input.Query("SN")
	controller.Ctx.WriteString("OK")
}

func (controller *DeviceZKTecoController) GetRequest() {
	//controller.Ctx.WriteString("C:11:DATA\tQUERY\tUSERINFO\tPIN=10086")
	controller.Ctx.WriteString("OK")
}

func (controller *DeviceZKTecoController) Ping() {
	controller.Ctx.WriteString("OK")
}