Explorar o código

tag_id 过滤掉空值和0

tsurumure hai 1 mes
pai
achega
e530b2fd1e

+ 9 - 0
src/main/java/com/backendsys/modules/material/service/impl/MaterialServiceImpl.java

@@ -24,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.concurrent.CompletableFuture;
 import java.util.stream.Collectors;
 
@@ -140,6 +141,14 @@ public class MaterialServiceImpl implements MaterialService {
             if (materialCategory == null) throw new CustException("素材分类不存在");
         }
 
+        // [Filter] tag_id 过滤掉空值和 0
+        String cleaned = Optional.ofNullable(material.getTag_ids())
+                .orElse("")
+                .replaceAll("\\b0\\b,?", "")
+                .replaceAll(",{2,}", ",")
+                .replaceAll("^,|,$", "");
+        material.setTag_ids(cleaned);
+
         // 编辑的时候,如果素材图片有修改,需要删除之前的图片
 
         // 生成缩略图,并填充缩略图地址