✨Feat: 实现MovieDay卡片回传

This commit is contained in:
2025-10-31 10:20:59 +08:00
parent 1a7760130f
commit 5ae1c4d6b2
2 changed files with 28 additions and 14 deletions
@@ -11,6 +11,7 @@ import cn.hezhaohui.pojo.vo.MovieVO;
import com.lark.oapi.core.utils.Jsons;
import com.lark.oapi.event.EventDispatcher;
import com.lark.oapi.event.cardcallback.P2CardActionTriggerHandler;
import com.lark.oapi.event.cardcallback.model.CallBackCard;
import com.lark.oapi.event.cardcallback.model.CallBackToast;
import com.lark.oapi.event.cardcallback.model.P2CardActionTrigger;
import com.lark.oapi.event.cardcallback.model.P2CardActionTriggerResponse;
@@ -45,16 +46,7 @@ public class EventListener {
LarkUtil.sendCard(CardEnum.CARD_WEATHER, weather);
} else if (eventKey.equals("movie")) {
MovieService movieService = BeanUtil.getBean(MovieService.class);
List<MovieVO> movies = movieService.listMovies();
List<Map<String, String>> movieList = new ArrayList<>();
for (MovieVO movie : movies) {
Map<String, String> movieInfo = new HashMap<>();
movieInfo.put("movie_title", movie.getName());
movieInfo.put("submit_time", movie.getDate());
movieList.add(movieInfo);
}
Map<String, Object> data = new HashMap<>();
data.put("recent_movie", movieList);
Map<String, Object> data = movieService.getMovies();
LarkUtil.sendCard(CardEnum.CARD_MOVIE, data);
}
}
@@ -75,6 +67,16 @@ public class EventListener {
toast.setType("success");
toast.setContent("Successful Operation!!!");
response.setToast(toast);
CallBackCard card = new CallBackCard();
card.setType("template");
Map<String, Object> movies = movieService.getMovies();
Map<String, Object> data = new HashMap<>();
data.put("template_id", CardEnum.CARD_MOVIE.getId());
data.put("template_version_name", CardEnum.CARD_MOVIE.getVersionName());
data.put("template_variable", movies);
card.setData(data);
response.setCard(card);
return response;
}
})
@@ -7,9 +7,7 @@ import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.*;
@Service
public class MovieService {
@@ -17,7 +15,21 @@ public class MovieService {
@Resource
private MovieClient movieClient;
public List<MovieVO> listMovies() {
public Map<String, Object> getMovies() {
List<MovieVO> input = this.listMovies();
List<Object> output = new ArrayList<>();
for (MovieVO movieVO : input) {
Map<String, String> movieInfo = new HashMap<>();
movieInfo.put("movie_title", movieVO.getName());
movieInfo.put("submit_time", movieVO.getDate());
output.add(movieInfo);
}
Map<String, Object> data = new HashMap<>();
data.put("recent_movie", output);
return data;
}
private List<MovieVO> listMovies() {
List<MovieDTO> movieDTOS = movieClient.listMovies();
List<MovieVO> movieVOS = new ArrayList<>();
for (MovieDTO movieDTO : movieDTOS) {