|
@@ -193,6 +193,17 @@ public interface StandardlyMapper {
|
|
@Select("select * from ${tableName} order by create_time desc limit 1")
|
|
@Select("select * from ${tableName} order by create_time desc limit 1")
|
|
JSONObject getNewest(@Param("tableName") String tableName);
|
|
JSONObject getNewest(@Param("tableName") String tableName);
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 功能描述: 通用删除数据 {@link SqlProvider#delete(java.util.Map)}
|
|
|
|
+ *
|
|
|
|
+ * @param tableName tableName
|
|
|
|
+ * @param condition condition
|
|
|
|
+ * @param packColCondition packColCondition
|
|
|
|
+ * @return int
|
|
|
|
+ */
|
|
|
|
+ @SelectProvider(type = SqlProvider.class, method = "delete")
|
|
|
|
+ Integer delete(@Param("tableName") String tableName, @Param("condition") JSONObject condition, @Param("packColCondition") JSONObject packColCondition);
|
|
|
|
+
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
class SqlProvider {
|
|
class SqlProvider {
|
|
static final String[] READONLY_COLUMNS = new String[]{"OWNERID", "OWNERNAME", "OWNERENAME", "CREATIONDATE", "ID"};
|
|
static final String[] READONLY_COLUMNS = new String[]{"OWNERID", "OWNERNAME", "OWNERENAME", "CREATIONDATE", "ID"};
|
|
@@ -443,34 +454,18 @@ public interface StandardlyMapper {
|
|
}
|
|
}
|
|
|
|
|
|
public String delete(Map<String, Object> para) {
|
|
public String delete(Map<String, Object> para) {
|
|
- 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)) {
|
|
|
|
- throw new IllegalArgumentException("tableName 无效");
|
|
|
|
- } else if (ids == null) {
|
|
|
|
- throw new IllegalArgumentException("ids 无效");
|
|
|
|
- } else if (ids.length == 0) {
|
|
|
|
- return "";
|
|
|
|
- } else if (ids.length == 1) {
|
|
|
|
- return "DELETE FROM " + tableName + " where " + pkName + " = #{ids[0]}";
|
|
|
|
- } else {
|
|
|
|
- StringBuffer sql = new StringBuffer();
|
|
|
|
- sql.append("DELETE FROM ");
|
|
|
|
- sql.append(tableName);
|
|
|
|
- sql.append(" WHERE ");
|
|
|
|
- sql.append(pkName + " in (");
|
|
|
|
|
|
+ JSONObject condition = (JSONObject) para.get("condition");
|
|
|
|
+ JSONObject packColCondition = (JSONObject) para.get("packColCondition");
|
|
|
|
|
|
- for (int i = 0; i < ids.length; ++i) {
|
|
|
|
- sql.append(String.format("#{ids[%d]}", i));
|
|
|
|
- sql.append(",");
|
|
|
|
- }
|
|
|
|
|
|
+ StringBuilder sql = new StringBuilder();
|
|
|
|
+ sql.append("DELETE FROM ");
|
|
|
|
+ sql.append(tableName);
|
|
|
|
+ packCondition(packColCondition, sql);
|
|
|
|
|
|
- sql.setCharAt(sql.length() - 1, ')');
|
|
|
|
- String sqlStr = sql.toString();
|
|
|
|
- LOGGER.info("删除的sql语句为: {} \r\n idList: {}", sqlStr, ids);
|
|
|
|
- return sqlStr;
|
|
|
|
- }
|
|
|
|
|
|
+ String sqlStr = sql.toString();
|
|
|
|
+ LOGGER.info("通用删除的sql语句为: {} \r\n condition: {}", sqlStr, condition);
|
|
|
|
+ return sqlStr;
|
|
}
|
|
}
|
|
|
|
|
|
public String updates(Map<String, Object> para) {
|
|
public String updates(Map<String, Object> para) {
|