Browse Source

Allow filtering by more than 1 location for previous and next

develop
LO Kam Tao Leo 3 years ago
parent
commit
404a744f07
  1. 4
      src/main/java/org/leolo/nrapi/v0/api/ScheduleSearchAPI.java
  2. 32
      src/main/java/org/leolo/nrapi/v0/api/ScheduleSearchQueryBuilder.java
  3. 27
      src/main/resources/static/docs/schedule_search.html

4
src/main/java/org/leolo/nrapi/v0/api/ScheduleSearchAPI.java

@ -66,10 +66,10 @@ public class ScheduleSearchAPI {
queryBuilder.setPlatforms(platform.split(",")); queryBuilder.setPlatforms(platform.split(","));
} }
if(previous!=null&&previous.length()>0){ if(previous!=null&&previous.length()>0){
queryBuilder.setPrevLocation(previous); queryBuilder.setPrevLocation(previous.split(","));
} }
if(next!=null&&next.length()>0){ 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.LONG_TERM_PLANNING).execute());
list.addAll(queryBuilder.setTableGroup(TableGroup.SHORT_TERM_PLANNING).execute()); list.addAll(queryBuilder.setTableGroup(TableGroup.SHORT_TERM_PLANNING).execute());

32
src/main/java/org/leolo/nrapi/v0/api/ScheduleSearchQueryBuilder.java

@ -32,8 +32,8 @@ class ScheduleSearchQueryBuilder {
private boolean strictMode = false; private boolean strictMode = false;
private String[] platforms; private String[] platforms;
private boolean stopOnly = false; private boolean stopOnly = false;
private String prevLocation; private String[] prevLocation;
private String nextLocation; private String[] nextLocation;
public ScheduleSearchQueryBuilder setTableGroup(TableGroup tableGroup) { public ScheduleSearchQueryBuilder setTableGroup(TableGroup tableGroup) {
this.tableGroup = tableGroup; this.tableGroup = tableGroup;
@ -76,12 +76,12 @@ class ScheduleSearchQueryBuilder {
return this; return this;
} }
public ScheduleSearchQueryBuilder setPrevLocation(String prevLocation) { public ScheduleSearchQueryBuilder setPrevLocation(String... prevLocation) {
this.prevLocation = prevLocation; this.prevLocation = prevLocation;
return this; return this;
} }
public ScheduleSearchQueryBuilder setNextLocation(String nextLocation) { public ScheduleSearchQueryBuilder setNextLocation(String... nextLocation) {
this.nextLocation = nextLocation; this.nextLocation = nextLocation;
return this; 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("origin_time, get_tiploc_name(destination), destination_time, mt.signal_id, mt.atoc_code ");
sql.append(" from ").append(tableGroup.getMainTable()).append(" mt ") sql.append(" from ").append(tableGroup.getMainTable()).append(" mt ")
.append(" JOIN ").append(tableGroup.getDetailTable()).append(" dt ON mt.suid=dt.suid "); .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"); 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(" JOIN ").append(tableGroup.getDetailTable()).append(" nt ON mt.suid=nt.suid AND dt.seq < nt.seq");
} }
sql.append(" where dt.tiploc_code IN ("); sql.append(" where dt.tiploc_code IN (");
@ -136,14 +136,22 @@ class ScheduleSearchQueryBuilder {
} }
sql.append(")"); sql.append(")");
} }
if(prevLocation!=null&&prevLocation.length()!=0){ if(prevLocation!=null){
sql.append(" AND pt.tiploc_code IN ("); sql.append(" AND ( 1=0 ");
appendLocationSearch(sql, params, prevLocation); for(String prev:prevLocation){
sql.append(" OR pt.tiploc_code IN (");
appendLocationSearch(sql, params, prev);
sql.append(")");
}
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(")");
} }
if(nextLocation!=null&&nextLocation.length()!=0){
sql.append(" AND nt.tiploc_code IN (");
appendLocationSearch(sql, params, nextLocation);
sql.append(")"); sql.append(")");
} }

27
src/main/resources/static/docs/schedule_search.html

@ -9,7 +9,13 @@
<body> <body>
<h1>Search train schedule by location</h1> <h1>Search train schedule by location</h1>
<h2>Syntax</h2> <h2>Syntax</h2>
<div class="syntax">/search/{location}[/{date}[/{time}]]?[range={range}][&amp;strict={strict}][&amp;stopOnly={stopOnly}]</div> <div class="syntax">/search/{location}[/{date}[/{time}]]?
[range={range}]
[&amp;strict={strict}]
[&amp;stopOnly={stopOnly}]
[&amp;previous={previous}]
[&amp;next={next}]
</div>
<h3>Parameters</h3> <h3>Parameters</h3>
<table class="param"> <table class="param">
<tr> <tr>
@ -64,6 +70,25 @@
<span style="font-weight: bold">Optional.</span> <span style="font-weight: bold">Optional.</span>
Show only stopping trains. Valid valued are <code>true</code> or <code>false</code>. Default value is Show only stopping trains. Valid valued are <code>true</code> or <code>false</code>. Default value is
<code>false</code>. <code>false</code>.
This value will also affect the <code>previous</code> and <code>next</code> settings.
</td>
</tr>
<tr>
<th>previous</th>
<td>
<span style="font-weight: bold">Optional.</span>
Only show the train previously calls, or passing though the specified locations. The location is provided
in a comma separated list.
</td>
</tr>
<tr>
<th>previous</th>
<td>
<span style="font-weight: bold">Optional.</span>
Only show the train will also call, or passing though the specified locations. The location is provided
in a comma separated list.
</td> </td>
</tr> </tr>
</table> </table>

Loading…
Cancel
Save