小程序经纬度接口,临时主页接口
This commit is contained in:
parent
0efbb1e747
commit
b8f5448a7b
|
|
@ -0,0 +1,297 @@
|
|||
package com.czg.controller.user;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.resp.CzgResult;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 小程序主页相关接口
|
||||
* @author Administrator
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/user/home")
|
||||
public class HomeController {
|
||||
@GetMapping("/homePageUp")
|
||||
public CzgResult<?> homePageUp() {
|
||||
return CzgResult.success(JSONObject.parseObject("""
|
||||
{
|
||||
"carousel": [
|
||||
{
|
||||
"name": "轮播图1",
|
||||
"coverImg": "https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/20240516/cba9df1d4d2b452daf0e7940fa6bafba.png",
|
||||
"jumpType": "relative",
|
||||
"absUrl": ""
|
||||
},
|
||||
{
|
||||
"name": "轮播图2",
|
||||
"coverImg": "https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/20240516/a2edc122ce4540ecae5e61f9cc7a701f.png",
|
||||
"jumpType": "relative",
|
||||
"absUrl": ""
|
||||
},
|
||||
{
|
||||
"name": "轮播图3",
|
||||
"coverImg": "https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/20240516/3d34f9c457fc4267b277c00a8f74d8f9.png",
|
||||
"jumpType": "relative",
|
||||
"absUrl": ""
|
||||
},
|
||||
{
|
||||
"name": "轮播图4",
|
||||
"coverImg": "https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/20240516/2482d7856e9b4c46b3f5b87d8b74126d.png",
|
||||
"jumpType": "relative",
|
||||
"absUrl": ""
|
||||
}
|
||||
],
|
||||
"district": [
|
||||
{
|
||||
"coverImg": "https://czg-oss.oss-cn-hangzhou.aliyuncs.com/app/statics/%E9%A2%84%E7%BA%A6%E5%88%B0%E5%BA%97.png",
|
||||
"name": "预约到店",
|
||||
"value": "",
|
||||
"fontColor": "",
|
||||
"jumpType": "relative",
|
||||
"absUrl": "index/tothestore"
|
||||
},
|
||||
{
|
||||
"coverImg": "https://czg-oss.oss-cn-hangzhou.aliyuncs.com/app/statics/%E6%89%AB%E7%A0%81%E7%82%B9%E9%A4%90.png",
|
||||
"name": "扫码点餐",
|
||||
"value": "scan",
|
||||
"fontColor": "",
|
||||
"jumpType": "scan",
|
||||
"absUrl": ""
|
||||
},
|
||||
{
|
||||
"coverImg": "https://czg-oss.oss-cn-hangzhou.aliyuncs.com/app/statics/%E5%92%96%E5%95%A1%E9%A5%AE%E5%93%81.png",
|
||||
"name": "咖啡饮品",
|
||||
"value": "1",
|
||||
"fontColor": "",
|
||||
"jumpType": "relative",
|
||||
"absUrl": "index/drinks"
|
||||
},
|
||||
{
|
||||
"coverImg": "https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/20240418/2f79d02678004e9c8db00ae6115e780a.png",
|
||||
"name": "每日免单",
|
||||
"value": "",
|
||||
"fontColor": "",
|
||||
"jumpType": "relative",
|
||||
"absUrl": "index/freedaily"
|
||||
},
|
||||
{
|
||||
"coverImg": "https://cashier-oss.oss-cn-beijing.aliyuncs.com/tcwm/wm.png",
|
||||
"name": "外 卖",
|
||||
"value": "{\\"appId\\":\\"wxc2bb94c0ddda1032\\",\\"path\\":\\"pages/index/shopList/index?token=ceshi\\"}",
|
||||
"fontColor": "",
|
||||
"jumpType": "scan_applet",
|
||||
"absUrl": ""
|
||||
}
|
||||
],
|
||||
"menu": [
|
||||
{
|
||||
"dictId": 1,
|
||||
"dictName": "allCity",
|
||||
"name": "全城",
|
||||
"isChild": true,
|
||||
"value": null,
|
||||
"detail": [
|
||||
{
|
||||
"dictId": 13,
|
||||
"dictName": "allCity",
|
||||
"name": "行政区",
|
||||
"isChild": null,
|
||||
"value": "",
|
||||
"detail": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"dictId": 2,
|
||||
"dictName": "category",
|
||||
"name": "品类",
|
||||
"isChild": true,
|
||||
"value": null,
|
||||
"detail": [
|
||||
{
|
||||
"dictId": 56,
|
||||
"dictName": "category",
|
||||
"name": "双人餐",
|
||||
"isChild": null,
|
||||
"value": "2",
|
||||
"detail": []
|
||||
},
|
||||
{
|
||||
"dictId": 11,
|
||||
"dictName": "category",
|
||||
"name": "饮品小吃",
|
||||
"isChild": null,
|
||||
"value": "4",
|
||||
"detail": []
|
||||
},
|
||||
{
|
||||
"dictId": 12,
|
||||
"dictName": "category",
|
||||
"name": "咖啡饮品",
|
||||
"isChild": null,
|
||||
"value": "1",
|
||||
"detail": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"dictId": 3,
|
||||
"dictName": "sort",
|
||||
"name": "智能排序",
|
||||
"isChild": true,
|
||||
"value": null,
|
||||
"detail": [
|
||||
{
|
||||
"dictId": 8,
|
||||
"dictName": "sort",
|
||||
"name": "离我最近",
|
||||
"isChild": null,
|
||||
"value": "1",
|
||||
"detail": []
|
||||
},
|
||||
{
|
||||
"dictId": 9,
|
||||
"dictName": "sort",
|
||||
"name": "销量优先",
|
||||
"isChild": null,
|
||||
"value": "2",
|
||||
"detail": []
|
||||
},
|
||||
{
|
||||
"dictId": 10,
|
||||
"dictName": "sort",
|
||||
"name": "价格优先",
|
||||
"isChild": null,
|
||||
"value": "3",
|
||||
"detail": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"dictId": 4,
|
||||
"dictName": "near1",
|
||||
"name": "附近1KM",
|
||||
"isChild": false,
|
||||
"value": "near",
|
||||
"detail": []
|
||||
}
|
||||
],
|
||||
"todayList": {
|
||||
"name": "今日上新",
|
||||
"todayList": [],
|
||||
"date": "10点更新"
|
||||
},
|
||||
"salesList": {
|
||||
"name": "飙升热榜",
|
||||
"hotList": [],
|
||||
"date": "8点更新"
|
||||
},
|
||||
"bannerVO": {
|
||||
"coupons": null,
|
||||
"counponsInfo": [
|
||||
{
|
||||
"name": "小***你",
|
||||
"logo": "https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/aef489a444793e37e2f33aeb3fe1fe13.jpeg",
|
||||
"money": 56.0
|
||||
},
|
||||
{
|
||||
"name": "红***好",
|
||||
"logo": "https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/a906414986b1bee60cec709dabf2103b.jpeg",
|
||||
"money": 159.5
|
||||
},
|
||||
{
|
||||
"name": "这***绿",
|
||||
"logo": "https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/e847667f37d86dc4a48ffcf69bb1a964.jpeg",
|
||||
"money": 106.5
|
||||
},
|
||||
{
|
||||
"name": "慢***上",
|
||||
"logo": "https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/a0be3632c238d1a8e24e51ff8942efc6.jpeg",
|
||||
"money": 171.0
|
||||
},
|
||||
{
|
||||
"name": "里***们",
|
||||
"logo": "https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/c26400a670209b60abcd28bfc6d22171.jpeg",
|
||||
"money": 59.5
|
||||
},
|
||||
{
|
||||
"name": "紫***大",
|
||||
"logo": "https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/e731f8a883ab1ef2a71487f2eb5b0e38.jpeg",
|
||||
"money": 165.0
|
||||
},
|
||||
{
|
||||
"name": "我***紫",
|
||||
"logo": "https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/f73810e20530a70dd068e0e0a82677d4.jpeg",
|
||||
"money": 100.0
|
||||
},
|
||||
{
|
||||
"name": "他***灰",
|
||||
"logo": "https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/cd794c0c5dd3b212e7c46eaa7c3a85cc.jpeg",
|
||||
"money": 133.0
|
||||
},
|
||||
{
|
||||
"name": "这***下",
|
||||
"logo": "https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/be1e70097583d1a08a9951925d66ef33.jpeg",
|
||||
"money": 37.5
|
||||
},
|
||||
{
|
||||
"name": "小***红",
|
||||
"logo": "https://cashier-oss.oss-cn-beijing.aliyuncs.com/status/%E6%BE%B6%E6%9D%91%E5%84%9A/ccf1f255cd30c2aed0b421213df01863.jpeg",
|
||||
"money": 109.0
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
"""));
|
||||
}
|
||||
|
||||
@GetMapping("/home")
|
||||
public CzgResult<?> home() {
|
||||
return CzgResult.success(JSONObject.parseObject("""
|
||||
{
|
||||
"total": 1,
|
||||
"list": [
|
||||
{
|
||||
"shopName": "漫巷咖啡",
|
||||
"shopImage": "https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/20240612/6f3618a31d2a4b489215647871ae732e.jpg",
|
||||
"productName": "鸡尾酒套餐",
|
||||
"image": "https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/20240612/0c07e1f79a244ed498dfe4a70848c479.jpeg",
|
||||
"originPrice": 200.00,
|
||||
"salePrice": 180.00,
|
||||
"discount": 9.00,
|
||||
"save": 20.00,
|
||||
"realSalesNumber": 0,
|
||||
"shopTag": [],
|
||||
"proTag": [],
|
||||
"distances": "4.2km",
|
||||
"districts": "未央区",
|
||||
"id": 661,
|
||||
"endTime": 1739577599999
|
||||
}
|
||||
],
|
||||
"pageNum": 1,
|
||||
"pageSize": 10,
|
||||
"size": 1,
|
||||
"startRow": 1,
|
||||
"endRow": 1,
|
||||
"pages": 1,
|
||||
"prePage": 0,
|
||||
"nextPage": 0,
|
||||
"isFirstPage": true,
|
||||
"isLastPage": true,
|
||||
"hasPreviousPage": false,
|
||||
"hasNextPage": false,
|
||||
"navigatePages": 8,
|
||||
"navigatepageNums": [
|
||||
1
|
||||
],
|
||||
"navigateFirstPage": 1,
|
||||
"navigateLastPage": 1,
|
||||
"firstPage": 1,
|
||||
"lastPage": 1
|
||||
}
|
||||
"""));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package com.czg.controller.user;
|
||||
|
||||
import com.czg.account.service.GeoService;
|
||||
import com.czg.resp.CzgResult;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* geo位置管理
|
||||
* @author Administrator
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/user/geo")
|
||||
public class UserGeoController {
|
||||
@Resource
|
||||
private GeoService geoService;
|
||||
|
||||
@GetMapping("/geocode")
|
||||
public CzgResult<?> getAddress(@RequestParam @NotEmpty String lat, @RequestParam @NotEmpty String lng) {
|
||||
return CzgResult.success(geoService.getAddress(lat, lng));
|
||||
}
|
||||
}
|
||||
|
|
@ -54,7 +54,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
|
|||
// 重置根路径,防止satoken切割根路径导致匹配不到路径
|
||||
ApplicationInfo.routePrefix = "";
|
||||
|
||||
SaRouter.match("/user/**").notMatch("/user/login", "/user/test")
|
||||
SaRouter.match("/user/**").notMatch("/user/login", "/user/test", "/user/geo/**", "/user/home/**")
|
||||
.check(r -> StpKit.USER.checkMiniUser())
|
||||
.setHit(true)
|
||||
// .match("/**")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package com.czg.account.service;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
public interface GeoService {
|
||||
Object getAddress(@NotEmpty String lat, @NotEmpty String lng);
|
||||
}
|
||||
|
|
@ -1,8 +1,15 @@
|
|||
package com.czg.utils;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
@Component
|
||||
public class GeoUtil {
|
||||
// 地球半径,单位:公里
|
||||
private static final double EARTH_RADIUS = 6371.0;
|
||||
|
|
@ -30,4 +37,5 @@ public class GeoUtil {
|
|||
// 计算距离(米)
|
||||
return EARTH_RADIUS * c * 1000;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
package com.czg.service.account.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.czg.account.service.GeoService;
|
||||
import com.czg.exception.ApiNotPrintException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestClient;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 经纬度
|
||||
*
|
||||
* @author Administrator
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class GeoServiceImpl implements GeoService {
|
||||
private final RestClient restClient = RestClient.create();
|
||||
private static final String API_KEY = "7a7f2e4790ea222660a027352ee3af39";
|
||||
private static final String BASE_URL = "https://restapi.amap.com/v3/geocode/regeo";
|
||||
|
||||
@Override
|
||||
public JSONObject getAddress(String lat, String lng) {
|
||||
// 高德 API 坐标格式为 "经度,纬度"
|
||||
String location = lng + "," + lat;
|
||||
|
||||
String response = restClient.get()
|
||||
.uri(BASE_URL + "?key=" + API_KEY + "&location=" + location)
|
||||
.retrieve()
|
||||
.body(String.class);
|
||||
|
||||
JSONObject jsonObject = JSONObject.parseObject(response);
|
||||
if (jsonObject == null) {
|
||||
log.warn("经纬度获取失败{}", response);
|
||||
throw new ApiNotPrintException("获取经纬度失败");
|
||||
}
|
||||
return jsonObject.getJSONObject("regeocode");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue