|
|
@@ -1,10 +1,16 @@
|
|
|
package com.uas.platform.b2b.task;
|
|
|
|
|
|
+import com.uas.platform.b2b.core.util.DateFormatUtils;
|
|
|
+import com.uas.platform.b2b.core.util.DateUtils;
|
|
|
+import com.uas.platform.b2b.dao.CommonDao;
|
|
|
+import com.uas.platform.b2b.dao.CommunalLogDao;
|
|
|
+import com.uas.platform.b2b.model.CommunalLog;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 系统日志任务
|
|
|
@@ -17,25 +23,62 @@ import org.springframework.stereotype.Component;
|
|
|
public class ErrorLogTask {
|
|
|
|
|
|
@Autowired
|
|
|
- private JdbcTemplate jdbcTemplate;
|
|
|
+ private CommonDao commonDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CommunalLogDao communalLogDao;
|
|
|
|
|
|
/**
|
|
|
* 每天凌晨0点到2点开始执行
|
|
|
*/
|
|
|
@Scheduled(cron = "0 0/5 0,1,2 * * ? ")
|
|
|
public void deleteLogs() {
|
|
|
+ int increase = -2;
|
|
|
+ // 两天前时间
|
|
|
+ Date date = DateUtils.addDay(new Date(), increase);
|
|
|
+
|
|
|
+ // 整点格式
|
|
|
+ String dateString = DateFormatUtils.WEE_HOURS_FORMAT.format(date);
|
|
|
+
|
|
|
// 先查询最大id
|
|
|
- Long maxId = jdbcTemplate.queryForObject("select max(log_id) from log$error where date_format(log_date, '%Y-%m-%d') <= date_format(date_add(now(), interval -2 day), '%Y-%m-%d')", Long.class);
|
|
|
-
|
|
|
- // 删除日志明细
|
|
|
- jdbcTemplate.execute("delete from log$error$detail where log_logid in (select log_id from log$error " +
|
|
|
- "where log_logid <= " + maxId + " limit 10000");
|
|
|
- // 删除日志主表信息
|
|
|
- jdbcTemplate.execute("delete from log$error " +
|
|
|
- "where log_id <= " + maxId + " limit 10000");
|
|
|
- // 删除单据记录
|
|
|
- jdbcTemplate.execute("delete from erp$orders where date_format(or_date, '%Y-%m-%d') <= date_format(date_add(now(), interval -2 day), '%Y-%m-%d') limit 10000");
|
|
|
- // 删除物料记录
|
|
|
- jdbcTemplate.execute("delete from erp$products where date_format(pr_date, '%Y-%m-%d') <= date_format(date_add(now(), interval -2 day), '%Y-%m-%d') limit 10000");
|
|
|
+ Long maxId = commonDao.queryForObject("select max(log_id) from log$error where log_date <= ?", Long.class, dateString);
|
|
|
+
|
|
|
+ if (null != maxId) {
|
|
|
+ // 删除日志明细
|
|
|
+ commonDao.getJdbcTemplate().execute("delete from log$error$detail where log_logid <= " + maxId + " limit 10000");
|
|
|
+
|
|
|
+ // 删除日志主表信息
|
|
|
+ commonDao.getJdbcTemplate().execute("delete from log$error " + "where log_id <= " + maxId + " limit 10000");
|
|
|
+
|
|
|
+ CommunalLog log = new CommunalLog();
|
|
|
+ log.setTitle("删除B2B异常日志");
|
|
|
+ log.setMessage("最大id" + maxId);
|
|
|
+ log.setTime(System.currentTimeMillis());
|
|
|
+ communalLogDao.save(log);
|
|
|
+ }
|
|
|
+
|
|
|
+ Long maxOrderId = commonDao.queryForObject("select max(or_id) from erp$orders where or_date <= ?", Long.class, dateString);
|
|
|
+
|
|
|
+ if (null != maxOrderId) {
|
|
|
+ // 删除单据记录
|
|
|
+ commonDao.getJdbcTemplate().execute("delete from erp$orders where or_id <= " + maxOrderId + " limit 10000");
|
|
|
+ CommunalLog log = new CommunalLog();
|
|
|
+ log.setTitle("删除ERP不存在单据记录");
|
|
|
+ log.setMessage("最大id" + maxOrderId);
|
|
|
+ log.setTime(System.currentTimeMillis());
|
|
|
+ communalLogDao.save(log);
|
|
|
+ }
|
|
|
+
|
|
|
+ Long maxProductId = commonDao.queryForObject("select max(pr_id) from erp$products where pr_date <= ?", Long.class, dateString);
|
|
|
+
|
|
|
+ if (null != maxProductId) {
|
|
|
+ // 删除物料记录
|
|
|
+ commonDao.getJdbcTemplate().execute("delete from erp$products where pr_id <= " + maxProductId + " limit 10000");
|
|
|
+ CommunalLog log = new CommunalLog();
|
|
|
+ log.setTitle("删除ERP不存在物料记录");
|
|
|
+ log.setMessage("最大id" + maxProductId);
|
|
|
+ log.setTime(System.currentTimeMillis());
|
|
|
+ communalLogDao.save(log);
|
|
|
+ }
|
|
|
}
|
|
|
}
|