|
|
package com.yoho.ufo.service.impl;
|
|
|
|
|
|
import com.yoho.core.common.utils.DateUtil;
|
|
|
import com.yoho.ufo.dal.SaleCategoryMapper;
|
|
|
import com.yoho.ufo.exception.CommonException;
|
|
|
import com.yoho.ufo.model.commoditybasicrole.category.ProductSort;
|
|
|
import com.yoho.ufo.model.salecategory.SaleCategory;
|
|
|
import com.yoho.ufo.service.ISaleCategoryService;
|
|
|
import com.yoho.ufo.util.OrikaUtils;
|
|
|
import com.yohobuy.ufo.model.response.salecategory.SaleCategoryResponseBo;
|
|
|
import com.yohobuy.ufo.model.response.salecategory.SaleCategoryTreeViewResponseBo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
...
|
...
|
@@ -14,6 +18,7 @@ import org.springframework.stereotype.Service; |
|
|
import java.util.ArrayList;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
...
|
...
|
@@ -30,21 +35,66 @@ public class SaleCategoryServiceImpl implements ISaleCategoryService { |
|
|
private static final Integer PRODUCT_SORT_LEVEL_1 = 1;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 二级层级
|
|
|
*/
|
|
|
private static final Integer PRODUCT_SORT_LEVEL_2 = 2;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 二级层级
|
|
|
*/
|
|
|
private static final Integer PRODUCT_SORT_LEVEL_3 = 3;
|
|
|
@Autowired
|
|
|
private SaleCategoryMapper saleCategoryMapper;
|
|
|
|
|
|
public void saveOrUpdateSaleCategory(SaleCategoryResponseBo saleCategoryResponseBo){
|
|
|
log.info("saveOrUpdateSaleCategory param = {}", saleCategoryResponseBo);
|
|
|
SaleCategory saleCategory = OrikaUtils.map(saleCategoryResponseBo, SaleCategory.class);
|
|
|
if (saleCategory.getId() == null || saleCategory.getId() == 0) {
|
|
|
// 新增
|
|
|
if (saleCategory.getParentId() == null || saleCategory.getParentId() == 0) {
|
|
|
// 一级层级
|
|
|
saleCategory.setLevel(PRODUCT_SORT_LEVEL_1);
|
|
|
saleCategory.setParentId(TOP_PARENT_ID);
|
|
|
} else {
|
|
|
//查看上一级的level
|
|
|
SaleCategory saleCategoryParent = saleCategoryMapper.selectById(saleCategory.getParentId());
|
|
|
if(saleCategoryParent==null){
|
|
|
throw new CommonException(201, "父类销售类目找不到!");
|
|
|
}
|
|
|
saleCategory.setLevel(saleCategoryParent.getLevel()+1);
|
|
|
}
|
|
|
saleCategory.setStatus(0);
|
|
|
saleCategory.setCreateTime(DateUtil.currentTimeSeconds());
|
|
|
saleCategory.setUpdateTime(saleCategory.getCreateTime());
|
|
|
|
|
|
List<SaleCategory> sameNameList = saleCategoryMapper.selectByNameAndParentId(saleCategory.getCategoryName(),saleCategory.getParentId());
|
|
|
if(CollectionUtils.isNotEmpty(sameNameList)){
|
|
|
throw new CommonException(201, "销售类目名称已被占用!");
|
|
|
}
|
|
|
|
|
|
@Autowired
|
|
|
private SaleCategoryMapper saleCategoryMapper;
|
|
|
saleCategoryMapper.insert(saleCategory);
|
|
|
} else {
|
|
|
// 更新
|
|
|
SaleCategory db_saleCategory = saleCategoryMapper.selectById(saleCategory.getId());
|
|
|
db_saleCategory.setCategoryName(saleCategoryResponseBo.getCategoryName());
|
|
|
db_saleCategory.setOrderBy(saleCategoryResponseBo.getOrderBy());
|
|
|
db_saleCategory.setUpdateTime(DateUtil.currentTimeSeconds());
|
|
|
|
|
|
List<SaleCategory> sameNameList = saleCategoryMapper.selectByNameAndParentId(saleCategory.getCategoryName(),saleCategory.getParentId());
|
|
|
if(CollectionUtils.isNotEmpty(sameNameList)){
|
|
|
//过滤掉自己
|
|
|
sameNameList = sameNameList.stream().filter(a -> !a.getId().equals(saleCategory.getId())) .collect(Collectors.toList());
|
|
|
if(CollectionUtils.isNotEmpty(sameNameList)){
|
|
|
throw new CommonException(201, "销售类目名称已被占用!");
|
|
|
}
|
|
|
}
|
|
|
saleCategoryMapper.updateSaleCategoryById(db_saleCategory);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public SaleCategoryResponseBo getSaleCategoryById(Integer id){
|
|
|
log.info("enter getSaleCategoryById param = {}",id);
|
|
|
SaleCategory saleCategory = saleCategoryMapper.selectById(id);
|
|
|
if(saleCategory!=null){
|
|
|
return OrikaUtils.map(saleCategory, SaleCategoryResponseBo.class);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public List<SaleCategoryTreeViewResponseBo> getSaleCategoryList() {
|
|
|
log.info("enter getSaleCategoryList param = {}");
|
...
|
...
|
|