|
@@ -1,6 +1,7 @@
|
|
package com.boman.web.core.mapper;
|
|
package com.boman.web.core.mapper;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.boman.common.core.utils.obj.ObjectUtils;
|
|
import com.boman.web.core.utils.ColumnUtils;
|
|
import com.boman.web.core.utils.ColumnUtils;
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -62,6 +63,10 @@ public interface StandardlyMapper {
|
|
)
|
|
)
|
|
int insert(@Param("tableName") String var1, @Param("model") JSONObject var2);
|
|
int insert(@Param("tableName") String var1, @Param("model") JSONObject var2);
|
|
|
|
|
|
|
|
+ /** {@link SqlProvider#insertList(Map)} */
|
|
|
|
+ @InsertProvider(type = SqlProvider.class,method = "insertList")
|
|
|
|
+ int insertList(@Param("tableName") String tableName, @Param("dataList") List<JSONObject> dataList);
|
|
|
|
+
|
|
@InsertProvider(
|
|
@InsertProvider(
|
|
type = SqlProvider.class,
|
|
type = SqlProvider.class,
|
|
method = "inserts"
|
|
method = "inserts"
|
|
@@ -341,6 +346,39 @@ public interface StandardlyMapper {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public String insertList(Map<String, Object> para) {
|
|
|
|
+ List<JSONObject> dataList = (List<JSONObject>) para.get("dataList");
|
|
|
|
+ String tableName = (String) para.get("tableName");
|
|
|
|
+ if (isNullOrEmpty(tableName)) {
|
|
|
|
+ throw new IllegalArgumentException("tableName 无效");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (ObjectUtils.isEmpty(dataList)) {
|
|
|
|
+ throw new IllegalArgumentException("需要插入的数据为空");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
|
+ stringBuilder.append("insert into ").append(tableName).append(" ( ");
|
|
|
|
+ JSONObject keySet = dataList.get(0);
|
|
|
|
+ stringBuilder.append(String.join(", ", keySet.keySet()));
|
|
|
|
+ stringBuilder.append(" ) ").append("values ");
|
|
|
|
+
|
|
|
|
+ for (JSONObject data : dataList) {
|
|
|
|
+ StringBuilder values = new StringBuilder();
|
|
|
|
+ values.append(" ( ");
|
|
|
|
+ for (Map.Entry<String, Object> entry : data.entrySet()) {
|
|
|
|
+ values.append("#{model.").append(entry.getKey()).append("}, ");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String beforeLast = StringUtils.substringBeforeLast(values.toString(), ", ");
|
|
|
|
+ stringBuilder.append(beforeLast).append(" ) ");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String sqlStr = stringBuilder.toString();
|
|
|
|
+ LOGGER.info("批量新增的sql语句为: {}, \r\n 新增的数据为: {}", sqlStr, dataList);
|
|
|
|
+ return sqlStr;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
public String updateByIdList(Map<String, Object> para) {
|
|
public String updateByIdList(Map<String, Object> para) {
|
|
String tableName = (String) para.get("tableName");
|
|
String tableName = (String) para.get("tableName");
|