REQ-2405: fix bugs
This commit is contained in:
parent
ffd688c7ad
commit
8a452b8439
@ -42,11 +42,11 @@ public class ReplaceInterceptor implements Interceptor {
|
|||||||
|
|
||||||
private static final ThreadLocal<Replacement> LOCAL = new ThreadLocal<>();
|
private static final ThreadLocal<Replacement> LOCAL = new ThreadLocal<>();
|
||||||
|
|
||||||
public static void enableReplacement(Replacement replacement) {
|
public static void enable(Replacement replacement) {
|
||||||
LOCAL.set(replacement);
|
LOCAL.set(replacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void disableReplacement() {
|
public static void disable() {
|
||||||
LOCAL.remove();
|
LOCAL.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,6 +67,8 @@ public class ReplaceInterceptor implements Interceptor {
|
|||||||
stmt = parser.parseSelect();
|
stmt = parser.parseSelect();
|
||||||
} else if (commandType == SqlCommandType.INSERT) {
|
} else if (commandType == SqlCommandType.INSERT) {
|
||||||
stmt = parser.parseInsert();
|
stmt = parser.parseInsert();
|
||||||
|
} else if (commandType == SqlCommandType.DELETE) {
|
||||||
|
stmt = parser.parseDeleteStatement();
|
||||||
} else {
|
} else {
|
||||||
return invocation.proceed();
|
return invocation.proceed();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,4 +19,12 @@ public enum Replacement {
|
|||||||
private final String destTable;
|
private final String destTable;
|
||||||
private final boolean insertPreserveId;
|
private final boolean insertPreserveId;
|
||||||
|
|
||||||
|
public void run(Runnable runnable) {
|
||||||
|
ReplaceInterceptor.enable(this);
|
||||||
|
try {
|
||||||
|
runnable.run();
|
||||||
|
} finally {
|
||||||
|
ReplaceInterceptor.disable();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -24,6 +24,7 @@ import java.util.List;
|
|||||||
/*@Mapper*/
|
/*@Mapper*/
|
||||||
public interface MessageRecordMapper extends IterableMapper<MessageRecord> {
|
public interface MessageRecordMapper extends IterableMapper<MessageRecord> {
|
||||||
|
|
||||||
|
void deleteRecordsPhysically(@Param("ids") List<Long> ids);
|
||||||
|
|
||||||
List<MsgStatisticsDTO> statisticsMsg(@Param("bizType") Integer bizType,
|
List<MsgStatisticsDTO> statisticsMsg(@Param("bizType") Integer bizType,
|
||||||
@Param("personId") Long personId,
|
@Param("personId") Long personId,
|
||||||
|
|||||||
@ -2,6 +2,14 @@
|
|||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="cn.axzo.msg.center.dal.mapper.MessageRecordMapper">
|
<mapper namespace="cn.axzo.msg.center.dal.mapper.MessageRecordMapper">
|
||||||
|
|
||||||
|
<delete id="deleteRecordsPhysically">
|
||||||
|
DELETE FROM message_record
|
||||||
|
WHERE id IN
|
||||||
|
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
|
||||||
<select id="statisticsMsg"
|
<select id="statisticsMsg"
|
||||||
resultType="cn.axzo.msg.center.domain.dto.MsgStatisticsDTO">
|
resultType="cn.axzo.msg.center.domain.dto.MsgStatisticsDTO">
|
||||||
select type,
|
select type,
|
||||||
|
|||||||
@ -0,0 +1,50 @@
|
|||||||
|
package cn.axzo.msg.center.dal.mapper;
|
||||||
|
|
||||||
|
import cn.axzo.msg.center.MsgCenterApplication;
|
||||||
|
import cn.axzo.msg.center.dal.MessageRecordDao;
|
||||||
|
import cn.axzo.msg.center.domain.entity.MessageRecord;
|
||||||
|
import cn.axzo.msg.center.message.service.todo.mybatis.Replacement;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.axzo.msg.center.inside.notices.utils.Queries.query;
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author yanglin
|
||||||
|
*/
|
||||||
|
@SpringBootTest(classes = MsgCenterApplication.class)
|
||||||
|
@RequiredArgsConstructor(onConstructor_ = @Autowired)
|
||||||
|
class MessageRecordMapperTest {
|
||||||
|
|
||||||
|
private final MessageRecordMapper messageRecordMapper;
|
||||||
|
private final MessageRecordDao messageRecordDao;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void tryMigrate() {
|
||||||
|
Iterable<Page<MessageRecord>> pages = messageRecordMapper
|
||||||
|
.iterateBath(10, query(MessageRecord.class)
|
||||||
|
.orderByAsc(MessageRecord::getId));
|
||||||
|
|
||||||
|
Iterator<Page<MessageRecord>> iterator = pages.iterator();
|
||||||
|
// 试试前5页数据,测试一下
|
||||||
|
for (int i = 0; i < 5 && iterator.hasNext(); i++) {
|
||||||
|
Page<MessageRecord> page = iterator.next();
|
||||||
|
Replacement.TO_MESSAGE_RECORD_COLD.run(() -> {
|
||||||
|
List<MessageRecord> records = page.getRecords();
|
||||||
|
List<Long> ids = records.stream()
|
||||||
|
.map(MessageRecord::getId)
|
||||||
|
.collect(toList());
|
||||||
|
messageRecordMapper.deleteRecordsPhysically(ids);
|
||||||
|
messageRecordDao.saveBatch(records);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user