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);
|
}
|
|
}
|