消息概要查询接口增加分页功能

This commit is contained in:
ajaxfan
2021-03-04 17:11:25 +08:00
parent d95abed510
commit bc3801ea3b
5 changed files with 83 additions and 21 deletions

View File

@ -1,18 +1,19 @@
package com.chinaunicom.mall.ebtp.extend.bizmessage.controller;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.chinaunicom.mall.ebtp.extend.bizmessage.dto.PageDTO;
import com.chinaunicom.mall.ebtp.extend.bizmessage.service.BizMessageConsumerService;
import com.chinaunicom.mall.ebtp.extend.bizmessage.vo.DescribeSiteMsgDetailVO;
import com.chinaunicom.mall.ebtp.extend.bizmessage.vo.DescribeSiteMsgVO;
@ -27,9 +28,9 @@ import io.swagger.annotations.ApiParam;
* @author ajaxfan
*/
@RestController
@Api(value= "消息查询服务", description = "消息查询服务")
@Api(value = "消息查询服务", description = "消息查询服务")
@RequestMapping("/v1/message/")
public class BizMessageQueryController {
public class BizMessageConsumerController {
private @Autowired BizMessageConsumerService service;
@ -41,15 +42,9 @@ public class BizMessageQueryController {
@ApiOperation("消息概要清单.")
@GetMapping("describeSiteMsg")
@ResponseStatus(code = HttpStatus.OK)
public List<DescribeSiteMsgVO> describeSiteMsg() {
// Dao -> Vo
return service.listOutline().stream().map(source -> {
DescribeSiteMsgVO vo = new DescribeSiteMsgVO();
vo.setMsgId(source.getId());
BeanUtils.copyProperties(source, vo);
return vo;
}).collect(Collectors.toList());
public IPage<DescribeSiteMsgVO> describeSiteMsg(
@ApiParam(value = "分页参数", required = false) @RequestBody(required = false) PageDTO page) {
return service.listOutline(page);
}
/**

View File

@ -0,0 +1,23 @@
package com.chinaunicom.mall.ebtp.extend.bizmessage.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 分页明细
*
* @author Ajaxfan
*/
@Data
public class PageDTO {
@ApiModelProperty(required = false, value = "当前页默认1")
private int current;
@ApiModelProperty(required = false, value = "页码默认1")
private int pageNo;
@ApiModelProperty(required = false, value = "单页数量默认15")
private int pageSize;
}

View File

@ -1,12 +1,13 @@
package com.chinaunicom.mall.ebtp.extend.bizmessage.service;
import java.util.List;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.chinaunicom.mall.ebtp.extend.bizmessage.dto.PageDTO;
import com.chinaunicom.mall.ebtp.extend.bizmessage.entity.BizMessage;
import com.chinaunicom.mall.ebtp.extend.bizmessage.vo.DescribeSiteMsgVO;
public interface BizMessageConsumerService {
List<BizMessage> listOutline();
IPage<DescribeSiteMsgVO> listOutline(PageDTO page);
BizMessage getDetailById(String id);

View File

@ -1,14 +1,20 @@
package com.chinaunicom.mall.ebtp.extend.bizmessage.service.impl;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chinaunicom.mall.ebtp.extend.bizmessage.dao.BizMessageMapper;
import com.chinaunicom.mall.ebtp.extend.bizmessage.dto.PageDTO;
import com.chinaunicom.mall.ebtp.extend.bizmessage.entity.BizMessage;
import com.chinaunicom.mall.ebtp.extend.bizmessage.service.BizMessageConsumerService;
import com.chinaunicom.mall.ebtp.extend.bizmessage.vo.DescribeSiteMsgVO;
/**
* 消息查询服务
@ -26,8 +32,25 @@ public class BizMessageConsumerServiceImpl implements BizMessageConsumerService
* @return
*/
@Override
public List<BizMessage> listOutline() {
return mapper.selectList(new QueryWrapper<BizMessage>().select("id", "title", "category", "createtime"));
public IPage<DescribeSiteMsgVO> listOutline(PageDTO page) {
page = createPageCondition(page);
IPage<BizMessage> pageEntity = mapper.selectPage(new Page<>(page.getPageNo(), page.getPageSize()),
new QueryWrapper<BizMessage>().select("id", "title", "category", "createtime")
.orderByDesc("createtime"));
// DAT -> VO 转换
IPage<DescribeSiteMsgVO> result = new Page<>();
BeanUtils.copyProperties(pageEntity, result, "records");
result.setRecords(pageEntity.getRecords().stream().map(source -> {
DescribeSiteMsgVO vo = new DescribeSiteMsgVO();
vo.setMsgId(source.getId());
BeanUtils.copyProperties(source, vo);
return vo;
}).collect(Collectors.toList()));
return result;
}
/**
@ -41,4 +64,19 @@ public class BizMessageConsumerServiceImpl implements BizMessageConsumerService
return mapper.selectById(id);
}
/**
* @param page
* @return
*/
private PageDTO createPageCondition(PageDTO page) {
page = Optional.ofNullable(page).map(p -> {
p.setCurrent(Math.max(1, p.getCurrent()));
p.setPageNo(Math.max(1, p.getPageNo()));
p.setPageSize(p.getPageSize() == 0 ? 15 : p.getPageSize());
return p;
}).orElseGet(PageDTO::new);
return page;
}
}

View File

@ -6,8 +6,13 @@ server:
seata:
service:
vgroup-mapping:
biz-service-ebtp-extend-service-group: default
biz-service-ebtp-extend-service-group: seata-server-jl
registry:
type: eureka
eureka:
serviceUrl: http://10.242.31.158:5001/eureka,http://10.242.31.158:5002/eureka,http://10.242.31.158:5003/eureka
# 对应 apollo 配置中心的应用名
app:
id: biz-service-ebtp-extend