15 changed files with 435 additions and 107 deletions
@ -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; |
||||
|
} |
||||
@ -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; |
||||
|
} |
||||
@ -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; |
||||
|
} |
||||
@ -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); |
|
||||
} |
|
||||
@ -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> { |
||||
|
} |
||||
@ -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<>(); |
||||
|
} |
||||
@ -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); |
|
||||
} |
|
||||
@ -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); |
||||
|
} |
||||
@ -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); |
|
||||
} |
|
||||
} |
|
||||
@ -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…
Reference in new issue