44323
2024-05-16 80870e154d7755c36cdb345147532c131858e270
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
113
114
115
116
117
118
119
120
121
122
123
124
125
package com.ruoyi.goods.controller;
 
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.goods.domain.TGoods;
import com.ruoyi.goods.domain.TGoodsType;
import com.ruoyi.goods.domain.TOrder;
import com.ruoyi.goods.dto.GoodsTypeQuery;
import com.ruoyi.goods.service.ITGoodsService;
import com.ruoyi.goods.service.ITGoodsTypeService;
import com.ruoyi.goods.service.ITOrderService;
import com.ruoyi.goods.vo.TGoodsVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author 无关风月
 * @since 2024-04-26
 */
@RestController
@RequestMapping("/base/goods")
public class TGoodsController {
    @Autowired
    private ITGoodsService goodsService;
    @Autowired
    private ITGoodsTypeService goodsTypeService;
    @Autowired
    private ITOrderService orderService;
    @PostMapping("/listType")
    @ApiOperation(value = "列表查询", tags = {"后台-商品类型管理"})
    public R<PageInfo<TGoodsType>> listType(@RequestBody GoodsTypeQuery query){
        QueryWrapper<TGoodsType> wrapper = new QueryWrapper<>();
        if (StringUtils.hasLength(query.getName())){
            wrapper.like("name", query.getName());
        }
        wrapper.ne("isDelete",1);
        wrapper.orderByDesc("id");
        List<TGoodsType> list = goodsTypeService.list(wrapper);
        PageInfo<TGoodsType> res = new PageInfo<>(query.getPageNumber(), query.getPageSize());
        res.setRecords(list);
        return R.ok(res);
    }
    @PostMapping("/addGoodsType")
    @ApiOperation(value = "添加", tags = {"后台-商品类型管理"})
    public R addGoodsType(@RequestBody TGoodsType dto) {
        goodsTypeService.save(dto);
        return R.ok("添加成功");
    }
    @PostMapping("/updateGoodsType")
    @ApiOperation(value = "修改", tags = {"后台-商品类型管理"})
    public R updateGoodsType(@RequestBody TGoodsType dto) {
        goodsTypeService.updateById(dto);
        return R.ok("修改成功");
    }
    @PostMapping("/deleteGoodsType")
    @ApiOperation(value = "删除", tags = {"后台-商品类型管理"})
    public R deleteGoodsType(Integer id) {
        TGoodsType byId = goodsTypeService.getById(id);
        byId.setIsDelete(1);
        goodsTypeService.removeById(byId);
        return R.ok("删除成功");
    }
    @GetMapping("/listAll")
    @ApiOperation(value = "列表查询", tags = {"后台-商品管理"})
 
    public R<PageInfo<TGoods>> listAll(@RequestBody GoodsTypeQuery query){
        QueryWrapper<TGoods> wrapper = new QueryWrapper<>();
        if (StringUtils.hasLength(query.getName())){
            wrapper.like("name", query.getName());
        }
        wrapper.orderByDesc("id");
        List<TGoods> list = goodsService.list(wrapper);
        PageInfo<TGoods> res = new PageInfo<>(query.getPageNumber(), query.getPageSize());
        res.setRecords(list);
        return R.ok(res);
    }
    @PostMapping("/addGoods")
    @ApiOperation(value = "添加", tags = {"后台-商品管理"})
    public R addGoods(@RequestBody TGoods dto) {
        goodsService.save(dto);
        return R.ok("添加成功");
    }
    @PostMapping("/deleteGoods")
    @ApiOperation(value = "删除", tags = {"后台-商品管理"})
    public R deleteGoods(@RequestParam Integer id) {
        TGoods byId = goodsService.getById(id);
        goodsService.removeById(byId);
        return R.ok("删除成功");
    }
    @PostMapping("/updateGoods")
    @ApiOperation(value = "修改", tags = {"后台-商品管理"})
    public R updateGoods(@RequestBody TGoods dto) {
        goodsService.updateById(dto);
        return R.ok("修改成功");
    }
    @PostMapping("/getGoodsInfo")
    @ApiOperation(value = "查看详情", tags = {"后台-商品管理"})
    public R<TGoodsVO> getGoodsInfo(@RequestParam Integer id) {
        TGoodsVO tGoodsVO = new TGoodsVO();
        TGoods byId = goodsService.getById(id);
        BeanUtils.copyProperties(byId,tGoodsVO);
        long goodsId = orderService.count(new QueryWrapper<TOrder>().eq("goodsId", id));
        tGoodsVO.setInventory(goodsId);
        return R.ok(tGoodsVO);
    }
    @PostMapping("/getGoodsTypeList")
    @ApiOperation(value = "获取商品类型列表", tags = {"后台-商品管理"})
    public R<List<TGoodsType>> getGoodsInfo() {
        List<TGoodsType> res = goodsTypeService.list(new QueryWrapper<TGoodsType>()
                .ne("isDelete", 1));
        return R.ok(res);
    }
 
}