Sfoglia il codice sorgente

更新 block 和书籍搜索接口

tianyunperfect 3 anni fa
parent
commit
da6bad3716

+ 2 - 2
book-server/src/main/java/com/book/server/controller/BookController.java

@@ -34,7 +34,7 @@ public class BookController extends BaseController {
      * @return
      */
     @PostMapping("/query")
-    public Result<PageResult<BookRes>> query(@RequestBody QueryVO queryVO) {
+    public Result<List<BookRes>> query(@RequestBody QueryVO queryVO) {
         return Result.success(bookService.query(queryVO));
     }
 
@@ -45,7 +45,7 @@ public class BookController extends BaseController {
      * @return
      */
     @PostMapping("/recommend")
-    public Result<PageResult<Book>> recommendByRead(@RequestBody QueryVO queryVO) {
+    public Result<List<Book>> recommendByRead(@RequestBody QueryVO queryVO) {
         return Result.success(bookService.recommendByRead(queryVO));
     }
 

+ 2 - 0
book-server/src/main/java/com/book/server/dao/entity/example/BookExample.java

@@ -5,6 +5,8 @@ import java.util.ArrayList;
 import java.util.List;
 
 public class BookExample {
+
+
     /**
      * This field was generated by MyBatis Generator.
      * This field corresponds to the database table book

+ 3 - 3
book-server/src/main/java/com/book/server/dao/mapper/BookMapper2.java

@@ -1,7 +1,7 @@
 package com.book.server.dao.mapper;
 
-import com.book.server.dao.entity.Book;
-import com.book.server.dao.entity.example.BookExample;
+import com.book.server.model.VO.BookRes;
+import com.book.server.model.VO.QueryVO;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
@@ -11,5 +11,5 @@ import java.util.List;
 @Mapper
 @Repository
 public interface BookMapper2 {
-
+    List<BookRes> queryBookRes(@Param("queryVO") QueryVO queryVO, @Param("page") int page, @Param("size") int size);
 }

+ 2 - 2
book-server/src/main/java/com/book/server/service/BookService.java

@@ -9,8 +9,8 @@ import com.book.server.model.VO.QueryVO;
 import java.util.List;
 
 public interface BookService {
-    PageResult<BookRes> query(QueryVO queryVO);
-    PageResult<Book> recommendByRead(QueryVO queryVO);
+    List<BookRes> query(QueryVO queryVO);
+    List<Book> recommendByRead(QueryVO queryVO);
 
     List<BlockRes> getBlockByPageId(Integer pageId);
 

+ 10 - 33
book-server/src/main/java/com/book/server/service/impl/BookServiceImpl.java

@@ -10,10 +10,7 @@ import com.book.server.dao.entity.example.BookCategoryExample;
 import com.book.server.dao.entity.example.BookExample;
 import com.book.server.dao.entity.example.ManageBlockExample;
 import com.book.server.dao.entity.example.ManageBlockResourceExample;
-import com.book.server.dao.mapper.BookCategoryMapper;
-import com.book.server.dao.mapper.BookMapper;
-import com.book.server.dao.mapper.ManageBlockMapper;
-import com.book.server.dao.mapper.ManageBlockResourceMapper;
+import com.book.server.dao.mapper.*;
 import com.book.server.model.VO.BlockRes;
 import com.book.server.model.VO.BookRes;
 import com.book.server.model.VO.ManageBlockResourceRes;
@@ -34,6 +31,8 @@ import java.util.stream.Collectors;
 public class BookServiceImpl implements BookService {
     @Autowired
     private BookMapper bookMapper;
+    @Autowired
+    private BookMapper2 bookMapper2;
 
     @Autowired
     private ManageBlockMapper manageBlockMapper;
@@ -52,44 +51,22 @@ public class BookServiceImpl implements BookService {
 
 
     @Override
-    public PageResult<BookRes> query(QueryVO queryVO) {
-        BookExample example = BookExample.newAndCreateCriteria().example();
-        example.or().andNameLike("%" + queryVO.getQuery() + "%");
-        example.or().andAuthorLike("%" + queryVO.getQuery() + "%");
-        long count = bookMapper.countByExample(example);
-        if (count <= 0) {
-            return new PageResult<>(queryVO.getPage(), queryVO.getSize(), 0L, null);
-        }
-        example.page(queryVO.getPage(), queryVO.getSize());
-        List<Book> books = bookMapper.selectByExample(example);
-        //查询关联表
-        List<BookCategory> allCategory = getAllCategory();
-        HashMap<Integer, String> map = new HashMap<>();
-        for (BookCategory bookCategory : allCategory) {
-            map.put(bookCategory.getId(), bookCategory.getName());
-        }
-        //转存
-        ArrayList<BookRes> bookResList = new ArrayList<>();
-        for (Book book : books) {
-            BookRes bookRes = new BookRes();
-            BeanUtils.copyProperties(book,bookRes);
-            bookRes.setCategoryName(map.get(book.getBookCategoryId()));
-            bookResList.add(bookRes);
-        }
-
-        return new PageResult<>(queryVO.getPage(), queryVO.getSize(), count, bookResList);
+    public List<BookRes> query(QueryVO queryVO) {
+        queryVO.setQuery("%"+queryVO.getQuery()+"%");
+        List<BookRes> bookResList = bookMapper2.queryBookRes(queryVO, queryVO.getPage() * queryVO.getSize(), queryVO.getSize());
+        return bookResList;
     }
 
     @Override
-    public PageResult<Book> recommendByRead(QueryVO queryVO) {
+    public List<Book> recommendByRead(QueryVO queryVO) {
         BookExample example = BookExample.newAndCreateCriteria()
+                .andStateEqualTo("1")
                 .andSexEqualTo(queryVO.getPageId())
                 .example();
-        long count = bookMapper.countByExample(example);
         example.orderBy(Book.Column.readNum.desc());
         example.page(queryVO.getPage(), queryVO.getSize());
         List<Book> books = bookMapper.selectByExample(example);
-        return new PageResult<>(queryVO.getPage(), queryVO.getSize(), count, books);
+        return books;
     }
 
     @Override

+ 71 - 0
book-server/src/main/resources/mapper/Book2Mapper.xml

@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.book.server.dao.mapper.BookMapper2">
+    <resultMap id="BaseResultMap" type="com.book.server.model.VO.BookRes">
+        <!--
+          WARNING - @mbg.generated
+          This element is automatically generated by MyBatis Generator, do not modify.
+          This element was generated on Thu Aug 12 00:28:56 CST 2021.
+        -->
+        <id column="id" jdbcType="BIGINT" property="id"/>
+        <result column="is_audio" jdbcType="TINYINT" property="isAudio"/>
+        <result column="book_category_id" jdbcType="INTEGER" property="bookCategoryId"/>
+        <result column="name" jdbcType="VARCHAR" property="name"/>
+        <result column="realname" jdbcType="VARCHAR" property="realname"/>
+        <result column="title" jdbcType="VARCHAR" property="title"/>
+        <result column="author" jdbcType="VARCHAR" property="author"/>
+        <result column="image" jdbcType="VARCHAR" property="image"/>
+        <result column="big_cover" jdbcType="VARCHAR" property="bigCover"/>
+        <result column="small_cover" jdbcType="VARCHAR" property="smallCover"/>
+        <result column="description" jdbcType="VARCHAR" property="description"/>
+        <result column="idx" jdbcType="INTEGER" property="idx"/>
+        <result column="referral_num" jdbcType="TINYINT" property="referralNum"/>
+        <result column="idxx" jdbcType="INTEGER" property="idxx"/>
+        <result column="state" jdbcType="CHAR" property="state"/>
+        <result column="free_stime" jdbcType="INTEGER" property="freeStime"/>
+        <result column="free_etime" jdbcType="INTEGER" property="freeEtime"/>
+        <result column="sex" jdbcType="CHAR" property="sex"/>
+        <result column="billing_type" jdbcType="CHAR" property="billingType"/>
+        <result column="price" jdbcType="INTEGER" property="price"/>
+        <result column="app_price" jdbcType="INTEGER" property="appPrice"/>
+        <result column="is_finish" jdbcType="CHAR" property="isFinish"/>
+        <result column="free_chapter_num" jdbcType="INTEGER" property="freeChapterNum"/>
+        <result column="word_count" jdbcType="VARCHAR" property="wordCount"/>
+        <result column="chapter_num" jdbcType="INTEGER" property="chapterNum"/>
+        <result column="first_chapter_id" jdbcType="BIGINT" property="firstChapterId"/>
+        <result column="first_chapter_name" jdbcType="VARCHAR" property="firstChapterName"/>
+        <result column="last_chapter_id" jdbcType="BIGINT" property="lastChapterId"/>
+        <result column="last_chapter_name" jdbcType="VARCHAR" property="lastChapterName"/>
+        <result column="last_chapter_utime" jdbcType="INTEGER" property="lastChapterUtime"/>
+        <result column="read_num" jdbcType="INTEGER" property="readNum"/>
+        <result column="article_chapter_order" jdbcType="INTEGER" property="articleChapterOrder"/>
+        <result column="attent_chapter_order" jdbcType="INTEGER" property="attentChapterOrder"/>
+        <result column="corner_mark" jdbcType="CHAR" property="cornerMark"/>
+        <result column="recommand_book_id" jdbcType="BIGINT" property="recommandBookId"/>
+        <result column="createtime" jdbcType="INTEGER" property="createtime"/>
+        <result column="updatetime" jdbcType="INTEGER" property="updatetime"/>
+        <result column="keywords" jdbcType="VARCHAR" property="keywords"/>
+        <result column="cansee" jdbcType="CHAR" property="cansee"/>
+        <result column="rank" jdbcType="TINYINT" property="rank"/>
+        <result column="check_rank" jdbcType="TINYINT" property="checkRank"/>
+        <result column="check_remark" jdbcType="VARCHAR" property="checkRemark"/>
+        <result column="editor_recommand" jdbcType="VARCHAR" property="editorRecommand"/>
+        <result column="book_tags" jdbcType="VARCHAR" property="bookTags"/>
+        <result column="a" jdbcType="TINYINT" property="a"/>
+        <result column="expire_time" jdbcType="INTEGER" property="expireTime"/>
+        <result column="cp_id" jdbcType="INTEGER" property="cpId"/>
+        <result column="cp_name" jdbcType="VARCHAR" property="cpName"/>
+        <result column="tags" jdbcType="VARCHAR" property="tags"/>
+        <result column="classify_white_list" jdbcType="TINYINT" property="classifyWhiteList"/>
+        <result column="put_ad_set" jdbcType="TINYINT" property="putAdSet"/>
+        <result column="categoryName" jdbcType="VARCHAR" property="categoryName"/>
+    </resultMap>
+
+    <select id="queryBookRes" resultMap="BaseResultMap">
+        SELECT t.*,c.`name` as "categoryName"
+        from book t left join book_category c on t.`book_category_id`=c.`id`
+        where t.state = '1'
+          and (t.`name` like #{queryVO.query} or t.author like #{queryVO.query}) limit #{page}, #{size};
+    </select>
+
+</mapper>

+ 0 - 63
book-server/src/main/resources/mapper/BookMapper2.xml

@@ -1,63 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.book.server.dao.mapper.BookMapper2">
-  <resultMap id="BaseResultMap" type="com.book.server.dao.entity.Book">
-    <!--
-      WARNING - @mbg.generated
-      This element is automatically generated by MyBatis Generator, do not modify.
-      This element was generated on Thu Aug 12 00:28:56 CST 2021.
-    -->
-    <id column="id" jdbcType="BIGINT" property="id" />
-    <result column="is_audio" jdbcType="TINYINT" property="isAudio" />
-    <result column="book_category_id" jdbcType="INTEGER" property="bookCategoryId" />
-    <result column="name" jdbcType="VARCHAR" property="name" />
-    <result column="realname" jdbcType="VARCHAR" property="realname" />
-    <result column="title" jdbcType="VARCHAR" property="title" />
-    <result column="author" jdbcType="VARCHAR" property="author" />
-    <result column="image" jdbcType="VARCHAR" property="image" />
-    <result column="big_cover" jdbcType="VARCHAR" property="bigCover" />
-    <result column="small_cover" jdbcType="VARCHAR" property="smallCover" />
-    <result column="description" jdbcType="VARCHAR" property="description" />
-    <result column="idx" jdbcType="INTEGER" property="idx" />
-    <result column="referral_num" jdbcType="TINYINT" property="referralNum" />
-    <result column="idxx" jdbcType="INTEGER" property="idxx" />
-    <result column="state" jdbcType="CHAR" property="state" />
-    <result column="free_stime" jdbcType="INTEGER" property="freeStime" />
-    <result column="free_etime" jdbcType="INTEGER" property="freeEtime" />
-    <result column="sex" jdbcType="CHAR" property="sex" />
-    <result column="billing_type" jdbcType="CHAR" property="billingType" />
-    <result column="price" jdbcType="INTEGER" property="price" />
-    <result column="app_price" jdbcType="INTEGER" property="appPrice" />
-    <result column="is_finish" jdbcType="CHAR" property="isFinish" />
-    <result column="free_chapter_num" jdbcType="INTEGER" property="freeChapterNum" />
-    <result column="word_count" jdbcType="VARCHAR" property="wordCount" />
-    <result column="chapter_num" jdbcType="INTEGER" property="chapterNum" />
-    <result column="first_chapter_id" jdbcType="BIGINT" property="firstChapterId" />
-    <result column="first_chapter_name" jdbcType="VARCHAR" property="firstChapterName" />
-    <result column="last_chapter_id" jdbcType="BIGINT" property="lastChapterId" />
-    <result column="last_chapter_name" jdbcType="VARCHAR" property="lastChapterName" />
-    <result column="last_chapter_utime" jdbcType="INTEGER" property="lastChapterUtime" />
-    <result column="read_num" jdbcType="INTEGER" property="readNum" />
-    <result column="article_chapter_order" jdbcType="INTEGER" property="articleChapterOrder" />
-    <result column="attent_chapter_order" jdbcType="INTEGER" property="attentChapterOrder" />
-    <result column="corner_mark" jdbcType="CHAR" property="cornerMark" />
-    <result column="recommand_book_id" jdbcType="BIGINT" property="recommandBookId" />
-    <result column="createtime" jdbcType="INTEGER" property="createtime" />
-    <result column="updatetime" jdbcType="INTEGER" property="updatetime" />
-    <result column="keywords" jdbcType="VARCHAR" property="keywords" />
-    <result column="cansee" jdbcType="CHAR" property="cansee" />
-    <result column="rank" jdbcType="TINYINT" property="rank" />
-    <result column="check_rank" jdbcType="TINYINT" property="checkRank" />
-    <result column="check_remark" jdbcType="VARCHAR" property="checkRemark" />
-    <result column="editor_recommand" jdbcType="VARCHAR" property="editorRecommand" />
-    <result column="book_tags" jdbcType="VARCHAR" property="bookTags" />
-    <result column="a" jdbcType="TINYINT" property="a" />
-    <result column="expire_time" jdbcType="INTEGER" property="expireTime" />
-    <result column="cp_id" jdbcType="INTEGER" property="cpId" />
-    <result column="cp_name" jdbcType="VARCHAR" property="cpName" />
-    <result column="tags" jdbcType="VARCHAR" property="tags" />
-    <result column="classify_white_list" jdbcType="TINYINT" property="classifyWhiteList" />
-    <result column="put_ad_set" jdbcType="TINYINT" property="putAdSet" />
-  </resultMap>
-
-</mapper>