feat(REQ-2649): 增加名单历史表,增加job定期归档历史数据 step2 处理逻辑删除插件导致的查询问题
This commit is contained in:
parent
1f6f58d6ea
commit
ce87db5b3e
@ -3,6 +3,10 @@ package cn.axzo.nanopart.server.dao.mapper;
|
||||
import cn.axzo.nanopart.server.dao.entity.SaasBlackWhiteList;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: chenwenjian
|
||||
@ -14,4 +18,19 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
@Mapper
|
||||
public interface BlackAndWhiteListMapper extends BaseMapper<SaasBlackWhiteList> {
|
||||
|
||||
/**
|
||||
* 查询已经删除的记录
|
||||
*
|
||||
* @param startId
|
||||
* @param limit
|
||||
* @return
|
||||
*/
|
||||
List<SaasBlackWhiteList> listDeleted(@Param("startId") Long startId, @Param("limit") Long limit);
|
||||
|
||||
/**
|
||||
* 物理删除已经删除的记录
|
||||
*
|
||||
* @param ids
|
||||
*/
|
||||
void absoluteDeletedByIds(@Param("ids") Collection<Long> ids);
|
||||
}
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
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.mapper.BlackAndWhiteListMapper;
|
||||
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;
|
||||
@ -25,7 +24,7 @@ import java.util.stream.Collectors;
|
||||
public class ArchiveBlackWhiteListJob extends IJobHandler {
|
||||
private static final String LIMIT_SUFFIX = " limit 200 ";
|
||||
@Autowired
|
||||
private BlackAndWhiteListRepository repository;
|
||||
private BlackAndWhiteListMapper mapper;
|
||||
@Autowired
|
||||
private BlackAndWhiteListHistoryRepository historyRepository;
|
||||
|
||||
@ -40,15 +39,10 @@ public class ArchiveBlackWhiteListJob extends IJobHandler {
|
||||
public ReturnT<String> execute(String param) throws Exception {
|
||||
log.info("archiveBlackWhiteListJob start.");
|
||||
XxlJobLogger.log("archiveBlackWhiteListJob start.");
|
||||
long offset = 0L;
|
||||
long startId = 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();
|
||||
List<SaasBlackWhiteList> list = mapper.listDeleted(startId, 200L);
|
||||
if (list.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
@ -63,10 +57,10 @@ public class ArchiveBlackWhiteListJob extends IJobHandler {
|
||||
.updateBy(e.getUpdateBy())
|
||||
.build())
|
||||
.collect(Collectors.toList());
|
||||
repository.deleteByIds(list.stream().map(SaasBlackWhiteList::getId).collect(Collectors.toSet()));
|
||||
mapper.absoluteDeletedByIds(list.stream().map(SaasBlackWhiteList::getId).collect(Collectors.toSet()));
|
||||
historyRepository.saveBatch(histories);
|
||||
totalCount += list.size();
|
||||
offset = list.get(list.size() - 1).getId();
|
||||
startId = list.get(list.size() - 1).getId();
|
||||
}
|
||||
log.info("archiveBlackWhiteListJob end. totalCount = {}", totalCount);
|
||||
XxlJobLogger.log("archiveBlackWhiteListJob end. totalCount = " + totalCount);
|
||||
|
||||
@ -0,0 +1,38 @@
|
||||
<?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="cn.axzo.nanopart.server.dao.mapper.BlackAndWhiteListMapper">
|
||||
|
||||
<resultMap type="cn.axzo.nanopart.server.dao.entity.SaasBlackWhiteList" id="SaasBlackWhiteListResultMap">
|
||||
<result property="id" column="id"/>
|
||||
<result property="isDelete" column="is_delete"/>
|
||||
<result property="createAt" column="create_at"/>
|
||||
<result property="updateAt" column="update_at"/>
|
||||
<result property="type" column="type"/>
|
||||
<result property="module" column="module"/>
|
||||
<result property="createBy" column="create_by"/>
|
||||
<result property="updateBy" column="update_by"/>
|
||||
<result property="param" column="param" typeHandler="com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="listDeleted" resultMap="SaasBlackWhiteListResultMap">
|
||||
select *
|
||||
from `saas_black_white_list`
|
||||
where is_delete > 0
|
||||
and id > #{startId}
|
||||
order by id asc limit #{limit}
|
||||
</select>
|
||||
|
||||
<delete id="absoluteDeletedByIds">
|
||||
DELETE
|
||||
FROM
|
||||
`saas_black_white_list`
|
||||
WHERE
|
||||
`id` in
|
||||
<foreach collection="ids" item="id" open="(" close=")" separator=",">
|
||||
#{id}
|
||||
</foreach>
|
||||
AND `is_delete` > 0
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue
Block a user