| | |
| | | @Autowired |
| | | private JdbcTemplate jdbcTemplate; |
| | | |
| | | @Value("${app.media-url:${app.media.url:}}") |
| | | @Value("${app.media-url}") |
| | | private String mediaBaseUrl; |
| | | |
| | | public MediaGraphqlApi(MediaRepository mediaRepository, MediaService mediaService) { |
| | |
| | | } |
| | | |
| | | @QueryMapping |
| | | public List<MediaResponse> mediasByTarget(@Argument Integer targetType, @Argument String targetId) { |
| | | public List<MediaResponse> mediasByTarget(@Argument Integer targetType, @Argument Long targetId) { |
| | | try { |
| | | // 使用 JDBC 直接查询,避免 Hibernate 类型转换问题 |
| | | String sql = "SELECT id, name, path, file_size, file_ext, media_type, target_type, target_id, thumb_path, duration, description " + |
| | | "FROM t_media WHERE target_type = ? AND target_id = ? AND target_id REGEXP '^[0-9]+$'"; |
| | | "FROM t_media WHERE target_type = ? AND target_id = ?"; |
| | | |
| | | List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql, targetType, Long.parseLong(targetId)); |
| | | List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql, targetType, targetId); |
| | | |
| | | List<MediaResponse> responses = new ArrayList<>(); |
| | | for (Map<String, Object> row : rows) { |
| | |
| | | } |
| | | |
| | | @MutationMapping |
| | | public Boolean deleteMedia(@Argument String id) { |
| | | public Boolean deleteMedia(@Argument Long id) { |
| | | System.out.println("=== deleteMedia GraphQL调用 ==="); |
| | | System.out.println("要删除的媒体ID: " + id); |
| | | |
| | | try { |
| | | Long mediaId = Long.parseLong(id); |
| | | System.out.println("转换后的媒体ID: " + mediaId); |
| | | |
| | | Boolean result = mediaService.deleteMedia(mediaId); |
| | | Boolean result = mediaService.deleteMedia(id); |
| | | System.out.println("删除结果: " + result); |
| | | return result; |
| | | } catch (Exception e) { |