测试环境redis 更换到0库

通用接口添加 根据经纬度获取位置信息接口
This commit is contained in:
wangw 2024-05-16 10:52:16 +08:00
parent c6257d75f2
commit 314d79ac2c
15 changed files with 58 additions and 129 deletions

View File

@ -1,7 +1,9 @@
package com.chaozhanggui.system.cashierservice.controller; package com.chaozhanggui.system.cashierservice.controller;
import com.alibaba.fastjson.TypeReference;
import com.chaozhanggui.system.cashierservice.dao.TbPlatformDictMapper; import com.chaozhanggui.system.cashierservice.dao.TbPlatformDictMapper;
import com.chaozhanggui.system.cashierservice.entity.TbPlatformDict; import com.chaozhanggui.system.cashierservice.entity.TbPlatformDict;
import com.chaozhanggui.system.cashierservice.entity.vo.DistrictVo;
import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.service.FileService; import com.chaozhanggui.system.cashierservice.service.FileService;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
@ -83,16 +85,22 @@ public class CommonController {
*/ */
@GetMapping("location/district") @GetMapping("location/district")
public Result createOrder(String keywords) throws JsonProcessingException { public Result createOrder(String keywords) throws JsonProcessingException {
String district = LocationUtils.district(keywords); String districtJson = LocationUtils.district(keywords);
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
// JSON 字符串解析为 JsonNode 对象 // JSON 字符串解析为 JsonNode 对象
JsonNode jsonNode = mapper.readTree(district); JsonNode jsonNode = mapper.readTree(districtJson);
JsonNode districts = jsonNode.get("districts"); JsonNode districts = jsonNode.get("districts");
String text = districts.toString();
List<DistrictVo> cityInfoList = mapper.readValue(text, mapper.getTypeFactory().constructCollectionType(List.class, DistrictVo.class));
return Result.success(CodeEnum.SUCCESS, districts); return Result.success(CodeEnum.SUCCESS, cityInfoList);
} }
@GetMapping("location/geocode")
public Result geocode(String location){
return Result.success(CodeEnum.SUCCESS, LocationUtils.geocode(location));
}
@GetMapping("location/getGPSByIp") @GetMapping("location/getGPSByIp")
public Result getGPSByIp(String ip) throws JsonProcessingException { public Result getGPSByIp(String ip) throws JsonProcessingException {
String gpsInfo = LocationUtils.getGPSByIp(ip); String gpsInfo = LocationUtils.getGPSByIp(ip);

View File

@ -1,7 +1,5 @@
package com.chaozhanggui.system.cashierservice.entity.vo; package com.chaozhanggui.system.cashierservice.entity.vo;
import com.chaozhanggui.system.cashierservice.entity.TbPlatformDict;
import java.util.List; import java.util.List;
/** /**

View File

@ -1,59 +0,0 @@
package com.chaozhanggui.system.cashierservice.entity.vo;
import com.chaozhanggui.system.cashierservice.entity.SysDictDetail;
import java.util.List;
/**
* @author lyf
*/
public class DicDetailVO {
private String name;
private String dictName;
private String description;
private List<SysDictDetail> detail;
private Boolean isChild;
public String getDictName() {
return dictName;
}
public void setDictName(String dictName) {
this.dictName = dictName;
}
public Boolean getIsChild() {
return isChild;
}
public void setIsChild(Boolean isChild) {
this.isChild = isChild;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public List<SysDictDetail> getDetail() {
return detail;
}
public void setDetail(List<SysDictDetail> detail) {
this.detail = detail;
}
}

View File

@ -1,19 +0,0 @@
package com.chaozhanggui.system.cashierservice.entity.vo;
/**
* @author lyf
*/
public class DistrictVO {
/**
* 图片
*/
private String icon;
/**
* 菜单名
*/
private String name;
/**
* 跳转地址
*/
private String relUrl;
}

View File

@ -0,0 +1,18 @@
package com.chaozhanggui.system.cashierservice.entity.vo;
import lombok.Data;
import java.util.List;
/**
* 行政区域返回vo
*/
@Data
public class DistrictVo {
private Object citycode;
private Object adcode;
private Object name;
private Object center;
private Object level;
private List<DistrictVo> districts;
}

View File

@ -1,6 +1,5 @@
package com.chaozhanggui.system.cashierservice.entity.vo; package com.chaozhanggui.system.cashierservice.entity.vo;
import com.chaozhanggui.system.cashierservice.entity.TbCashierCart;
import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail; import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
import lombok.Data; import lombok.Data;

View File

@ -1,16 +0,0 @@
package com.chaozhanggui.system.cashierservice.entity.vo;
/**
* 轮播图
* @author lyf
*/
public class carouselVO {
/**
* 封面图
*/
private String coverImg;
/**
* 跳转地址
*/
private String relUrl;
}

View File

@ -3,18 +3,10 @@ package com.chaozhanggui.system.cashierservice.rabbit;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.vo.CashierCarVo;
import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.redis.RedisCst; import com.chaozhanggui.system.cashierservice.redis.RedisCst;
import com.chaozhanggui.system.cashierservice.redis.RedisUtil; import com.chaozhanggui.system.cashierservice.redis.RedisUtil;
import com.chaozhanggui.system.cashierservice.service.CartService; import com.chaozhanggui.system.cashierservice.service.CartService;
import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
import com.chaozhanggui.system.cashierservice.util.JSONUtil;
import com.chaozhanggui.system.cashierservice.util.RedisUtils;
import com.chaozhanggui.system.cashierservice.util.SnowFlakeUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.rabbit.annotation.RabbitHandler; import org.springframework.amqp.rabbit.annotation.RabbitHandler;
@ -23,10 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.Instant;
import java.util.*;
@Slf4j @Slf4j
@Component @Component
//@RabbitListener(queues = {RabbitConstants.CART_QUEUE_PUT}) //@RabbitListener(queues = {RabbitConstants.CART_QUEUE_PUT})

View File

@ -5,27 +5,19 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*; import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.dto.ProductCartDto;
import com.chaozhanggui.system.cashierservice.entity.vo.CashierCarVo;
import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.redis.RedisCst; import com.chaozhanggui.system.cashierservice.redis.RedisCst;
import com.chaozhanggui.system.cashierservice.redis.RedisUtil; import com.chaozhanggui.system.cashierservice.redis.RedisUtil;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer; import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
import com.chaozhanggui.system.cashierservice.socket.WebSocketServer;
import com.chaozhanggui.system.cashierservice.util.DateUtils; import com.chaozhanggui.system.cashierservice.util.DateUtils;
import com.chaozhanggui.system.cashierservice.util.JSONUtil; import com.chaozhanggui.system.cashierservice.util.JSONUtil;
import com.chaozhanggui.system.cashierservice.util.N; import com.chaozhanggui.system.cashierservice.util.N;
import com.chaozhanggui.system.cashierservice.util.SnowFlakeUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.Instant; import java.time.Instant;

View File

@ -95,7 +95,7 @@ public class HomePageService {
/** /**
* 商品列表 * 商品列表
*/ */
public Result proList(HomeDto homeDto) throws ExecutionException, InterruptedException { public Result proList(HomeDto homeDto) {
PageInfo products = productService.products(homeDto); PageInfo products = productService.products(homeDto);
return Result.success(CodeEnum.SUCCESS, products); return Result.success(CodeEnum.SUCCESS, products);
} }

View File

@ -1,6 +1,10 @@
package com.chaozhanggui.system.cashierservice.util; package com.chaozhanggui.system.cashierservice.util;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.web.client.RestTemplate;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
@ -27,6 +31,22 @@ public class LocationUtils {
return s; return s;
} }
/**
* 通过经纬度获取信息
*/
public static JsonNode geocode(String location) {
RestTemplate restTemplate = new RestTemplate();
String s = restTemplate.getForObject("https://restapi.amap.com/v3/geocode/regeo?key=7a7f2e4790ea222660a027352ee3af39&location="+location, String.class);
ObjectMapper objectMapper = new ObjectMapper();
// JSON 字符串解析为 JsonNode 对象
try {
JsonNode jsonNode = objectMapper.readTree(s).get("regeocode");
return jsonNode;
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
/** /**
* 行政区域查询 * 行政区域查询
* @param keywords * @param keywords
@ -37,7 +57,7 @@ public class LocationUtils {
//超掌柜生活-用户端 //超掌柜生活-用户端
param.put("key", "7a7f2e4790ea222660a027352ee3af39"); param.put("key", "7a7f2e4790ea222660a027352ee3af39");
param.put("keywords", keywords); param.put("keywords", keywords);
param.put("subdistrict", "2"); param.put("subdistrict", "1");
param.put("extensions", "base"); param.put("extensions", "base");
String s = HttpClientUtil.doGet("https://restapi.amap.com/v3/config/district", param); String s = HttpClientUtil.doGet("https://restapi.amap.com/v3/config/district", param);
return s; return s;
@ -80,7 +100,7 @@ public class LocationUtils {
* 左下点 double[] leftBottomPoints = stringMap.get("leftBottomPoint"); * 左下点 double[] leftBottomPoints = stringMap.get("leftBottomPoint");
*/ */
public static Map<String, double[]> returnLLSquarePoint(double longitude, double latitude, String distanceInKm) { public static Map<String, double[]> returnLLSquarePoint(double longitude, double latitude, String distanceInKm) {
BigDecimal distanceKm = new BigDecimal(10); BigDecimal distanceKm = new BigDecimal(20);
if (StringUtils.isNotBlank(distanceInKm)) { if (StringUtils.isNotBlank(distanceInKm)) {
distanceKm = new BigDecimal(distanceInKm); distanceKm = new BigDecimal(distanceInKm);
} }

View File

@ -16,7 +16,7 @@ spring:
com.chaozhanggui.system.openness: info com.chaozhanggui.system.openness: info
redis: redis:
# redis数据库索引默认为0我们使用索引为3的数据库避免和其他数据库冲突 # redis数据库索引默认为0我们使用索引为3的数据库避免和其他数据库冲突
database: 5 database: 0
# redis服务器地址默认为localhost # redis服务器地址默认为localhost
host: 101.37.12.135 host: 101.37.12.135
# redis端口默认为6379 # redis端口默认为6379

View File

@ -13,7 +13,7 @@ spring:
com.chaozhanggui.system.openness: info com.chaozhanggui.system.openness: info
redis: redis:
# redis数据库索引默认为0我们使用索引为3的数据库避免和其他数据库冲突 # redis数据库索引默认为0我们使用索引为3的数据库避免和其他数据库冲突
database: 5 database: 0
# redis服务器地址默认为localhost # redis服务器地址默认为localhost
host: 101.37.12.135 host: 101.37.12.135
# redis端口默认为6379 # redis端口默认为6379

View File

@ -15,7 +15,7 @@ spring:
com.chaozhanggui.system.openness: info com.chaozhanggui.system.openness: info
redis: redis:
# redis数据库索引默认为0我们使用索引为3的数据库避免和其他数据库冲突 # redis数据库索引默认为0我们使用索引为3的数据库避免和其他数据库冲突
database: 5 database: 0
# redis服务器地址默认为localhost # redis服务器地址默认为localhost
host: 101.37.12.135 host: 101.37.12.135
# redis端口默认为6379 # redis端口默认为6379

View File

@ -13,7 +13,7 @@ spring:
com.chaozhanggui.system.openness: info com.chaozhanggui.system.openness: info
redis: redis:
# redis数据库索引默认为0我们使用索引为3的数据库避免和其他数据库冲突 # redis数据库索引默认为0我们使用索引为3的数据库避免和其他数据库冲突
database: 5 database: 0
# redis服务器地址默认为localhost # redis服务器地址默认为localhost
host: 101.37.12.135 host: 101.37.12.135
# redis端口默认为6379 # redis端口默认为6379