From fafae77d59bc333a11c6b43e8f8606e190341e4a Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期二, 10 六月 2025 16:53:13 +0800
Subject: [PATCH] 部分代码

---
 ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/TGoodsController.java |  757 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 694 insertions(+), 63 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 12d46fe..c87a3ae 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
@@ -1,34 +1,41 @@
 package com.ruoyi.goods.controller;
+import java.util.Date;
 
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.ruoyi.common.core.constant.Constants;
 import com.ruoyi.common.core.domain.R;
-import com.ruoyi.common.core.web.domain.AjaxResult;
+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;
 import com.ruoyi.goods.domain.*;
 import com.ruoyi.goods.dto.*;
 import com.ruoyi.goods.service.*;
+import com.ruoyi.goods.vo.ExchangeRecordVO;
 import com.ruoyi.goods.vo.GoodDetailVO;
 import com.ruoyi.goods.vo.TGoodsVO;
 import com.ruoyi.goods.vo.TOrderVO;
 import com.ruoyi.study.api.domain.TUser;
 import com.ruoyi.study.api.feignClient.StudyClient;
+import com.ruoyi.study.api.vo.UserPersonalCenterVO;
+import com.ruoyi.system.api.model.LoginUserParent;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
-import org.springframework.beans.BeanUtils;
+import io.swagger.annotations.ApiOperationSupport;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.StringUtils;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -53,7 +60,38 @@
     private IRegionService regionService;
     @Resource
     private TokenService tokenService;
-
+    @PostMapping("/testAddData")
+    @ApiOperation(value = "测试分片", tags = {"测试分片"})
+    public R<Object> testAddData() {
+        TOrder tOrder = new TOrder();
+        tOrder.setOrderNumber("");
+        tOrder.setUserId(63);
+        tOrder.setInsertTime(new Date());
+        tOrder.setGoodsId(0);
+        tOrder.setCount(0);
+        tOrder.setState(0);
+        tOrder.setExpress("");
+        tOrder.setExpressNumber("");
+        tOrder.setExpressTime(new Date());
+        tOrder.setIntegral(0);
+        tOrder.setCompleteTime(new Date());
+        tOrder.setConsigneeName("");
+        tOrder.setImg("");
+        tOrder.setName("");
+        tOrder.setType("");
+        tOrder.setConsigneePhone("");
+        tOrder.setConsigneeAddress("");
+        tOrder.setProvince("");
+        tOrder.setCity("");
+        tOrder.setRemark("");
+        tOrder.setDisabled(false);
+        tOrder.setCreateBy("");
+        tOrder.setCreateTime(new Date());
+        tOrder.setUpdateBy("");
+        tOrder.setUpdateTime(new Date());
+        orderService.save(tOrder);
+        return R.ok();
+    }
     @PostMapping("/listType")
     @ApiOperation(value = "列表查询", tags = {"后台-商品类型管理"})
     public R<PageInfo<TGoodsType>> listType(@RequestBody GoodsTypeQuery query) {
@@ -70,16 +108,59 @@
     }
 
     @PostMapping("/goodList")
-    @ApiOperation(value = "商品列表查询", tags = {"学习端-商品列表"})
+    @ApiOperation(value = "商品列表查询", tags = {"家长端-商品列表"})
     public R<PageInfo<TGoods>> listType(@RequestBody GoodQueryDTO goodQuery) {
-        List<String> type = goodQuery.getType();
+        if (tokenService.getLoginUser1() == null) {
+            return R.tokenError("登录失效");
+        }
         String keywords = goodQuery.getKeywords();
         // 初始化条件构造器
         QueryWrapper<TGoods> wrapper = new QueryWrapper<>();
-        wrapper = keywords != null && "".equals(keywords.trim()) ? wrapper.like("name", keywords) : wrapper;
+        wrapper = keywords != null && !"".equals(keywords.trim()) ? wrapper.like("name", keywords) : wrapper;
+
         // 类型匹配 todo
-        wrapper = type.isEmpty() ? wrapper : wrapper.in("");
+        if (goodQuery.getType() != null && goodQuery.getType().size() > 0) {
+            for (int i = 0; i < goodQuery.getType().size(); i++) {
+//                if (i == 0){
+//                    wrapper.apply("FIND_IN_SET('" + goodQuery.getType().get(i) + "', typeIds)"); // 将每个类型 ID 应用于 FIND_IN_SET 函数
+//                }else{
+                    wrapper.or().apply("FIND_IN_SET('" + goodQuery.getType().get(i) + "', typeIds)"); // 将每个类型 ID 应用于 FIND_IN_SET 函数
+//                }
+            }
+        }
         wrapper.eq("isDelete", 0);
+        // sort排序
+        wrapper.orderByAsc("CASE WHEN sort IS NULL THEN 1 ELSE 0 END")
+                .orderByAsc("sort")
+                .orderByDesc("createTime");
+        return R.ok(goodsService.page(new PageInfo<>(goodQuery.getPageNumber(), goodQuery.getPageSize()), wrapper));
+    }
+
+    @PostMapping("/goodListStudy")
+    @ApiOperation(value = "商品列表查询", tags = {"学习端-商城"})
+    public R<PageInfo<TGoods>> goodListStudy(@RequestBody GoodQueryDTO goodQuery) {
+        if (tokenService.getLoginUserStudy() == null) {
+            return R.tokenError("登录失效");
+        }
+        String keywords = goodQuery.getKeywords();
+        // 初始化条件构造器
+        QueryWrapper<TGoods> wrapper = new QueryWrapper<>();
+        wrapper = keywords != null && !"".equals(keywords.trim()) ? wrapper.like("name", keywords) : wrapper;
+        // 类型匹配 todo
+        if (goodQuery.getType() != null && goodQuery.getType().size() > 0) {
+            for (int i = 0; i < goodQuery.getType().size(); i++) {
+                if (i == 0){
+                    wrapper.apply("FIND_IN_SET('" + goodQuery.getType().get(i) + "', typeIds)"); // 将每个类型 ID 应用于 FIND_IN_SET 函数
+                }else{
+                    wrapper.or().apply("FIND_IN_SET('" + goodQuery.getType().get(i) + "', typeIds)"); // 将每个类型 ID 应用于 FIND_IN_SET 函数
+                }
+            }
+        }
+        wrapper.eq("isDelete", 0);
+        // sort排序
+        wrapper.orderByAsc("CASE WHEN sort IS NULL THEN 1 ELSE 0 END")
+                .orderByDesc("sort")
+                .orderByDesc("createTime");
         return R.ok(goodsService.page(new PageInfo<>(goodQuery.getPageNumber(), goodQuery.getPageSize()), wrapper));
     }
 
@@ -100,6 +181,15 @@
     @PostMapping("/deleteGoodsType/{id}")
     @ApiOperation(value = "删除", tags = {"后台-商品类型管理"})
     public R deleteGoodsType(@PathVariable("id") Integer id) {
+        // 初始化条件构造器
+        QueryWrapper<TGoods> wrapper = new QueryWrapper<>();
+        // 类型匹配 todo
+        wrapper.or().apply("FIND_IN_SET('" + id + "', typeIds)"); // 将每个类型 ID 应用于 FIND_IN_SET 函数
+        wrapper.eq("isDelete", 0);
+        List<TGoods> list = goodsService.list(wrapper);
+        if (!list.isEmpty()) {
+            return R.fail("当前商品分类被使用,无法删除!");
+        }
         TGoodsType byId = goodsTypeService.getById(id);
         byId.setIsDelete(1);
         goodsTypeService.removeById(byId);
@@ -116,9 +206,27 @@
         wrapper.orderByDesc("id");
         List<TGoods> list = goodsService.list(wrapper);
         for (TGoods tGoods : list) {
-            long goodsId = orderService.count(new QueryWrapper<TOrder>().eq("goodsId", tGoods.getId()));
-            tGoods.setInventory(goodsId);
+            Long temp = 0L;
+            List<TOrder> list1 = orderService.list(new QueryWrapper<TOrder>().eq("goodsId", tGoods.getId()));
+            for (TOrder tOrder : list1) {
+                temp += tOrder.getCount();
+            }
+            tGoods.setInventory(temp);
+            // 剩余兑换数量
+            Integer residueNumber = null;
+            if (null != tGoods.getTotal()) {
+                // 计算剩余兑换数量
+                List<TOrder> orderList = orderService.lambdaQuery().eq(TOrder::getGoodsId, tGoods)
+                        .eq(TOrder::getDisabled, 0).list();
+                Integer item = 0;
+                for (TOrder order : orderList) {
+                    item += order.getCount();
+                }
+                residueNumber = tGoods.getTotal() - item;
+                tGoods.setSurplus(residueNumber);
+            }
         }
+
         PageInfo<TGoods> res = new PageInfo<>(query.getPageNumber(), query.getPageSize());
         res.setRecords(list);
         return R.ok(res);
@@ -127,6 +235,11 @@
     @PostMapping("/addGoods")
     @ApiOperation(value = "添加", tags = {"后台-商品管理"})
     public R addGoods(@RequestBody TGoods dto) {
+        if (dto.getTotal() != null) {
+            dto.setSurplus(dto.getTotal());
+        } else {
+            dto.setSurplus(0);
+        }
         goodsService.save(dto);
         return R.ok("添加成功");
     }
@@ -142,7 +255,22 @@
     @PostMapping("/updateGoods")
     @ApiOperation(value = "修改", tags = {"后台-商品管理"})
     public R updateGoods(@RequestBody TGoods dto) {
+        TGoods byId = goodsService.getById(dto.getId());
+        if (byId.getTotal()!=null && dto.getTotal()!=null &&!Objects.equals(byId.getTotal(), dto.getTotal())){
+            // 如果修改了商品总数 那么需要再判断当前商品已被购买了多少
+            List<TOrder> list = orderService.list(new QueryWrapper<TOrder>()
+                    .eq("goodsId", dto.getId()));
+            Integer temp = 0;
+            for (TOrder tOrder : list) {
+                temp += tOrder.getCount();
+            }
+            if (dto.getTotal()<temp){
+                return R.fail("商品总数不能小于当前商品已兑换数量,"+"当前商品已兑换数量为:"+temp);
+            }
+        }
         goodsService.updateById(dto);
+        goodsService.updateOne(dto);
+
         return R.ok("修改成功");
     }
 
@@ -169,32 +297,215 @@
      * 兑换记录
      */
     @GetMapping("/exchangeRecord")
-    @ApiOperation(value = "兑换记录", tags = {"兑换记录"})
-    public R<List<TOrder>> exchangeRecord() {
-        return R.ok(orderService.lambdaQuery().eq(TOrder::getUserId, tokenService.getLoginUserStudy().getUserid())
-                .orderByDesc(TOrder::getCreateTime).list());
+    @ApiOperation(value = "学习端-兑换记录", tags = {"学习端-商城"})
+    public R<PageInfo<ExchangeRecordVO>> exchangeRecord(Integer pageNumber,Integer pageSize) {
+        PageInfo<ExchangeRecordVO> res = new PageInfo<>(pageNumber, pageSize);
+        LoginUserParent loginUserStudy = tokenService.getLoginUserStudy();
+        if (null == loginUserStudy) {
+            return R.tokenError("登录失效!");
+        }
+        List<ExchangeRecordVO> exchangeRecord = orderService.exchangeRecord(res,tokenService.getLoginUserStudy().getUserid());
+        for (ExchangeRecordVO record : exchangeRecord) {
+            TGoods goods = goodsService.getById1(record.getGoodsId());
+            List<String> typeList;
+            if (null != goods) {
+                List<TGoodsType> goodsTypes = goodsTypeService.lambdaQuery().in(TGoodsType::getId, Arrays.stream(goods.getTypeIds().split(",")).collect(Collectors.toList()))
+                        .eq(TGoodsType::getIsDelete, 0).list();
+                typeList = goodsTypes.stream().map(TGoodsType::getName).collect(Collectors.toList());
+            } else {
+                typeList = new ArrayList<>();
+            }
+            record.setGoodsType(typeList);
+        }
+        res.setRecords(exchangeRecord);
+        res.setTotal(exchangeRecord.size());
+        return R.ok(res);
+    }
+
+    @GetMapping("/exchangeRecordParent")
+    @ApiOperation(value = "家长端-兑换记录", tags = {"家长端-兑换记录"})
+    public R<PageInfo<ExchangeRecordVO>> exchangeRecordParent(Integer pageNumber,Integer pageSize) {
+        PageInfo<ExchangeRecordVO> res = new PageInfo<>(pageNumber, pageSize);
+        if (tokenService.getLoginUser1() == null) {
+            return R.tokenError("登录失效");
+        }
+        List<ExchangeRecordVO> exchangeRecord = orderService.exchangeRecord(res,tokenService.getLoginUser1().getUserid());
+        for (ExchangeRecordVO record : exchangeRecord) {
+            TGoods goods = goodsService.getById1(record.getGoodsId());
+            List<String> typeList;
+            if (null != goods) {
+                List<TGoodsType> goodsTypes = goodsTypeService.lambdaQuery().in(TGoodsType::getId, Arrays.stream(goods.getTypeIds().split(",")).collect(Collectors.toList()))
+                        .eq(TGoodsType::getIsDelete, 0).list();
+                typeList = goodsTypes.stream().map(TGoodsType::getName).collect(Collectors.toList());
+            } else {
+                typeList = new ArrayList<>();
+            }
+            record.setGoodsType(typeList);
+        }
+        res.setRecords(exchangeRecord);
+        res.setTotal(exchangeRecord.size());
+        return R.ok(res);
     }
 
     /**
      * 兑换记录
      */
     @GetMapping("/confirm")
-    @ApiOperation(value = "确认收货", tags = {"兑换记录"})
+    @ApiOperation(value = "确认收货", tags = {"家长端-兑换记录"})
+    @ApiOperationSupport(order = 16)
     @ApiImplicitParams({
             @ApiImplicitParam(value = "订单id", name = "id", dataType = "String", required = true)
     })
-    public R<Boolean> confirm(@RequestParam Integer id) {
+    public R<Boolean> confirm(@RequestParam String id) {
+        if (tokenService.getLoginUser1() == null) {
+            return R.tokenError("登录失效");
+        }
         TOrder byId = orderService.getById(id);
+        byId.setUserId(null);
         byId.setState(3);
+        byId.setCompleteTime(new Date());
+        return R.ok(orderService.updateById(byId));
+    }
+
+    /**
+     * 兑换记录
+     */
+    @GetMapping("/confirmStudy")
+    @ApiOperation(value = "确认收货", tags = {"学习端-商城"})
+    @ApiOperationSupport(order = 29)
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "订单id", name = "id", dataType = "String", required = true)
+    })
+    public R<Boolean> confirmStudy(@RequestParam String id) {
+        if (tokenService.getLoginUserStudy() == null) {
+            return R.tokenError("登录失效");
+        }
+        TOrder byId = orderService.getById(id);
+        byId.setUserId(null);
+        byId.setState(3);
+        byId.setCompleteTime(new Date());
         return R.ok(orderService.updateById(byId));
     }
 
     /**
      * 获取用户收货地址
      */
+    @GetMapping("/shopAddressParent")
+    @ApiOperation(value = "获取用户收货地址", tags = {"家长端-获取用户收货地址"})
+    @ApiOperationSupport(order = 17)
+    public R<List<Recipient>> shopAddressParent() {
+        if (tokenService.getLoginUser1() == null) {
+            return R.tokenError("登录失效");
+        }
+        return R.ok(recipientService.lambdaQuery().eq(Recipient::getUserId,
+                tokenService.getLoginUser1().getUserid()).list());
+    }
+
+    /**
+     * 设置默认地址
+     */
+    @GetMapping("/setDefault")
+    @ApiOperation(value = "设置默认地址", tags = {"家长端-设置默认地址"})
+    @ApiOperationSupport(order = 18)
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "地址id", name = "id", dataType = "String", required = true)
+    })
+    public R setDefault(@RequestParam Integer id) {
+        if (tokenService.getLoginUser1() == null) {
+            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()));
+        for (Recipient recipient1 : userId) {
+            recipient1.setIsDefault(0);
+            recipientService.updateById(recipient1);
+        }
+        return R.ok();
+    }
+
+    /**
+     * 设置默认地址
+     */
+    @GetMapping("/setDefaultStudy")
+    @ApiOperation(value = "设置默认地址", tags = {"学习端-收货地址"})
+    @ApiOperationSupport(order = 30)
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "地址id", name = "id", dataType = "String", required = true)
+    })
+    public R setDefaultStudy(@RequestParam Integer id) {
+        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", userStudy.getUserid())
+                .ne("id", byId.getId()));
+        for (Recipient recipient1 : userId) {
+            recipient1.setIsDefault(0);
+            recipientService.updateById(recipient1);
+        }
+        return R.ok();
+    }
+
+    /**
+     * 根据地址id 获取详情
+     *
+     * @param id
+     * @return
+     */
+    @GetMapping("/getAddressById")
+    @ApiOperation(value = "获取地址详情", tags = {"家长端-收货地址"})
+    @ApiOperationSupport(order = 19)
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "地址id", name = "id", dataType = "String", required = true)
+    })
+    public R<Recipient> getAddressById(@RequestParam Integer id) {
+        if (tokenService.getLoginUser1() == null) {
+            return R.tokenError("登录失效");
+        }
+        Recipient byId = recipientService.getById(id);
+        return R.ok(byId);
+    }
+
+    /**
+     * 根据地址id 获取详情
+     *
+     * @param id
+     * @return
+     */
+    @GetMapping("/getAddressByIdStudy")
+    @ApiOperation(value = "获取地址详情", tags = {"学习端-收货地址"})
+    @ApiOperationSupport(order = 31)
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "地址id", name = "id", dataType = "String", required = true)
+    })
+    public R<Recipient> getAddressByIdStudy(@RequestParam Integer id) {
+        if (tokenService.getLoginUserStudy() == null) {
+            return R.tokenError("登录失效");
+        }
+        Recipient byId = recipientService.getById(id);
+        return R.ok(byId);
+    }
+
+    /**
+     * 获取用户收货地址
+     */
     @GetMapping("/shopAddress")
-    @ApiOperation(value = "获取用户收货地址", tags = {"获取用户收货地址"})
+    @ApiOperation(value = "获取用户收货地址列表", tags = {"学习端-收货地址"})
+    @ApiOperationSupport(order = 32)
     public R<List<Recipient>> shopAddress() {
+        if (tokenService.getLoginUserStudy() == null) {
+            return R.tokenError("登录失效");
+        }
         return R.ok(recipientService.lambdaQuery().eq(Recipient::getUserId,
                 tokenService.getLoginUserStudy().getUserid()).list());
     }
@@ -203,46 +514,175 @@
      * 新增收货地址/修改收货地址
      */
     @PostMapping("/addressSaveOrUpdate")
-    @ApiOperation(value = "新增收货地址/修改收货地址", tags = {"新增收货地址/修改收货地址"})
+    @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());
-        return R.ok(recipientService.addressSaveOrUpdate(recipient));
+        if (recipient.getIsDefault() == 1) {
+            // 如果设置为默认地址 那么要将之前的默认地址取消掉
+            List<Recipient> userId = recipientService.list(new QueryWrapper<Recipient>()
+                    .eq("userId", userStudy.getUserid()));
+            for (Recipient recipient1 : userId) {
+                recipient1.setIsDefault(0);
+                recipientService.updateById(recipient1);
+            }
+        }
+        return recipientService.addressSaveOrUpdate(recipient) ? R.ok() : R.fail();
+    }
+
+    /**
+     * 新增收货地址/修改收货地址
+     */
+    @PostMapping("/addressSaveOrUpdateParent")
+    @ApiOperation(value = "家长端-新增收货地址/修改收货地址", tags = {"家长端-新增收货地址/修改收货地址"})
+    @ApiOperationSupport(order = 20)
+    public R<String> addressSaveOrUpdateParent(@RequestBody Recipient recipient) {
+        if (tokenService.getLoginUser1() == null) {
+            return R.tokenError("登录失效!");
+        }
+        recipient.setUserId(tokenService.getLoginUser1().getUserid());
+        if (recipient.getId() != null) {
+            if (recipient.getIsDefault() == 1) {
+                // 如果设置为默认地址 那么要将之前的默认地址取消掉
+                List<Recipient> userId = recipientService.list(new QueryWrapper<Recipient>()
+                        .eq("userId", tokenService.getLoginUser1().getUserid()));
+                for (Recipient recipient1 : userId) {
+                    recipient1.setIsDefault(0);
+                    recipientService.updateById(recipient1);
+                }
+            }
+            recipientService.updateById(recipient);
+        } else {
+            if (recipient.getIsDefault() == 1) {
+                // 如果设置为默认地址 那么要将之前的默认地址取消掉
+                List<Recipient> userId = recipientService.list(new QueryWrapper<Recipient>()
+                        .eq("userId", tokenService.getLoginUser1().getUserid()));
+                for (Recipient recipient1 : userId) {
+                    recipient1.setIsDefault(0);
+                    recipientService.updateById(recipient1);
+                }
+            }
+            recipientService.save(recipient);
+
+        }
+        return R.ok();
     }
 
     /**
      * 删除收货地址
      */
     @GetMapping("/addressDelete")
-    @ApiOperation(value = "删除收货地址", tags = {"删除收货地址"})
+    @ApiOperation(value = "删除收货地址", tags = {"学习端-收货地址"})
+    @ApiOperationSupport(order = 34)
     @ApiImplicitParams({
-            @ApiImplicitParam(value = "地址信息id", name = "id", dataType = "String", required = true)
+            @ApiImplicitParam(value = "地址信息id", name = "id", dataType = "Integer", required = true)
     })
-    public R<String> addressDelete(@RequestParam String id) {
+    public R<String> addressDelete(@RequestParam Integer id) {
         return R.ok(recipientService.removeById(id) ? "删除成功!" : "删除失败!");
     }
 
     /**
-     * 修改订单收货地址
-     *
-     * @param orderId 订单id
+     * 删除收货地址
      */
-    @GetMapping("/updateOrderAddress")
-    @ApiOperation(value = "修改订单收货地址", tags = {"修改订单收货地址"})
+    @GetMapping("/addressDeleteParent")
+    @ApiOperation(value = "家长端-删除收货地址", tags = {"家长端-删除收货地址"})
+    @ApiOperationSupport(order = 21)
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "地址信息id", name = "id", dataType = "Integer", required = true)
+    })
+    public R<String> addressDeleteParent(@RequestParam Integer id) {
+        return R.ok(recipientService.removeById(id) ? "删除成功!" : "删除失败!");
+    }
+
+
+    @GetMapping("/getOrderAddressParent")
+    @ApiOperation(value = "获取修改订单收货地址", tags = {"家长端-获取修改订单收货地址"})
+    @ApiOperationSupport(order = 22)
+    public R<List<Recipient>> getOrderAddressParent() {
+        if (tokenService.getLoginUser1() == null) {
+            return R.tokenError("登录失效");
+        }
+        List<Recipient> userId = recipientService.list(new QueryWrapper<Recipient>()
+                .eq("userId", tokenService.getLoginUser1().getUserid()));
+
+        return R.ok(userId);
+    }
+
+    @GetMapping("/getOrderAddress")
+    @ApiOperation(value = "获取修改订单收货地址", tags = {"学习端-收货地址"})
+    @ApiOperationSupport(order = 35)
+    public R<List<Recipient>> getOrderAddress() {
+        if (tokenService.getLoginUserStudy() == null) {
+            return R.tokenError("登录失效");
+        }
+        List<Recipient> userId = recipientService.list(new QueryWrapper<Recipient>()
+                .eq("userId", tokenService.getLoginUserStudy().getUserid()));
+        return R.ok(userId);
+    }
+
+    @GetMapping("/updateOrderAddressParent")
+    @ApiOperation(value = "修改订单收货地址", tags = {"家长端-修改订单收货地址"})
     @ApiImplicitParams({
             @ApiImplicitParam(value = "订单id", name = "orderId", dataType = "String", required = true),
-            @ApiImplicitParam(value = "完整收货地址", name = "address", dataType = "String", required = true)
+            @ApiImplicitParam(value = "地址信息id", name = "recipientId", dataType = "String", required = true)
     })
-    public R<Boolean> updateOrderAddress(@RequestParam String orderId,
-                                                  @RequestParam String address) {
-        return R.ok(orderService.lambdaUpdate().set(TOrder::getConsigneeAddress, address)
-                .eq(TOrder::getId, orderId).eq(TOrder::getState, 1).update());
+    public R updateOrderAddressParent(@RequestParam String orderId, @RequestParam Integer recipientId) {
+        if (tokenService.getLoginUser1() == null) {
+            return R.tokenError("登录失效");
+        }
+        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.setUserId(null);
+        order.setConsigneeName(recipient.getRecipient());
+        order.setConsigneePhone(recipient.getRecipientPhone());
+        order.setConsigneeAddress(recipient.getProvince()+recipient.getCity()+recipient.getAddress());
+        orderService.updateById(order);
+        return R.ok();
+    }
+
+    @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 String orderId, @RequestParam Integer recipientId) {
+        if (tokenService.getLoginUserStudy() == null) {
+            return R.tokenError("登录失效");
+        }
+        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.setUserId(null);
+        order.setConsigneeName(recipient.getRecipient());
+        order.setConsigneePhone(recipient.getRecipientPhone());
+        order.setConsigneeAddress(recipient.getProvince()+recipient.getCity()+recipient.getAddress());
+        orderService.updateById(order);
+        return R.ok();
     }
 
     /**
      * 收货地址省市区三级联动
      */
     @GetMapping("/addressTree")
-    @ApiOperation(value = "收货地址省市区三级联动", tags = {"收货地址省市区三级联动"})
+    @ApiOperation(value = "收货地址省市区三级联动", tags = {"学习端-商城"})
+    @ApiOperationSupport(order = 37)
     public R<List<Region>> addressTree() {
         return R.ok(regionService.addressTree());
     }
@@ -252,9 +692,37 @@
      * 远程调用
      */
     @GetMapping("/goodRecommend")
-    @ApiOperation(value = "可兑换商品推荐", tags = {"可兑换商品推荐"})
+    @ApiOperation(value = "可兑换商品推荐", tags = {"学习端-商城"})
+    @ApiOperationSupport(order = 38)
     public R<List<TGoodsVO>> goodRecommend() {
-        return R.ok(goodsService.goodRecommend(tokenService.getLoginUserStudy().getUserid()));
+        LoginUserParent loginUserStudy = tokenService.getLoginUserStudy();
+        if (null == loginUserStudy) {
+            return R.tokenError("登录失效!");
+        }
+        UserPersonalCenterVO data = studyClient.userInfo().getData();
+        List<TGoodsVO> tGoodsVOS = goodsService.goodRecommend(loginUserStudy.getUserid());
+        List<TGoodsVO> res = new ArrayList<>();
+        int temp = 0;
+        for (TGoodsVO re : tGoodsVOS) {
+            if (temp>=3){
+                break;
+            }
+            if (data.getUser().getIntegral()>=re.getIntegral()){
+                res.add(re);
+                temp++;
+            }
+        }
+        return R.ok(res);
+    }
+
+    /**
+     * 获取所有商品分类
+     */
+    @GetMapping("/goodTypeStudy")
+    @ApiOperation(value = "商品分类列表", tags = {"学习端-商城"})
+    @ApiOperationSupport(order = 39)
+    public R<List<TGoodsType>> goodTypeStudy() {
+        return R.ok(goodsTypeService.lambdaQuery().eq(TGoodsType::getIsDelete, 0).list());
     }
 
     /**
@@ -263,33 +731,173 @@
      * @param goodId 商品id
      */
     @GetMapping("/goodDetail")
-    @ApiOperation(value = "商品详情", tags = {"商品详情"})
+    @ApiOperation(value = "商品详情", tags = {"学习端-商城"})
+    @ApiOperationSupport(order = 40)
     @ApiImplicitParams({
             @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true)
     })
     public R<GoodDetailVO> goodDetail(@RequestParam String goodId) {
+        if (tokenService.getLoginUserStudy() == null) {
+            return R.tokenError("登录失效!");
+        }
         // 商品详情
         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();
         // 已兑换人数
-        int number = goods.getBasicCount() + orderService.getGoodBuyNumber(goods.getId());
-        return R.ok(new GoodDetailVO(goods, goodsTypes, number));
+        int number = 0;
+        if (null != goods.getBasicCount()) {
+            number += goods.getBasicCount();
+        }
+        List<TOrder> list = orderService.list(new QueryWrapper<TOrder>().eq("goodsId", goods.getId()));
+        for (TOrder tOrder : list) {
+            number+=tOrder.getCount();
+        }
+        // 剩余兑换数量
+        Integer residueNumber = null;
+        if (null != goods.getTotal()) {
+            // 计算剩余兑换数量
+            List<TOrder> orderList = orderService.lambdaQuery().eq(TOrder::getGoodsId, goodId)
+                    .eq(TOrder::getDisabled, 0).list();
+            Integer item = 0;
+            for (TOrder order : orderList) {
+                item += order.getCount();
+            }
+            residueNumber = goods.getTotal() - item;
+        }
+        return R.ok(new GoodDetailVO(goods, goodsTypes, number, residueNumber));
+    }
+
+    /**
+     * 商品详情
+     *
+     * @param goodId 商品id
+     */
+    @GetMapping("/goodDetailParent")
+    @ApiOperation(value = "商品详情", tags = {"家长端-商城"})
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true)
+    })
+    public R<GoodDetailVO> goodDetailParent(@RequestParam String goodId) {
+//        if (tokenService.getLoginUser1() == null) {
+//            return R.tokenError("登录失效");
+//        }
+        // 商品详情
+        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();
+        // 已兑换人数
+        int number = 0;
+        if (null != goods.getBasicCount()) {
+            number += goods.getBasicCount();
+        }
+        List<TOrder> list = orderService.list(new QueryWrapper<TOrder>().eq("goodsId", goods.getId()));
+        for (TOrder tOrder : list) {
+            number+=tOrder.getCount();
+        }
+        // 剩余兑换数量
+        Integer residueNumber = null;
+        if (null != goods.getTotal()) {
+            // 计算剩余兑换数量
+            List<TOrder> orderList = orderService.lambdaQuery().eq(TOrder::getGoodsId, goodId)
+                    .eq(TOrder::getDisabled, 0).list();
+            Integer item = 0;
+            for (TOrder order : orderList) {
+                item += order.getCount();
+            }
+            residueNumber = goods.getTotal() - item;
+        }
+        return R.ok(new GoodDetailVO(goods, goodsTypes, number, residueNumber));
     }
 
     /**
      * 商城-立即兑换
      */
     @GetMapping("/redeemNow")
-    @ApiOperation(value = "商城-立即兑换", tags = {"立即兑换"})
+    @ApiOperation(value = "商城立即兑换", tags = {"学习端-商城"})
+    @ApiOperationSupport(order = 41)
     @ApiImplicitParams({
             @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true)
     })
     public R<GoodDetailVO> redeemNow(@RequestParam String goodId) {
+        if (tokenService.getLoginUserStudy() == null) {
+            return R.tokenError("登录失效");
+        }
         Recipient recipient = recipientService.lambdaQuery()
                 .eq(Recipient::getUserId, tokenService.getLoginUserStudy().getUserid())
+                .eq(Recipient::getIsDefault, 1)
+                .eq(Recipient::getDisabled, 0).one();
+        if (null == recipient) {
+            recipient = recipientService.lambdaQuery()
+                    .eq(Recipient::getUserId, tokenService.getLoginUserStudy().getUserid())
+                    .eq(Recipient::getDisabled, 0)
+                    .orderByDesc(Recipient::getCreateTime)
+                    .last("limit 1").one();
+        }
+        GoodDetailVO goodDetailVO = goodsService.redeemNow(goodId, recipient);
+        LocalDateTime currentDateTime = LocalDateTime.now();
+        // 格式化日期和时间信息
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
+        String formattedDateTime = currentDateTime.format(formatter);
+        // 生成随机数,填充剩余位数
+        Random random = new Random();
+        StringBuilder randomPart = new StringBuilder();
+        for (int i = 0; i < 3; i++) {
+            // 大写字母
+            randomPart.append((char) (random.nextInt(26) + 'A'));
+        }
+        // 组合订单编号
+        String orderNumber = formattedDateTime + randomPart;
+        goodDetailVO.setOrderNumber(orderNumber);
+        return R.ok(goodDetailVO);
+    }
+
+    /**
+     * 商城-立即兑换
+     */
+    @GetMapping("/redeemNowParent")
+    @ApiOperation(value = "商城立即兑换", tags = {"家长端-商城"})
+    @ApiOperationSupport(order = 25)
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true)
+    })
+    public R<GoodDetailVO> redeemNowParent(@RequestParam String goodId) {
+        if (tokenService.getLoginUser1() == null) {
+            return R.tokenError("登录失效");
+        }
+        Recipient recipient = recipientService.lambdaQuery()
+                .eq(Recipient::getUserId, tokenService.getLoginUser1().getUserid())
                 .eq(Recipient::getIsDefault, 1).one();
-        return R.ok(goodsService.redeemNow(goodId, recipient));
+        if (recipient == null) {
+            // 随便取一条地址数据
+            recipient = recipientService.lambdaQuery()
+                    .eq(Recipient::getUserId, tokenService.getLoginUser1().getUserid())
+                    .orderByDesc(Recipient::getCreateTime)
+                    .eq(Recipient::getDisabled, 0).last("limit 1")
+                    .one();
+        }
+        GoodDetailVO goodDetailVO = goodsService.redeemNow(goodId, recipient);
+        LocalDateTime currentDateTime = LocalDateTime.now();
+        // 格式化日期和时间信息
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
+        String formattedDateTime = currentDateTime.format(formatter);
+        // 生成随机数,填充剩余位数
+        Random random = new Random();
+        StringBuilder randomPart = new StringBuilder();
+        for (int i = 0; i < 3; i++) {
+            // 大写字母
+            randomPart.append((char) (random.nextInt(26) + 'A'));
+        }
+        // 组合订单编号
+        String orderNumber = formattedDateTime + randomPart;
+        goodDetailVO.setOrderNumber(orderNumber);
+        return R.ok(goodDetailVO);
     }
 
 
@@ -299,30 +907,50 @@
      * @param goodExchange 商品信息
      */
     @PostMapping("/goodExchange")
-    @ApiOperation(value = "商品兑换-确认", tags = {"商品兑换-确认"})
-    public R<Boolean> goodExchange(@RequestBody GoodExchangeDTO goodExchange) {
-        Recipient recipient = recipientService.getById(goodExchange.getRecipientId());
-        return R.ok(goodsService.goodExchange(goodExchange, recipient));
+    @ApiOperation(value = "家长端-商品兑换确认", tags = {"家长端-商品兑换确认"})
+    public R goodExchange(@RequestBody GoodExchangeDTO goodExchange) {
+        System.err.println("家长兑换:");
+        Recipient recipient = recipientService.getById(Integer.valueOf(goodExchange.getRecipientId()));
+        return goodsService.goodExchange1(goodExchange, recipient);
     }
+
+    @PostMapping("/goodExchangeStudy")
+    @ApiOperation(value = "商品兑换确认", tags = {"学习端-商城"})
+    @ApiOperationSupport(order = 42)
+    public R<String> goodExchangeStudy(@RequestBody @Validated GoodExchangeDTO goodExchange) {
+        System.err.println("学习兑换:");
+        Recipient recipient = recipientService.getById(goodExchange.getRecipientId());
+        return goodsService.goodExchange(goodExchange, recipient);
+    }
+
+
     @Autowired
     private StudyClient studyClient;
+
     @PostMapping("/getOrderInfo/{id}")
     @ApiOperation(value = "查看详情", tags = {"后台-订单管理"})
-    public R<TOrderVO> getOrderInfo(@PathVariable("id")Integer id) {
+    @ApiOperationSupport(order = 11)
+    public R<TOrderVO> getOrderInfo(@PathVariable("id") String id) {
         TOrder byId = orderService.getById(id);
-        TGoods byId2 = goodsService.getById(byId.getGoodsId());
+        TGoods byId2 = goodsService.getById1(byId.getGoodsId());
         TOrderVO tGoodsVO = new TOrderVO();
+        BeanUtils.copyProperties(byId, tGoodsVO);
         tGoodsVO.setName(byId2.getName());
-        BeanUtils.copyProperties(byId,tGoodsVO);
         TUser byId1 = studyClient.getUserById(byId.getUserId()).getData();
         tGoodsVO.setUserName(byId1.getName());
         tGoodsVO.setPhone(byId1.getPhone());
+        if (byId.getProvince() != null && byId.getCity() != null) {
+            tGoodsVO.setConsigneeAddress(byId.getProvince() + byId.getCity() + tGoodsVO.getConsigneeAddress());
+        }
         return R.ok(tGoodsVO);
     }
+
     @PostMapping("/confirm1")
     @ApiOperation(value = "确认发货", tags = {"后台-订单管理"})
+    @ApiOperationSupport(order = 12)
     public R getGoodsInfo1(@RequestBody OrderDTO dto) {
         TOrder byId = orderService.getById(dto.getId());
+        byId.setUserId(null);
         byId.setState(2);
         byId.setExpress(dto.getExpress());
         byId.setExpressNumber(dto.getExpressNumber());
@@ -330,14 +958,19 @@
         orderService.updateById(byId);
         return R.ok("修改成功");
     }
+
     @PostMapping("/listAll1")
     @ApiOperation(value = "列表查询", tags = {"后台-订单管理"})
-    public R<PageInfo<TOrderVO>> listAll1(@RequestBody  OrderQuery query) throws ParseException {
-        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+    @ApiOperationSupport(order = 13)
+    public R<PageInfo<TOrderVO>> listAll1(@RequestBody OrderQuery query) throws ParseException {
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
 
-        if (query.getEndTime()!=null){
+        if (query.getEndTime() != null) {
             Date parse = format.parse(query.getStartTime());
             Date parse1 = format.parse(query.getEndTime());
+            parse1.setHours(23);
+            parse1.setMinutes(59);
+            parse1.setSeconds(59);
             query.setStartTime1(parse);
             query.setEndTime1(parse1);
         }
@@ -345,30 +978,28 @@
         List<TOrderVO> list1 = new ArrayList<>();
         for (TOrderVO tOrderVO : list) {
             TUser data = studyClient.getUserById(tOrderVO.getUserId()).getData();
-            if (data!=null){
+            if (data != null) {
                 tOrderVO.setUserName(data.getName());
                 tOrderVO.setPhone(data.getPhone());
             }
-            if (!StringUtils.hasLength(query.getPhone()) && !StringUtils.hasLength(query.getUserName())){
+            if (!StringUtils.hasLength(query.getPhone()) && !StringUtils.hasLength(query.getUserName())) {
                 list1.add(tOrderVO);
                 continue;
             }
             // 如果筛选条件输入了电话或者姓名那么需要过滤掉不符合条件的数据
-            if (StringUtils.hasLength(query.getPhone()) && StringUtils.hasLength(query.getUserName())){
-                if (tOrderVO.getPhone().contains(query.getPhone()) && tOrderVO.getUserName().contains(query.getUserName())){
+            if (StringUtils.hasLength(query.getPhone()) && StringUtils.hasLength(query.getUserName())) {
+                if (tOrderVO.getPhone().contains(query.getPhone()) && tOrderVO.getUserName().contains(query.getUserName())) {
                     list1.add(tOrderVO);
                 }
-            }else if (StringUtils.hasLength(query.getPhone())){
-                if (tOrderVO.getPhone().contains(query.getPhone())){
+            } else if (StringUtils.hasLength(query.getPhone())) {
+                if (tOrderVO.getPhone().contains(query.getPhone())) {
                     list1.add(tOrderVO);
                 }
-            }else if (StringUtils.hasLength(query.getUserName())){
-                if (tOrderVO.getUserName().contains(query.getUserName())){
+            } else if (StringUtils.hasLength(query.getUserName())) {
+                if (tOrderVO.getUserName().contains(query.getUserName())) {
                     list1.add(tOrderVO);
                 }
             }
-
-
         }
         PageInfo<TOrderVO> res = new PageInfo<>(query.getPageNumber(), query.getPageSize());
         res.setRecords(list1);

--
Gitblit v1.7.1