2727
2828import jakarta .servlet .AsyncContext ;
2929import jakarta .servlet .ServletResponse ;
30+ import org .apache .commons .text .StringSubstitutor ;
3031import org .jetbrains .annotations .NotNull ;
3132import org .springframework .beans .factory .annotation .Autowired ;
3233import org .springframework .http .*;
@@ -2234,11 +2235,34 @@ public static void init(boolean shutdownWhenServerError, APIJSONCreator<?, ? ext
22342235 // onServerError("服务器内部错误,Document 表中的 id=" + JSON.getString(item, "id") + ", name=" + JSON.getString(item, "name") + ", url=" + url + " 对应 url 值错误!只允许合法的 URL 格式!", shutdownWhenServerError);
22352236 //}
22362237 } else {
2237- sqlauto = StringUtil .trim (sqlauto );
2238- List <Map <String , Object >> mapList = newMap .get (sqlauto );
2238+ String sql = StringUtil .trim (sqlauto );
2239+
2240+ String header = JSON .getString (item , "header" );
2241+ String [] args = StringUtil .split (header , "\n " );
2242+ if (args != null ) {
2243+ Map <String , String > valuesMap = new LinkedHashMap <>();
2244+
2245+ for (int j = 0 ; j < args .length ; j ++) {
2246+ String arg = StringUtil .trim (args [j ]);
2247+ int ind = arg .startsWith ("//" ) || arg .startsWith ("#" ) || arg .startsWith ("--" ) ? -1 : arg .indexOf (": " );
2248+ String key = ind <= 0 ? null : arg .substring (0 , ind );
2249+ if (StringUtil .isEmpty (key )) {
2250+ continue ;
2251+ }
2252+
2253+ valuesMap .put (key , "?" );
2254+ }
2255+
2256+ if (! valuesMap .isEmpty ()) {
2257+ StringSubstitutor sub = new StringSubstitutor (valuesMap );
2258+ sql = sub .replace (sqlauto );
2259+ }
2260+ }
2261+
2262+ List <Map <String , Object >> mapList = newMap .get (sql );
22392263 if (mapList == null ) {
22402264 mapList = new ArrayList <>();
2241- newMap .put (sqlauto , mapList );
2265+ newMap .put (sql , mapList );
22422266 }
22432267 mapList .add (item );
22442268 }
@@ -2329,9 +2353,9 @@ public String execute(@RequestBody String request, HttpSession session) {
23292353 }
23302354 }
23312355
2332- String trimmedSQL = sql == null ? null : sql .trim ();
2356+ String trimmedSQL = sql .trim ();
23332357
2334- String sqlPrefix = trimmedSQL == null || trimmedSQL .length () < 7 ? "" : trimmedSQL .substring (0 , 7 ).toUpperCase ();
2358+ String sqlPrefix = trimmedSQL .length () < 7 ? "" : trimmedSQL .substring (0 , 7 ).toUpperCase ();
23352359 boolean isInsert = sqlPrefix .startsWith ("INSERT " );
23362360 boolean isWrite = isInsert || sqlPrefix .startsWith ("UPDATE " ) || sqlPrefix .startsWith ("DELETE " );
23372361 if (WRITE_STRICTLY && isWrite && ! isInsert ) {
@@ -2349,7 +2373,7 @@ public String execute(@RequestBody String request, HttpSession session) {
23492373 List <Map <String , Object >> list = sqlauto .equalsIgnoreCase (trimmedSQL ) ? entry .getValue () : null ;
23502374 if (list != null && ! list .isEmpty ()) {
23512375 find = list ;
2352- Log .d (TAG , "execute find DELETE/UPDATE rows = " + JSON .toJSONString (find , true ));
2376+ Log .d (TAG , "execute " + sql + " : find match rows = " + JSON .toJSONString (find , true ));
23532377 break ;
23542378 }
23552379 }
0 commit comments