hjl
2024-06-06 c62e9f81b2072473b084abb30f7c005ed341a336
ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/TGoodsController.java
@@ -2,12 +2,15 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
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;
@@ -16,7 +19,7 @@
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.web.bind.annotation.*;
@@ -27,6 +30,7 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
/**
 * <p>
@@ -199,20 +203,51 @@
     * 兑换记录
     */
    @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<List<ExchangeRecordVO>> exchangeRecord() {
        List<ExchangeRecordVO> exchangeRecord = orderService.exchangeRecord(tokenService.getLoginUserStudy().getUserid());
        for (ExchangeRecordVO record : exchangeRecord) {
            TGoods goods = goodsService.getById(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);
        }
        return R.ok(exchangeRecord);
    }
    @GetMapping("/exchangeRecordParent")
    @ApiOperation(value = "家长端-兑换记录", tags = {"家长端-兑换记录"})
    public R<List<TOrder>> exchangeRecordParent() {
        if (tokenService.getLoginUser1() == null) {
    public R<Page<TOrder>> exchangeRecordParent(Integer pageNumber, Integer pageSize) {
        if (tokenService.getLoginUser1() == null){
            return R.tokenError("登录失效");
        }
        return R.ok(orderService.lambdaQuery().eq(TOrder::getUserId, tokenService.getLoginUser1().getUserid())
                .orderByDesc(TOrder::getCreateTime).list());
        Page<TOrder> page = orderService.page(new Page<>(pageNumber, pageSize), new QueryWrapper<TOrder>().eq("userId", tokenService.getLoginUser1().getUserid())
                .orderByDesc("createTime"));
        List<TOrder> records = page.getRecords();
        for (TOrder tOrder : records) {
            TGoods byId = goodsService.getById(tOrder.getGoodsId());
            tOrder.setName(byId.getName());
            tOrder.setImg(byId.getCoverImg());
            StringBuilder stringBuilder = new StringBuilder();
            if (StringUtils.hasLength(byId.getTypeIds())){
                String[] split = byId.getTypeIds().split(",");
                for (String s : split) {
                    TGoodsType byId1 = goodsTypeService.getById(s);
                    stringBuilder.append(byId1.getName()).append("|");
                }
                // 去除最后一个字符
                stringBuilder.deleteCharAt(stringBuilder.length() - 1);
                tOrder.setType(stringBuilder.toString());
            }
        }
        return R.ok(page);
    }
    /**
@@ -220,6 +255,7 @@
     */
    @GetMapping("/confirm")
    @ApiOperation(value = "确认收货", tags = {"家长端-兑换记录"})
    @ApiOperationSupport(order = 16)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "订单id", name = "id", dataType = "String", required = true)
    })
@@ -236,7 +272,8 @@
     * 兑换记录
     */
    @GetMapping("/confirmStudy")
    @ApiOperation(value = "确认收货", tags = {"学习端-兑换记录"})
    @ApiOperation(value = "确认收货", tags = {"学习端-商城"})
    @ApiOperationSupport(order = 29)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "订单id", name = "id", dataType = "String", required = true)
    })
@@ -254,6 +291,7 @@
     */
    @GetMapping("/shopAddressParent")
    @ApiOperation(value = "获取用户收货地址", tags = {"家长端-获取用户收货地址"})
    @ApiOperationSupport(order = 17)
    public R<List<Recipient>> shopAddressParent() {
        if (tokenService.getLoginUser1() == null) {
            return R.tokenError("登录失效");
@@ -267,6 +305,7 @@
     */
    @GetMapping("/setDefault")
    @ApiOperation(value = "设置默认地址", tags = {"家长端-设置默认地址"})
    @ApiOperationSupport(order = 18)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "地址id", name = "id", dataType = "String", required = true)
    })
@@ -277,6 +316,14 @@
        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();
    }
@@ -284,7 +331,8 @@
     * 设置默认地址
     */
    @GetMapping("/setDefaultStudy")
    @ApiOperation(value = "设置默认地址", tags = {"学习端-设置默认地址"})
    @ApiOperation(value = "设置默认地址", tags = {"学习端-收货地址"})
    @ApiOperationSupport(order = 30)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "地址id", name = "id", dataType = "String", required = true)
    })
@@ -295,6 +343,14 @@
        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();
    }
@@ -305,7 +361,8 @@
     * @return
     */
    @GetMapping("/getAddressById")
    @ApiOperation(value = "获取地址详情", tags = {"家长端-获取地址详情"})
    @ApiOperation(value = "获取地址详情", tags = {"家长端-收货地址"})
    @ApiOperationSupport(order = 19)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "地址id", name = "id", dataType = "String", required = true)
    })
@@ -324,7 +381,8 @@
     * @return
     */
    @GetMapping("/getAddressByIdStudy")
    @ApiOperation(value = "获取地址详情", tags = {"学习端-获取地址详情"})
    @ApiOperation(value = "获取地址详情", tags = {"学习端-收货地址"})
    @ApiOperationSupport(order = 31)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "地址id", name = "id", dataType = "String", required = true)
    })
@@ -340,7 +398,8 @@
     * 获取用户收货地址
     */
    @GetMapping("/shopAddress")
    @ApiOperation(value = "获取用户收货地址", tags = {"学习端-获取用户收货地址"})
    @ApiOperation(value = "获取用户收货地址列表", tags = {"学习端-收货地址"})
    @ApiOperationSupport(order = 32)
    public R<List<Recipient>> shopAddress() {
        if (tokenService.getLoginUserStudy() == null) {
            return R.tokenError("登录失效");
@@ -353,9 +412,21 @@
     * 新增收货地址/修改收货地址
     */
    @PostMapping("/addressSaveOrUpdate")
    @ApiOperation(value = "学习端-新增收货地址/修改收货地址", tags = {"学习端-新增收货地址/修改收货地址"})
    @ApiOperation(value = "新增收货地址/修改收货地址", tags = {"学习端-收货地址"})
    @ApiOperationSupport(order = 33)
    public R<String> addressSave(@RequestBody Recipient recipient) {
        return R.ok(recipientService.addressSaveOrUpdate(recipient));
        recipient.setUserId(tokenService.getLoginUserStudy().getUserid());
        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.addressSaveOrUpdate(recipient);
        return R.ok();
    }
    /**
@@ -363,12 +434,35 @@
     */
    @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.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 {
        }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();
    }
@@ -377,11 +471,12 @@
     * 删除收货地址
     */
    @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) ? "删除成功!" : "删除失败!");
    }
@@ -390,16 +485,18 @@
     */
    @GetMapping("/addressDeleteParent")
    @ApiOperation(value = "家长端-删除收货地址", tags = {"家长端-删除收货地址"})
    @ApiOperationSupport(order = 21)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "地址信息id", name = "id", dataType = "String", required = true)
            @ApiImplicitParam(value = "地址信息id", name = "id", dataType = "Integer", required = true)
    })
    public R<String> addressDeleteParent(@RequestParam String id) {
    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("登录失效");
@@ -411,7 +508,8 @@
    }
    @GetMapping("/getOrderAddress")
    @ApiOperation(value = "获取修改订单收货地址", tags = {"学习端-获取修改订单收货地址"})
    @ApiOperation(value = "获取修改订单收货地址", tags = {"学习端-收货地址"})
    @ApiOperationSupport(order = 35)
    public R<List<Recipient>> getOrderAddress() {
        if (tokenService.getLoginUserStudy() == null) {
            return R.tokenError("登录失效");
@@ -433,7 +531,7 @@
        }
        Recipient userId = recipientService.getById(recipientId);
        TOrder byId = orderService.getById(orderId);
        byId.setConsigneeName(userId.getAddress());
        byId.setConsigneeName(userId.getRecipient());
        byId.setConsigneePhone(userId.getRecipientPhone());
        byId.setConsigneeAddress(userId.getAddress());
        orderService.updateById(byId);
@@ -441,7 +539,8 @@
    }
    @GetMapping("/updateOrderAddress")
    @ApiOperation(value = "修改订单收货地址", tags = {"学习端-修改订单收货地址"})
    @ApiOperation(value = "修改订单收货地址", tags = {"学习端-收货地址"})
    @ApiOperationSupport(order = 36)
    public R updateOrderAddress(@RequestParam Integer orderId, @RequestParam Integer recipientId) {
        if (tokenService.getLoginUserStudy() == null) {
            return R.tokenError("登录失效");
@@ -459,7 +558,8 @@
     * 收货地址省市区三级联动
     */
    @GetMapping("/addressTree")
    @ApiOperation(value = "学习端-收货地址省市区三级联动", tags = {"学习端-收货地址省市区三级联动"})
    @ApiOperation(value = "收货地址省市区三级联动", tags = {"学习端-商城"})
    @ApiOperationSupport(order = 37)
    public R<List<Region>> addressTree() {
        return R.ok(regionService.addressTree());
    }
@@ -469,7 +569,8 @@
     * 远程调用
     */
    @GetMapping("/goodRecommend")
    @ApiOperation(value = "学习端-可兑换商品推荐", tags = {"学习端-可兑换商品推荐"})
    @ApiOperation(value = "可兑换商品推荐", tags = {"学习端-商城"})
    @ApiOperationSupport(order = 38)
    public R<List<TGoodsVO>> goodRecommend() {
        return R.ok(goodsService.goodRecommend(tokenService.getLoginUserStudy().getUserid()));
    }
@@ -478,7 +579,8 @@
     * 获取所有商品分类
     */
    @GetMapping("/goodTypeStudy")
    @ApiOperation(value = "学习端-商品分类列表", tags = {"学习端-商品分类列表"})
    @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());
    }
@@ -489,7 +591,8 @@
     * @param goodId 商品id
     */
    @GetMapping("/goodDetail")
    @ApiOperation(value = "学习端-商品详情", tags = {"学习端-商城"})
    @ApiOperation(value = "商品详情", tags = {"学习端-商城"})
    @ApiOperationSupport(order = 40)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true)
    })
@@ -510,6 +613,7 @@
     */
    @GetMapping("/goodDetailParent")
    @ApiOperation(value = "商品详情", tags = {"家长端-商城"})
    @ApiOperationSupport(order = 24)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true)
    })
@@ -531,6 +635,7 @@
     */
    @GetMapping("/redeemNow")
    @ApiOperation(value = "商城立即兑换", tags = {"学习端-商城"})
    @ApiOperationSupport(order = 41)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true)
    })
@@ -563,6 +668,7 @@
     */
    @GetMapping("/redeemNowParent")
    @ApiOperation(value = "商城立即兑换", tags = {"家长端-商城"})
    @ApiOperationSupport(order = 25)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true)
    })
@@ -573,6 +679,15 @@
        Recipient recipient = recipientService.lambdaQuery()
                .eq(Recipient::getUserId, tokenService.getLoginUser1().getUserid())
                .eq(Recipient::getIsDefault, 1).one();
        if (recipient == null){
            // 随便取一条地址数据
            List<Recipient> list = recipientService.lambdaQuery()
                    .eq(Recipient::getUserId, tokenService.getLoginUser1().getUserid())
                    .eq(Recipient::getIsDefault, 1).list();
            if (!list.isEmpty()){
                recipient = list.get(0);
            }
        }
        GoodDetailVO goodDetailVO = goodsService.redeemNow(goodId, recipient);
        LocalDateTime currentDateTime = LocalDateTime.now();
        // 格式化日期和时间信息
@@ -597,14 +712,15 @@
     * @param goodExchange 商品信息
     */
    @PostMapping("/goodExchange")
    @ApiOperation(value = "学习端-商品兑换确认", tags = {"家长端-商品兑换确认"})
    @ApiOperation(value = "家长端-商品兑换确认", tags = {"家长端-商品兑换确认"})
    public R goodExchange(@RequestBody GoodExchangeDTO goodExchange) {
        Recipient recipient = recipientService.getById(goodExchange.getRecipientId());
        Recipient recipient = recipientService.getById(Integer.valueOf(goodExchange.getRecipientId()));
        return goodsService.goodExchange1(goodExchange, recipient);
    }
    @PostMapping("/goodExchangeStudy")
    @ApiOperation(value = "学习端-商品兑换确认", tags = {"学习端-商品兑换确认"})
    @ApiOperation(value = "商品兑换确认", tags = {"学习端-商城"})
    @ApiOperationSupport(order = 42)
    public R goodExchangeStudy(@RequestBody GoodExchangeDTO goodExchange) {
        Recipient recipient = recipientService.getById(goodExchange.getRecipientId());
        return goodsService.goodExchange(goodExchange, recipient);
@@ -616,6 +732,7 @@
    @PostMapping("/getOrderInfo/{id}")
    @ApiOperation(value = "查看详情", tags = {"后台-订单管理"})
    @ApiOperationSupport(order = 11)
    public R<TOrderVO> getOrderInfo(@PathVariable("id") Integer id) {
        TOrder byId = orderService.getById(id);
        TGoods byId2 = goodsService.getById(byId.getGoodsId());
@@ -630,6 +747,7 @@
    @PostMapping("/confirm1")
    @ApiOperation(value = "确认发货", tags = {"后台-订单管理"})
    @ApiOperationSupport(order = 12)
    public R getGoodsInfo1(@RequestBody OrderDTO dto) {
        TOrder byId = orderService.getById(dto.getId());
        byId.setState(2);
@@ -642,6 +760,7 @@
    @PostMapping("/listAll1")
    @ApiOperation(value = "列表查询", tags = {"后台-订单管理"})
    @ApiOperationSupport(order = 13)
    public R<PageInfo<TOrderVO>> listAll1(@RequestBody OrderQuery query) throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");