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;
}
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());
}
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());
}
Aggregations