| 493 |
rajveer |
1 |
package in.shop2020.hotspot.dashbaord.server;
|
|
|
2 |
|
| 19015 |
manish.sha |
3 |
import in.shop2020.hotspot.dashbaord.server.OrderPromisedShippingComparator;
|
| 493 |
rajveer |
4 |
import in.shop2020.hotspot.dashbaord.shared.actions.Order;
|
| 19032 |
manish.sha |
5 |
import in.shop2020.hotspot.dashbaord.shared.actions.OrderAlert;
|
| 493 |
rajveer |
6 |
import in.shop2020.hotspot.dashbaord.shared.actions.OrderType;
|
| 2697 |
chandransh |
7 |
import in.shop2020.hotspot.dashbaord.shared.actions.ReturnOrder;
|
| 5945 |
mandeep.dh |
8 |
import in.shop2020.model.v1.inventory.InventoryType;
|
| 18100 |
manish.sha |
9 |
import in.shop2020.model.v1.inventory.WarehouseType;
|
| 5110 |
mandeep.dh |
10 |
import in.shop2020.model.v1.catalog.Item;
|
|
|
11 |
import in.shop2020.model.v1.catalog.ItemType;
|
| 5945 |
mandeep.dh |
12 |
import in.shop2020.model.v1.inventory.Warehouse;
|
| 914 |
chandransh |
13 |
import in.shop2020.model.v1.order.LineItem;
|
| 7422 |
rajveer |
14 |
import in.shop2020.model.v1.order.OrderSource;
|
| 493 |
rajveer |
15 |
import in.shop2020.model.v1.order.OrderStatus;
|
|
|
16 |
import in.shop2020.model.v1.order.TransactionService.Client;
|
| 19050 |
manish.sha |
17 |
import in.shop2020.hotspot.dashbaord.server.EhcacheWrapper;
|
| 5110 |
mandeep.dh |
18 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 5948 |
mandeep.dh |
19 |
import in.shop2020.thrift.clients.InventoryClient;
|
| 3132 |
rajveer |
20 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 13146 |
manish.sha |
21 |
import in.shop2020.thrift.clients.LogisticsClient;
|
| 493 |
rajveer |
22 |
|
| 4411 |
rajveer |
23 |
import java.io.ByteArrayOutputStream;
|
|
|
24 |
import java.io.File;
|
|
|
25 |
import java.io.FileNotFoundException;
|
|
|
26 |
import java.io.FileOutputStream;
|
|
|
27 |
import java.io.IOException;
|
| 18938 |
manish.sha |
28 |
import java.text.DecimalFormat;
|
|
|
29 |
import java.text.NumberFormat;
|
| 19054 |
manish.sha |
30 |
import java.text.SimpleDateFormat;
|
| 493 |
rajveer |
31 |
import java.util.ArrayList;
|
| 4411 |
rajveer |
32 |
import java.util.Calendar;
|
| 19004 |
manish.sha |
33 |
import java.util.Collections;
|
| 493 |
rajveer |
34 |
import java.util.Date;
|
| 4411 |
rajveer |
35 |
import java.util.GregorianCalendar;
|
|
|
36 |
import java.util.HashMap;
|
| 493 |
rajveer |
37 |
import java.util.List;
|
| 4411 |
rajveer |
38 |
import java.util.Map;
|
| 19004 |
manish.sha |
39 |
import java.util.Map.Entry;
|
| 19110 |
manish.sha |
40 |
import java.util.Set;
|
| 493 |
rajveer |
41 |
|
| 19050 |
manish.sha |
42 |
import net.sf.ehcache.CacheManager;
|
|
|
43 |
|
| 4411 |
rajveer |
44 |
import org.slf4j.Logger;
|
|
|
45 |
import org.slf4j.LoggerFactory;
|
|
|
46 |
|
| 2449 |
chandransh |
47 |
/**
|
|
|
48 |
* This class is a facade to the Transaction service and should be used to
|
| 4133 |
chandransh |
49 |
* access all order specific data which requires some kind of transformation.
|
| 2449 |
chandransh |
50 |
*
|
|
|
51 |
* @author Chandranshu
|
|
|
52 |
*
|
|
|
53 |
*/
|
| 493 |
rajveer |
54 |
public class TransactionUtils {
|
| 4411 |
rajveer |
55 |
private static String courierDetailsPath = "/CourierDetailReports";
|
|
|
56 |
private static Logger logger = LoggerFactory.getLogger(TransactionUtils.class);
|
| 19196 |
manish.sha |
57 |
private static long ALL_GREEN = 1L;
|
|
|
58 |
private static long GREEN_AND_PURPULE = 2L;
|
|
|
59 |
private static long GREEN_AND_IN_RED_OR_WHITE = 3L;
|
|
|
60 |
private static long ALL_RED = 4L;
|
|
|
61 |
private static long ALL_PURPLE = 5L;
|
|
|
62 |
private static long PURPLE_AND_IN_RED_OR_WHITE = 6L;
|
|
|
63 |
private static long ALL_OTHERS = 7L;
|
| 4411 |
rajveer |
64 |
|
| 19196 |
manish.sha |
65 |
private static enum ColorCode {
|
|
|
66 |
GREEN,
|
|
|
67 |
PURPLE,
|
|
|
68 |
RED,
|
|
|
69 |
OTHER
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
|
| 2449 |
chandransh |
73 |
/**
|
|
|
74 |
* The human user is concerned only with a consolidated view of actionable
|
|
|
75 |
* orders. Orders with different statuses in the database can be part of the
|
|
|
76 |
* same consolidated view. This method uses a mapping of <i>type</i> to
|
|
|
77 |
* <i>status</i> to get all such orders and return them as order beans.
|
|
|
78 |
*
|
|
|
79 |
* @param type
|
|
|
80 |
* The type of orders to return.
|
| 4133 |
chandransh |
81 |
* @param offset
|
|
|
82 |
* Offset to start from
|
|
|
83 |
* @param limit
|
|
|
84 |
* No. of orders to return
|
| 2449 |
chandransh |
85 |
* @param warehouseId
|
|
|
86 |
* The warehouse for which the orders should be queried.
|
|
|
87 |
* @return A list of orders of the given type to be fulfilled from the given
|
|
|
88 |
* warehouse
|
|
|
89 |
*/
|
| 8303 |
amar.kumar |
90 |
public static List<Order> getOrders(OrderType type, long offset, long limit, long warehouseId, long source){
|
| 2449 |
chandransh |
91 |
List<OrderStatus> statuses = getStatuses(type);
|
| 493 |
rajveer |
92 |
|
|
|
93 |
List<Order> orders = new ArrayList<Order>();
|
|
|
94 |
try{
|
| 4133 |
chandransh |
95 |
TransactionClient txnClient = new TransactionClient();
|
|
|
96 |
Client client = txnClient.getClient();
|
| 493 |
rajveer |
97 |
|
|
|
98 |
List<in.shop2020.model.v1.order.Order> t_orders = new ArrayList<in.shop2020.model.v1.order.Order>();
|
| 19004 |
manish.sha |
99 |
if(type==OrderType.NEW || type==OrderType.ALL_PENDING || type ==OrderType.LOW_INVENTORY || type == OrderType.PO_RAISED
|
|
|
100 |
|| type == OrderType.REVERSAL_INITIATED || type == OrderType.NOT_AVAILABLE){
|
|
|
101 |
t_orders.addAll(client.getOrdersInBatchAsPromisedShipping(statuses, offset, limit, warehouseId, source));
|
|
|
102 |
}else{
|
|
|
103 |
t_orders.addAll(client.getOrdersInBatch(statuses, offset, limit, warehouseId, source));
|
|
|
104 |
}
|
| 493 |
rajveer |
105 |
|
|
|
106 |
for (in.shop2020.model.v1.order.Order t_order: t_orders){
|
| 671 |
chandransh |
107 |
Order o = getOrderFromThriftOrder(t_order);
|
| 493 |
rajveer |
108 |
orders.add(o);
|
|
|
109 |
}
|
| 19004 |
manish.sha |
110 |
if(type==OrderType.NEW || type==OrderType.ALL_PENDING || type ==OrderType.LOW_INVENTORY || type == OrderType.PO_RAISED
|
|
|
111 |
|| type == OrderType.REVERSAL_INITIATED || type == OrderType.NOT_AVAILABLE){
|
|
|
112 |
Map<Long, List<Order>> transactionOrdersMap = new HashMap<Long, List<Order>>();
|
| 19196 |
manish.sha |
113 |
Map<Long, Map<String, Long>> transactionsColorMap = new HashMap<Long, Map<String, Long>>();
|
| 19004 |
manish.sha |
114 |
for(Order order : orders){
|
|
|
115 |
if(transactionOrdersMap.containsKey(order.getTransactionId())){
|
|
|
116 |
List<Order> txnOrders = transactionOrdersMap.get(order.getTransactionId());
|
|
|
117 |
txnOrders.add(order);
|
|
|
118 |
transactionOrdersMap.put(order.getTransactionId(), txnOrders);
|
|
|
119 |
}else{
|
|
|
120 |
List<Order> txnOrders = new ArrayList<Order>();
|
|
|
121 |
txnOrders.add(order);
|
|
|
122 |
transactionOrdersMap.put(order.getTransactionId(), txnOrders);
|
|
|
123 |
}
|
| 19196 |
manish.sha |
124 |
|
|
|
125 |
if(transactionsColorMap.containsKey(order.getTransactionId())){
|
|
|
126 |
Map<String, Long> colorMap = transactionsColorMap.get(order.getTransactionId());
|
|
|
127 |
//SHIPPING_TIME_EXCEEDED, DELIVERY_TIME_EXCEEDED, ORDER_NOT_CONNECTED_FOR_TOO_LONG, ORDER_NOT_CONNECTED
|
|
|
128 |
if(order.getAlert()==OrderAlert.TODAY_SHIPPING_IN_STOCK){
|
|
|
129 |
if(colorMap.containsKey(ColorCode.GREEN.toString())){
|
|
|
130 |
colorMap.put(ColorCode.GREEN.toString(),colorMap.get(ColorCode.GREEN.toString())+1);
|
|
|
131 |
}else{
|
|
|
132 |
colorMap.put(ColorCode.GREEN.toString(),1L);
|
|
|
133 |
}
|
|
|
134 |
}else if(order.getAlert()==OrderAlert.TODAY_SHIPPING_NOT_IN_STOCK){
|
|
|
135 |
if(colorMap.containsKey(ColorCode.RED.toString())){
|
|
|
136 |
colorMap.put(ColorCode.RED.toString(),colorMap.get(ColorCode.RED.toString())+1);
|
|
|
137 |
}else{
|
|
|
138 |
colorMap.put(ColorCode.RED.toString(),1L);
|
|
|
139 |
}
|
|
|
140 |
}else if(order.getAlert()==OrderAlert.LATER_SHIPPING_IN_STOCK){
|
|
|
141 |
if(colorMap.containsKey(ColorCode.PURPLE.toString())){
|
|
|
142 |
colorMap.put(ColorCode.PURPLE.toString(),colorMap.get(ColorCode.PURPLE.toString())+1);
|
|
|
143 |
}else{
|
|
|
144 |
colorMap.put(ColorCode.PURPLE.toString(),1L);
|
|
|
145 |
}
|
|
|
146 |
}else{
|
|
|
147 |
if(colorMap.containsKey(ColorCode.OTHER.toString())){
|
|
|
148 |
colorMap.put(ColorCode.OTHER.toString(),colorMap.get(ColorCode.OTHER.toString())+1);
|
|
|
149 |
}else{
|
|
|
150 |
colorMap.put(ColorCode.OTHER.toString(),1L);
|
|
|
151 |
}
|
|
|
152 |
}
|
|
|
153 |
transactionsColorMap.put(order.getTransactionId(), colorMap);
|
|
|
154 |
}else{
|
|
|
155 |
Map<String, Long> colorMap = new HashMap<String, Long>();
|
|
|
156 |
if(order.getAlert()==OrderAlert.TODAY_SHIPPING_IN_STOCK){
|
|
|
157 |
colorMap.put(ColorCode.GREEN.toString(),1L);
|
|
|
158 |
}else if(order.getAlert()==OrderAlert.TODAY_SHIPPING_NOT_IN_STOCK){
|
|
|
159 |
colorMap.put(ColorCode.RED.toString(),1L);
|
|
|
160 |
}else if(order.getAlert()==OrderAlert.LATER_SHIPPING_IN_STOCK){
|
|
|
161 |
colorMap.put(ColorCode.PURPLE.toString(),1L);
|
|
|
162 |
}else{
|
|
|
163 |
colorMap.put(ColorCode.OTHER.toString(),1L);
|
|
|
164 |
}
|
|
|
165 |
transactionsColorMap.put(order.getTransactionId(), colorMap);
|
|
|
166 |
}
|
|
|
167 |
|
| 19004 |
manish.sha |
168 |
}
|
| 19196 |
manish.sha |
169 |
|
|
|
170 |
Map<Long, List<Long>> orderCategoryMap = new HashMap<Long, List<Long>>();
|
|
|
171 |
|
|
|
172 |
for(Entry<Long, Map<String, Long>> colorMapEntry : transactionsColorMap.entrySet()){
|
|
|
173 |
Map<String, Long> colorMap = colorMapEntry.getValue();
|
|
|
174 |
List<String> colorSet = new ArrayList<String>(colorMap.keySet());
|
|
|
175 |
long colorMapSize = colorSet.size();
|
|
|
176 |
if(colorMapSize==1){
|
|
|
177 |
if(ColorCode.GREEN.toString().equalsIgnoreCase(colorSet.get(0))){
|
|
|
178 |
if(orderCategoryMap.containsKey(ALL_GREEN)){
|
|
|
179 |
List<Long> transactions = orderCategoryMap.get(ALL_GREEN);
|
|
|
180 |
transactions.add(colorMapEntry.getKey());
|
|
|
181 |
orderCategoryMap.put(ALL_GREEN, transactions);
|
|
|
182 |
}else{
|
|
|
183 |
List<Long> transactions = new ArrayList<Long>();
|
|
|
184 |
transactions.add(colorMapEntry.getKey());
|
|
|
185 |
orderCategoryMap.put(ALL_GREEN, transactions);
|
|
|
186 |
}
|
|
|
187 |
}else if(ColorCode.RED.toString().equalsIgnoreCase(colorSet.get(0))){
|
|
|
188 |
if(orderCategoryMap.containsKey(ALL_RED)){
|
|
|
189 |
List<Long> transactions = orderCategoryMap.get(ALL_RED);
|
|
|
190 |
transactions.add(colorMapEntry.getKey());
|
|
|
191 |
orderCategoryMap.put(ALL_RED, transactions);
|
|
|
192 |
}else{
|
|
|
193 |
List<Long> transactions = new ArrayList<Long>();
|
|
|
194 |
transactions.add(colorMapEntry.getKey());
|
|
|
195 |
orderCategoryMap.put(ALL_RED, transactions);
|
|
|
196 |
}
|
|
|
197 |
}else if(ColorCode.PURPLE.toString().equalsIgnoreCase(colorSet.get(0))){
|
|
|
198 |
if(orderCategoryMap.containsKey(ALL_PURPLE)){
|
|
|
199 |
List<Long> transactions = orderCategoryMap.get(ALL_PURPLE);
|
|
|
200 |
transactions.add(colorMapEntry.getKey());
|
|
|
201 |
orderCategoryMap.put(ALL_PURPLE, transactions);
|
|
|
202 |
}else{
|
|
|
203 |
List<Long> transactions = new ArrayList<Long>();
|
|
|
204 |
transactions.add(colorMapEntry.getKey());
|
|
|
205 |
orderCategoryMap.put(ALL_PURPLE, transactions);
|
|
|
206 |
}
|
|
|
207 |
}else{
|
|
|
208 |
if(orderCategoryMap.containsKey(ALL_OTHERS)){
|
|
|
209 |
List<Long> transactions = orderCategoryMap.get(ALL_OTHERS);
|
|
|
210 |
transactions.add(colorMapEntry.getKey());
|
|
|
211 |
orderCategoryMap.put(ALL_OTHERS, transactions);
|
|
|
212 |
}else{
|
|
|
213 |
List<Long> transactions = new ArrayList<Long>();
|
|
|
214 |
transactions.add(colorMapEntry.getKey());
|
|
|
215 |
orderCategoryMap.put(ALL_OTHERS, transactions);
|
|
|
216 |
}
|
|
|
217 |
}
|
|
|
218 |
}else if(colorMapSize>1){
|
|
|
219 |
if(colorSet.contains(ColorCode.GREEN.toString())){
|
|
|
220 |
if(colorSet.contains(ColorCode.PURPLE.toString())){
|
|
|
221 |
if(orderCategoryMap.containsKey(GREEN_AND_PURPULE)){
|
|
|
222 |
List<Long> transactions = orderCategoryMap.get(GREEN_AND_PURPULE);
|
|
|
223 |
transactions.add(colorMapEntry.getKey());
|
|
|
224 |
orderCategoryMap.put(GREEN_AND_PURPULE, transactions);
|
|
|
225 |
}else{
|
|
|
226 |
List<Long> transactions = new ArrayList<Long>();
|
|
|
227 |
transactions.add(colorMapEntry.getKey());
|
|
|
228 |
orderCategoryMap.put(GREEN_AND_PURPULE, transactions);
|
|
|
229 |
}
|
|
|
230 |
}else{
|
|
|
231 |
if(orderCategoryMap.containsKey(GREEN_AND_IN_RED_OR_WHITE)){
|
|
|
232 |
List<Long> transactions = orderCategoryMap.get(GREEN_AND_IN_RED_OR_WHITE);
|
|
|
233 |
transactions.add(colorMapEntry.getKey());
|
|
|
234 |
orderCategoryMap.put(GREEN_AND_IN_RED_OR_WHITE, transactions);
|
|
|
235 |
}else{
|
|
|
236 |
List<Long> transactions = new ArrayList<Long>();
|
|
|
237 |
transactions.add(colorMapEntry.getKey());
|
|
|
238 |
orderCategoryMap.put(GREEN_AND_IN_RED_OR_WHITE, transactions);
|
|
|
239 |
}
|
|
|
240 |
}
|
|
|
241 |
}else if(colorSet.contains(ColorCode.PURPLE.toString())){
|
|
|
242 |
if(orderCategoryMap.containsKey(PURPLE_AND_IN_RED_OR_WHITE)){
|
|
|
243 |
List<Long> transactions = orderCategoryMap.get(PURPLE_AND_IN_RED_OR_WHITE);
|
|
|
244 |
transactions.add(colorMapEntry.getKey());
|
|
|
245 |
orderCategoryMap.put(PURPLE_AND_IN_RED_OR_WHITE, transactions);
|
|
|
246 |
}else{
|
|
|
247 |
List<Long> transactions = new ArrayList<Long>();
|
|
|
248 |
transactions.add(colorMapEntry.getKey());
|
|
|
249 |
orderCategoryMap.put(PURPLE_AND_IN_RED_OR_WHITE, transactions);
|
|
|
250 |
}
|
|
|
251 |
}else{
|
|
|
252 |
if(orderCategoryMap.containsKey(ALL_OTHERS)){
|
|
|
253 |
List<Long> transactions = orderCategoryMap.get(ALL_OTHERS);
|
|
|
254 |
transactions.add(colorMapEntry.getKey());
|
|
|
255 |
orderCategoryMap.put(ALL_OTHERS, transactions);
|
|
|
256 |
}else{
|
|
|
257 |
List<Long> transactions = new ArrayList<Long>();
|
|
|
258 |
transactions.add(colorMapEntry.getKey());
|
|
|
259 |
orderCategoryMap.put(ALL_OTHERS, transactions);
|
|
|
260 |
}
|
|
|
261 |
}
|
|
|
262 |
}
|
| 19004 |
manish.sha |
263 |
}
|
| 19110 |
manish.sha |
264 |
|
| 19196 |
manish.sha |
265 |
List<Long> categoryList = new ArrayList<Long>(orderCategoryMap.keySet());
|
|
|
266 |
Collections.sort(categoryList);
|
| 19110 |
manish.sha |
267 |
|
| 19196 |
manish.sha |
268 |
orders = new ArrayList<Order>();
|
|
|
269 |
for(Long category:categoryList){
|
|
|
270 |
List<Long> transactions = orderCategoryMap.get(category);
|
|
|
271 |
for(Long transactionId: transactions){
|
|
|
272 |
List<Order> txnOrders = transactionOrdersMap.get(transactionId);
|
|
|
273 |
Collections.sort(txnOrders,new OrderPromisedShippingComparator());
|
|
|
274 |
orders.addAll(txnOrders);
|
|
|
275 |
}
|
| 19004 |
manish.sha |
276 |
}
|
|
|
277 |
}
|
|
|
278 |
|
| 493 |
rajveer |
279 |
}catch(Exception e){
|
| 2449 |
chandransh |
280 |
e.printStackTrace();
|
| 493 |
rajveer |
281 |
}
|
|
|
282 |
return orders;
|
|
|
283 |
}
|
|
|
284 |
|
| 2449 |
chandransh |
285 |
/**
|
| 4133 |
chandransh |
286 |
* Wrapper around the method of same name in the transaction service. This
|
|
|
287 |
* method uses a mapping of <i>type</i> to <i>status</i> to get the count of
|
|
|
288 |
* all orders with a given status.
|
|
|
289 |
*
|
|
|
290 |
* @param type
|
|
|
291 |
* The type of orders to return.
|
|
|
292 |
* @param warehouseId
|
|
|
293 |
* The warehouse for which the orders should be queried.
|
|
|
294 |
* @return The count of orders of the given type assigned to the given
|
|
|
295 |
* warehouse.
|
|
|
296 |
*/
|
| 8303 |
amar.kumar |
297 |
public static int getOrderCount(OrderType type, long warehouseId, long source){
|
| 4133 |
chandransh |
298 |
List<OrderStatus> statuses = getStatuses(type);
|
|
|
299 |
|
|
|
300 |
int count = 0;
|
|
|
301 |
try{
|
|
|
302 |
TransactionClient txnClient = new TransactionClient();
|
|
|
303 |
Client client = txnClient.getClient();
|
| 8303 |
amar.kumar |
304 |
count += client.getOrderCount(statuses, warehouseId, source);
|
| 4133 |
chandransh |
305 |
}catch(Exception e){
|
|
|
306 |
e.printStackTrace();
|
|
|
307 |
}
|
|
|
308 |
return count;
|
|
|
309 |
}
|
|
|
310 |
|
|
|
311 |
/**
|
| 2449 |
chandransh |
312 |
* Calls the same method of the transaction service and returns the status
|
|
|
313 |
* returned. Catches all exceptions that are raised and returns false in
|
|
|
314 |
* that case.
|
|
|
315 |
*
|
|
|
316 |
* @param warehouseId
|
|
|
317 |
* The warehouse for which the orders should be marked as
|
|
|
318 |
* manifested.
|
|
|
319 |
* @param providerId
|
|
|
320 |
* The provider for which the orders should be marked as
|
|
|
321 |
* manifested.
|
| 3065 |
chandransh |
322 |
* @param cod
|
|
|
323 |
* Whether cod orders have to be marked as manifested
|
| 2449 |
chandransh |
324 |
* @return True if everything goes fine, false otherwise.
|
|
|
325 |
*/
|
| 5769 |
rajveer |
326 |
public static Map<Long, Long> getBilledOrders(long warehouseId, String providerId, boolean cod){
|
|
|
327 |
Map<Long, Long> orders = new HashMap<Long, Long>();
|
| 760 |
chandransh |
328 |
try {
|
|
|
329 |
long provider_id = Long.parseLong(providerId);
|
| 3132 |
rajveer |
330 |
TransactionClient client = new TransactionClient();
|
| 760 |
chandransh |
331 |
Client c = client.getClient();
|
| 4790 |
rajveer |
332 |
|
|
|
333 |
List<OrderStatus> statuses = new ArrayList<OrderStatus>();
|
|
|
334 |
statuses.add(OrderStatus.BILLED);
|
| 8303 |
amar.kumar |
335 |
List<in.shop2020.model.v1.order.Order> torders = c.getOrdersInBatch(statuses, 0, 0, warehouseId, 0);
|
| 4790 |
rajveer |
336 |
for(in.shop2020.model.v1.order.Order torder: torders){
|
| 5556 |
rajveer |
337 |
if(torder.getLogistics_provider_id() == provider_id && torder.isLogisticsCod() == cod){
|
| 5769 |
rajveer |
338 |
orders.put(torder.getId(), torder.getPickupStoreId());
|
| 4790 |
rajveer |
339 |
}
|
| 4411 |
rajveer |
340 |
}
|
|
|
341 |
|
| 760 |
chandransh |
342 |
}catch(Exception e){
|
|
|
343 |
e.printStackTrace();
|
|
|
344 |
}
|
| 4790 |
rajveer |
345 |
return orders;
|
| 760 |
chandransh |
346 |
}
|
| 2449 |
chandransh |
347 |
|
| 4790 |
rajveer |
348 |
public static boolean generateCourierDetailsFile(List<Long> orderIds, long providerId, long warehouseId, boolean isCod){
|
| 4411 |
rajveer |
349 |
Calendar date = new GregorianCalendar();
|
|
|
350 |
int year = date.get(Calendar.YEAR);
|
|
|
351 |
int month = date.get(Calendar.MONTH) +1;
|
|
|
352 |
int day = date.get(Calendar.DAY_OF_MONTH);
|
|
|
353 |
|
|
|
354 |
String fileNameSuffix = "-" + warehouseId + "-"+ providerId + "-" + year + "-" + month + "-" + day;
|
|
|
355 |
if(isCod){
|
|
|
356 |
fileNameSuffix = "cod" + fileNameSuffix ;
|
|
|
357 |
}
|
|
|
358 |
else{
|
|
|
359 |
fileNameSuffix = "prepaid" + fileNameSuffix;
|
|
|
360 |
}
|
|
|
361 |
|
|
|
362 |
try {
|
| 4790 |
rajveer |
363 |
String fileName = courierDetailsPath + "/courier-details-" + fileNameSuffix + "-temp.xls";
|
| 4415 |
rajveer |
364 |
FileOutputStream f = new FileOutputStream(fileName);
|
| 4411 |
rajveer |
365 |
CourierDetailsGenerator courierDetailsGenerator = new CourierDetailsGenerator();
|
| 4790 |
rajveer |
366 |
ByteArrayOutputStream baosXLS = courierDetailsGenerator.generateCourierDetails(orderIds, warehouseId, providerId, isCod);
|
| 4411 |
rajveer |
367 |
baosXLS.writeTo(f);
|
|
|
368 |
f.close();
|
|
|
369 |
} catch (FileNotFoundException e) {
|
|
|
370 |
logger.error("Unable to create the courier details file", e);
|
|
|
371 |
} catch (IOException e) {
|
|
|
372 |
logger.error("Unable to create the courier details file", e);
|
|
|
373 |
}
|
|
|
374 |
|
|
|
375 |
CourierDetailsReportMerger merger = new CourierDetailsReportMerger();
|
|
|
376 |
try {
|
|
|
377 |
Map<Long, String> warehouseIdFileNames = new HashMap<Long, String>();
|
| 4790 |
rajveer |
378 |
String fName;
|
|
|
379 |
fName = courierDetailsPath + "/courier-details-" + fileNameSuffix + "-temp.xls";
|
|
|
380 |
if((new File(fName)).exists()){
|
|
|
381 |
warehouseIdFileNames.put(0L, fName);
|
| 4411 |
rajveer |
382 |
}
|
| 4790 |
rajveer |
383 |
fName = courierDetailsPath + "/courier-details-" + fileNameSuffix + ".xls";
|
|
|
384 |
if((new File(fName)).exists()){
|
|
|
385 |
warehouseIdFileNames.put(1L, fName);
|
| 4411 |
rajveer |
386 |
}
|
| 4790 |
rajveer |
387 |
ByteArrayOutputStream binXLS = merger.mergeCourierDetailsReports(warehouseIdFileNames);
|
|
|
388 |
FileOutputStream f = new FileOutputStream(courierDetailsPath + "/courier-details-" + fileNameSuffix + ".xls");
|
| 4411 |
rajveer |
389 |
binXLS.writeTo(f);
|
|
|
390 |
f.close();
|
| 4790 |
rajveer |
391 |
File tempFile = new File(courierDetailsPath + "/courier-details-" + fileNameSuffix + "-temp.xls");
|
|
|
392 |
if(tempFile.exists()){
|
|
|
393 |
tempFile.delete();
|
|
|
394 |
}
|
| 4411 |
rajveer |
395 |
} catch (FileNotFoundException e) {
|
|
|
396 |
logger.error("Error while creating the Courier Details report", e);
|
|
|
397 |
} catch (IOException e) {
|
|
|
398 |
logger.error("IO error while writing the Courier Details report", e);
|
|
|
399 |
}
|
|
|
400 |
return true;
|
|
|
401 |
}
|
|
|
402 |
|
| 671 |
chandransh |
403 |
/**
|
| 2449 |
chandransh |
404 |
*
|
| 671 |
chandransh |
405 |
* @param t_order
|
| 2449 |
chandransh |
406 |
* A thrift order object with line items.
|
|
|
407 |
* @return an Order bean which can be used for rendering on the client side.
|
| 671 |
chandransh |
408 |
*/
|
|
|
409 |
public static Order getOrderFromThriftOrder(in.shop2020.model.v1.order.Order t_order) {
|
| 914 |
chandransh |
410 |
LineItem lineItem = t_order.getLineitems().get(0);
|
| 5110 |
mandeep.dh |
411 |
String pickFromWarehouse = null;
|
|
|
412 |
Item item = null;
|
| 19004 |
manish.sha |
413 |
String warehouseType = "";
|
| 13146 |
manish.sha |
414 |
|
|
|
415 |
Map<Long, Map<String, String>> acceptTogetherOrdersMap = null;
|
|
|
416 |
Map<Long, Map<String, String>> billTogetherOrdersMap = null;
|
| 5110 |
mandeep.dh |
417 |
|
|
|
418 |
try {
|
| 5945 |
mandeep.dh |
419 |
in.shop2020.model.v1.catalog.CatalogService.Client client = new CatalogClient().getClient();
|
| 5948 |
mandeep.dh |
420 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = new InventoryClient().getClient();
|
| 5110 |
mandeep.dh |
421 |
item = client.getItem(lineItem.getItem_id());
|
|
|
422 |
pickFromWarehouse = CatalogUtils.getWarehousesForBillingWarehouse(t_order.getWarehouse_id())
|
|
|
423 |
.get(t_order.getFulfilmentWarehouseId());
|
|
|
424 |
|
|
|
425 |
if (pickFromWarehouse == null) {
|
| 5948 |
mandeep.dh |
426 |
Warehouse warehouse = inventoryClient.getWarehouse(t_order.getFulfilmentWarehouseId());
|
|
|
427 |
pickFromWarehouse = inventoryClient.getWarehouses(null, InventoryType.GOOD, warehouse.getVendor().getId(), t_order.getWarehouse_id(), 0).get(0).getDisplayName();
|
| 13146 |
manish.sha |
428 |
}
|
|
|
429 |
if(!t_order.isSetAccepted_timestamp()){
|
|
|
430 |
acceptTogetherOrdersMap = new HashMap<Long, Map<String, String>>();
|
|
|
431 |
Map<String, String> orderValuesMap = new HashMap<String, String>();
|
|
|
432 |
orderValuesMap.put("ProductName", getItemDisplayName(lineItem));
|
|
|
433 |
orderValuesMap.put("Quantity", lineItem.getQuantity()+"");
|
| 18100 |
manish.sha |
434 |
if(!inventoryClient.isAlive()){
|
|
|
435 |
inventoryClient = new InventoryClient().getClient();
|
|
|
436 |
}
|
|
|
437 |
Warehouse fulfillmentWarehouse = inventoryClient.getWarehouse(t_order.getFulfilmentWarehouseId());
|
| 19004 |
manish.sha |
438 |
warehouseType = fulfillmentWarehouse.getWarehouseType().toString();
|
| 18100 |
manish.sha |
439 |
orderValuesMap.put("WarehouseType", fulfillmentWarehouse.getWarehouseType().toString());
|
| 19054 |
manish.sha |
440 |
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy");
|
| 18938 |
manish.sha |
441 |
orderValuesMap.put("Promised_Shipping", sdf.format(new Date(t_order.getPromised_shipping_time())));
|
| 18964 |
manish.sha |
442 |
NumberFormat formatter = new DecimalFormat("#0.000");
|
|
|
443 |
orderValuesMap.put("Weight", formatter.format(t_order.getLineitems().get(0).getUnit_weight()));
|
|
|
444 |
formatter = new DecimalFormat("#0.00");
|
| 18938 |
manish.sha |
445 |
orderValuesMap.put("UnitPrice", formatter.format(t_order.getLineitems().get(0).getUnit_price()));
|
| 18964 |
manish.sha |
446 |
orderValuesMap.put("PackQuantity", item.getPackQuantity()+"");
|
| 13146 |
manish.sha |
447 |
acceptTogetherOrdersMap.put(t_order.getId(), orderValuesMap);
|
|
|
448 |
List<in.shop2020.model.v1.order.Order> taOrders = new TransactionClient().getClient().getOrdersForTransaction(t_order.getTransactionId(), t_order.getCustomer_id());
|
|
|
449 |
in.shop2020.logistics.Provider provider = new LogisticsClient().getClient().getProvider(t_order.getLogistics_provider_id());
|
|
|
450 |
for(in.shop2020.model.v1.order.Order taOrder : taOrders){
|
|
|
451 |
LineItem lineItem1 = taOrder.getLineitems().get(0);
|
|
|
452 |
if(t_order.getId()==taOrder.getId()){
|
|
|
453 |
continue;
|
| 13156 |
manish.sha |
454 |
}
|
|
|
455 |
else if(taOrder.getSource()!=OrderSource.WEBSITE.getValue()){
|
|
|
456 |
continue;
|
|
|
457 |
}
|
|
|
458 |
else{
|
| 13146 |
manish.sha |
459 |
orderValuesMap = new HashMap<String, String>();
|
| 13323 |
manish.sha |
460 |
if(provider.isGroupShipmentAllowed() && !taOrder.isSetAccepted_timestamp() && t_order.getStatus()==taOrder.getStatus()
|
|
|
461 |
&& taOrder.getLogistics_provider_id()==t_order.getLogistics_provider_id()
|
|
|
462 |
&& taOrder.isLogisticsCod()==t_order.isLogisticsCod() && taOrder.getWarehouse_id() == t_order.getWarehouse_id()
|
|
|
463 |
&& taOrder.getOrderType() == t_order.getOrderType() && taOrder.getPickupStoreId() == t_order.getPickupStoreId()){
|
| 13146 |
manish.sha |
464 |
orderValuesMap.put("ProductName", getItemDisplayName(lineItem1));
|
|
|
465 |
orderValuesMap.put("Quantity", lineItem1.getQuantity()+"");
|
| 18100 |
manish.sha |
466 |
if(!inventoryClient.isAlive()){
|
|
|
467 |
inventoryClient = new InventoryClient().getClient();
|
|
|
468 |
}
|
|
|
469 |
fulfillmentWarehouse = inventoryClient.getWarehouse(taOrder.getFulfilmentWarehouseId());
|
|
|
470 |
orderValuesMap.put("WarehouseType", fulfillmentWarehouse.getWarehouseType().toString());
|
| 18938 |
manish.sha |
471 |
orderValuesMap.put("Promised_Shipping", sdf.format(new Date(taOrder.getPromised_shipping_time())));
|
|
|
472 |
orderValuesMap.put("UnitPrice", formatter.format(taOrder.getLineitems().get(0).getUnit_price()));
|
| 18964 |
manish.sha |
473 |
formatter = new DecimalFormat("#0.000");
|
|
|
474 |
orderValuesMap.put("Weight", formatter.format(taOrder.getLineitems().get(0).getUnit_weight()));
|
|
|
475 |
Item orderItem = client.getItem(taOrder.getLineitems().get(0).getItem_id());
|
|
|
476 |
orderValuesMap.put("PackQuantity", orderItem.getPackQuantity()+"");
|
| 13146 |
manish.sha |
477 |
}
|
|
|
478 |
if(orderValuesMap!=null && orderValuesMap.size()>0){
|
|
|
479 |
acceptTogetherOrdersMap.put(taOrder.getId(), orderValuesMap);
|
|
|
480 |
}
|
|
|
481 |
}
|
|
|
482 |
}
|
| 5110 |
mandeep.dh |
483 |
}
|
| 13146 |
manish.sha |
484 |
|
|
|
485 |
if(t_order.isSetLogisticsTransactionId()){
|
|
|
486 |
billTogetherOrdersMap = new HashMap<Long, Map<String, String>>();
|
|
|
487 |
Map<String, String> orderValuesMap = new HashMap<String, String>();
|
| 19091 |
manish.sha |
488 |
if(t_order.getStatus()==OrderStatus.ACCEPTED || t_order.getStatus()==OrderStatus.RTO_IN_TRANSIT ){
|
| 18100 |
manish.sha |
489 |
orderValuesMap.put("ProductName", getItemDisplayName(lineItem));
|
|
|
490 |
orderValuesMap.put("Quantity", lineItem.getQuantity()+"");
|
|
|
491 |
if(ItemType.SERIALIZED==item.getType()){
|
|
|
492 |
orderValuesMap.put("IsSerialized", "true");
|
|
|
493 |
}else{
|
|
|
494 |
orderValuesMap.put("IsSerialized", "false");
|
|
|
495 |
}
|
|
|
496 |
if(t_order.isSetFreebieItemId() && t_order.getFreebieItemId()!=0){
|
|
|
497 |
orderValuesMap.put("IsFreebie", "true");
|
|
|
498 |
} else {
|
|
|
499 |
orderValuesMap.put("IsFreebie", "false");
|
|
|
500 |
}
|
|
|
501 |
billTogetherOrdersMap.put(t_order.getId(), orderValuesMap);
|
| 13146 |
manish.sha |
502 |
}
|
|
|
503 |
Map<Long, Item> orderItemMap = new HashMap<Long, Item>();
|
|
|
504 |
List<in.shop2020.model.v1.order.Order> taOrders = new TransactionClient().getClient().getGroupOrdersByLogisticsTxnId(t_order.getLogisticsTransactionId());
|
|
|
505 |
for(in.shop2020.model.v1.order.Order ord1: taOrders){
|
| 19091 |
manish.sha |
506 |
if(ord1.getStatus()==OrderStatus.ACCEPTED || ord1.getStatus()==OrderStatus.RTO_IN_TRANSIT ){
|
| 18100 |
manish.sha |
507 |
if(ord1.getId()== t_order.getId()){
|
|
|
508 |
orderItemMap.put(ord1.getId(), item);
|
|
|
509 |
} else {
|
|
|
510 |
if(!client.isAlive()){
|
|
|
511 |
client = new CatalogClient().getClient();
|
|
|
512 |
}
|
|
|
513 |
Item it = client.getItem(ord1.getLineitems().get(0).getItem_id());
|
|
|
514 |
orderItemMap.put(ord1.getId(), it);
|
| 13146 |
manish.sha |
515 |
}
|
|
|
516 |
}
|
|
|
517 |
}
|
|
|
518 |
|
|
|
519 |
for(in.shop2020.model.v1.order.Order taOrder: taOrders){
|
| 19091 |
manish.sha |
520 |
if(taOrder.getStatus()==OrderStatus.ACCEPTED || taOrder.getStatus()==OrderStatus.RTO_IN_TRANSIT ){
|
| 18100 |
manish.sha |
521 |
if(taOrder.getId()==t_order.getId()){
|
|
|
522 |
continue;
|
|
|
523 |
} else {
|
|
|
524 |
orderValuesMap = new HashMap<String, String>();
|
|
|
525 |
Item orderItem = orderItemMap.get(taOrder.getId());
|
|
|
526 |
orderValuesMap.put("ProductName", getProductName(orderItem));
|
|
|
527 |
orderValuesMap.put("Quantity", taOrder.getLineitems().get(0).getQuantity()+"");
|
|
|
528 |
if(ItemType.SERIALIZED==orderItem.getType()){
|
|
|
529 |
orderValuesMap.put("IsSerialized", "true");
|
|
|
530 |
}else{
|
|
|
531 |
orderValuesMap.put("IsSerialized", "false");
|
|
|
532 |
}
|
|
|
533 |
if(taOrder.isSetFreebieItemId() && taOrder.getFreebieItemId()!=0){
|
|
|
534 |
orderValuesMap.put("IsFreebie", "true");
|
|
|
535 |
} else {
|
|
|
536 |
orderValuesMap.put("IsFreebie", "false");
|
|
|
537 |
}
|
|
|
538 |
billTogetherOrdersMap.put(taOrder.getId(), orderValuesMap);
|
|
|
539 |
}
|
| 13146 |
manish.sha |
540 |
}
|
|
|
541 |
}
|
|
|
542 |
}
|
|
|
543 |
else{
|
|
|
544 |
billTogetherOrdersMap = new HashMap<Long, Map<String, String>>();
|
|
|
545 |
Map<String, String> orderValuesMap = new HashMap<String, String>();
|
|
|
546 |
orderValuesMap.put("ProductName", getItemDisplayName(lineItem));
|
|
|
547 |
orderValuesMap.put("Quantity", lineItem.getQuantity()+"");
|
|
|
548 |
if(ItemType.SERIALIZED==item.getType()){
|
|
|
549 |
orderValuesMap.put("IsSerialized", "true");
|
|
|
550 |
}else{
|
|
|
551 |
orderValuesMap.put("IsSerialized", "false");
|
|
|
552 |
}
|
|
|
553 |
if(t_order.isSetFreebieItemId() && t_order.getFreebieItemId()!=0){
|
|
|
554 |
orderValuesMap.put("IsFreebie", "true");
|
|
|
555 |
} else {
|
|
|
556 |
orderValuesMap.put("IsFreebie", "false");
|
|
|
557 |
}
|
|
|
558 |
billTogetherOrdersMap.put(t_order.getId(), orderValuesMap);
|
|
|
559 |
}
|
| 5110 |
mandeep.dh |
560 |
}
|
|
|
561 |
catch (Exception e) {
|
|
|
562 |
logger.error("Error looking up warehouse: " + t_order.getVendorId(), e);
|
|
|
563 |
}
|
|
|
564 |
|
| 3553 |
chandransh |
565 |
String delayReason = null;
|
|
|
566 |
if(t_order.getDelayReason() != null)
|
| 7433 |
rajveer |
567 |
delayReason = t_order.getDelayReason().name();
|
| 3553 |
chandransh |
568 |
|
| 7556 |
rajveer |
569 |
String osource = OrderSource.findByValue((int)t_order.getSource()).toString();
|
| 7433 |
rajveer |
570 |
|
| 966 |
chandransh |
571 |
Order order = new Order(t_order.getId(),
|
|
|
572 |
t_order.getCustomer_id(),
|
|
|
573 |
t_order.getCustomer_name(),
|
|
|
574 |
t_order.getCustomer_mobilenumber(),
|
|
|
575 |
t_order.getCustomer_pincode(),
|
|
|
576 |
t_order.getCustomer_address1(),
|
|
|
577 |
t_order.getCustomer_address2(),
|
|
|
578 |
t_order.getCustomer_city(),
|
|
|
579 |
t_order.getCustomer_state(),
|
|
|
580 |
t_order.getCustomer_email(),
|
|
|
581 |
t_order.getCreated_timestamp(),
|
| 4004 |
chandransh |
582 |
t_order.getShipping_timestamp(),
|
|
|
583 |
t_order.getVerification_timestamp(),
|
| 966 |
chandransh |
584 |
t_order.getExpected_delivery_time(),
|
| 3994 |
chandransh |
585 |
t_order.getPromised_delivery_time(),
|
| 4004 |
chandransh |
586 |
t_order.getExpected_shipping_time(),
|
| 4666 |
rajveer |
587 |
t_order.getPromised_shipping_time(),
|
| 966 |
chandransh |
588 |
t_order.getStatus().getValue(),
|
|
|
589 |
t_order.getStatusDescription(),
|
| 5527 |
anupam.sin |
590 |
t_order.getOrderType().name(),
|
| 966 |
chandransh |
591 |
lineItem.getItem_id(),
|
|
|
592 |
lineItem.getProductGroup(),
|
|
|
593 |
lineItem.getBrand(),
|
|
|
594 |
lineItem.getModel_name(),
|
|
|
595 |
lineItem.getModel_number(),
|
|
|
596 |
lineItem.getColor(),
|
|
|
597 |
lineItem.getExtra_info(),
|
| 4172 |
rajveer |
598 |
lineItem.getDealText(),
|
| 5387 |
rajveer |
599 |
lineItem.getQuantity(),
|
| 2782 |
chandransh |
600 |
t_order.getTotal_amount(),
|
|
|
601 |
t_order.getTotal_weight(),
|
|
|
602 |
t_order.getAirwaybill_no(),
|
|
|
603 |
t_order.getBilled_by(),
|
|
|
604 |
t_order.getInvoice_number(),
|
|
|
605 |
t_order.getJacket_number(),
|
|
|
606 |
lineItem.getItem_number(),
|
| 4659 |
mandeep.dh |
607 |
lineItem.getSerial_number(),
|
| 3065 |
chandransh |
608 |
t_order.getBatchNo(),
|
|
|
609 |
t_order.getSerialNo(),
|
| 2509 |
chandransh |
610 |
t_order.isDoaFlag(),
|
| 3065 |
chandransh |
611 |
t_order.getPickupRequestNo(),
|
| 5556 |
rajveer |
612 |
t_order.isLogisticsCod(),
|
| 5110 |
mandeep.dh |
613 |
delayReason,
|
|
|
614 |
pickFromWarehouse,
|
| 6028 |
rajveer |
615 |
ItemType.SERIALIZED.equals(item.getType()),
|
|
|
616 |
item.isHasItemNo(),
|
| 5769 |
rajveer |
617 |
t_order.getFulfilmentWarehouseId(),
|
| 9263 |
amar.kumar |
618 |
t_order.getWarehouse_id(),
|
| 7190 |
amar.kumar |
619 |
t_order.getPickupStoreId(),
|
| 7422 |
rajveer |
620 |
t_order.getFreebieItemId(),
|
| 8717 |
amar.kumar |
621 |
osource,
|
| 13146 |
manish.sha |
622 |
new Long(t_order.getProductCondition().getValue()),
|
|
|
623 |
t_order.getTransactionId());
|
|
|
624 |
if(acceptTogetherOrdersMap!=null && acceptTogetherOrdersMap.size()>0){
|
|
|
625 |
order.setAcceptTogetherOrdersMap(acceptTogetherOrdersMap);
|
|
|
626 |
}
|
|
|
627 |
if(billTogetherOrdersMap!=null && billTogetherOrdersMap.size()>0){
|
|
|
628 |
order.setBillTogetherOrdersMap(billTogetherOrdersMap);
|
|
|
629 |
}
|
|
|
630 |
if(t_order.isSetLogisticsTransactionId()){
|
|
|
631 |
order.setLogisticsTransactionId(t_order.getLogisticsTransactionId());
|
|
|
632 |
}
|
| 19054 |
manish.sha |
633 |
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
| 19032 |
manish.sha |
634 |
Date date = new Date(System.currentTimeMillis());
|
|
|
635 |
long currentDateTime = 0;
|
| 19196 |
manish.sha |
636 |
long promisedShippingTime =0 ;
|
| 19032 |
manish.sha |
637 |
long currentTime = date.getTime();
|
| 19054 |
manish.sha |
638 |
try{
|
|
|
639 |
currentDateTime = sdf.parse(sdf.format(date)).getTime();
|
| 19196 |
manish.sha |
640 |
promisedShippingTime = sdf.parse(sdf.format(new Date(order.getPromisedShippingTime()))).getTime();
|
| 19054 |
manish.sha |
641 |
}catch(Exception e){
|
|
|
642 |
e.printStackTrace();
|
|
|
643 |
}
|
| 19196 |
manish.sha |
644 |
if(promisedShippingTime >0 && (order.getStatus()==3 || order.getStatus()==5 || order.getStatus()==41 ||
|
| 19058 |
manish.sha |
645 |
order.getStatus()==35 || order.getStatus()==36 || order.getStatus()==37)){
|
| 19196 |
manish.sha |
646 |
if(promisedShippingTime <= currentDateTime){
|
| 19050 |
manish.sha |
647 |
if(loadVirtualWarehouseDetails().contains(order.getFulfilmentWarehouseId())){
|
| 19032 |
manish.sha |
648 |
order.setAlert(OrderAlert.TODAY_SHIPPING_NOT_IN_STOCK);
|
|
|
649 |
}else{
|
|
|
650 |
order.setAlert(OrderAlert.TODAY_SHIPPING_IN_STOCK);
|
|
|
651 |
}
|
|
|
652 |
}else{
|
| 19162 |
manish.sha |
653 |
if(!loadVirtualWarehouseDetails().contains(order.getFulfilmentWarehouseId())){
|
| 19164 |
manish.sha |
654 |
order.setAlert(OrderAlert.LATER_SHIPPING_IN_STOCK);
|
| 19032 |
manish.sha |
655 |
}
|
|
|
656 |
}
|
|
|
657 |
}
|
| 966 |
chandransh |
658 |
return order;
|
| 671 |
chandransh |
659 |
}
|
|
|
660 |
|
| 2449 |
chandransh |
661 |
/**
|
| 2697 |
chandransh |
662 |
* Queries the transction server to get the list of all return orders that
|
|
|
663 |
* have to be processed.
|
|
|
664 |
*
|
|
|
665 |
* @return A list of all return orders to be processed.
|
|
|
666 |
*/
|
|
|
667 |
public static List<ReturnOrder> getReturnOrders(long warehouseId){
|
|
|
668 |
List<ReturnOrder> retOrders = new ArrayList<ReturnOrder>();
|
|
|
669 |
try{
|
| 3132 |
rajveer |
670 |
TransactionClient client = new TransactionClient();
|
| 2697 |
chandransh |
671 |
Client c = client.getClient();
|
|
|
672 |
List<in.shop2020.model.v1.order.ReturnOrder> tRetOrders = c.getReturnOrders(warehouseId, 0L, new Date().getTime());
|
|
|
673 |
for(in.shop2020.model.v1.order.ReturnOrder retOrder : tRetOrders){
|
|
|
674 |
retOrders.add(getReturnOrderFromThriftRO(retOrder));
|
|
|
675 |
}
|
|
|
676 |
}catch(Exception e){
|
|
|
677 |
e.printStackTrace();
|
|
|
678 |
}
|
|
|
679 |
return retOrders;
|
|
|
680 |
}
|
|
|
681 |
|
| 2700 |
chandransh |
682 |
public static ReturnOrder getReturnOrderFromThriftRO(in.shop2020.model.v1.order.ReturnOrder tRetOrder){
|
|
|
683 |
ReturnOrder retOrder = new ReturnOrder(tRetOrder.getOrderId(),
|
|
|
684 |
tRetOrder.getWarehouseId(),
|
|
|
685 |
tRetOrder.getItemId(),
|
|
|
686 |
tRetOrder.getProductGroup(),
|
|
|
687 |
tRetOrder.getBrand(),
|
|
|
688 |
tRetOrder.getModelName(),
|
|
|
689 |
tRetOrder.getModelNumber(),
|
|
|
690 |
tRetOrder.getColor(),
|
|
|
691 |
tRetOrder.getInvoiceNumber(),
|
|
|
692 |
tRetOrder.getJacketNumber(),
|
|
|
693 |
tRetOrder.getTotalPrice(),
|
|
|
694 |
tRetOrder.getTransferPrice(),
|
|
|
695 |
false,
|
|
|
696 |
tRetOrder.getCreatedAt());
|
| 2697 |
chandransh |
697 |
return retOrder;
|
|
|
698 |
}
|
|
|
699 |
|
|
|
700 |
/**
|
| 2449 |
chandransh |
701 |
* This method maps a given type to a list of statuses.
|
|
|
702 |
*
|
|
|
703 |
* @param type
|
|
|
704 |
* The type of orders to fetch.
|
|
|
705 |
* @return The list of Thrift statuses associated with a particular order
|
|
|
706 |
* type.
|
|
|
707 |
*/
|
| 4361 |
rajveer |
708 |
public static List<OrderStatus> getStatuses(OrderType type) {
|
| 2449 |
chandransh |
709 |
List<OrderStatus> statuses = new ArrayList<OrderStatus>();
|
|
|
710 |
|
|
|
711 |
switch (type) {
|
|
|
712 |
case ACCEPTED:
|
|
|
713 |
statuses.add(OrderStatus.ACCEPTED);
|
|
|
714 |
break;
|
|
|
715 |
|
| 4361 |
rajveer |
716 |
case ALL_PENDING:
|
|
|
717 |
statuses.add(OrderStatus.SUBMITTED_FOR_PROCESSING);
|
| 4421 |
mandeep.dh |
718 |
statuses.add(OrderStatus.CAPTURE_IN_PROCESS);
|
| 4361 |
rajveer |
719 |
statuses.add(OrderStatus.INVENTORY_LOW);
|
|
|
720 |
statuses.add(OrderStatus.LOW_INV_PO_RAISED);
|
|
|
721 |
statuses.add(OrderStatus.LOW_INV_REVERSAL_IN_PROCESS);
|
|
|
722 |
statuses.add(OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT);
|
| 2449 |
chandransh |
723 |
break;
|
|
|
724 |
|
|
|
725 |
case NEW:
|
|
|
726 |
statuses.add(OrderStatus.SUBMITTED_FOR_PROCESSING);
|
| 4421 |
mandeep.dh |
727 |
statuses.add(OrderStatus.CAPTURE_IN_PROCESS);
|
| 2449 |
chandransh |
728 |
break;
|
|
|
729 |
|
|
|
730 |
case BILLED:
|
|
|
731 |
statuses.add(OrderStatus.BILLED);
|
|
|
732 |
break;
|
|
|
733 |
|
| 4308 |
rajveer |
734 |
case LOW_INVENTORY:
|
| 2449 |
chandransh |
735 |
statuses.add(OrderStatus.INVENTORY_LOW);
|
|
|
736 |
break;
|
| 4248 |
rajveer |
737 |
|
| 4308 |
rajveer |
738 |
case PO_RAISED:
|
|
|
739 |
statuses.add(OrderStatus.LOW_INV_PO_RAISED);
|
|
|
740 |
break;
|
|
|
741 |
|
|
|
742 |
case REVERSAL_INITIATED:
|
|
|
743 |
statuses.add(OrderStatus.LOW_INV_REVERSAL_IN_PROCESS);
|
|
|
744 |
break;
|
|
|
745 |
|
|
|
746 |
case NOT_AVAILABLE:
|
|
|
747 |
statuses.add(OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT);
|
|
|
748 |
break;
|
|
|
749 |
|
| 4248 |
rajveer |
750 |
case CANCEL_CONFIRMED:
|
|
|
751 |
statuses.add(OrderStatus.CANCEL_REQUEST_CONFIRMED);
|
|
|
752 |
break;
|
| 2449 |
chandransh |
753 |
|
| 4459 |
rajveer |
754 |
case DOA_REQUEST_AUTHORIZED:
|
|
|
755 |
statuses.add(OrderStatus.DOA_REQUEST_AUTHORIZED);
|
| 4515 |
mandeep.dh |
756 |
statuses.add(OrderStatus.DOA_PICKUP_REQUEST_RAISED);
|
| 4459 |
rajveer |
757 |
break;
|
|
|
758 |
|
| 4666 |
rajveer |
759 |
case LOST_IN_TRANSIT:
|
|
|
760 |
statuses.add(OrderStatus.LOST_IN_TRANSIT);
|
|
|
761 |
break;
|
|
|
762 |
|
| 4459 |
rajveer |
763 |
case DOA_LOST_IN_TRANSIT:
|
|
|
764 |
statuses.add(OrderStatus.DOA_LOST_IN_TRANSIT);
|
| 4478 |
rajveer |
765 |
break;
|
|
|
766 |
|
|
|
767 |
case DOA_RECEIVED_DAMAGED:
|
| 4459 |
rajveer |
768 |
statuses.add(OrderStatus.DOA_RECEIVED_DAMAGED);
|
|
|
769 |
break;
|
| 4495 |
rajveer |
770 |
|
|
|
771 |
case RET_REQUEST_AUTHORIZED:
|
|
|
772 |
statuses.add(OrderStatus.RET_REQUEST_AUTHORIZED);
|
| 4515 |
mandeep.dh |
773 |
statuses.add(OrderStatus.RET_PICKUP_REQUEST_RAISED);
|
| 4495 |
rajveer |
774 |
break;
|
|
|
775 |
|
|
|
776 |
case RET_AWAITED:
|
|
|
777 |
statuses.add(OrderStatus.RET_RETURN_IN_TRANSIT);
|
| 4515 |
mandeep.dh |
778 |
statuses.add(OrderStatus.RET_PICKUP_CONFIRMED);
|
| 4495 |
rajveer |
779 |
break;
|
| 4459 |
rajveer |
780 |
|
| 4495 |
rajveer |
781 |
case RET_RECEIVED_PRESTINE:
|
|
|
782 |
statuses.add(OrderStatus.RET_RECEIVED_PRESTINE);
|
| 4515 |
mandeep.dh |
783 |
statuses.add(OrderStatus.RET_PRODUCT_USABLE);
|
| 4495 |
rajveer |
784 |
break;
|
|
|
785 |
|
|
|
786 |
case RET_LOST_IN_TRANSIT:
|
|
|
787 |
statuses.add(OrderStatus.RET_LOST_IN_TRANSIT);
|
|
|
788 |
break;
|
|
|
789 |
|
|
|
790 |
case RET_RECEIVED_DAMAGED:
|
|
|
791 |
statuses.add(OrderStatus.RET_RECEIVED_DAMAGED);
|
| 4515 |
mandeep.dh |
792 |
statuses.add(OrderStatus.RET_PRODUCT_UNUSABLE);
|
| 4495 |
rajveer |
793 |
break;
|
|
|
794 |
|
| 2449 |
chandransh |
795 |
case REJECTED:
|
|
|
796 |
statuses.add(OrderStatus.REJECTED);
|
|
|
797 |
break;
|
|
|
798 |
|
|
|
799 |
case SHIPPED:
|
|
|
800 |
statuses.add(OrderStatus.SHIPPED_FROM_WH);
|
|
|
801 |
statuses.add(OrderStatus.SHIPPED_TO_LOGST);
|
| 5016 |
phani.kuma |
802 |
statuses.add(OrderStatus.SHIPPED_TO_DESTINATION_CITY);
|
|
|
803 |
statuses.add(OrderStatus.REACHED_DESTINATION_CITY);
|
|
|
804 |
statuses.add(OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE);
|
| 2449 |
chandransh |
805 |
break;
|
|
|
806 |
|
|
|
807 |
case DELIVERED:
|
|
|
808 |
statuses.add(OrderStatus.DELIVERY_SUCCESS);
|
| 4452 |
rajveer |
809 |
statuses.add(OrderStatus.DOA_PICKUP_REQUEST_RAISED);
|
| 2449 |
chandransh |
810 |
break;
|
| 2610 |
chandransh |
811 |
|
|
|
812 |
case DOA_AWAITED:
|
| 4452 |
rajveer |
813 |
statuses.add(OrderStatus.DOA_PICKUP_CONFIRMED);
|
| 2610 |
chandransh |
814 |
statuses.add(OrderStatus.DOA_RETURN_IN_TRANSIT);
|
| 4452 |
rajveer |
815 |
statuses.add(OrderStatus.DOA_RECEIVED_PRESTINE);
|
| 2610 |
chandransh |
816 |
break;
|
| 2449 |
chandransh |
817 |
|
| 4495 |
rajveer |
818 |
case RTO_AWAITED:
|
| 4484 |
rajveer |
819 |
statuses.add(OrderStatus.RTO_IN_TRANSIT);
|
| 2509 |
chandransh |
820 |
break;
|
|
|
821 |
|
| 4515 |
mandeep.dh |
822 |
case RTO_RECEIVED_DAMAGED:
|
|
|
823 |
statuses.add(OrderStatus.RTO_RECEIVED_DAMAGED);
|
|
|
824 |
break;
|
|
|
825 |
|
|
|
826 |
case DOA_RECEIVED_PRESTINE:
|
| 2610 |
chandransh |
827 |
statuses.add(OrderStatus.DOA_CERT_VALID);
|
| 4515 |
mandeep.dh |
828 |
statuses.add(OrderStatus.DOA_CERT_INVALID);
|
| 2610 |
chandransh |
829 |
break;
|
|
|
830 |
|
| 4495 |
rajveer |
831 |
case RTO_RETURNED:
|
| 4484 |
rajveer |
832 |
statuses.add(OrderStatus.RTO_RECEIVED_PRESTINE);
|
| 2509 |
chandransh |
833 |
break;
|
|
|
834 |
|
| 2628 |
chandransh |
835 |
case RESHIPPED:
|
| 4484 |
rajveer |
836 |
statuses.add(OrderStatus.RTO_RESHIPPED);
|
| 2628 |
chandransh |
837 |
statuses.add(OrderStatus.DOA_INVALID_RESHIPPED);
|
| 4452 |
rajveer |
838 |
statuses.add(OrderStatus.DOA_VALID_RESHIPPED);
|
| 2628 |
chandransh |
839 |
break;
|
|
|
840 |
|
|
|
841 |
case REFUNDED:
|
| 4682 |
rajveer |
842 |
statuses.add(OrderStatus.COD_VERIFICATION_FAILED);
|
| 4484 |
rajveer |
843 |
statuses.add(OrderStatus.RTO_REFUNDED);
|
| 2628 |
chandransh |
844 |
statuses.add(OrderStatus.DOA_INVALID_REFUNDED);
|
|
|
845 |
statuses.add(OrderStatus.DOA_VALID_REFUNDED);
|
| 4682 |
rajveer |
846 |
statuses.add(OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY);
|
| 2628 |
chandransh |
847 |
break;
|
| 2509 |
chandransh |
848 |
|
| 3065 |
chandransh |
849 |
case VERIFICATION_PENDING:
|
| 4664 |
rajveer |
850 |
statuses.add(OrderStatus.COD_VERIFICATION_PENDING);
|
| 3065 |
chandransh |
851 |
break;
|
| 2449 |
chandransh |
852 |
default:
|
|
|
853 |
break;
|
|
|
854 |
}
|
|
|
855 |
return statuses;
|
|
|
856 |
}
|
| 13146 |
manish.sha |
857 |
|
|
|
858 |
public static List<Long> getEligibleOrdersToBeAccepted(Order order){
|
|
|
859 |
List<Long> orders = new ArrayList<Long>();
|
|
|
860 |
try {
|
|
|
861 |
|
|
|
862 |
TransactionClient client = new TransactionClient();
|
|
|
863 |
Client c = client.getClient();
|
|
|
864 |
|
|
|
865 |
in.shop2020.model.v1.order.Order thriftOrder = c.getOrder(order.getOrderId());
|
|
|
866 |
long provider_id = thriftOrder.getLogistics_provider_id();
|
|
|
867 |
boolean cod = thriftOrder.isLogisticsCod();
|
|
|
868 |
|
|
|
869 |
List<in.shop2020.model.v1.order.Order> torders = c.getOrdersForTransaction(thriftOrder.getTransactionId(), thriftOrder.getCustomer_id());
|
|
|
870 |
for(in.shop2020.model.v1.order.Order torder: torders){
|
|
|
871 |
if(torder.getLogistics_provider_id() == provider_id && torder.isLogisticsCod() == cod){
|
|
|
872 |
orders.add(torder.getId());
|
|
|
873 |
}
|
|
|
874 |
}
|
|
|
875 |
|
|
|
876 |
}catch(Exception e){
|
|
|
877 |
e.printStackTrace();
|
|
|
878 |
}
|
|
|
879 |
return orders;
|
|
|
880 |
}
|
|
|
881 |
|
|
|
882 |
public static String getItemDisplayName(LineItem lineitem){
|
|
|
883 |
StringBuffer itemName = new StringBuffer();
|
|
|
884 |
if (lineitem.getBrand() != null)
|
|
|
885 |
itemName.append(lineitem.getBrand() + " ");
|
|
|
886 |
if (lineitem.getModel_name() != null)
|
|
|
887 |
itemName.append(lineitem.getModel_name() + " ");
|
|
|
888 |
if (lineitem.getModel_number() != null)
|
|
|
889 |
itemName.append(lineitem.getModel_number() + " ");
|
|
|
890 |
if (lineitem.getColor() != null
|
|
|
891 |
&& !lineitem.getColor().trim().equals("NA"))
|
|
|
892 |
itemName.append("(" + lineitem.getColor() + ")");
|
|
|
893 |
|
|
|
894 |
return itemName.toString();
|
|
|
895 |
}
|
|
|
896 |
|
|
|
897 |
public static String getProductName(in.shop2020.model.v1.catalog.Item item){
|
|
|
898 |
StringBuffer itemName = new StringBuffer();
|
|
|
899 |
if (item.getBrand() != null)
|
|
|
900 |
itemName.append(item.getBrand() + " ");
|
|
|
901 |
if (item.getModelName() != null)
|
|
|
902 |
itemName.append(item.getModelName() + " ");
|
|
|
903 |
if (item.getModelNumber() != null)
|
|
|
904 |
itemName.append(item.getModelNumber() + " ");
|
|
|
905 |
if (item.getColor() != null
|
|
|
906 |
&& !item.getColor().trim().equals("NA"))
|
|
|
907 |
itemName.append("(" + item.getColor() + ")");
|
|
|
908 |
|
|
|
909 |
return itemName.toString();
|
|
|
910 |
}
|
| 19050 |
manish.sha |
911 |
|
|
|
912 |
public static List<Long> loadVirtualWarehouseDetails(){
|
|
|
913 |
EhcacheWrapper<String, List<Long>> virtualWhCache = new EhcacheWrapper<String, List<Long>>(
|
|
|
914 |
"VirtualWarehouses", CacheManager.create());
|
|
|
915 |
|
|
|
916 |
List<Long> virtualWarehouseIds = virtualWhCache.get("virtual_warehouses");
|
|
|
917 |
|
|
|
918 |
if(virtualWarehouseIds!=null && virtualWarehouseIds.size()>0){
|
| 19052 |
manish.sha |
919 |
System.out.println("Virtual Warehouse Exists");
|
|
|
920 |
logger.info("Virtual Warehouse Exists");
|
| 19050 |
manish.sha |
921 |
return virtualWarehouseIds;
|
|
|
922 |
}else{
|
| 19052 |
manish.sha |
923 |
System.out.println("Virtual Warehouse Not Exists");
|
|
|
924 |
logger.info("Virtual Warehouse Not Exists");
|
| 19050 |
manish.sha |
925 |
virtualWarehouseIds = new ArrayList<Long>();
|
|
|
926 |
try{
|
|
|
927 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = new InventoryClient().getClient();
|
|
|
928 |
List<Warehouse> allWarehouses = inventoryClient.getWarehouses(null, null, 0, 0, 0);
|
|
|
929 |
for(Warehouse wh:allWarehouses){
|
|
|
930 |
if(wh.getWarehouseType()==WarehouseType.THIRD_PARTY){
|
|
|
931 |
virtualWarehouseIds.add(wh.getId());
|
|
|
932 |
}
|
|
|
933 |
}
|
|
|
934 |
}catch(Exception e){
|
|
|
935 |
e.printStackTrace();
|
|
|
936 |
}
|
|
|
937 |
virtualWhCache.put("virtual_warehouses", virtualWarehouseIds);
|
|
|
938 |
}
|
|
|
939 |
|
|
|
940 |
return virtualWarehouseIds;
|
|
|
941 |
}
|
| 493 |
rajveer |
942 |
}
|