Search in sources :

Example 1 with StatAllPO

use of com.ibeiliao.deployment.admin.po.stat.StatAllPO in project Corgi by kevinYin.

the class StatAllDaoTest method create.

private StatAllPO create(Date date, int envId) {
    StatAllPO po = new StatAllPO();
    po.setStatDate(date);
    po.setDeployTimes(random.nextInt(1000000));
    po.setSuccess(1);
    po.setEnvId(envId);
    return po;
}
Also used : StatAllPO(com.ibeiliao.deployment.admin.po.stat.StatAllPO)

Example 2 with StatAllPO

use of com.ibeiliao.deployment.admin.po.stat.StatAllPO in project Corgi by kevinYin.

the class StatAllDaoTest method testBatchInsertAndQuery.

@Test
public void testBatchInsertAndQuery() {
    Date today = new Date();
    int env1Id = 1;
    List<StatAllPO> list = new ArrayList<>();
    list.add(create(today, env1Id));
    list.add(create(today, 2));
    list.add(create(today, 3));
    list.add(create(today, 4));
    statAllDao.batchInsertOrUpdate(list);
    Date startDate = DateUtil.currentStartDate();
    Date endDate = DateUtil.currentEndDate();
    List<StatAllPO> queryResult = statAllDao.queryByDate(env1Id, startDate, endDate);
    assertTrue(queryResult.size() == 1);
    // 检查 on duplicate
    list = new ArrayList<>();
    StatAllPO env1 = create(today, env1Id);
    list.add(env1);
    list.add(create(today, 2));
    statAllDao.batchInsertOrUpdate(list);
    queryResult = statAllDao.queryByDate(env1.getEnvId(), startDate, endDate);
    assertTrue(queryResult.size() == 1);
    StatAllPO tmp = queryResult.get(0);
    assertTrue(tmp.getDeployTimes() == env1.getDeployTimes());
}
Also used : StatAllPO(com.ibeiliao.deployment.admin.po.stat.StatAllPO) ArrayList(java.util.ArrayList) Date(java.util.Date) Test(org.junit.Test)

Example 3 with StatAllPO

use of com.ibeiliao.deployment.admin.po.stat.StatAllPO in project Corgi by kevinYin.

the class StatServiceImpl method saveStatAll.

private void saveStatAll(Date date, Collection<StatProjectPO> collection) {
    Map<Integer, StatAllPO> envStat = new HashMap<>();
    for (StatProjectPO sp : collection) {
        StatAllPO statAll = envStat.get(sp.getEnvId());
        if (statAll == null) {
            statAll = new StatAllPO();
            statAll.setEnvId(sp.getEnvId());
            statAll.setStatDate(sp.getStatDate());
            envStat.put(sp.getEnvId(), statAll);
        }
        statAll.setDeployTimes(statAll.getDeployTimes() + sp.getDeployTimes());
        statAll.setSuccess(statAll.getSuccess() + sp.getSuccess());
        statAll.setFailure(statAll.getFailure() + sp.getFailure());
    }
    statAllDao.deleteByDate(date);
    statAllDao.batchInsertOrUpdate(envStat.values());
}
Also used : StatAllPO(com.ibeiliao.deployment.admin.po.stat.StatAllPO) StatProjectPO(com.ibeiliao.deployment.admin.po.stat.StatProjectPO)

Aggregations

StatAllPO (com.ibeiliao.deployment.admin.po.stat.StatAllPO)3 StatProjectPO (com.ibeiliao.deployment.admin.po.stat.StatProjectPO)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Test (org.junit.Test)1