New file |
| | |
| | | package com.yc.open.init.shcedule; |
| | | |
| | | import com.yc.entity.DataSourceEntity; |
| | | import com.yc.factory.FactoryBean; |
| | | import com.yc.multiData.SpObserver; |
| | | import com.yc.service.BaseService; |
| | | |
| | | /** |
| | | * 删除系统日志表中的记录 |
| | | */ |
| | | public class DeleteSystemLogSchedule extends BaseSchedule implements Runnable { |
| | | |
| | | public DeleteSystemLogSchedule(DataSourceEntity dataSourceEntity) { |
| | | super(dataSourceEntity); |
| | | } |
| | | |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | if (Thread.interrupted()) { |
| | | throw new InterruptedException(); |
| | | } |
| | | String dbid = dataSourceEntity.getDbId() + ""; |
| | | log.info(dataSourceEntity.getSystemDescribe() + "-开始执行删除系统日志表中的记录"); |
| | | SpObserver.setDBtoInstance("_" + dbid); |
| | | BaseService baseService = (BaseService) FactoryBean.getBean("BaseService"); |
| | | String sql="--慢查询日志,保留30天\n" + |
| | | " delete a from _sys_InquireTableLog a where InsertDate < DATEADD(day,-30,getdate())\n" + |
| | | " \n" + |
| | | " --回收站,保留30天\n" + |
| | | " delete a from _Sys_SaveRecSQLForDeleted a \n" + |
| | | " where exists(select 1 from _Sys_SaveRecForDeleted as b where a.DocCode = b.DocCode and b.EnterDate < DATEADD(day,-30,getdate())) \n" + |
| | | " --回收站,保留30天\n" + |
| | | " delete a from _Sys_SaveRecItemForDeleted a\n" + |
| | | " where exists(select 1 from _Sys_SaveRecForDeleted as b where a.DocCode = b.DocCode and b.EnterDate < DATEADD(day,-30,getdate())) \n" + |
| | | " --回收站,保留30天\n" + |
| | | " delete a from _Sys_SaveRecForDeleted a where a.EnterDate < DATEADD(day,-30,getdate())\n" + |
| | | " \n" + |
| | | " --库存异动日志表,保留30天\n" + |
| | | " delete a from t140902Log a where a.logtime < DATEADD(day,-30,getdate())\n" + |
| | | " \n" + |
| | | " --最近访问,保留30天\n" + |
| | | " delete a from _sys_RecentAccessFormid a where a.lasttime < DATEADD(day,-30,getdate())\n" + |
| | | " \n" + |
| | | " --打印日志,保留30天\n" + |
| | | " delete a from _sysprintlog a where a.printdate < DATEADD(day,-30,getdate())\n" + |
| | | " \n" + |
| | | " --登录日志,保留60天\n" + |
| | | " delete a from _sysloginlog a where a.intime < DATEADD(day,-60,getdate())\n" + |
| | | " \n" + |
| | | " --系统错误日志,保留60天\n" + |
| | | " delete a from _sysErrorLog a where a.recordingtime < DATEADD(day,-60,getdate())\n" + |
| | | " \n" + |
| | | " --附件删除日志,保留60天\n" + |
| | | " delete a from _sys_AttachmentLog a where a.downloadtime < DATEADD(day,-60,getdate()) "; |
| | | baseService.getSimpleJdbcTemplate().execute(sql); |
| | | log.info(dataSourceEntity.getSystemDescribe() + "-完成删除系统日志表中的记录"); |
| | | } catch (InterruptedException ex) { |
| | | log.info(dataSourceEntity.getSystemID() + "删除系统日志表中的记录被终止"); |
| | | } catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | | log.error(dataSourceEntity.getSystemDescribe() + ":" + ex.getMessage()); |
| | | } finally { |
| | | SpObserver.setDBtoInstance(); |
| | | } |
| | | } |
| | | } |