From 6c3f781630bc0c559ceca1a69d4c9e7e33e5daf1 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期二, 23 九月 2025 17:47:32 +0800 Subject: [PATCH] 修改bug --- ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/controller/console/ShopController.java | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/controller/console/ShopController.java b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/controller/console/ShopController.java index c922714..439951f 100644 --- a/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/controller/console/ShopController.java +++ b/ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/controller/console/ShopController.java @@ -169,12 +169,19 @@ } @PostMapping("/getShopByUserId") - public R<ShopRelUserVo> getShopByUserId(@RequestBody Long userId) - { + public R<ShopRelUserVo> getShopByUserId(@RequestBody Long userId) { + System.err.println("查询商户的用户id:" + userId); List<ShopRelUser> shopRelUser = shopRelUserService.getByUserId(userId); Optional.ofNullable(shopRelUser).orElseThrow(() -> new ServiceException("未查询到用户关联商户")); ShopRelUserVo shopRelUserVo = new ShopRelUserVo(); - ShopRelUser shopRelUser1 = shopRelUser.stream().filter(s -> s.getIsDefault() == 1).collect(Collectors.toList()).get(0); + Optional<ShopRelUser> first = shopRelUser.stream().filter(s -> s.getIsDefault() == 1).findFirst(); + ShopRelUser shopRelUser1 = null; + if(first.isPresent()){ + shopRelUser1 = first.get(); + } + if(null == shopRelUser1){ + shopRelUser1 = shopRelUser.get(0); + } shopRelUserVo.setShopId(shopRelUser1.getShopId()); shopRelUserVo.setUserName(shopRelUser1.getUserName()); Shop shop = shopService.getById(shopRelUser1.getShopId()); -- Gitblit v1.7.1