| | |
| | | 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.domain.TOrder; |
| | | 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 com.ruoyi.management.vo.TGoodsVO; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.List; |
| | |
| | | @ApiOperation(value = "列表查询", tags = {"后台-商品类型管理"}) |
| | | |
| | | public AjaxResult<PageInfo<TGoodsType>> listType(String name, Integer pageNumber, Integer pageSize){ |
| | | QueryWrapper<TGoodsType> wrapper = new QueryWrapper<>(); |
| | | if (StringUtils.hasLength(name)){ |
| | | wrapper.like("name", name); |
| | | } |
| | | wrapper.ne("isDelete",1); |
| | | wrapper.orderByDesc("id"); |
| | | List<TGoodsType> list = goodsTypeService.list(wrapper); |
| | | PageInfo<TGoodsType> res = new PageInfo<>(pageNumber, pageSize); |
| | | res.setRecords(list); |
| | | GoodsTypeQuery goodsTypeQuery = new GoodsTypeQuery(); |
| | | goodsTypeQuery.setName(name); |
| | | goodsTypeQuery.setPageNumber(pageNumber); |
| | | goodsTypeQuery.setPageSize(pageSize); |
| | | |
| | | // PageInfo<TGoodsType> data = goodsClient.listType(goodsTypeQuery).getData(); |
| | | return AjaxResult.success(res); |
| | | PageInfo<TGoodsType> data = goodsClient.listType(goodsTypeQuery).getData(); |
| | | return AjaxResult.success(data); |
| | | } |
| | | @ResponseBody |
| | | @PostMapping("/addGoodsType") |
| | | @ApiOperation(value = "添加", tags = {"后台-商品类型管理"}) |
| | | public AjaxResult<TGoods> addGoodsType(TGoodsType dto) { |
| | | goodsTypeService.save(dto); |
| | | goodsClient.addGoodsType(dto); |
| | | // goodsTypeService.save(dto); |
| | | return AjaxResult.success("添加成功"); |
| | | } |
| | | @ResponseBody |
| | | @PostMapping("/updateGoodsType") |
| | | @ApiOperation(value = "修改", tags = {"后台-商品类型管理"}) |
| | | public AjaxResult<TGoods> updateGoodsType(TGoodsType dto) { |
| | | goodsTypeService.updateById(dto); |
| | | goodsClient.updateGoodsType(dto); |
| | | // goodsTypeService.updateById(dto); |
| | | return AjaxResult.success("修改成功"); |
| | | } |
| | | @ResponseBody |
| | | @PostMapping("/deleteGoodsType") |
| | | @ApiOperation(value = "删除", tags = {"后台-商品类型管理"}) |
| | | public AjaxResult deleteGoodsType(Integer id) { |
| | | TGoodsType byId = goodsTypeService.getById(id); |
| | | byId.setIsDelete(1); |
| | | goodsTypeService.updateById(byId); |
| | | goodsClient.deleteGoodsType(id); |
| | | // TGoodsType byId = goodsTypeService.getById(id); |
| | | // byId.setIsDelete(1); |
| | | // goodsTypeService.updateById(byId); |
| | | return AjaxResult.success("删除成功"); |
| | | } |
| | | @ResponseBody |
| | | @GetMapping("/listAll") |
| | | @ApiOperation(value = "列表查询", tags = {"后台-商品管理"}) |
| | | public AjaxResult<PageInfo<TGoods>> listAll(String name, Integer pageNumber, Integer pageSize){ |
| | | 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(res); |
| | | 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) { |
| | | goodsService.save(dto); |
| | | goodsClient.addGoods(dto); |
| | | return AjaxResult.success("添加成功"); |
| | | } |
| | | @ResponseBody |
| | | @PostMapping("/deleteGoods") |
| | | @ApiOperation(value = "删除", tags = {"后台-商品管理"}) |
| | | public AjaxResult deleteGoods(Integer id) { |
| | | TGoods byId = goodsService.getById(id); |
| | | goodsService.removeById(byId); |
| | | 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) { |
| | | goodsService.updateById(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); |
| | | return AjaxResult.success(tGoodsVO); |
| | | // 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)); |
| | | return AjaxResult.success(res); |
| | | // List<TGoodsType> res = goodsTypeService.list(new QueryWrapper<TGoodsType>() |
| | | // .ne("isDelete", 1)); |
| | | List<TGoodsType> data = goodsClient.getGoodsInfo().getData(); |
| | | |
| | | return AjaxResult.success(data); |
| | | } |
| | | |
| | | } |