From 2c7e87daa7aef11b9fcb5885832c4f59f4766263 Mon Sep 17 00:00:00 2001 From: aiShuiJiaoDeXioShou <2832294398@qq.com> Date: Thu, 19 Sep 2024 08:02:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E7=AB=AF=E6=A8=A1=E5=9D=97=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/handler/DefaultDBFieldHandler.java | 2 +- .../controller/ChinaAddressController.java | 19 ++++++++++++------- .../app/address/entity/ChinaAddress.java | 4 ++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/yskj-framework/yskj-spring-boot-starter-mybatis/src/main/java/cn/yskj/linghe/framework/mybatis/core/handler/DefaultDBFieldHandler.java b/yskj-framework/yskj-spring-boot-starter-mybatis/src/main/java/cn/yskj/linghe/framework/mybatis/core/handler/DefaultDBFieldHandler.java index 5306f52..971cd13 100644 --- a/yskj-framework/yskj-spring-boot-starter-mybatis/src/main/java/cn/yskj/linghe/framework/mybatis/core/handler/DefaultDBFieldHandler.java +++ b/yskj-framework/yskj-spring-boot-starter-mybatis/src/main/java/cn/yskj/linghe/framework/mybatis/core/handler/DefaultDBFieldHandler.java @@ -45,7 +45,7 @@ public class DefaultDBFieldHandler implements MetaObjectHandler { // 更新userId 字段 if (userId != null) { - var loginUserId = String.valueOf(SecurityFrameworkUtils.getLoginUserId()); + var loginUserId = SecurityFrameworkUtils.getLoginUserId(); if (metaObject.hasSetter("userId")) { // 检查是否存在 userId 字段 Object userIdValue = metaObject.getValue("userId"); // 仅当 userId 为 null 时设置新值,防止覆盖已存在的值 diff --git a/yskj-module-acdr/yskj-module-acdr-biz/src/main/java/cn/yskj/linghe/module/acdr/controller/app/address/controller/ChinaAddressController.java b/yskj-module-acdr/yskj-module-acdr-biz/src/main/java/cn/yskj/linghe/module/acdr/controller/app/address/controller/ChinaAddressController.java index 252638c..e45b836 100644 --- a/yskj-module-acdr/yskj-module-acdr-biz/src/main/java/cn/yskj/linghe/module/acdr/controller/app/address/controller/ChinaAddressController.java +++ b/yskj-module-acdr/yskj-module-acdr-biz/src/main/java/cn/yskj/linghe/module/acdr/controller/app/address/controller/ChinaAddressController.java @@ -2,12 +2,14 @@ package cn.yskj.linghe.module.acdr.controller.app.address.controller; import cn.yskj.linghe.module.acdr.api.AuthApi; import cn.hutool.http.HttpUtil; -import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import cn.yskj.linghe.module.acdr.controller.app.address.service.ChinaAddressService; import cn.yskj.linghe.module.acdr.controller.app.address.entity.ChinaAddress; import cn.yskj.linghe.module.acdr.controller.app.address.mapper.ChinaAddressMapper; import cn.yskj.linghe.module.acdr.common.response.GlobalResponse; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import jakarta.annotation.Resource; @@ -71,20 +73,23 @@ public class ChinaAddressController { String address = param.getProvince() + param.getCity() + param.getDetailAddress(); String res = HttpUtil.get(urlGeo+"?key=%s&address=%s".formatted(amapkey, address)); // 解析res json 数据 - JSONObject resMap = JSONUtil.parseObj(res); + JSONObject resMap = JSON.parseObject(res); if(resMap.isEmpty()) { return GlobalResponse.failure("服务错误,请联系管理人员修复!"); } - if(resMap.get("status", Integer.class) == 1) { + if(resMap.getString("status").equals("1")) { + JSONArray geocodes = resMap.getJSONArray("geocodes"); + JSONObject obj = geocodes.getJSONObject(0); + String location = obj.getString("location"); // 获取经纬度信息 - String[] locations = resMap.get("location", String.class).split(","); - param.setLongitude(Long.parseLong(locations[0])); - param.setLatitude(Long.parseLong(locations[1])); + String[] locations = location.split(","); + param.setLongitude(locations[0]); + param.setLatitude(locations[1]); } else { return GlobalResponse.failure("错误地址信息无法添加,"+resMap.get("info")+"!"); } service.save(param); - return GlobalResponse.success("中国地址表新增成功!"); + return GlobalResponse.success("新增地址成功!"); } @ApiOperation(value = "中国地址表修改") diff --git a/yskj-module-acdr/yskj-module-acdr-biz/src/main/java/cn/yskj/linghe/module/acdr/controller/app/address/entity/ChinaAddress.java b/yskj-module-acdr/yskj-module-acdr-biz/src/main/java/cn/yskj/linghe/module/acdr/controller/app/address/entity/ChinaAddress.java index db6ee2b..77bff6d 100644 --- a/yskj-module-acdr/yskj-module-acdr-biz/src/main/java/cn/yskj/linghe/module/acdr/controller/app/address/entity/ChinaAddress.java +++ b/yskj-module-acdr/yskj-module-acdr-biz/src/main/java/cn/yskj/linghe/module/acdr/controller/app/address/entity/ChinaAddress.java @@ -96,11 +96,11 @@ public class ChinaAddress extends ExtendEntity implements Serializable { @ApiModelProperty("经度") @TableField(value = "latitude") - private Long latitude; + private String latitude; @ApiModelProperty("纬度") @TableField(value = "longitude") - private Long longitude; + private String longitude; @ApiModelProperty("是否为默认地址") @TableField("is_default")