| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| - |
|
3 |
import java.io.IOException;
|
| 3 |
import java.time.LocalDate;
|
4 |
import java.time.LocalDate;
|
| 4 |
import java.time.LocalDateTime;
|
5 |
import java.time.LocalDateTime;
|
| 5 |
import java.time.temporal.ChronoUnit;
|
6 |
import java.time.temporal.ChronoUnit;
|
| 6 |
import java.util.ArrayList;
|
7 |
import java.util.ArrayList;
|
| 7 |
import java.util.Arrays;
|
8 |
import java.util.Arrays;
|
| 8 |
import java.util.List;
|
9 |
import java.util.List;
|
| 9 |
|
10 |
|
| 10 |
import javax.servlet.http.HttpServletRequest;
|
11 |
import javax.servlet.http.HttpServletRequest;
|
| 11 |
import javax.servlet.http.HttpServletResponse;
|
12 |
import javax.servlet.http.HttpServletResponse;
|
| 12 |
|
13 |
|
| - |
|
14 |
import org.apache.http.conn.HttpHostConnectException;
|
| 13 |
import org.apache.logging.log4j.LogManager;
|
15 |
import org.apache.logging.log4j.LogManager;
|
| 14 |
import org.apache.logging.log4j.Logger;
|
16 |
import org.apache.logging.log4j.Logger;
|
| 15 |
import org.apache.thrift.TException;
|
17 |
import org.apache.thrift.TException;
|
| 16 |
import org.json.JSONArray;
|
18 |
import org.json.JSONArray;
|
| 17 |
import org.json.JSONObject;
|
19 |
import org.json.JSONObject;
|
| - |
|
20 |
import org.json.XML;
|
| 18 |
import org.springframework.beans.factory.annotation.Autowired;
|
21 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 19 |
import org.springframework.beans.factory.annotation.Value;
|
22 |
import org.springframework.beans.factory.annotation.Value;
|
| 20 |
import org.springframework.http.MediaType;
|
23 |
import org.springframework.http.MediaType;
|
| 21 |
import org.springframework.http.ResponseEntity;
|
24 |
import org.springframework.http.ResponseEntity;
|
| 22 |
import org.springframework.stereotype.Controller;
|
25 |
import org.springframework.stereotype.Controller;
|
| 23 |
import org.springframework.transaction.annotation.Transactional;
|
26 |
import org.springframework.transaction.annotation.Transactional;
|
| 24 |
import org.springframework.web.bind.annotation.RequestMapping;
|
27 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 25 |
import org.springframework.web.bind.annotation.RequestMethod;
|
28 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 26 |
import org.springframework.web.bind.annotation.RequestParam;
|
29 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 27 |
|
30 |
|
| - |
|
31 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 28 |
import com.spice.profitmandi.common.model.CustomOrder;
|
32 |
import com.spice.profitmandi.common.model.CustomOrder;
|
| - |
|
33 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 29 |
import com.spice.profitmandi.common.model.TrackingModel;
|
34 |
import com.spice.profitmandi.common.model.TrackingModel;
|
| - |
|
35 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 30 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
36 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 31 |
import com.spice.profitmandi.dao.entity.logistics.Provider;
|
37 |
import com.spice.profitmandi.dao.entity.logistics.Provider;
|
| 32 |
import com.spice.profitmandi.dao.entity.logistics.ProviderTat;
|
38 |
import com.spice.profitmandi.dao.entity.logistics.ProviderTat;
|
| 33 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
39 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| 34 |
import com.spice.profitmandi.dao.model.ProductPojo;
|
40 |
import com.spice.profitmandi.dao.model.ProductPojo;
|
| Line 76... |
Line 82... |
| 76 |
private String loginId;
|
82 |
private String loginId;
|
| 77 |
|
83 |
|
| 78 |
@Value("#{'${prod}'=='true' ? '9sjnjt61hghmtjuvjio0osqkmujkphlt' : 'poehq2kiqjnllkrote9hxglo4teptfqf'}")
|
84 |
@Value("#{'${prod}'=='true' ? '9sjnjt61hghmtjuvjio0osqkmujkphlt' : 'poehq2kiqjnllkrote9hxglo4teptfqf'}")
|
| 79 |
private String licencekey;
|
85 |
private String licencekey;
|
| 80 |
|
86 |
|
| - |
|
87 |
@Autowired
|
| - |
|
88 |
private RestClient restClient;
|
| - |
|
89 |
|
| 81 |
private static final Logger LOGGER = LogManager.getLogger(TrackingController.class);
|
90 |
private static final Logger LOGGER = LogManager.getLogger(TrackingController.class);
|
| 82 |
|
91 |
|
| 83 |
@RequestMapping(value = "/order/tracking", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
92 |
@RequestMapping(value = "/order/tracking", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 84 |
@ApiImplicitParams({
|
93 |
@ApiImplicitParams({
|
| 85 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
94 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 86 |
public ResponseEntity<?> getDeliveryOrder(HttpServletRequest request, HttpServletResponse response,
|
95 |
public ResponseEntity<?> getDeliveryOrder(HttpServletRequest request, HttpServletResponse response,
|
| 87 |
@RequestParam String airwayBillNo) throws Throwable {
|
96 |
@RequestParam String airwayBillNo) throws Throwable {
|
| 88 |
|
97 |
|
| - |
|
98 |
List<Order> orders = orderRepository.selectByAirwayBillNumber(airwayBillNo);
|
| - |
|
99 |
|
| - |
|
100 |
int providerId = orders.get(0).getLogisticsProviderId();
|
| - |
|
101 |
TrackingDetailModel tdm = null;
|
| - |
|
102 |
|
| - |
|
103 |
if (providerId == ProfitMandiConstants.DELHIVERY_PROVIDERID) {
|
| - |
|
104 |
|
| - |
|
105 |
tdm = getDelhiveryTracking(airwayBillNo);
|
| - |
|
106 |
|
| - |
|
107 |
} else if (providerId == ProfitMandiConstants.BLUEDART_PROVIDERID) {
|
| - |
|
108 |
|
| - |
|
109 |
tdm = getBlueDartTracking(airwayBillNo);
|
| - |
|
110 |
|
| - |
|
111 |
}
|
| - |
|
112 |
|
| - |
|
113 |
LOGGER.info("tdm" + tdm);
|
| - |
|
114 |
|
| - |
|
115 |
return responseSender.ok(tdm);
|
| - |
|
116 |
}
|
| - |
|
117 |
|
| - |
|
118 |
private TrackingDetailModel getDelhiveryTracking(String airwayBillNo) throws IOException {
|
| 89 |
String url = "https://track.delhivery.com/api/v1/packages/json/";
|
119 |
String url = "https://track.delhivery.com/api/v1/packages/json/";
|
| 90 |
|
120 |
|
| 91 |
OkHttpClient client = new OkHttpClient();
|
121 |
OkHttpClient client = new OkHttpClient();
|
| 92 |
|
122 |
|
| 93 |
Request request1 = new Request.Builder()
|
123 |
Request request1 = new Request.Builder()
|
| Line 116... |
Line 146... |
| 116 |
JSONArray scans = shipment.getJSONArray("Scans");
|
146 |
JSONArray scans = shipment.getJSONArray("Scans");
|
| 117 |
|
147 |
|
| 118 |
for (int j = 0; j < scans.length(); j++) {
|
148 |
for (int j = 0; j < scans.length(); j++) {
|
| 119 |
JSONObject scanObject = scans.getJSONObject(j);
|
149 |
JSONObject scanObject = scans.getJSONObject(j);
|
| 120 |
|
150 |
|
| 121 |
JSONObject scandetails = scanObject.getJSONObject("ScanDetail");
|
151 |
JSONObject scandetail = scanObject.getJSONObject("ScanDetail");
|
| 122 |
|
152 |
|
| 123 |
ScannedDetailModel sdm = new ScannedDetailModel();
|
153 |
ScannedDetailModel sdm = new ScannedDetailModel();
|
| 124 |
sdm.setStatusDateTime(scandetails.getString("ScanDateTime"));
|
154 |
sdm.setStatusDateTime(scandetail.getString("ScanDateTime"));
|
| 125 |
sdm.setStatusLocation(scandetails.getString("ScannedLocation"));
|
155 |
sdm.setStatusLocation(scandetail.getString("ScannedLocation"));
|
| 126 |
sdm.setInstruction(scandetails.getString("Instructions"));
|
156 |
sdm.setInstruction(scandetail.getString("Instructions"));
|
| 127 |
sdms.add(sdm);
|
157 |
sdms.add(sdm);
|
| 128 |
|
158 |
|
| 129 |
}
|
159 |
}
|
| 130 |
|
160 |
|
| 131 |
tdm.setExpectedDelivery(shipment.getString("ExpectedDeliveryDate"));
|
161 |
tdm.setExpectedDelivery(shipment.getString("ExpectedDeliveryDate"));
|
| 132 |
tdm.setAwb(shipment.getString("AWB"));
|
162 |
tdm.setAwb(shipment.getString("AWB"));
|
| 133 |
|
163 |
|
| 134 |
}
|
164 |
}
|
| 135 |
|
165 |
|
| 136 |
tdm.setSdm(sdms);
|
166 |
tdm.setSdm(sdms);
|
| 137 |
LOGGER.info("tdm" + tdm);
|
- |
|
| 138 |
|
- |
|
| 139 |
return responseSender.ok(tdm);
|
167 |
return tdm;
|
| 140 |
}
|
168 |
}
|
| 141 |
|
169 |
|
| 142 |
@RequestMapping(value = "/order/tracking/bluedart", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
170 |
private TrackingDetailModel getBlueDartTracking(String airwayBillNo)
|
| 143 |
@ApiImplicitParams({
|
- |
|
| 144 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
- |
|
| 145 |
public ResponseEntity<?> getBluedartOrderTracking(HttpServletRequest request) throws Throwable {
|
171 |
throws ProfitMandiBusinessException, HttpHostConnectException {
|
| 146 |
|
172 |
|
| 147 |
String airwayBillNo = "81007630141";
|
173 |
String loginId = "DEL81122";
|
| - |
|
174 |
|
| - |
|
175 |
String licencekey = "uhfhlg2jpmnqfhfrlsgzfr1nhu1qfvel";
|
| 148 |
|
176 |
|
| 149 |
String url = "https://api.bluedart.com/servlet/RoutingServlet?handler=tnt&action=custawbquery";
|
177 |
String url = "https://api.bluedart.com/servlet/RoutingServlet?handler=tnt&action=custawbquery";
|
| 150 |
|
178 |
|
| 151 |
OkHttpClient client = new OkHttpClient();
|
179 |
String response = restClient.get(url + "&loginid=" + loginId + "&awb=awb&numbers="
|
| - |
|
180 |
+ String.join(",", airwayBillNo) + "&format=xml&lickey=" + licencekey + "&verno=1.3&scan=1", null,
|
| - |
|
181 |
null);
|
| 152 |
|
182 |
|
| 153 |
Request request1 = new Request.Builder()
|
183 |
JSONObject updateJson = XML.toJSONObject(response);
|
| 154 |
.url(url + "&loginid=" + "DEL95932" + "&awb=awb&numbers=" + String.join(",", airwayBillNo)
|
- |
|
| 155 |
+ "&format=xml&lickey=" + "poehq2kiqjnllkrote9hxglo4teptfqf" + "&verno=1.3&scan=1")
|
- |
|
| 156 |
.get().build();
|
- |
|
| 157 |
|
184 |
|
| 158 |
LOGGER.info("request1" + request1);
|
185 |
TrackingDetailModel tdm = new TrackingDetailModel();
|
| 159 |
|
186 |
|
| 160 |
Response response1 = client.newCall(request1).execute();
|
187 |
List<ScannedDetailModel> sdms = new ArrayList<>();
|
| 161 |
|
188 |
|
| - |
|
189 |
JSONObject shipmentData = updateJson.getJSONObject("ShipmentData");
|
| - |
|
190 |
JSONObject shipment = shipmentData.getJSONObject("Shipment");
|
| - |
|
191 |
JSONObject scan = shipment.getJSONObject("Scans");
|
| - |
|
192 |
|
| - |
|
193 |
JSONArray scandetails = scan.getJSONArray("ScanDetail");
|
| - |
|
194 |
|
| 162 |
LOGGER.info("jsonbj" + response1);
|
195 |
for (int j = 0; j < scandetails.length(); j++) {
|
| - |
|
196 |
JSONObject scanDetail = scandetails.getJSONObject(j);
|
| - |
|
197 |
|
| - |
|
198 |
ScannedDetailModel sdm = new ScannedDetailModel();
|
| - |
|
199 |
sdm.setStatusDateTime(scanDetail.getString("ScanDate"));
|
| - |
|
200 |
sdm.setStatusLocation(scanDetail.getString("ScannedLocation"));
|
| - |
|
201 |
sdm.setInstruction(scanDetail.getString("Scan"));
|
| - |
|
202 |
sdms.add(sdm);
|
| 163 |
|
203 |
|
| - |
|
204 |
}
|
| - |
|
205 |
|
| - |
|
206 |
tdm.setExpectedDelivery(shipment.getString("ExpectedDeliveryDate"));
|
| 164 |
TrackingDetailModel tdm = new TrackingDetailModel();
|
207 |
tdm.setAwb(shipment.getNumber("AWB").toString());
|
| - |
|
208 |
|
| - |
|
209 |
tdm.setSdm(sdms);
|
| - |
|
210 |
LOGGER.info("tdm" + tdm);
|
| - |
|
211 |
return tdm;
|
| 165 |
|
212 |
|
| 166 |
return responseSender.ok(tdm);
|
- |
|
| 167 |
}
|
213 |
}
|
| 168 |
|
214 |
|
| 169 |
@RequestMapping(value = "/order/detail", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
215 |
@RequestMapping(value = "/order/detail", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 170 |
@ApiImplicitParams({
|
216 |
@ApiImplicitParams({
|
| 171 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
217 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|