Bladeren bron

rename file

tanlie 1 maand geleden
bovenliggende
commit
cfd65c0c2b
21 gewijzigde bestanden met toevoegingen van 301 en 116 verwijderingen
  1. 1 1
      wishing-admin/src/views/wishing/tree/list.vue
  2. 19 19
      wishing-platform/platform-core/platform-core-base/src/main/java/cn/qinys/platform/base/exceptions/GlobalDefaultExceptionHandler.java
  3. 1 0
      wishing-platform/platform-core/platform-core-base/src/main/java/cn/qinys/platform/base/response/Result.java
  4. 0 70
      wishing-platform/platform-core/platform-core-base/src/main/java/cn/qinys/platform/base/response/UnifyResponse.java
  5. 45 0
      wishing-platform/platform-entity/platform-entity-upms/src/main/java/cn/qinys/platform/entity/upms/CommonGeoKey.java
  6. 3 0
      wishing-platform/platform-entity/platform-entity-wishing/target/maven-archiver/pom.properties
  7. 3 0
      wishing-platform/platform-entity/platform-entity-wishing/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
  8. 3 0
      wishing-platform/platform-entity/platform-entity-wishing/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
  9. BIN
      wishing-platform/platform-entity/platform-entity-wishing/target/platform-entity-wishing-1.0.0-SNAPSHOT.jar
  10. 2 2
      wishing-platform/platform-gateway/src/main/java/cn/qinys/platform/gateway/config/GlobalExceptionConfiguration.java
  11. 1 1
      wishing-platform/platform-gateway/src/main/java/cn/qinys/platform/gateway/response/Result.java
  12. 5 6
      wishing-platform/platform-service/platform-service-admin/src/main/java/cn/qinys/platform/admin/controller/WishTreeController.java
  13. 24 0
      wishing-platform/platform-service/platform-service-admin/src/main/java/cn/qinys/platform/admin/req/GeoAddressReq.java
  14. 10 0
      wishing-platform/platform-service/platform-service-admin/src/main/java/cn/qinys/platform/admin/service/impl/WishTreeServiceImpl.java
  15. 6 8
      wishing-platform/platform-service/platform-service-admin/src/main/java/cn/qinys/platform/openfeign/UpmsFeignClient.java
  16. 3 3
      wishing-platform/platform-service/platform-service-mobile/src/main/java/cn/qinys/platform/mobile/controller/WishingTreeController.java
  17. 16 1
      wishing-platform/platform-service/platform-service-upms/src/main/java/cn/qinys/platform/upms/api/controller/GaoDeKeyController.java
  18. 22 0
      wishing-platform/platform-service/platform-service-upms/src/main/java/cn/qinys/platform/upms/api/mapper/CommonGeoKeyMapper.java
  19. 23 0
      wishing-platform/platform-service/platform-service-upms/src/main/java/cn/qinys/platform/upms/api/req/GaoDeGetAddressReq.java
  20. 8 0
      wishing-platform/platform-service/platform-service-upms/src/main/java/cn/qinys/platform/upms/api/service/IGaoDeKeyService.java
  21. 106 5
      wishing-platform/platform-service/platform-service-upms/src/main/java/cn/qinys/platform/upms/api/service/impl/GaoDeKeyServiceImpl.java

+ 1 - 1
wishing-admin/src/views/wishing/tree/list.vue

@@ -70,7 +70,7 @@
 <script>
 import { creatTree, queryTreePage } from '@api/wishing/tree';
 import { removeUser, updateUserDetail } from '@api/upms/api-user';
-import { isNumber,isInteger } from '@utils/validate';
+import { isNumber, isInteger } from '@utils/validate';
 
 export default {
   name: 'WishingTree',

+ 19 - 19
wishing-platform/platform-core/platform-core-base/src/main/java/cn/qinys/platform/base/exceptions/GlobalDefaultExceptionHandler.java

@@ -2,7 +2,7 @@ package cn.qinys.platform.base.exceptions;
 
 
 
-import cn.qinys.platform.base.response.UnifyResponse;
+import cn.qinys.platform.base.response.Result;
 import cn.qinys.platform.base.response.ResultCodeEnum;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.http.HttpStatus;
@@ -37,9 +37,9 @@ public class GlobalDefaultExceptionHandler {
      */
     @ExceptionHandler(value = Exception.class)
     @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
-    public UnifyResponse<String> defaultErrorHandler(Exception ex) {
+    public Result<String> defaultErrorHandler(Exception ex) {
         log.error("全局异常: [{}]", ex.getMessage(), ex);
-        return new UnifyResponse<String>(ResultCodeEnum.INTERNAL_SERVER_ERROR).setData(ex.getMessage());
+        return new Result<String>(ResultCodeEnum.INTERNAL_SERVER_ERROR).setData(ex.getMessage());
         // 网络安全中心要求发生异常时不能泄漏代码和数据库的信息,直接返回ex.getMessage()可能会泄露.
         //return new Result<String>(ResultCodeEnum.INTERNAL_SERVER_ERROR).setData("");
     }
@@ -47,9 +47,9 @@ public class GlobalDefaultExceptionHandler {
 
     @ExceptionHandler(value = AccessDeniedException.class)
     @ResponseStatus(HttpStatus.UNAUTHORIZED)
-    public UnifyResponse<String> accessDeniedHandler(Exception ex) {
+    public Result<String> accessDeniedHandler(Exception ex) {
         log.error("401:该账号无权限: [{}]", ex.getMessage());
-        return new UnifyResponse<>(ResultCodeEnum.UNAUTHORIZED);
+        return new Result<>(ResultCodeEnum.UNAUTHORIZED);
     }
 
 
@@ -61,12 +61,12 @@ public class GlobalDefaultExceptionHandler {
      */
     @ExceptionHandler(value = MethodArgumentNotValidException.class)
     @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
-    public UnifyResponse<String> validationErrorHandler(MethodArgumentNotValidException ex) {
+    public Result<String> validationErrorHandler(MethodArgumentNotValidException ex) {
         StringBuilder sb = new StringBuilder();
         ex.getBindingResult().getAllErrors().forEach(error -> sb.append(error.getDefaultMessage()).append(","));
         log.error("验证未通过 ==> [{}], 字段 ==> [{}]", ex.getMessage(), sb.toString());
         //return new Result<String>(ResultCodeEnum.VALIDATE_NOT_ACCESS).setMsg(sb.toString());
-        return new UnifyResponse<>(400, sb.toString());
+        return new Result<>(400, sb.toString());
     }
 
     /**
@@ -77,9 +77,9 @@ public class GlobalDefaultExceptionHandler {
      */
     @ExceptionHandler(value = MissingServletRequestParameterException.class)
     @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
-    public UnifyResponse<String> missingServletRequestParameterErrorHandler(MissingServletRequestParameterException ex) {
+    public Result<String> missingServletRequestParameterErrorHandler(MissingServletRequestParameterException ex) {
         log.error("缺少请求参数:[{}]", ex.getMessage());
-        return new UnifyResponse<String>(ResultCodeEnum.MISSING_REQUEST_PARAMETER).setData(ex.getMessage());
+        return new Result<String>(ResultCodeEnum.MISSING_REQUEST_PARAMETER).setData(ex.getMessage());
     }
 
     /**
@@ -90,9 +90,9 @@ public class GlobalDefaultExceptionHandler {
      */
     @ExceptionHandler(value = BindException.class)
     @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
-    public UnifyResponse<String> badRequestErrorHandler(BindException ex) {
+    public Result<String> badRequestErrorHandler(BindException ex) {
         log.error("请求参数类型错误:[{}]", ex.getMessage());
-        return new UnifyResponse<String>(ResultCodeEnum.BAD_REQUEST).setData(ex.getMessage());
+        return new Result<String>(ResultCodeEnum.BAD_REQUEST).setData(ex.getMessage());
     }
 
     /**
@@ -103,9 +103,9 @@ public class GlobalDefaultExceptionHandler {
      */
     @ExceptionHandler(value = SQLException.class)
     @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
-    public UnifyResponse<String> databaseErrorHandler(SQLException ex) {
+    public Result<String> databaseErrorHandler(SQLException ex) {
         log.error("数据库操作错误:[{}]", ex.getMessage());
-        return new UnifyResponse<String>(ResultCodeEnum.DATABASE_ERROR).setData(ex.getMessage());
+        return new Result<String>(ResultCodeEnum.DATABASE_ERROR).setData(ex.getMessage());
     }
 
     /**
@@ -116,9 +116,9 @@ public class GlobalDefaultExceptionHandler {
      */
     @ExceptionHandler(value = ConnectException.class)
     @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
-    public UnifyResponse<String> connect(ConnectException ex) {
+    public Result<String> connect(ConnectException ex) {
         log.error("网络连接失败:[{}]", ex.getMessage());
-        return new UnifyResponse<String>(ResultCodeEnum.CONNECTION_ERROR).setData(ex.getMessage());
+        return new Result<String>(ResultCodeEnum.CONNECTION_ERROR).setData(ex.getMessage());
     }
 
     /**
@@ -129,9 +129,9 @@ public class GlobalDefaultExceptionHandler {
      */
     @ExceptionHandler(value = BizException.class)
     @ResponseStatus(value = HttpStatus.OK)
-    public UnifyResponse<String> bizException(BizException ex) {
+    public Result<String> bizException(BizException ex) {
         log.info("业务异常:[{}]=={}", ex.getMsg(), ex.getData());
-        return new UnifyResponse<>(400, ex.getMsg(), ex.getMsg());
+        return new Result<>(400, ex.getMsg(), ex.getMsg());
     }
 
 
@@ -144,8 +144,8 @@ public class GlobalDefaultExceptionHandler {
      */
     @ExceptionHandler(value = HttpClientErrorException.class)
     @ResponseStatus(value = HttpStatus.FORBIDDEN)
-    public UnifyResponse<String> badRequestException(HttpClientErrorException ex) {
-        return new UnifyResponse<>(403, ex.getMessage());
+    public Result<String> badRequestException(HttpClientErrorException ex) {
+        return new Result<>(403, ex.getMessage());
     }
 
 }

+ 1 - 0
wishing-platform/platform-core/platform-core-base/src/main/java/cn/qinys/platform/base/response/Result.java

@@ -31,6 +31,7 @@ public class Result<T> implements Serializable {
     public Result(String msg) {
         this.code = ResultCodeEnum.SUCCESS.getCode();
         this.msg = msg;
+        this.data = (T) msg;
     }
 
     public Result(T data) {

+ 0 - 70
wishing-platform/platform-core/platform-core-base/src/main/java/cn/qinys/platform/base/response/UnifyResponse.java

@@ -1,70 +0,0 @@
-package cn.qinys.platform.base.response;
-
-
-import lombok.Data;
-import lombok.NoArgsConstructor;
-import lombok.experimental.Accessors;
-
-import java.io.Serializable;
-
-/**
- * Description:
- *
- * @author tanlie
- * Date: 2024/1/9 8:32
- */
-@Data
-@NoArgsConstructor
-@Accessors(chain = true)
-public class UnifyResponse<T> implements Serializable {
-
-    private static final long serialVersionUID = 4822942452184119123L;
-    private int code;
-    private String msg;
-    private T data;
-
-    public UnifyResponse(ResultCodeEnum rCode) {
-        this.code = rCode.getCode();
-        this.msg = rCode.getDesc();
-    }
-
-    public UnifyResponse(String msg) {
-        this.code = ResultCodeEnum.SUCCESS.getCode();
-        this.msg = msg;
-    }
-
-    public UnifyResponse(T data) {
-        this.code = ResultCodeEnum.SUCCESS.getCode();
-        this.msg = ResultCodeEnum.SUCCESS.getDesc();
-        this.data = data;
-    }
-
-    public UnifyResponse(String msg, T data) {
-        this.code = ResultCodeEnum.SUCCESS.getCode();
-        this.msg = msg;
-        this.data = data;
-    }
-
-    public UnifyResponse(ResultCodeEnum rCode, T data) {
-        this.code = rCode.getCode();
-        this.msg = rCode.getDesc();
-        this.data = data;
-    }
-
-    public UnifyResponse(int code, String msg) {
-        this.code = code;
-        this.msg = msg;
-    }
-
-    public UnifyResponse(int code, String msg, T data) {
-        this.code = code;
-        this.msg = msg;
-        this.data = data;
-    }
-
-    public UnifyResponse setCodeEnum(ResultCodeEnum rCode) {
-        this.code = rCode.getCode();
-        return this;
-    }
-
-}

+ 45 - 0
wishing-platform/platform-entity/platform-entity-upms/src/main/java/cn/qinys/platform/entity/upms/CommonGeoKey.java

@@ -0,0 +1,45 @@
+package cn.qinys.platform.entity.upms;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 高德逆地理解析key(CommonGeoKey)实体类
+ *
+ * @author makejava
+ * @since 2024-04-17 14:44:06
+ */
+
+@Data
+@TableName("common_geo_key")
+public class CommonGeoKey implements Serializable {
+
+    /**
+     * id
+     * 自增 => @TableId(type = IdType.AUTO)
+     */
+    @TableId(type = IdType.AUTO)
+    private Integer id;
+    /**
+     * key
+     */
+    private String geoKey;
+    /**
+     * 备注
+     */
+    private String remark;
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+    /**
+     * 更新时间
+     */
+    private Date updateTime;
+
+}

+ 3 - 0
wishing-platform/platform-entity/platform-entity-wishing/target/maven-archiver/pom.properties

@@ -0,0 +1,3 @@
+artifactId=platform-entity-wishing
+groupId=cn.qinys
+version=1.0.0-SNAPSHOT

+ 3 - 0
wishing-platform/platform-entity/platform-entity-wishing/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst

@@ -0,0 +1,3 @@
+cn\qinys\platform\entity\wishing\BaseEntity.class
+cn\qinys\platform\entity\wishing\WishingTree.class
+cn\qinys\platform\entity\wishing\WishingUser.class

+ 3 - 0
wishing-platform/platform-entity/platform-entity-wishing/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst

@@ -0,0 +1,3 @@
+G:\许愿树\wishing-platform\platform-entity\platform-entity-wishing\src\main\java\cn\qinys\platform\entity\wishing\BaseEntity.java
+G:\许愿树\wishing-platform\platform-entity\platform-entity-wishing\src\main\java\cn\qinys\platform\entity\wishing\WishingTree.java
+G:\许愿树\wishing-platform\platform-entity\platform-entity-wishing\src\main\java\cn\qinys\platform\entity\wishing\WishingUser.java

BIN
wishing-platform/platform-entity/platform-entity-wishing/target/platform-entity-wishing-1.0.0-SNAPSHOT.jar


+ 2 - 2
wishing-platform/platform-gateway/src/main/java/cn/qinys/platform/gateway/config/GlobalExceptionConfiguration.java

@@ -1,7 +1,7 @@
 package cn.qinys.platform.gateway.config;
 
 
-import cn.qinys.platform.gateway.response.UnifyResponse;
+import cn.qinys.platform.gateway.response.Result;
 import lombok.extern.slf4j.Slf4j;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -38,7 +38,7 @@ public class GlobalExceptionConfiguration implements ErrorWebExceptionHandler, O
             response.setStatusCode(rse.getStatusCode());
         }
         logger.error("服务器异常 == {}", ex.getMessage());
-        return UnifyResponse.fail(response, 500, ex.getMessage());
+        return Result.fail(response, 500, ex.getMessage());
 
     }
 

+ 1 - 1
wishing-platform/platform-gateway/src/main/java/cn/qinys/platform/gateway/response/UnifyResponse.java → wishing-platform/platform-gateway/src/main/java/cn/qinys/platform/gateway/response/Result.java

@@ -17,7 +17,7 @@ import java.util.Map;
  */
 
 @Component
-public class UnifyResponse {
+public class Result {
 
     public static Mono<Void> fail(ServerHttpResponse response, Integer code, String msg) {
         if (StringUtils.hasLength(msg) && msg.contains("404 NOT_FOUND")) {

+ 5 - 6
wishing-platform/platform-service/platform-service-admin/src/main/java/cn/qinys/platform/admin/controller/WishTreeController.java

@@ -4,8 +4,7 @@ import cn.qinys.platform.admin.req.WishingTreeCreateReq;
 import cn.qinys.platform.admin.req.WishingTreePageReq;
 import cn.qinys.platform.admin.resp.WishingTreePageResp;
 import cn.qinys.platform.admin.service.WishTreeService;
-import cn.qinys.platform.base.response.UnifyResponse;
-import cn.qinys.platform.openfeign.UpmsFeignClient;
+import cn.qinys.platform.base.response.Result;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import jakarta.annotation.Resource;
 import jakarta.validation.Valid;
@@ -26,15 +25,15 @@ public class WishTreeController {
 
 
     @GetMapping("/page")
-    public UnifyResponse<Page<WishingTreePageResp>> getWishTreePage(WishingTreePageReq req) {
+    public Result<Page<WishingTreePageResp>> getWishTreePage(WishingTreePageReq req) {
         Page<WishingTreePageResp> wishTreePage = wishTreeService.getWishTreePage(req);
-        return new UnifyResponse<>(wishTreePage);
+        return new Result<>(wishTreePage);
     }
 
     @PostMapping("/create")
-    public UnifyResponse<Long> createWishTree(@RequestBody @Valid WishingTreeCreateReq req) {
+    public Result<Long> createWishTree(@RequestBody @Valid WishingTreeCreateReq req) {
         Long id = wishTreeService.createWishTree(req);
-        return new UnifyResponse<>("created", id);
+        return new Result<>("created", id);
     }
 
 }

+ 24 - 0
wishing-platform/platform-service/platform-service-admin/src/main/java/cn/qinys/platform/admin/req/GeoAddressReq.java

@@ -0,0 +1,24 @@
+package cn.qinys.platform.admin.req;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * Request for creating a wishing tree
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class GeoAddressReq implements Serializable {
+
+    private BigDecimal longitude;
+
+    private BigDecimal latitude;
+
+
+}
+

+ 10 - 0
wishing-platform/platform-service/platform-service-admin/src/main/java/cn/qinys/platform/admin/service/impl/WishTreeServiceImpl.java

@@ -1,12 +1,15 @@
 package cn.qinys.platform.admin.service.impl;
 
 import cn.qinys.platform.admin.mapper.WishingTreeMapper;
+import cn.qinys.platform.admin.req.GeoAddressReq;
 import cn.qinys.platform.admin.req.WishingTreeCreateReq;
 import cn.qinys.platform.admin.req.WishingTreePageReq;
 import cn.qinys.platform.admin.resp.WishingTreePageResp;
 import cn.qinys.platform.admin.service.WishTreeService;
+import cn.qinys.platform.base.response.Result;
 import cn.qinys.platform.base.utils.BeanExUtils;
 import cn.qinys.platform.entity.wishing.WishingTree;
+import cn.qinys.platform.openfeign.UpmsFeignClient;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import jakarta.annotation.Resource;
@@ -24,10 +27,17 @@ public class WishTreeServiceImpl implements WishTreeService {
     @Resource
     private WishingTreeMapper wishingTreeMapper;
 
+    @Resource
+    UpmsFeignClient upmsFeignClient;
+
     @Override
     public Long createWishTree(WishingTreeCreateReq req) {
         WishingTree tree = BeanExUtils.convert(req, WishingTree.class);
         // insert returns number of rows; id is populated into entity if DB supports generated keys
+        if (!StringUtils.hasText(tree.getAddress())) {
+            Result<String> address = upmsFeignClient.getAddressByAltitudeAndLongitude(new GeoAddressReq(req.getLongitude(), req.getLatitude()));
+            tree.setAddress(address.getData());
+        }
         wishingTreeMapper.insert(tree);
         return tree.getId();
     }

+ 6 - 8
wishing-platform/platform-service/platform-service-admin/src/main/java/cn/qinys/platform/openfeign/UpmsFeignClient.java

@@ -1,15 +1,13 @@
 package cn.qinys.platform.openfeign;
 
-import cn.qinys.platform.admin.req.BasePageReq;
+import cn.qinys.platform.admin.req.GeoAddressReq;
 import cn.qinys.platform.base.constants.ServiceConstants;
 import cn.qinys.platform.base.response.Result;
 import cn.qinys.platform.config.FeignConfiguration;
-import com.alibaba.fastjson2.JSONObject;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.stereotype.Component;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.cloud.openfeign.SpringQueryMap;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 
 /**
  * @author lie tan
@@ -23,10 +21,10 @@ public interface UpmsFeignClient {
 
 
     /**
-     * 初始化redis中的
+     * 根据经纬度获取地址信息
      *
      * @return 无
      */
-    @GetMapping("/upms/gaodekey/page")
-    Result<Page<JSONObject>> getGaoDeKeyPage(@SpringQueryMap BasePageReq req);
+    @PostMapping("/upms/gaodekey/address")
+    Result<String> getAddressByAltitudeAndLongitude(@RequestBody GeoAddressReq req);
 }

+ 3 - 3
wishing-platform/platform-service/platform-service-mobile/src/main/java/cn/qinys/platform/mobile/controller/WishingTreeController.java

@@ -1,6 +1,6 @@
 package cn.qinys.platform.mobile.controller;
 
-import cn.qinys.platform.base.response.UnifyResponse;
+import cn.qinys.platform.base.response.Result;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -15,9 +15,9 @@ import org.springframework.web.bind.annotation.RestController;
 public class WishingTreeController {
 
     @RequestMapping("/ping")
-    public UnifyResponse<String> pong() {
+    public Result<String> pong() {
 
-        return new UnifyResponse<>("wishingtree pong");
+        return new Result<>("wishingtree pong");
     }
 
 }

+ 16 - 1
wishing-platform/platform-service/platform-service-upms/src/main/java/cn/qinys/platform/upms/api/controller/GaoDeKeyController.java

@@ -4,11 +4,13 @@ import cn.qinys.platform.base.response.Result;
 import cn.qinys.platform.base.security.annotation.HasPermission;
 import cn.qinys.platform.base.utils.excel.ExcelElement;
 import cn.qinys.platform.base.utils.excel.ExcelUtils;
+import cn.qinys.platform.upms.api.req.GaoDeGetAddressReq;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import cn.qinys.platform.upms.api.req.GaoDeKeyPageReq;
 import cn.qinys.platform.upms.api.resp.GaoDeKeyPageResp;
 import cn.qinys.platform.upms.api.service.IGaoDeKeyService;
 import jakarta.servlet.http.HttpServletResponse;
+import jakarta.validation.Valid;
 import lombok.AllArgsConstructor;
 import org.springframework.web.bind.annotation.*;
 
@@ -56,7 +58,7 @@ public class GaoDeKeyController extends DevBaseController {
         query.setCurrent(1);
         query.setSize(5000);
         Page<GaoDeKeyPageResp> voPage = gaoDeKeyService.getPage(query);
-        List<ExcelElement> excelElements =new ArrayList<>();
+        List<ExcelElement> excelElements = new ArrayList<>();
         excelElements.add(new ExcelElement("key", "geoKey"));
         excelElements.add(new ExcelElement("日期", "date"));
         excelElements.add(new ExcelElement("使用量", "useCount"));
@@ -66,4 +68,17 @@ public class GaoDeKeyController extends DevBaseController {
         ExcelUtils.normalExport("高德key使用量统计", voPage.getRecords(), excelElements, response);
     }
 
+
+    /**
+     * 网关日志分页
+     *
+     * @return
+     */
+    @PostMapping("/address")
+    public Result<String> getAddressByAltitudeAndLongitude(@RequestBody @Valid GaoDeGetAddressReq req) {
+        String address = gaoDeKeyService.getAddress(req);
+        return new Result<>(address);
+    }
+
+
 }

+ 22 - 0
wishing-platform/platform-service/platform-service-upms/src/main/java/cn/qinys/platform/upms/api/mapper/CommonGeoKeyMapper.java

@@ -0,0 +1,22 @@
+package cn.qinys.platform.upms.api.mapper;
+
+import cn.qinys.platform.entity.upms.CommonGeoKey;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+import org.apache.ibatis.annotations.Mapper;
+import org.springframework.stereotype.Repository;
+
+
+/**
+ * 高德逆地理解析key(CommonGeoKey)表数据库访问层
+ *
+ * @author makejava
+ * @since 2024-04-17 14:44:06
+ */
+ @Repository
+ @Mapper
+public interface CommonGeoKeyMapper extends BaseMapper<CommonGeoKey>{
+
+
+}
+

+ 23 - 0
wishing-platform/platform-service/platform-service-upms/src/main/java/cn/qinys/platform/upms/api/req/GaoDeGetAddressReq.java

@@ -0,0 +1,23 @@
+package cn.qinys.platform.upms.api.req;
+
+import jakarta.validation.constraints.NotNull;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * Description:
+ *
+ * @author tanlie
+ * Date: 2024/2/27 8:42
+ */
+@Data
+public class GaoDeGetAddressReq implements Serializable {
+    @NotNull(message = "longitude can not be null")
+    private BigDecimal longitude;
+
+    @NotNull(message = "latitude can not be null")
+    private BigDecimal latitude;
+
+}

+ 8 - 0
wishing-platform/platform-service/platform-service-upms/src/main/java/cn/qinys/platform/upms/api/service/IGaoDeKeyService.java

@@ -1,5 +1,6 @@
 package cn.qinys.platform.upms.api.service;
 
+import cn.qinys.platform.upms.api.req.GaoDeGetAddressReq;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import cn.qinys.platform.upms.api.req.GaoDeKeyPageReq;
 import cn.qinys.platform.upms.api.resp.GaoDeKeyPageResp;
@@ -19,4 +20,11 @@ public interface IGaoDeKeyService {
      * @return
      */
     Page<GaoDeKeyPageResp> getPage(GaoDeKeyPageReq req);
+
+    /**
+     * get address
+     * @param req
+     * @return
+     */
+    String getAddress(GaoDeGetAddressReq req);
 }

+ 106 - 5
wishing-platform/platform-service/platform-service-upms/src/main/java/cn/qinys/platform/upms/api/service/impl/GaoDeKeyServiceImpl.java

@@ -1,15 +1,27 @@
 package cn.qinys.platform.upms.api.service.impl;
 
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import cn.qinys.platform.base.exceptions.BizException;
+import cn.qinys.platform.base.utils.DateUtils;
+import cn.qinys.platform.base.utils.RedisUtils;
 import cn.qinys.platform.entity.upms.CommonGeoCount;
+import cn.qinys.platform.entity.upms.CommonGeoKey;
 import cn.qinys.platform.upms.api.mapper.CommonGeoCountMapper;
+import cn.qinys.platform.upms.api.mapper.CommonGeoKeyMapper;
+import cn.qinys.platform.upms.api.req.GaoDeGetAddressReq;
 import cn.qinys.platform.upms.api.req.GaoDeKeyPageReq;
 import cn.qinys.platform.upms.api.resp.GaoDeKeyPageResp;
 import cn.qinys.platform.upms.api.service.IGaoDeKeyService;
-import lombok.AllArgsConstructor;
+import com.alibaba.fastjson2.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import jakarta.annotation.Resource;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
+import org.springframework.web.client.RestTemplate;
+
+import java.math.BigDecimal;
+import java.util.Date;
 
 /**
  * Description:
@@ -17,11 +29,20 @@ import org.springframework.util.StringUtils;
  * @author tanlie
  * Date: 2024/7/8 8:54
  */
+@Slf4j
 @Service
-@AllArgsConstructor
 public class GaoDeKeyServiceImpl implements IGaoDeKeyService {
 
-    private final CommonGeoCountMapper countMapper;
+    @Resource
+    private CommonGeoCountMapper countMapper;
+    @Resource
+    private CommonGeoKeyMapper geoKeyMapper;
+    @Resource
+    private RestTemplate restTemplate;
+    @Resource
+    RedisUtils redisUtils;
+    @Resource
+    CommonGeoCountMapper geoCountMapper;
 
     @Override
     public Page<GaoDeKeyPageResp> getPage(GaoDeKeyPageReq req) {
@@ -33,4 +54,84 @@ public class GaoDeKeyServiceImpl implements IGaoDeKeyService {
         wrapper.orderByDesc("id");
         return countMapper.selectCountPage(page, wrapper);
     }
+
+    @Override
+    public String getAddress(GaoDeGetAddressReq req) {
+        return this.getGaoDeResult("", req.getLongitude(), req.getLatitude(), 0);
+    }
+
+
+    private String getGaoDeResult(String key, BigDecimal lon, BigDecimal lat, Integer index) {
+        if (index >= 100) {
+            return null;
+        }
+
+        CommonGeoKey geoKey = this.getGaoDeKey();
+        index++;
+        String url = "https://restapi.amap.com/v3/geocode/regeo?key={0}&location={1},{2}";
+        JSONObject res = restTemplate.getForObject(url, JSONObject.class, geoKey.getGeoKey(), lon, lat);
+        if (res == null) {
+            throw new BizException("逆地理解释出现错误");
+        }
+        if ("1".equals(res.getString("status"))) {
+            log.info("获取逆地理解析信息成功{}", res);
+            JSONObject regeocode = res.getJSONObject("regeocode");
+            String address = regeocode.getString("formatted_address");
+            this.countKeyUsage(geoKey.getGeoKey());
+            return address;
+        } else {
+            return this.getGaoDeResult(geoKey.getGeoKey(), lon, lat, index);
+        }
+    }
+
+
+    private CommonGeoKey getGaoDeKey() {
+        QueryWrapper<CommonGeoKey> wrapper = new QueryWrapper<>();
+        wrapper.orderByAsc("update_time", "id");
+        wrapper.last("LIMIT 1");
+        return geoKeyMapper.selectOne(wrapper);
+    }
+
+    private void countKeyUsage(String key) {
+        String lockKey = this.getClass() + ":" + key;
+        String lockValue = "gao de key count lock is being used";
+        boolean hasKey = false;
+        for (int i = 0; i < 5; i++) {
+            hasKey = redisUtils.tryLock(lockKey, lockValue);
+            if (hasKey) {
+                break;
+            }
+            try {
+                Thread.sleep(1000L);
+            } catch (Exception ignored) {
+            }
+        }
+        // 多次获取不到key,放弃统计
+        if (!hasKey) {
+            return;
+        }
+        try {
+            String date = DateUtils.dateFormatter(new Date(), "yyyy-MM-dd");
+            QueryWrapper<CommonGeoCount> wrapper = new QueryWrapper<>();
+            wrapper.eq("date", date);
+            wrapper.eq("geo_key", key);
+            wrapper.last("LIMIT 1");
+            CommonGeoCount exit = geoCountMapper.selectOne(wrapper);
+            if (exit != null) {
+                exit.setUseCount(exit.getUseCount() + 1);
+                exit.setUpdateTime(new Date());
+                geoCountMapper.updateById(exit);
+                return;
+            }
+            CommonGeoCount count = new CommonGeoCount();
+            count.setGeoKey(key);
+            count.setDate(date);
+            count.setUseCount(1);
+            count.setCreateTime(new Date());
+            count.setUpdateTime(new Date());
+            geoCountMapper.insert(count);
+        } finally {
+            redisUtils.unlock(lockKey, lockValue);
+        }
+    }
 }