Search in sources :

Example 1 with ShardingRealVO

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());
    }
}
Also used : PaginationModel(org.sagacity.sqltoy.model.PaginationModel) ShardingRealVO(sqltoy.showcase.system.vo.ShardingRealVO) ShardingHisVO(sqltoy.showcase.system.vo.ShardingHisVO) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) BigDecimal(java.math.BigDecimal) Date(java.util.Date) Test(org.junit.Test)

Aggregations

BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 Test (org.junit.Test)1 PaginationModel (org.sagacity.sqltoy.model.PaginationModel)1 ShardingHisVO (sqltoy.showcase.system.vo.ShardingHisVO)1 ShardingRealVO (sqltoy.showcase.system.vo.ShardingRealVO)1