小说微服务开发完成,用户微服务开发中

This commit is contained in:
xiongxiaoyang 2020-05-28 22:16:26 +08:00
parent bcd1caf7a8
commit 861e966a88
18 changed files with 583 additions and 19 deletions

View File

@ -89,6 +89,8 @@ novel-cloud
![QQ20200520-215756](./assert/QQ20200528-200023.png)
![QQ20200520-215756](./assert/QQ20200528-221348.png)
5. 门户网站
![QQ20200520-215756](./assert/pc_index.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 KiB

View File

@ -16,6 +16,7 @@
<groupId>com.java2nb.novel</groupId>
<artifactId>novel-common</artifactId>
</dependency>
</dependencies>

View File

@ -3,9 +3,10 @@ package com.java2nb.novel.book.entity;
import io.swagger.annotations.ApiModelProperty;
import javax.annotation.Generated;
import java.io.Serializable;
import java.util.Date;
public class BookComment {
public class BookComment implements Serializable {
@ApiModelProperty(value = "主键")
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Long id;

View File

@ -0,0 +1,28 @@
package com.java2nb.novel.book.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.java2nb.novel.book.entity.BookComment;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @author 11797
*/
@Data
public class BookCommentVO extends BookComment {
private String createUserName;
private String createUserPhoto;
@ApiModelProperty(value = "评价时间")
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
@Override
public String toString() {
return super.toString();
}
}

View File

@ -17,6 +17,10 @@
<groupId>com.java2nb.novel</groupId>
<artifactId>book-api</artifactId>
</dependency>
<dependency>
<groupId>com.java2nb.novel</groupId>
<artifactId>user-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
@ -38,6 +42,8 @@
</dependencies>

View File

@ -1,10 +1,24 @@
package com.java2nb.novel.book.controller;
import com.github.pagehelper.PageInfo;
import com.java2nb.novel.book.entity.Book;
import com.java2nb.novel.book.entity.BookCategory;
import com.java2nb.novel.book.entity.BookContent;
import com.java2nb.novel.book.entity.BookIndex;
import com.java2nb.novel.book.service.BookService;
import com.java2nb.novel.book.vo.BookCommentVO;
import com.java2nb.novel.common.bean.PageBean;
import com.java2nb.novel.common.bean.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author 11797
@ -16,5 +30,140 @@ import org.springframework.web.bind.annotation.RestController;
@Api(tags = "小说相关接口")
public class BookController {
private final BookService bookService;
/**
* 小说分类列表查询接口
*/
@ApiOperation("小说分类列表查询接口")
@GetMapping("listBookCategory")
public ResultBean<List<BookCategory>> listBookCategory() {
return ResultBean.ok(bookService.listBookCategory());
}
/**
* 小说详情信息查询接口
*/
@ApiOperation("小说详情信息查询接口")
@GetMapping("{id}")
public ResultBean<Book> queryBookDetail(@ApiParam("小说ID") @PathVariable("id") Long id) {
return ResultBean.ok(bookService.queryBookDetail(id));
}
/**
* 小说排行信息查询接口
*/
@ApiOperation("小说排行信息查询接口")
@GetMapping("listRank")
public ResultBean<List<Book>> listRank(@ApiParam(value = "排行类型0:点击排行1更新排行2新书排行3评论排行", defaultValue = "0") @RequestParam(value = "type", defaultValue = "0") Byte type) {
return ResultBean.ok(bookService.listRank(type, 30));
}
/**
* 点击量新增接口
*/
@ApiOperation("点击量新增接口")
@PostMapping("addVisitCount")
public ResultBean addVisitCount(@ApiParam("小说ID") @RequestParam("bookId") Long bookId) {
bookService.addVisitCount(bookId, 1);
return ResultBean.ok();
}
/**
* 章节相关信息查询接口
* */
@ApiOperation("章节相关信息查询接口")
@GetMapping("queryBookIndexAbout")
public ResultBean<Map<String,Object>> queryBookIndexAbout(@ApiParam("小说ID") @RequestParam("bookId") Long bookId,@ApiParam("最新章节目录ID") @RequestParam("lastBookIndexId") Long lastBookIndexId) {
Map<String,Object> data = new HashMap<>(2);
//查询章节总数
data.put("bookIndexCount",bookService.queryIndexCount(bookId));
//查询最新章节内容
String lastBookContent = bookService.queryBookContent(lastBookIndexId).getContent();
if(lastBookContent.length()>42){
lastBookContent=lastBookContent.substring(0,42);
}
data.put("lastBookContent",lastBookContent);
return ResultBean.ok(data);
}
/**
* 同类推荐书籍查询接口
* */
@ApiOperation("同类推荐书籍查询接口")
@GetMapping("listRecBookByCatId")
public ResultBean<List<Book>> listRecBookByCatId(@ApiParam("小说分类ID") @RequestParam("catId") Integer catId) {
return ResultBean.ok(bookService.listRecBookByCatId(catId));
}
/**
*书籍评论列表分页查询接口
* */
@ApiOperation("书籍评论列表分页查询接口")
@GetMapping("listCommentByPage")
public ResultBean<List<BookCommentVO>> listCommentByPage(@ApiParam("小说ID") @RequestParam("bookId") Long bookId, @ApiParam("当前页码") @RequestParam(value = "curr", defaultValue = "1") int page, @ApiParam("分页大小") @RequestParam(value = "limit", defaultValue = "5") int pageSize) {
return ResultBean.ok(new PageBean<>(bookService.listCommentByPage(null,bookId,page,pageSize)));
}
/**
* 小说目录列表查询接口
* */
@ApiOperation("小说目录列表查询接口")
@GetMapping("listNewIndex")
public ResultBean<List<BookIndex>> listNewIndex(@ApiParam("小说ID") @RequestParam("bookId") Long bookId,@ApiParam(value = "排序字符串,为空则按目录号排序") @RequestParam("orderBy") String orderBy,@ApiParam(value = "查询数量,为空则全部查询") @RequestParam("limit") Integer limit){
return ResultBean.ok(bookService.listNewIndex(bookId,orderBy,limit));
}
/**
* 首章目录ID查询接口
* */
@ApiOperation("首章目录ID查询接口")
@GetMapping("queryFirstBookIndexId")
public ResultBean<Long> queryFirstBookIndexId(@ApiParam("小说ID") @RequestParam("bookId") Long bookId){
return ResultBean.ok(bookService.queryFirstBookIndexId(bookId));
}
/**
* 目录查询接口
* */
@ApiOperation("目录查询接口")
@GetMapping("queryBookIndex")
public ResultBean<BookIndex> queryBookIndex(@ApiParam("目录ID") @RequestParam("bookIndexId") Long bookIndexId){
return ResultBean.ok(bookService.queryBookIndex(bookIndexId));
}
/**
* 上一章节和下一章节目录ID查询接口
* */
@ApiOperation("上一章节和下一章节目录ID查询接口")
@GetMapping("queryPreAndNextBookIndexId")
public ResultBean<Map<String,Long>> queryPreAndNextBookIndexId(@ApiParam("小说ID") @RequestParam("bookId") Long bookId,@ApiParam("目录号") @RequestParam("indexNum") Integer indexNum){
return ResultBean.ok(bookService.queryPreAndNextBookIndexId(bookId,indexNum));
}
/**
* 内容查询接口
* */
@ApiOperation("内容查询接口")
@GetMapping("queryBookContent")
public ResultBean<BookContent> queryBookContent(@ApiParam("目录ID") @RequestParam("bookIndexId") Long bookIndexId){
return ResultBean.ok(bookService.queryBookContent(bookIndexId));
}
}

View File

@ -0,0 +1,15 @@
package com.java2nb.novel.book.feign;
import com.java2nb.novel.user.api.UserApi;
import org.springframework.cloud.openfeign.FeignClient;
/**
* 用户服务Feign客户端
* @author xiongxiaoyang
* @version 1.0
* @since 2020/5/28
*/
@FeignClient("user-service")
public interface UserFeignClient extends UserApi {
}

View File

@ -1,6 +1,7 @@
package com.java2nb.novel.book.mapper;
import com.java2nb.novel.book.entity.BookComment;
import com.java2nb.novel.book.vo.BookCommentVO;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.SqlBuilder;
@ -181,4 +182,5 @@ public interface BookCommentMapper {
.build()
.execute();
}
}

View File

@ -307,4 +307,8 @@ public interface BookMapper {
.build()
.execute();
}
void addVisitCount(@Param("bookId") Long bookId, @Param("visitCount") Integer visitCount);
List<Book> listRecBookByCatId(@Param("catId") Integer catId);
}

View File

@ -1,9 +1,14 @@
package com.java2nb.novel.book.service;
import com.java2nb.novel.book.entity.Book;
import com.java2nb.novel.book.entity.BookCategory;
import com.java2nb.novel.book.entity.BookContent;
import com.java2nb.novel.book.entity.BookIndex;
import com.java2nb.novel.book.vo.BookCommentVO;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 小说服务接口
@ -17,22 +22,106 @@ public interface BookService {
* 根据最小更新时间分页查询书籍列表
* @param minDate 最小时间包括该时间
* @param limit 查询数量
* @return 书籍列表
* @return 书籍数据集合
* */
List<Book> queryBookByMinUpdateTime(Date minDate, int limit);
/**
* 根据小说ID集合查询书籍列表
* @param ids 小说ID集合
* @return 书籍列表
* @return 书籍数据集合
* */
List<Book> queryBookByIds(List<Long> ids);
/**
* 小说排行数据查询列表
* @param type 排行类型1更新排行2新书排行3评论排行
* @param type 排行类型0:点击排行1更新排行2新书排行3评论排行
* @param limit 查询数量
* @return 书籍列表
* @return 书籍数据集合
* */
List<Book> listRank(Byte type, Integer limit);
/**
* 小说分类列表查询
* @return 分类数据集合
* */
List<BookCategory> listBookCategory();
/**
* 小说详情信息查询
* @param id 小说ID
* @return 小说数据对象
* */
Book queryBookDetail(Long id);
/**
* 增加小说点击量
* @param bookId 小说ID
* @param addCount 新增的数量
* */
void addVisitCount(Long bookId, int addCount);
/**
* 查询章节数
* @param bookId 书籍ID
* @return 章节数量
* */
long queryIndexCount(Long bookId);
/**
* 查询章节内容
* @param bookIndexId 目录ID
* @return 书籍内容
* */
BookContent queryBookContent(Long bookIndexId);
/**
* 根据分类id查询同类推荐书籍
* @param catId 分类id
* @return 书籍集合
* */
List<Book> listRecBookByCatId(Integer catId);
/**
*分页查询书籍评论列表
* @param userId 用户ID
* @param bookId 书籍ID
* @param page 页码
* @param pageSize 分页大小
* @return 评论集合
* */
List<BookCommentVO> listCommentByPage(Long userId, Long bookId, int page, int pageSize);
/**
* 查询目录列表
* @param bookId 书籍ID
* @param orderBy 排序
*@param limit 查询条数
*@return 目录集合
* */
List<BookIndex> listNewIndex(Long bookId, String orderBy, Integer limit);
/**
* 查询首章目录ID
* @param bookId 书籍ID
* @return 首章目录ID
* */
Long queryFirstBookIndexId(Long bookId);
/**
* 查询目录
* @param bookIndexId 目录ID
* @return 目录信息
* */
BookIndex queryBookIndex(Long bookIndexId);
/**
* 上一章节和下一章节目录ID查询接口
* @param bookId 书籍ID
* @param indexNum 目录号
* @return 上一章节和下一章节目录ID数据
* */
Map<String,Long> queryPreAndNextBookIndexId(Long bookId, Integer indexNum);
}

View File

@ -1,21 +1,28 @@
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.github.pagehelper.PageHelper;
import com.java2nb.novel.book.entity.*;
import com.java2nb.novel.book.feign.UserFeignClient;
import com.java2nb.novel.book.mapper.*;
import com.java2nb.novel.book.service.BookService;
import com.java2nb.novel.book.vo.BookCommentVO;
import com.java2nb.novel.common.utils.BeanUtil;
import com.java2nb.novel.user.entity.User;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.mybatis.dynamic.sql.SortSpecification;
import org.mybatis.dynamic.sql.render.RenderingStrategies;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import tk.mybatis.orderbyhelper.OrderByHelper;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import static com.java2nb.novel.book.mapper.BookDynamicSqlSupport.book;
import static org.mybatis.dynamic.sql.SqlBuilder.isGreaterThan;
import static org.mybatis.dynamic.sql.SqlBuilder.isIn;
import static org.mybatis.dynamic.sql.SqlBuilder.*;
import static org.mybatis.dynamic.sql.select.SelectDSL.select;
/**
@ -30,6 +37,16 @@ public class BookServiceImpl implements BookService {
private final BookMapper bookMapper;
private final BookCategoryMapper bookCategoryMapper;
private final BookIndexMapper bookIndexMapper;
private final BookContentMapper bookContentMapper;
private final BookCommentMapper bookCommentMapper;
private final UserFeignClient userFeignClient;
@Override
public List<Book> queryBookByMinUpdateTime(Date minDate, int limit) {
return bookMapper.selectMany(select(book.allColumns())
@ -90,4 +107,175 @@ public class BookServiceImpl implements BookService {
.render(RenderingStrategies.MYBATIS3);
return bookMapper.selectMany(selectStatement);
}
@Override
public List<BookCategory> listBookCategory() {
SelectStatementProvider selectStatementProvider = select(BookCategoryDynamicSqlSupport.id, BookCategoryDynamicSqlSupport.name, BookCategoryDynamicSqlSupport.workDirection)
.from(BookCategoryDynamicSqlSupport.bookCategory)
.orderBy(BookCategoryDynamicSqlSupport.sort)
.build()
.render(RenderingStrategies.MYBATIS3);
return bookCategoryMapper.selectMany(selectStatementProvider);
}
@Override
public Book queryBookDetail(Long id) {
SelectStatementProvider selectStatement = select(BookDynamicSqlSupport.book.allColumns())
.from(BookDynamicSqlSupport.book)
.where(BookDynamicSqlSupport.id, isEqualTo(id))
.limit(1)
.build()
.render(RenderingStrategies.MYBATIS3);
List<Book> books = bookMapper.selectMany(selectStatement);
return books.size() >0 ? books.get(0) : null;
}
@Override
public void addVisitCount(Long bookId, int addCount) {
bookMapper.addVisitCount(bookId,addCount);
}
@Override
public long queryIndexCount(Long bookId) {
SelectStatementProvider selectStatement = select(count(BookIndexDynamicSqlSupport.id))
.from(BookIndexDynamicSqlSupport.bookIndex)
.where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId))
.build()
.render(RenderingStrategies.MYBATIS3);
return bookIndexMapper.count(selectStatement);
}
@Override
public BookContent queryBookContent(Long bookIndexId) {
SelectStatementProvider selectStatement = select(BookContentDynamicSqlSupport.id, BookContentDynamicSqlSupport.content)
.from(BookContentDynamicSqlSupport.bookContent)
.where(BookContentDynamicSqlSupport.indexId, isEqualTo(bookIndexId))
.limit(1)
.build()
.render(RenderingStrategies.MYBATIS3);
return bookContentMapper.selectMany(selectStatement).get(0);
}
@Override
public List<Book> listRecBookByCatId(Integer catId) {
return bookMapper.listRecBookByCatId(catId);
}
@Override
public List<BookCommentVO> listCommentByPage(Long userId, Long bookId, int page, int pageSize) {
//分页查询小说评论数据
PageHelper.startPage(page, pageSize);
List<BookComment> bookCommentList = bookCommentMapper.selectMany(
select(BookCommentDynamicSqlSupport.id,BookCommentDynamicSqlSupport.bookId,
BookCommentDynamicSqlSupport.createUserId,
BookCommentDynamicSqlSupport.commentContent,BookCommentDynamicSqlSupport.replyCount,
BookCommentDynamicSqlSupport.createTime)
.from(BookCommentDynamicSqlSupport.bookComment)
.where(BookCommentDynamicSqlSupport.bookId,isEqualTo(bookId))
.orderBy(BookCommentDynamicSqlSupport.createTime.descending())
.build()
.render(RenderingStrategies.MYBATIS3));
//根据评论人ID集合查询出评论人集合数据
List<User> users = userFeignClient.queryById(bookCommentList.stream().map(BookComment::getCreateUserId).collect(Collectors.toList()));
Map<Long, User> userMap = users.stream().collect(Collectors.toMap(User::getId, Function.identity(), (key1, key2) -> key2));
//将评论数据和评论人数据关联起来
List<BookCommentVO> resultList = new ArrayList<>(bookCommentList.size());
for(BookComment bookComment : bookCommentList){
BookCommentVO bookCommentVO = new BookCommentVO();
BeanUtils.copyProperties(bookComment,bookCommentVO);
User user = userMap.get(bookComment.getCreateUserId());
if(user != null){
bookCommentVO.setCreateUserName(user.getUsername());
bookCommentVO.setCreateUserPhoto(user.getUserPhoto());
}
resultList.add(bookCommentVO);
}
return resultList;
}
@Override
public List<BookIndex> listNewIndex(Long bookId, String orderBy, Integer limit) {
if (StringUtils.isNotBlank(orderBy)) {
OrderByHelper.orderBy(orderBy);
}
if (limit != null) {
PageHelper.startPage(1, limit);
}
SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id, BookIndexDynamicSqlSupport.bookId,
BookIndexDynamicSqlSupport.indexNum, BookIndexDynamicSqlSupport.indexName,
BookIndexDynamicSqlSupport.updateTime, BookIndexDynamicSqlSupport.isVip)
.from(BookIndexDynamicSqlSupport.bookIndex)
.where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId))
.build()
.render(RenderingStrategies.MYBATIS3);
return bookIndexMapper.selectMany(selectStatement);
}
@Override
public Long queryFirstBookIndexId(Long bookId) {
SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id)
.from(BookIndexDynamicSqlSupport.bookIndex)
.where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId))
.orderBy(BookIndexDynamicSqlSupport.indexNum)
.limit(1)
.build()
.render(RenderingStrategies.MYBATIS3);
return bookIndexMapper.selectMany(selectStatement).get(0).getId();
}
@Override
public BookIndex queryBookIndex(Long bookIndexId) {
SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id, BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.indexNum, BookIndexDynamicSqlSupport.indexName, BookIndexDynamicSqlSupport.wordCount, BookIndexDynamicSqlSupport.updateTime, BookIndexDynamicSqlSupport.isVip)
.from(BookIndexDynamicSqlSupport.bookIndex)
.where(BookIndexDynamicSqlSupport.id, isEqualTo(bookIndexId))
.limit(1)
.build()
.render(RenderingStrategies.MYBATIS3);
return bookIndexMapper.selectMany(selectStatement).get(0);
}
@Override
public Map<String, Long> queryPreAndNextBookIndexId(Long bookId, Integer indexNum) {
Map<String, Long> result = new HashMap<>(2);
SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id)
.from(BookIndexDynamicSqlSupport.bookIndex)
.where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId))
.and(BookIndexDynamicSqlSupport.indexNum, isLessThan(indexNum))
.orderBy(BookIndexDynamicSqlSupport.indexNum.descending())
.limit(1)
.build()
.render(RenderingStrategies.MYBATIS3);
List<BookIndex> list = bookIndexMapper.selectMany(selectStatement);
if (list.size() == 0) {
result.put("preBookIndexId",0L);
} else {
result.put("preBookIndexId",list.get(0).getId());
}
selectStatement = select(BookIndexDynamicSqlSupport.id)
.from(BookIndexDynamicSqlSupport.bookIndex)
.where(BookIndexDynamicSqlSupport.bookId, isEqualTo(bookId))
.and(BookIndexDynamicSqlSupport.indexNum, isGreaterThan(indexNum))
.orderBy(BookIndexDynamicSqlSupport.indexNum)
.limit(1)
.build()
.render(RenderingStrategies.MYBATIS3);
list = bookIndexMapper.selectMany(selectStatement);
if (list.size() == 0) {
result.put("nextBookIndexId",0L);
} else {
result.put("nextBookIndexId",list.get(0).getId());
}
return result;
}
}

View File

@ -0,0 +1,38 @@
<?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.java2nb.novel.book.mapper.BookMapper">
<update id="addVisitCount" >
update book set visit_count = visit_count + ${visitCount}
where id = #{bookId}
</update>
<select id="listRecBookByCatId" parameterType="int" resultType="com.java2nb.novel.book.entity.Book">
select id,pic_url,book_name,book_desc
from book
where cat_id = #{catId}
order by RAND() LIMIT 4
</select>
<update id="addCommentCount" parameterType="long">
update book set comment_count = comment_count+1
where id = #{bookId}
</update>
<select id="queryNetworkPicBooks" resultType="com.java2nb.novel.book.entity.Book">
select
id,pic_url from book
where pic_url like 'http%'
and pic_url not like concat('%',#{localPicPrefix},'%')
limit #{limit}
</select>
<select id="selectIdsByScoreAndRandom" parameterType="int" resultType="com.java2nb.novel.book.entity.Book">
select id,book_name,author_name,pic_url,book_desc,score from book ORDER BY score,RAND() LIMIT #{limit};
</select>
</mapper>

View File

@ -3,8 +3,11 @@ package com.java2nb.novel.user.api;
import com.java2nb.novel.user.entity.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
/**
* 用户微服务API接口定义内部
* @author xiongxiaoyang
@ -19,8 +22,16 @@ public interface UserApi {
* @param password 密码
* @return 用户对象不存在返回null
* */
@GetMapping("api/queryByUsernameAndPassword")
@GetMapping("api/user/queryByUsernameAndPassword")
User queryByUsernameAndPassword(@RequestParam("username") String username, @RequestParam("password") String password);
/**
* 根据用户名ID集合查询用户集合信息
* @param ids 用户ID集合
* @return 用户集合对象
* */
@GetMapping("api/user/queryById")
List<User> queryById(@RequestBody List<Long> ids);
}

View File

@ -3,9 +3,10 @@ package com.java2nb.novel.user.entity;
import io.swagger.annotations.ApiModelProperty;
import javax.annotation.Generated;
import java.io.Serializable;
import java.util.Date;
public class User {
public class User implements Serializable {
@ApiModelProperty(value = "主键")
@Generated("org.mybatis.generator.api.MyBatisGenerator")
private Long id;

View File

@ -4,11 +4,11 @@ package com.java2nb.novel.user.controller.api;
import com.java2nb.novel.user.entity.User;
import com.java2nb.novel.user.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;
/**
* 用户微服务API接口内部调用
* @author xiongxiaoyang
@ -33,6 +33,16 @@ public class UserApi {
}
/**
* 根据用户名ID集合查询用户集合信息
* @param ids 用户ID集合
* @return 用户集合对象
* */
@GetMapping("queryById")
List<User> queryById(@RequestBody List<Long> ids){
return userService.queryById(ids);
}

View File

@ -5,6 +5,8 @@ import com.java2nb.novel.common.bean.UserDetails;
import com.java2nb.novel.user.entity.User;
import com.java2nb.novel.user.form.UserForm;
import java.util.List;
/**
* 用户服务接口
* @author xiongxiaoyang
@ -29,4 +31,10 @@ public interface UserService {
UserDetails login(UserForm form);
/**
* 根据用户名ID集合查询用户集合信息
* @param ids 用户ID集合
* @return 用户集合对象
* */
List<User> queryById(List<Long> ids);
}

View File

@ -18,6 +18,7 @@ import org.springframework.stereotype.Service;
import java.util.List;
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;
import static org.mybatis.dynamic.sql.SqlBuilder.isIn;
import static org.mybatis.dynamic.sql.select.SelectDSL.select;
/**
@ -62,4 +63,14 @@ public class UserServiceImpl implements UserService {
userDetails.setUsername(form.getUsername());
return userDetails;
}
@Override
public List<User> queryById(List<Long> ids) {
return userMapper.selectMany(
select(UserDynamicSqlSupport.id,UserDynamicSqlSupport.username,
UserDynamicSqlSupport.userPhoto)
.from(UserDynamicSqlSupport.user)
.where(UserDynamicSqlSupport.id,isIn(ids)).build()
.render(RenderingStrategies.MYBATIS3));
}
}