【Mybatis Plus】自定义组合关系重写 SaveOrUpdateBatch方法
主要使用 MybatisPlus 底层方法 SqlHelper.saveOrUpdateBatch
@Transactional(rollbackFor = Exception.class)
public boolean customSaveOrUpdateBatch(Collection<AiUserMarkActionEntity> entityList, int batchSize) {
TableInfo tableInfo = TableInfoHelper.getTableInfo(entityClass);
return SqlHelper.saveOrUpdateBatch(this.entityClass, this.mapperClass, this.log, entityList, batchSize,
(sqlSession, entity) -> {
LambdaQueryWrapper<AiUserMarkActionEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(AiUserMarkActionEntity::getUserId, entity.getUserId())
.eq(AiUserMarkActionEntity::getActionType, entity.getActionType())
.eq(AiUserMarkActionEntity::getRecordId, entity.getRecordId());
Map<String, Object> param = new HashMap<>();
param.put(Constants.WRAPPER, queryWrapper);
return CollUtil.isEmpty(sqlSession.selectList(sqlStatement(SqlMethod.SELECT_LIST), param));
},
(sqlSession, entity) -> {
Map<String, Object> param = new HashMap<>();
param.put(Constants.ENTITY, entity);
UpdateWrapper<AiUserMarkActionEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("user_id", entity.getUserId())
.eq("action_type", entity.getActionType())
.eq("record_id", entity.getRecordId());
param.put(Constants.WRAPPER, updateWrapper);
sqlSession.update(sqlStatement(SqlMethod.UPDATE), param);
}
);