KPI绩效考核系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.3 KiB

package wechatcallback
import (
"encoding/json"
"encoding/xml"
"fmt"
"key_performance_indicators/middleware/grocerystore"
"key_performance_indicators/overall"
"key_performance_indicators/overall/publicmethod"
"time"
)
func GeographicalPosition(eventMsg []byte) { //进入应用上报地址位置
var msgContent GeographicalPositionType
err := xml.Unmarshal(eventMsg, &msgContent)
if nil != err {
fmt.Println("***********Unmarshal fail")
}
userAddress := publicmethod.MapOut[string]()
userAddress["userid"] = msgContent.FromUsername //userID
userAddress["latitude"] = msgContent.Latitude //地理位置纬度
userAddress["longitude"] = msgContent.Longitude //地理位置经度
userAddress["precision"] = msgContent.Precision //地理位置精度
userAddress["time"] = time.Now().Unix()
marshal, err := json.Marshal(userAddress)
if err != nil {
marshal = []byte{}
}
redisPrefix := "Location:GeographicalPosition_" + overall.CONSTANT_CONFIG.RedisPrefixStr.PreFix + ":userId_" + msgContent.FromUsername //redis KEY
// redisClient := redishandel.RunRedis()
redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS1)
// fmt.Printf("button===101===>%v\n", redisClient)
locationJson, locationErr := redisClient.Lindex(redisPrefix, 0)
// fmt.Printf("button===102===>%v===>%v\n", locationJson, locationErr)
if locationErr != nil {
redisClient.Lpush(redisPrefix, string(marshal))
// fmt.Printf("button===1===>%v\n", marshal)
} else {
var geographicalPositionRedis GeographicalPositionRedis
jsonErr := json.Unmarshal([]byte(locationJson), &geographicalPositionRedis)
// fmt.Printf("button===2111===>%v===>%v\n", jsonErr, geographicalPositionRedis)
if jsonErr != nil {
redisClient.Lpush(redisPrefix, string(marshal))
// fmt.Printf("button===2===>%v===>%v\n", jsonErr, locationJson)
} else {
timeVal := geographicalPositionRedis.Time
if time.Now().Unix()-timeVal >= 300 {
redisClient.Lpush(redisPrefix, string(marshal))
// fmt.Printf("button===4===>%v\n", marshal)
} else {
// fmt.Printf("button===412===>%v===>%v\n", timeVal, time.Now().Unix()-timeVal)
}
}
}
// longFloat, _ := strconv.ParseFloat(msgContent.Longitude, 64)
// latFloat, _ := strconv.ParseFloat(msgContent.Latitude, 64)
// long, latg := commonus.GCJ02toBD09(longFloat, latFloat)
// fmt.Printf("button======>%v======>%v======>%v\n", msgContent, long, latg)
}