Explorar o código

增加商品分类接口

周箭河 %!s(int64=5) %!d(string=hai) anos
pai
achega
d5f665a23e

+ 2 - 1
mec-auth/mec-auth-server/src/main/java/com/ym/mec/auth/dal/dao/SysMenuDao.java

@@ -2,6 +2,7 @@ package com.ym.mec.auth.dal.dao;
 
 import com.ym.mec.auth.api.entity.SysMenu;
 import com.ym.mec.common.dal.BaseDAO;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -26,5 +27,5 @@ public interface SysMenuDao extends BaseDAO<Integer, SysMenu> {
      * 根据权限标识查菜单
      * @return
      */
-    SysMenu findMenuByPermission(String permission);
+    SysMenu findMenuByPermission(@Param("permission") String permission);
 }

+ 3 - 1
mec-auth/mec-auth-server/src/main/java/com/ym/mec/auth/dal/dao/SysRoleDao.java

@@ -2,6 +2,8 @@ package com.ym.mec.auth.dal.dao;
 
 import com.ym.mec.auth.api.entity.SysRole;
 import com.ym.mec.common.dal.BaseDAO;
+import org.apache.ibatis.annotations.Param;
+
 import java.util.List;
 
 public interface SysRoleDao extends BaseDAO<Integer, SysRole> {
@@ -18,5 +20,5 @@ public interface SysRoleDao extends BaseDAO<Integer, SysRole> {
      * @param code
      * @return
      */
-    SysRole findRoleByCode(String code);
+    SysRole findRoleByCode(@Param("code") String code);
 }

+ 58 - 0
mec-web/src/main/java/com/ym/mec/web/controller/GoodsCategoryController.java

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

+ 7 - 0
mec-web/src/main/java/com/ym/mec/web/dal/dao/GoodsDao.java

@@ -14,4 +14,11 @@ public interface GoodsDao extends BaseDAO<Integer, Goods> {
      * @return
      */
     List<Goods> findGoodsBySubId(@Param("subjectId") Integer subjectId, @Param("goodsCategoryId") Integer goodsCategoryId);
+
+    /**
+     * 根据商品分类查找商品数量
+     * @param goodsCategoryId
+     * @return
+     */
+    int findGoodsNumByCategoryId(@Param("goodsCategoryId") Integer goodsCategoryId);
 }

+ 9 - 0
mec-web/src/main/java/com/ym/mec/web/service/GoodsService.java

@@ -2,6 +2,7 @@ package com.ym.mec.web.service;
 
 import com.ym.mec.common.service.BaseService;
 import com.ym.mec.web.dal.entity.Goods;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -13,4 +14,12 @@ public interface GoodsService extends BaseService<Integer, Goods> {
      * @return
      */
     List<Goods> findGoodsBySubId(Integer subjectId,Integer goodsCategoryId);
+
+    /**
+     * 根据商品分类id查找商品数量
+     * @param goodsCategoryId
+     * @return
+     */
+    int findGoodsNumByCategoryId(@Param("goodsCategoryId") Integer goodsCategoryId);
+
 }

+ 4 - 0
mec-web/src/main/java/com/ym/mec/web/service/impl/GoodsServiceImpl.java

@@ -26,4 +26,8 @@ public class GoodsServiceImpl extends BaseServiceImpl<Integer, Goods>  implement
 	public List<Goods> findGoodsBySubId(Integer subjectId,Integer goodsCategoryId) {
 		return goodsDao.findGoodsBySubId(subjectId,goodsCategoryId);
 	}
+
+	public int findGoodsNumByCategoryId(Integer goodsCategoryId){
+		return goodsDao.findGoodsNumByCategoryId(goodsCategoryId);
+	}
 }

+ 5 - 0
mec-web/src/main/resources/config/mybatis/GoodsMapper.xml

@@ -138,4 +138,9 @@
         SELECT g.* FROM subject_goods_mapper sgm LEFT JOIN goods g ON sgm.goods_id_ = g.id_
         WHERE sgm.subject_id_ =  #{subjectId} AND g.goods_category_id_ = #{goodsCategoryId}
     </select>
+
+    <!-- 根据 -->
+    <select id="findGoodsNumByCategoryId" resultType="int">
+        SELECT COUNT(*) FROM goods WHERE goods_category_id_ = #{goodsCategoryId}
+    </select>
 </mapper>