diff --git a/src/main/java/org/leolo/nrapi/v0/api/ScheduleSearchAPI.java b/src/main/java/org/leolo/nrapi/v0/api/ScheduleSearchAPI.java index e7bd561..b8cbce0 100644 --- a/src/main/java/org/leolo/nrapi/v0/api/ScheduleSearchAPI.java +++ b/src/main/java/org/leolo/nrapi/v0/api/ScheduleSearchAPI.java @@ -66,10 +66,10 @@ public class ScheduleSearchAPI { queryBuilder.setPlatforms(platform.split(",")); } if(previous!=null&&previous.length()>0){ - queryBuilder.setPrevLocation(previous); + queryBuilder.setPrevLocation(previous.split(",")); } if(next!=null&&next.length()>0){ - queryBuilder.setNextLocation(next); + queryBuilder.setNextLocation(next.split(",")); } list.addAll(queryBuilder.setTableGroup(TableGroup.LONG_TERM_PLANNING).execute()); list.addAll(queryBuilder.setTableGroup(TableGroup.SHORT_TERM_PLANNING).execute()); diff --git a/src/main/java/org/leolo/nrapi/v0/api/ScheduleSearchQueryBuilder.java b/src/main/java/org/leolo/nrapi/v0/api/ScheduleSearchQueryBuilder.java index 5ed5324..7de1f81 100644 --- a/src/main/java/org/leolo/nrapi/v0/api/ScheduleSearchQueryBuilder.java +++ b/src/main/java/org/leolo/nrapi/v0/api/ScheduleSearchQueryBuilder.java @@ -32,8 +32,8 @@ class ScheduleSearchQueryBuilder { private boolean strictMode = false; private String[] platforms; private boolean stopOnly = false; - private String prevLocation; - private String nextLocation; + private String[] prevLocation; + private String[] nextLocation; public ScheduleSearchQueryBuilder setTableGroup(TableGroup tableGroup) { this.tableGroup = tableGroup; @@ -76,12 +76,12 @@ class ScheduleSearchQueryBuilder { return this; } - public ScheduleSearchQueryBuilder setPrevLocation(String prevLocation) { + public ScheduleSearchQueryBuilder setPrevLocation(String... prevLocation) { this.prevLocation = prevLocation; return this; } - public ScheduleSearchQueryBuilder setNextLocation(String nextLocation) { + public ScheduleSearchQueryBuilder setNextLocation(String... nextLocation) { this.nextLocation = nextLocation; return this; } @@ -98,10 +98,10 @@ class ScheduleSearchQueryBuilder { sql.append("origin_time, get_tiploc_name(destination), destination_time, mt.signal_id, mt.atoc_code "); sql.append(" from ").append(tableGroup.getMainTable()).append(" mt ") .append(" JOIN ").append(tableGroup.getDetailTable()).append(" dt ON mt.suid=dt.suid "); - if(prevLocation!=null&&prevLocation.length()!=0){ + if(prevLocation!=null){ sql.append(" JOIN ").append(tableGroup.getDetailTable()).append(" pt ON mt.suid=pt.suid AND dt.seq > pt.seq"); } - if(nextLocation!=null&&nextLocation.length()!=0){ + if(nextLocation!=null){ sql.append(" JOIN ").append(tableGroup.getDetailTable()).append(" nt ON mt.suid=nt.suid AND dt.seq < nt.seq"); } sql.append(" where dt.tiploc_code IN ("); @@ -136,15 +136,23 @@ class ScheduleSearchQueryBuilder { } sql.append(")"); } - if(prevLocation!=null&&prevLocation.length()!=0){ - sql.append(" AND pt.tiploc_code IN ("); - appendLocationSearch(sql, params, prevLocation); - sql.append(") "); + if(prevLocation!=null){ + sql.append(" AND ( 1=0 "); + for(String prev:prevLocation){ + sql.append(" OR pt.tiploc_code IN ("); + appendLocationSearch(sql, params, prev); + sql.append(")"); + } + sql.append(")"); } - if(nextLocation!=null&&nextLocation.length()!=0){ - sql.append(" AND nt.tiploc_code IN ("); - appendLocationSearch(sql, params, nextLocation); - sql.append(") "); + if(nextLocation!=null){ + sql.append(" AND ( 1=0 "); + for(String next:nextLocation){ + sql.append(" OR nt.tiploc_code IN ("); + appendLocationSearch(sql, params, next); + sql.append(")"); + } + sql.append(")"); } log.info(sql.toString()); diff --git a/src/main/resources/static/docs/schedule_search.html b/src/main/resources/static/docs/schedule_search.html index 4919faa..cbf14e9 100644 --- a/src/main/resources/static/docs/schedule_search.html +++ b/src/main/resources/static/docs/schedule_search.html @@ -9,7 +9,13 @@
| previous | ++ Optional. + Only show the train previously calls, or passing though the specified locations. The location is provided + in a comma separated list. + | +
|---|---|
| previous | ++ Optional. + Only show the train will also call, or passing though the specified locations. The location is provided + in a comma separated list. + |