use of sqltoy.showcase.system.vo.ShardingRealVO in project sagacity-sqltoy by chenrenfei.
the class SeniorQueryServiceTest method testFindSharding.
/**
* 分库分表sharding
*
* @throws Exception
*/
@Test
public void testFindSharding() throws Exception {
List<ShardingRealVO> realVOs = new ArrayList<ShardingRealVO>();
for (int i = 0; i < 100; i++) {
ShardingRealVO realVO = new ShardingRealVO();
realVO.setId(new BigDecimal(i));
realVO.setComments("real" + i);
realVO.setStaffId("S" + CommonUtils.getRandomNum(100));
realVO.setPostType("POST_MASTER");
realVO.setCreateTime(DateUtil.addDay(new Date(), -CommonUtils.getRandomNum(15)));
realVOs.add(realVO);
}
sqlToyCRUDService.saveOrUpdateAll(realVOs);
List<ShardingHisVO> hisVOs = new ArrayList<ShardingHisVO>();
for (int i = 101; i < 500; i++) {
ShardingHisVO hisVO = new ShardingHisVO();
hisVO.setId(new BigDecimal(i));
hisVO.setComments("real" + i);
hisVO.setStaffId("S" + CommonUtils.getRandomNum(100));
hisVO.setPostType("POST_MASTER");
hisVO.setCreateTime(DateUtil.addDay(new Date(), -CommonUtils.getRandomNum(15, 100)));
hisVOs.add(hisVO);
}
sqlToyCRUDService.saveOrUpdateAll(hisVOs);
PaginationModel pageModel = new PaginationModel();
// 14天前,则查询历史表
// Date beginTime = DateUtil.addDay(new Date(), -30);
// Date endTime = DateUtil.addDay(new Date(), -14);
// 14天以内,则查询实时表
Date beginTime = DateUtil.addDay(new Date(), -13);
Date endTime = DateUtil.addDay(new Date(), -1);
PaginationModel results = seniorQueryService.findSharding(pageModel, new String[] { "beginTime", "endTime" }, new Object[] { beginTime, endTime }, ShardingRealVO.class);
for (ShardingRealVO sharding : (List<ShardingRealVO>) results.getRows()) {
System.out.println("staffId=" + sharding.getStaffId() + ",createTime=" + sharding.getCreateTime() + ";comments=" + sharding.getComments());
}
}
Aggregations