arextest / arex-agent-java

Lightweight Java agent for traffic capture and replay, enhancing testing and debugging.
https://doc.arextest.com/
Apache License 2.0
416 stars 82 forks source link

[Bug] mybatis-plus3.1 回放时没有实现insertBatchSomeColumn 主键生成填充 #477

Closed claywong closed 1 month ago

claywong commented 1 month ago

Search before asking

AREX Test Service

AREX Java Agent (arextest/arex-agent-java)

Current Behavior

List list image

image

操作之后,list中Log的id字段没有自增填充

Expected Behavior

Log中id被设置

Steps To Reproduce

最新打包的agent,mybatis-plus 3.1.0

Anything else

No response

Are you willing to submit a pull request to fix on your own?

YongwuHe commented 1 month ago

@claywong 能否贴一下方法的具体实现?

claywong commented 1 month ago

public class CommonService<M extends CommonMapper<T>, T> extends ServiceImpl<M, T> {

    private static final int BATCH_SIZE = 1000;

    public CommonService() {
    }

    @Transactional(
        rollbackFor = {Exception.class}
    )
    public boolean realSaveBatch(List<T> list, int batchSize) {
        if (CollectionUtils.isEmpty(list)) {
            return true;
        } else {
            batchSize = batchSize < 1 ? 1000 : batchSize;
            if (list.size() <= batchSize) {
                return this.retBool(((CommonMapper)this.baseMapper).insertBatchSomeColumn(list));
            } else {
                int fromIdx = 0;
                int endIdx = batchSize;

                while(true) {
                    if (endIdx > list.size()) {
                        endIdx = list.size();
                    }

                    ((CommonMapper)this.baseMapper).insertBatchSomeColumn(list.subList(fromIdx, endIdx));
                    if (endIdx == list.size()) {
                        return true;
                    }

                    fromIdx += batchSize;
                    endIdx += batchSize;
                }
            }
        }
    }
}

public interface CommonMapper<T> extends BaseMapper<T> {

    Integer insertBatchSomeColumn(Collection<T> list);

}
YongwuHe commented 1 month ago

@claywong 已经支持,请拉取主分支最新代码进行验证