|
@@ -3,6 +3,7 @@ package com.boman.system.mapper;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.ibatis.annotations.*;
|
|
import org.apache.ibatis.annotations.*;
|
|
|
|
+import org.apache.ibatis.annotations.Param;
|
|
import org.apache.ibatis.jdbc.SQL;
|
|
import org.apache.ibatis.jdbc.SQL;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -26,7 +27,8 @@ public interface StandardlyMapper {
|
|
type = StandardlyMapper.SqlProvider.class,
|
|
type = StandardlyMapper.SqlProvider.class,
|
|
method = "update"
|
|
method = "update"
|
|
)
|
|
)
|
|
- int updateById(@Param("tableName") String var1, @Param("model") JSONObject var2);
|
|
|
|
|
|
+ int updateById(@Param("tableName") String var1, @Param("model") JSONObject var2
|
|
|
|
+ , @Param("pkName") String pkName, @Param("ids") Long[] ids);
|
|
|
|
|
|
@UpdateProvider(
|
|
@UpdateProvider(
|
|
type = StandardlyMapper.SqlProvider.class,
|
|
type = StandardlyMapper.SqlProvider.class,
|
|
@@ -39,7 +41,7 @@ public interface StandardlyMapper {
|
|
type = StandardlyMapper.SqlProvider.class,
|
|
type = StandardlyMapper.SqlProvider.class,
|
|
method = "delete"
|
|
method = "delete"
|
|
)
|
|
)
|
|
- int deleteByIds(@Param("tableName") String var1, @Param("ids") long[] var2);
|
|
|
|
|
|
+ int deleteByIds(@Param("tableName") String var1, @Param("ids") Long[] var2, @Param("pkName") String pkName);
|
|
|
|
|
|
@Delete({"DELETE FROM ${tableName} where ID = #{id}"})
|
|
@Delete({"DELETE FROM ${tableName} where ID = #{id}"})
|
|
int deleteById(@Param("tableName") String var1, @Param("id") long var2);
|
|
int deleteById(@Param("tableName") String var1, @Param("id") long var2);
|
|
@@ -130,24 +132,34 @@ public interface StandardlyMapper {
|
|
public String update(Map<String, Object> para) {
|
|
public String update(Map<String, Object> para) {
|
|
String tableName = (String) para.get("tableName");
|
|
String tableName = (String) para.get("tableName");
|
|
JSONObject model = (JSONObject) para.get("model");
|
|
JSONObject model = (JSONObject) para.get("model");
|
|
- //if (isNullOrEmpty(tableName)) {
|
|
|
|
|
|
+ String pkName = (String) para.get("pkName");
|
|
|
|
+ Long[] ids = (Long[]) para.get("ids");
|
|
if (StringUtils.isBlank(tableName)) {
|
|
if (StringUtils.isBlank(tableName)) {
|
|
throw new IllegalArgumentException("tableName 无效");
|
|
throw new IllegalArgumentException("tableName 无效");
|
|
} else if (!model.isEmpty()) {
|
|
} else if (!model.isEmpty()) {
|
|
keyToUpper(model);
|
|
keyToUpper(model);
|
|
SQL sql = new SQL();
|
|
SQL sql = new SQL();
|
|
sql.UPDATE(tableName);
|
|
sql.UPDATE(tableName);
|
|
- Iterator var5 = model.keySet().iterator();
|
|
|
|
|
|
|
|
- while (var5.hasNext()) {
|
|
|
|
- String key = (String) var5.next();
|
|
|
|
|
|
+ // 拼装set
|
|
|
|
+ model.forEach((key, value)->{
|
|
if (!isReadOnly(key)) {
|
|
if (!isReadOnly(key)) {
|
|
- sql.SET(key + "= #{model." + key + "}");
|
|
|
|
|
|
+ // 此处需要对value加一个""
|
|
|
|
+ sql.SET(key + " = \"" + value + "\"");
|
|
}
|
|
}
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // 拼装in
|
|
|
|
+ StringBuilder inSql = new StringBuilder();
|
|
|
|
+ for (int i = 0; i < ids.length; ++i) {
|
|
|
|
+ inSql.append(String.format("#{ids[%d]}", i));
|
|
|
|
+ inSql.append(",");
|
|
}
|
|
}
|
|
|
|
|
|
- sql.WHERE("ID = #{model.ID}");
|
|
|
|
- return sql.toString();
|
|
|
|
|
|
+ sql.WHERE(pkName + " in (" + inSql.toString());
|
|
|
|
+ String wholeSql = StringUtils.substringBeforeLast(sql.toString(), ",") + "))";
|
|
|
|
+ LOGGER.info("更改的sql语句为: {}", wholeSql);
|
|
|
|
+ return wholeSql;
|
|
} else {
|
|
} else {
|
|
throw new IllegalArgumentException("model 无效");
|
|
throw new IllegalArgumentException("model 无效");
|
|
}
|
|
}
|
|
@@ -224,14 +236,15 @@ public interface StandardlyMapper {
|
|
}
|
|
}
|
|
|
|
|
|
String sqlStr = sql.toString();
|
|
String sqlStr = sql.toString();
|
|
- LOGGER.info("新增拼接的sql语句为: {}", sqlStr);
|
|
|
|
|
|
+ LOGGER.info("新增的sql语句为: {}", sqlStr);
|
|
return sqlStr;
|
|
return sqlStr;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public String delete(Map<String, Object> para) {
|
|
public String delete(Map<String, Object> para) {
|
|
- long[] ids = (long[]) ((long[]) para.get("ids"));
|
|
|
|
|
|
+ Long[] ids = (Long[]) para.get("ids");
|
|
String tableName = (String) para.get("tableName");
|
|
String tableName = (String) para.get("tableName");
|
|
|
|
+ String pkName = (String) para.get("pkName");
|
|
if (isNullOrEmpty(tableName)) {
|
|
if (isNullOrEmpty(tableName)) {
|
|
throw new IllegalArgumentException("tableName 无效");
|
|
throw new IllegalArgumentException("tableName 无效");
|
|
} else if (ids == null) {
|
|
} else if (ids == null) {
|
|
@@ -239,13 +252,13 @@ public interface StandardlyMapper {
|
|
} else if (ids.length == 0) {
|
|
} else if (ids.length == 0) {
|
|
return "";
|
|
return "";
|
|
} else if (ids.length == 1) {
|
|
} else if (ids.length == 1) {
|
|
- return "DELETE FROM " + tableName + " where ID = #{ids[0]}";
|
|
|
|
|
|
+ return "DELETE FROM " + tableName + " where " + pkName + " = #{ids[0]}";
|
|
} else {
|
|
} else {
|
|
StringBuffer sql = new StringBuffer();
|
|
StringBuffer sql = new StringBuffer();
|
|
sql.append("DELETE FROM ");
|
|
sql.append("DELETE FROM ");
|
|
sql.append(tableName);
|
|
sql.append(tableName);
|
|
sql.append(" WHERE ");
|
|
sql.append(" WHERE ");
|
|
- sql.append("ID in (");
|
|
|
|
|
|
+ sql.append(pkName + " in (");
|
|
|
|
|
|
for (int i = 0; i < ids.length; ++i) {
|
|
for (int i = 0; i < ids.length; ++i) {
|
|
sql.append(String.format("#{ids[%d]}", i));
|
|
sql.append(String.format("#{ids[%d]}", i));
|
|
@@ -253,7 +266,9 @@ public interface StandardlyMapper {
|
|
}
|
|
}
|
|
|
|
|
|
sql.setCharAt(sql.length() - 1, ')');
|
|
sql.setCharAt(sql.length() - 1, ')');
|
|
- return sql.toString();
|
|
|
|
|
|
+ String sqlStr = sql.toString();
|
|
|
|
+ LOGGER.info("删除的sql语句为: {}", sqlStr);
|
|
|
|
+ return sqlStr;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -360,7 +375,9 @@ public interface StandardlyMapper {
|
|
}
|
|
}
|
|
|
|
|
|
sql.deleteCharAt(sql.length() - 1);
|
|
sql.deleteCharAt(sql.length() - 1);
|
|
- return sql.toString();
|
|
|
|
|
|
+ String sqlStr = sql.toString();
|
|
|
|
+ LOGGER.info("更新的sql语句为: {}", sqlStr);
|
|
|
|
+ return sqlStr;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
throw new IllegalArgumentException("model 无效");
|
|
throw new IllegalArgumentException("model 无效");
|