From bec58fa7fe4fae2deac88200d8d939e12ec8a08f Mon Sep 17 00:00:00 2001
From: lrj <owen.stl@gmail.com>
Date: 星期五, 03 十月 2025 22:26:39 +0800
Subject: [PATCH] 修复小程序WXS日期显示问题并重新设计【我的】页面
---
backend/src/main/java/com/rongyichuang/carousel/resolver/CarouselResolver.java | 93 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 93 insertions(+), 0 deletions(-)
diff --git a/backend/src/main/java/com/rongyichuang/carousel/resolver/CarouselResolver.java b/backend/src/main/java/com/rongyichuang/carousel/resolver/CarouselResolver.java
index 2aa71ce..b41de54 100644
--- a/backend/src/main/java/com/rongyichuang/carousel/resolver/CarouselResolver.java
+++ b/backend/src/main/java/com/rongyichuang/carousel/resolver/CarouselResolver.java
@@ -5,14 +5,21 @@
import com.rongyichuang.carousel.dto.response.CarouselResponse;
import com.rongyichuang.carousel.service.CarouselService;
import com.rongyichuang.common.dto.PageResponse;
+import com.rongyichuang.common.dto.response.MediaResponse;
+import com.rongyichuang.common.enums.MediaTargetType;
+import com.rongyichuang.common.repository.MediaRepository;
+import com.rongyichuang.common.entity.Media;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.graphql.data.method.annotation.Argument;
import org.springframework.graphql.data.method.annotation.MutationMapping;
import org.springframework.graphql.data.method.annotation.QueryMapping;
+import org.springframework.graphql.data.method.annotation.SchemaMapping;
import org.springframework.stereotype.Controller;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
/**
* 杞挱鍥綠raphQL瑙f瀽鍣�
@@ -22,6 +29,12 @@
@Autowired
private CarouselService carouselService;
+
+ @Autowired
+ private MediaRepository mediaRepository;
+
+ @Value("${app.media-url}")
+ private String mediaBaseUrl;
/**
* 鍒嗛〉鏌ヨ杞挱鍥�
@@ -77,4 +90,84 @@
System.out.println("鏇存柊缁撴灉: " + result);
return result;
}
+
+ /**
+ * 瑙f瀽Carousel鐨刢overImage瀛楁
+ */
+ @SchemaMapping(typeName = "CarouselResponse", field = "coverImage")
+ public MediaResponse coverImage(CarouselResponse carousel) {
+ List<Media> mediaList = mediaRepository.findByTargetTypeAndTargetIdAndState(
+ MediaTargetType.CAROUSEL.getValue(), carousel.getId(), 1);
+
+ // 鏌ユ壘绗竴涓浘鐗囩被鍨嬬殑濯掍綋浣滀负灏侀潰鍥�
+ return mediaList.stream()
+ .filter(media -> media.getMediaType() != null && media.getMediaType() == 1) // 1琛ㄧず鍥剧墖
+ .findFirst()
+ .map(this::convertToMediaResponse)
+ .orElse(null);
+ }
+
+ /**
+ * 瑙f瀽Carousel鐨刬mages瀛楁
+ */
+ @SchemaMapping(typeName = "CarouselResponse", field = "images")
+ public List<MediaResponse> images(CarouselResponse carousel) {
+ List<Media> mediaList = mediaRepository.findByTargetTypeAndTargetIdAndState(
+ MediaTargetType.CAROUSEL.getValue(), carousel.getId(), 1);
+
+ // 杩斿洖鎵�鏈夊浘鐗囩被鍨嬬殑濯掍綋
+ return mediaList.stream()
+ .filter(media -> media.getMediaType() != null && media.getMediaType() == 1) // 1琛ㄧず鍥剧墖
+ .map(this::convertToMediaResponse)
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * 瑙f瀽Carousel鐨剉ideos瀛楁
+ */
+ @SchemaMapping(typeName = "CarouselResponse", field = "videos")
+ public List<MediaResponse> videos(CarouselResponse carousel) {
+ List<Media> mediaList = mediaRepository.findByTargetTypeAndTargetIdAndState(
+ MediaTargetType.CAROUSEL.getValue(), carousel.getId(), 1);
+
+ // 杩斿洖鎵�鏈夎棰戠被鍨嬬殑濯掍綋
+ return mediaList.stream()
+ .filter(media -> media.getMediaType() != null && media.getMediaType() == 2) // 2琛ㄧず瑙嗛
+ .map(this::convertToMediaResponse)
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * 灏哅edia瀹炰綋杞崲涓篗ediaResponse
+ */
+ private MediaResponse convertToMediaResponse(Media media) {
+ MediaResponse response = new MediaResponse();
+ response.setId(media.getId());
+ response.setName(media.getName());
+ response.setPath(media.getPath());
+ response.setFileSize(media.getFileSize());
+ response.setFileExt(media.getFileExt());
+ response.setMediaType(media.getMediaType());
+ response.setTargetType(media.getTargetType());
+ response.setTargetId(media.getTargetId());
+ response.setThumbPath(media.getThumbPath());
+ response.setDuration(media.getDuration());
+ response.setDescription(media.getDescription());
+
+ // 璁剧疆瀹屾暣URL
+ if (mediaBaseUrl != null && !mediaBaseUrl.isEmpty() && media.getPath() != null) {
+ String base = mediaBaseUrl.endsWith("/") ? mediaBaseUrl.substring(0, mediaBaseUrl.length() - 1) : mediaBaseUrl;
+ String path = media.getPath().startsWith("/") ? media.getPath() : ("/" + media.getPath());
+ response.setFullUrl(base + path);
+ }
+
+ // 璁剧疆缂╃暐鍥惧畬鏁碪RL
+ if (mediaBaseUrl != null && !mediaBaseUrl.isEmpty() && media.getThumbPath() != null) {
+ String base = mediaBaseUrl.endsWith("/") ? mediaBaseUrl.substring(0, mediaBaseUrl.length() - 1) : mediaBaseUrl;
+ String thumbPath = media.getThumbPath().startsWith("/") ? media.getThumbPath() : ("/" + media.getThumbPath());
+ response.setFullThumbUrl(base + thumbPath);
+ }
+
+ return response;
+ }
}
\ No newline at end of file
--
Gitblit v1.8.0