From e11362ca4849da567a77d8b5e5be510df9fb0741 Mon Sep 17 00:00:00 2001
From: hjl <1657978663@qq.com>
Date: 星期一, 17 六月 2024 11:51:51 +0800
Subject: [PATCH] fix: 学习端bug

---
 ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/TGoodsController.java |   77 ++++++++++++++++++++++++--------------
 1 files changed, 49 insertions(+), 28 deletions(-)

diff --git a/ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/TGoodsController.java b/ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/TGoodsController.java
index dd26251..0cfcc7b 100644
--- a/ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/TGoodsController.java
+++ b/ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/TGoodsController.java
@@ -3,7 +3,9 @@
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.common.core.constant.Constants;
 import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.exception.GlobalException;
 import com.ruoyi.common.core.utils.bean.BeanUtils;
 import com.ruoyi.common.core.web.page.PageInfo;
 import com.ruoyi.common.security.service.TokenService;
@@ -16,6 +18,7 @@
 import com.ruoyi.goods.vo.TOrderVO;
 import com.ruoyi.study.api.domain.TUser;
 import com.ruoyi.study.api.feignClient.StudyClient;
+import com.ruoyi.system.api.model.LoginUserParent;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
@@ -95,12 +98,11 @@
     }
 
     @PostMapping("/goodListStudy")
-    @ApiOperation(value = "商品列表查询", tags = {"学习端"})
+    @ApiOperation(value = "商品列表查询", tags = {"学习端-商城"})
     public R<PageInfo<TGoods>> goodListStudy(@RequestBody GoodQueryDTO goodQuery) {
         if (tokenService.getLoginUserStudy() == null) {
             return R.tokenError("登录失效");
         }
-        List<String> type = goodQuery.getType();
         String keywords = goodQuery.getKeywords();
         // 初始化条件构造器
         QueryWrapper<TGoods> wrapper = new QueryWrapper<>();
@@ -108,7 +110,6 @@
 
         // 类型匹配 todo
         if (goodQuery.getType() != null && goodQuery.getType().size() > 0) {
-            StringBuilder temp = new StringBuilder("");
             for (String s : goodQuery.getType()) {
                 wrapper.or().apply("FIND_IN_SET('" + s + "', typeIds)"); // 将每个类型 ID 应用于 FIND_IN_SET 函数
             }
@@ -224,7 +225,7 @@
     @GetMapping("/exchangeRecordParent")
     @ApiOperation(value = "家长端-兑换记录", tags = {"家长端-兑换记录"})
     public R<Page<TOrder>> exchangeRecordParent(Integer pageNumber, Integer pageSize) {
-        if (tokenService.getLoginUser1() == null){
+        if (tokenService.getLoginUser1() == null) {
             return R.tokenError("登录失效");
         }
         Page<TOrder> page = orderService.page(new Page<>(pageNumber, pageSize), new QueryWrapper<TOrder>().eq("userId", tokenService.getLoginUser1().getUserid())
@@ -235,7 +236,7 @@
             tOrder.setName(byId.getName());
             tOrder.setImg(byId.getCoverImg());
             StringBuilder stringBuilder = new StringBuilder();
-            if (StringUtils.hasLength(byId.getTypeIds())){
+            if (StringUtils.hasLength(byId.getTypeIds())) {
                 String[] split = byId.getTypeIds().split(",");
                 for (String s : split) {
                     TGoodsType byId1 = goodsTypeService.getById(s);
@@ -321,7 +322,7 @@
         // 如果设置为默认地址 那么要将之前的默认地址取消掉
         List<Recipient> userId = recipientService.list(new QueryWrapper<Recipient>()
                 .eq("userId", tokenService.getLoginUser1().getUserid())
-                .ne("id",byId.getId()));
+                .ne("id", byId.getId()));
         for (Recipient recipient1 : userId) {
             recipient1.setIsDefault(0);
             recipientService.updateById(recipient1);
@@ -339,16 +340,17 @@
             @ApiImplicitParam(value = "地址id", name = "id", dataType = "String", required = true)
     })
     public R setDefaultStudy(@RequestParam Integer id) {
-        if (tokenService.getLoginUserStudy() == null) {
-            return R.tokenError("登录失效");
+        LoginUserParent userStudy = tokenService.getLoginUserStudy();
+        if (null == userStudy) {
+            return R.tokenError("登录失效!");
         }
         Recipient byId = recipientService.getById(id);
         byId.setIsDefault(1);
         recipientService.updateById(byId);
         // 如果设置为默认地址 那么要将之前的默认地址取消掉
         List<Recipient> userId = recipientService.list(new QueryWrapper<Recipient>()
-                .eq("userId", tokenService.getLoginUser1().getUserid())
-                .ne("id",byId.getId()));
+                .eq("userId", userStudy.getUserid())
+                .ne("id", byId.getId()));
         for (Recipient recipient1 : userId) {
             recipient1.setIsDefault(0);
             recipientService.updateById(recipient1);
@@ -417,18 +419,21 @@
     @ApiOperation(value = "新增收货地址/修改收货地址", tags = {"学习端-收货地址"})
     @ApiOperationSupport(order = 33)
     public R<String> addressSave(@RequestBody Recipient recipient) {
+        LoginUserParent userStudy = tokenService.getLoginUserStudy();
+        if (null == userStudy) {
+            return R.tokenError("登录失效!");
+        }
         recipient.setUserId(tokenService.getLoginUserStudy().getUserid());
-        if (recipient.getIsDefault() == 1){
+        if (recipient.getIsDefault() == 1) {
             // 如果设置为默认地址 那么要将之前的默认地址取消掉
             List<Recipient> userId = recipientService.list(new QueryWrapper<Recipient>()
-                    .eq("userId", tokenService.getLoginUser1().getUserid()));
+                    .eq("userId", userStudy.getUserid()));
             for (Recipient recipient1 : userId) {
                 recipient1.setIsDefault(0);
                 recipientService.updateById(recipient1);
             }
         }
-        recipientService.addressSaveOrUpdate(recipient);
-        return R.ok();
+        return recipientService.addressSaveOrUpdate(recipient) ? R.ok() : R.fail();
     }
 
     /**
@@ -438,12 +443,12 @@
     @ApiOperation(value = "家长端-新增收货地址/修改收货地址", tags = {"家长端-新增收货地址/修改收货地址"})
     @ApiOperationSupport(order = 20)
     public R<String> addressSaveOrUpdateParent(@RequestBody Recipient recipient) {
-        if (tokenService.getLoginUser1() == null){
+        if (tokenService.getLoginUser1() == null) {
             return R.tokenError("登录失效!");
         }
         recipient.setUserId(tokenService.getLoginUser1().getUserid());
-        if (recipient.getId() != null){
-            if (recipient.getIsDefault() == 1){
+        if (recipient.getId() != null) {
+            if (recipient.getIsDefault() == 1) {
                 // 如果设置为默认地址 那么要将之前的默认地址取消掉
                 List<Recipient> userId = recipientService.list(new QueryWrapper<Recipient>()
                         .eq("userId", tokenService.getLoginUser1().getUserid()));
@@ -453,8 +458,8 @@
                 }
             }
             recipientService.updateById(recipient);
-        }else{
-            if (recipient.getIsDefault() == 1){
+        } else {
+            if (recipient.getIsDefault() == 1) {
                 // 如果设置为默认地址 那么要将之前的默认地址取消掉
                 List<Recipient> userId = recipientService.list(new QueryWrapper<Recipient>()
                         .eq("userId", tokenService.getLoginUser1().getUserid()));
@@ -543,16 +548,26 @@
     @GetMapping("/updateOrderAddress")
     @ApiOperation(value = "修改订单收货地址", tags = {"学习端-收货地址"})
     @ApiOperationSupport(order = 36)
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "订单id", name = "orderId", dataType = "String", required = true),
+            @ApiImplicitParam(value = "地址信息id", name = "recipientId", dataType = "String", required = true)
+    })
     public R updateOrderAddress(@RequestParam Integer orderId, @RequestParam Integer recipientId) {
         if (tokenService.getLoginUserStudy() == null) {
             return R.tokenError("登录失效");
         }
-        Recipient userId = recipientService.getById(recipientId);
-        TOrder byId = orderService.getById(orderId);
-        byId.setConsigneeName(userId.getAddress());
-        byId.setConsigneePhone(userId.getRecipientPhone());
-        byId.setConsigneeAddress(userId.getAddress());
-        orderService.updateById(byId);
+        Recipient recipient = recipientService.getById(recipientId);
+        TOrder order = orderService.getById(orderId);
+        if (null == order) {
+            throw new GlobalException("订单不存在!");
+        }
+        if (!Constants.ONE.equals(order.getState())) {
+            throw new GlobalException("订单已发货,无法修改收货地址!");
+        }
+        order.setConsigneeName(recipient.getAddress());
+        order.setConsigneePhone(recipient.getRecipientPhone());
+        order.setConsigneeAddress(recipient.getAddress());
+        orderService.updateById(order);
         return R.ok();
     }
 
@@ -584,7 +599,7 @@
     @ApiOperation(value = "商品分类列表", tags = {"学习端-商城"})
     @ApiOperationSupport(order = 39)
     public R<List<TGoodsType>> goodTypeStudy() {
-        return R.ok(goodsTypeService.lambdaQuery().eq(TGoodsType::getIsDelete, 0).eq(TGoodsType::getIsDelete, 0).list());
+        return R.ok(goodsTypeService.lambdaQuery().eq(TGoodsType::getIsDelete, 0).list());
     }
 
     /**
@@ -601,6 +616,9 @@
     public R<GoodDetailVO> goodDetail(@RequestParam String goodId) {
         // 商品详情
         TGoods goods = goodsService.lambdaQuery().eq(TGoods::getId, goodId).one();
+        if (null == goods) {
+            throw new GlobalException("获取商品详情失败,商品不存在!");
+        }
         // 商品分类详情
         List<TGoodsType> goodsTypes = goodsTypeService.lambdaQuery().in(TGoodsType::getId, Arrays.asList(goods.getTypeIds().split(","))).list();
         // 已兑换人数
@@ -625,6 +643,9 @@
         }
         // 商品详情
         TGoods goods = goodsService.lambdaQuery().eq(TGoods::getId, goodId).one();
+        if (null == goods) {
+            throw new GlobalException("获取商品详情失败,商品不存在!");
+        }
         // 商品分类详情
         List<TGoodsType> goodsTypes = goodsTypeService.lambdaQuery().in(TGoodsType::getId, Arrays.asList(goods.getTypeIds().split(","))).list();
         // 已兑换人数
@@ -681,12 +702,12 @@
         Recipient recipient = recipientService.lambdaQuery()
                 .eq(Recipient::getUserId, tokenService.getLoginUser1().getUserid())
                 .eq(Recipient::getIsDefault, 1).one();
-        if (recipient == null){
+        if (recipient == null) {
             // 随便取一条地址数据
             List<Recipient> list = recipientService.lambdaQuery()
                     .eq(Recipient::getUserId, tokenService.getLoginUser1().getUserid())
                     .eq(Recipient::getIsDefault, 1).list();
-            if (!list.isEmpty()){
+            if (!list.isEmpty()) {
                 recipient = list.get(0);
             }
         }

--
Gitblit v1.7.1