| 29349 |
tejbeer |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.util.ArrayList;
|
|
|
4 |
import java.util.HashSet;
|
|
|
5 |
import java.util.List;
|
|
|
6 |
import java.util.Set;
|
|
|
7 |
|
|
|
8 |
import javax.servlet.http.HttpServletRequest;
|
|
|
9 |
import javax.servlet.http.HttpServletResponse;
|
|
|
10 |
|
|
|
11 |
import org.apache.logging.log4j.LogManager;
|
|
|
12 |
import org.apache.logging.log4j.Logger;
|
|
|
13 |
import org.json.JSONArray;
|
|
|
14 |
import org.json.JSONObject;
|
|
|
15 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
16 |
import org.springframework.beans.factory.annotation.Value;
|
|
|
17 |
import org.springframework.http.MediaType;
|
|
|
18 |
import org.springframework.http.ResponseEntity;
|
|
|
19 |
import org.springframework.stereotype.Controller;
|
|
|
20 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
21 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
22 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
23 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
24 |
|
|
|
25 |
import com.eclipsesource.json.JsonArray;
|
|
|
26 |
import com.spice.profitmandi.common.model.CustomNotifyOrder;
|
|
|
27 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
28 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
|
|
29 |
import com.spice.profitmandi.dao.entity.transaction.NotifyCancel;
|
|
|
30 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
|
|
31 |
import com.spice.profitmandi.model.tracking.ScannedDetailModel;
|
|
|
32 |
import com.spice.profitmandi.model.tracking.TrackingDetailModel;
|
|
|
33 |
|
|
|
34 |
import in.shop2020.model.v1.order.OrderStatus;
|
|
|
35 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
36 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
37 |
import okhttp3.OkHttpClient;
|
|
|
38 |
import okhttp3.Request;
|
|
|
39 |
import okhttp3.Response;
|
|
|
40 |
|
|
|
41 |
@Controller
|
|
|
42 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
43 |
public class TrackingController {
|
|
|
44 |
|
|
|
45 |
@Value("${delhivery.tracking.token}")
|
|
|
46 |
private String token;
|
|
|
47 |
|
|
|
48 |
@Autowired
|
|
|
49 |
private ResponseSender<?> responseSender;
|
|
|
50 |
|
|
|
51 |
private static final Logger LOGGER = LogManager.getLogger(TrackingController.class);
|
|
|
52 |
|
|
|
53 |
@RequestMapping(value = "/order/tracking", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
54 |
@ApiImplicitParams({
|
|
|
55 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
56 |
public ResponseEntity<?> getNotifyCancelOrders(HttpServletRequest request, HttpServletResponse response,
|
|
|
57 |
@RequestParam String airwayBillNo) throws Throwable {
|
|
|
58 |
|
|
|
59 |
String url = "https://track.delhivery.com/api/v1/packages/json/";
|
|
|
60 |
|
|
|
61 |
OkHttpClient client = new OkHttpClient();
|
|
|
62 |
|
|
|
63 |
Request request1 = new Request.Builder()
|
|
|
64 |
.url(url + "?waybill=" + String.join(",", airwayBillNo) + "&token=" + token).get().build();
|
|
|
65 |
|
|
|
66 |
LOGGER.info("request1" + request1);
|
|
|
67 |
|
|
|
68 |
Response response1 = client.newCall(request1).execute();
|
|
|
69 |
|
|
|
70 |
LOGGER.info("jsonbj" + response1.body());
|
|
|
71 |
|
|
|
72 |
JSONObject jsonObj = new JSONObject(response1.body().string());
|
|
|
73 |
|
|
|
74 |
LOGGER.info("jsonObj" + jsonObj);
|
|
|
75 |
|
|
|
76 |
JSONArray shipmentData = jsonObj.getJSONArray("ShipmentData");
|
|
|
77 |
|
|
|
78 |
TrackingDetailModel tdm = new TrackingDetailModel();
|
|
|
79 |
|
|
|
80 |
List<ScannedDetailModel> sdms = new ArrayList<>();
|
|
|
81 |
|
|
|
82 |
for (int i = 0; i < shipmentData.length(); i++) {
|
|
|
83 |
JSONObject jsonObject = shipmentData.getJSONObject(i);
|
|
|
84 |
JSONObject shipment = jsonObject.getJSONObject("Shipment");
|
|
|
85 |
|
|
|
86 |
JSONArray scans = shipment.getJSONArray("Scans");
|
|
|
87 |
|
|
|
88 |
for (int j = 0; j < scans.length(); j++) {
|
|
|
89 |
JSONObject scanObject = scans.getJSONObject(j);
|
|
|
90 |
|
|
|
91 |
JSONObject scandetails = scanObject.getJSONObject("ScanDetail");
|
|
|
92 |
|
|
|
93 |
ScannedDetailModel sdm = new ScannedDetailModel();
|
|
|
94 |
sdm.setStatusDateTime(scandetails.getString("ScanDateTime"));
|
|
|
95 |
sdm.setStatusLocation(scandetails.getString("ScannedLocation"));
|
|
|
96 |
sdm.setInstruction(scandetails.getString("Instructions"));
|
|
|
97 |
sdms.add(sdm);
|
|
|
98 |
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
tdm.setExpectedDelivery(shipment.getString("ExpectedDeliveryDate"));
|
|
|
102 |
tdm.setAwb(shipment.getString("AWB"));
|
|
|
103 |
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
tdm.setSdm(sdms);
|
|
|
107 |
LOGGER.info("tdm" + tdm);
|
|
|
108 |
|
|
|
109 |
return responseSender.ok(tdm);
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
}
|