<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
@ApiModel(“费用申请表”) @TableName(“marketing_expenses”) @Data public class MarketingExpensesPO { @TableId(type = IdType.AUTO) @ApiModelProperty(value = “ID”, dataType = “Long”) private Long id; @ApiModelProperty(value = “校区ID”, dataType = “Long”) private Long schoolId;
importcom.baomidou.mybatisplus.core.mapper.BaseMapper; public interface MarketingExpensesMapper extends BaseMapper{ }
import com.baomidou.mybatisplus.extension.service.IService; public interface MarketingExpensesService extends IService { PageUtil getMarketingExpenses(MarketingExpensesConditionQuery query); }
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.zhangxin.base.utils.PageUtil;
import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service(“MarketingExpensesService”) public class MarketingExpensesServiceImpl extends ServiceImpl<MarketingExpensesMapper,MarketingExpensesPO> implements MarketingExpensesService { @Resource private MetadataApi metadataApi; @Override public PageUtil getMarketingExpenses(MarketingExpensesConditionQuery query) {
List list = lambdaQuery().like(query.getActivityName() != null, MarketingExpensesPO::getActivityName, query.getActivityName()) .like(query.getActivityPeople() != null, MarketingExpensesPO::getActivityPeople, query.getActivityPeople()) .like(query.getSchoolId() != null, MarketingExpensesPO::getSchoolId, query.getSchoolId()).list(); List voList = new ArrayList<>(); if (list.size()>0){ for (int i = 0; i < list.size(); i++) { MarketingExpensesRespVO respVO = new MarketingExpensesRespVO(); MarketingExpensesPO marketingExpensesPO = list.get(i); BeanUtils.copyProperties(marketingExpensesPO,respVO);
Long schoolId = marketingExpensesPO.getSchoolId(); WebResult listSchool = metadataApi.getListSchool(); Object data = listSchool.getData(); List school = new ArrayList<>(); if (data instanceof ArrayList<?>) { for (Object o : (List<?>) data) { school.add(SchoolRespVO.class.cast(o)); } } for (int j = 0; j < school.size(); j++) { SchoolRespVO schoolRespVO = school.get(j); if (schoolId!=null&&schoolId.equals(schoolRespVO.getSchoolId())){ respVO.setSchoolName(schoolRespVO.getSchoolName());
}
}
voList.add(respVO);
}
}
Page page = lambdaQuery().page(query.getPage()).setRecords(voList);
return new PageUtil<>(page); } }
@Data @NoArgsConstructor @ApiModel(“分页返回信息工具类”) public class PageUtil implements Serializable{
private static final long serialVersionUID = 8235500712990915980L;
/**
* 总记录数
*/
@ApiModelProperty(value = "总记录数")
private Integer totalCount;
/**
* 每页记录数
*/
@ApiModelProperty(value = "每页查询数量")
private Integer pageSize;
/**
* 总页数
*/
@ApiModelProperty(value = "总页数")
private Integer totalPage;
/**
* 当前页码
*/
@ApiModelProperty(value = "当前页码")
private Integer currPage;
/**
* 列表数据
*/
@ApiModelProperty(value = "数据列表")
private List<T> list;
/**
* 分页
*
* @param list 列表数据
* @param totalCount 总记录数
* @param pageSize 每页记录数
* @param currPage 当前页数
*/
public PageUtil(List<T> list, int totalCount, int pageSize, int currPage) {
this.list = list;
this.totalCount = totalCount;
this.pageSize = pageSize;
this.currPage = currPage;
this.totalPage = (int) Math.ceil((double)totalCount/pageSize);
}
/**
* 分页参数格式化
*
* @param page 分页对象
*/
public PageUtil(IPage<T> page) {
this.list = Optional.ofNullable(page.getRecords()).orElse(Collections.emptyList());
this.totalCount = (int) page.getTotal();
this.pageSize = (int) page.getSize();
this.currPage = (int) page.getCurrent();
this.totalPage = (int) page.getPages();
}
}
|