Authored by Lixiaodi

排序值不重复

... ... @@ -23,5 +23,5 @@ public interface SaleCategoryMapper {
List<SaleCategory> selectAll();
List<SaleCategory> selectByPidAndOrderBy(@Param("pid") Integer pid, @Param("orderBy") Integer orderBy);
}
... ...
... ... @@ -65,6 +65,10 @@
select <include refid="Base_Column_List" />
from sale_category where id = #{id}
</select>
<select id="selectByPidAndOrderBy" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from sale_category where parent_id = #{pid} and order_by=#{orderBy}
</select>
<select id="selectByNameAndParentId" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
... ...
... ... @@ -84,6 +84,9 @@ public class SaleCategoryServiceImpl implements ISaleCategoryService {
// 一级层级
saleCategory.setLevel(PRODUCT_SORT_LEVEL_1);
saleCategory.setParentId(TOP_PARENT_ID);
if (!saleCategoryMapper.selectByPidAndOrderBy(TOP_PARENT_ID, saleCategory.getOrderBy()).isEmpty()) {
throw new CommonException(201, "排序已存在:" + saleCategory.getOrderBy());
}
if(StringUtils.equals(saleCategoryResponseBo.getLinkType(), "on")) {
saleCategory.setLinkType("series");
} else {
... ... @@ -95,6 +98,9 @@ public class SaleCategoryServiceImpl implements ISaleCategoryService {
if(saleCategoryParent==null){
throw new CommonException(201, "父类销售类目找不到!");
}
if (!saleCategoryMapper.selectByPidAndOrderBy(saleCategory.getParentId(), saleCategory.getOrderBy()).isEmpty()) {
throw new CommonException(201, "排序已存在:" + saleCategory.getOrderBy());
}
saleCategory.setLevel(saleCategoryParent.getLevel()+1);
}
saleCategory.setStatus(1);//新创建的默认为“关闭”
... ... @@ -113,6 +119,12 @@ public class SaleCategoryServiceImpl implements ISaleCategoryService {
if(db_saleCategory==null){
throw new CommonException(201, "找不到销售类目!");
}
List<SaleCategory> exists = saleCategoryMapper.selectByPidAndOrderBy(db_saleCategory.getParentId(), saleCategory.getOrderBy());
if (exists.size() > 1 || (exists.size() == 1 && !exists.get(0).getId().equals(saleCategory.getId()))) {
throw new CommonException(201, "排序已存在:" + saleCategory.getOrderBy());
}
db_saleCategory.setCategoryName(saleCategory.getCategoryName());
db_saleCategory.setOrderBy(saleCategory.getOrderBy());
db_saleCategory.setImageUrl(saleCategory.getImageUrl());
... ...