diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsController.java b/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsController.java index fce2f0b8..ddda3036 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsController.java @@ -18,7 +18,6 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.*; -import java.util.stream.Collectors; @Controller @RequestMapping("/goods/goods") @@ -43,13 +42,13 @@ public class GoodsController extends BaseController { return PREFIX + "/goods"; } -// @RequiresPermissions("goods:goods:list") + // @RequiresPermissions("goods:goods:list") @PostMapping("/list") @ResponseBody - public TableDataInfo list(@RequestBody Goods goods) { + public TableDataInfo list(Goods goods) { startPage(); List list = goodsService.selectGoodsList(goods); - list.forEach(one->{ + list.forEach(one -> { // 补全商品 List goodsAreas = goodsAreaService.selectByGoodsId(one.getGoodsId()); one.setGoodsAreaList(goodsAreas); @@ -70,13 +69,13 @@ public class GoodsController extends BaseController { deptGoodsCategory.setLevel(2); List categoryList = deptGoodsCategoryService.list(deptGoodsCategory); Collection ids = new ArrayList<>(); - categoryList.forEach(category->{ + categoryList.forEach(category -> { ids.add(category.getGoodsCategoryId()); }); startPage(); List list = goodsService.selectByCategoryIds(ids); - list.forEach(one->{ + list.forEach(one -> { // 补全商品 List goodsAreas = goodsAreaService.selectByGoodsId(one.getGoodsId()); one.setGoodsAreaList(goodsAreas); @@ -90,11 +89,11 @@ public class GoodsController extends BaseController { @PostMapping("/addGoods") @ResponseBody - public AjaxResult addGoods(@RequestBody Goods goods){ + public AjaxResult addGoods(@RequestBody Goods goods) { try { goodsService.addGoods(goods); return AjaxResult.success("新增成功"); - }catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage()); return AjaxResult.error(ExceptionUtil.getExceptionMessage(e)); @@ -103,7 +102,7 @@ public class GoodsController extends BaseController { @PostMapping("/getDetail") @ResponseBody - public AjaxResult getDetail(@RequestBody Goods goods){ + public AjaxResult getDetail(@RequestBody Goods goods) { try { Goods result = goodsService.selectById(goods.getGoodsId()); @@ -124,7 +123,7 @@ public class GoodsController extends BaseController { result.setGoodsStandardList(goodsStandards); return AjaxResult.success(result); - }catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); logger.error(e.getMessage()); return AjaxResult.error(ExceptionUtil.getExceptionMessage(e)); @@ -222,4 +221,25 @@ public class GoodsController extends BaseController { return goodsService.checkGoodsCodeUnique(goods); } + /** + * 修改商品状态 + * + * @param goodsId 商品ID + * @param status 0=上架,1=下架,2删除 + */ + @PostMapping("/status") + @ResponseBody + public AjaxResult status(Long goodsId, Integer status) { + try { + Goods goods = new Goods(); + goods.setGoodsId(goodsId); + goods.setStatus(status); + goodsService.updateGoods(goods); + return AjaxResult.success("操作成功"); + } catch (Exception e) { + e.printStackTrace(); + logger.error(e.getMessage()); + return AjaxResult.error(ExceptionUtil.getExceptionMessage(e)); + } + } } diff --git a/ghy-admin/src/main/resources/templates/goods/goods/goods.html b/ghy-admin/src/main/resources/templates/goods/goods/goods.html index efd2b5ce..270a6d3f 100644 --- a/ghy-admin/src/main/resources/templates/goods/goods/goods.html +++ b/ghy-admin/src/main/resources/templates/goods/goods/goods.html @@ -16,7 +16,7 @@
  • 类目状态:
  • @@ -34,9 +34,9 @@ 新增 - - - + + +
    @@ -111,6 +111,12 @@ align: 'left', formatter: function (value, row, index) { var actions = []; + if (row.status === 1) { + actions.push('上架 '); + } + if (row.status === 0) { + actions.push('下架 '); + } actions.push('编辑 '); actions.push('删除'); return actions.join(''); @@ -119,6 +125,15 @@ }; $.table.init(options); }); + + function enable(goodsId) { + $.operate.post(prefix + "/status?goodsId=" + goodsId + "&status=" + 0); + } + + function disable(goodsId) { + $.operate.post(prefix + "/status?goodsId=" + goodsId + "&status=" + 1); + } + \ No newline at end of file