feat(REQ-2649): 增加名单历史表,增加job定期归档历史数据
This commit is contained in:
parent
f9aa9e3f46
commit
1f6f58d6ea
@ -0,0 +1,61 @@
|
|||||||
|
package cn.axzo.nanopart.server.dao.entity;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.axzo.pokonyan.config.mybatisplus.BaseEntity;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author: chenwenjian
|
||||||
|
* @date: 2023/8/11 15:19
|
||||||
|
* @description: 黑白名单表对应实体
|
||||||
|
* @modifiedBy:
|
||||||
|
* @version: 1.0
|
||||||
|
*/
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@TableName(value = "saas_black_white_list_history", autoResultMap = true)
|
||||||
|
public class SaasBlackWhiteListHistory extends BaseEntity<SaasBlackWhiteListHistory> {
|
||||||
|
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模块名
|
||||||
|
*/
|
||||||
|
private String module;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数
|
||||||
|
*/
|
||||||
|
@TableField(value = "param", typeHandler = JacksonTypeHandler.class)
|
||||||
|
private Map<String, Object> param;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private Date originCreateAt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改时间
|
||||||
|
*/
|
||||||
|
private Date originUpdateAt;
|
||||||
|
|
||||||
|
private Long originId;
|
||||||
|
|
||||||
|
private Long createBy;
|
||||||
|
|
||||||
|
private Long updateBy;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
package cn.axzo.nanopart.server.dao.mapper;
|
||||||
|
|
||||||
|
import cn.axzo.nanopart.server.dao.entity.SaasBlackWhiteListHistory;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface BlackAndWhiteListHistoryMapper extends BaseMapper<SaasBlackWhiteListHistory> {
|
||||||
|
|
||||||
|
}
|
||||||
@ -3,9 +3,6 @@ package cn.axzo.nanopart.server.dao.mapper;
|
|||||||
import cn.axzo.nanopart.server.dao.entity.SaasBlackWhiteList;
|
import cn.axzo.nanopart.server.dao.entity.SaasBlackWhiteList;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author: chenwenjian
|
* @author: chenwenjian
|
||||||
|
|||||||
@ -0,0 +1,14 @@
|
|||||||
|
package cn.axzo.nanopart.server.dao.repository;
|
||||||
|
|
||||||
|
import cn.axzo.nanopart.server.dao.entity.SaasBlackWhiteListHistory;
|
||||||
|
import cn.axzo.nanopart.server.dao.mapper.BlackAndWhiteListHistoryMapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Repository
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class BlackAndWhiteListHistoryRepository extends ServiceImpl<BlackAndWhiteListHistoryMapper, SaasBlackWhiteListHistory> {
|
||||||
|
}
|
||||||
@ -0,0 +1,75 @@
|
|||||||
|
package cn.axzo.nanopart.server.job;
|
||||||
|
|
||||||
|
import cn.axzo.basics.common.constant.enums.TableIsDeleteEnum;
|
||||||
|
import cn.axzo.nanopart.server.dao.entity.SaasBlackWhiteList;
|
||||||
|
import cn.axzo.nanopart.server.dao.entity.SaasBlackWhiteListHistory;
|
||||||
|
import cn.axzo.nanopart.server.dao.repository.BlackAndWhiteListHistoryRepository;
|
||||||
|
import cn.axzo.nanopart.server.dao.repository.BlackAndWhiteListRepository;
|
||||||
|
import com.xxl.job.core.biz.model.ReturnT;
|
||||||
|
import com.xxl.job.core.handler.IJobHandler;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
|
import com.xxl.job.core.log.XxlJobLogger;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时归档已删除的黑白名单
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class ArchiveBlackWhiteListJob extends IJobHandler {
|
||||||
|
private static final String LIMIT_SUFFIX = " limit 200 ";
|
||||||
|
@Autowired
|
||||||
|
private BlackAndWhiteListRepository repository;
|
||||||
|
@Autowired
|
||||||
|
private BlackAndWhiteListHistoryRepository historyRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时任务执行逻辑
|
||||||
|
*
|
||||||
|
* @param param
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Throwable.class)
|
||||||
|
@XxlJob("archiveBlackWhiteListJob")
|
||||||
|
public ReturnT<String> execute(String param) throws Exception {
|
||||||
|
log.info("archiveBlackWhiteListJob start.");
|
||||||
|
XxlJobLogger.log("archiveBlackWhiteListJob start.");
|
||||||
|
long offset = 0L;
|
||||||
|
long totalCount = 0L;
|
||||||
|
while (true) {
|
||||||
|
List<SaasBlackWhiteList> list = repository.lambdaQuery()
|
||||||
|
.ne(SaasBlackWhiteList::getIsDelete, TableIsDeleteEnum.NORMAL.value)
|
||||||
|
.gt(SaasBlackWhiteList::getId, offset)
|
||||||
|
.orderByAsc(SaasBlackWhiteList::getId)
|
||||||
|
.last(LIMIT_SUFFIX)
|
||||||
|
.list();
|
||||||
|
if (list.isEmpty()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
List<SaasBlackWhiteListHistory> histories = list.stream().map(e -> SaasBlackWhiteListHistory.builder()
|
||||||
|
.type(e.getType())
|
||||||
|
.module(e.getModule())
|
||||||
|
.param(e.getParam())
|
||||||
|
.originId(e.getId())
|
||||||
|
.originCreateAt(e.getCreateAt())
|
||||||
|
.originUpdateAt(e.getUpdateAt())
|
||||||
|
.createBy(e.getCreateBy())
|
||||||
|
.updateBy(e.getUpdateBy())
|
||||||
|
.build())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
repository.deleteByIds(list.stream().map(SaasBlackWhiteList::getId).collect(Collectors.toSet()));
|
||||||
|
historyRepository.saveBatch(histories);
|
||||||
|
totalCount += list.size();
|
||||||
|
offset = list.get(list.size() - 1).getId();
|
||||||
|
}
|
||||||
|
log.info("archiveBlackWhiteListJob end. totalCount = {}", totalCount);
|
||||||
|
XxlJobLogger.log("archiveBlackWhiteListJob end. totalCount = " + totalCount);
|
||||||
|
return ReturnT.SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user