|
@@ -15,6 +15,8 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URL;
|
|
|
import java.text.ParseException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
@@ -96,6 +98,22 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
|
communityArticleVos = communityArticleMapper.selectCommunityArticleList(communityArticle, circleIds, offset, pageSize);
|
|
|
Long userId = SecurityUtils.getUserId();
|
|
|
for (CommunityArticleVo articleVo : communityArticleVos) {
|
|
|
+ List<CommunityArticleImages> imageList = articleVo.getImageList();
|
|
|
+ List<CommunityArticleImages> videoList = new ArrayList<>();
|
|
|
+ CommunityArticleImages videos = null;
|
|
|
+ for (CommunityArticleImages image : imageList) {
|
|
|
+ videos = new CommunityArticleImages();
|
|
|
+ String imageUrl = image.getImageUrl();
|
|
|
+ //判断是否是视频
|
|
|
+ boolean isVideo = isVideoFile(imageUrl);
|
|
|
+ if (isVideo) {
|
|
|
+ imageList.remove(image);
|
|
|
+ BeanUtils.copyProperties(image, videos);
|
|
|
+ videoList.add(videos);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ articleVo.setVideoList(videoList);
|
|
|
+
|
|
|
//设置文章的点赞数量
|
|
|
articleVo.setLikeCount(communityLikeMapper
|
|
|
.selectList(new QueryWrapper<CommunityLike>()
|
|
@@ -427,4 +445,27 @@ public class CommunityArticleServiceImpl extends ServiceImpl<CommunityArticleMap
|
|
|
return communityUserLikeVos;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 判断是否是视频文件
|
|
|
+ *
|
|
|
+ * @param fileUrl 文件地址
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ public static boolean isVideoFile(String fileUrl) {
|
|
|
+ try {
|
|
|
+ // 打开 HTTP 连接
|
|
|
+ URL url = new URL(fileUrl);
|
|
|
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
|
+ connection.setRequestMethod("GET");
|
|
|
+
|
|
|
+ // 获取文件类型
|
|
|
+ String mimeType = connection.getContentType();
|
|
|
+
|
|
|
+ // 判断是否为视频类型
|
|
|
+ return mimeType != null && mimeType.startsWith("video");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|