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