| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| - |
|
3 |
import java.time.LocalDate;
|
| - |
|
4 |
import java.time.LocalDateTime;
|
| - |
|
5 |
import java.time.temporal.ChronoUnit;
|
| 3 |
import java.util.ArrayList;
|
6 |
import java.util.ArrayList;
|
| 4 |
import java.util.HashSet;
|
- |
|
| 5 |
import java.util.List;
|
7 |
import java.util.List;
|
| 6 |
import java.util.Set;
|
- |
|
| 7 |
|
8 |
|
| 8 |
import javax.servlet.http.HttpServletRequest;
|
9 |
import javax.servlet.http.HttpServletRequest;
|
| 9 |
import javax.servlet.http.HttpServletResponse;
|
10 |
import javax.servlet.http.HttpServletResponse;
|
| 10 |
|
11 |
|
| 11 |
import org.apache.logging.log4j.LogManager;
|
12 |
import org.apache.logging.log4j.LogManager;
|
| 12 |
import org.apache.logging.log4j.Logger;
|
13 |
import org.apache.logging.log4j.Logger;
|
| - |
|
14 |
import org.apache.thrift.TException;
|
| 13 |
import org.json.JSONArray;
|
15 |
import org.json.JSONArray;
|
| 14 |
import org.json.JSONObject;
|
16 |
import org.json.JSONObject;
|
| 15 |
import org.springframework.beans.factory.annotation.Autowired;
|
17 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 16 |
import org.springframework.beans.factory.annotation.Value;
|
18 |
import org.springframework.beans.factory.annotation.Value;
|
| 17 |
import org.springframework.http.MediaType;
|
19 |
import org.springframework.http.MediaType;
|
| Line 20... |
Line 22... |
| 20 |
import org.springframework.transaction.annotation.Transactional;
|
22 |
import org.springframework.transaction.annotation.Transactional;
|
| 21 |
import org.springframework.web.bind.annotation.RequestMapping;
|
23 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 22 |
import org.springframework.web.bind.annotation.RequestMethod;
|
24 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 23 |
import org.springframework.web.bind.annotation.RequestParam;
|
25 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 24 |
|
26 |
|
| 25 |
import com.eclipsesource.json.JsonArray;
|
- |
|
| 26 |
import com.spice.profitmandi.common.model.CustomNotifyOrder;
|
27 |
import com.spice.profitmandi.common.model.CustomOrder;
|
| 27 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
- |
|
| 28 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
28 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 29 |
import com.spice.profitmandi.dao.entity.transaction.NotifyCancel;
|
29 |
import com.spice.profitmandi.dao.entity.logistics.Provider;
|
| - |
|
30 |
import com.spice.profitmandi.dao.entity.logistics.ProviderTat;
|
| 30 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
31 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| - |
|
32 |
import com.spice.profitmandi.dao.model.ProductPojo;
|
| - |
|
33 |
import com.spice.profitmandi.dao.repository.logistics.ProviderRepository;
|
| - |
|
34 |
import com.spice.profitmandi.dao.repository.logistics.ProviderTatRepository;
|
| - |
|
35 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| - |
|
36 |
import com.spice.profitmandi.dao.util.ContentPojoPopulator;
|
| 31 |
import com.spice.profitmandi.model.tracking.ScannedDetailModel;
|
37 |
import com.spice.profitmandi.model.tracking.ScannedDetailModel;
|
| 32 |
import com.spice.profitmandi.model.tracking.TrackingDetailModel;
|
38 |
import com.spice.profitmandi.model.tracking.TrackingDetailModel;
|
| - |
|
39 |
import com.spice.profitmandi.service.LogisticsService;
|
| 33 |
|
40 |
|
| 34 |
import in.shop2020.model.v1.order.OrderStatus;
|
41 |
import in.shop2020.model.v1.order.OrderStatusGroups;
|
| 35 |
import io.swagger.annotations.ApiImplicitParam;
|
42 |
import io.swagger.annotations.ApiImplicitParam;
|
| 36 |
import io.swagger.annotations.ApiImplicitParams;
|
43 |
import io.swagger.annotations.ApiImplicitParams;
|
| 37 |
import okhttp3.OkHttpClient;
|
44 |
import okhttp3.OkHttpClient;
|
| 38 |
import okhttp3.Request;
|
45 |
import okhttp3.Request;
|
| 39 |
import okhttp3.Response;
|
46 |
import okhttp3.Response;
|
| Line 46... |
Line 53... |
| 46 |
private String token;
|
53 |
private String token;
|
| 47 |
|
54 |
|
| 48 |
@Autowired
|
55 |
@Autowired
|
| 49 |
private ResponseSender<?> responseSender;
|
56 |
private ResponseSender<?> responseSender;
|
| 50 |
|
57 |
|
| - |
|
58 |
@Autowired
|
| - |
|
59 |
private OrderRepository orderRepository;
|
| - |
|
60 |
|
| - |
|
61 |
@Autowired
|
| - |
|
62 |
private ProviderRepository providerRepository;
|
| - |
|
63 |
|
| - |
|
64 |
@Autowired
|
| - |
|
65 |
private ContentPojoPopulator contentPojoPopulator;
|
| - |
|
66 |
|
| - |
|
67 |
@Autowired
|
| - |
|
68 |
private ProviderTatRepository providerTatRepository;
|
| - |
|
69 |
|
| - |
|
70 |
@Autowired
|
| - |
|
71 |
private LogisticsService logisticsService;
|
| 51 |
private static final Logger LOGGER = LogManager.getLogger(TrackingController.class);
|
72 |
private static final Logger LOGGER = LogManager.getLogger(TrackingController.class);
|
| 52 |
|
73 |
|
| 53 |
@RequestMapping(value = "/order/tracking", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
74 |
@RequestMapping(value = "/order/tracking", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 54 |
@ApiImplicitParams({
|
75 |
@ApiImplicitParams({
|
| 55 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
76 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 56 |
public ResponseEntity<?> getNotifyCancelOrders(HttpServletRequest request, HttpServletResponse response,
|
77 |
public ResponseEntity<?> getDeliveryOrder(HttpServletRequest request, HttpServletResponse response,
|
| 57 |
@RequestParam String airwayBillNo) throws Throwable {
|
78 |
@RequestParam String airwayBillNo) throws Throwable {
|
| 58 |
|
79 |
|
| 59 |
String url = "https://track.delhivery.com/api/v1/packages/json/";
|
80 |
String url = "https://track.delhivery.com/api/v1/packages/json/";
|
| 60 |
|
81 |
|
| 61 |
OkHttpClient client = new OkHttpClient();
|
82 |
OkHttpClient client = new OkHttpClient();
|
| Line 107... |
Line 128... |
| 107 |
LOGGER.info("tdm" + tdm);
|
128 |
LOGGER.info("tdm" + tdm);
|
| 108 |
|
129 |
|
| 109 |
return responseSender.ok(tdm);
|
130 |
return responseSender.ok(tdm);
|
| 110 |
}
|
131 |
}
|
| 111 |
|
132 |
|
| - |
|
133 |
@RequestMapping(value = "/order/detail", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| - |
|
134 |
@ApiImplicitParams({
|
| - |
|
135 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| - |
|
136 |
public ResponseEntity<?> getOrderDetails(HttpServletRequest request, HttpServletResponse response,
|
| - |
|
137 |
@RequestParam String airwayBillNo) throws Throwable {
|
| - |
|
138 |
List<Order> orders = orderRepository.selectByAirwayBillNumber(airwayBillNo);
|
| - |
|
139 |
List<CustomOrder> customOrders = new ArrayList<CustomOrder>();
|
| - |
|
140 |
|
| - |
|
141 |
for (Order order : orders) {
|
| - |
|
142 |
CustomOrder co = null;
|
| - |
|
143 |
|
| - |
|
144 |
try {
|
| - |
|
145 |
co = toCustomOrder(order);
|
| - |
|
146 |
} catch (Exception e) {
|
| - |
|
147 |
continue;
|
| - |
|
148 |
}
|
| - |
|
149 |
customOrders.add(co);
|
| - |
|
150 |
}
|
| - |
|
151 |
|
| - |
|
152 |
return responseSender.ok(customOrders);
|
| - |
|
153 |
|
| - |
|
154 |
}
|
| - |
|
155 |
|
| - |
|
156 |
private CustomOrder toCustomOrder(Order order) throws Exception {
|
| - |
|
157 |
CustomOrder co = new CustomOrder();
|
| - |
|
158 |
co.setId(order.getId());
|
| - |
|
159 |
co.setRetailerName(order.getRetailerName());
|
| - |
|
160 |
co.setExpectedDeliveryTime(order.getExpectedDeliveryTime());
|
| - |
|
161 |
co.setPromisedDeliveryTime(order.getPromisedDeliveryTime());
|
| - |
|
162 |
co.setRetailerPinCode(order.getRetailerPinCode());
|
| - |
|
163 |
co.setRetailerAddress1(order.getRetailerAddress1());
|
| - |
|
164 |
co.setRetailerCity(order.getRetailerCity());
|
| - |
|
165 |
co.setStatusDescription(order.getStatusDescription());
|
| - |
|
166 |
co.setStatus(order.getStatus());
|
| - |
|
167 |
co.setBrand(order.getLineItem().getBrand());
|
| - |
|
168 |
co.setTransactionId(order.getTransactionId());
|
| - |
|
169 |
co.setExtraInfo(order.getLineItem().getExtraInfo());
|
| - |
|
170 |
co.setItemId(order.getLineItem().getItemId());
|
| - |
|
171 |
co.setQuantity(order.getLineItem().getQuantity());
|
| - |
|
172 |
co.setTotalAmount(order.getTotalAmount());
|
| - |
|
173 |
co.setColor(order.getLineItem().getColor());
|
| - |
|
174 |
co.setShippingCost(order.getShippingCost());
|
| - |
|
175 |
co.setCreateTimestamp(order.getCreateTimestamp());
|
| - |
|
176 |
co.setModelName(order.getLineItem().getModelName());
|
| - |
|
177 |
co.setModelNumber(order.getLineItem().getModelNumber());
|
| - |
|
178 |
co.setDeliveryTimestamp(order.getDeliveryTimestamp());
|
| - |
|
179 |
co.setImageUrl(getImageUrl(order));
|
| - |
|
180 |
co.setCancellable(getCancellableRequest(order));
|
| - |
|
181 |
co.setProviderId(order.getLogisticsProviderId());
|
| - |
|
182 |
co.setDelayReason(order.getDelayReasonText());
|
| - |
|
183 |
Provider provider = providerRepository.selectById(order.getLogisticsProviderId());
|
| - |
|
184 |
co.setProviderName(provider.getName());
|
| - |
|
185 |
co.setAirwayBillNo(order.getAirwayBillNumber());
|
| - |
|
186 |
co.setCancellationTimestamp(order.getRefundTimestamp());
|
| - |
|
187 |
co.setBillingTimestamp(order.getBillingTimestamp());
|
| - |
|
188 |
co.setShippingTimestamp(order.getShippingTimestamp());
|
| - |
|
189 |
co.setInvoiceNumber(order.getInvoiceNumber());
|
| - |
|
190 |
if (order.getShippingTimestamp() != null) {
|
| - |
|
191 |
ProviderTat pt = providerTatRepository.selectByProviderId(order.getLogisticsProviderId(),
|
| - |
|
192 |
order.getWarehouseId(), order.getRetailerPinCode());
|
| - |
|
193 |
LocalDateTime shipping = order.getShippingTimestamp();
|
| - |
|
194 |
|
| - |
|
195 |
LocalDate deliveryTime = logisticsService.calculateDeliveryTimeline(shipping.toLocalDate(), pt, 0);
|
| - |
|
196 |
LOGGER.info("deliveryTime" + deliveryTime);
|
| - |
|
197 |
LocalDateTime expected = order.getExpectedDeliveryTime();
|
| - |
|
198 |
LOGGER.info("expected" + expected);
|
| - |
|
199 |
|
| - |
|
200 |
long noOfDaysBetween = ChronoUnit.DAYS.between(expected, deliveryTime.atStartOfDay());
|
| - |
|
201 |
|
| - |
|
202 |
co.setDelayAfterShipping((int) noOfDaysBetween);
|
| - |
|
203 |
|
| - |
|
204 |
}
|
| - |
|
205 |
|
| - |
|
206 |
return co;
|
| - |
|
207 |
}
|
| - |
|
208 |
|
| - |
|
209 |
private String getImageUrl(Order order) throws TException {
|
| - |
|
210 |
|
| - |
|
211 |
ProductPojo pp = contentPojoPopulator.getShortContent(order.getLineItem().getItem().getCatalogItemId());
|
| - |
|
212 |
String imageUrl = "";
|
| - |
|
213 |
LOGGER.info("pp {}", pp);
|
| - |
|
214 |
if (pp != null) {
|
| - |
|
215 |
imageUrl = pp.getImageUrl();
|
| - |
|
216 |
}
|
| - |
|
217 |
|
| - |
|
218 |
return imageUrl;
|
| - |
|
219 |
}
|
| - |
|
220 |
|
| - |
|
221 |
private Boolean getCancellableRequest(Order order) throws Exception {
|
| - |
|
222 |
OrderStatusGroups orderStatusGroups = new OrderStatusGroups();
|
| - |
|
223 |
if (order.isCod() == null) {
|
| - |
|
224 |
throw new Exception("Invalid order");
|
| - |
|
225 |
}
|
| - |
|
226 |
if (order.isCod()) {
|
| - |
|
227 |
if (orderStatusGroups.getCodCancellable().contains(order.getStatus())) {
|
| - |
|
228 |
return true;
|
| - |
|
229 |
} else {
|
| - |
|
230 |
return false;
|
| - |
|
231 |
}
|
| - |
|
232 |
} else {
|
| - |
|
233 |
if (orderStatusGroups.getPrepaidCancellableBeforeBilled().contains(order.getStatus())) {
|
| - |
|
234 |
return true;
|
| - |
|
235 |
} else if (orderStatusGroups.getPrepaidCancellableAfterBilled().contains(order.getStatus())) {
|
| - |
|
236 |
return true;
|
| - |
|
237 |
} else {
|
| - |
|
238 |
return false;
|
| - |
|
239 |
}
|
| - |
|
240 |
}
|
| - |
|
241 |
}
|
| - |
|
242 |
|
| 112 |
}
|
243 |
}
|
| 113 |
|
244 |
|