From 00bb295cb094454c275cd2b220d9c46379c24bc2 Mon Sep 17 00:00:00 2001 From: dzq Date: Fri, 18 Apr 2025 15:55:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=85=B3=E8=81=94=E6=A0=BC=E5=8F=A3ID?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E5=BE=AE=E4=BF=A1=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在`shop_order_goods`表中添加`cell_id`字段,用于关联订单商品与柜子格口。同时优化微信授权逻辑,改进token提取与处理方式,并增加日志记录。此外,调整订单服务中柜子格口的验证逻辑,确保订单商品已绑定柜子格口。 --- .../api/controller/ShopController.java | 29 ++++++++++++------- .../shop/order/OrderApplicationService.java | 13 +++++---- .../shop/order/db/ShopOrderGoodsEntity.java | 4 +++ sql/20250328_return_approval.sql | 3 ++ 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/agileboot-api/src/main/java/com/agileboot/api/controller/ShopController.java b/agileboot-api/src/main/java/com/agileboot/api/controller/ShopController.java index ce85dd7..86bf867 100644 --- a/agileboot-api/src/main/java/com/agileboot/api/controller/ShopController.java +++ b/agileboot-api/src/main/java/com/agileboot/api/controller/ShopController.java @@ -67,23 +67,32 @@ public class ShopController { } @GetMapping("/wechatAuth") - public RedirectView wechatAuthRedirect(HttpServletRequest request, @RequestParam String token) { + public RedirectView wechatAuthRedirect(HttpServletRequest request) { /*java.util.StringJoiner joiner = new java.util.StringJoiner("&"); request.getParameterMap().forEach((key, values) -> { joiner.add(key + "=" + String.join(",", values)); + log.info("wechatAuth key: {} value: {}", key, values[0]); }); log.info("wechatAuth 参数:{}", joiner.toString());*/ - String state = ""; - if (StringUtils.isNoneBlank(token)) { - state = "token_" + token; - } - /*try { - state = URLEncoder.encode(state, StandardCharsets.UTF_8.name()); - } catch (UnsupportedEncodingException e) { - log.error("wechatAuth 编码失败", e); - }*/ + // 从请求参数中提取包含token的参数名(参数名本身可能包含"token=") + String token = request.getParameterMap().keySet().stream() + .filter(key -> key.contains("token=")) + .findFirst().orElse(""); + log.info("wechatAuth token:{}", token); + String state = ""; + if (StringUtils.isNotBlank(token)) { + // 清洗token参数值(原参数名格式为"token=xxx") + token = token.replace("token=", ""); + // 构造带有token标识的state参数,用于授权后回传 + state = "token_" + token; + } else { + // 默认state参数,保持微信要求的标准格式 + state = "state"; + } + + // 构造微信网页授权URL String authUrl = "https://open.weixin.qq.com/connect/oauth2/authorize" + "?appid=" + WeixinConstants.appid + "&redirect_uri=http%3A%2F%2Fwxshop.ab98.cn%2Fshop" diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/shop/order/OrderApplicationService.java b/agileboot-domain/src/main/java/com/agileboot/domain/shop/order/OrderApplicationService.java index d1b5577..e62b9e7 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/shop/order/OrderApplicationService.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/shop/order/OrderApplicationService.java @@ -73,6 +73,7 @@ public class OrderApplicationService { throw new ApiException(ErrorCode.Client.COMMON_FORBIDDEN_TO_CALL, "订单状态不允许操作"); } + // 获取并验证订单商品信息 ShopOrderGoodsEntity goodsEntity = orderGoodsService.getById(orderGoodsId); if (null == goodsEntity || !orderId.equals(goodsEntity.getOrderId())) { throw new ApiException(ErrorCode.Client.COMMON_FORBIDDEN_TO_CALL, "订单商品不存在"); @@ -80,19 +81,19 @@ public class OrderApplicationService { if (goodsEntity.getStatus() != 1 && goodsEntity.getStatus()!= 5) { throw new ApiException(ErrorCode.Client.COMMON_FORBIDDEN_TO_CALL, "订单商品状态不允许操作"); } - - List cabinetCellEntityList = cabinetCellService.selectByGoodsId(goodsEntity.getGoodsId()); - if (null == cabinetCellEntityList || cabinetCellEntityList.isEmpty()) { - throw new ApiException(ErrorCode.Client.COMMON_FORBIDDEN_TO_CALL, "商品未绑定柜子"); + if (goodsEntity.getCellId() == null) { + throw new ApiException(ErrorCode.Client.COMMON_FORBIDDEN_TO_CALL, "订单商品未绑定柜子"); } - CabinetCellEntity cabinetCellEntity = cabinetCellEntityList.get(0); + // 获取柜子单元和智能柜信息 + CabinetCellEntity cabinetCellEntity = cabinetCellService.getById(goodsEntity.getCellId()); SmartCabinetEntity smartCabinet = smartCabinetService.getById(cabinetCellEntity.getCabinetId()); if (null == smartCabinet) { throw new ApiException(ErrorCode.Client.COMMON_FORBIDDEN_TO_CALL, "柜子不存在"); } - // 发送指令 + // 构造MQTT开柜指令: + // 指令格式:8A + 锁控编号(2位HEX) + 引脚号(2位HEX) + 操作码11 String mqttDate = "8A"; mqttDate += String.format("%02X", smartCabinet.getLockControlNo()); mqttDate += String.format("%02X", cabinetCellEntity.getPinNo()); diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/shop/order/db/ShopOrderGoodsEntity.java b/agileboot-domain/src/main/java/com/agileboot/domain/shop/order/db/ShopOrderGoodsEntity.java index b580afd..e4c0f23 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/shop/order/db/ShopOrderGoodsEntity.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/shop/order/db/ShopOrderGoodsEntity.java @@ -40,6 +40,10 @@ public class ShopOrderGoodsEntity extends BaseEntity { @TableField("goods_id") private Long goodsId; + @ApiModelProperty("关联格口ID") + @TableField("cell_id") + private Long cellId; + @ApiModelProperty("购买数量") @TableField("quantity") private Integer quantity; diff --git a/sql/20250328_return_approval.sql b/sql/20250328_return_approval.sql index 4992aa6..edfa6ca 100644 --- a/sql/20250328_return_approval.sql +++ b/sql/20250328_return_approval.sql @@ -69,3 +69,6 @@ ADD COLUMN `userid` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_c ALTER TABLE `shop_order` ADD COLUMN `name` varchar(30) DEFAULT NULL COMMENT '成员名称' AFTER `mobile`; + +ALTER TABLE `shop_order_goods` +ADD COLUMN `cell_id` BIGINT NULL COMMENT '格口ID' AFTER `goods_id`; \ No newline at end of file