Authored by Lixiaodi

排序值不重复

@@ -23,5 +23,5 @@ public interface SaleCategoryMapper { @@ -23,5 +23,5 @@ public interface SaleCategoryMapper {
23 23
24 List<SaleCategory> selectAll(); 24 List<SaleCategory> selectAll();
25 25
26 - 26 + List<SaleCategory> selectByPidAndOrderBy(@Param("pid") Integer pid, @Param("orderBy") Integer orderBy);
27 } 27 }
@@ -65,6 +65,10 @@ @@ -65,6 +65,10 @@
65 select <include refid="Base_Column_List" /> 65 select <include refid="Base_Column_List" />
66 from sale_category where id = #{id} 66 from sale_category where id = #{id}
67 </select> 67 </select>
  68 + <select id="selectByPidAndOrderBy" resultMap="BaseResultMap">
  69 + select <include refid="Base_Column_List" />
  70 + from sale_category where parent_id = #{pid} and order_by=#{orderBy}
  71 + </select>
68 72
69 <select id="selectByNameAndParentId" resultMap="BaseResultMap"> 73 <select id="selectByNameAndParentId" resultMap="BaseResultMap">
70 select <include refid="Base_Column_List" /> 74 select <include refid="Base_Column_List" />
@@ -84,6 +84,9 @@ public class SaleCategoryServiceImpl implements ISaleCategoryService { @@ -84,6 +84,9 @@ public class SaleCategoryServiceImpl implements ISaleCategoryService {
84 // 一级层级 84 // 一级层级
85 saleCategory.setLevel(PRODUCT_SORT_LEVEL_1); 85 saleCategory.setLevel(PRODUCT_SORT_LEVEL_1);
86 saleCategory.setParentId(TOP_PARENT_ID); 86 saleCategory.setParentId(TOP_PARENT_ID);
  87 + if (!saleCategoryMapper.selectByPidAndOrderBy(TOP_PARENT_ID, saleCategory.getOrderBy()).isEmpty()) {
  88 + throw new CommonException(201, "排序已存在:" + saleCategory.getOrderBy());
  89 + }
87 if(StringUtils.equals(saleCategoryResponseBo.getLinkType(), "on")) { 90 if(StringUtils.equals(saleCategoryResponseBo.getLinkType(), "on")) {
88 saleCategory.setLinkType("series"); 91 saleCategory.setLinkType("series");
89 } else { 92 } else {
@@ -95,6 +98,9 @@ public class SaleCategoryServiceImpl implements ISaleCategoryService { @@ -95,6 +98,9 @@ public class SaleCategoryServiceImpl implements ISaleCategoryService {
95 if(saleCategoryParent==null){ 98 if(saleCategoryParent==null){
96 throw new CommonException(201, "父类销售类目找不到!"); 99 throw new CommonException(201, "父类销售类目找不到!");
97 } 100 }
  101 + if (!saleCategoryMapper.selectByPidAndOrderBy(saleCategory.getParentId(), saleCategory.getOrderBy()).isEmpty()) {
  102 + throw new CommonException(201, "排序已存在:" + saleCategory.getOrderBy());
  103 + }
98 saleCategory.setLevel(saleCategoryParent.getLevel()+1); 104 saleCategory.setLevel(saleCategoryParent.getLevel()+1);
99 } 105 }
100 saleCategory.setStatus(1);//新创建的默认为“关闭” 106 saleCategory.setStatus(1);//新创建的默认为“关闭”
@@ -113,6 +119,12 @@ public class SaleCategoryServiceImpl implements ISaleCategoryService { @@ -113,6 +119,12 @@ public class SaleCategoryServiceImpl implements ISaleCategoryService {
113 if(db_saleCategory==null){ 119 if(db_saleCategory==null){
114 throw new CommonException(201, "找不到销售类目!"); 120 throw new CommonException(201, "找不到销售类目!");
115 } 121 }
  122 +
  123 + List<SaleCategory> exists = saleCategoryMapper.selectByPidAndOrderBy(db_saleCategory.getParentId(), saleCategory.getOrderBy());
  124 + if (exists.size() > 1 || (exists.size() == 1 && !exists.get(0).getId().equals(saleCategory.getId()))) {
  125 + throw new CommonException(201, "排序已存在:" + saleCategory.getOrderBy());
  126 + }
  127 +
116 db_saleCategory.setCategoryName(saleCategory.getCategoryName()); 128 db_saleCategory.setCategoryName(saleCategory.getCategoryName());
117 db_saleCategory.setOrderBy(saleCategory.getOrderBy()); 129 db_saleCategory.setOrderBy(saleCategory.getOrderBy());
118 db_saleCategory.setImageUrl(saleCategory.getImageUrl()); 130 db_saleCategory.setImageUrl(saleCategory.getImageUrl());