Error with package path

This commit is contained in:
Philipp 2020-06-10 14:51:12 +02:00
parent 3775f96f3f
commit f671baf7f0
9 changed files with 180 additions and 17 deletions

View File

@ -4,6 +4,7 @@ package org.hso.ecommerce.supplier;
import org.hso.ecommerce.supplier.data.Delivery;
import org.hso.ecommerce.supplier.data.DeliveryManager;
import org.hso.ecommerce.supplier.data.ReturnStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
@ -22,7 +23,7 @@ public class RequestController {
return delivery.getUuid().toString();
}
@GetMapping("/status")
@GetMapping(value = "/status", produces = MediaType.APPLICATION_JSON_VALUE)
public ReturnStatus searchArticles(@RequestParam(value = "trackingID") String trackingID, HttpServletRequest request, HttpServletResponse response) {
Delivery delivery = DeliveryManager.getInstance().getDeliveryByeID(trackingID);

View File

@ -0,0 +1,84 @@
package org.hso.ecommerce.action.shop;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.hso.ecommerce.controller.intern.customers.CustomerOrderController;
import org.hso.ecommerce.entities.shop.CustomerOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import java.util.*;
@Service
public class RestServiceForDelivery {
@Autowired
private RestTemplateBuilder restTemplateBuilder;
public String getDeliveryID(CustomerOrder customerOrder)
{
String url = "http://[::1]:8082/newDelivery";
RestTemplate restTemplate = restTemplateBuilder.build();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
Map<String, String> requestBody = new HashMap<>();
requestBody.put("name",customerOrder.destination.name);
requestBody.put("address",customerOrder.destination.addressString);
HttpEntity<Map<String, String>> entity = new HttpEntity<>(requestBody,headers);
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST,entity, String.class);
if (response.getStatusCode() == HttpStatus.OK)
{
return response.getBody();
} else {
return null;
}
}
public CustomerOrderController.DeliveryData getDeliveryData(UUID trackingID) {
String url = "http://[::1]:8082/status";
RestTemplate restTemplate = restTemplateBuilder.build();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url).queryParam("trackingID",trackingID.toString());
HttpEntity<?> entity = new HttpEntity<>(headers);
ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
ObjectMapper mapper = new ObjectMapper();
JsonNode node = null;
try {
node = mapper.readTree(response.getBody());
} catch (JsonProcessingException e) {
e.printStackTrace();
}
if (response.getStatusCode() == HttpStatus.OK)
{
return new CustomerOrderController.DeliveryData(node.get("status").asText(),node.get("estimatedArrival").asText());
} else {
return null;
}
}
}

View File

@ -1,15 +1,26 @@
package org.hso.ecommerce.controller.intern.customers;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.hibernate.Session;
import org.hso.ecommerce.action.shop.RestServiceForDelivery;
import org.hso.ecommerce.entities.shop.CustomerOrder;
import org.hso.ecommerce.repos.shop.CustomerOderRepository;
import org.hso.ecommerce.repos.user.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@Controller
@RequestMapping("intern/customerOrders")
@ -21,7 +32,12 @@ public class CustomerOrderController {
@GetMapping("")
public String internCustomerOrder(Model model) {
List<CustomerOrder> orders = customerOrderRepository.getAllOrders();
model.addAttribute("orders", orders);
Map<CustomerOrder, DeliveryData> customerOrderDeliveryDataMap = orders.stream().collect
(Collectors.toMap
(Function.identity(), this::getDeliveryDataFromCustomerOrder));
model.addAttribute("orderDeliveryDataMap", customerOrderDeliveryDataMap);
return "intern/customerOrders/index";
}
@ -30,9 +46,64 @@ public class CustomerOrderController {
@PathVariable("id") String id
) {
CustomerOrder order = customerOrderRepository.findById(Long.parseLong(id)).get();
DeliveryData deliveryData = getDeliveryDataFromCustomerOrder(order);
model.addAttribute("order", order);
model.addAttribute("deliveryData", deliveryData);
return "intern/customerOrders/id";
}
private DeliveryData getDeliveryDataFromCustomerOrder(CustomerOrder customerOrder)
{
if(customerOrder.trackingId == null)
return new CustomerOrderController.DeliveryData("Bestellung wurde elektronisch angekündigt","");
if(customerOrder.deliveredAt == null)
{
DeliveryData deliveryData = new RestServiceForDelivery(new RestTemplateBuilder()).getDeliveryData(UUID.fromString(customerOrder.trackingId));
if(deliveryData.isDelivered())
{
customerOrderRepository.updateUserDeliveredAt(customerOrder.id, Timestamp.valueOf(deliveryData.estimatedArrival));
System.out.println(Timestamp.valueOf(deliveryData.estimatedArrival));
}
return deliveryData;
}
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
return new CustomerOrderController.DeliveryData("Lieferung erfolgreich",formatter.format(customerOrder.deliveredAt));
}
public static class DeliveryData
{
@JsonProperty("status")
private String status;
@JsonProperty("estimatedArrival")
private String estimatedArrival;
private boolean isDelivered;
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
public DeliveryData(String status, String estimatedArrival) {
this.status = status;
System.out.println(status);
this.estimatedArrival = estimatedArrival;
isDelivered = status.equals("Lieferung erfolgreich");
}
public boolean isDelivered() {
return isDelivered;
}
public String getStatus() {
return status;
}
public String getEstimatedArrival() {
return estimatedArrival;
}
}
}

View File

@ -136,7 +136,7 @@ public class ShopCheckoutController {
CreateOrderAction.Result result = null;
try {
result = action.finish();
EnableTrackingAction.addTrackingInfo(result.customerOrder);
//EnableTrackingAction.addTrackingInfo(result.customerOrder);
customerOderRepository.save(result.customerOrder);
bookingRepository.saveAll(result.bookings);

View File

@ -31,7 +31,7 @@ public class CustomerOrder {
@NotNull
public java.sql.Timestamp created;
@NotNull
@Column(nullable = true)
public String trackingId;
@Column(nullable = true)

View File

@ -2,6 +2,7 @@ package org.hso.ecommerce.repos.shop;
import org.hso.ecommerce.entities.shop.CustomerOrder;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
@ -17,5 +18,9 @@ public interface CustomerOderRepository extends JpaRepository<CustomerOrder, Lon
@Query("SELECT co FROM CustomerOrder co ORDER BY co.created DESC")
List<CustomerOrder> getAllOrders();
@Modifying(clearAutomatically = true)
@Query("UPDATE CustomerOrder co SET co.deliveredAt = :newDeliveredAt WHERE co.id = :customerOrderID")
int updateUserDeliveredAt(long customerOrderID, java.sql.Timestamp newDeliveredAt);
}

View File

@ -2,17 +2,19 @@ package org.hso.ecommerce.repos.user;
import org.hso.ecommerce.entities.user.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.Optional;
import static jdk.nashorn.internal.runtime.regexp.joni.Syntax.Java;
@Repository
public interface UserRepository extends JpaRepository<User, Long> {
@Query("SELECT c FROM User c WHERE c.email = :email")
Optional<User> findByEmail(String email);
}

View File

@ -34,12 +34,13 @@
</tr>
<tr>
<th>Lieferstatus</th>
<td th:if="${order.deliveredAt == null}"><b>Unterwegs</b> <br/> Vorraussichtliche Ankunft: <span th:text="${order.getEstimatedArrival()}" /></td>
<td th:if="${order.deliveredAt != null}"><b>Angekommen</b> <br/> Ankunft: <span th:text="${order.deliveredAt.toString().substring(0,10)}" /></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 th:if="${order.deliveredAt != null && order.trackingId!=null}"><b>Angekommen</b> Ankunft: <span th:text="${deliveryData.getEstimatedArrival()}" /></tr>
</tr>
<tr>
<th>Sendeverfolgungsnummer</th>
<td th:text="${order.trackingId}"></td>
<td th:text="${order.trackingId!=null} ? ${order.trackingId} : 'Es wurde noch keine Sendungsnummer vergeben'"></td>
</tr>
<tr>
<th></th>

View File

@ -40,14 +40,13 @@
<th>Status</th>
<th></th>
</tr>
<tr th:each="order: ${orders}">
<td><a th:href="@{/intern/customers/{id}(id=${order.customer.id})}" th:text="${order.customer.id}">101</a></td>
<td th:text="${order.id}"></td>
<td th:text="${order.created.toString().substring(0, 10)}"></td>
<td th:text="${#numbers.formatDecimal(order.totalGrossCent * 0.01, 1, 'POINT', 2, 'COMMA')}"></td>
<td th:if="${order.deliveredAt == null}">In Zustellung</td>
<td th:if="${order.deliveredAt != null}">Zugestellt</td>
<td><a th:href="@{/intern/customerOrders/{id}(id=${order.id})}" class="button smaller">Details</a></td>
<tr th:each="order: ${orderDeliveryDataMap}">
<td><a th:href="@{/intern/customers/{id}(id=${order.getKey().customer.id})}" th:text="${order.getKey().customer.id}">101</a></td>
<td th:text="${order.getKey().id}"></td>
<td th:text="${order.getKey().created.toString().substring(0, 10)}"></td>
<td th:text="${#numbers.formatDecimal(order.getKey().totalGrossCent * 0.01, 1, 'POINT', 2, 'COMMA')}"></td>
<td th:text="${order.getValue().getStatus()}"></td>
<td><a th:href="@{/intern/customerOrders/{id}(id=${order.getKey().id})}" class="button smaller">Details</a></td>
</tr>
</table>
</p>