Skip to content

Commit

Permalink
Parallel for travel (#170)
Browse files Browse the repository at this point in the history
* style for TravelService

* style for TravelService

* travel: add travel parallel api
  • Loading branch information
xiya.wu committed Sep 2, 2021
1 parent 2ab3207 commit 350f620
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 77 deletions.
95 changes: 49 additions & 46 deletions ts-travel-service/pom.xml
Original file line number Diff line number Diff line change
@@ -1,50 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>fdse.microservice</groupId>
<artifactId>ts-travel-service</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<name>ts-travel-service</name>
<description>ts-travel-service</description>

<parent>
<groupId>org.services</groupId>
<artifactId>ts-service</artifactId>
<version>0.1.0</version>
<relativePath>../</relativePath>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.services</groupId>
<artifactId>ts-common</artifactId>
<version>0.1.0</version>
</dependency>


</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>fdse.microservice</groupId>
<artifactId>ts-travel-service</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<name>ts-travel-service</name>
<description>ts-travel-service</description>

<parent>
<groupId>org.services</groupId>
<artifactId>ts-service</artifactId>
<version>0.1.0</version>
<relativePath>../</relativePath>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.services</groupId>
<artifactId>ts-common</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.skywalking</groupId>
<artifactId>apm-toolkit-trace</artifactId>
<version>8.6.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public String home(@RequestHeader HttpHeaders headers) {
public HttpEntity getTrainTypeByTripId(@PathVariable String tripId,
@RequestHeader HttpHeaders headers) {
// TrainType
TravelController.LOGGER.info("Get train Type by Trip id,TripId: {}",tripId);
TravelController.LOGGER.info("Get train Type by Trip id,TripId: {}", tripId);
return ok(travelService.getTrainTypeByTripId(tripId, headers));
}

Expand All @@ -53,53 +53,53 @@ public HttpEntity getRouteByTripId(@PathVariable String tripId,
public HttpEntity getTripsByRouteId(@RequestBody ArrayList<String> routeIds,
@RequestHeader HttpHeaders headers) {
// ArrayList<ArrayList<Trip>>
TravelController.LOGGER.info("Get Trips by Route ids,RouteIds: {}",routeIds.size());
TravelController.LOGGER.info("Get Trips by Route ids,RouteIds: {}", routeIds.size());
return ok(travelService.getTripByRoute(routeIds, headers));
}

@CrossOrigin(origins = "*")
@PostMapping(value = "/trips")
public HttpEntity<?> createTrip(@RequestBody TravelInfo routeIds, @RequestHeader HttpHeaders headers) {
// null
TravelController.LOGGER.info("Create trip,TripId: {}",routeIds.getTripId());
TravelController.LOGGER.info("Create trip,TripId: {}", routeIds.getTripId());
return new ResponseEntity<>(travelService.create(routeIds, headers), HttpStatus.CREATED);
}

/**
* Return Trip only, no left ticket information
*
* @param tripId trip id
* @param tripId trip id
* @param headers headers
* @return HttpEntity
*/
@CrossOrigin(origins = "*")
@GetMapping(value = "/trips/{tripId}")
public HttpEntity retrieve(@PathVariable String tripId, @RequestHeader HttpHeaders headers) {
// Trip
TravelController.LOGGER.info("Retrieve trip,TripId: {}",tripId);
TravelController.LOGGER.info("Retrieve trip,TripId: {}", tripId);
return ok(travelService.retrieve(tripId, headers));
}

@CrossOrigin(origins = "*")
@PutMapping(value = "/trips")
public HttpEntity updateTrip(@RequestBody TravelInfo info, @RequestHeader HttpHeaders headers) {
// Trip
TravelController.LOGGER.info("Update trip,TripId: {}",info.getTripId());
TravelController.LOGGER.info("Update trip,TripId: {}", info.getTripId());
return ok(travelService.update(info, headers));
}

@CrossOrigin(origins = "*")
@DeleteMapping(value = "/trips/{tripId}")
public HttpEntity deleteTrip(@PathVariable String tripId, @RequestHeader HttpHeaders headers) {
// string
TravelController.LOGGER.info("Delete trip,TripId: {}",tripId);
TravelController.LOGGER.info("Delete trip,TripId: {}", tripId);
return ok(travelService.delete(tripId, headers));
}

/**
* Return Trips and the remaining tickets
*
* @param info trip info
* @param info trip info
* @param headers headers
* @return HttpEntity
*/
Expand All @@ -117,10 +117,31 @@ public HttpEntity queryInfo(@RequestBody TripInfo info, @RequestHeader HttpHeade
return ok(travelService.query(info, headers));
}

/**
* Return Trips and the remaining tickets
*
* @param info trip info
* @param headers headers
* @return HttpEntity
*/
@CrossOrigin(origins = "*")
@PostMapping(value = "/trips/left_parallel")
public HttpEntity queryInfoInparallel(@RequestBody TripInfo info, @RequestHeader HttpHeaders headers) {
if (info.getStartingPlace() == null || info.getStartingPlace().length() == 0 ||
info.getEndPlace() == null || info.getEndPlace().length() == 0 ||
info.getDepartureTime() == null) {
TravelController.LOGGER.info("[[Travel Query] Fail.Something null.");
ArrayList<TripResponse> errorList = new ArrayList<>();
return ok(errorList);
}
TravelController.LOGGER.info(" Query TripResponse");
return ok(travelService.queryInParallel(info, headers));
}

/**
* Return a Trip and the remaining
*
* @param gtdi trip all detail info
* @param gtdi trip all detail info
* @param headers headers
* @return HttpEntity
*/
Expand All @@ -129,7 +150,7 @@ public HttpEntity queryInfo(@RequestBody TripInfo info, @RequestHeader HttpHeade
public HttpEntity getTripAllDetailInfo(@RequestBody TripAllDetailInfo gtdi, @RequestHeader HttpHeaders headers) {
// TripAllDetailInfo
// TripAllDetail tripAllDetail
TravelController.LOGGER.info("Get trip detail,TripId: {}",gtdi.getTripId());
TravelController.LOGGER.info("Get trip detail,TripId: {}", gtdi.getTripId());
return ok(travelService.getTripAllDetailInfo(gtdi, headers));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.ArrayList;

/**
* @author Chenjie Xu
* @author Chenjie Xu
* @date 2017/5/9.
*/
public interface TravelService {
Expand All @@ -22,6 +22,8 @@ public interface TravelService {

Response query(TripInfo info, HttpHeaders headers);

Response queryInParallel(TripInfo info, HttpHeaders headers);

Response getTripAllDetailInfo(TripAllDetailInfo gtdi, HttpHeaders headers);

Response getRouteByTripId(String tripId, HttpHeaders headers);
Expand All @@ -30,7 +32,7 @@ public interface TravelService {

Response queryAll(HttpHeaders headers);

Response getTripByRoute(ArrayList<String> routeIds, HttpHeaders headers);
Response getTripByRoute(ArrayList<String> routeIds, HttpHeaders headers);

Response adminQueryAll(HttpHeaders headers);
}
Loading

0 comments on commit 350f620

Please sign in to comment.