diff --git a/src/main/java/com/hxtec/polaris/controller/CategoryController.java b/src/main/java/com/hxtec/polaris/controller/CategoryController.java index dbfd53e99baac7976e9dcee36d276ef12d095c52..22e7b42c45447376231639e080c420cba0492991 100644 --- a/src/main/java/com/hxtec/polaris/controller/CategoryController.java +++ b/src/main/java/com/hxtec/polaris/controller/CategoryController.java @@ -77,4 +77,14 @@ public class CategoryController { public Object updateCategory(HttpServletRequest request,String id, String pid, String name){ return categoryService.updateCategory(request,pid,id,name); } + + /** + * 构建分类tree + * @param id + * @return + */ + @GetMapping("buildTree") + public Object buildTree(Integer id){ + return categoryService.buildTree(id); + } } diff --git a/src/main/java/com/hxtec/polaris/mapper/ShopCategoryMapper.java b/src/main/java/com/hxtec/polaris/mapper/ShopCategoryMapper.java index 525e96a258494080540325933da9d2da524d2a93..e6c8d806827cec7c3c56a2f62b0247a02d2ab2a1 100644 --- a/src/main/java/com/hxtec/polaris/mapper/ShopCategoryMapper.java +++ b/src/main/java/com/hxtec/polaris/mapper/ShopCategoryMapper.java @@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Param; import tk.mybatis.mapper.MyMapper; import java.util.List; +import java.util.Map; /** * @author yonyong @@ -75,4 +76,17 @@ public interface ShopCategoryMapper extends MyMapper { * @return */ Integer updateCategoryPath(@Param("id") String id,@Param("path") String path); + + /** + * 初始化tree + * @return + */ + List> getFirstTree(); + + /** + * 获取下级分类信息 + * @param id + * @return + */ + List> getChildTree(Integer id); } \ No newline at end of file diff --git a/src/main/java/com/hxtec/polaris/service/CategoryService.java b/src/main/java/com/hxtec/polaris/service/CategoryService.java index 5d7242ba6af08a90ae5d040018511684ce048136..42200fdfc453a31117999b4d514e7aaee6c2e1f6 100644 --- a/src/main/java/com/hxtec/polaris/service/CategoryService.java +++ b/src/main/java/com/hxtec/polaris/service/CategoryService.java @@ -35,4 +35,11 @@ public interface CategoryService { * @return */ Object updateCategory(HttpServletRequest request, String pid, String id, String name); + + /** + * 构建分类tree + * @param id + * @return + */ + Object buildTree(Integer id); } diff --git a/src/main/java/com/hxtec/polaris/service/impl/CategoryServiceImpl.java b/src/main/java/com/hxtec/polaris/service/impl/CategoryServiceImpl.java index f3c560b3121912e24745a3d8fe07174f42ffde7f..53d7de27d0428115a07664bdcf9750b78c405e79 100644 --- a/src/main/java/com/hxtec/polaris/service/impl/CategoryServiceImpl.java +++ b/src/main/java/com/hxtec/polaris/service/impl/CategoryServiceImpl.java @@ -21,6 +21,7 @@ import javax.servlet.http.HttpServletRequest; import java.text.MessageFormat; import java.util.Date; import java.util.List; +import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ThreadFactory; @@ -134,6 +135,19 @@ public class CategoryServiceImpl implements CategoryService { return Result.ok(Msg.CATEGORY_UPDATE_OK); } + @Override + public Object buildTree(Integer id) { + if (null == id){ + //初始化tree + List> mapList = shopCategoryMapper.getFirstTree(); + return Result.ok(mapList); + }else { + //获取下级分类信息 + List> mapList = shopCategoryMapper.getChildTree(id); + return Result.ok(mapList); + } + } + /** * ShopCategory实例赋值 * @param pid diff --git a/src/main/resources/mapper/ShopCategoryMapper.xml b/src/main/resources/mapper/ShopCategoryMapper.xml index f0deae71364b9797a52662363f6cfad5b006dcc5..130cc06f4d85791d8137459fd19ca8ef9fe7843e 100644 --- a/src/main/resources/mapper/ShopCategoryMapper.xml +++ b/src/main/resources/mapper/ShopCategoryMapper.xml @@ -38,6 +38,17 @@ from shop_category where is_delete='N' and id = #{id} + + + insert into shop_category (parent_id, is_parent,