Example #1
0
        public IActionResult PostBind([FromBody] JObject data)
        {
            var mac  = data.GetValue("mac", "");
            var sbno = data.GetValue("sbno", "");

            Check.Require(mac.HasValue(), $"必须指定MAC地址");

            var loc = new Location
            {
                Longitude = data.GetValue("longitude", ""),
                Latitude  = data.GetValue("latitude", "")
            };

            if (data.ContainsKey("address"))
            {
                loc.AdCode   = data.GetValue("adcode", "");
                loc.Address  = data.GetValue("address", "");
                loc.Province = data.GetValue("province", "");
                loc.City     = data.GetValue("city", "");
                loc.District = data.GetValue("district", "");
            }
            else
            {
                loc = cloudService.GetLocationService().GetLoc(loc.Longitude, loc.Latitude);
            }

            var wea = cloudService.GetWeatherService().GetWea(loc.Longitude, loc.Latitude);

            iotService.PostBind(new
            {
                mac,
                sbno,
                newid  = App.IdWorker.NextId(),
                userid = AppCtx.AC.User.Id,
                loc.Longitude,
                loc.Latitude,
                loc.Address,
                loc.Province,
                loc.City,
                loc.District,
                adcode = loc.AdCode,
                wea.city.cityid
            });

            // refresh cache for device.
            cacheService.RemoveDevice(mac);

            return(Ok(null));
        }
Example #2
0
 public Location GetLocation(string lng, string lat)
 {
     return(cloudService.GetLocationService().GetLoc(lng, lat));
 }