Procházet zdrojové kódy

bugfix:dict_id累加

lyx před 2 týdny
rodič
revize
f2c809e2ae

+ 12 - 15
alien-store/src/main/java/shop/alien/store/service/impl/PlatformBusinessSectionServiceImpl.java

@@ -142,9 +142,13 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
             }
         }
 
-        // 生成 dict_id:查询同级(相同 parent_id)的最大 dict_id,然后 +1
-        String maxDictId = getMaxDictIdByParentId(parentId);
-        int nextDictId = (maxDictId == null ? 0 : Integer.parseInt(maxDictId)) + 1;
+        // 生成 dict_id:根据 typeName 查询最大 dict_id,然后 +1
+        String typeName = storeDictionary.getTypeName();
+        if (StringUtils.isBlank(typeName)) {
+            throw new IllegalArgumentException("typeName不能为空");
+        }
+        String maxDictId = getMaxDictIdByTypeName(typeName);
+        int nextDictId = (maxDictId == null ? 1 : Integer.parseInt(maxDictId)) + 1;
         storeDictionary.setDictId(String.valueOf(nextDictId));
 
         // 生成 sort_id
@@ -347,23 +351,16 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
     }
 
     /**
-     * 根据 parent_id 获取同级最大 dict_id
+     * 根据 typeName 获取最大 dict_id
      *
-     * @param parentId 父节点ID
+     * @param typeName 类型名称
      * @return 最大 dict_id,如果不存在则返回 null
      */
-    private String getMaxDictIdByParentId(Integer parentId) {
+    private String getMaxDictIdByTypeName(String typeName) {
         LambdaQueryWrapper<StoreDictionary> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.in(StoreDictionary::getTypeName, "business_section","business_type","business_classify");;
+        queryWrapper.eq(StoreDictionary::getTypeName, typeName);
         queryWrapper.eq(StoreDictionary::getDeleteFlag, 0);
         
-        if (parentId == null || parentId == 0) {
-            queryWrapper.and(wrapper -> wrapper.isNull(StoreDictionary::getParentId)
-                    .or().eq(StoreDictionary::getParentId, 0));
-        } else {
-            queryWrapper.eq(StoreDictionary::getParentId, parentId);
-        }
-        
         queryWrapper.orderByDesc(StoreDictionary::getDictId);
         queryWrapper.last("LIMIT 1");
         
@@ -835,7 +832,7 @@ public class PlatformBusinessSectionServiceImpl extends ServiceImpl<StoreDiction
         newDict.setCreatedTime(new Date());
 
         // 生成 dict_id
-        String maxDictId = getMaxDictIdByParentId(newDict.getParentId());
+        String maxDictId = getMaxDictIdByTypeName(newDict.getTypeName());
         newDict.setDictId(String.valueOf(maxDictId == null ? 1 : Integer.parseInt(maxDictId) + 1));
         
         // 生成 sort_id