mitao
2024-09-21 f44e4d609e7efaed9eac545137970b1e334f8106
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package com.ruoyi.goods.controller.inner;
 
 
import com.fasterxml.jackson.core.JsonProcessingException;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.annotation.InnerAuth;
import com.ruoyi.goods.service.IGoodsSeckillService;
import com.ruoyi.system.api.domain.GoodsSeckill;
import com.ruoyi.system.api.domain.GoodsSku;
import com.ruoyi.system.api.domain.dto.GoodsStockUpdDTO;
import java.util.List;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
 
/**
 * <p>
 * 商品秒杀表 前端控制器
 * </p>
 *
 * @author mitao
 * @since 2024-05-16
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/goods-seckill")
public class GoodsSeckillController {
 
    private final IGoodsSeckillService goodsSeckillService;
 
    @InnerAuth
    @PostMapping("/getGoodsSeckillOne")
    @ResponseBody
    public R<GoodsSeckill> getGoodsSeckillOne(@RequestBody Long goodsSkuId) {
        GoodsSeckill GoodsSeckillOne = goodsSeckillService.getById(goodsSkuId);
        return R.ok(GoodsSeckillOne);
    }
 
    @InnerAuth
    @PutMapping("/updGoodsSeckill")
    R<?> updGoodsSeckill(@RequestBody GoodsStockUpdDTO goodsStockUpdDTOS) {
        GoodsSeckill GoodsSeckillOne = goodsSeckillService.getById(goodsStockUpdDTOS.getGoodsSkuId());
        GoodsSeckillOne.setSeckillStock(goodsStockUpdDTOS.getAuctionStock());
        goodsSeckillService.updateById(GoodsSeckillOne);
        return R.ok();
    }
    @InnerAuth
    @PutMapping("/updGoodsSeckill1")
    R<Boolean> updGoodsSeckill1(@RequestBody GoodsSku goodsSku){
        GoodsSeckill GoodsSeckillOne = goodsSeckillService.getById(goodsSku.getId());
        Integer m= GoodsSeckillOne.getSoldQuantity()+goodsSku.getSoldQuantity();
        GoodsSeckillOne.setSoldQuantity(m);
        goodsSeckillService.updateById(GoodsSeckillOne);
        return R.ok();
    }
 
 
    /**
     * 开始秒杀
     *
     * @param seckillId 秒杀id
     */
    @InnerAuth
    @GetMapping("/start/{seckillId}")
    R<?> startSeckill(@PathVariable("seckillId") Long seckillId) {
        try {
            goodsSeckillService.startSeckill(seckillId);
        } catch (JsonProcessingException e) {
            log.error("秒杀开始异常", e);
            return R.fail();
        }
        return R.ok();
    }
 
    /**
     * 结束秒杀
     *
     * @param seckillId 秒杀id
     */
    @InnerAuth
    @GetMapping("/end/{seckillId}")
    R<?> endSeckill(@PathVariable("seckillId") Long seckillId) {
        try {
            goodsSeckillService.endSeckill(seckillId);
        } catch (JsonProcessingException e) {
            log.error("秒杀结束异常", e);
            return R.fail();
        }
        return R.ok();
    }
 
    /**
     * 根据秒杀id集合查询商品sku信息
     *
     * @param seckillIdSet
     * @return
     */
    @InnerAuth
    @PostMapping("/getGoodsSkuBySeckillIdSet")
    R<List<GoodsSku>> getGoodsSkuBySeckillIdSet(@RequestBody Set<Long> seckillIdSet) {
        return R.ok(goodsSeckillService.getGoodsSkuBySeckillIdSet(seckillIdSet));
    }
}