无关风月
2024-06-17 f0cb2ed0aed012ae08fd957338650d91c3cc1d14
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package com.ruoyi.management.controller;
 
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.goods.api.domain.TGoods;
import com.ruoyi.goods.api.domain.TGoodsType;
import com.ruoyi.goods.api.feignClient.GoodsClient;
import com.ruoyi.goods.api.model.GoodsTypeQuery;
import com.ruoyi.goods.api.model.TGoodsVO;
import com.ruoyi.management.service.ITGoodsService;
import com.ruoyi.management.service.ITGoodsTypeService;
import com.ruoyi.management.service.ITOrderService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author 无关风月
 * @since 2024-04-26
 */
@Controller
@RequestMapping("/tGoods")
public class TGoodsController {
    @Autowired
    private ITGoodsService goodsService;
    @Autowired
    private ITGoodsTypeService goodsTypeService;
    @Autowired
    private ITOrderService orderService;
    @Autowired
    private GoodsClient goodsClient;
    @ResponseBody
    @PostMapping("/listType")
    @ApiOperation(value = "列表查询", tags = {"后台-商品类型管理"})
 
    public AjaxResult<PageInfo<TGoodsType>> listType(String name, Integer pageNumber, Integer pageSize){
        GoodsTypeQuery goodsTypeQuery = new GoodsTypeQuery();
        goodsTypeQuery.setName(name);
        goodsTypeQuery.setPageNumber(pageNumber);
        goodsTypeQuery.setPageSize(pageSize);
 
        PageInfo<TGoodsType> data = goodsClient.listType(goodsTypeQuery).getData();
        return AjaxResult.success(data);
    }
    @ResponseBody
    @PostMapping("/addGoodsType")
    @ApiOperation(value = "添加", tags = {"后台-商品类型管理"})
    public AjaxResult<TGoods> addGoodsType(TGoodsType dto) {
        goodsClient.addGoodsType(dto);
//        goodsTypeService.save(dto);
        return AjaxResult.success("添加成功");
    }
    @ResponseBody
    @PostMapping("/updateGoodsType")
    @ApiOperation(value = "修改", tags = {"后台-商品类型管理"})
    public AjaxResult<TGoods> updateGoodsType(TGoodsType dto) {
        goodsClient.updateGoodsType(dto);
//        goodsTypeService.updateById(dto);
        return AjaxResult.success("修改成功");
    }
    @ResponseBody
    @PostMapping("/deleteGoodsType")
    @ApiOperation(value = "删除", tags = {"后台-商品类型管理"})
    public AjaxResult deleteGoodsType(Integer id) {
        goodsClient.deleteGoodsType(id);
//        TGoodsType byId = goodsTypeService.getById(id);
//        byId.setIsDelete(1);
//        goodsTypeService.updateById(byId);
        return AjaxResult.success("删除成功");
    }
    @ResponseBody
    @PostMapping("/listAll")
    @ApiOperation(value = "列表查询", tags = {"后台-商品管理"})
    public AjaxResult<PageInfo<TGoods>> listAll( String name,Integer pageNumber,Integer pageSize){
        GoodsTypeQuery goodsTypeQuery = new GoodsTypeQuery();
        goodsTypeQuery.setName(name);
        goodsTypeQuery.setPageNumber(pageNumber);
        goodsTypeQuery.setPageSize(pageSize);
 
        PageInfo<TGoods> data = goodsClient.listAll(goodsTypeQuery).getData();
 
//        QueryWrapper<TGoods> wrapper = new QueryWrapper<>();
//        if (StringUtils.hasLength(name)){
//            wrapper.like("name", name);
//        }
//        wrapper.orderByDesc("id");
//        List<TGoods> list = goodsService.list(wrapper);
//        PageInfo<TGoods> res = new PageInfo<>(pageNumber, pageSize);
//        res.setRecords(list);
        return AjaxResult.success(data);
    }
    @ResponseBody
    @PostMapping("/addGoods")
    @ApiOperation(value = "添加", tags = {"后台-商品管理"})
    public AjaxResult<TGoods> addGoods(@RequestBody TGoods dto) {
        goodsClient.addGoods(dto);
        return AjaxResult.success("添加成功");
    }
    @ResponseBody
    @PostMapping("/deleteGoods")
    @ApiOperation(value = "删除", tags = {"后台-商品管理"})
    public AjaxResult deleteGoods(Integer id) {
        goodsClient.deleteGoods(id);
//        TGoods byId = goodsService.getById(id);
//        goodsService.removeById(byId);
        return AjaxResult.success("删除成功");
    }
    @ResponseBody
    @PostMapping("/updateGoods")
    @ApiOperation(value = "修改", tags = {"后台-商品管理"})
    public AjaxResult<TGoods> updateGoods(@RequestBody TGoods dto) {
        goodsClient.updateGoods(dto);
        return AjaxResult.success("修改成功");
    }
    @ResponseBody
    @PostMapping("/getGoodsInfo")
    @ApiOperation(value = "查看详情", tags = {"后台-商品管理"})
    public AjaxResult<TGoodsVO> getGoodsInfo(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);
        TGoodsVO data = goodsClient.getGoodsInfo(id).getData();
 
        return AjaxResult.success(data);
    }
    @ResponseBody
    @PostMapping("/getGoodsTypeList")
    @ApiOperation(value = "获取商品类型列表", tags = {"后台-商品管理"})
    public AjaxResult<List<TGoodsType>> getGoodsInfo() {
//        List<TGoodsType> res = goodsTypeService.list(new QueryWrapper<TGoodsType>()
//                .ne("isDelete", 1));
        List<TGoodsType> data = goodsClient.getGoodsInfo().getData();
 
        return AjaxResult.success(data);
    }
 
}