| 493 |
rajveer |
1 |
package in.shop2020.hotspot.dashbaord.server;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.hotspot.dashbaord.shared.actions.Order;
|
|
|
4 |
import in.shop2020.hotspot.dashbaord.shared.actions.OrderType;
|
| 2697 |
chandransh |
5 |
import in.shop2020.hotspot.dashbaord.shared.actions.ReturnOrder;
|
| 5945 |
mandeep.dh |
6 |
import in.shop2020.model.v1.inventory.InventoryType;
|
| 18100 |
manish.sha |
7 |
import in.shop2020.model.v1.inventory.WarehouseType;
|
| 5110 |
mandeep.dh |
8 |
import in.shop2020.model.v1.catalog.Item;
|
|
|
9 |
import in.shop2020.model.v1.catalog.ItemType;
|
| 5945 |
mandeep.dh |
10 |
import in.shop2020.model.v1.inventory.Warehouse;
|
| 914 |
chandransh |
11 |
import in.shop2020.model.v1.order.LineItem;
|
| 7422 |
rajveer |
12 |
import in.shop2020.model.v1.order.OrderSource;
|
| 493 |
rajveer |
13 |
import in.shop2020.model.v1.order.OrderStatus;
|
|
|
14 |
import in.shop2020.model.v1.order.TransactionService.Client;
|
| 5110 |
mandeep.dh |
15 |
import in.shop2020.thrift.clients.CatalogClient;
|
| 5948 |
mandeep.dh |
16 |
import in.shop2020.thrift.clients.InventoryClient;
|
| 3132 |
rajveer |
17 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 13146 |
manish.sha |
18 |
import in.shop2020.thrift.clients.LogisticsClient;
|
| 493 |
rajveer |
19 |
|
| 4411 |
rajveer |
20 |
import java.io.ByteArrayOutputStream;
|
|
|
21 |
import java.io.File;
|
|
|
22 |
import java.io.FileNotFoundException;
|
|
|
23 |
import java.io.FileOutputStream;
|
|
|
24 |
import java.io.IOException;
|
| 493 |
rajveer |
25 |
import java.util.ArrayList;
|
| 4411 |
rajveer |
26 |
import java.util.Calendar;
|
| 493 |
rajveer |
27 |
import java.util.Date;
|
| 4411 |
rajveer |
28 |
import java.util.GregorianCalendar;
|
|
|
29 |
import java.util.HashMap;
|
| 493 |
rajveer |
30 |
import java.util.List;
|
| 4411 |
rajveer |
31 |
import java.util.Map;
|
| 493 |
rajveer |
32 |
|
| 4411 |
rajveer |
33 |
import org.slf4j.Logger;
|
|
|
34 |
import org.slf4j.LoggerFactory;
|
|
|
35 |
|
| 2449 |
chandransh |
36 |
/**
|
|
|
37 |
* This class is a facade to the Transaction service and should be used to
|
| 4133 |
chandransh |
38 |
* access all order specific data which requires some kind of transformation.
|
| 2449 |
chandransh |
39 |
*
|
|
|
40 |
* @author Chandranshu
|
|
|
41 |
*
|
|
|
42 |
*/
|
| 493 |
rajveer |
43 |
public class TransactionUtils {
|
| 4411 |
rajveer |
44 |
private static String courierDetailsPath = "/CourierDetailReports";
|
|
|
45 |
private static Logger logger = LoggerFactory.getLogger(TransactionUtils.class);
|
|
|
46 |
|
| 2449 |
chandransh |
47 |
/**
|
|
|
48 |
* The human user is concerned only with a consolidated view of actionable
|
|
|
49 |
* orders. Orders with different statuses in the database can be part of the
|
|
|
50 |
* same consolidated view. This method uses a mapping of <i>type</i> to
|
|
|
51 |
* <i>status</i> to get all such orders and return them as order beans.
|
|
|
52 |
*
|
|
|
53 |
* @param type
|
|
|
54 |
* The type of orders to return.
|
| 4133 |
chandransh |
55 |
* @param offset
|
|
|
56 |
* Offset to start from
|
|
|
57 |
* @param limit
|
|
|
58 |
* No. of orders to return
|
| 2449 |
chandransh |
59 |
* @param warehouseId
|
|
|
60 |
* The warehouse for which the orders should be queried.
|
|
|
61 |
* @return A list of orders of the given type to be fulfilled from the given
|
|
|
62 |
* warehouse
|
|
|
63 |
*/
|
| 8303 |
amar.kumar |
64 |
public static List<Order> getOrders(OrderType type, long offset, long limit, long warehouseId, long source){
|
| 2449 |
chandransh |
65 |
List<OrderStatus> statuses = getStatuses(type);
|
| 493 |
rajveer |
66 |
|
|
|
67 |
List<Order> orders = new ArrayList<Order>();
|
|
|
68 |
try{
|
| 4133 |
chandransh |
69 |
TransactionClient txnClient = new TransactionClient();
|
|
|
70 |
Client client = txnClient.getClient();
|
| 493 |
rajveer |
71 |
|
|
|
72 |
List<in.shop2020.model.v1.order.Order> t_orders = new ArrayList<in.shop2020.model.v1.order.Order>();
|
| 8303 |
amar.kumar |
73 |
t_orders.addAll(client.getOrdersInBatch(statuses, offset, limit, warehouseId, source));
|
| 493 |
rajveer |
74 |
|
|
|
75 |
for (in.shop2020.model.v1.order.Order t_order: t_orders){
|
| 671 |
chandransh |
76 |
Order o = getOrderFromThriftOrder(t_order);
|
| 493 |
rajveer |
77 |
orders.add(o);
|
|
|
78 |
}
|
|
|
79 |
}catch(Exception e){
|
| 2449 |
chandransh |
80 |
e.printStackTrace();
|
| 493 |
rajveer |
81 |
}
|
|
|
82 |
return orders;
|
|
|
83 |
}
|
|
|
84 |
|
| 2449 |
chandransh |
85 |
/**
|
| 4133 |
chandransh |
86 |
* Wrapper around the method of same name in the transaction service. This
|
|
|
87 |
* method uses a mapping of <i>type</i> to <i>status</i> to get the count of
|
|
|
88 |
* all orders with a given status.
|
|
|
89 |
*
|
|
|
90 |
* @param type
|
|
|
91 |
* The type of orders to return.
|
|
|
92 |
* @param warehouseId
|
|
|
93 |
* The warehouse for which the orders should be queried.
|
|
|
94 |
* @return The count of orders of the given type assigned to the given
|
|
|
95 |
* warehouse.
|
|
|
96 |
*/
|
| 8303 |
amar.kumar |
97 |
public static int getOrderCount(OrderType type, long warehouseId, long source){
|
| 4133 |
chandransh |
98 |
List<OrderStatus> statuses = getStatuses(type);
|
|
|
99 |
|
|
|
100 |
int count = 0;
|
|
|
101 |
try{
|
|
|
102 |
TransactionClient txnClient = new TransactionClient();
|
|
|
103 |
Client client = txnClient.getClient();
|
| 8303 |
amar.kumar |
104 |
count += client.getOrderCount(statuses, warehouseId, source);
|
| 4133 |
chandransh |
105 |
}catch(Exception e){
|
|
|
106 |
e.printStackTrace();
|
|
|
107 |
}
|
|
|
108 |
return count;
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
/**
|
| 2449 |
chandransh |
112 |
* Calls the same method of the transaction service and returns the status
|
|
|
113 |
* returned. Catches all exceptions that are raised and returns false in
|
|
|
114 |
* that case.
|
|
|
115 |
*
|
|
|
116 |
* @param warehouseId
|
|
|
117 |
* The warehouse for which the orders should be marked as
|
|
|
118 |
* manifested.
|
|
|
119 |
* @param providerId
|
|
|
120 |
* The provider for which the orders should be marked as
|
|
|
121 |
* manifested.
|
| 3065 |
chandransh |
122 |
* @param cod
|
|
|
123 |
* Whether cod orders have to be marked as manifested
|
| 2449 |
chandransh |
124 |
* @return True if everything goes fine, false otherwise.
|
|
|
125 |
*/
|
| 5769 |
rajveer |
126 |
public static Map<Long, Long> getBilledOrders(long warehouseId, String providerId, boolean cod){
|
|
|
127 |
Map<Long, Long> orders = new HashMap<Long, Long>();
|
| 760 |
chandransh |
128 |
try {
|
|
|
129 |
long provider_id = Long.parseLong(providerId);
|
| 3132 |
rajveer |
130 |
TransactionClient client = new TransactionClient();
|
| 760 |
chandransh |
131 |
Client c = client.getClient();
|
| 4790 |
rajveer |
132 |
|
|
|
133 |
List<OrderStatus> statuses = new ArrayList<OrderStatus>();
|
|
|
134 |
statuses.add(OrderStatus.BILLED);
|
| 8303 |
amar.kumar |
135 |
List<in.shop2020.model.v1.order.Order> torders = c.getOrdersInBatch(statuses, 0, 0, warehouseId, 0);
|
| 4790 |
rajveer |
136 |
for(in.shop2020.model.v1.order.Order torder: torders){
|
| 5556 |
rajveer |
137 |
if(torder.getLogistics_provider_id() == provider_id && torder.isLogisticsCod() == cod){
|
| 5769 |
rajveer |
138 |
orders.put(torder.getId(), torder.getPickupStoreId());
|
| 4790 |
rajveer |
139 |
}
|
| 4411 |
rajveer |
140 |
}
|
|
|
141 |
|
| 760 |
chandransh |
142 |
}catch(Exception e){
|
|
|
143 |
e.printStackTrace();
|
|
|
144 |
}
|
| 4790 |
rajveer |
145 |
return orders;
|
| 760 |
chandransh |
146 |
}
|
| 2449 |
chandransh |
147 |
|
| 4790 |
rajveer |
148 |
public static boolean generateCourierDetailsFile(List<Long> orderIds, long providerId, long warehouseId, boolean isCod){
|
| 4411 |
rajveer |
149 |
Calendar date = new GregorianCalendar();
|
|
|
150 |
int year = date.get(Calendar.YEAR);
|
|
|
151 |
int month = date.get(Calendar.MONTH) +1;
|
|
|
152 |
int day = date.get(Calendar.DAY_OF_MONTH);
|
|
|
153 |
|
|
|
154 |
String fileNameSuffix = "-" + warehouseId + "-"+ providerId + "-" + year + "-" + month + "-" + day;
|
|
|
155 |
if(isCod){
|
|
|
156 |
fileNameSuffix = "cod" + fileNameSuffix ;
|
|
|
157 |
}
|
|
|
158 |
else{
|
|
|
159 |
fileNameSuffix = "prepaid" + fileNameSuffix;
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
try {
|
| 4790 |
rajveer |
163 |
String fileName = courierDetailsPath + "/courier-details-" + fileNameSuffix + "-temp.xls";
|
| 4415 |
rajveer |
164 |
FileOutputStream f = new FileOutputStream(fileName);
|
| 4411 |
rajveer |
165 |
CourierDetailsGenerator courierDetailsGenerator = new CourierDetailsGenerator();
|
| 4790 |
rajveer |
166 |
ByteArrayOutputStream baosXLS = courierDetailsGenerator.generateCourierDetails(orderIds, warehouseId, providerId, isCod);
|
| 4411 |
rajveer |
167 |
baosXLS.writeTo(f);
|
|
|
168 |
f.close();
|
|
|
169 |
} catch (FileNotFoundException e) {
|
|
|
170 |
logger.error("Unable to create the courier details file", e);
|
|
|
171 |
} catch (IOException e) {
|
|
|
172 |
logger.error("Unable to create the courier details file", e);
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
CourierDetailsReportMerger merger = new CourierDetailsReportMerger();
|
|
|
176 |
try {
|
|
|
177 |
Map<Long, String> warehouseIdFileNames = new HashMap<Long, String>();
|
| 4790 |
rajveer |
178 |
String fName;
|
|
|
179 |
fName = courierDetailsPath + "/courier-details-" + fileNameSuffix + "-temp.xls";
|
|
|
180 |
if((new File(fName)).exists()){
|
|
|
181 |
warehouseIdFileNames.put(0L, fName);
|
| 4411 |
rajveer |
182 |
}
|
| 4790 |
rajveer |
183 |
fName = courierDetailsPath + "/courier-details-" + fileNameSuffix + ".xls";
|
|
|
184 |
if((new File(fName)).exists()){
|
|
|
185 |
warehouseIdFileNames.put(1L, fName);
|
| 4411 |
rajveer |
186 |
}
|
| 4790 |
rajveer |
187 |
ByteArrayOutputStream binXLS = merger.mergeCourierDetailsReports(warehouseIdFileNames);
|
|
|
188 |
FileOutputStream f = new FileOutputStream(courierDetailsPath + "/courier-details-" + fileNameSuffix + ".xls");
|
| 4411 |
rajveer |
189 |
binXLS.writeTo(f);
|
|
|
190 |
f.close();
|
| 4790 |
rajveer |
191 |
File tempFile = new File(courierDetailsPath + "/courier-details-" + fileNameSuffix + "-temp.xls");
|
|
|
192 |
if(tempFile.exists()){
|
|
|
193 |
tempFile.delete();
|
|
|
194 |
}
|
| 4411 |
rajveer |
195 |
} catch (FileNotFoundException e) {
|
|
|
196 |
logger.error("Error while creating the Courier Details report", e);
|
|
|
197 |
} catch (IOException e) {
|
|
|
198 |
logger.error("IO error while writing the Courier Details report", e);
|
|
|
199 |
}
|
|
|
200 |
return true;
|
|
|
201 |
}
|
|
|
202 |
|
| 671 |
chandransh |
203 |
/**
|
| 2449 |
chandransh |
204 |
*
|
| 671 |
chandransh |
205 |
* @param t_order
|
| 2449 |
chandransh |
206 |
* A thrift order object with line items.
|
|
|
207 |
* @return an Order bean which can be used for rendering on the client side.
|
| 671 |
chandransh |
208 |
*/
|
|
|
209 |
public static Order getOrderFromThriftOrder(in.shop2020.model.v1.order.Order t_order) {
|
| 914 |
chandransh |
210 |
LineItem lineItem = t_order.getLineitems().get(0);
|
| 5110 |
mandeep.dh |
211 |
String pickFromWarehouse = null;
|
|
|
212 |
Item item = null;
|
| 13146 |
manish.sha |
213 |
|
|
|
214 |
Map<Long, Map<String, String>> acceptTogetherOrdersMap = null;
|
|
|
215 |
Map<Long, Map<String, String>> billTogetherOrdersMap = null;
|
| 5110 |
mandeep.dh |
216 |
|
|
|
217 |
try {
|
| 5945 |
mandeep.dh |
218 |
in.shop2020.model.v1.catalog.CatalogService.Client client = new CatalogClient().getClient();
|
| 5948 |
mandeep.dh |
219 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = new InventoryClient().getClient();
|
| 5110 |
mandeep.dh |
220 |
item = client.getItem(lineItem.getItem_id());
|
|
|
221 |
pickFromWarehouse = CatalogUtils.getWarehousesForBillingWarehouse(t_order.getWarehouse_id())
|
|
|
222 |
.get(t_order.getFulfilmentWarehouseId());
|
|
|
223 |
|
|
|
224 |
if (pickFromWarehouse == null) {
|
| 5948 |
mandeep.dh |
225 |
Warehouse warehouse = inventoryClient.getWarehouse(t_order.getFulfilmentWarehouseId());
|
|
|
226 |
pickFromWarehouse = inventoryClient.getWarehouses(null, InventoryType.GOOD, warehouse.getVendor().getId(), t_order.getWarehouse_id(), 0).get(0).getDisplayName();
|
| 13146 |
manish.sha |
227 |
}
|
|
|
228 |
if(!t_order.isSetAccepted_timestamp()){
|
|
|
229 |
acceptTogetherOrdersMap = new HashMap<Long, Map<String, String>>();
|
|
|
230 |
Map<String, String> orderValuesMap = new HashMap<String, String>();
|
|
|
231 |
orderValuesMap.put("ProductName", getItemDisplayName(lineItem));
|
|
|
232 |
orderValuesMap.put("Quantity", lineItem.getQuantity()+"");
|
| 18100 |
manish.sha |
233 |
if(!inventoryClient.isAlive()){
|
|
|
234 |
inventoryClient = new InventoryClient().getClient();
|
|
|
235 |
}
|
|
|
236 |
Warehouse fulfillmentWarehouse = inventoryClient.getWarehouse(t_order.getFulfilmentWarehouseId());
|
|
|
237 |
orderValuesMap.put("WarehouseType", fulfillmentWarehouse.getWarehouseType().toString());
|
| 13146 |
manish.sha |
238 |
acceptTogetherOrdersMap.put(t_order.getId(), orderValuesMap);
|
|
|
239 |
List<in.shop2020.model.v1.order.Order> taOrders = new TransactionClient().getClient().getOrdersForTransaction(t_order.getTransactionId(), t_order.getCustomer_id());
|
|
|
240 |
in.shop2020.logistics.Provider provider = new LogisticsClient().getClient().getProvider(t_order.getLogistics_provider_id());
|
|
|
241 |
for(in.shop2020.model.v1.order.Order taOrder : taOrders){
|
|
|
242 |
LineItem lineItem1 = taOrder.getLineitems().get(0);
|
|
|
243 |
if(t_order.getId()==taOrder.getId()){
|
|
|
244 |
continue;
|
| 13156 |
manish.sha |
245 |
}
|
|
|
246 |
else if(taOrder.getSource()!=OrderSource.WEBSITE.getValue()){
|
|
|
247 |
continue;
|
|
|
248 |
}
|
|
|
249 |
else{
|
| 13146 |
manish.sha |
250 |
orderValuesMap = new HashMap<String, String>();
|
| 13323 |
manish.sha |
251 |
if(provider.isGroupShipmentAllowed() && !taOrder.isSetAccepted_timestamp() && t_order.getStatus()==taOrder.getStatus()
|
|
|
252 |
&& taOrder.getLogistics_provider_id()==t_order.getLogistics_provider_id()
|
|
|
253 |
&& taOrder.isLogisticsCod()==t_order.isLogisticsCod() && taOrder.getWarehouse_id() == t_order.getWarehouse_id()
|
|
|
254 |
&& taOrder.getOrderType() == t_order.getOrderType() && taOrder.getPickupStoreId() == t_order.getPickupStoreId()){
|
| 13146 |
manish.sha |
255 |
orderValuesMap.put("ProductName", getItemDisplayName(lineItem1));
|
|
|
256 |
orderValuesMap.put("Quantity", lineItem1.getQuantity()+"");
|
| 18100 |
manish.sha |
257 |
if(!inventoryClient.isAlive()){
|
|
|
258 |
inventoryClient = new InventoryClient().getClient();
|
|
|
259 |
}
|
|
|
260 |
fulfillmentWarehouse = inventoryClient.getWarehouse(taOrder.getFulfilmentWarehouseId());
|
|
|
261 |
orderValuesMap.put("WarehouseType", fulfillmentWarehouse.getWarehouseType().toString());
|
| 13146 |
manish.sha |
262 |
}
|
|
|
263 |
if(orderValuesMap!=null && orderValuesMap.size()>0){
|
|
|
264 |
acceptTogetherOrdersMap.put(taOrder.getId(), orderValuesMap);
|
|
|
265 |
}
|
|
|
266 |
}
|
|
|
267 |
}
|
| 5110 |
mandeep.dh |
268 |
}
|
| 13146 |
manish.sha |
269 |
|
|
|
270 |
if(t_order.isSetLogisticsTransactionId()){
|
|
|
271 |
billTogetherOrdersMap = new HashMap<Long, Map<String, String>>();
|
|
|
272 |
Map<String, String> orderValuesMap = new HashMap<String, String>();
|
| 18100 |
manish.sha |
273 |
if(t_order.getStatus()==OrderStatus.ACCEPTED){
|
|
|
274 |
orderValuesMap.put("ProductName", getItemDisplayName(lineItem));
|
|
|
275 |
orderValuesMap.put("Quantity", lineItem.getQuantity()+"");
|
|
|
276 |
if(ItemType.SERIALIZED==item.getType()){
|
|
|
277 |
orderValuesMap.put("IsSerialized", "true");
|
|
|
278 |
}else{
|
|
|
279 |
orderValuesMap.put("IsSerialized", "false");
|
|
|
280 |
}
|
|
|
281 |
if(t_order.isSetFreebieItemId() && t_order.getFreebieItemId()!=0){
|
|
|
282 |
orderValuesMap.put("IsFreebie", "true");
|
|
|
283 |
} else {
|
|
|
284 |
orderValuesMap.put("IsFreebie", "false");
|
|
|
285 |
}
|
|
|
286 |
billTogetherOrdersMap.put(t_order.getId(), orderValuesMap);
|
| 13146 |
manish.sha |
287 |
}
|
|
|
288 |
Map<Long, Item> orderItemMap = new HashMap<Long, Item>();
|
|
|
289 |
List<in.shop2020.model.v1.order.Order> taOrders = new TransactionClient().getClient().getGroupOrdersByLogisticsTxnId(t_order.getLogisticsTransactionId());
|
|
|
290 |
for(in.shop2020.model.v1.order.Order ord1: taOrders){
|
| 18100 |
manish.sha |
291 |
if(ord1.getStatus()==OrderStatus.ACCEPTED){
|
|
|
292 |
if(ord1.getId()== t_order.getId()){
|
|
|
293 |
orderItemMap.put(ord1.getId(), item);
|
|
|
294 |
} else {
|
|
|
295 |
if(!client.isAlive()){
|
|
|
296 |
client = new CatalogClient().getClient();
|
|
|
297 |
}
|
|
|
298 |
Item it = client.getItem(ord1.getLineitems().get(0).getItem_id());
|
|
|
299 |
orderItemMap.put(ord1.getId(), it);
|
| 13146 |
manish.sha |
300 |
}
|
|
|
301 |
}
|
|
|
302 |
}
|
|
|
303 |
|
|
|
304 |
for(in.shop2020.model.v1.order.Order taOrder: taOrders){
|
| 18100 |
manish.sha |
305 |
if(taOrder.getStatus()==OrderStatus.ACCEPTED){
|
|
|
306 |
if(taOrder.getId()==t_order.getId()){
|
|
|
307 |
continue;
|
|
|
308 |
} else {
|
|
|
309 |
orderValuesMap = new HashMap<String, String>();
|
|
|
310 |
Item orderItem = orderItemMap.get(taOrder.getId());
|
|
|
311 |
orderValuesMap.put("ProductName", getProductName(orderItem));
|
|
|
312 |
orderValuesMap.put("Quantity", taOrder.getLineitems().get(0).getQuantity()+"");
|
|
|
313 |
if(ItemType.SERIALIZED==orderItem.getType()){
|
|
|
314 |
orderValuesMap.put("IsSerialized", "true");
|
|
|
315 |
}else{
|
|
|
316 |
orderValuesMap.put("IsSerialized", "false");
|
|
|
317 |
}
|
|
|
318 |
if(taOrder.isSetFreebieItemId() && taOrder.getFreebieItemId()!=0){
|
|
|
319 |
orderValuesMap.put("IsFreebie", "true");
|
|
|
320 |
} else {
|
|
|
321 |
orderValuesMap.put("IsFreebie", "false");
|
|
|
322 |
}
|
|
|
323 |
billTogetherOrdersMap.put(taOrder.getId(), orderValuesMap);
|
|
|
324 |
}
|
| 13146 |
manish.sha |
325 |
}
|
|
|
326 |
}
|
|
|
327 |
}
|
|
|
328 |
else{
|
|
|
329 |
billTogetherOrdersMap = new HashMap<Long, Map<String, String>>();
|
|
|
330 |
Map<String, String> orderValuesMap = new HashMap<String, String>();
|
|
|
331 |
orderValuesMap.put("ProductName", getItemDisplayName(lineItem));
|
|
|
332 |
orderValuesMap.put("Quantity", lineItem.getQuantity()+"");
|
|
|
333 |
if(ItemType.SERIALIZED==item.getType()){
|
|
|
334 |
orderValuesMap.put("IsSerialized", "true");
|
|
|
335 |
}else{
|
|
|
336 |
orderValuesMap.put("IsSerialized", "false");
|
|
|
337 |
}
|
|
|
338 |
if(t_order.isSetFreebieItemId() && t_order.getFreebieItemId()!=0){
|
|
|
339 |
orderValuesMap.put("IsFreebie", "true");
|
|
|
340 |
} else {
|
|
|
341 |
orderValuesMap.put("IsFreebie", "false");
|
|
|
342 |
}
|
|
|
343 |
billTogetherOrdersMap.put(t_order.getId(), orderValuesMap);
|
|
|
344 |
}
|
| 5110 |
mandeep.dh |
345 |
}
|
|
|
346 |
catch (Exception e) {
|
|
|
347 |
logger.error("Error looking up warehouse: " + t_order.getVendorId(), e);
|
|
|
348 |
}
|
|
|
349 |
|
| 3553 |
chandransh |
350 |
String delayReason = null;
|
|
|
351 |
if(t_order.getDelayReason() != null)
|
| 7433 |
rajveer |
352 |
delayReason = t_order.getDelayReason().name();
|
| 3553 |
chandransh |
353 |
|
| 7556 |
rajveer |
354 |
String osource = OrderSource.findByValue((int)t_order.getSource()).toString();
|
| 7433 |
rajveer |
355 |
|
| 966 |
chandransh |
356 |
Order order = new Order(t_order.getId(),
|
|
|
357 |
t_order.getCustomer_id(),
|
|
|
358 |
t_order.getCustomer_name(),
|
|
|
359 |
t_order.getCustomer_mobilenumber(),
|
|
|
360 |
t_order.getCustomer_pincode(),
|
|
|
361 |
t_order.getCustomer_address1(),
|
|
|
362 |
t_order.getCustomer_address2(),
|
|
|
363 |
t_order.getCustomer_city(),
|
|
|
364 |
t_order.getCustomer_state(),
|
|
|
365 |
t_order.getCustomer_email(),
|
|
|
366 |
t_order.getCreated_timestamp(),
|
| 4004 |
chandransh |
367 |
t_order.getShipping_timestamp(),
|
|
|
368 |
t_order.getVerification_timestamp(),
|
| 966 |
chandransh |
369 |
t_order.getExpected_delivery_time(),
|
| 3994 |
chandransh |
370 |
t_order.getPromised_delivery_time(),
|
| 4004 |
chandransh |
371 |
t_order.getExpected_shipping_time(),
|
| 4666 |
rajveer |
372 |
t_order.getPromised_shipping_time(),
|
| 966 |
chandransh |
373 |
t_order.getStatus().getValue(),
|
|
|
374 |
t_order.getStatusDescription(),
|
| 5527 |
anupam.sin |
375 |
t_order.getOrderType().name(),
|
| 966 |
chandransh |
376 |
lineItem.getItem_id(),
|
|
|
377 |
lineItem.getProductGroup(),
|
|
|
378 |
lineItem.getBrand(),
|
|
|
379 |
lineItem.getModel_name(),
|
|
|
380 |
lineItem.getModel_number(),
|
|
|
381 |
lineItem.getColor(),
|
|
|
382 |
lineItem.getExtra_info(),
|
| 4172 |
rajveer |
383 |
lineItem.getDealText(),
|
| 5387 |
rajveer |
384 |
lineItem.getQuantity(),
|
| 2782 |
chandransh |
385 |
t_order.getTotal_amount(),
|
|
|
386 |
t_order.getTotal_weight(),
|
|
|
387 |
t_order.getAirwaybill_no(),
|
|
|
388 |
t_order.getBilled_by(),
|
|
|
389 |
t_order.getInvoice_number(),
|
|
|
390 |
t_order.getJacket_number(),
|
|
|
391 |
lineItem.getItem_number(),
|
| 4659 |
mandeep.dh |
392 |
lineItem.getSerial_number(),
|
| 3065 |
chandransh |
393 |
t_order.getBatchNo(),
|
|
|
394 |
t_order.getSerialNo(),
|
| 2509 |
chandransh |
395 |
t_order.isDoaFlag(),
|
| 3065 |
chandransh |
396 |
t_order.getPickupRequestNo(),
|
| 5556 |
rajveer |
397 |
t_order.isLogisticsCod(),
|
| 5110 |
mandeep.dh |
398 |
delayReason,
|
|
|
399 |
pickFromWarehouse,
|
| 6028 |
rajveer |
400 |
ItemType.SERIALIZED.equals(item.getType()),
|
|
|
401 |
item.isHasItemNo(),
|
| 5769 |
rajveer |
402 |
t_order.getFulfilmentWarehouseId(),
|
| 9263 |
amar.kumar |
403 |
t_order.getWarehouse_id(),
|
| 7190 |
amar.kumar |
404 |
t_order.getPickupStoreId(),
|
| 7422 |
rajveer |
405 |
t_order.getFreebieItemId(),
|
| 8717 |
amar.kumar |
406 |
osource,
|
| 13146 |
manish.sha |
407 |
new Long(t_order.getProductCondition().getValue()),
|
|
|
408 |
t_order.getTransactionId());
|
|
|
409 |
if(acceptTogetherOrdersMap!=null && acceptTogetherOrdersMap.size()>0){
|
|
|
410 |
order.setAcceptTogetherOrdersMap(acceptTogetherOrdersMap);
|
|
|
411 |
}
|
|
|
412 |
if(billTogetherOrdersMap!=null && billTogetherOrdersMap.size()>0){
|
|
|
413 |
order.setBillTogetherOrdersMap(billTogetherOrdersMap);
|
|
|
414 |
}
|
|
|
415 |
if(t_order.isSetLogisticsTransactionId()){
|
|
|
416 |
order.setLogisticsTransactionId(t_order.getLogisticsTransactionId());
|
|
|
417 |
}
|
| 966 |
chandransh |
418 |
return order;
|
| 671 |
chandransh |
419 |
}
|
|
|
420 |
|
| 2449 |
chandransh |
421 |
/**
|
| 2697 |
chandransh |
422 |
* Queries the transction server to get the list of all return orders that
|
|
|
423 |
* have to be processed.
|
|
|
424 |
*
|
|
|
425 |
* @return A list of all return orders to be processed.
|
|
|
426 |
*/
|
|
|
427 |
public static List<ReturnOrder> getReturnOrders(long warehouseId){
|
|
|
428 |
List<ReturnOrder> retOrders = new ArrayList<ReturnOrder>();
|
|
|
429 |
try{
|
| 3132 |
rajveer |
430 |
TransactionClient client = new TransactionClient();
|
| 2697 |
chandransh |
431 |
Client c = client.getClient();
|
|
|
432 |
List<in.shop2020.model.v1.order.ReturnOrder> tRetOrders = c.getReturnOrders(warehouseId, 0L, new Date().getTime());
|
|
|
433 |
for(in.shop2020.model.v1.order.ReturnOrder retOrder : tRetOrders){
|
|
|
434 |
retOrders.add(getReturnOrderFromThriftRO(retOrder));
|
|
|
435 |
}
|
|
|
436 |
}catch(Exception e){
|
|
|
437 |
e.printStackTrace();
|
|
|
438 |
}
|
|
|
439 |
return retOrders;
|
|
|
440 |
}
|
|
|
441 |
|
| 2700 |
chandransh |
442 |
public static ReturnOrder getReturnOrderFromThriftRO(in.shop2020.model.v1.order.ReturnOrder tRetOrder){
|
|
|
443 |
ReturnOrder retOrder = new ReturnOrder(tRetOrder.getOrderId(),
|
|
|
444 |
tRetOrder.getWarehouseId(),
|
|
|
445 |
tRetOrder.getItemId(),
|
|
|
446 |
tRetOrder.getProductGroup(),
|
|
|
447 |
tRetOrder.getBrand(),
|
|
|
448 |
tRetOrder.getModelName(),
|
|
|
449 |
tRetOrder.getModelNumber(),
|
|
|
450 |
tRetOrder.getColor(),
|
|
|
451 |
tRetOrder.getInvoiceNumber(),
|
|
|
452 |
tRetOrder.getJacketNumber(),
|
|
|
453 |
tRetOrder.getTotalPrice(),
|
|
|
454 |
tRetOrder.getTransferPrice(),
|
|
|
455 |
false,
|
|
|
456 |
tRetOrder.getCreatedAt());
|
| 2697 |
chandransh |
457 |
return retOrder;
|
|
|
458 |
}
|
|
|
459 |
|
|
|
460 |
/**
|
| 2449 |
chandransh |
461 |
* This method maps a given type to a list of statuses.
|
|
|
462 |
*
|
|
|
463 |
* @param type
|
|
|
464 |
* The type of orders to fetch.
|
|
|
465 |
* @return The list of Thrift statuses associated with a particular order
|
|
|
466 |
* type.
|
|
|
467 |
*/
|
| 4361 |
rajveer |
468 |
public static List<OrderStatus> getStatuses(OrderType type) {
|
| 2449 |
chandransh |
469 |
List<OrderStatus> statuses = new ArrayList<OrderStatus>();
|
|
|
470 |
|
|
|
471 |
switch (type) {
|
|
|
472 |
case ACCEPTED:
|
|
|
473 |
statuses.add(OrderStatus.ACCEPTED);
|
|
|
474 |
break;
|
|
|
475 |
|
| 4361 |
rajveer |
476 |
case ALL_PENDING:
|
|
|
477 |
statuses.add(OrderStatus.SUBMITTED_FOR_PROCESSING);
|
| 4421 |
mandeep.dh |
478 |
statuses.add(OrderStatus.CAPTURE_IN_PROCESS);
|
| 4361 |
rajveer |
479 |
statuses.add(OrderStatus.INVENTORY_LOW);
|
|
|
480 |
statuses.add(OrderStatus.LOW_INV_PO_RAISED);
|
|
|
481 |
statuses.add(OrderStatus.LOW_INV_REVERSAL_IN_PROCESS);
|
|
|
482 |
statuses.add(OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT);
|
| 2449 |
chandransh |
483 |
break;
|
|
|
484 |
|
|
|
485 |
case NEW:
|
|
|
486 |
statuses.add(OrderStatus.SUBMITTED_FOR_PROCESSING);
|
| 4421 |
mandeep.dh |
487 |
statuses.add(OrderStatus.CAPTURE_IN_PROCESS);
|
| 2449 |
chandransh |
488 |
break;
|
|
|
489 |
|
|
|
490 |
case BILLED:
|
|
|
491 |
statuses.add(OrderStatus.BILLED);
|
|
|
492 |
break;
|
|
|
493 |
|
| 4308 |
rajveer |
494 |
case LOW_INVENTORY:
|
| 2449 |
chandransh |
495 |
statuses.add(OrderStatus.INVENTORY_LOW);
|
|
|
496 |
break;
|
| 4248 |
rajveer |
497 |
|
| 4308 |
rajveer |
498 |
case PO_RAISED:
|
|
|
499 |
statuses.add(OrderStatus.LOW_INV_PO_RAISED);
|
|
|
500 |
break;
|
|
|
501 |
|
|
|
502 |
case REVERSAL_INITIATED:
|
|
|
503 |
statuses.add(OrderStatus.LOW_INV_REVERSAL_IN_PROCESS);
|
|
|
504 |
break;
|
|
|
505 |
|
|
|
506 |
case NOT_AVAILABLE:
|
|
|
507 |
statuses.add(OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT);
|
|
|
508 |
break;
|
|
|
509 |
|
| 4248 |
rajveer |
510 |
case CANCEL_CONFIRMED:
|
|
|
511 |
statuses.add(OrderStatus.CANCEL_REQUEST_CONFIRMED);
|
|
|
512 |
break;
|
| 2449 |
chandransh |
513 |
|
| 4459 |
rajveer |
514 |
case DOA_REQUEST_AUTHORIZED:
|
|
|
515 |
statuses.add(OrderStatus.DOA_REQUEST_AUTHORIZED);
|
| 4515 |
mandeep.dh |
516 |
statuses.add(OrderStatus.DOA_PICKUP_REQUEST_RAISED);
|
| 4459 |
rajveer |
517 |
break;
|
|
|
518 |
|
| 4666 |
rajveer |
519 |
case LOST_IN_TRANSIT:
|
|
|
520 |
statuses.add(OrderStatus.LOST_IN_TRANSIT);
|
|
|
521 |
break;
|
|
|
522 |
|
| 4459 |
rajveer |
523 |
case DOA_LOST_IN_TRANSIT:
|
|
|
524 |
statuses.add(OrderStatus.DOA_LOST_IN_TRANSIT);
|
| 4478 |
rajveer |
525 |
break;
|
|
|
526 |
|
|
|
527 |
case DOA_RECEIVED_DAMAGED:
|
| 4459 |
rajveer |
528 |
statuses.add(OrderStatus.DOA_RECEIVED_DAMAGED);
|
|
|
529 |
break;
|
| 4495 |
rajveer |
530 |
|
|
|
531 |
case RET_REQUEST_AUTHORIZED:
|
|
|
532 |
statuses.add(OrderStatus.RET_REQUEST_AUTHORIZED);
|
| 4515 |
mandeep.dh |
533 |
statuses.add(OrderStatus.RET_PICKUP_REQUEST_RAISED);
|
| 4495 |
rajveer |
534 |
break;
|
|
|
535 |
|
|
|
536 |
case RET_AWAITED:
|
|
|
537 |
statuses.add(OrderStatus.RET_RETURN_IN_TRANSIT);
|
| 4515 |
mandeep.dh |
538 |
statuses.add(OrderStatus.RET_PICKUP_CONFIRMED);
|
| 4495 |
rajveer |
539 |
break;
|
| 4459 |
rajveer |
540 |
|
| 4495 |
rajveer |
541 |
case RET_RECEIVED_PRESTINE:
|
|
|
542 |
statuses.add(OrderStatus.RET_RECEIVED_PRESTINE);
|
| 4515 |
mandeep.dh |
543 |
statuses.add(OrderStatus.RET_PRODUCT_USABLE);
|
| 4495 |
rajveer |
544 |
break;
|
|
|
545 |
|
|
|
546 |
case RET_LOST_IN_TRANSIT:
|
|
|
547 |
statuses.add(OrderStatus.RET_LOST_IN_TRANSIT);
|
|
|
548 |
break;
|
|
|
549 |
|
|
|
550 |
case RET_RECEIVED_DAMAGED:
|
|
|
551 |
statuses.add(OrderStatus.RET_RECEIVED_DAMAGED);
|
| 4515 |
mandeep.dh |
552 |
statuses.add(OrderStatus.RET_PRODUCT_UNUSABLE);
|
| 4495 |
rajveer |
553 |
break;
|
|
|
554 |
|
| 2449 |
chandransh |
555 |
case REJECTED:
|
|
|
556 |
statuses.add(OrderStatus.REJECTED);
|
|
|
557 |
break;
|
|
|
558 |
|
|
|
559 |
case SHIPPED:
|
|
|
560 |
statuses.add(OrderStatus.SHIPPED_FROM_WH);
|
|
|
561 |
statuses.add(OrderStatus.SHIPPED_TO_LOGST);
|
| 5016 |
phani.kuma |
562 |
statuses.add(OrderStatus.SHIPPED_TO_DESTINATION_CITY);
|
|
|
563 |
statuses.add(OrderStatus.REACHED_DESTINATION_CITY);
|
|
|
564 |
statuses.add(OrderStatus.FIRST_DELIVERY_ATTEMPT_MADE);
|
| 2449 |
chandransh |
565 |
break;
|
|
|
566 |
|
|
|
567 |
case DELIVERED:
|
|
|
568 |
statuses.add(OrderStatus.DELIVERY_SUCCESS);
|
| 4452 |
rajveer |
569 |
statuses.add(OrderStatus.DOA_PICKUP_REQUEST_RAISED);
|
| 2449 |
chandransh |
570 |
break;
|
| 2610 |
chandransh |
571 |
|
|
|
572 |
case DOA_AWAITED:
|
| 4452 |
rajveer |
573 |
statuses.add(OrderStatus.DOA_PICKUP_CONFIRMED);
|
| 2610 |
chandransh |
574 |
statuses.add(OrderStatus.DOA_RETURN_IN_TRANSIT);
|
| 4452 |
rajveer |
575 |
statuses.add(OrderStatus.DOA_RECEIVED_PRESTINE);
|
| 2610 |
chandransh |
576 |
break;
|
| 2449 |
chandransh |
577 |
|
| 4495 |
rajveer |
578 |
case RTO_AWAITED:
|
| 4484 |
rajveer |
579 |
statuses.add(OrderStatus.RTO_IN_TRANSIT);
|
| 2509 |
chandransh |
580 |
break;
|
|
|
581 |
|
| 4515 |
mandeep.dh |
582 |
case RTO_RECEIVED_DAMAGED:
|
|
|
583 |
statuses.add(OrderStatus.RTO_RECEIVED_DAMAGED);
|
|
|
584 |
break;
|
|
|
585 |
|
|
|
586 |
case DOA_RECEIVED_PRESTINE:
|
| 2610 |
chandransh |
587 |
statuses.add(OrderStatus.DOA_CERT_VALID);
|
| 4515 |
mandeep.dh |
588 |
statuses.add(OrderStatus.DOA_CERT_INVALID);
|
| 2610 |
chandransh |
589 |
break;
|
|
|
590 |
|
| 4495 |
rajveer |
591 |
case RTO_RETURNED:
|
| 4484 |
rajveer |
592 |
statuses.add(OrderStatus.RTO_RECEIVED_PRESTINE);
|
| 2509 |
chandransh |
593 |
break;
|
|
|
594 |
|
| 2628 |
chandransh |
595 |
case RESHIPPED:
|
| 4484 |
rajveer |
596 |
statuses.add(OrderStatus.RTO_RESHIPPED);
|
| 2628 |
chandransh |
597 |
statuses.add(OrderStatus.DOA_INVALID_RESHIPPED);
|
| 4452 |
rajveer |
598 |
statuses.add(OrderStatus.DOA_VALID_RESHIPPED);
|
| 2628 |
chandransh |
599 |
break;
|
|
|
600 |
|
|
|
601 |
case REFUNDED:
|
| 4682 |
rajveer |
602 |
statuses.add(OrderStatus.COD_VERIFICATION_FAILED);
|
| 4484 |
rajveer |
603 |
statuses.add(OrderStatus.RTO_REFUNDED);
|
| 2628 |
chandransh |
604 |
statuses.add(OrderStatus.DOA_INVALID_REFUNDED);
|
|
|
605 |
statuses.add(OrderStatus.DOA_VALID_REFUNDED);
|
| 4682 |
rajveer |
606 |
statuses.add(OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY);
|
| 2628 |
chandransh |
607 |
break;
|
| 2509 |
chandransh |
608 |
|
| 3065 |
chandransh |
609 |
case VERIFICATION_PENDING:
|
| 4664 |
rajveer |
610 |
statuses.add(OrderStatus.COD_VERIFICATION_PENDING);
|
| 3065 |
chandransh |
611 |
break;
|
| 2449 |
chandransh |
612 |
default:
|
|
|
613 |
break;
|
|
|
614 |
}
|
|
|
615 |
return statuses;
|
|
|
616 |
}
|
| 13146 |
manish.sha |
617 |
|
|
|
618 |
public static List<Long> getEligibleOrdersToBeAccepted(Order order){
|
|
|
619 |
List<Long> orders = new ArrayList<Long>();
|
|
|
620 |
try {
|
|
|
621 |
|
|
|
622 |
TransactionClient client = new TransactionClient();
|
|
|
623 |
Client c = client.getClient();
|
|
|
624 |
|
|
|
625 |
in.shop2020.model.v1.order.Order thriftOrder = c.getOrder(order.getOrderId());
|
|
|
626 |
long provider_id = thriftOrder.getLogistics_provider_id();
|
|
|
627 |
boolean cod = thriftOrder.isLogisticsCod();
|
|
|
628 |
|
|
|
629 |
List<in.shop2020.model.v1.order.Order> torders = c.getOrdersForTransaction(thriftOrder.getTransactionId(), thriftOrder.getCustomer_id());
|
|
|
630 |
for(in.shop2020.model.v1.order.Order torder: torders){
|
|
|
631 |
if(torder.getLogistics_provider_id() == provider_id && torder.isLogisticsCod() == cod){
|
|
|
632 |
orders.add(torder.getId());
|
|
|
633 |
}
|
|
|
634 |
}
|
|
|
635 |
|
|
|
636 |
}catch(Exception e){
|
|
|
637 |
e.printStackTrace();
|
|
|
638 |
}
|
|
|
639 |
return orders;
|
|
|
640 |
}
|
|
|
641 |
|
|
|
642 |
public static String getItemDisplayName(LineItem lineitem){
|
|
|
643 |
StringBuffer itemName = new StringBuffer();
|
|
|
644 |
if (lineitem.getBrand() != null)
|
|
|
645 |
itemName.append(lineitem.getBrand() + " ");
|
|
|
646 |
if (lineitem.getModel_name() != null)
|
|
|
647 |
itemName.append(lineitem.getModel_name() + " ");
|
|
|
648 |
if (lineitem.getModel_number() != null)
|
|
|
649 |
itemName.append(lineitem.getModel_number() + " ");
|
|
|
650 |
if (lineitem.getColor() != null
|
|
|
651 |
&& !lineitem.getColor().trim().equals("NA"))
|
|
|
652 |
itemName.append("(" + lineitem.getColor() + ")");
|
|
|
653 |
|
|
|
654 |
return itemName.toString();
|
|
|
655 |
}
|
|
|
656 |
|
|
|
657 |
public static String getProductName(in.shop2020.model.v1.catalog.Item item){
|
|
|
658 |
StringBuffer itemName = new StringBuffer();
|
|
|
659 |
if (item.getBrand() != null)
|
|
|
660 |
itemName.append(item.getBrand() + " ");
|
|
|
661 |
if (item.getModelName() != null)
|
|
|
662 |
itemName.append(item.getModelName() + " ");
|
|
|
663 |
if (item.getModelNumber() != null)
|
|
|
664 |
itemName.append(item.getModelNumber() + " ");
|
|
|
665 |
if (item.getColor() != null
|
|
|
666 |
&& !item.getColor().trim().equals("NA"))
|
|
|
667 |
itemName.append("(" + item.getColor() + ")");
|
|
|
668 |
|
|
|
669 |
return itemName.toString();
|
|
|
670 |
}
|
| 493 |
rajveer |
671 |
}
|