|
@@ -1,6 +1,7 @@
|
|
|
package com.boman.web.core.mapper;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.boman.common.core.utils.obj.ObjectUtils;
|
|
|
import com.boman.web.core.utils.ColumnUtils;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -62,6 +63,10 @@ public interface StandardlyMapper {
|
|
|
)
|
|
|
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(
|
|
|
type = SqlProvider.class,
|
|
|
method = "inserts"
|
|
@@ -88,6 +93,10 @@ public interface StandardlyMapper {
|
|
|
int updateByIdList(@Param("tableName") String tableName, @Param("pkName") String pkName
|
|
|
, @Param("idList") List<Long> idList, @Param("model") JSONObject models);
|
|
|
|
|
|
+ @UpdateProvider(type = SqlProvider.class, method = "updateByForeignKey")
|
|
|
+ int updateByForeignKey(@Param("tableName") String tableName, @Param("foreignKeyName") String foreignKeyName
|
|
|
+ , @Param("foreignKeyList") List<Long> foreignKeyList, @Param("model") JSONObject models);
|
|
|
+
|
|
|
@Select("select id from ${tableName} where ${akColumnName} = #{akColumnValue}")
|
|
|
Long selectIdByAkColumn(@Param("tableName") String tableName, @Param("akColumnName") String akColumnName, @Param("akColumnValue") String akColumnValue);
|
|
|
|
|
@@ -341,6 +350,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) {
|
|
|
String tableName = (String) para.get("tableName");
|
|
@@ -371,6 +413,35 @@ public interface StandardlyMapper {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public String updateByForeignKey(Map<String, Object> para) {
|
|
|
+ String tableName = (String) para.get("tableName");
|
|
|
+ String foreignKeyName = (String) para.get("foreignKeyName");
|
|
|
+ List<Long> foreignKeyList = (List<Long>) para.get("foreignKeyList");
|
|
|
+ JSONObject models = (JSONObject) para.get("model");
|
|
|
+
|
|
|
+ StringBuilder wholeSql = new StringBuilder();
|
|
|
+ wholeSql.append("update ").append(tableName).append(" set ");
|
|
|
+ for (Map.Entry<String, Object> entry : models.entrySet()) {
|
|
|
+ String key = entry.getKey();
|
|
|
+ Object value = entry.getValue();
|
|
|
+ wholeSql.append(key).append(covert(EQ, CHAR, key, value)).append(" , ");
|
|
|
+ }
|
|
|
+
|
|
|
+ wholeSql = new StringBuilder(StringUtils.substringBeforeLast(wholeSql.toString(), ","));
|
|
|
+ wholeSql.append(" where ").append(foreignKeyName).append(" in ( ");
|
|
|
+
|
|
|
+ for (Long id : foreignKeyList) {
|
|
|
+ wholeSql.append(id);
|
|
|
+ wholeSql.append(",");
|
|
|
+ }
|
|
|
+
|
|
|
+ wholeSql.setCharAt(wholeSql.length() - 1, ')');
|
|
|
+ String sqlStr = wholeSql.toString();
|
|
|
+ LOGGER.info("批量更新的sql语句为: {}, \r\n 更改的数据为: {}, \r\n foreignKeyList: {}", sqlStr, models, foreignKeyList);
|
|
|
+ return sqlStr;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
public String delete(Map<String, Object> para) {
|
|
|
Long[] ids = (Long[]) para.get("ids");
|
|
|
String tableName = (String) para.get("tableName");
|