|
@@ -1,28 +1,14 @@
|
|
|
package mybatisex.core.mapper;
|
|
package mybatisex.core.mapper;
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
import java.util.Collection;
|
|
|
-import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
|
|
-
|
|
|
|
|
-import org.apache.ibatis.logging.Log;
|
|
|
|
|
-import org.apache.ibatis.logging.LogFactory;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.enums.SqlMethod;
|
|
|
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
|
-import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
|
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.ClassUtils;
|
|
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.Constants;
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
-import com.baomidou.mybatisplus.extension.toolkit.Db;
|
|
|
|
|
-import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
|
|
|
|
import com.github.yulichang.base.MPJBaseMapper;
|
|
import com.github.yulichang.base.MPJBaseMapper;
|
|
|
|
|
|
|
|
-import mybatisex.core.util.DbX;
|
|
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* 在 MyBatis Plus 的 BaseMapper 的基础上拓展,提供更多的能力
|
|
* 在 MyBatis Plus 的 BaseMapper 的基础上拓展,提供更多的能力
|
|
|
*
|
|
*
|
|
@@ -338,63 +324,5 @@ public interface BaseMapperX<T> extends MPJBaseMapper<T> {
|
|
|
entity.set(setField, setValue);
|
|
entity.set(setField, setValue);
|
|
|
return update(entity);
|
|
return update(entity);
|
|
|
}
|
|
}
|
|
|
- // 更新操作结束
|
|
|
|
|
-
|
|
|
|
|
- // -----------------------------------------------------------------------
|
|
|
|
|
-
|
|
|
|
|
- // 删除条件-----------------------end--------------------------------
|
|
|
|
|
- /**
|
|
|
|
|
- * 批量插入,适合大量数据插入
|
|
|
|
|
- *
|
|
|
|
|
- * @param entities 实体们
|
|
|
|
|
- */
|
|
|
|
|
- default Boolean insertBatch(Collection<T> entities) {
|
|
|
|
|
- return Db.saveBatch(entities);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 批量插入,适合大量数据插入
|
|
|
|
|
- *
|
|
|
|
|
- * @param entities 实体们
|
|
|
|
|
- * @param size 插入数量 Db.saveBatch 默认为 1000
|
|
|
|
|
- */
|
|
|
|
|
- default Boolean insertBatch(Collection<T> entities, int size) {
|
|
|
|
|
- return Db.saveBatch(entities, size);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- default Boolean updateBatch(Collection<T> entities) {
|
|
|
|
|
- return Db.updateBatchById(entities);
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- default Boolean updateBatch(Collection<T> entities, int size) {
|
|
|
|
|
- return Db.updateBatchById(entities, size);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- default Boolean insertOrUpdate(T entity) {
|
|
|
|
|
- return Db.saveOrUpdate(entity);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- default Boolean insertOrUpdateBatch(Collection<T> collection) {
|
|
|
|
|
- return Db.saveOrUpdateBatch(collection);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- UpdateWrapper<T> getUpdateWrapper(T t);
|
|
|
|
|
-
|
|
|
|
|
- @SuppressWarnings("deprecation")
|
|
|
|
|
- default boolean updateBatchByColumn(Collection<T> entityList) {
|
|
|
|
|
- if (CollectionUtils.isEmpty(entityList)) {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
- final Log log = LogFactory.getLog(this.getClass());
|
|
|
|
|
- Class<T> entityClass = DbX.getEntityClass(entityList);
|
|
|
|
|
- TableInfo tableInfo = DbX.getTableInfo(entityClass);
|
|
|
|
|
- Class<?> mapperClass = ClassUtils.toClassConfident(tableInfo.getCurrentNamespace());
|
|
|
|
|
- String sqlStatement = SqlHelper.getSqlStatement(mapperClass, SqlMethod.UPDATE);
|
|
|
|
|
- return SqlHelper.executeBatch(entityClass, log, entityList, 1000, (sqlSession, entity) -> {
|
|
|
|
|
- Map<String, Object> param = new HashMap<>();
|
|
|
|
|
- param.put(Constants.ENTITY, entity);
|
|
|
|
|
- param.put(Constants.WRAPPER, getUpdateWrapper(entity));
|
|
|
|
|
- sqlSession.update(sqlStatement, param);
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|