消息概要查询接口增加分页功能
This commit is contained in:
@ -1,18 +1,19 @@
|
|||||||
package com.chinaunicom.mall.ebtp.extend.bizmessage.controller;
|
package com.chinaunicom.mall.ebtp.extend.bizmessage.controller;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
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.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
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.service.BizMessageConsumerService;
|
||||||
import com.chinaunicom.mall.ebtp.extend.bizmessage.vo.DescribeSiteMsgDetailVO;
|
import com.chinaunicom.mall.ebtp.extend.bizmessage.vo.DescribeSiteMsgDetailVO;
|
||||||
import com.chinaunicom.mall.ebtp.extend.bizmessage.vo.DescribeSiteMsgVO;
|
import com.chinaunicom.mall.ebtp.extend.bizmessage.vo.DescribeSiteMsgVO;
|
||||||
@ -27,9 +28,9 @@ import io.swagger.annotations.ApiParam;
|
|||||||
* @author ajaxfan
|
* @author ajaxfan
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@Api(value= "消息查询服务", description = "消息查询服务")
|
@Api(value = "消息查询服务", description = "消息查询服务")
|
||||||
@RequestMapping("/v1/message/")
|
@RequestMapping("/v1/message/")
|
||||||
public class BizMessageQueryController {
|
public class BizMessageConsumerController {
|
||||||
|
|
||||||
private @Autowired BizMessageConsumerService service;
|
private @Autowired BizMessageConsumerService service;
|
||||||
|
|
||||||
@ -41,15 +42,9 @@ public class BizMessageQueryController {
|
|||||||
@ApiOperation("消息概要清单.")
|
@ApiOperation("消息概要清单.")
|
||||||
@GetMapping("describeSiteMsg")
|
@GetMapping("describeSiteMsg")
|
||||||
@ResponseStatus(code = HttpStatus.OK)
|
@ResponseStatus(code = HttpStatus.OK)
|
||||||
public List<DescribeSiteMsgVO> describeSiteMsg() {
|
public IPage<DescribeSiteMsgVO> describeSiteMsg(
|
||||||
// Dao -> Vo
|
@ApiParam(value = "分页参数", required = false) @RequestBody(required = false) PageDTO page) {
|
||||||
return service.listOutline().stream().map(source -> {
|
return service.listOutline(page);
|
||||||
DescribeSiteMsgVO vo = new DescribeSiteMsgVO();
|
|
||||||
vo.setMsgId(source.getId());
|
|
||||||
BeanUtils.copyProperties(source, vo);
|
|
||||||
|
|
||||||
return vo;
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
@ -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;
|
||||||
|
|
||||||
|
}
|
@ -1,12 +1,13 @@
|
|||||||
package com.chinaunicom.mall.ebtp.extend.bizmessage.service;
|
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.entity.BizMessage;
|
||||||
|
import com.chinaunicom.mall.ebtp.extend.bizmessage.vo.DescribeSiteMsgVO;
|
||||||
|
|
||||||
public interface BizMessageConsumerService {
|
public interface BizMessageConsumerService {
|
||||||
|
|
||||||
List<BizMessage> listOutline();
|
IPage<DescribeSiteMsgVO> listOutline(PageDTO page);
|
||||||
|
|
||||||
BizMessage getDetailById(String id);
|
BizMessage getDetailById(String id);
|
||||||
|
|
||||||
|
@ -1,14 +1,20 @@
|
|||||||
package com.chinaunicom.mall.ebtp.extend.bizmessage.service.impl;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
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.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.entity.BizMessage;
|
||||||
import com.chinaunicom.mall.ebtp.extend.bizmessage.service.BizMessageConsumerService;
|
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
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<BizMessage> listOutline() {
|
public IPage<DescribeSiteMsgVO> listOutline(PageDTO page) {
|
||||||
return mapper.selectList(new QueryWrapper<BizMessage>().select("id", "title", "category", "createtime"));
|
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);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,13 @@ server:
|
|||||||
seata:
|
seata:
|
||||||
service:
|
service:
|
||||||
vgroup-mapping:
|
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 配置中心的应用名
|
# 对应 apollo 配置中心的应用名
|
||||||
app:
|
app:
|
||||||
id: biz-service-ebtp-extend
|
id: biz-service-ebtp-extend
|
||||||
|
Reference in New Issue
Block a user