Commit 33fdd0d5 authored by 王飞's avatar 王飞

Feat

1、swagger兼容分页查询。

Reference N/A
parent 38aaca5f
......@@ -3,12 +3,15 @@ package com.ruoyi.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ruoyi.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 书籍
* @TableName t_book
*/
@ApiModel
@TableName(value ="t_book")
@Data
public class Book extends BaseEntity {
......@@ -17,12 +20,14 @@ public class Book extends BaseEntity {
/**
* 主键
*/
@ApiModelProperty("主键")
@TableId
private Long id;
/**
* 书名
*/
@ApiModelProperty("书名")
private String name;
}
\ No newline at end of file
......@@ -18,7 +18,7 @@ import java.util.List;
*/
@Repository
public interface BookMapper extends BaseMapper<Book> {
List<Book> selectBookList(Book book);
List<Book> selectBookList(@Param("name") String name);
}
......
......@@ -15,8 +15,8 @@ import java.util.List;
*/
public interface BookService extends IService<Book> {
List<Book> selectBookList(Book book);
List<Book> selectBookList(String name);
List<Book> selectBookListException(Book book);
List<Book> selectBookListException(String name);
}
......@@ -27,12 +27,12 @@ public class BookServiceImpl extends ServiceImpl<BookMapper, Book> implements Bo
@Trace
@Tags({@Tag(key = "param", value = "arg[0]"), @Tag(key = "result", value = "returnedObj")})
@Override
public List<Book> selectBookList(Book book) {
return bookMapper.selectBookList(book);
public List<Book> selectBookList(String name) {
return bookMapper.selectBookList(name);
}
@Override
public List<Book> selectBookListException(Book book) {
public List<Book> selectBookListException(String name) {
if(1 == 1) {
throw new ServiceException("测试异常处理");
}
......
package com.ruoyi.web;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.domain.Book;
import com.ruoyi.service.BookService;
import com.ruoyi.web.request.BookDeleteRequest;
import com.ruoyi.web.request.BookListRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
......@@ -16,45 +20,56 @@ import java.util.Arrays;
import java.util.List;
@Api("书籍管理")
@RestController
@RequestMapping("/book")
public class BookController extends BaseController {
@Autowired
private BookService bookService;
@ApiOperation("添加书籍")
@Trace
@Tags({@Tag(key = "param", value = "arg[0]"), @Tag(key = "result", value = "returnedObj")})
@RequestMapping(method = RequestMethod.POST, value = "/add")
public AjaxResult add(@Validated @RequestBody Book book) {
return toAjax(bookService.save(book));
public R add(@Validated @RequestBody Book book) {
bookService.save(book);
return R.ok();
}
@ApiOperation("修改书籍")
@Trace
@Tags({@Tag(key = "param", value = "arg[0]"), @Tag(key = "result", value = "returnedObj")})
@RequestMapping(method = RequestMethod.POST, value = "/edit")
public AjaxResult edit(@Validated @RequestBody Book book) {
return toAjax(bookService.updateById(book));
public R edit(@Validated @RequestBody Book book) {
bookService.updateById(book);
return R.ok();
}
@ApiOperation("查询书籍列表")
@Trace
@Tags({@Tag(key = "param", value = "arg[0]"), @Tag(key = "result", value = "returnedObj")})
@RequestMapping(method = RequestMethod.POST, value = "/list")
public TableDataInfo list(@Validated @RequestBody Book book) {
startPage();
List<Book> books = bookService.selectBookList(book);
public TableDataInfo list(@Validated @RequestBody BookListRequest request) {
startPage(request);
List<Book> books = bookService.selectBookList(request.getName());
return getDataTable(books);
}
@ApiOperation("删除书籍")
@Trace
@Tags({@Tag(key = "param", value = "arg[0]"), @Tag(key = "result", value = "returnedObj")})
@RequestMapping(method = RequestMethod.POST, value = "/remove")
public AjaxResult remove(@Validated @RequestBody Long[] userIds) {
return toAjax(bookService.removeBatchByIds(Arrays.asList(userIds)));
public R remove(@Validated @RequestBody BookDeleteRequest request) {
bookService.removeBatchByIds(Arrays.asList(request.getIds()));
return R.ok();
}
@Trace
@Tags({@Tag(key = "param", value = "arg[0]"), @Tag(key = "result", value = "returnedObj")})
@RequestMapping(method = RequestMethod.POST, value = "/listException")
public TableDataInfo listException(@Validated @RequestBody Book book) {
startPage();
List<Book> books = bookService.selectBookListException(book);
public TableDataInfo listException(@Validated @RequestBody BookListRequest request) {
startPage(request);
List<Book> books = bookService.selectBookListException(request.getName());
return getDataTable(books);
}
......
......@@ -8,8 +8,7 @@ import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.domain.ReviewSceneChangeTask;
import com.ruoyi.service.ReviewSceneChangeTaskService;
import com.ruoyi.web.request.ReviewSceneChangeTaskCreateRequest;
import com.ruoyi.web.request.ReviewSceneChangeTaskPassRequest;
import com.ruoyi.web.request.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.skywalking.apm.toolkit.trace.Tag;
......@@ -74,8 +73,8 @@ public class ReviewSceneChangeTaskController extends BaseController {
@Trace
@Tags({@Tag(key = "param", value = "arg[0]"), @Tag(key = "result", value = "returnedObj")})
@RequestMapping(method = RequestMethod.POST, value = "/findPending")
public TableDataInfo<ReviewSceneChangeTask> findPending() {
startPage();
public TableDataInfo<ReviewSceneChangeTask> findPending(@Validated @RequestBody ReviewSceneChangeTaskFindPendingRequest request) {
startPage(request);
return getDataTable(reviewSceneChangeTaskService.findPendingListByUserId(getUserId()));
}
......@@ -87,8 +86,8 @@ public class ReviewSceneChangeTaskController extends BaseController {
@Trace
@Tags({@Tag(key = "param", value = "arg[0]"), @Tag(key = "result", value = "returnedObj")})
@RequestMapping(method = RequestMethod.POST, value = "/findFinish")
public TableDataInfo<ReviewSceneChangeTask> findFinish() {
startPage();
public TableDataInfo<ReviewSceneChangeTask> findFinish(ReviewSceneChangeTaskFindFinishRequest request) {
startPage(request);
return getDataTable(reviewSceneChangeTaskService.findFinishListByUserId(getUserId()));
}
......@@ -100,8 +99,8 @@ public class ReviewSceneChangeTaskController extends BaseController {
@Trace
@Tags({@Tag(key = "param", value = "arg[0]"), @Tag(key = "result", value = "returnedObj")})
@RequestMapping(method = RequestMethod.POST, value = "/findCreate")
public TableDataInfo<ReviewSceneChangeTask> findCreate() {
startPage();
public TableDataInfo<ReviewSceneChangeTask> findCreate(ReviewSceneChangeTaskFindCreateRequest request) {
startPage(request);
return getDataTable(reviewSceneChangeTaskService.findCreateListByUserId(getUserId()));
}
......
package com.ruoyi.web.request;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel
public class BookDeleteRequest {
@ApiModelProperty("书籍id")
private Long[] ids;
}
package com.ruoyi.web.request;
import com.ruoyi.common.core.page.PageDomain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ApiModel
@Data
public class BookListRequest extends PageDomain {
@ApiModelProperty("数名")
private String name;
}
package com.ruoyi.web.request;
import com.ruoyi.common.core.page.PageDomain;
import io.swagger.annotations.ApiModel;
@ApiModel
public class ReviewSceneChangeTaskFindCreateRequest extends PageDomain {
}
package com.ruoyi.web.request;
import com.ruoyi.common.core.page.PageDomain;
import io.swagger.annotations.ApiModel;
@ApiModel
public class ReviewSceneChangeTaskFindFinishRequest extends PageDomain {
}
package com.ruoyi.web.request;
import com.ruoyi.common.core.page.PageDomain;
import io.swagger.annotations.ApiModel;
@ApiModel
public class ReviewSceneChangeTaskFindPendingRequest extends PageDomain {
}
......@@ -55,6 +55,18 @@ public class BaseController
PageUtils.startPage();
}
/**
* 设置请求分页数据
*/
protected void startPage(PageDomain pageDomain)
{
Integer pageNum = pageDomain.getPageNum();
Integer pageSize = pageDomain.getPageSize();
String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
Boolean reasonable = pageDomain.getReasonable();
PageHelper.startPage(pageNum, pageSize, orderBy).setReasonable(reasonable);
}
/**
* 设置请求排序数据
*/
......
package com.ruoyi.common.core.page;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
* 分页数据
*
* @author ruoyi
*/
@ApiModel
public class PageDomain
{
/** 当前记录起始索引 */
@ApiModelProperty("当前记录起始索引")
private Integer pageNum;
/** 每页显示记录数 */
@ApiModelProperty("每页显示记录数")
private Integer pageSize;
/** 排序列 */
@ApiModelProperty("排序列")
private String orderByColumn;
/** 排序的方向desc或者asc */
@ApiModelProperty("排序的方向desc或者asc")
private String isAsc = "asc";
/** 分页参数合理化 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment