|
@@ -0,0 +1,58 @@
|
|
|
+package com.ym.mec.web.controller;
|
|
|
+
|
|
|
+import com.ym.mec.common.controller.BaseController;
|
|
|
+import com.ym.mec.web.dal.entity.GoodsCategory;
|
|
|
+import com.ym.mec.web.service.GoodsCategoryService;
|
|
|
+import com.ym.mec.web.service.GoodsService;
|
|
|
+import io.swagger.annotations.*;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+@RequestMapping("category")
|
|
|
+@Api(tags = "商品分类服务")
|
|
|
+@RestController
|
|
|
+public class GoodsCategoryController extends BaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GoodsCategoryService GoodsCategoryCategoryService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GoodsService goodsService;
|
|
|
+
|
|
|
+ @ApiOperation(value = "新增商品分类")
|
|
|
+ @PostMapping("/add")
|
|
|
+ public Object add(GoodsCategory goodsCategory) {
|
|
|
+ Date date = new Date();
|
|
|
+ goodsCategory.setCreateTime(date);
|
|
|
+ goodsCategory.setUpdateTime(date);
|
|
|
+ GoodsCategoryCategoryService.insert(goodsCategory);
|
|
|
+ return succeed();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "删除商品分类")
|
|
|
+ @DeleteMapping("/del/{id}")
|
|
|
+ public Object del(@ApiParam(value = "商品分类编号", required = true) @PathVariable("id") Integer id) {
|
|
|
+ int num = goodsService.findGoodsNumByCategoryId(id);
|
|
|
+ if (num > 0) {
|
|
|
+ return failed("商品分类下有商品,不能删除");
|
|
|
+ }
|
|
|
+ GoodsCategoryCategoryService.delete(id);
|
|
|
+ return succeed();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "修改商品分类")
|
|
|
+ @PutMapping("/update")
|
|
|
+ public Object update(GoodsCategory goodsCategory) {
|
|
|
+ goodsCategory.setUpdateTime(new Date());
|
|
|
+ GoodsCategoryCategoryService.update(goodsCategory);
|
|
|
+ return succeed();
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "根据商品分类编号查询商品分类")
|
|
|
+ @GetMapping("/get/{id}")
|
|
|
+ public Object get(@ApiParam(value = "商品分类编号", required = true) @PathVariable("id") Integer id) {
|
|
|
+ return succeed(GoodsCategoryCategoryService.get(id));
|
|
|
+ }
|
|
|
+}
|