فهرست منبع

Merge branch 'dev-yhq'

tsurumure 1 ماه پیش
والد
کامیت
34bd4403a6

+ 21 - 9
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;
 
@@ -106,18 +107,21 @@ public class MaterialServiceImpl implements MaterialService {
         MaterialCategory materialCategory = materialCategoryDao.selectById(material.getCategory_id());
         if (materialCategory == null) throw new CustException("素材分类不存在");
 
-        ObjectKeyEntity objectKeyEntity = objectKeyUtil.urlToObjectKey(material.getImage_url());
-
-//        // 错误做法:原图地址不能加参数,否则缩略图会重复加参数
-//        if (StrUtil.isNotEmpty(material.getImage_url())) {
-//            String image_url = UploadUtil.getImageThumbUrl(material.getImage_url(), objectKeyEntity.getTarget(), 315, null, null, true);
-//            material.setImage_url(image_url);
-//        }
+        // [Filter] tag_id 过滤掉空值和 0
+        String cleaned = Optional.ofNullable(material.getTag_ids())
+            .orElse("")
+            .replaceAll("\\b0\\b,?", "")
+            .replaceAll(",{2,}", ",")
+            .replaceAll("^,|,$", "");
+        material.setTag_ids(cleaned);
 
         // 生成缩略图,并填充缩略图地址
         if (StrUtil.isNotEmpty(material.getImage_url())) {
-            String image_thumb_url = UploadUtil.getImageThumbUrl(material.getImage_url(), objectKeyEntity.getTarget(), 276, 155);
-            material.setImage_thumb_url(image_thumb_url);
+            ObjectKeyEntity objectKeyEntity = objectKeyUtil.urlToObjectKey(material.getImage_url());
+            if (objectKeyEntity != null) {
+                String image_thumb_url = UploadUtil.getImageThumbUrl(material.getImage_url(), objectKeyEntity.getTarget(), 276, 155);
+                material.setImage_thumb_url(image_thumb_url);
+            }
         }
 
         materialDao.insertMaterial(material);
@@ -140,6 +144,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);
+
         // 编辑的时候,如果素材图片有修改,需要删除之前的图片
 
         // 生成缩略图,并填充缩略图地址

+ 9 - 4
src/main/java/com/backendsys/modules/sdk/tencentcloud/cos/service/impl/TencentCosServiceImpl.java

@@ -157,7 +157,7 @@ public class TencentCosServiceImpl implements TencentCosService {
 //             */
 //            // 判断图片类型
 //            List<String> imageType = Arrays.asList("jpg", "jpeg", "png", "bmp", "webp", "tiff", "gif");
-//            boolean isImage = imageType.contains(FilenameUtil.getFilenameSuffix(multipartFile, false).toLowerCase());
+//            boolean isImage = imageType.contains(CommonUtil.getFilenameSuffix(multipartFile, false).toLowerCase());
 //            if (isImage) {
 //                // 选用样式1,并限定缩略图的宽高最小值为100×100 绝对质量为60
 //                String rule = "imageView2/1/w/100/h/100/q/60";
@@ -186,9 +186,14 @@ public class TencentCosServiceImpl implements TencentCosService {
 
             System.out.println("[腾讯云][cos-uploadResult] = " + uploadResult.getDateStr());
 
-            // 打水印
-            if (is_watermark != null && is_watermark == 1) {
-                addWatermask(object_key);
+            // 判断是图片类型
+            List<String> imageType = Arrays.asList("jpg", "jpeg", "png", "bmp", "webp", "tiff", "gif");
+            boolean isImage = imageType.contains(CommonUtil.getFilenameSuffix(multipartFile, false).toLowerCase());
+            if (isImage) {
+                // 打水印
+                if (is_watermark != null && is_watermark == 1) {
+                    addWatermask(object_key);
+                }
             }
 
             // 自定义返回结果实体

+ 7 - 5
src/main/resources/mapper/ai/material/MaterialDao.xml

@@ -132,11 +132,13 @@
         user_id = #{user_id}
         <if test="category_id != null and category_id != ''">, category_id = #{category_id}</if>
         <if test="material_name != null and material_name != ''">, material_name = #{material_name}</if>
-        <if test="tag_ids != null and tag_ids != ''">, tag_ids = #{tag_ids}</if>
-        <if test="image_thumb_url != null and image_thumb_url != ''">, image_thumb_url = #{image_thumb_url}</if>
-        <if test="image_url != null and image_url != ''">, image_url = #{image_url}</if>
-        <if test="file_url != null and file_url != ''">, file_url = #{file_url}</if>
-        <if test="pan_baidu_url != null and pan_baidu_url != ''">, pan_baidu_url = #{pan_baidu_url}</if>
+        <!-- 允许为空 -->
+        <if test="tag_ids != null">, tag_ids = #{tag_ids}</if>
+        <if test="image_thumb_url != null">, image_thumb_url = #{image_thumb_url}</if>
+        <if test="image_url != null">, image_url = #{image_url}</if>
+        <if test="file_url != null">, file_url = #{file_url}</if>
+        <if test="pan_baidu_url != null">, pan_baidu_url = #{pan_baidu_url}</if>
+        <!-- -->
         <if test="is_copyright != null and is_copyright != ''">, is_copyright = #{is_copyright}</if>
         WHERE id = #{material_id}
     </update>