Selaa lähdekoodia

优化了/api/moment/v1/publish接口,图片或者视频不是必填

jinshihui 1 kuukausi sitten
vanhempi
commit
0a33985a78

+ 16 - 17
nightFragrance-massage/src/main/java/com/ylx/moment/service/impl/TechnicianMomentServiceImpl.java

@@ -311,24 +311,23 @@ public class TechnicianMomentServiceImpl extends ServiceImpl<TechnicianMomentMap
                 throw new ServiceException("动态内容不能为空");
             }
             // 校验媒体类型和媒体文件
-            if (dto.getMediaType() == null) {
-                throw new ServiceException("媒体类型不能为空");
-            }
-            if (dto.getMediaType() == 1) {
-                // 图片类型
-                if (dto.getImageUrls() == null || dto.getImageUrls().isEmpty()) {
-                    throw new ServiceException("图片不能为空");
-                }
-                if (dto.getImageUrls().size() > 9) {
-                    throw new ServiceException("最多只能上传9张图片");
-                }
-            } else if (dto.getMediaType() == 2) {
-                // 视频类型
-                if (StringUtils.isBlank(dto.getVideoUrl())) {
-                    throw new ServiceException("视频不能为空");
+            if (dto.getMediaType() != null) {
+                if (dto.getMediaType() == 1) {
+                    // 图片类型
+                    if (dto.getImageUrls() == null || dto.getImageUrls().isEmpty()) {
+                        throw new ServiceException("图片不能为空");
+                    }
+                    if (dto.getImageUrls().size() > 9) {
+                        throw new ServiceException("最多只能上传9张图片");
+                    }
+                } else if (dto.getMediaType() == 2) {
+                    // 视频类型
+                    if (StringUtils.isBlank(dto.getVideoUrl())) {
+                        throw new ServiceException("视频不能为空");
+                    }
+                } else {
+                    throw new ServiceException("媒体类型不正确");
                 }
-            } else {
-                throw new ServiceException("媒体类型不正确");
             }
         }