Compare commits
2
Commits
e5c8688659
...
5ae1c4d6b2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5ae1c4d6b2 | ||
|
|
1a7760130f |
@@ -7,4 +7,6 @@ import java.util.List;
|
|||||||
public interface MovieClient {
|
public interface MovieClient {
|
||||||
|
|
||||||
List<MovieDTO> listMovies();
|
List<MovieDTO> listMovies();
|
||||||
|
|
||||||
|
void addMovie(MovieDTO movieDTO);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,4 +15,9 @@ public class MovieClientImpl implements MovieClient {
|
|||||||
String ans = HttpUtil.get("http://localhost:8081/movie");
|
String ans = HttpUtil.get("http://localhost:8081/movie");
|
||||||
return JSONUtil.parseArray(ans).toList(MovieDTO.class);
|
return JSONUtil.parseArray(ans).toList(MovieDTO.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addMovie(MovieDTO movieDTO) {
|
||||||
|
HttpUtil.post("http://localhost:8081/movie", JSONUtil.toJsonStr(movieDTO));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import cn.hezhaohui.pojo.vo.MovieVO;
|
|||||||
import com.lark.oapi.core.utils.Jsons;
|
import com.lark.oapi.core.utils.Jsons;
|
||||||
import com.lark.oapi.event.EventDispatcher;
|
import com.lark.oapi.event.EventDispatcher;
|
||||||
import com.lark.oapi.event.cardcallback.P2CardActionTriggerHandler;
|
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.CallBackToast;
|
||||||
import com.lark.oapi.event.cardcallback.model.P2CardActionTrigger;
|
import com.lark.oapi.event.cardcallback.model.P2CardActionTrigger;
|
||||||
import com.lark.oapi.event.cardcallback.model.P2CardActionTriggerResponse;
|
import com.lark.oapi.event.cardcallback.model.P2CardActionTriggerResponse;
|
||||||
@@ -45,16 +46,7 @@ public class EventListener {
|
|||||||
LarkUtil.sendCard(CardEnum.CARD_WEATHER, weather);
|
LarkUtil.sendCard(CardEnum.CARD_WEATHER, weather);
|
||||||
} else if (eventKey.equals("movie")) {
|
} else if (eventKey.equals("movie")) {
|
||||||
MovieService movieService = BeanUtil.getBean(MovieService.class);
|
MovieService movieService = BeanUtil.getBean(MovieService.class);
|
||||||
List<MovieVO> movies = movieService.listMovies();
|
Map<String, Object> data = movieService.getMovies();
|
||||||
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);
|
|
||||||
LarkUtil.sendCard(CardEnum.CARD_MOVIE, data);
|
LarkUtil.sendCard(CardEnum.CARD_MOVIE, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,13 +59,24 @@ public class EventListener {
|
|||||||
String input = event.getEvent().getAction().getFormValue().get("movie_name").toString();
|
String input = event.getEvent().getAction().getFormValue().get("movie_name").toString();
|
||||||
System.out.println(input);
|
System.out.println(input);
|
||||||
|
|
||||||
// TODO: 添加用户输入的电影
|
MovieService movieService = BeanUtil.getBean(MovieService.class);
|
||||||
|
movieService.addMovie(input);
|
||||||
|
|
||||||
P2CardActionTriggerResponse response = new P2CardActionTriggerResponse();
|
P2CardActionTriggerResponse response = new P2CardActionTriggerResponse();
|
||||||
CallBackToast toast = new CallBackToast();
|
CallBackToast toast = new CallBackToast();
|
||||||
toast.setType("success");
|
toast.setType("success");
|
||||||
toast.setContent("Operation success!!!");
|
toast.setContent("Successful Operation!!!");
|
||||||
response.setToast(toast);
|
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;
|
return response;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -7,8 +7,7 @@ import jakarta.annotation.Resource;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class MovieService {
|
public class MovieService {
|
||||||
@@ -16,7 +15,21 @@ public class MovieService {
|
|||||||
@Resource
|
@Resource
|
||||||
private MovieClient movieClient;
|
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<MovieDTO> movieDTOS = movieClient.listMovies();
|
||||||
List<MovieVO> movieVOS = new ArrayList<>();
|
List<MovieVO> movieVOS = new ArrayList<>();
|
||||||
for (MovieDTO movieDTO : movieDTOS) {
|
for (MovieDTO movieDTO : movieDTOS) {
|
||||||
@@ -27,4 +40,12 @@ public class MovieService {
|
|||||||
}
|
}
|
||||||
return movieVOS;
|
return movieVOS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addMovie(String movie_name) {
|
||||||
|
MovieDTO movieDTO = new MovieDTO();
|
||||||
|
movieDTO.setName(movie_name);
|
||||||
|
movieDTO.setDay(new Date());
|
||||||
|
System.out.println("movieDTO: " + movieDTO);
|
||||||
|
movieClient.addMovie(movieDTO);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,10 @@ package cn.hezhaohui.movie.controller;
|
|||||||
|
|
||||||
import cn.hezhaohui.movie.entity.Movie;
|
import cn.hezhaohui.movie.entity.Movie;
|
||||||
import cn.hezhaohui.movie.service.MovieService;
|
import cn.hezhaohui.movie.service.MovieService;
|
||||||
|
import cn.hezhaohui.pojo.dto.MovieDTO;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -22,4 +21,12 @@ public class MovieController {
|
|||||||
return movieService.list(new QueryWrapper<Movie>().orderByDesc("id"));
|
return movieService.list(new QueryWrapper<Movie>().orderByDesc("id"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public void addMovie(@RequestBody MovieDTO movieDTO){
|
||||||
|
Movie movie = new Movie();
|
||||||
|
movie.setName(movieDTO.getName());
|
||||||
|
movie.setDay(movieDTO.getDay());
|
||||||
|
movieService.save(movie);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user