提交 02f926b8 编写于 作者: ibiz4j's avatar ibiz4j

dameng批量

上级 61bf0450
......@@ -29,4 +29,23 @@ public interface DbEntityMapper extends BaseMapper<EntityObj>{
" ) T2 \n ${model.mergeSegment}"+
"</script>"})
boolean save(@Param("model") EntityModel model, @Param("entity") EntityObj entity);
@Insert({"<script> "+
"<foreach collection=\"list\" item=\"item\" index=\"index\" separator=\";\">\n" +
" MERGE INTO ${model.tableName} T1\n" +
" USING (\n" +
" SELECT ${model.mergeColumnSegment} FROM dual\n" +
" ) T2 \n ${model.mergeSegment}"+
"</foreach>\n" +
"</script>"})
boolean saveBatchDm(@Param("model") EntityModel model, @Param("list") List<EntityObj> list);
@Insert({"<script> "+" MERGE INTO ${model.tableName} T1\n" +
" USING (\n" +
" SELECT ${model.mergeColumnSegment} FROM dual\n" +
" ) T2 \n ${model.mergeSegment}"+
"</script>"})
boolean saveDm(@Param("model") EntityModel model, @Param("entity") EntityObj entity);
}
\ No newline at end of file
......@@ -9,6 +9,8 @@ import cn.ibizlab.core.lite.extensions.domain.ModelObj;
import cn.ibizlab.core.lite.extensions.filter.DbEntitySearchContext;
import cn.ibizlab.core.lite.extensions.model.DataModel;
import cn.ibizlab.util.filter.QueryFilter;
import com.alibaba.druid.pool.DruidDataSource;
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
......@@ -20,8 +22,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import javax.sql.DataSource;
import java.io.BufferedReader;
import java.io.Reader;
import java.sql.Timestamp;
......@@ -211,6 +215,10 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
}
}
@Autowired
@Lazy
private DynamicRoutingDataSource dynamicRoutingDataSource;
@Override
public boolean saveBatch(String dsName, EntityModel entityModel, List<EntityObj> list) {
try {
......@@ -219,6 +227,16 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
dstDataSourceService.initDataSource(dsName);
DynamicDataSourceContextHolder.push(dsName);
String dstype="";
Map<String, DataSource> dynamicDSMap = dynamicRoutingDataSource.getCurrentDataSources();
if (!ObjectUtils.isEmpty(dynamicDSMap) && dynamicDSMap.containsKey(dsName)) {
DataSource ds = dynamicDSMap.get(dsName);
if (ds instanceof DruidDataSource) {
DruidDataSource druidDataSource = (DruidDataSource) dynamicDSMap.get(dsName);
dstype=druidDataSource.getDbType();
}
}
list.forEach(entityObj -> {
entityObj.keySet().forEach(key -> {
if(!key.toUpperCase().equals(key))
......@@ -226,7 +244,14 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
});
});
baseMapper.saveBatch(entityModel, list);
if ("dameng".equals(dstype)||"dm".equals(dstype)) {
baseMapper.saveBatchDm(entityModel, list);
}
else
{
baseMapper.saveBatch(entityModel, list);
}
return true;
} catch (Exception ex) {
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册