|
@@ -0,0 +1,92 @@
|
|
|
+package com.sf.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.sf.common.resp.RestResp;
|
|
|
+import com.sf.constant.DatabaseConsts;
|
|
|
+import com.sf.dto.resp.HomeBookRespDto;
|
|
|
+import com.sf.dto.resp.HomeFriendLinkRespDto;
|
|
|
+import com.sf.mapper.BookInfoMapper;
|
|
|
+import com.sf.po.BookInfo;
|
|
|
+import com.sf.po.HomeBook;
|
|
|
+import com.sf.mapper.HomeBookMapper;
|
|
|
+import com.sf.service.IHomeBookService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 小说推荐 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author Qing
|
|
|
+ * @since 2023-12-19
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class HomeBookServiceImpl extends ServiceImpl<HomeBookMapper, HomeBook> implements IHomeBookService {
|
|
|
+ private final HomeBookMapper homeBookMapper;
|
|
|
+
|
|
|
+ private final BookInfoMapper bookInfoMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RestResp<List<HomeBookRespDto>> listHomeBooks() {
|
|
|
+ // 从首页小说推荐表中查询出需要推荐的小说
|
|
|
+ QueryWrapper<HomeBook> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.orderByAsc(DatabaseConsts.CommonColumnEnum.SORT.getName());
|
|
|
+ List<HomeBook> homeBooks = homeBookMapper.selectList(queryWrapper);
|
|
|
+
|
|
|
+ // 获取推荐小说ID列表
|
|
|
+ if (!CollectionUtils.isEmpty(homeBooks)) {
|
|
|
+ List<Long> bookIds = homeBooks.stream()
|
|
|
+ .map(HomeBook::getBookId)
|
|
|
+ .toList();
|
|
|
+
|
|
|
+ // 根据小说ID列表查询相关的小说信息列表
|
|
|
+ QueryWrapper<BookInfo> bookInfoQueryWrapper = new QueryWrapper<>();
|
|
|
+ bookInfoQueryWrapper.in(DatabaseConsts.CommonColumnEnum.ID.getName(), bookIds);
|
|
|
+ List<BookInfo> bookInfos = bookInfoMapper.selectList(bookInfoQueryWrapper);
|
|
|
+
|
|
|
+ // 组装 HomeBookRespDto 列表数据并返回
|
|
|
+ if (!CollectionUtils.isEmpty(bookInfos)) {
|
|
|
+ Map<Long, BookInfo> bookInfoMap = bookInfos.stream()
|
|
|
+ .collect(Collectors.toMap(BookInfo::getId, Function.identity()));
|
|
|
+ List<HomeBookRespDto> homeBookRespDtoList = homeBooks.stream().map(v -> {
|
|
|
+ BookInfo bookInfo = bookInfoMap.get(v.getBookId());
|
|
|
+ HomeBookRespDto bookRespDto = new HomeBookRespDto();
|
|
|
+ bookRespDto.setType(v.getType().intValue());
|
|
|
+ bookRespDto.setBookId(v.getBookId());
|
|
|
+ bookRespDto.setBookName(bookInfo.getBookName());
|
|
|
+ bookRespDto.setPicUrl(bookInfo.getPicUrl());
|
|
|
+ bookRespDto.setAuthorName(bookInfo.getAuthorName());
|
|
|
+ bookRespDto.setBookDesc(bookInfo.getBookDesc());
|
|
|
+ return bookRespDto;
|
|
|
+ }).toList();
|
|
|
+ return RestResp.ok(homeBookRespDtoList);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return RestResp.ok(Collections.emptyList());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RestResp<List<HomeFriendLinkRespDto>> listHomeFriendLinks() {
|
|
|
+ // 从友情链接表中查询出友情链接列表
|
|
|
+// QueryWrapper<HomeFriendLink> queryWrapper = new QueryWrapper<>();
|
|
|
+// queryWrapper.orderByAsc(DatabaseConsts.CommonColumnEnum.SORT.getName());
|
|
|
+// List<HomeFriendLinkRespDto> friendLinkRespDtos = friendLinkMapper.selectList(queryWrapper).stream().map(v -> {
|
|
|
+// HomeFriendLinkRespDto respDto = new HomeFriendLinkRespDto();
|
|
|
+// respDto.setLinkName(v.getLinkName());
|
|
|
+// respDto.setLinkUrl(v.getLinkUrl());
|
|
|
+// return respDto;
|
|
|
+// }).toList();
|
|
|
+ return RestResp.ok(Collections.emptyList());
|
|
|
+ }
|
|
|
+}
|