diff --git a/hiver-core/src/main/java/cc/hiver/core/vo/Option.java b/hiver-core/src/main/java/cc/hiver/core/vo/Option.java
new file mode 100644
index 00000000..1bcd9ee6
--- /dev/null
+++ b/hiver-core/src/main/java/cc/hiver/core/vo/Option.java
@@ -0,0 +1,52 @@
+/*
+Copyright [2022] [https://hiver.cc]
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+ */
+package cc.hiver.core.vo;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.List;
+
+/**
+ * @author Yazhi Li
+ */
+@ApiModel("涓嬫媺閫夐」瀵硅薄")
+@Data
+@NoArgsConstructor
+public class Option
{
+ public Option(T value, String label) {
+ this.value = value;
+ this.label = label;
+ }
+
+ public Option(T value, String label, List children) {
+ this.value = value;
+ this.label = label;
+ this.children= children;
+ }
+
+ @ApiModelProperty("閫夐」鐨勫")
+ private T value;
+
+ @ApiModelProperty("閫夐」鐨勬爣绛")
+ private String label;
+
+ @JsonInclude(value = JsonInclude.Include.NON_EMPTY)
+ private List children;
+}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/GoodsAttributeController.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/GoodsAttributeController.java
new file mode 100644
index 00000000..abfa48ed
--- /dev/null
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/GoodsAttributeController.java
@@ -0,0 +1,45 @@
+/*
+Copyright [2022] [https://hiver.cc]
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+ */
+package cc.hiver.mall.controller;
+
+import cc.hiver.mall.service.GoodsAttributeService;
+import cc.hiver.mall.service.GoodsCategoryAttributeService;
+import cc.hiver.mall.service.GoodsCategoryBrandService;
+import io.swagger.annotations.Api;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author Yazhi Li
+ */
+@Slf4j
+@RestController
+@Api(tags = "鍟嗗搧瑙勬牸鎺ュ彛")
+@RequestMapping(value = "/hiver/app/attribute/")
+@Transactional
+public class GoodsAttributeController {
+ @Autowired
+ private GoodsAttributeService goodsAttributeService;
+
+ @Autowired
+ private GoodsCategoryAttributeService goodsCategoryAttributeService;
+
+ @Autowired
+ private GoodsCategoryBrandService goodsCategoryBrandService;
+}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/GoodsBrandController.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/GoodsBrandController.java
index 6e1b0a88..41b7146e 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/GoodsBrandController.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/GoodsBrandController.java
@@ -1,9 +1,21 @@
package cc.hiver.mall.controller;
+import cc.hiver.core.base.HiverBaseController;
+import cc.hiver.core.base.HiverBaseService;
+import cc.hiver.core.common.utils.PageUtil;
+import cc.hiver.core.common.utils.ResultUtil;
+import cc.hiver.core.common.vo.PageVo;
+import cc.hiver.core.common.vo.Result;
+import cc.hiver.mall.entity.GoodsBrand;
+import cc.hiver.mall.service.GoodsBrandService;
import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
@@ -16,5 +28,20 @@ import org.springframework.web.bind.annotation.RestController;
@Api(tags = "鍟嗗搧鍝佺墝鎺ュ彛")
@RequestMapping(value = "/hiver/app/brand/")
@Transactional
-public class GoodsBrandController {
+public class GoodsBrandController extends HiverBaseController {
+ @Autowired
+ private GoodsBrandService goodsBrandService;
+
+ @Override
+ public HiverBaseService getService() {
+ return goodsBrandService;
+ }
+
+ @RequestMapping(value = "/getByCondition", method = RequestMethod.GET)
+ @ApiOperation(value = "澶氭潯浠跺垎椤佃幏鍙栧搧鐗屽垪琛")
+ public Result> getByCondition(GoodsBrand goodsBrand,
+ PageVo pageVo) {
+ Page page = goodsBrandService.findByCondition(goodsBrand, PageUtil.initPage(pageVo));
+ return new ResultUtil>().setData(page);
+ }
}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/GoodsCartController.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/GoodsCartController.java
new file mode 100644
index 00000000..2ee2f67e
--- /dev/null
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/GoodsCartController.java
@@ -0,0 +1,41 @@
+/*
+Copyright [2022] [https://hiver.cc]
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+ */
+package cc.hiver.mall.controller;
+
+import cc.hiver.mall.service.SalesOrderItemService;
+import cc.hiver.mall.service.SalesOrderService;
+import io.swagger.annotations.Api;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author Yazhi Li
+ */
+@Slf4j
+@RestController
+@Api(tags = "閿鍞崟鎺ュ彛")
+@RequestMapping(value = "/hiver/app/cart/")
+@Transactional
+public class GoodsCartController {
+ @Autowired
+ private SalesOrderService salesOrderService;
+
+ @Autowired
+ private SalesOrderItemService salesOrderItemService;
+}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/GoodsCategoryController.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/GoodsCategoryController.java
index cb78cf2c..30fa7168 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/GoodsCategoryController.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/GoodsCategoryController.java
@@ -1,14 +1,17 @@
package cc.hiver.mall.controller;
-import cc.hiver.core.common.constant.CommonConstant;
import cc.hiver.core.common.utils.ResultUtil;
import cc.hiver.core.common.vo.Result;
+import cc.hiver.core.vo.Option;
import cc.hiver.mall.entity.GoodsCategory;
-import cc.hiver.mall.service.GoodsCategoryService;
+import cc.hiver.mall.pojo.vo.GoodsCategoryVO;
+import cc.hiver.mall.service.mybatis.GoodsCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.CacheEvict;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
@@ -23,25 +26,54 @@ public class GoodsCategoryController {
@Autowired
private GoodsCategoryService goodsCategoryService;
- @RequestMapping(value = "/getByParentId/{parentId}", method = RequestMethod.GET)
- @ApiOperation(value = "閫氳繃parentId鑾峰彇")
- public Result> getByParentId(@PathVariable String parentId) {
- List list = goodsCategoryService.findByParentIdOrderBySortOrder(parentId);
- return new ResultUtil>().setData(list);
+ @RequestMapping(value = "/list", method = RequestMethod.GET)
+ @ApiOperation(value = "鏍规嵁parentId鑾峰緱鍟嗗搧鍒嗙被鍒楄〃")
+ public Result> list(@ApiParam("涓婄骇鍒嗙被ID") String parentId) {
+ List list = goodsCategoryService.listCategory(parentId);
+ return new ResultUtil>().setData(list);
+ }
+
+ @RequestMapping(value = "/getAll", method = RequestMethod.GET)
+ @ApiOperation(value = "鑾峰緱鍟嗗搧鍒嗙被鍒楄〃")
+ public Result> getAll() {
+ List list = goodsCategoryService.listCategory(null);
+ return new ResultUtil>().setData(list);
+ }
+
+ @RequestMapping(value = "/options", method = RequestMethod.GET)
+ @ApiOperation(value = "鍟嗗搧鍒嗙被绾ц仈鍒楄〃")
+ public Result> listCategoryOptions() {
+ List list = goodsCategoryService.listCategoryOptions();
+ return new ResultUtil>().setData(list);
+ }
+
+ @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
+ @ApiOperation(value = "鍟嗗搧鍒嗙被璇︽儏")
+ public Result get(@PathVariable String id) {
+ GoodsCategory data = goodsCategoryService.getById(id);
+ return new ResultUtil().setData(data);
}
@RequestMapping(value = "/save", method = RequestMethod.POST)
- @ApiOperation(value = "淇濆瓨鏁版嵁")
- public Result save(GoodsCategory entity) {
- GoodsCategory address = goodsCategoryService.save(entity);
- return new ResultUtil().setData(address);
+ @ApiOperation(value = "鏂板鍟嗗搧鍒嗙被")
+ public Result save(GoodsCategory entity) {
+ String id = goodsCategoryService.saveCategory(entity);
+ return ResultUtil.success(id);
+ }
+
+ @RequestMapping(value = "/edit", method = RequestMethod.POST)
+ @ApiOperation(value = "淇敼鍟嗗搧鍒嗙被")
+ public Result edit(GoodsCategory entity) {
+ String id = goodsCategoryService.saveCategory(entity);
+ return ResultUtil.success(id);
}
@RequestMapping(value = "/delByIds", method = RequestMethod.POST)
- @ApiOperation(value = "鎵归噺閫氳繃ids鍒犻櫎")
+ @ApiOperation(value = "鍒犻櫎鍟嗗搧鍒嗙被")
+ @CacheEvict(value = "mall", key = "'categoryList'")
public Result delByIds(@RequestParam String[] ids) {
for (String id : ids) {
- goodsCategoryService.delete(id);
+ goodsCategoryService.removeById(id);
}
return ResultUtil.success("鎵归噺閫氳繃id鍒犻櫎鏁版嵁鎴愬姛");
}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/GoodsCategoryDao.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/GoodsCategoryDao.java
deleted file mode 100644
index 90816c05..00000000
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/GoodsCategoryDao.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package cc.hiver.mall.dao;
-
-import cc.hiver.core.base.HiverBaseDao;
-import cc.hiver.mall.entity.GoodsCategory;
-
-import java.util.List;
-
-public interface GoodsCategoryDao extends HiverBaseDao {
- /**
- * 閫氳繃鐖秈d鑾峰彇 鍗囧簭
- *
- * @param parentId
- * @return
- */
- List findByParentIdOrderBySortOrder(String parentId);
-
- /**
- * 閫氳繃鐖秈d鍜岀姸鎬佽幏鍙 鍗囧簭
- *
- * @param parentId
- * @param status
- * @return
- */
- List findByParentIdAndStatusOrderBySortOrder(String parentId, Integer status);
-}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/GoodsCategoryMapper.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/GoodsCategoryMapper.java
new file mode 100644
index 00000000..2d676b6f
--- /dev/null
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/GoodsCategoryMapper.java
@@ -0,0 +1,27 @@
+/*
+Copyright [2022] [https://hiver.cc]
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+ */
+package cc.hiver.mall.dao.mapper;
+
+import cc.hiver.mall.entity.GoodsCategory;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * @author Yazhi Li
+ */
+@Mapper
+public interface GoodsCategoryMapper extends BaseMapper {
+}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/GoodsCategoryVO.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/GoodsCategoryVO.java
new file mode 100644
index 00000000..f6fc6a09
--- /dev/null
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/GoodsCategoryVO.java
@@ -0,0 +1,56 @@
+/*
+Copyright [2022] [https://hiver.cc]
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+ */
+package cc.hiver.mall.pojo.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.persistence.Column;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Yazhi Li
+ */
+@Data
+public class GoodsCategoryVO {
+ @ApiModelProperty(value = "缂栧彿")
+ private String id;
+
+ @ApiModelProperty(value = "鍟嗗搧鍒嗙被鍚嶇О")
+ private String name;
+
+ @ApiModelProperty(value = "鐖剁骇ID")
+ @Column(nullable = false)
+ private String parentId;
+
+ @ApiModelProperty(value = "灞傜骇")
+ private Integer level;
+
+ @ApiModelProperty(value = "鍥炬爣鍦板潃")
+ private String iconUrl;
+
+ @ApiModelProperty(value = "鎺掑簭鍊")
+ @Column(precision = 10, scale = 2)
+ private BigDecimal sortOrder;
+
+ @ApiModelProperty(value = "鏄惁鍚敤 0鍚敤 -1绂佺敤")
+ private Integer status;
+
+ @ApiModelProperty(value = "瀛愯妭鐐")
+ private List children = new ArrayList<>();
+}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/GoodsBrandService.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/GoodsBrandService.java
index cce645b3..5aa0f9e5 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/GoodsBrandService.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/GoodsBrandService.java
@@ -2,6 +2,8 @@ package cc.hiver.mall.service;
import cc.hiver.core.base.HiverBaseService;
import cc.hiver.mall.entity.GoodsBrand;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
/**
* 鍟嗗搧鍝佺墝鏈嶅姟鎺ュ彛
@@ -9,4 +11,5 @@ import cc.hiver.mall.entity.GoodsBrand;
* @author Yazhi Li
*/
public interface GoodsBrandService extends HiverBaseService {
+ Page findByCondition(GoodsBrand goodsBrand, Pageable pageable);
}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/GoodsCategoryService.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/GoodsCategoryService.java
deleted file mode 100644
index 45bee869..00000000
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/GoodsCategoryService.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package cc.hiver.mall.service;
-
-import cc.hiver.core.base.HiverBaseService;
-import cc.hiver.mall.entity.GoodsCategory;
-
-import java.util.List;
-
-public interface GoodsCategoryService extends HiverBaseService {
- /**
- * 閫氳繃鐖秈d鑾峰彇 鍗囧簭
- *
- * @param parentId
- * @return
- */
- List findByParentIdOrderBySortOrder(String parentId);
-
- /**
- * 閫氳繃鐖秈d鍜岀姸鎬佽幏鍙 鍗囧簭
- *
- * @param parentId
- * @param status
- * @return
- */
- List findByParentIdAndStatusOrderBySortOrder(String parentId, Integer status);
-}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/GoodsCategoryService.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/GoodsCategoryService.java
new file mode 100644
index 00000000..e1527c7f
--- /dev/null
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/GoodsCategoryService.java
@@ -0,0 +1,16 @@
+package cc.hiver.mall.service.mybatis;
+
+import cc.hiver.core.vo.Option;
+import cc.hiver.mall.entity.GoodsCategory;
+import cc.hiver.mall.pojo.vo.GoodsCategoryVO;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+import java.util.List;
+
+public interface GoodsCategoryService extends IService {
+ List listCategory(String parentId);
+
+ List listCategoryOptions();
+
+ String saveCategory(GoodsCategory category);
+}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/GoodsBrandServiceImpl.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/GoodsBrandServiceImpl.java
index c4254385..51d64967 100644
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/GoodsBrandServiceImpl.java
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/GoodsBrandServiceImpl.java
@@ -4,11 +4,20 @@ import cc.hiver.core.base.HiverBaseDao;
import cc.hiver.mall.dao.GoodsBrandDao;
import cc.hiver.mall.entity.GoodsBrand;
import cc.hiver.mall.service.GoodsBrandService;
+import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import javax.persistence.criteria.*;
+import java.util.ArrayList;
+import java.util.List;
+
@Slf4j
@Service
@Transactional
@@ -20,4 +29,27 @@ public class GoodsBrandServiceImpl implements GoodsBrandService {
public HiverBaseDao getRepository() {
return goodsBrandDao;
}
+
+ @Override
+ public Page findByCondition(GoodsBrand goodsBrand, Pageable pageable) {
+ return goodsBrandDao.findAll(new Specification() {
+ @Nullable
+ @Override
+ public Predicate toPredicate(Root root, CriteriaQuery> cq, CriteriaBuilder cb) {
+
+ Path nameField = root.get("name");
+
+ List list = new ArrayList<>();
+
+ // 妯$硦鎼滅礌
+ if (StrUtil.isNotBlank(goodsBrand.getName())) {
+ list.add(cb.like(nameField, '%' + goodsBrand.getName() + '%'));
+ }
+
+ Predicate[] arr = new Predicate[list.size()];
+ cq.where(list.toArray(arr));
+ return null;
+ }
+ }, pageable);
+ }
}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/GoodsCategoryServiceImpl.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/GoodsCategoryServiceImpl.java
deleted file mode 100644
index 93170fbb..00000000
--- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/GoodsCategoryServiceImpl.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package cc.hiver.mall.serviceimpl;
-
-import cc.hiver.core.base.HiverBaseDao;
-import cc.hiver.mall.dao.GoodsCategoryDao;
-import cc.hiver.mall.entity.GoodsCategory;
-import cc.hiver.mall.service.GoodsCategoryService;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.util.List;
-
-@Slf4j
-@Service
-@Transactional
-public class GoodsCategoryServiceImpl implements GoodsCategoryService {
- @Autowired
- private GoodsCategoryDao goodsCategoryDao;
-
- @Override
- public HiverBaseDao getRepository() {
- return goodsCategoryDao;
- }
-
- @Override
- public List findByParentIdOrderBySortOrder(String parentId) {
- return goodsCategoryDao.findByParentIdOrderBySortOrder(parentId);
- }
-
- @Override
- public List findByParentIdAndStatusOrderBySortOrder(String parentId, Integer status) {
- return goodsCategoryDao.findByParentIdAndStatusOrderBySortOrder(parentId, status);
- }
-}
diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/GoodsCategoryServiceImpl.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/GoodsCategoryServiceImpl.java
new file mode 100644
index 00000000..8b557b42
--- /dev/null
+++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/GoodsCategoryServiceImpl.java
@@ -0,0 +1,82 @@
+package cc.hiver.mall.serviceimpl.mybatis;
+
+import cc.hiver.core.common.constant.CommonConstant;
+import cc.hiver.core.vo.Option;
+import cc.hiver.mall.dao.mapper.GoodsCategoryMapper;
+import cc.hiver.mall.entity.GoodsCategory;
+import cc.hiver.mall.pojo.vo.GoodsCategoryVO;
+import cc.hiver.mall.service.mybatis.GoodsCategoryService;
+import cn.hutool.core.bean.BeanUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+@Service
+public class GoodsCategoryServiceImpl extends ServiceImpl implements GoodsCategoryService {
+ @Override
+ public List listCategory(String parentId) {
+ List categoryList = this.list(
+ new LambdaQueryWrapper()
+ .eq(GoodsCategory::getStatus, CommonConstant.STATUS_NORMAL)
+ .orderByDesc(GoodsCategory::getSortOrder)
+ );
+ List list = recursionTree(parentId != null ? parentId : CommonConstant.PARENT_ID, categoryList);
+ return list;
+ }
+
+ private static List recursionTree(String parentId, List categoryList) {
+ List list = new ArrayList<>();
+ Optional.ofNullable(categoryList)
+ .ifPresent(categories ->
+ categories.stream().filter(category ->
+ category.getParentId().equals(parentId))
+ .forEach(category -> {
+ GoodsCategoryVO goodsCategoryVO = new GoodsCategoryVO();
+ BeanUtil.copyProperties(category, goodsCategoryVO);
+ List children = recursionTree(category.getId(), categoryList);
+ goodsCategoryVO.setChildren(children);
+ list.add(goodsCategoryVO);
+ }));
+ return list;
+ }
+
+ @Override
+ public List listCategoryOptions() {
+ List categoryList = this.list(
+ new LambdaQueryWrapper()
+ .eq(GoodsCategory::getStatus, CommonConstant.STATUS_NORMAL)
+ .orderByAsc(GoodsCategory::getSortOrder)
+ );
+ List list = recursionCascade(CommonConstant.PARENT_ID, categoryList);
+ return list;
+ }
+
+ private List recursionCascade(String parentId, List categoryList) {
+ List list = new ArrayList<>();
+ Optional.ofNullable(categoryList)
+ .ifPresent(categories ->
+ categories.stream().filter(category ->
+ category.getParentId().equals(parentId))
+ .forEach(category -> {
+ Option categoryVO = new Option<>(category.getId(), category.getName());
+ BeanUtil.copyProperties(category, categoryVO);
+ List children = recursionCascade(category.getId(), categoryList);
+ categoryVO.setChildren(children);
+ list.add(categoryVO);
+ })
+ );
+ return list;
+ }
+
+ @CacheEvict(value = "mall", key = "'categoryList'")
+ @Override
+ public String saveCategory(GoodsCategory category) {
+ this.saveOrUpdate(category);
+ return category.getId();
+ }
+}