fix: fix insert batch in highgo
This commit is contained in:
@@ -52,5 +52,7 @@ public interface TableMapper {
|
||||
|
||||
Long countBySql(@Param("sql") String sql);
|
||||
int insertBatch(@Param("list") List<Map<String, Object>> list, @Param("tableName") String tableName);
|
||||
int insertBatchSeq(@Param("list") List<Map<String, Object>> list, @Param("tableName") String tableName,@Param("pkName")String pkName);
|
||||
|
||||
int updateBatchByPk(@Param("sql")String sql);
|
||||
}
|
||||
|
||||
@@ -740,36 +740,21 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
throw new ServiceException("list can not empty");
|
||||
}
|
||||
// JudgesNull(data, "tableName can not be null!");
|
||||
String key;
|
||||
DatasourceConfig datasourceConfig = new DatasourceConfig();
|
||||
try {
|
||||
key = DBContextHolder.getDataSource();
|
||||
datasourceConfig = DataSourceUtil.get(key);
|
||||
} catch (Exception e) {
|
||||
if (dataType.contains("oracle")) {
|
||||
datasourceConfig.setCommonType(DataUnit.ORACLE);
|
||||
}
|
||||
if (dataType.contains("mysql")) {
|
||||
datasourceConfig.setCommonType(DataUnit.MYSQL);
|
||||
}
|
||||
if (dataType.contains("DmDriver")) {
|
||||
datasourceConfig.setCommonType(DataUnit.DAMENG);
|
||||
}
|
||||
if (dataType.contains("sqlite")) {
|
||||
datasourceConfig.setCommonType(DataUnit.SQLITE);
|
||||
}
|
||||
}
|
||||
String dataTypeConfig = getDataConfig();
|
||||
if (StringUtils.isEmpty(pkName)) {
|
||||
pkName = "ID";
|
||||
}
|
||||
|
||||
if (datasourceConfig.getCommonType().equals(DataUnit.ORACLE) || datasourceConfig.getCommonType().equals(DataUnit.DAMENG)) {
|
||||
int i;
|
||||
if (dataTypeConfig.equals(DataUnit.ORACLE) || dataTypeConfig.equals(DataUnit.DAMENG) || dataTypeConfig.equals(DataUnit.HANGO)) {
|
||||
Object id = getSequence(tableName, pkName);
|
||||
for (Map<String, Object> map : list) {
|
||||
Object id = getSequence(tableName, pkName);
|
||||
map.put(pkName, id);
|
||||
map.put(pkName, "nextval('"+tableName.toLowerCase()+"_seq')");
|
||||
}
|
||||
i = tableMapper.insertBatchSeq(list,tableName,pkName);
|
||||
}else {
|
||||
i = tableMapper.insertBatch(list, tableName);
|
||||
|
||||
}
|
||||
int i = tableMapper.insertBatch(list, tableName);
|
||||
SqlException.base(i, "保存失败");
|
||||
return i;
|
||||
}
|
||||
@@ -828,12 +813,12 @@ public class BaseMapperImpl implements BaseMapper {
|
||||
if (!tableMapper.judgeHighGoSequenceExist(tableName.toLowerCase())) {
|
||||
Map<String, Object> map = selectRecentData(tableName, pkName);
|
||||
if (map == null) {
|
||||
tableMapper.createHighGoSequence(tableName, 1);
|
||||
tableMapper.createHighGoSequence(tableName.toLowerCase(), 1);
|
||||
} else {
|
||||
tableMapper.createHighGoSequence(tableName, map.get(pkName));
|
||||
tableMapper.createHighGoSequence(tableName.toLowerCase(), map.get(pkName));
|
||||
}
|
||||
}
|
||||
id = tableMapper.getHighGoSequence(tableName);
|
||||
id = tableMapper.getHighGoSequence(tableName.toLowerCase());
|
||||
} else {
|
||||
try {
|
||||
String url = druidDataSource.getUrl();
|
||||
|
||||
@@ -158,7 +158,7 @@
|
||||
from dual
|
||||
</select>
|
||||
<select id="getHighGoSequence" resultType="java.lang.Object">
|
||||
select ${tableName}_seq.nextval
|
||||
select nextval('${tableName}_seq')
|
||||
</select>
|
||||
<insert id="createSequence">
|
||||
CREATE
|
||||
@@ -209,8 +209,31 @@
|
||||
VALUES
|
||||
<foreach collection="list" item="row" separator=",">
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<foreach collection="row" item="value">
|
||||
#{value},
|
||||
<foreach collection="row" item="value" separator=",">
|
||||
#{value}
|
||||
</foreach>
|
||||
</trim>
|
||||
</foreach>
|
||||
</insert>
|
||||
<insert id="insertBatchSeq" parameterType="map">
|
||||
INSERT INTO ${tableName}
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<foreach collection="list[0].keySet()" item="column" separator=",">
|
||||
${column}
|
||||
</foreach>
|
||||
</trim>
|
||||
VALUES
|
||||
<foreach collection="list" item="row" separator=",">
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<foreach collection="row" item="value" index="key" separator=",">
|
||||
<choose>
|
||||
<when test="key == pkName">
|
||||
${value}
|
||||
</when>
|
||||
<otherwise>
|
||||
#{value}
|
||||
</otherwise>
|
||||
</choose>
|
||||
</foreach>
|
||||
</trim>
|
||||
</foreach>
|
||||
|
||||
Reference in New Issue
Block a user