| Line 49... |
Line 49... |
| 49 |
import org.apache.http.impl.client.HttpClients;
|
49 |
import org.apache.http.impl.client.HttpClients;
|
| 50 |
import org.apache.logging.log4j.LogManager;
|
50 |
import org.apache.logging.log4j.LogManager;
|
| 51 |
import org.apache.logging.log4j.Logger;
|
51 |
import org.apache.logging.log4j.Logger;
|
| 52 |
import org.json.JSONArray;
|
52 |
import org.json.JSONArray;
|
| 53 |
import org.json.JSONObject;
|
53 |
import org.json.JSONObject;
|
| - |
|
54 |
import org.json.XML;
|
| 54 |
import org.springframework.beans.factory.annotation.Autowired;
|
55 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 55 |
import org.springframework.beans.factory.annotation.Qualifier;
|
56 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 56 |
import org.springframework.beans.factory.annotation.Value;
|
57 |
import org.springframework.beans.factory.annotation.Value;
|
| 57 |
import org.springframework.core.io.ByteArrayResource;
|
58 |
import org.springframework.core.io.ByteArrayResource;
|
| 58 |
import org.springframework.core.io.InputStreamSource;
|
59 |
import org.springframework.core.io.InputStreamSource;
|
| Line 3361... |
Line 3362... |
| 3361 |
if (status.equals("Delivered")) {
|
3362 |
if (status.equals("Delivered")) {
|
| 3362 |
airwaybillStatus.add(awb);
|
3363 |
airwaybillStatus.add(awb);
|
| 3363 |
}
|
3364 |
}
|
| 3364 |
|
3365 |
|
| 3365 |
}
|
3366 |
}
|
| - |
|
3367 |
markOrderDelivered(airwaybillStatus);
|
| - |
|
3368 |
}
|
| - |
|
3369 |
}
|
| - |
|
3370 |
|
| - |
|
3371 |
public void markBlueDartOrderDelivered() throws ProfitMandiBusinessException, IOException {
|
| - |
|
3372 |
|
| - |
|
3373 |
String loginId = "DEL81122";
|
| - |
|
3374 |
|
| - |
|
3375 |
String licencekey = "uhfhlg2jpmnqfhfrlsgzfr1nhu1qfvel";
|
| - |
|
3376 |
|
| - |
|
3377 |
List<Order> orders = orderRepository.selectOrderByProviderIdAndStatus(ProfitMandiConstants.BLUEDART_PROVIDERID,
|
| - |
|
3378 |
OrderStatus.SHIPPED_FROM_WH);
|
| - |
|
3379 |
|
| 3366 |
if (!airwaybillStatus.isEmpty()) {
|
3380 |
if (!orders.isEmpty()) {
|
| 3367 |
for (String aws : airwaybillStatus) {
|
3381 |
String airwayBillNo = "81007630141";
|
| - |
|
3382 |
|
| - |
|
3383 |
// Set<String> airwayBillNo = orders.stream().map(x ->
|
| - |
|
3384 |
// x.getAirwayBillNumber()).collect(Collectors.toSet());
|
| 3368 |
|
3385 |
|
| 3369 |
List<Order> deliverdOrders = orderRepository.selectByAirwayBillNumber(aws);
|
- |
|
| 3370 |
for (Order dlo : deliverdOrders) {
|
3386 |
LOGGER.info("airwayBill" + airwayBillNo);
|
| 3371 |
dlo.setStatus(OrderStatus.DELIVERY_SUCCESS);
|
3387 |
String url = "https://api.bluedart.com/servlet/RoutingServlet?handler=tnt&action=custawbquery";
|
| - |
|
3388 |
|
| 3372 |
dlo.setStatusDescription("Order Delivered");
|
3389 |
String response = restClient.get(url + "&loginid=" + loginId + "&awb=awb&numbers="
|
| 3373 |
dlo.setDeliveryTimestamp(LocalDateTime.now());
|
3390 |
+ String.join(",", airwayBillNo) + "&format=xml&lickey=" + licencekey + "&verno=1.3&scan=1", null,
|
| 3374 |
}
|
3391 |
null);
|
| 3375 |
|
3392 |
|
| 3376 |
com.spice.profitmandi.dao.entity.user.User user = userUserRepository
|
- |
|
| 3377 |
.selectById(orders.get(0).getRetailerId());
|
3393 |
JSONObject updateJson = XML.toJSONObject(response);
|
| 3378 |
|
3394 |
|
| 3379 |
Address address = addressRepository.selectById(user.getAddressId());
|
3395 |
JSONObject shipmentData = updateJson.getJSONObject("ShipmentData");
|
| 3380 |
|
- |
|
| 3381 |
String title = "Order Delivered";
|
3396 |
Object shipmentObject = shipmentData.get("Shipment");
|
| 3382 |
|
3397 |
|
| 3383 |
String message = String.format("Dear partner, Your SmartDukaan Order " + aws
|
- |
|
| 3384 |
+ " has been delivered to you in a safe sealed bag.");
|
3398 |
Set<String> airwaybillStatus = new HashSet<>();
|
| 3385 |
|
3399 |
|
| 3386 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
3400 |
if (shipmentObject instanceof JSONArray) {
|
| 3387 |
sendNotificationModel.setCampaignName("Order Delivered");
|
3401 |
JSONArray shipments = (JSONArray) shipmentObject;
|
| 3388 |
sendNotificationModel.setTitle(title);
|
3402 |
for (int i = 0; i < shipments.length(); i++) {
|
| 3389 |
sendNotificationModel.setMessage(message);
|
3403 |
JSONObject jsonObject = shipments.getJSONObject(i);
|
| - |
|
3404 |
|
| 3390 |
sendNotificationModel.setType("url");
|
3405 |
Number awb = jsonObject.getNumber("WaybillNo");
|
| 3391 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
- |
|
| 3392 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
- |
|
| 3393 |
sendNotificationModel.setMessageType(MessageType.notification);
|
3406 |
String status = jsonObject.getString("Status");
|
| 3394 |
int userId = userAccountRepository.selectUserIdByRetailerId(orders.get(0).getRetailerId());
|
- |
|
| - |
|
3407 |
|
| 3395 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
3408 |
if (status.equals("SHIPMENT DELIVERED")) {
|
| 3396 |
notificationService.sendNotification(sendNotificationModel);
|
3409 |
airwaybillStatus.add(awb.toString());
|
| - |
|
3410 |
}
|
| 3397 |
|
3411 |
|
| - |
|
3412 |
}
|
| - |
|
3413 |
} else {
|
| - |
|
3414 |
JSONObject jsonObject = (JSONObject) shipmentObject;
|
| - |
|
3415 |
Number awb = jsonObject.getNumber("WaybillNo");
|
| 3398 |
notificationService.sendWhatsappMessage(message, title, address.getPhoneNumber());
|
3416 |
String status = jsonObject.getString("Status");
|
| 3399 |
|
3417 |
|
| - |
|
3418 |
if (status.equals("SHIPMENT DELIVERED")) {
|
| - |
|
3419 |
airwaybillStatus.add(awb.toString());
|
| 3400 |
}
|
3420 |
}
|
| - |
|
3421 |
|
| 3401 |
}
|
3422 |
}
|
| 3402 |
|
3423 |
|
| - |
|
3424 |
LOGGER.info("airwaybillStatus" + airwaybillStatus);
|
| - |
|
3425 |
|
| - |
|
3426 |
// markOrderDelivered(airwaybillStatus);
|
| - |
|
3427 |
}
|
| - |
|
3428 |
|
| - |
|
3429 |
}
|
| - |
|
3430 |
|
| - |
|
3431 |
private void markOrderDelivered(Set<String> airwaybillStatus)
|
| - |
|
3432 |
throws ProfitMandiBusinessException, HttpHostConnectException {
|
| - |
|
3433 |
if (!airwaybillStatus.isEmpty()) {
|
| - |
|
3434 |
for (String aws : airwaybillStatus) {
|
| - |
|
3435 |
|
| - |
|
3436 |
List<Order> deliverdOrders = orderRepository.selectByAirwayBillNumber(aws);
|
| - |
|
3437 |
|
| - |
|
3438 |
int fofoId = deliverdOrders.get(0).getRetailerId();
|
| - |
|
3439 |
for (Order dlo : deliverdOrders) {
|
| - |
|
3440 |
dlo.setStatus(OrderStatus.DELIVERY_SUCCESS);
|
| - |
|
3441 |
dlo.setStatusDescription("Order Delivered");
|
| - |
|
3442 |
dlo.setDeliveryTimestamp(LocalDateTime.now());
|
| - |
|
3443 |
}
|
| - |
|
3444 |
|
| - |
|
3445 |
com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(fofoId);
|
| - |
|
3446 |
|
| - |
|
3447 |
Address address = addressRepository.selectById(user.getAddressId());
|
| - |
|
3448 |
|
| - |
|
3449 |
String title = "Order Delivered";
|
| - |
|
3450 |
|
| - |
|
3451 |
String message = String.format("Dear partner, Your SmartDukaan Order " + aws
|
| - |
|
3452 |
+ " has been delivered to you in a safe sealed bag.");
|
| - |
|
3453 |
|
| - |
|
3454 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
| - |
|
3455 |
sendNotificationModel.setCampaignName("Order Delivered");
|
| - |
|
3456 |
sendNotificationModel.setTitle(title);
|
| - |
|
3457 |
sendNotificationModel.setMessage(message);
|
| - |
|
3458 |
sendNotificationModel.setType("url");
|
| - |
|
3459 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
| - |
|
3460 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
| - |
|
3461 |
sendNotificationModel.setMessageType(MessageType.notification);
|
| - |
|
3462 |
int userId = userAccountRepository.selectUserIdByRetailerId(fofoId);
|
| - |
|
3463 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
| - |
|
3464 |
notificationService.sendNotification(sendNotificationModel);
|
| - |
|
3465 |
|
| - |
|
3466 |
notificationService.sendWhatsappMessage(message, title, address.getPhoneNumber());
|
| - |
|
3467 |
|
| - |
|
3468 |
}
|
| 3403 |
}
|
3469 |
}
|
| 3404 |
}
|
3470 |
}
|
| 3405 |
|
3471 |
|
| 3406 |
public void partnerWiseCreditAccount() throws Exception {
|
3472 |
public void partnerWiseCreditAccount() throws Exception {
|
| 3407 |
|
3473 |
|