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

master
x_z 2 years ago
parent dcb2fc3870
commit cec3ccb030

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

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

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

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

@ -0,0 +1,15 @@
package com.glxp.api.dao.system;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.glxp.api.entity.system.SysErpLogEntity;
import org.apache.ibatis.annotations.Param;
public interface SysErpLogDao extends BaseMapper<SysErpLogEntity> {
/**
*
*
* @param date
*/
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,10 @@ public interface ThrCorpImportLogDao {
boolean deleteByTime();
/**
*
*
* @param date
*/
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,5 @@ 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,71 @@
package com.glxp.api.entity.system;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.util.Date;
/**
*
*/
@Data
@TableName(value = "sys_erp_log")
public class SysErpLogEntity {
/**
* id
*/
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
/**
*
*/
@TableField(value = "url")
private String url;
/**
* /
*/
@TableField(value = "`name`")
private String name;
/**
*
*/
@TableField(value = "params")
private String params;
/**
*
*/
@TableField(value = "`result`")
private String result;
/**
*
*/
@TableField(value = "createTime")
private Date createTime;
/**
* interface: third
*/
@TableField(value = "`type`")
private String type;
/**
*
*/
@TableField(value = "`status`")
private Integer status;
/**
*
*/
@TableField(value = "time")
private Long time;
}

@ -1,7 +1,9 @@
package com.glxp.api.task;
import javax.annotation.Resource;
import com.glxp.api.dao.schedule.ScheduledDao;
import com.glxp.api.entity.system.ScheduledEntity;
import com.glxp.api.idc.service.IdcService;
import com.glxp.api.req.system.ScheduledRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.EnableScheduling;
@ -10,10 +12,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;
import com.glxp.api.dao.schedule.ScheduledDao;
import com.glxp.api.entity.system.ScheduledEntity;
import com.glxp.api.idc.service.IdcService;
import com.glxp.api.req.system.ScheduledRequest;
import javax.annotation.Resource;
@ -50,7 +49,7 @@ public class AsyncUdiTask implements SchedulingConfigurer {
private void process() {
logger.info("syncIdcUdi----process------------");
idcService.asyncUdiTask();
//idcService.asyncUdiTask();
}
}

@ -0,0 +1,159 @@
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.system.SysErpLogDao;
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 SysErpLogDao sysErpLogDao;
@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);
//删除第三方接口服务日志
sysErpLogDao.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>

@ -88,4 +88,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>

@ -71,4 +71,8 @@
Delete 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>

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.glxp.api.dao.system.SysErpLogDao">
<delete id="deleteByDate">
delete
from sys_erp_log
where date_format(#{date}, '%Y-%m-%d') >= date_format(createTime, '%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