1.添加删除日志数据定时任务

master
x_z 2 years ago
parent d3dc0e9556
commit 22610e1449

@ -27,5 +27,10 @@ public interface SysLogininforMapper {
*/
void insertLogininfor(SysLogininfor logininfor);
/**
*
*
* @param date
*/
void deleteByDate(@Param("date") String date);
}

@ -25,4 +25,5 @@ public interface SysOperLogMapper {
SysOperLog selectById(Long id);
void deleteByDate(@Param("date") String date);
}

@ -22,4 +22,5 @@ public interface BasicDownloadDao {
boolean updateDownloadStatus(BasicDownloadStatusEntity basicDownloadStatusEntity);
void deleteByDate(@Param("date") String date);
}

@ -21,4 +21,5 @@ public interface BasicExportDao {
boolean updateExportStatus(BasicExportStatusEntity warehouseEntity);
void deleteByDate(@Param("date") String date);
}

@ -23,4 +23,11 @@ public interface ThrCorpExportLogDao {
boolean deleteByTime();
String selectFilePathById(@Param("id") String id);
/**
*
*
* @param date
*/
void deleteByDate(@Param("date") String date);
}

@ -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);
}

@ -17,4 +17,6 @@ public interface ThrInvProductsExportLogDao {
boolean updateThrInvProductsExportLog(ThrInvProductsExportLogEntity thrInvProductsExportLogEntity);
boolean deleteById(@Param("id") String id);
void deleteByDate(@Param("date") String date);
}

@ -19,4 +19,5 @@ public interface ThrInvProductsImportLogDao {
boolean deleteById(@Param("id") String id);
void deleteByDate(@Param("date") String date);
}

@ -20,4 +20,6 @@ public interface ThrOrderExportLogDao {
boolean deleteById(@Param("id") String id);
boolean deleteByTime();
void deleteByDate(@Param("date") String date);
}

@ -21,4 +21,6 @@ public interface ThrOrderImportLogDao {
boolean deleteByTime();
void deleteByDate(@Param("date") String date);
}

@ -28,4 +28,6 @@ public interface ThrProductsExportLogDao {
String selectFilePathById(@Param("id") String id);
boolean deleteByTime();
void deleteByDate(@Param("date") String date);
}

@ -19,4 +19,6 @@ public interface ThrProductsImportLogDao {
boolean deleteById(@Param("id") String id);
boolean deleteByTime();
void deleteByDate(@Param("date") String date);
}

@ -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);
}
}

@ -75,4 +75,7 @@
</delete>
<delete id="deleteByDate">
delete from monitor_login_log where date_format(#{date}, '%Y-%m-%d') >= date_format(login_time, '%Y-%m-%d')
</delete>
</mapper>

@ -108,4 +108,7 @@
</delete>
<delete id="deleteByDate">
delete from monitor_oper_log where date_format(#{date}, '%Y-%m-%d') >= date_format(oper_time, '%Y-%m-%d')
</delete>
</mapper>

@ -75,5 +75,7 @@
#{paramExplain})
</insert>
<select id="selectValueByParamKey" resultType="java.lang.String">
select paramValue from sys_param_config where paramKey = #{key}
</select>
</mapper>

@ -86,4 +86,8 @@
From basic_download_status
where date(startTime) &lt;= date(DATE_SUB(NOW(), INTERVAL 30 day))
</delete>
<delete id="deleteByDate">
delete from basic_download_status where date_format(#{date}, '%Y-%m-%d') >= date_format(updateTime, '%Y-%m-%d')
</delete>
</mapper>

@ -94,4 +94,8 @@
From basic_export_status
where date(startTime) &lt;= date(DATE_SUB(NOW(), INTERVAL 30 day))
</delete>
<delete id="deleteByDate">
delete from basic_export_status where date_format(#{date}, '%Y-%m-%d') >= date_format(startTime, '%Y-%m-%d')
</delete>
</mapper>

@ -64,4 +64,7 @@
where date(updateTime) &lt;= date(DATE_SUB(NOW(),INTERVAL 30 day))
</delete>
<delete id="deleteByDate">
delete from thr_corp_export_log where date_format(#{date}, '%Y-%m-%d') >= date_format(updateTime, '%Y-%m-%d')
</delete>
</mapper>

@ -67,4 +67,7 @@
where date(updateTime) &lt;= date(DATE_SUB(NOW(),INTERVAL 30 day))
</delete>
<delete id="deleteByDate">
delete from thr_corp_import_log where date_format(#{date}, '%Y-%m-%d') >= date_format(updateTime, '%Y-%m-%d')
</delete>
</mapper>

@ -55,4 +55,7 @@
WHERE genKey = #{genKey}
</update>
<delete id="deleteByDate">
delete from thr_inv_products_export_log where date_format(#{date}, '%Y-%m-%d') >= date_format(updateTime, '%Y-%m-%d')
</delete>
</mapper>

@ -61,4 +61,7 @@
WHERE genKey = #{genKey}
</update>
<delete id="deleteByDate">
delete from thr_inv_products_import_log where date_format(#{date}, '%Y-%m-%d') >= date_format(updateTime, '%Y-%m-%d')
</delete>
</mapper>

@ -56,4 +56,7 @@
</delete>
<delete id="deleteByDate">
delete from thr_order_export_log where date_format(#{date}, '%Y-%m-%d') >= date_format(updateTime, '%Y-%m-%d')
</delete>
</mapper>

@ -59,4 +59,7 @@
where date(updateTime) &lt;= date(DATE_SUB(NOW(),INTERVAL 30 day))
</delete>
<delete id="deleteByDate">
delete from thr_order_import_log where date_format(#{date}, '%Y-%m-%d') >= date_format(updateTime, '%Y-%m-%d')
</delete>
</mapper>

@ -64,4 +64,7 @@
where date(updateTime) &lt;= date(DATE_SUB(NOW(),INTERVAL 30 day))
</delete>
<delete id="deleteByDate">
delete from thr_products_export_log where date_format(#{date}, '%Y-%m-%d') >= date_format(updateTime, '%Y-%m-%d')
</delete>
</mapper>

@ -65,4 +65,7 @@
where date(updateTime) &lt;= date(DATE_SUB(NOW(),INTERVAL 30 day))
</delete>
<delete id="deleteByDate">
delete from thr_products_import_log where date_format(#{date}, '%Y-%m-%d') >= date_format(updateTime, '%Y-%m-%d')
</delete>
</mapper>
Loading…
Cancel
Save