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