| | |
| | | |
| | | import ( |
| | | "fmt" |
| | | "gat1400Exchange/pkg" |
| | | |
| | | "encoding/json" |
| | | "gat1400Exchange/config" |
| | | "gat1400Exchange/pkg/logger" |
| | | "gat1400Exchange/util" |
| | | "gat1400Exchange/vo" |
| | | ) |
| | | |
| | |
| | | } |
| | | |
| | | url := fmt.Sprintf("%s://%s:%s%s", config.ClientConf.Proto, config.ClientConf.ServerAddr, config.ClientConf.ServerPort, FacesUrI) |
| | | rsp, err := util.HttpPost(url, headers, msg) |
| | | rsp, err := pkg.HttpPost(url, headers, msg) |
| | | if err != nil { |
| | | logger.Warn("Post faces failed, %s", err.Error()) |
| | | return vo.StatusOtherError |
| | |
| | | } |
| | | |
| | | url := fmt.Sprintf("%s://%s:%s%s", config.ClientConf.Proto, config.ClientConf.ServerAddr, config.ClientConf.ServerPort, PersonsUrI) |
| | | rsp, err := util.HttpPost(url, headers, msg) |
| | | rsp, err := pkg.HttpPost(url, headers, msg) |
| | | if err != nil { |
| | | logger.Warn("Post person failed, %s", err.Error()) |
| | | return vo.StatusOtherError |
| | |
| | | |
| | | import ( |
| | | "encoding/json" |
| | | "gat1400Exchange/pkg" |
| | | "gat1400Exchange/pkg/logger" |
| | | "gat1400Exchange/util" |
| | | "gat1400Exchange/vo" |
| | | ) |
| | | |
| | |
| | | return clientStatus |
| | | } |
| | | |
| | | rsp, err := util.HttpPost(url, headers, msg) |
| | | rsp, err := pkg.HttpPost(url, headers, msg) |
| | | if err != nil { |
| | | logger.Warn("Post notification failed, %s", err.Error()) |
| | | return vo.StatusOtherError |
| | |
| | | // return clientStatus |
| | | //} |
| | | |
| | | rsp, err := util.HttpPost(url, headers, msg) |
| | | rsp, err := pkg.HttpPost(url, headers, msg) |
| | | if err != nil { |
| | | logger.Warn("Post subscribe failed, %s", err.Error()) |
| | | return vo.StatusOtherError |
| | |
| | | } |
| | | |
| | | func UpdateSubscribe(url string, msg []byte) int { |
| | | rsp, err := util.HttpPut(url, headers, msg) |
| | | rsp, err := pkg.HttpPut(url, headers, msg) |
| | | if err != nil { |
| | | logger.Warn("Put subscribe failed, %s", err.Error()) |
| | | return vo.StatusOtherError |
| | |
| | | } |
| | | |
| | | func GetSubscribes(url string) ([]byte, error) { |
| | | rsp, err := util.HttpGet(url, headers) |
| | | rsp, err := pkg.HttpGet(url, headers) |
| | | if err != nil { |
| | | logger.Warn("Get subscribe failed, %s", err.Error()) |
| | | } |
| | |
| | | import ( |
| | | "encoding/json" |
| | | "fmt" |
| | | "gat1400Exchange/pkg" |
| | | "io/ioutil" |
| | | |
| | | "gat1400Exchange/config" |
| | | "gat1400Exchange/pkg/logger" |
| | | "gat1400Exchange/util" |
| | | "gat1400Exchange/vo" |
| | | |
| | | dac "github.com/xinsnake/go-http-digest-auth-client" |
| | |
| | | |
| | | url := fmt.Sprintf("%s://%s:%s%s", config.ClientConf.Proto, config.ClientConf.ServerAddr, config.ClientConf.ServerPort, KeepaliveUrI) |
| | | b, _ := json.Marshal(body) |
| | | rsp, err := util.HttpPost(url, headers, b) |
| | | rsp, err := pkg.HttpPost(url, headers, b) |
| | | if err != nil { |
| | | logger.Warn("Keepalive request failed, %s", err.Error()) |
| | | return vo.StatusOtherError |
| | |
| | | "gat1400Exchange/pkg/logger" |
| | | "gat1400Exchange/repository" |
| | | "gat1400Exchange/service" |
| | | "gat1400Exchange/util" |
| | | "gat1400Exchange/vo" |
| | | |
| | | "github.com/gin-gonic/gin" |
| | |
| | | |
| | | today := time.Now().Format("2006-01-02") |
| | | imagePath := path.Join(config.LogConf.Path, "gat1400_face_images", today, img.ImageID+".jpeg") |
| | | err = util.WriteToFile(imagePath, imageBytes) |
| | | err = pkg.WriteToFile(imagePath, imageBytes) |
| | | if err == nil { |
| | | face.SubImageList.SubImageInfoObject[idx].Data = "" |
| | | face.SubImageList.SubImageInfoObject[idx].StoragePath = config.ImageConf.ImageUriPrefix + "/" + today + "/" + img.ImageID + ".jpeg" |
| | |
| | | import ( |
| | | "encoding/json" |
| | | "fmt" |
| | | "gat1400Exchange/pkg" |
| | | "net/http" |
| | | "strings" |
| | | "time" |
| | | |
| | | "gat1400Exchange/config" |
| | | "gat1400Exchange/pkg/logger" |
| | | "gat1400Exchange/util" |
| | | |
| | | "github.com/gin-gonic/gin" |
| | | ) |
| | | |
| | |
| | | "Cookie": "eyJuYW1lIjoiYWRtaW4iLCAicGFzZCI6ImFkbWluMTIzIn0=", |
| | | } |
| | | |
| | | rsp, err := util.HttpPost(url, header, payload) |
| | | rsp, err := pkg.HttpPost(url, header, payload) |
| | | if err != nil { |
| | | logger.Warn("Get A2 floor data failure,%s", err.Error()) |
| | | return |
File was renamed from util/file.go |
| | |
| | | package util |
| | | package pkg |
| | | |
| | | import ( |
| | | "fmt" |
| | |
| | | // 生成一个包含楼层的人脸id,解析楼层 |
| | | // 使用48位源id, 其中前41位是imageid, 不可以修改 41-43位填 06 代表图像, +99 + 3位楼层(第一位0表示正,1表示负) |
| | | func GenerateFaceIdContainFloor(srcId, floorStr string) string { |
| | | floorNum, _ := ParseFloor("0", floorStr) |
| | | floorNum, _ := BuildFloorString("0", floorStr) |
| | | newId := srcId[0:43] + "99" + floorNum |
| | | //newId := srcId[0:43] + "99" + floorNum + snowflake.CreateRandomNumber(1) |
| | | |
| | |
| | | return RestoreFloor(srcId[45:48]) |
| | | } |
| | | |
| | | // ParseFloor parses the floor string and returns a three-character string |
| | | func ParseFloor(direction, floor string) (string, error) { |
| | | // BuildFloorString parses the floor string and returns a string |
| | | func BuildFloorString(direction, floor string) (string, error) { |
| | | var dire string |
| | | var sign string |
| | | var number string |
| | | |
| | | switch direction { |
| | | case "in": |
| | | dire = "1" |
| | | case "out": |
| | | dire = "2" |
| | | default: |
| | | dire = "0" |
| | | } |
| | | |
| | | // Check if the floor is negative |
| | | if strings.HasPrefix(floor, "-") { |
| | |
| | | // Format the number to be two digits |
| | | formattedNumber := fmt.Sprintf("%02s", number) |
| | | |
| | | return direction + sign + formattedNumber, nil |
| | | return dire + sign + formattedNumber, nil |
| | | } |
| | | |
| | | // RestoreFloor restores the three-character string back to the original floor string |
| | |
| | | |
| | | return directionStr, floorStr, nil |
| | | } |
| | | |
| | | func CheckDirection(str1, str2 string) string { |
| | | // 去掉字符串最后一个字符 'F' |
| | | numStr1 := strings.TrimSuffix(str1, "F") |
| | | numStr2 := strings.TrimSuffix(str2, "F") |
| | | |
| | | // 转换为 int 类型 |
| | | num1, err1 := strconv.Atoi(numStr1) |
| | | num2, err2 := strconv.Atoi(numStr2) |
| | | |
| | | // 检查转换是否成功 |
| | | if err1 != nil || err2 != nil { |
| | | return "" |
| | | } |
| | | |
| | | // 比较两个整数的大小 |
| | | if num1 > num2 { |
| | | return "out" |
| | | } else { |
| | | return "in" |
| | | } |
| | | } |
File was renamed from util/http.go |
| | |
| | | package util |
| | | package pkg |
| | | |
| | | import ( |
| | | "bytes" |
| | |
| | | import ( |
| | | "encoding/base64" |
| | | "encoding/json" |
| | | "strconv" |
| | | "strings" |
| | | "time" |
| | | |
| | | "gat1400Exchange/client" |
| | |
| | | bgImageStr = image.Data |
| | | } |
| | | } else if image.StoragePath != "" { |
| | | imgData, err := util.ImageDownload(image.StoragePath, nil) |
| | | imgData, err := pkg.ImageDownload(image.StoragePath, nil) |
| | | if err != nil { |
| | | logger.Warn("Image download failure, %s", err.Error()) |
| | | } else { |
| | |
| | | // 转发图像 |
| | | logger.Debug("Prepare forward image, deviceId:%s, bgImage len:%d, smImage len:%d server:%s", deviceId, len(bgImageBytes), len(faceImageBytes), config.ForwardConf.SyncServer) |
| | | if deviceId != "" && bgImageStr != "" && config.ForwardConf.SyncServer != "" { |
| | | pd := c.PackPushDataV2(deviceId, faceId, face.FaceAppearTime, bgImageBytes, faceImageBytes) |
| | | if pd == nil { |
| | | pushData := c.PackPushDataV2(deviceId, faceId, face.FaceAppearTime, bgImageBytes, faceImageBytes) |
| | | if pushData == nil { |
| | | return |
| | | } |
| | | |
| | | // 处理梯控填写的楼层信息 暂时使用otherFeature字段 |
| | | if face.OtherFeature != "" && pd.CameraFloor == "" { |
| | | pd.Direction, pd.CameraFloor, _ = pkg.RestoreFloor(face.OtherFeature) |
| | | if face.OtherFeature != "" && pushData.CameraFloor == "" { |
| | | pushData.Direction, pushData.CameraFloor, _ = pkg.RestoreFloor(face.OtherFeature) |
| | | } |
| | | |
| | | payload, err := json.Marshal(pd) |
| | | payload, err := json.Marshal(pushData) |
| | | if err != nil { |
| | | logger.Warn("Marshal error, %s", err.Error()) |
| | | return |
| | | } |
| | | |
| | | if !util.SendData(payload, config.ForwardConf.SyncServer) { |
| | | cacheItem, _ := json.Marshal(pd) |
| | | if !pkg.SendData(payload, config.ForwardConf.SyncServer) { |
| | | cacheItem, _ := json.Marshal(pushData) |
| | | c.CacheData(cacheItem, "basic") |
| | | logger.Warn("The data forwarding failed, adding to local cache.") |
| | | } else { |
| | |
| | | bgImageStr = image.Data |
| | | } |
| | | } else if image.StoragePath != "" { |
| | | imgData, err := util.ImageDownload(image.StoragePath, nil) |
| | | imgData, err := pkg.ImageDownload(image.StoragePath, nil) |
| | | if err != nil { |
| | | logger.Warn("Image download failure, %s", err.Error()) |
| | | } else { |
| | |
| | | return |
| | | } |
| | | |
| | | if !util.SendData(payload, config.ForwardConf.SyncServer) { |
| | | if !pkg.SendData(payload, config.ForwardConf.SyncServer) { |
| | | cacheItem, _ := json.Marshal(pd) |
| | | c.CacheData(cacheItem, "basic") |
| | | logger.Warn("The data forwarding failed, adding to local cache.") |
| | |
| | | |
| | | for i := 0; i < config.NVCSConf.WaitRunTime; i++ { |
| | | if runState = nvcs.CurrentRunState(); runState.Floor != "" && runState.Floor != floor { |
| | | runDir = compareFloor(floor, runState.Floor) |
| | | runDir = pkg.CheckDirection(floor, runState.Floor) |
| | | break |
| | | } |
| | | |
| | |
| | | |
| | | for i := 0; i < config.NVCSConf.WaitRunTime; i++ { |
| | | if runState = nvcs.CurrentRunState(); runState.Floor != "" && runState.Floor != floor { |
| | | runDir = compareFloor(floor, runState.Floor) |
| | | runDir = pkg.CheckDirection(floor, runState.Floor) |
| | | break |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | for idx, _ := range msg.FaceListObject.FaceObject { |
| | | msg.FaceListObject.FaceObject[idx].OtherFeature, _ = pkg.ParseFloor(runDir, floor) |
| | | msg.FaceListObject.FaceObject[idx].OtherFeature, _ = pkg.BuildFloorString(runDir, floor) |
| | | //if config.ClientConf.AddFloorToFaceId { |
| | | // msg.FaceListObject.FaceObject[idx].FaceID = pkg.GenerateFaceIdContainFloor(face.FaceID, devPos.Pos) |
| | | //} |
| | |
| | | logger.Debug("Pub record message %s, %s", deviceId, msgId) |
| | | body, _ := json.Marshal(&msg) |
| | | |
| | | _, err := util.HttpPost(config.ForwardConf.RecordServer, nil, body) |
| | | _, err := pkg.HttpPost(config.ForwardConf.RecordServer, nil, body) |
| | | if err != nil { |
| | | logger.Warn(err.Error()) |
| | | } |
| | | } |
| | | |
| | | func compareFloor(str1, str2 string) string { |
| | | // 去掉字符串最后一个字符 'F' |
| | | numStr1 := strings.TrimSuffix(str1, "F") |
| | | numStr2 := strings.TrimSuffix(str2, "F") |
| | | |
| | | // 转换为 int 类型 |
| | | num1, err1 := strconv.Atoi(numStr1) |
| | | num2, err2 := strconv.Atoi(numStr2) |
| | | |
| | | // 检查转换是否成功 |
| | | if err1 != nil || err2 != nil { |
| | | return "" |
| | | } |
| | | |
| | | // 比较两个整数的大小 |
| | | if num1 > num2 { |
| | | return "2" |
| | | } else { |
| | | return "1" |
| | | } |
| | | } |
| | |
| | | import ( |
| | | "encoding/json" |
| | | "fmt" |
| | | "gat1400Exchange/pkg" |
| | | "time" |
| | | |
| | | "gat1400Exchange/config" |
| | | "gat1400Exchange/models" |
| | | "gat1400Exchange/util" |
| | | ) |
| | | |
| | | type DevReportData struct { |
| | |
| | | } |
| | | |
| | | headers := map[string]string{"Content-Type": "application/json; charset=UTF-8"} |
| | | _, err = util.HttpPost(config.ForwardConf.ReportServer, headers, data) |
| | | _, err = pkg.HttpPost(config.ForwardConf.ReportServer, headers, data) |
| | | if err != nil { |
| | | return err |
| | | } |
| | |
| | | "gat1400Exchange/client" |
| | | "gat1400Exchange/config" |
| | | "gat1400Exchange/models" |
| | | "gat1400Exchange/pkg" |
| | | "gat1400Exchange/pkg/logger" |
| | | "gat1400Exchange/util" |
| | | "gat1400Exchange/vo" |
| | | ) |
| | | |
| | |
| | | return |
| | | } |
| | | } else { |
| | | if !util.SendData([]byte(c.Data), config.ForwardConf.SyncServer) { |
| | | if !pkg.SendData([]byte(c.Data), config.ForwardConf.SyncServer) { |
| | | c.UpdateRetryCount() |
| | | logger.Warn("The data resend failed. retry count %d", c.Retry+1) |
| | | return |