From 8cd6050dfe1bcb5216e8d5e231f9c16a36de5128 Mon Sep 17 00:00:00 2001 From: HH Date: Thu, 9 Jun 2022 19:56:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=B8=8A=E6=9E=B6/=E4=B8=8B=E6=9E=B6=E6=8C=89?= =?UTF-8?q?=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/goods/GoodsController.java | 40 ++++++++++++++----- .../templates/goods/goods/goods.html | 23 +++++++++-- 2 files changed, 49 insertions(+), 14 deletions(-) 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