Browse Source

更新品牌和分类的逻辑。

cangku
delicacylee 3 years ago
parent
commit
73aff9031f
No known key found for this signature in database GPG Key ID: 40CBD364B612268F
  1. 16
      hiver-admin/test-output/test-report.html
  2. 52
      hiver-core/src/main/java/cc/hiver/core/vo/Option.java
  3. 45
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/GoodsAttributeController.java
  4. 29
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/GoodsBrandController.java
  5. 41
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/GoodsCartController.java
  6. 58
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/GoodsCategoryController.java
  7. 25
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/GoodsCategoryDao.java
  8. 27
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/mapper/GoodsCategoryMapper.java
  9. 56
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/GoodsCategoryVO.java
  10. 3
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/GoodsBrandService.java
  11. 25
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/GoodsCategoryService.java
  12. 16
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/mybatis/GoodsCategoryService.java
  13. 32
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/GoodsBrandServiceImpl.java
  14. 35
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/GoodsCategoryServiceImpl.java
  15. 82
      hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/mybatis/GoodsCategoryServiceImpl.java

16
hiver-admin/test-output/test-report.html

@ -35,7 +35,7 @@
<a href="#"><span class="badge badge-primary">Hiver</span></a>
</li>
<li class="m-r-10">
<a href="#"><span class="badge badge-primary">七月 30, 2023 16:13:08</span></a>
<a href="#"><span class="badge badge-primary">七月 31, 2023 09:25:02</span></a>
</li>
</ul>
</div>
@ -84,7 +84,7 @@
<div class="test-detail">
<span class="meta text-white badge badge-sm"></span>
<p class="name">passTest</p>
<p class="text-sm"><span>16:13:08 下</span> / <span>0.012 secs</span></p>
<p class="text-sm"><span>09:25:03 上</span> / <span>0.022 secs</span></p>
</div>
<div class="test-contents d-none">
<div class="detail-head">
@ -92,9 +92,9 @@
<div class="info">
<div class='float-right'><span class='badge badge-default'>#test-id=1</span></div>
<h5 class="test-status text-pass">passTest</h5>
<span class='badge badge-success'>07.30.2023 16:13:08</span>
<span class='badge badge-danger'>07.30.2023 16:13:08</span>
<span class='badge badge-default'>0.012 secs</span>
<span class='badge badge-success'>07.31.2023 09:25:03</span>
<span class='badge badge-danger'>07.31.2023 09:25:03</span>
<span class='badge badge-default'>0.022 secs</span>
</div>
<div class="m-t-10 m-l-5"></div>
</div>
@ -104,7 +104,7 @@
<tbody>
<tr class="event-row">
<td><span class="badge log pass-bg">Pass</span></td>
<td>16:13:08</td>
<td>9:25:03</td>
<td>
Test passed
</td>
@ -128,13 +128,13 @@
<div class="col-md-3">
<div class="card"><div class="card-body">
<p class="m-b-0">Started</p>
<h3>七月 30, 2023 16:13:08</h3>
<h3>七月 31, 2023 09:25:02</h3>
</div></div>
</div>
<div class="col-md-3">
<div class="card"><div class="card-body">
<p class="m-b-0">Ended</p>
<h3>七月 30, 2023 16:13:08</h3>
<h3>七月 31, 2023 09:25:03</h3>
</div></div>
</div>
<div class="col-md-3">

52
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<T> {
public Option(T value, String label) {
this.value = value;
this.label = label;
}
public Option(T value, String label, List<Option> 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<Option> children;
}

45
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;
}

29
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<GoodsBrand, String> {
@Autowired
private GoodsBrandService goodsBrandService;
@Override
public HiverBaseService<GoodsBrand, String> getService() {
return goodsBrandService;
}
@RequestMapping(value = "/getByCondition", method = RequestMethod.GET)
@ApiOperation(value = "多条件分页获取品牌列表")
public Result<Page<GoodsBrand>> getByCondition(GoodsBrand goodsBrand,
PageVo pageVo) {
Page<GoodsBrand> page = goodsBrandService.findByCondition(goodsBrand, PageUtil.initPage(pageVo));
return new ResultUtil<Page<GoodsBrand>>().setData(page);
}
}

41
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;
}

58
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<List<GoodsCategory>> getByParentId(@PathVariable String parentId) {
List<GoodsCategory> list = goodsCategoryService.findByParentIdOrderBySortOrder(parentId);
return new ResultUtil<List<GoodsCategory>>().setData(list);
@RequestMapping(value = "/list", method = RequestMethod.GET)
@ApiOperation(value = "根据parentId获得商品分类列表")
public Result<List<GoodsCategoryVO>> list(@ApiParam("上级分类ID") String parentId) {
List<GoodsCategoryVO> list = goodsCategoryService.listCategory(parentId);
return new ResultUtil<List<GoodsCategoryVO>>().setData(list);
}
@RequestMapping(value = "/getAll", method = RequestMethod.GET)
@ApiOperation(value = "获得商品分类列表")
public Result<List<GoodsCategoryVO>> getAll() {
List<GoodsCategoryVO> list = goodsCategoryService.listCategory(null);
return new ResultUtil<List<GoodsCategoryVO>>().setData(list);
}
@RequestMapping(value = "/options", method = RequestMethod.GET)
@ApiOperation(value = "商品分类级联列表")
public Result<List<Option>> listCategoryOptions() {
List<Option> list = goodsCategoryService.listCategoryOptions();
return new ResultUtil<List<Option>>().setData(list);
}
@RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
@ApiOperation(value = "商品分类详情")
public Result<GoodsCategory> get(@PathVariable String id) {
GoodsCategory data = goodsCategoryService.getById(id);
return new ResultUtil<GoodsCategory>().setData(data);
}
@RequestMapping(value = "/save", method = RequestMethod.POST)
@ApiOperation(value = "保存数据")
public Result<GoodsCategory> save(GoodsCategory entity) {
GoodsCategory address = goodsCategoryService.save(entity);
return new ResultUtil<GoodsCategory>().setData(address);
@ApiOperation(value = "新增商品分类")
public Result<String> save(GoodsCategory entity) {
String id = goodsCategoryService.saveCategory(entity);
return ResultUtil.success(id);
}
@RequestMapping(value = "/edit", method = RequestMethod.POST)
@ApiOperation(value = "修改商品分类")
public Result<String> 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删除数据成功");
}

25
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/dao/GoodsCategoryDao.java

@ -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<GoodsCategory, String> {
/**
* 通过父id获取 升序
*
* @param parentId
* @return
*/
List<GoodsCategory> findByParentIdOrderBySortOrder(String parentId);
/**
* 通过父id和状态获取 升序
*
* @param parentId
* @param status
* @return
*/
List<GoodsCategory> findByParentIdAndStatusOrderBySortOrder(String parentId, Integer status);
}

27
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<GoodsCategory> {
}

56
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<GoodsCategoryVO> children = new ArrayList<>();
}

3
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<GoodsBrand, String> {
Page<GoodsBrand> findByCondition(GoodsBrand goodsBrand, Pageable pageable);
}

25
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/service/GoodsCategoryService.java

@ -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<GoodsCategory, String> {
/**
* 通过父id获取 升序
*
* @param parentId
* @return
*/
List<GoodsCategory> findByParentIdOrderBySortOrder(String parentId);
/**
* 通过父id和状态获取 升序
*
* @param parentId
* @param status
* @return
*/
List<GoodsCategory> findByParentIdAndStatusOrderBySortOrder(String parentId, Integer status);
}

16
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<GoodsCategory> {
List<GoodsCategoryVO> listCategory(String parentId);
List<Option> listCategoryOptions();
String saveCategory(GoodsCategory category);
}

32
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<GoodsBrand, String> getRepository() {
return goodsBrandDao;
}
@Override
public Page<GoodsBrand> findByCondition(GoodsBrand goodsBrand, Pageable pageable) {
return goodsBrandDao.findAll(new Specification<GoodsBrand>() {
@Nullable
@Override
public Predicate toPredicate(Root<GoodsBrand> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
Path<String> nameField = root.get("name");
List<Predicate> 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);
}
}

35
hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/GoodsCategoryServiceImpl.java

@ -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<GoodsCategory, String> getRepository() {
return goodsCategoryDao;
}
@Override
public List<GoodsCategory> findByParentIdOrderBySortOrder(String parentId) {
return goodsCategoryDao.findByParentIdOrderBySortOrder(parentId);
}
@Override
public List<GoodsCategory> findByParentIdAndStatusOrderBySortOrder(String parentId, Integer status) {
return goodsCategoryDao.findByParentIdAndStatusOrderBySortOrder(parentId, status);
}
}

82
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<GoodsCategoryMapper, GoodsCategory> implements GoodsCategoryService {
@Override
public List<GoodsCategoryVO> listCategory(String parentId) {
List<GoodsCategory> categoryList = this.list(
new LambdaQueryWrapper<GoodsCategory>()
.eq(GoodsCategory::getStatus, CommonConstant.STATUS_NORMAL)
.orderByDesc(GoodsCategory::getSortOrder)
);
List<GoodsCategoryVO> list = recursionTree(parentId != null ? parentId : CommonConstant.PARENT_ID, categoryList);
return list;
}
private static List<GoodsCategoryVO> recursionTree(String parentId, List<GoodsCategory> categoryList) {
List<GoodsCategoryVO> 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<GoodsCategoryVO> children = recursionTree(category.getId(), categoryList);
goodsCategoryVO.setChildren(children);
list.add(goodsCategoryVO);
}));
return list;
}
@Override
public List<Option> listCategoryOptions() {
List<GoodsCategory> categoryList = this.list(
new LambdaQueryWrapper<GoodsCategory>()
.eq(GoodsCategory::getStatus, CommonConstant.STATUS_NORMAL)
.orderByAsc(GoodsCategory::getSortOrder)
);
List<Option> list = recursionCascade(CommonConstant.PARENT_ID, categoryList);
return list;
}
private List<Option> recursionCascade(String parentId, List<GoodsCategory> categoryList) {
List<Option> 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<Option> 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();
}
}
Loading…
Cancel
Save