mirror of
https://github.com/getrebuild/rebuild.git
synced 2025-02-26 07:15:19 +08:00
RecycleBinCleanerJob
This commit is contained in:
parent
9349a58fd1
commit
ee8b943565
5 changed files with 93 additions and 12 deletions
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
rebuild - Building your business-systems freely.
|
||||
Copyright (C) 2019 devezhao <zhaofang123@gmail.com>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.rebuild.server.business.recyclebin;
|
||||
|
||||
import cn.devezhao.commons.CalendarUtils;
|
||||
import cn.devezhao.persist4j.Entity;
|
||||
import com.rebuild.server.Application;
|
||||
import com.rebuild.server.business.series.SeriesZeroResetJob;
|
||||
import com.rebuild.server.helper.ConfigurableItem;
|
||||
import com.rebuild.server.helper.SysConfiguration;
|
||||
import com.rebuild.server.metadata.EntityHelper;
|
||||
import com.rebuild.server.metadata.MetadataHelper;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.springframework.scheduling.quartz.QuartzJobBean;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 回收站清理
|
||||
*
|
||||
* @author devezhao
|
||||
* @since 2019/8/21
|
||||
*/
|
||||
public class RecycleBinCleanerJob extends QuartzJobBean {
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(SeriesZeroResetJob.class);
|
||||
|
||||
@Override
|
||||
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
|
||||
int keepingDays = (int) SysConfiguration.getLong(ConfigurableItem.RecycleBinKeepingDays);
|
||||
LOG.info("RecycleBinCleanerJob running ... " + keepingDays);
|
||||
if (keepingDays > 9999) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity entity = MetadataHelper.getEntity(EntityHelper.RecycleBin);
|
||||
Date before = CalendarUtils.addDay(-keepingDays);
|
||||
|
||||
String delSql = String.format("delete from `%s` where `%s` < '%s 00:00:00'",
|
||||
entity.getPhysicalName(),
|
||||
entity.getField("deletedOn").getPhysicalName(),
|
||||
CalendarUtils.getUTCDateFormat().format(before));
|
||||
int del = Application.getSQLExecutor().execute(delSql, 120);
|
||||
LOG.warn("RecycleBin cleaned : " + del);
|
||||
}
|
||||
}
|
|
@ -18,19 +18,19 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
|
||||
package com.rebuild.server.business.series;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
import cn.devezhao.commons.CalendarUtils;
|
||||
import cn.devezhao.persist4j.Entity;
|
||||
import cn.devezhao.persist4j.Field;
|
||||
import com.rebuild.server.metadata.MetadataHelper;
|
||||
import com.rebuild.server.metadata.entity.DisplayType;
|
||||
import com.rebuild.server.metadata.entity.EasyMeta;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.springframework.scheduling.quartz.QuartzJobBean;
|
||||
|
||||
import com.rebuild.server.metadata.MetadataHelper;
|
||||
import com.rebuild.server.metadata.entity.DisplayType;
|
||||
import com.rebuild.server.metadata.entity.EasyMeta;
|
||||
|
||||
import cn.devezhao.commons.CalendarUtils;
|
||||
import cn.devezhao.persist4j.Entity;
|
||||
import cn.devezhao.persist4j.Field;
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* 数字系列归零。每日 00:00 执行
|
||||
|
@ -40,8 +40,12 @@ import cn.devezhao.persist4j.Field;
|
|||
*/
|
||||
public class SeriesZeroResetJob extends QuartzJobBean {
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(SeriesZeroResetJob.class);
|
||||
|
||||
@Override
|
||||
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
|
||||
LOG.info("SeriesZeroResetJob running ...");
|
||||
|
||||
boolean isFirstDayOfYear = false;
|
||||
boolean isFirstDayOfMonth = false;
|
||||
final Calendar now = CalendarUtils.getInstance();
|
||||
|
@ -59,10 +63,13 @@ public class SeriesZeroResetJob extends QuartzJobBean {
|
|||
String zeroFlag = easy.getFieldExtConfig().getString("seriesZero");
|
||||
if ("D".equalsIgnoreCase(zeroFlag)) {
|
||||
SeriesGeneratorFactory.zero(field);
|
||||
LOG.info("Zero field by [D] : " + field);
|
||||
} else if ("M".equalsIgnoreCase(zeroFlag) && isFirstDayOfMonth) {
|
||||
SeriesGeneratorFactory.zero(field);
|
||||
LOG.info("Zero field by [M] : " + field);
|
||||
} else if ("Y".equalsIgnoreCase(zeroFlag) && isFirstDayOfYear) {
|
||||
SeriesGeneratorFactory.zero(field);
|
||||
LOG.info("Zero field by [Y] : " + field);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ public enum ConfigurableItem {
|
|||
LiveWallpaper(true),
|
||||
|
||||
// 回收站数据保留天数(0为禁用回收站)
|
||||
RecycleBinKeepingDays(9999),
|
||||
RecycleBinKeepingDays(30),
|
||||
|
||||
;
|
||||
|
||||
|
|
|
@ -22,15 +22,25 @@
|
|||
</property>
|
||||
<property name="cronExpression" value="0 0 0 * * ?" />
|
||||
</bean>
|
||||
|
||||
<bean id="recycleBinCleanerJob" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
|
||||
<property name="jobDetail">
|
||||
<bean class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
|
||||
<property name="jobClass" value="com.rebuild.server.business.recyclebin.RecycleBinCleanerJob" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="cronExpression" value="0 5 0 * * ?" />
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
|
||||
<property name="autoStartup" value="true"/>
|
||||
<property name="startupDelay" value="60000"/>
|
||||
<property name="startupDelay" value="30000"/>
|
||||
<property name="configLocation" value="classpath:quartz.properties"/>
|
||||
<property name="triggers">
|
||||
<list>
|
||||
<ref bean="taskExecutors" />
|
||||
<ref bean="seriesZeroResetJob" />
|
||||
<ref bean="recycleBinCleanerJob" />
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
|
|
@ -40,7 +40,6 @@ td .badge {
|
|||
</div>
|
||||
<div class="col-12 col-md-6">
|
||||
<div class="dataTables_oper">
|
||||
<button class="btn btn-space btn-danger J_restore"><i class="icon zmdi zmdi-undo"></i> 恢复</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue