diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java index 6f6617a..ed3e5c8 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/CommonController.java @@ -1,7 +1,9 @@ package com.chaozhanggui.system.cashierservice.controller; +import com.alibaba.fastjson.TypeReference; import com.chaozhanggui.system.cashierservice.dao.TbPlatformDictMapper; 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.service.FileService; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; @@ -83,16 +85,22 @@ public class CommonController { */ @GetMapping("location/district") public Result createOrder(String keywords) throws JsonProcessingException { - String district = LocationUtils.district(keywords); + String districtJson = LocationUtils.district(keywords); ObjectMapper mapper = new ObjectMapper(); // 将 JSON 字符串解析为 JsonNode 对象 - JsonNode jsonNode = mapper.readTree(district); + JsonNode jsonNode = mapper.readTree(districtJson); JsonNode districts = jsonNode.get("districts"); - - - return Result.success(CodeEnum.SUCCESS, districts); + String text = districts.toString(); + List cityInfoList = mapper.readValue(text, mapper.getTypeFactory().constructCollectionType(List.class, DistrictVo.class)); + 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") public Result getGPSByIp(String ip) throws JsonProcessingException { String gpsInfo = LocationUtils.getGPSByIp(ip); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/BannerVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/BannerVO.java index b98784c..c9e82da 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/BannerVO.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/BannerVO.java @@ -1,7 +1,5 @@ package com.chaozhanggui.system.cashierservice.entity.vo; -import com.chaozhanggui.system.cashierservice.entity.TbPlatformDict; - import java.util.List; /** diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DicDetailVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DicDetailVO.java deleted file mode 100644 index aa84863..0000000 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DicDetailVO.java +++ /dev/null @@ -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 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 getDetail() { - return detail; - } - - public void setDetail(List detail) { - this.detail = detail; - } -} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DistrictVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DistrictVO.java deleted file mode 100644 index aff7937..0000000 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DistrictVO.java +++ /dev/null @@ -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; -} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DistrictVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DistrictVo.java new file mode 100644 index 0000000..bfda3ac --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/DistrictVo.java @@ -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 districts; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/OrderVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/OrderVo.java index b179b01..2126631 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/OrderVo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/OrderVo.java @@ -1,6 +1,5 @@ package com.chaozhanggui.system.cashierservice.entity.vo; -import com.chaozhanggui.system.cashierservice.entity.TbCashierCart; import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail; import lombok.Data; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/carouselVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/carouselVO.java deleted file mode 100644 index d7cffc7..0000000 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/carouselVO.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.chaozhanggui.system.cashierservice.entity.vo; - -/** - * 轮播图 - * @author lyf - */ -public class carouselVO { - /** - * 封面图 - */ - private String coverImg; - /** - * 跳转地址 - */ - private String relUrl; -} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java index de871ca..6a01041 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/rabbit/CartConsumer.java @@ -3,18 +3,10 @@ package com.chaozhanggui.system.cashierservice.rabbit; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; 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.redis.RedisCst; import com.chaozhanggui.system.cashierservice.redis.RedisUtil; 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 org.apache.commons.lang3.StringUtils; 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.Service; -import java.math.BigDecimal; -import java.time.Instant; -import java.util.*; - @Slf4j @Component //@RabbitListener(queues = {RabbitConstants.CART_QUEUE_PUT}) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java index 110d980..dd404c1 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/CartService.java @@ -5,27 +5,19 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.chaozhanggui.system.cashierservice.dao.*; 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.redis.RedisCst; 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.WebSocketServer; import com.chaozhanggui.system.cashierservice.util.DateUtils; import com.chaozhanggui.system.cashierservice.util.JSONUtil; import com.chaozhanggui.system.cashierservice.util.N; -import com.chaozhanggui.system.cashierservice.util.SnowFlakeUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.annotation.Resource; import java.io.IOException; import java.math.BigDecimal; import java.time.Instant; diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java index 846cd42..6959f87 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java @@ -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); return Result.success(CodeEnum.SUCCESS, products); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java index dca81d6..c733b2c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/LocationUtils.java @@ -1,6 +1,10 @@ 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.springframework.web.client.RestTemplate; import java.math.BigDecimal; import java.math.RoundingMode; @@ -27,6 +31,22 @@ public class LocationUtils { 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 @@ -37,7 +57,7 @@ public class LocationUtils { //超掌柜生活-用户端 param.put("key", "7a7f2e4790ea222660a027352ee3af39"); param.put("keywords", keywords); - param.put("subdistrict", "2"); + param.put("subdistrict", "1"); param.put("extensions", "base"); String s = HttpClientUtil.doGet("https://restapi.amap.com/v3/config/district", param); return s; @@ -80,7 +100,7 @@ public class LocationUtils { * 左下点 double[] leftBottomPoints = stringMap.get("leftBottomPoint"); */ public static Map returnLLSquarePoint(double longitude, double latitude, String distanceInKm) { - BigDecimal distanceKm = new BigDecimal(10); + BigDecimal distanceKm = new BigDecimal(20); if (StringUtils.isNotBlank(distanceInKm)) { distanceKm = new BigDecimal(distanceInKm); } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index f05640a..98135c4 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -16,7 +16,7 @@ spring: com.chaozhanggui.system.openness: info redis: # redis数据库索引(默认为0),我们使用索引为3的数据库,避免和其他数据库冲突 - database: 5 + database: 0 # redis服务器地址(默认为localhost) host: 101.37.12.135 # redis端口(默认为6379) diff --git a/src/main/resources/application-dev2.yml b/src/main/resources/application-dev2.yml index 32b0c0f..b2b5fb8 100644 --- a/src/main/resources/application-dev2.yml +++ b/src/main/resources/application-dev2.yml @@ -13,7 +13,7 @@ spring: com.chaozhanggui.system.openness: info redis: # redis数据库索引(默认为0),我们使用索引为3的数据库,避免和其他数据库冲突 - database: 5 + database: 0 # redis服务器地址(默认为localhost) host: 101.37.12.135 # redis端口(默认为6379) diff --git a/src/main/resources/application-hph.yml b/src/main/resources/application-hph.yml index b05f49b..4eb52e5 100644 --- a/src/main/resources/application-hph.yml +++ b/src/main/resources/application-hph.yml @@ -15,7 +15,7 @@ spring: com.chaozhanggui.system.openness: info redis: # redis数据库索引(默认为0),我们使用索引为3的数据库,避免和其他数据库冲突 - database: 5 + database: 0 # redis服务器地址(默认为localhost) host: 101.37.12.135 # redis端口(默认为6379) diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index 568a2b7..e7f2d81 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -13,7 +13,7 @@ spring: com.chaozhanggui.system.openness: info redis: # redis数据库索引(默认为0),我们使用索引为3的数据库,避免和其他数据库冲突 - database: 5 + database: 0 # redis服务器地址(默认为localhost) host: 101.37.12.135 # redis端口(默认为6379)