无关风月
2024-06-19 5feb2085f70f764d2a44dff707a3f57fa5fb306f
ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/TGoodsController.java
@@ -25,6 +25,7 @@
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;
@@ -106,12 +107,13 @@
        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
        if (goodQuery.getType() != null && goodQuery.getType().size() > 0) {
        if (goodQuery.getType() != null && !goodQuery.getType().isEmpty()) {
            for (String s : goodQuery.getType()) {
                wrapper.or().apply("FIND_IN_SET('" + s + "', typeIds)"); // 将每个类型 ID 应用于 FIND_IN_SET 函数
                // 将每个类型 ID 应用于 FIND_IN_SET 函数
                wrapper.or().apply("FIND_IN_SET('" + s + "', typeIds)");
            }
        }
        wrapper.eq("isDelete", 0);
@@ -162,6 +164,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("添加成功");
    }
@@ -177,6 +184,11 @@
    @PostMapping("/updateGoods")
    @ApiOperation(value = "修改", tags = {"后台-商品管理"})
    public R updateGoods(@RequestBody TGoods dto) {
        if (dto.getTotal()!=null){
            dto.setSurplus(dto.getTotal());
        }else{
            dto.setSurplus(0);
        }
        goodsService.updateById(dto);
        return R.ok("修改成功");
    }
@@ -240,7 +252,7 @@
                String[] split = byId.getTypeIds().split(",");
                for (String s : split) {
                    TGoodsType byId1 = goodsTypeService.getById(s);
                    if (byId1!=null){
                    if (byId1 != null) {
                        stringBuilder.append(byId1.getName()).append("|");
                    }
                }
@@ -286,6 +298,7 @@
        }
        TOrder byId = orderService.getById(id);
        byId.setState(3);
        byId.setCompleteTime(new Date());
        return R.ok(orderService.updateById(byId));
    }
@@ -614,6 +627,9 @@
            @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) {
@@ -622,7 +638,11 @@
        // 商品分类详情
        List<TGoodsType> goodsTypes = goodsTypeService.lambdaQuery().in(TGoodsType::getId, Arrays.asList(goods.getTypeIds().split(","))).list();
        // 已兑换人数
        int number = goods.getBasicCount() + orderService.getGoodBuyNumber(goods.getId());
        int number = 0;
        if (null != goods.getBasicCount()) {
            number += goods.getBasicCount();
        }
        number += orderService.getGoodBuyNumber(goods.getId());
        return R.ok(new GoodDetailVO(goods, goodsTypes, number));
    }
@@ -638,9 +658,9 @@
            @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true)
    })
    public R<GoodDetailVO> goodDetailParent(@RequestParam String goodId) {
        if (tokenService.getLoginUser1() == null) {
            return R.tokenError("登录失效");
        }
//        if (tokenService.getLoginUser1() == null) {
//            return R.tokenError("登录失效");
//        }
        // 商品详情
        TGoods goods = goodsService.lambdaQuery().eq(TGoods::getId, goodId).one();
        if (null == goods) {
@@ -649,7 +669,11 @@
        // 商品分类详情
        List<TGoodsType> goodsTypes = goodsTypeService.lambdaQuery().in(TGoodsType::getId, Arrays.asList(goods.getTypeIds().split(","))).list();
        // 已兑换人数
        int number = goods.getBasicCount() + orderService.getGoodBuyNumber(goods.getId());
        int number = 0;
        if (null != goods.getBasicCount()) {
            number += goods.getBasicCount();
        }
        number += orderService.getGoodBuyNumber(goods.getId());
        return R.ok(new GoodDetailVO(goods, goodsTypes, number));
    }
@@ -668,7 +692,8 @@
        }
        Recipient recipient = recipientService.lambdaQuery()
                .eq(Recipient::getUserId, tokenService.getLoginUserStudy().getUserid())
                .eq(Recipient::getIsDefault, 1).one();
                .eq(Recipient::getIsDefault, 1)
                .eq(Recipient::getDisabled, 0).one();
        GoodDetailVO goodDetailVO = goodsService.redeemNow(goodId, recipient);
        LocalDateTime currentDateTime = LocalDateTime.now();
        // 格式化日期和时间信息
@@ -678,10 +703,11 @@
        Random random = new Random();
        StringBuilder randomPart = new StringBuilder();
        for (int i = 0; i < 3; i++) {
            randomPart.append((char) (random.nextInt(26) + 'A')); // 大写字母
            // 大写字母
            randomPart.append((char) (random.nextInt(26) + 'A'));
        }
        // 组合订单编号
        String orderNumber = formattedDateTime + randomPart.toString();
        String orderNumber = formattedDateTime + randomPart;
        goodDetailVO.setOrderNumber(orderNumber);
        return R.ok(goodDetailVO);
    }
@@ -720,10 +746,11 @@
        Random random = new Random();
        StringBuilder randomPart = new StringBuilder();
        for (int i = 0; i < 3; i++) {
            randomPart.append((char) (random.nextInt(26) + 'A')); // 大写字母
            // 大写字母
            randomPart.append((char) (random.nextInt(26) + 'A'));
        }
        // 组合订单编号
        String orderNumber = formattedDateTime + randomPart.toString();
        String orderNumber = formattedDateTime + randomPart;
        goodDetailVO.setOrderNumber(orderNumber);
        return R.ok(goodDetailVO);
    }
@@ -737,6 +764,7 @@
    @PostMapping("/goodExchange")
    @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);
    }
@@ -744,7 +772,8 @@
    @PostMapping("/goodExchangeStudy")
    @ApiOperation(value = "商品兑换确认", tags = {"学习端-商城"})
    @ApiOperationSupport(order = 42)
    public R goodExchangeStudy(@RequestBody GoodExchangeDTO goodExchange) {
    public R<String> goodExchangeStudy(@RequestBody @Validated GoodExchangeDTO goodExchange) {
        System.err.println("学习兑换:");
        Recipient recipient = recipientService.getById(goodExchange.getRecipientId());
        return goodsService.goodExchange(goodExchange, recipient);
    }