Search in sources :

Example 1 with Order

use of cn.hutool.db.sql.Order in project hutool by looly.

the class PageTest method addOrderTest.

@Test
public void addOrderTest() {
    Page page = new Page();
    page.addOrder(new Order("aaa"));
    Assert.assertEquals(page.getOrders().length, 1);
    page.addOrder(new Order("aaa"));
    Assert.assertEquals(page.getOrders().length, 2);
}
Also used : Order(cn.hutool.db.sql.Order) Test(org.junit.Test)

Example 2 with Order

use of cn.hutool.db.sql.Order in project Jpom by dromara.

the class BaseDbService method autoLoopClear.

/**
 * 自动清理数据接口
 *
 * @param timeClo  时间字段
 * @param maxCount 最大数量
 * @param consumer 查询出超过范围的时间回调
 */
protected void autoLoopClear(String timeClo, int maxCount, Consumer<Entity> whereCon, Consumer<T> consumer) {
    if (maxCount <= 0) {
        return;
    }
    ThreadUtil.execute(() -> {
        Entity entity = Entity.create(super.getTableName());
        long timeValue = this.getLastTimeValue(timeClo, maxCount, whereCon);
        if (timeValue <= 0) {
            return;
        }
        if (whereCon != null) {
            // 条件
            whereCon.accept(entity);
        }
        entity.set(timeClo, "< " + timeValue);
        while (true) {
            Page page = new Page(1, 50);
            page.addOrder(new Order(timeClo, Direction.DESC));
            PageResultDto<T> pageResult = super.listPage(entity, page);
            if (pageResult.isEmpty()) {
                return;
            }
            pageResult.each(consumer);
            List<String> ids = pageResult.getResult().stream().map(BaseDbModel::getId).collect(Collectors.toList());
            super.delByKey(ids, null);
        }
    });
}
Also used : Order(cn.hutool.db.sql.Order) Entity(cn.hutool.db.Entity) Page(cn.hutool.db.Page)

Example 3 with Order

use of cn.hutool.db.sql.Order in project hutool by dromara.

the class PageTest method addOrderTest.

@Test
public void addOrderTest() {
    Page page = new Page();
    page.addOrder(new Order("aaa"));
    Assert.assertEquals(page.getOrders().length, 1);
    page.addOrder(new Order("aaa"));
    Assert.assertEquals(page.getOrders().length, 2);
}
Also used : Order(cn.hutool.db.sql.Order) Test(org.junit.Test)

Example 4 with Order

use of cn.hutool.db.sql.Order in project Jpom by dromara.

the class NodeWelcomeController method getList.

private List<SystemMonitorLog> getList() {
    NodeModel node = getNode();
    String startDateStr = getParameter("time[0]");
    String endDateStr = getParameter("time[1]");
    if (StrUtil.hasEmpty(startDateStr, endDateStr)) {
        SystemMonitorLog systemMonitorLog = new SystemMonitorLog();
        systemMonitorLog.setNodeId(node.getId());
        return dbSystemMonitorLogService.queryList(systemMonitorLog, 500, new Order("monitorTime", Direction.DESC));
    }
    // 处理时间
    DateTime startDate = DateUtil.parse(startDateStr);
    long startTime = startDate.getTime();
    DateTime endDate = DateUtil.parse(endDateStr);
    if (startDate.equals(endDate)) {
        // 时间相等
        endDate = DateUtil.endOfDay(endDate);
    }
    long endTime = endDate.getTime();
    // 开启了节点信息采集
    Page pageObj = new Page(1, 5000);
    pageObj.addOrder(new Order("monitorTime", Direction.DESC));
    Entity entity = Entity.create();
    entity.set("nodeId", node.getId());
    entity.set(" MONITORTIME", ">= " + startTime);
    entity.set("MONITORTIME", "<= " + endTime);
    return dbSystemMonitorLogService.listPageOnlyResult(entity, pageObj);
}
Also used : Order(cn.hutool.db.sql.Order) Entity(cn.hutool.db.Entity) NodeModel(io.jpom.model.data.NodeModel) SystemMonitorLog(io.jpom.model.log.SystemMonitorLog) Page(cn.hutool.db.Page) DateTime(cn.hutool.core.date.DateTime)

Example 5 with Order

use of cn.hutool.db.sql.Order in project Jpom by dromara.

the class BackupInfoService method createAutoBackup.

/**
 * 创建自动备份数据
 */
private void createAutoBackup() {
    // 自动备份
    Integer autoBackupIntervalDay = dbExtConfig.getAutoBackupIntervalDay();
    if (autoBackupIntervalDay != null && autoBackupIntervalDay > 0) {
        BackupInfoModel backupInfoModel = new BackupInfoModel();
        backupInfoModel.setBackupType(3);
        List<BackupInfoModel> infoModels = super.queryList(backupInfoModel, 1, new Order("createTimeMillis", Direction.DESC));
        BackupInfoModel first = CollUtil.getFirst(infoModels);
        if (first != null) {
            Long createTimeMillis = first.getCreateTimeMillis();
            long interval = SystemClock.now() - createTimeMillis;
            if (interval < TimeUnit.DAYS.toMillis(autoBackupIntervalDay)) {
                return;
            }
        }
        this.autoBackup();
    }
}
Also used : BackupInfoModel(io.jpom.model.data.BackupInfoModel) Order(cn.hutool.db.sql.Order)

Aggregations

Order (cn.hutool.db.sql.Order)9 Entity (cn.hutool.db.Entity)4 Page (cn.hutool.db.Page)4 DateTime (cn.hutool.core.date.DateTime)2 Test (org.junit.Test)2 BackupInfoModel (io.jpom.model.data.BackupInfoModel)1 NodeModel (io.jpom.model.data.NodeModel)1 MonitorNotifyLog (io.jpom.model.log.MonitorNotifyLog)1 SystemMonitorLog (io.jpom.model.log.SystemMonitorLog)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1