diff --git a/src/main/java/com/glxp/api/dao/monitor/SysLogininforMapper.java b/src/main/java/com/glxp/api/dao/monitor/SysLogininforMapper.java
index 60ea5db4..d30a5345 100644
--- a/src/main/java/com/glxp/api/dao/monitor/SysLogininforMapper.java
+++ b/src/main/java/com/glxp/api/dao/monitor/SysLogininforMapper.java
@@ -27,5 +27,10 @@ public interface SysLogininforMapper {
*/
void insertLogininfor(SysLogininfor logininfor);
-
+ /**
+ * 根据此日期之前的数据(包括当前时间)
+ *
+ * @param date 日期
+ */
+ void deleteByDate(@Param("date") String date);
}
diff --git a/src/main/java/com/glxp/api/dao/monitor/SysOperLogMapper.java b/src/main/java/com/glxp/api/dao/monitor/SysOperLogMapper.java
index 4d6db93a..167f92e3 100644
--- a/src/main/java/com/glxp/api/dao/monitor/SysOperLogMapper.java
+++ b/src/main/java/com/glxp/api/dao/monitor/SysOperLogMapper.java
@@ -25,4 +25,5 @@ public interface SysOperLogMapper {
SysOperLog selectById(Long id);
+ void deleteByDate(@Param("date") String date);
}
diff --git a/src/main/java/com/glxp/api/dao/sync/BasicDownloadDao.java b/src/main/java/com/glxp/api/dao/sync/BasicDownloadDao.java
index 6b50ba4a..2e0184ff 100644
--- a/src/main/java/com/glxp/api/dao/sync/BasicDownloadDao.java
+++ b/src/main/java/com/glxp/api/dao/sync/BasicDownloadDao.java
@@ -22,4 +22,5 @@ public interface BasicDownloadDao {
boolean updateDownloadStatus(BasicDownloadStatusEntity basicDownloadStatusEntity);
+ void deleteByDate(@Param("date") String date);
}
diff --git a/src/main/java/com/glxp/api/dao/sync/BasicExportDao.java b/src/main/java/com/glxp/api/dao/sync/BasicExportDao.java
index 76c6830d..0ff63900 100644
--- a/src/main/java/com/glxp/api/dao/sync/BasicExportDao.java
+++ b/src/main/java/com/glxp/api/dao/sync/BasicExportDao.java
@@ -21,4 +21,5 @@ public interface BasicExportDao {
boolean updateExportStatus(BasicExportStatusEntity warehouseEntity);
+ void deleteByDate(@Param("date") String date);
}
diff --git a/src/main/java/com/glxp/api/dao/thrsys/ThrCorpExportLogDao.java b/src/main/java/com/glxp/api/dao/thrsys/ThrCorpExportLogDao.java
index e7d7c62a..ed843553 100644
--- a/src/main/java/com/glxp/api/dao/thrsys/ThrCorpExportLogDao.java
+++ b/src/main/java/com/glxp/api/dao/thrsys/ThrCorpExportLogDao.java
@@ -23,4 +23,11 @@ public interface ThrCorpExportLogDao {
boolean deleteByTime();
String selectFilePathById(@Param("id") String id);
+
+ /**
+ * 根据时间删除日志数据
+ *
+ * @param date 日期
+ */
+ void deleteByDate(@Param("date") String date);
}
diff --git a/src/main/java/com/glxp/api/dao/thrsys/ThrCorpImportLogDao.java b/src/main/java/com/glxp/api/dao/thrsys/ThrCorpImportLogDao.java
index a1195980..1f8b6771 100644
--- a/src/main/java/com/glxp/api/dao/thrsys/ThrCorpImportLogDao.java
+++ b/src/main/java/com/glxp/api/dao/thrsys/ThrCorpImportLogDao.java
@@ -3,7 +3,6 @@ package com.glxp.api.dao.thrsys;
import com.glxp.api.entity.thrsys.ThrCorpImportLogEntity;
import com.glxp.api.req.thrsys.FilterThrCorpImportLogRequest;
-import com.glxp.api.req.thrsys.FilterThrProductsImportLogRequest;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@@ -22,4 +21,5 @@ public interface ThrCorpImportLogDao {
boolean deleteByTime();
+ void deleteByDate(@Param("date") String date);
}
diff --git a/src/main/java/com/glxp/api/dao/thrsys/ThrInvProductsExportLogDao.java b/src/main/java/com/glxp/api/dao/thrsys/ThrInvProductsExportLogDao.java
index e7442296..b8699daf 100644
--- a/src/main/java/com/glxp/api/dao/thrsys/ThrInvProductsExportLogDao.java
+++ b/src/main/java/com/glxp/api/dao/thrsys/ThrInvProductsExportLogDao.java
@@ -17,4 +17,6 @@ public interface ThrInvProductsExportLogDao {
boolean updateThrInvProductsExportLog(ThrInvProductsExportLogEntity thrInvProductsExportLogEntity);
boolean deleteById(@Param("id") String id);
+
+ void deleteByDate(@Param("date") String date);
}
diff --git a/src/main/java/com/glxp/api/dao/thrsys/ThrInvProductsImportLogDao.java b/src/main/java/com/glxp/api/dao/thrsys/ThrInvProductsImportLogDao.java
index 4b29dbb9..294a43a2 100644
--- a/src/main/java/com/glxp/api/dao/thrsys/ThrInvProductsImportLogDao.java
+++ b/src/main/java/com/glxp/api/dao/thrsys/ThrInvProductsImportLogDao.java
@@ -19,4 +19,5 @@ public interface ThrInvProductsImportLogDao {
boolean deleteById(@Param("id") String id);
+ void deleteByDate(@Param("date") String date);
}
diff --git a/src/main/java/com/glxp/api/dao/thrsys/ThrOrderExportLogDao.java b/src/main/java/com/glxp/api/dao/thrsys/ThrOrderExportLogDao.java
index 4fa30dea..ad879790 100644
--- a/src/main/java/com/glxp/api/dao/thrsys/ThrOrderExportLogDao.java
+++ b/src/main/java/com/glxp/api/dao/thrsys/ThrOrderExportLogDao.java
@@ -20,4 +20,6 @@ public interface ThrOrderExportLogDao {
boolean deleteById(@Param("id") String id);
boolean deleteByTime();
+
+ void deleteByDate(@Param("date") String date);
}
diff --git a/src/main/java/com/glxp/api/dao/thrsys/ThrOrderImportLogDao.java b/src/main/java/com/glxp/api/dao/thrsys/ThrOrderImportLogDao.java
index 4ee02506..7fcaab03 100644
--- a/src/main/java/com/glxp/api/dao/thrsys/ThrOrderImportLogDao.java
+++ b/src/main/java/com/glxp/api/dao/thrsys/ThrOrderImportLogDao.java
@@ -21,4 +21,6 @@ public interface ThrOrderImportLogDao {
boolean deleteByTime();
+ void deleteByDate(@Param("date") String date);
+
}
diff --git a/src/main/java/com/glxp/api/dao/thrsys/ThrProductsExportLogDao.java b/src/main/java/com/glxp/api/dao/thrsys/ThrProductsExportLogDao.java
index 047061e5..f419ed63 100644
--- a/src/main/java/com/glxp/api/dao/thrsys/ThrProductsExportLogDao.java
+++ b/src/main/java/com/glxp/api/dao/thrsys/ThrProductsExportLogDao.java
@@ -28,4 +28,6 @@ public interface ThrProductsExportLogDao {
String selectFilePathById(@Param("id") String id);
boolean deleteByTime();
+
+ void deleteByDate(@Param("date") String date);
}
diff --git a/src/main/java/com/glxp/api/dao/thrsys/ThrProductsImportLogDao.java b/src/main/java/com/glxp/api/dao/thrsys/ThrProductsImportLogDao.java
index 45ea90e8..0ed66f76 100644
--- a/src/main/java/com/glxp/api/dao/thrsys/ThrProductsImportLogDao.java
+++ b/src/main/java/com/glxp/api/dao/thrsys/ThrProductsImportLogDao.java
@@ -19,4 +19,6 @@ public interface ThrProductsImportLogDao {
boolean deleteById(@Param("id") String id);
boolean deleteByTime();
+
+ void deleteByDate(@Param("date") String date);
}
diff --git a/src/main/java/com/glxp/api/task/CleanLogTask.java b/src/main/java/com/glxp/api/task/CleanLogTask.java
new file mode 100644
index 00000000..68d5eb57
--- /dev/null
+++ b/src/main/java/com/glxp/api/task/CleanLogTask.java
@@ -0,0 +1,154 @@
+package com.glxp.api.task;
+
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.StrUtil;
+import com.glxp.api.dao.monitor.SysLogininforMapper;
+import com.glxp.api.dao.monitor.SysOperLogMapper;
+import com.glxp.api.dao.schedule.ScheduledDao;
+import com.glxp.api.dao.schedule.SystemParamConfigDao;
+import com.glxp.api.dao.sync.BasicDownloadDao;
+import com.glxp.api.dao.sync.BasicExportDao;
+import com.glxp.api.dao.thrsys.*;
+import com.glxp.api.entity.system.ScheduledEntity;
+import com.glxp.api.req.system.ScheduledRequest;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.scheduling.annotation.SchedulingConfigurer;
+import org.springframework.scheduling.config.ScheduledTaskRegistrar;
+import org.springframework.scheduling.support.CronTrigger;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.util.Date;
+
+/**
+ * 清理日志定时任务
+ */
+@Slf4j
+@Component
+@Transactional(rollbackFor = Exception.class)
+public class CleanLogTask implements SchedulingConfigurer {
+
+ @Resource
+ private ScheduledDao scheduledDao;
+ @Resource
+ private SystemParamConfigDao systemParamConfigDao;
+ @Resource
+ private SysOperLogMapper sysOperLogMapper;
+ @Resource
+ private SysLogininforMapper sysLogininforMapper;
+ @Resource
+ private ThrCorpExportLogDao thrCorpExportLogDao;
+ @Resource
+ private ThrCorpImportLogDao thrCorpImportLogDao;
+ @Resource
+ private ThrInvProductsExportLogDao thrInvProductsExportLogDao;
+ @Resource
+ private ThrInvProductsImportLogDao thrInvProductsImportLogDao;
+ @Resource
+ private ThrOrderExportLogDao thrOrderExportLogDao;
+ @Resource
+ private ThrOrderImportLogDao thrOrderImportLogDao;
+ @Resource
+ private ThrProductsExportLogDao thrProductsExportLogDao;
+ @Resource
+ private ThrProductsImportLogDao thrProductsImportLogDao;
+ @Resource
+ private BasicDownloadDao basicDownloadDao;
+ @Resource
+ private BasicExportDao basicExportDao;
+
+ @Override
+ public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
+ taskRegistrar.addTriggerTask(this::process, triggerContext -> {
+ ScheduledRequest scheduledRequest = new ScheduledRequest();
+ scheduledRequest.setCronName("clean_log_task");
+ ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest);
+ String cron = scheduledEntity.getCron();
+ if (StrUtil.isBlank(cron)) {
+ log.error("清理日志定时任务参数未配置");
+ }
+ return new CronTrigger(cron).nextExecutionTime(triggerContext);
+ });
+ }
+
+ private void process() {
+ //查询删除日志时间配置
+ String value = systemParamConfigDao.selectValueByParamKey("clean_log_days");
+ if (StrUtil.isBlank(value)) {
+ log.info("删除日志天数参数未配置,结束任务");
+ } else {
+ int days = Integer.parseInt(value);
+ if (days > 0) {
+ String date = DateUtil.offsetDay(new Date(), -days).toString("yyyy-MM-dd");
+ //查询系统日志删除是否开启
+ String cleanSystemLogValue = systemParamConfigDao.selectValueByParamKey("clean_system_log");
+ if ("1".equals(cleanSystemLogValue)) {
+ cleanSystemLog(date);
+ }
+ String cleanThrLogValue = systemParamConfigDao.selectValueByParamKey("clean_thr_log");
+ if ("1".equals(cleanThrLogValue)) {
+ cleanThrLog(date);
+ }
+ String cleanSyncLogValue = systemParamConfigDao.selectValueByParamKey("clean_sync_log");
+ if ("1".equals(cleanSyncLogValue)) {
+ cleanSyncLog(date);
+ }
+ } else {
+ log.info("配置删除日志天数为0,不进行删除");
+ }
+ }
+ }
+
+ /**
+ * 删除系统日志
+ *
+ * @param date 时间
+ */
+ private void cleanSystemLog(String date) {
+ //删除操作系统日志
+ sysOperLogMapper.deleteByDate(date);
+ //删除系统访问日志
+ sysLogininforMapper.deleteByDate(date);
+ }
+
+ /**
+ * 删除第三方系统日志
+ *
+ * @param date 时间
+ */
+ private void cleanThrLog(String date) {
+ log.info("删除第三方系统日志");
+ //删除第三方往来单位导出日志
+ thrCorpExportLogDao.deleteByDate(date);
+ //删除第三方往来单位导入日志
+ thrCorpImportLogDao.deleteByDate(date);
+ //删除第三方库存产品导出日志
+ thrInvProductsExportLogDao.deleteByDate(date);
+ //删除第三方库存产品导入日志
+ thrInvProductsImportLogDao.deleteByDate(date);
+ //删除第三方单据导出日志
+ thrOrderExportLogDao.deleteByDate(date);
+ //删除第三方单据导入日志
+ thrOrderImportLogDao.deleteByDate(date);
+ //删除第三方产品导出日志
+ thrProductsExportLogDao.deleteByDate(date);
+ //删除第三方产品导入日志
+ thrProductsImportLogDao.deleteByDate(date);
+ log.info("第三方系统日志删除完成");
+ }
+
+ /**
+ * 删除同步日志
+ *
+ * @param date 时间
+ */
+ private void cleanSyncLog(String date) {
+ log.info("开始删除同步日志");
+ //删除下载日志
+ basicDownloadDao.deleteByDate(date);
+ //删除上传日志
+ basicExportDao.deleteByDate(date);
+ }
+
+}
diff --git a/src/main/resources/mybatis/mapper/monitor/SysLogininforMapper.xml b/src/main/resources/mybatis/mapper/monitor/SysLogininforMapper.xml
index 349cb37f..28ba1c31 100644
--- a/src/main/resources/mybatis/mapper/monitor/SysLogininforMapper.xml
+++ b/src/main/resources/mybatis/mapper/monitor/SysLogininforMapper.xml
@@ -75,4 +75,7 @@
+
+ delete from monitor_login_log where date_format(#{date}, '%Y-%m-%d') >= date_format(login_time, '%Y-%m-%d')
+
diff --git a/src/main/resources/mybatis/mapper/monitor/SysOperLogMapper.xml b/src/main/resources/mybatis/mapper/monitor/SysOperLogMapper.xml
index 115b42ed..dfcaae4d 100644
--- a/src/main/resources/mybatis/mapper/monitor/SysOperLogMapper.xml
+++ b/src/main/resources/mybatis/mapper/monitor/SysOperLogMapper.xml
@@ -108,4 +108,7 @@
+
+ delete from monitor_oper_log where date_format(#{date}, '%Y-%m-%d') >= date_format(oper_time, '%Y-%m-%d')
+
diff --git a/src/main/resources/mybatis/mapper/schedule/SystemParamConfigDao.xml b/src/main/resources/mybatis/mapper/schedule/SystemParamConfigDao.xml
index 948e368a..6c99e5eb 100644
--- a/src/main/resources/mybatis/mapper/schedule/SystemParamConfigDao.xml
+++ b/src/main/resources/mybatis/mapper/schedule/SystemParamConfigDao.xml
@@ -75,5 +75,7 @@
#{paramExplain})
-
+
\ No newline at end of file
diff --git a/src/main/resources/mybatis/mapper/sync/BasicDownloadDao.xml b/src/main/resources/mybatis/mapper/sync/BasicDownloadDao.xml
index 3665bae5..77b9bce8 100644
--- a/src/main/resources/mybatis/mapper/sync/BasicDownloadDao.xml
+++ b/src/main/resources/mybatis/mapper/sync/BasicDownloadDao.xml
@@ -86,4 +86,8 @@
From basic_download_status
where date(startTime) <= date(DATE_SUB(NOW(), INTERVAL 30 day))
+
+
+ delete from basic_download_status where date_format(#{date}, '%Y-%m-%d') >= date_format(updateTime, '%Y-%m-%d')
+
diff --git a/src/main/resources/mybatis/mapper/sync/BasicExportDao.xml b/src/main/resources/mybatis/mapper/sync/BasicExportDao.xml
index 7e0bc7c1..7b4d86a1 100644
--- a/src/main/resources/mybatis/mapper/sync/BasicExportDao.xml
+++ b/src/main/resources/mybatis/mapper/sync/BasicExportDao.xml
@@ -94,4 +94,8 @@
From basic_export_status
where date(startTime) <= date(DATE_SUB(NOW(), INTERVAL 30 day))
+
+
+ delete from basic_export_status where date_format(#{date}, '%Y-%m-%d') >= date_format(startTime, '%Y-%m-%d')
+
diff --git a/src/main/resources/mybatis/mapper/thrsys/ThrCorpExportLogDao.xml b/src/main/resources/mybatis/mapper/thrsys/ThrCorpExportLogDao.xml
index 3cba3fd1..86f09971 100644
--- a/src/main/resources/mybatis/mapper/thrsys/ThrCorpExportLogDao.xml
+++ b/src/main/resources/mybatis/mapper/thrsys/ThrCorpExportLogDao.xml
@@ -64,4 +64,7 @@
where date(updateTime) <= date(DATE_SUB(NOW(),INTERVAL 30 day))
+
+ delete from thr_corp_export_log where date_format(#{date}, '%Y-%m-%d') >= date_format(updateTime, '%Y-%m-%d')
+
\ No newline at end of file
diff --git a/src/main/resources/mybatis/mapper/thrsys/ThrCorpImportLogDao.xml b/src/main/resources/mybatis/mapper/thrsys/ThrCorpImportLogDao.xml
index d1731c5a..b66030b1 100644
--- a/src/main/resources/mybatis/mapper/thrsys/ThrCorpImportLogDao.xml
+++ b/src/main/resources/mybatis/mapper/thrsys/ThrCorpImportLogDao.xml
@@ -67,4 +67,7 @@
where date(updateTime) <= date(DATE_SUB(NOW(),INTERVAL 30 day))
+
+ delete from thr_corp_import_log where date_format(#{date}, '%Y-%m-%d') >= date_format(updateTime, '%Y-%m-%d')
+
\ No newline at end of file
diff --git a/src/main/resources/mybatis/mapper/thrsys/ThrInvProductsExportLogDao.xml b/src/main/resources/mybatis/mapper/thrsys/ThrInvProductsExportLogDao.xml
index ad1e8c70..3e92cea1 100644
--- a/src/main/resources/mybatis/mapper/thrsys/ThrInvProductsExportLogDao.xml
+++ b/src/main/resources/mybatis/mapper/thrsys/ThrInvProductsExportLogDao.xml
@@ -55,4 +55,7 @@
WHERE genKey = #{genKey}
+
+ delete from thr_inv_products_export_log where date_format(#{date}, '%Y-%m-%d') >= date_format(updateTime, '%Y-%m-%d')
+
\ No newline at end of file
diff --git a/src/main/resources/mybatis/mapper/thrsys/ThrInvProductsImportLogDao.xml b/src/main/resources/mybatis/mapper/thrsys/ThrInvProductsImportLogDao.xml
index 29a07654..f950315f 100644
--- a/src/main/resources/mybatis/mapper/thrsys/ThrInvProductsImportLogDao.xml
+++ b/src/main/resources/mybatis/mapper/thrsys/ThrInvProductsImportLogDao.xml
@@ -61,4 +61,7 @@
WHERE genKey = #{genKey}
+
+ delete from thr_inv_products_import_log where date_format(#{date}, '%Y-%m-%d') >= date_format(updateTime, '%Y-%m-%d')
+
\ No newline at end of file
diff --git a/src/main/resources/mybatis/mapper/thrsys/ThrOrderExportLogDao.xml b/src/main/resources/mybatis/mapper/thrsys/ThrOrderExportLogDao.xml
index db61f7c4..cd6235c1 100644
--- a/src/main/resources/mybatis/mapper/thrsys/ThrOrderExportLogDao.xml
+++ b/src/main/resources/mybatis/mapper/thrsys/ThrOrderExportLogDao.xml
@@ -56,4 +56,7 @@
+
+ delete from thr_order_export_log where date_format(#{date}, '%Y-%m-%d') >= date_format(updateTime, '%Y-%m-%d')
+
\ No newline at end of file
diff --git a/src/main/resources/mybatis/mapper/thrsys/ThrOrderImportLogDao.xml b/src/main/resources/mybatis/mapper/thrsys/ThrOrderImportLogDao.xml
index dc560b65..10fc17f1 100644
--- a/src/main/resources/mybatis/mapper/thrsys/ThrOrderImportLogDao.xml
+++ b/src/main/resources/mybatis/mapper/thrsys/ThrOrderImportLogDao.xml
@@ -59,4 +59,7 @@
where date(updateTime) <= date(DATE_SUB(NOW(),INTERVAL 30 day))
+
+ delete from thr_order_import_log where date_format(#{date}, '%Y-%m-%d') >= date_format(updateTime, '%Y-%m-%d')
+
\ No newline at end of file
diff --git a/src/main/resources/mybatis/mapper/thrsys/ThrProductsExportLogDao.xml b/src/main/resources/mybatis/mapper/thrsys/ThrProductsExportLogDao.xml
index ad8c644a..c15292a7 100644
--- a/src/main/resources/mybatis/mapper/thrsys/ThrProductsExportLogDao.xml
+++ b/src/main/resources/mybatis/mapper/thrsys/ThrProductsExportLogDao.xml
@@ -64,4 +64,7 @@
where date(updateTime) <= date(DATE_SUB(NOW(),INTERVAL 30 day))
+
+ delete from thr_products_export_log where date_format(#{date}, '%Y-%m-%d') >= date_format(updateTime, '%Y-%m-%d')
+
\ No newline at end of file
diff --git a/src/main/resources/mybatis/mapper/thrsys/ThrProductsImportLogDao.xml b/src/main/resources/mybatis/mapper/thrsys/ThrProductsImportLogDao.xml
index 574d9e57..11311c56 100644
--- a/src/main/resources/mybatis/mapper/thrsys/ThrProductsImportLogDao.xml
+++ b/src/main/resources/mybatis/mapper/thrsys/ThrProductsImportLogDao.xml
@@ -65,4 +65,7 @@
where date(updateTime) <= date(DATE_SUB(NOW(),INTERVAL 30 day))
+
+ delete from thr_products_import_log where date_format(#{date}, '%Y-%m-%d') >= date_format(updateTime, '%Y-%m-%d')
+
\ No newline at end of file