package oa_logic import ( "dubbo.apache.org/dubbo-go/v3/common/logger" "errors" "fmt" "github.com/fonchain_enterprise/fonchain-main/api/oa" "github.com/fonchain_enterprise/fonchain-main/pkg/cache" "github.com/fonchain_enterprise/fonchain-main/pkg/e" "github.com/go-redis/redis" "strconv" ) func CheckClickInAddress(lng, lat string, chickInMap []*oa.WorkingTime_ChickIn) (bool, error) { // 实际打卡经纬度 操作 lngF, _ := strconv.ParseFloat(lng, 64) latF, _ := strconv.ParseFloat(lat, 64) // 打卡地点经纬度 操作 for _, v := range chickInMap { geoLocation := new(redis.GeoLocation) geoLocation.Name = v.Address geoLocation.Latitude, _ = strconv.ParseFloat(v.Lat, 64) geoLocation.Longitude, _ = strconv.ParseFloat(v.Lng, 64) // 扩大范围 + 200m v.Distance = v.Distance + 200 fmt.Printf("geoLocation %+v\n", geoLocation) _, geoLocationErr := cache.GeoAdd(cache.ChickInMap, geoLocation) if geoLocationErr != nil { logger.Errorf("打卡经纬度 存储 失败 err %+v\n", geoLocationErr) fmt.Printf("打卡经纬度 存储 失败 err %+v\n", geoLocationErr) return false, errors.New(e.ErrorSaveCacheGeo) } results, geoRadiusErr := cache.GeoRadius(cache.ChickInMap, lngF, latF, &redis.GeoRadiusQuery{ Radius: float64(v.Distance), Unit: "m", WithGeoHash: false, WithDist: true, }) if geoRadiusErr != nil { logger.Errorf("打卡经纬度 范围查询 失败 err %+v\n", geoLocationErr) fmt.Printf("打卡经纬度 范围查询 失败 err %+v\n", geoLocationErr) return false, errors.New(e.ErrorQueryRangeGeo) } geoLocation.Latitude = 0 geoLocation.Longitude = 0 _, delGeoLocation := cache.GeoAdd(cache.ChickInMap, geoLocation) if delGeoLocation != nil { logger.Errorf("删除缓存的打卡经纬度 失败 err %+v\n", delGeoLocation) fmt.Printf("删除缓存的打卡经纬度 失败 err %+v\n", delGeoLocation) return false, errors.New(e.ErrorDelCacheGeo) } fmt.Printf("results %+v\n", results) for _, result := range results { if result.Dist <= float64(v.Distance) { return true, nil } } } return false, nil }