liujie
2025-12-09 0f364ddb7716e8d3429e1ddca29f56cc85ce364c
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
package com.ruoyi.web.controller.api;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.model.TBigGiftPackage;
import com.ruoyi.system.query.BigGiftPackageQuery;
import com.ruoyi.system.service.TBigGiftPackageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
 
import java.util.Objects;
 
/**
 * <p>
 * 大礼包 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2025-12-08
 */
@RestController
@RequestMapping("/t-big-gift-package")
@Api(tags = "(嘉视达)大礼包")
public class TBigGiftPackageController {
 
    private final TBigGiftPackageService tBigGiftPackageService;
    private final TokenService tokenService;
 
    public TBigGiftPackageController(TBigGiftPackageService tBigGiftPackageService, TokenService tokenService) {
        this.tBigGiftPackageService = tBigGiftPackageService;
        this.tokenService = tokenService;
    }
 
    @ApiOperation(value = "大礼包分页列表")
    @PostMapping(value = "/pageList")
    public R<Page<TBigGiftPackage>> pageList(@RequestBody BigGiftPackageQuery query) {
        Page<TBigGiftPackage> tBigGiftPackagePage = new Page<>(query.getPageNum(), query.getPageSize());
        LambdaQueryWrapper<TBigGiftPackage> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(TBigGiftPackage::getStatus,1);
        wrapper.like(Objects.nonNull(query.getName()), TBigGiftPackage::getName, query.getName());
        wrapper.orderByDesc(TBigGiftPackage::getCreateTime);
 
        Page<TBigGiftPackage> pageInfo = tBigGiftPackageService.page(tBigGiftPackagePage, wrapper);
        return R.ok(pageInfo);
    }
 
    @ApiOperation(value = "大礼包详情")
    @GetMapping(value = "/detail/{id}")
    public R<TBigGiftPackage> detail(@PathVariable Integer id ) {
        TBigGiftPackage tBigGiftPackage = tBigGiftPackageService.getById(id);
        return R.ok(tBigGiftPackage);
    }
 
 
    @ApiOperation(value = "大礼包添加")
    @PostMapping(value = "/add")
    @Log(title = "大礼包-添加", businessType = BusinessType.INSERT)
    public R<String> add(@RequestBody TBigGiftPackage tBigGiftPackage) {
 
        LoginUser loginUser = tokenService.getLoginUser();
        tBigGiftPackage.setCreateUserId(loginUser.getUserId());
        boolean save = tBigGiftPackageService.save(tBigGiftPackage);
        if (save) {
            return R.ok("添加成功");
        }
        return R.fail("添加失败");
    }
 
    @ApiOperation(value = "大礼包修改")
    @PostMapping(value = "/update")
    @Log(title = "大礼包-修改", businessType = BusinessType.UPDATE)
    public R<String> update(@RequestBody TBigGiftPackage tBigGiftPackage) {
 
        LoginUser loginUser = tokenService.getLoginUser();
        tBigGiftPackage.setUpdateUserId(loginUser.getUserId());
        boolean update = tBigGiftPackageService.updateById(tBigGiftPackage);
        if (update) {
            return R.ok("修改成功");
        }
        return R.fail("修改失败");
    }
 
    @ApiOperation(value = "大礼包删除")
    @DeleteMapping(value = "/delete/{id}")
    @Log(title = "大礼包-删除", businessType = BusinessType.DELETE)
    public R<String> delete(@PathVariable Integer id ) {
        TBigGiftPackage bigGiftPackage = tBigGiftPackageService.getById(id);
        bigGiftPackage.setStatus(0);
        bigGiftPackage.setUpdateUserId(tokenService.getLoginUser().getUserId());
        boolean remove = tBigGiftPackageService.updateById(bigGiftPackage);
        if (remove) {
            return R.ok("删除成功");
        }
        return R.fail("删除失败");
    }
}