impl tracking ID
This commit is contained in:
parent
f671baf7f0
commit
ebeba72278
@ -1,4 +1,4 @@
|
|||||||
package org.hso.ecommerce.action.shop;
|
package org.hso.ecommerce.api;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
@ -19,8 +19,8 @@ import java.util.*;
|
|||||||
public class RestServiceForDelivery {
|
public class RestServiceForDelivery {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RestTemplateBuilder restTemplateBuilder;
|
private final RestTemplateBuilder restTemplateBuilder = null;
|
||||||
|
|
||||||
|
|
||||||
public String getDeliveryID(CustomerOrder customerOrder)
|
public String getDeliveryID(CustomerOrder customerOrder)
|
||||||
{
|
{
|
||||||
@ -61,20 +61,11 @@ public class RestServiceForDelivery {
|
|||||||
|
|
||||||
HttpEntity<?> entity = new HttpEntity<>(headers);
|
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||||
|
|
||||||
ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
|
ResponseEntity<CustomerOrderController.DeliveryData> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, CustomerOrderController.DeliveryData.class);
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
JsonNode node = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
node = mapper.readTree(response.getBody());
|
|
||||||
} catch (JsonProcessingException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response.getStatusCode() == HttpStatus.OK)
|
if (response.getStatusCode() == HttpStatus.OK)
|
||||||
{
|
{
|
||||||
return new CustomerOrderController.DeliveryData(node.get("status").asText(),node.get("estimatedArrival").asText());
|
return response.getBody();
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,12 @@ package org.hso.ecommerce.app;
|
|||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||||
|
import org.springframework.context.ConfigurableApplicationContext;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@ComponentScan(basePackages = {"org.hso.ecommerce"})
|
@ComponentScan(basePackages = {"org.hso.ecommerce"})
|
||||||
@EntityScan("org.hso.ecommerce")
|
@EntityScan("org.hso.ecommerce")
|
||||||
@ -13,6 +16,7 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
|||||||
public class Application {
|
public class Application {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
SpringApplication.run(Application.class, args);
|
SpringApplication.run(Application.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,21 +2,21 @@ package org.hso.ecommerce.controller.intern.customers;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import org.hibernate.Session;
|
import org.hso.ecommerce.api.RestServiceForDelivery;
|
||||||
import org.hso.ecommerce.action.shop.RestServiceForDelivery;
|
|
||||||
import org.hso.ecommerce.entities.shop.CustomerOrder;
|
import org.hso.ecommerce.entities.shop.CustomerOrder;
|
||||||
import org.hso.ecommerce.repos.shop.CustomerOderRepository;
|
import org.hso.ecommerce.repos.shop.CustomerOderRepository;
|
||||||
import org.hso.ecommerce.repos.user.UserRepository;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
import org.springframework.format.datetime.DateFormatterRegistrar;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
import javax.transaction.Transaction;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@ -28,6 +28,8 @@ public class CustomerOrderController {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private final CustomerOderRepository customerOrderRepository = null;
|
private final CustomerOderRepository customerOrderRepository = null;
|
||||||
|
@Autowired
|
||||||
|
private final RestServiceForDelivery restServiceForDelivery = null;
|
||||||
|
|
||||||
@GetMapping("")
|
@GetMapping("")
|
||||||
public String internCustomerOrder(Model model) {
|
public String internCustomerOrder(Model model) {
|
||||||
@ -61,12 +63,21 @@ public class CustomerOrderController {
|
|||||||
|
|
||||||
if(customerOrder.deliveredAt == null)
|
if(customerOrder.deliveredAt == null)
|
||||||
{
|
{
|
||||||
DeliveryData deliveryData = new RestServiceForDelivery(new RestTemplateBuilder()).getDeliveryData(UUID.fromString(customerOrder.trackingId));
|
DeliveryData deliveryData = restServiceForDelivery.getDeliveryData(UUID.fromString(customerOrder.trackingId));
|
||||||
|
|
||||||
if(deliveryData.isDelivered())
|
if(deliveryData.isDelivered())
|
||||||
{
|
{
|
||||||
customerOrderRepository.updateUserDeliveredAt(customerOrder.id, Timestamp.valueOf(deliveryData.estimatedArrival));
|
Calendar calendar = Calendar.getInstance();
|
||||||
System.out.println(Timestamp.valueOf(deliveryData.estimatedArrival));
|
|
||||||
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MM-yyyy");
|
||||||
|
|
||||||
|
try {
|
||||||
|
calendar.setTime(simpleDateFormat.parse(deliveryData.estimatedArrival));
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
customerOrderRepository.updateUserDeliveredAt(customerOrder.id, new Timestamp(calendar.getTimeInMillis()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return deliveryData;
|
return deliveryData;
|
||||||
@ -78,17 +89,16 @@ public class CustomerOrderController {
|
|||||||
|
|
||||||
public static class DeliveryData
|
public static class DeliveryData
|
||||||
{
|
{
|
||||||
@JsonProperty("status")
|
|
||||||
private String status;
|
private final String status;
|
||||||
@JsonProperty("estimatedArrival")
|
|
||||||
private String estimatedArrival;
|
private final String estimatedArrival;
|
||||||
|
|
||||||
private boolean isDelivered;
|
private boolean isDelivered;
|
||||||
|
|
||||||
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
|
||||||
public DeliveryData(String status, String estimatedArrival) {
|
public DeliveryData(String status, String estimatedArrival) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
System.out.println(status);
|
|
||||||
this.estimatedArrival = estimatedArrival;
|
this.estimatedArrival = estimatedArrival;
|
||||||
isDelivered = status.equals("Lieferung erfolgreich");
|
isDelivered = status.equals("Lieferung erfolgreich");
|
||||||
}
|
}
|
||||||
|
@ -43,9 +43,4 @@ public class CustomerOrder {
|
|||||||
public int totalNetCent;
|
public int totalNetCent;
|
||||||
public int totalGrossCent;
|
public int totalGrossCent;
|
||||||
public int totalVatCent;
|
public int totalVatCent;
|
||||||
|
|
||||||
public String getEstimatedArrival() {
|
|
||||||
//TODO: get estimated arrival from api
|
|
||||||
return "TODO TODO TODO";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
|||||||
import org.springframework.data.jpa.repository.Modifying;
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -19,6 +20,7 @@ public interface CustomerOderRepository extends JpaRepository<CustomerOrder, Lon
|
|||||||
@Query("SELECT co FROM CustomerOrder co ORDER BY co.created DESC")
|
@Query("SELECT co FROM CustomerOrder co ORDER BY co.created DESC")
|
||||||
List<CustomerOrder> getAllOrders();
|
List<CustomerOrder> getAllOrders();
|
||||||
|
|
||||||
|
@Transactional
|
||||||
@Modifying(clearAutomatically = true)
|
@Modifying(clearAutomatically = true)
|
||||||
@Query("UPDATE CustomerOrder co SET co.deliveredAt = :newDeliveredAt WHERE co.id = :customerOrderID")
|
@Query("UPDATE CustomerOrder co SET co.deliveredAt = :newDeliveredAt WHERE co.id = :customerOrderID")
|
||||||
int updateUserDeliveredAt(long customerOrderID, java.sql.Timestamp newDeliveredAt);
|
int updateUserDeliveredAt(long customerOrderID, java.sql.Timestamp newDeliveredAt);
|
||||||
|
@ -35,8 +35,11 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Lieferstatus</th>
|
<th>Lieferstatus</th>
|
||||||
<td th:text="${deliveryData.getStatus()}"></td>
|
<td th:text="${deliveryData.getStatus()}"></td>
|
||||||
<tr th:if="${order.deliveredAt == null && order.trackingId!=null}">Vorraussichtliche Ankunft: <span th:text="${deliveryData.getEstimatedArrival()}" /></tr>
|
</tr>
|
||||||
<tr th:if="${order.deliveredAt != null && order.trackingId!=null}"><b>Angekommen</b> Ankunft: <span th:text="${deliveryData.getEstimatedArrival()}" /></tr>
|
<tr>
|
||||||
|
<td></td>
|
||||||
|
<td th:if="${order.deliveredAt == null && order.trackingId!=null}">Vorraussichtliche Ankunft: <span th:text="${deliveryData.getEstimatedArrival()}" /></td>
|
||||||
|
<td th:if="${order.deliveredAt != null && order.trackingId!=null}"><b>Angekommen</b> Ankunft: <span th:text="${deliveryData.getEstimatedArrival()}" /></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Sendeverfolgungsnummer</th>
|
<th>Sendeverfolgungsnummer</th>
|
||||||
|
Reference in New Issue
Block a user