SpringBoot+React养老院管理系统 附带详细运行指导视频
@Override
public ResponseDTO<PageDTO<CheckDTO>> getCheckList(PageDTO<CheckDTO> pageDTO) {
CheckExample checkExample = new CheckExample();
// 不知道当前页多少,默认为第一页
if(pageDTO.getPage() == null){
pageDTO.setPage(1);
}
// 不知道每页多少条记录,默认为每页10条记录
if(pageDTO.getSize() == null){
pageDTO.setSize(10);
}
CheckExample.Criteria c1 = checkExample.createCriteria();
if(pageDTO.getParam() != null) {
CheckDTO checkDTO = pageDTO.getParam();
if(!CommonUtil.isEmpty(checkDTO.getUsername())) {
c1.andUsernameLike("%" + checkDTO.getUsername() + "%");
}
if(!CommonUtil.isEmpty(checkDTO.getPhone())) {
c1.andPhoneLike("%" + checkDTO.getPhone() + "%");
}
if(!CommonUtil.isEmpty(checkDTO.getUserId())) {
c1.andUserIdEqualTo(checkDTO.getUserId());
}
if(checkDTO.getState() != null && checkDTO.getState() != 0) {
c1.andStateEqualTo(checkDTO.getState());
}
}
checkExample.setOrderByClause("start_date desc, id desc");
PageHelper.startPage(pageDTO.getPage(), pageDTO.getSize());
// 分页查出入住数据
List<Check> checkList = checkMapper.selectByExample(checkExample);
PageInfo<Check> pageInfo = new PageInfo<>(checkList);
// 获取数据的总数
pageDTO.setTotal(pageInfo.getTotal());
// 将domain类型数据 转成 DTO类型数据
List<CheckDTO> checkDTOList = CopyUtil.copyList(checkList, CheckDTO.class);
for(CheckDTO checkDTO : checkDTOList) {
User user = userMapper.selectByPrimaryKey(checkDTO.getUserId());
checkDTO.setUserDTO(CopyUtil.copy(Optional.ofNullable(user).orElse(new User()), UserDTO.class));
PackageItemExample packageItemExample = new PackageItemExample();
packageItemExample.createCriteria().andCheckIdEqualTo(checkDTO.getId());
List<PackageItem> packageItemList = packageItemMapper.selectByExample(packageItemExample);
checkDTO.setPackageItemDTOList(CopyUtil.copyList(packageItemList, PackageItemDTO.class));
Building building = buildingMapper.selectByPrimaryKey(checkDTO.getBuildingId());
checkDTO.setBuildingDTO(CopyUtil.copy(Optional.ofNullable(building).orElse(new Building()), BuildingDTO.class));
// 更新入住数据的状态
checkDTO.setState(updateCheckState(checkDTO));
}
pageDTO.setList(checkDTOList);
return ResponseDTO.success(pageDTO);
}