搜索服务完成

This commit is contained in:
xiongxiaoyang
2020-05-28 09:48:46 +08:00
parent c6e6a1df9f
commit a310512221
35 changed files with 4546 additions and 24 deletions

View File

@ -1,8 +1,14 @@
package com.java2nb.novel;
import com.java2nb.novel.common.cache.CacheService;
import com.java2nb.novel.common.cache.impl.RedisServiceImpl;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
/**
* 小说微服务启动器
@ -10,7 +16,11 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
* @version 1.0
* @since 2020/5/27
*/
@SpringBootApplication
@SpringBootApplication(exclude={
RedisAutoConfiguration.class,
RedisRepositoriesAutoConfiguration.class
})
//@ComponentScan(excludeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {CacheService.class})})
@EnableFeignClients
public class BookApplication {

View File

@ -0,0 +1,20 @@
package com.java2nb.novel.book.controller;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author 11797
*/
@RestController
@RequestMapping("book")
@RequiredArgsConstructor
@Slf4j
@Api(tags = "小说相关接口")
public class BookController {
}

View File

@ -0,0 +1,43 @@
package com.java2nb.novel.book.controller.api;
import com.java2nb.novel.book.entity.Book;
import com.java2nb.novel.book.service.BookService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
import java.util.Date;
import java.util.List;
/**
* 小说微服务API接口内部调用
* @author xiongxiaoyang
* @version 1.0
* @since 2020/5/27
*/
@RestController
@RequestMapping(("api/book"))
@ApiIgnore
@RequiredArgsConstructor
public class BookApi {
private final BookService bookService;
/**
* 根据最小更新时间分页查询书籍列表
* @param minDate 最小时间,包括该时间
* @param limit 查询数量
* @return 书籍列表
* */
@GetMapping("queryBookByMinUpdateTime")
List<Book> queryBookByMinUpdateTime(Date minDate, int limit){
return bookService.queryBookByMinUpdateTime(minDate,limit);
}
}

View File

@ -0,0 +1,24 @@
package com.java2nb.novel.book.service;
import com.java2nb.novel.book.entity.Book;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.Date;
import java.util.List;
/**
* 小说服务接口
* @author xiongxiaoyang
* @version 1.0
* @since 2020/5/28
*/
public interface BookService {
/**
* 根据最小更新时间分页查询书籍列表
* @param minDate 最小时间,包括该时间
* @param limit 查询数量
* @return 书籍列表
* */
List<Book> queryBookByMinUpdateTime(Date minDate, int limit);
}

View File

@ -0,0 +1,40 @@
package com.java2nb.novel.book.service.impl;
import com.java2nb.novel.book.entity.Book;
import com.java2nb.novel.book.mapper.BookDynamicSqlSupport;
import com.java2nb.novel.book.mapper.BookMapper;
import com.java2nb.novel.book.service.BookService;
import lombok.RequiredArgsConstructor;
import org.mybatis.dynamic.sql.render.RenderingStrategies;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import static com.java2nb.novel.book.mapper.BookDynamicSqlSupport.book;
import static org.mybatis.dynamic.sql.SqlBuilder.isGreaterThan;
import static org.mybatis.dynamic.sql.select.SelectDSL.select;
/**
* 小说服务接口实现
* @author xiongxiaoyang
* @version 1.0
* @since 2020/5/28
*/
@Service
@RequiredArgsConstructor
public class BookServiceImpl implements BookService {
private final BookMapper bookMapper;
@Override
public List<Book> queryBookByMinUpdateTime(Date minDate, int limit) {
return bookMapper.selectMany(select(book.allColumns())
.from(book)
.where(BookDynamicSqlSupport.updateTime, isGreaterThan(minDate))
.orderBy(BookDynamicSqlSupport.updateTime)
.limit(limit)
.build()
.render(RenderingStrategies.MYBATIS3));
}
}