feat(admin): 举报工单返回短剧与分集信息
This commit is contained in:
1 parent
6ddddef5ec
commit
9a74876b3f
8 files changed
+727
-4
No files matched your search
+209
@@ -0,0 +1,209 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
package com.fruitshorts.admin.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fruitshorts.admin.vo.AdminReportRespVO;
|
||||
import com.fruitshorts.common.pojo.PageResult;
|
||||
import com.fruitshorts.content.dal.entity.Drama;
|
||||
import com.fruitshorts.content.dal.entity.DramaEpisode;
|
||||
import com.fruitshorts.content.dal.mapper.DramaEpisodeMapper;
|
||||
import com.fruitshorts.content.dal.mapper.DramaMapper;
|
||||
import com.fruitshorts.interaction.dal.entity.ContentComment;
|
||||
import com.fruitshorts.interaction.dal.entity.ContentReport;
|
||||
import com.fruitshorts.interaction.dal.mapper.ContentCommentMapper;
|
||||
import com.fruitshorts.interaction.dal.mapper.ContentReportMapper;
|
||||
import com.fruitshorts.interaction.service.ReportService;
|
||||
import com.fruitshorts.interaction.vo.ReportQueryReqVO;
|
||||
import com.fruitshorts.user.dal.entity.AppUser;
|
||||
import com.fruitshorts.user.dal.mapper.AppUserMapper;
|
||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/** 后台举报工单目标摘要与批量装配。 */
|
||||
class ReportAdminServiceTest {
|
||||
|
||||
private ContentReportMapper reportMapper;
|
||||
private ContentCommentMapper commentMapper;
|
||||
private DramaMapper dramaMapper;
|
||||
private DramaEpisodeMapper episodeMapper;
|
||||
private AppUserMapper appUserMapper;
|
||||
private ReportAdminService service;
|
||||
|
||||
@BeforeAll
|
||||
static void initTableInfoCache() {
|
||||
TableInfoHelper.initTableInfo(
|
||||
new MapperBuilderAssistant(new MybatisConfiguration(), ""),
|
||||
ContentReport.class);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
reportMapper = mock(ContentReportMapper.class);
|
||||
commentMapper = mock(ContentCommentMapper.class);
|
||||
dramaMapper = mock(DramaMapper.class);
|
||||
episodeMapper = mock(DramaEpisodeMapper.class);
|
||||
appUserMapper = mock(AppUserMapper.class);
|
||||
service = new ReportAdminService(reportMapper, commentMapper, dramaMapper,
|
||||
episodeMapper, appUserMapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_build_summary_and_batch_relations_for_all_report_types() {
|
||||
List<ContentReport> rows = List.of(
|
||||
report(1L, 7L, ReportService.TYPE_COMMENT, 101L),
|
||||
report(2L, 8L, ReportService.TYPE_DRAMA, 5L),
|
||||
report(3L, 7L, ReportService.TYPE_USER, 9L));
|
||||
stubPage(rows);
|
||||
given(commentMapper.selectByIdsIncludingDeleted(any()))
|
||||
.willReturn(List.of(comment(101L, 5L, 11L, "bad comment", 0)));
|
||||
given(dramaMapper.selectBatchIds(any())).willReturn(List.of(drama(5L, "Signal")));
|
||||
given(episodeMapper.selectBatchIds(any())).willReturn(List.of(episode(11L, 3, "The Call")));
|
||||
given(appUserMapper.selectBatchIds(any())).willReturn(List.of(
|
||||
user(7L, "Alice", "u-7"),
|
||||
user(8L, "Bob", "u-8"),
|
||||
user(9L, "Target", "u-9")));
|
||||
|
||||
PageResult<AdminReportRespVO> result = service.page(new ReportQueryReqVO());
|
||||
|
||||
AdminReportRespVO commentReport = result.getList().get(0);
|
||||
assertThat(commentReport.getTargetSummary())
|
||||
.isEqualTo("Signal · 第 3 集 · The Call");
|
||||
assertThat(commentReport.getDramaTitle()).isEqualTo("Signal");
|
||||
assertThat(commentReport.getEpisodeNo()).isEqualTo(3);
|
||||
assertThat(commentReport.getCommentContent()).isEqualTo("bad comment");
|
||||
assertThat(commentReport.getReporterNickname()).isEqualTo("Alice");
|
||||
assertThat(commentReport.getReporterUid()).isEqualTo("u-7");
|
||||
|
||||
AdminReportRespVO dramaReport = result.getList().get(1);
|
||||
assertThat(dramaReport.getTargetSummary()).isEqualTo("Signal");
|
||||
assertThat(dramaReport.getDramaId()).isEqualTo(5L);
|
||||
|
||||
AdminReportRespVO userReport = result.getList().get(2);
|
||||
assertThat(userReport.getTargetSummary()).isEqualTo("Target(u-9)");
|
||||
assertThat(userReport.getTargetNickname()).isEqualTo("Target");
|
||||
assertThat(userReport.getTargetUid()).isEqualTo("u-9");
|
||||
verify(commentMapper, times(1)).selectByIdsIncludingDeleted(List.of(101L));
|
||||
verify(dramaMapper, times(1)).selectBatchIds(any());
|
||||
verify(episodeMapper, times(1)).selectBatchIds(any());
|
||||
verify(appUserMapper, times(1)).selectBatchIds(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_leave_all_filters_unset_when_status_and_filters_are_empty() {
|
||||
stubPage(List.of());
|
||||
|
||||
PageResult<AdminReportRespVO> result = service.page(new ReportQueryReqVO());
|
||||
|
||||
assertThat(result.getTotal()).isZero();
|
||||
assertThat(result.getList()).isEmpty();
|
||||
ArgumentCaptor<LambdaQueryWrapper<ContentReport>> captor = queryCaptor();
|
||||
verify(reportMapper).selectPage(any(), captor.capture());
|
||||
assertThat(captor.getValue().getSqlSegment())
|
||||
.doesNotContain("status")
|
||||
.doesNotContain("target_type")
|
||||
.doesNotContain("reason_code")
|
||||
.doesNotContain("reporter_id");
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_fallback_to_ids_when_targets_are_deleted_or_missing() {
|
||||
List<ContentReport> rows = List.of(
|
||||
report(1L, 7L, ReportService.TYPE_COMMENT, 101L),
|
||||
report(2L, 7L, ReportService.TYPE_DRAMA, 5L),
|
||||
report(3L, 7L, ReportService.TYPE_USER, 9L));
|
||||
stubPage(rows);
|
||||
given(commentMapper.selectByIdsIncludingDeleted(any()))
|
||||
.willReturn(List.of(comment(101L, 5L, 11L, "removed", 1)));
|
||||
given(dramaMapper.selectBatchIds(any())).willReturn(List.of());
|
||||
given(appUserMapper.selectBatchIds(any()))
|
||||
.willReturn(List.of(user(7L, "Alice", "u-7")));
|
||||
|
||||
PageResult<AdminReportRespVO> result = service.page(new ReportQueryReqVO());
|
||||
|
||||
assertThat(result.getList()).extracting(AdminReportRespVO::getTargetSummary)
|
||||
.containsExactly("评论 #101", "短剧 #5", "用户 #9");
|
||||
assertThat(result.getList().get(0).getCommentContent()).isNull();
|
||||
verify(episodeMapper, never()).selectBatchIds(any());
|
||||
}
|
||||
|
||||
private void stubPage(List<ContentReport> rows) {
|
||||
Page<ContentReport> page = new Page<>(1, 10);
|
||||
page.setTotal(rows.size());
|
||||
page.setRecords(rows);
|
||||
given(reportMapper.selectPage(any(Page.class), any())).willReturn(page);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private ArgumentCaptor<LambdaQueryWrapper<ContentReport>> queryCaptor() {
|
||||
return ArgumentCaptor.forClass(LambdaQueryWrapper.class);
|
||||
}
|
||||
|
||||
private ContentReport report(Long id, Long reporterId, String type, Long targetId) {
|
||||
ContentReport report = new ContentReport();
|
||||
report.setId(id);
|
||||
report.setReporterId(reporterId);
|
||||
report.setTargetType(type);
|
||||
report.setTargetId(targetId);
|
||||
report.setReasonCode("VIOLATION");
|
||||
report.setDescription("description");
|
||||
report.setStatus("pending");
|
||||
report.setHandleBy(0L);
|
||||
report.setHandleNote("");
|
||||
report.setCreatedAt(LocalDateTime.of(2026, 10, 21, 12, 0));
|
||||
return report;
|
||||
}
|
||||
|
||||
private ContentComment comment(Long id, Long dramaId, Long episodeId, String content,
|
||||
int deleted) {
|
||||
ContentComment comment = new ContentComment();
|
||||
comment.setId(id);
|
||||
comment.setDramaId(dramaId);
|
||||
comment.setEpisodeId(episodeId);
|
||||
comment.setUserId(9L);
|
||||
comment.setContent(content);
|
||||
comment.setStatus(deleted == 1 ? "deleted" : "published");
|
||||
comment.setDeleted(deleted);
|
||||
return comment;
|
||||
}
|
||||
|
||||
private Drama drama(Long id, String title) {
|
||||
Drama drama = new Drama();
|
||||
drama.setId(id);
|
||||
drama.setTitle(title);
|
||||
return drama;
|
||||
}
|
||||
|
||||
private DramaEpisode episode(Long id, int no, String title) {
|
||||
DramaEpisode episode = new DramaEpisode();
|
||||
episode.setId(id);
|
||||
episode.setEpNo(no);
|
||||
episode.setTitle(title);
|
||||
return episode;
|
||||
}
|
||||
|
||||
private AppUser user(Long id, String nickname, String uid) {
|
||||
AppUser user = new AppUser();
|
||||
user.setId(id);
|
||||
user.setNickname(nickname);
|
||||
user.setUid(uid);
|
||||
return user;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user