| 21545 |
ashik.ali |
1 |
package com.spice.profitmandi.dao.util;
|
|
|
2 |
import java.text.SimpleDateFormat;
|
|
|
3 |
import java.util.Calendar;
|
|
|
4 |
import java.util.GregorianCalendar;
|
|
|
5 |
import java.util.HashMap;
|
|
|
6 |
import java.util.Map;
|
|
|
7 |
|
|
|
8 |
import org.apache.thrift.TException;
|
| 23568 |
govind |
9 |
import org.apache.logging.log4j.Logger;
|
|
|
10 |
import org.apache.logging.log4j.LogManager;
|
| 21545 |
ashik.ali |
11 |
|
|
|
12 |
import com.spice.profitmandi.dao.model.LogisticsInfoPojo;
|
|
|
13 |
import com.spice.profitmandi.thrift.clients.LogisticsClient;
|
|
|
14 |
|
|
|
15 |
import in.shop2020.logistics.DeliveryType;
|
|
|
16 |
import in.shop2020.logistics.LogisticsInfo;
|
|
|
17 |
import in.shop2020.logistics.LogisticsService.Client;
|
|
|
18 |
import in.shop2020.logistics.LogisticsServiceException;
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
public class LogisticsService {
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
private static Map<Integer, String> businessDayToActualDateMap = new HashMap<Integer, String>();
|
|
|
25 |
|
| 23568 |
govind |
26 |
private static final Logger log=LogManager.getLogger(LogisticsService.class);
|
| 21545 |
ashik.ali |
27 |
|
|
|
28 |
public static LogisticsInfoPojo getLogisticsInfo(long itemId, String pinCode){
|
|
|
29 |
LogisticsClient logisticsServiceClient = null;
|
|
|
30 |
long businessDays = -1;
|
|
|
31 |
boolean isOTGAvailable = false;
|
|
|
32 |
String days="-1";
|
|
|
33 |
String codDays="-1";
|
|
|
34 |
boolean isCODAvailable = false;
|
|
|
35 |
LogisticsInfoPojo lip = new LogisticsInfoPojo();
|
|
|
36 |
|
|
|
37 |
try {
|
|
|
38 |
logisticsServiceClient = new LogisticsClient();
|
|
|
39 |
Client logisticsClient = logisticsServiceClient.getClient();
|
|
|
40 |
LogisticsInfo logistincInfo = logisticsClient.getLogisticsEstimation(itemId, pinCode, DeliveryType.PREPAID);
|
|
|
41 |
|
|
|
42 |
if(logistincInfo.getDeliveryTime()!=-1L){
|
|
|
43 |
days = getDeliveryDateString((int)logistincInfo.getDeliveryTime(), DeliveryType.PREPAID);
|
|
|
44 |
if(logistincInfo.isCodAllowed()){
|
|
|
45 |
codDays = getDeliveryDateString((int)(logistincInfo.getDeliveryTime()), DeliveryType.COD);
|
|
|
46 |
}
|
|
|
47 |
}
|
|
|
48 |
businessDays = logistincInfo.getDeliveryTime();
|
|
|
49 |
isCODAvailable = logistincInfo.isCodAllowed();
|
|
|
50 |
isOTGAvailable = logistincInfo.isOtgAvailable();
|
|
|
51 |
lip.setBusinessDays(businessDays);
|
|
|
52 |
lip.setCodDeliveryEstimate(codDays);
|
|
|
53 |
lip.setDelivelyEstimate(days);
|
|
|
54 |
lip.setIsCodAvailableForLocation(isCODAvailable);
|
|
|
55 |
lip.setOnTimeGuarantee(isOTGAvailable);
|
|
|
56 |
} catch (LogisticsServiceException e) {
|
|
|
57 |
days = "-1";
|
|
|
58 |
isCODAvailable = false;
|
|
|
59 |
log.error("Unable to get estimate/COD availability for " + itemId + " and pincode : " + pinCode);
|
|
|
60 |
|
|
|
61 |
} catch(TException e) {
|
|
|
62 |
|
|
|
63 |
} catch (Exception e) {
|
|
|
64 |
|
|
|
65 |
}
|
|
|
66 |
return lip;
|
|
|
67 |
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
public static void main(String[] args) throws TException {
|
|
|
71 |
System.out.println(getDeliveryDateString(1, DeliveryType.COD));
|
|
|
72 |
System.out.println(getDeliveryDateString(2, DeliveryType.COD));
|
|
|
73 |
System.out.println(getDeliveryDateString(2, DeliveryType.PREPAID));
|
|
|
74 |
System.out.println(getDeliveryDateString(3, DeliveryType.PREPAID));
|
|
|
75 |
}
|
|
|
76 |
public static String getDeliveryDateString(int days, DeliveryType type) throws TException {
|
|
|
77 |
Calendar now = new GregorianCalendar();
|
|
|
78 |
int hour = now.get(Calendar.HOUR_OF_DAY);
|
|
|
79 |
if(type == DeliveryType.COD && hour < 15){
|
|
|
80 |
days = days + 1;
|
|
|
81 |
}
|
|
|
82 |
if(businessDayToActualDateMap.containsKey(days)){
|
|
|
83 |
if(hour != 0){
|
|
|
84 |
return businessDayToActualDateMap.get(days);
|
|
|
85 |
}
|
|
|
86 |
businessDayToActualDateMap.clear();
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
now.set(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
|
|
|
90 |
|
|
|
91 |
LogisticsClient logisticsServiceClient = null;
|
|
|
92 |
logisticsServiceClient = new LogisticsClient();
|
|
|
93 |
Client logisticsClient = logisticsServiceClient.getClient();
|
|
|
94 |
|
|
|
95 |
int newdays = (int) logisticsClient.adjustDeliveryDays(now.getTimeInMillis(), days);
|
|
|
96 |
now.add(Calendar.DAY_OF_MONTH, newdays);
|
|
|
97 |
|
|
|
98 |
SimpleDateFormat dateformat = new SimpleDateFormat("EEE dd-MMM-yy");
|
|
|
99 |
if(newdays == 1){
|
|
|
100 |
businessDayToActualDateMap.put(days, "Tomorrow, " + dateformat.format(now.getTime()));
|
|
|
101 |
}else{
|
|
|
102 |
businessDayToActualDateMap.put(days, dateformat.format(now.getTime()));
|
|
|
103 |
}
|
|
|
104 |
return businessDayToActualDateMap.get(days);
|
|
|
105 |
}
|
|
|
106 |
}
|