package callback import ( "encoding/json" "encoding/xml" "fmt" "strconv" "time" "github.com/flipped-aurora/gin-vue-admin/server/commonus" "github.com/flipped-aurora/gin-vue-admin/server/global" "github.com/flipped-aurora/gin-vue-admin/server/utils/redishandel" ) //相关事件处理 func GeographicalPosition(eventMsg []byte) { var msgContent GeographicalPositionType err := xml.Unmarshal(eventMsg, &msgContent) if nil != err { fmt.Println("***********Unmarshal fail") } userAddress := commonus.MapOut() 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_" + global.GVA_CONFIG.RedisPrefix.PreFix + ":userId_" + msgContent.FromUsername //redis KEY redisClient := redishandel.RunRedis() redisClient.SetRedisDb(1) // fmt.Printf("button===101===>%v\n", string(marshal)) 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 >= 1800 { 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) }