Search in sources :

Example 1 with StatProjectPO

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

the class StatProjectDaoTest method testBatchInsertAndQuery.

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

Example 2 with StatProjectPO

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

the class StatServiceImpl method statProjectAndSave.

private void statProjectAndSave(Date startTime, Date endTime) {
    List<StatProjectResult> projectResults = deployHistoryService.statProject(startTime, endTime);
    Map<Integer, StatProjectPO> projectStatMap = new HashMap<>();
    for (StatProjectResult spr : projectResults) {
        StatProjectPO statProject = projectStatMap.get(spr.getProjectId());
        if (statProject == null) {
            statProject = new StatProjectPO();
            statProject.setEnvId(spr.getEnvId());
            statProject.setStatDate(startTime);
            statProject.setProjectId(spr.getProjectId());
            projectStatMap.put(spr.getProjectId(), statProject);
        }
        statProject.setDeployTimes(statProject.getDeployTimes() + spr.getNum());
        if (spr.getResult() == DeployResult.SUCCESS.getValue()) {
            statProject.setSuccess(statProject.getSuccess() + spr.getNum());
        } else {
            // 其他都算做失败,包括部分成功的
            statProject.setFailure(statProject.getFailure() + spr.getNum());
        }
    }
    Collection<StatProjectPO> statProjects = projectStatMap.values();
    if (statProjects.isEmpty()) {
        logger.warn("没有发布数据");
        return;
    }
    statProjectDao.deleteByDate(startTime);
    statProjectDao.batchInsertOrUpdate(statProjects);
    saveStatAll(startTime, statProjects);
}
Also used : StatProjectPO(com.ibeiliao.deployment.admin.po.stat.StatProjectPO) StatProjectResult(com.ibeiliao.deployment.admin.vo.stat.StatProjectResult)

Example 3 with StatProjectPO

use of com.ibeiliao.deployment.admin.po.stat.StatProjectPO 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)

Example 4 with StatProjectPO

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

the class StatProjectDaoTest method create.

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

Aggregations

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