| Line 1... |
Line 1... |
| 1 |
package in.shop2020.support.services;
|
1 |
package in.shop2020.support.services;
|
| 2 |
|
2 |
|
| - |
|
3 |
import in.shop2020.logistics.DeliveryType;
|
| 3 |
import in.shop2020.logistics.LogisticsServiceException;
|
4 |
import in.shop2020.logistics.LogisticsServiceException;
|
| 4 |
import in.shop2020.logistics.Provider;
|
5 |
import in.shop2020.logistics.Provider;
|
| 5 |
import in.shop2020.model.v1.catalog.InventoryServiceException;
|
6 |
import in.shop2020.model.v1.catalog.InventoryServiceException;
|
| 6 |
import in.shop2020.model.v1.catalog.Warehouse;
|
7 |
import in.shop2020.model.v1.catalog.Warehouse;
|
| 7 |
import in.shop2020.model.v1.order.LineItem;
|
8 |
import in.shop2020.model.v1.order.LineItem;
|
| Line 25... |
Line 26... |
| 25 |
import org.apache.poi.ss.usermodel.CreationHelper;
|
26 |
import org.apache.poi.ss.usermodel.CreationHelper;
|
| 26 |
import org.apache.poi.ss.usermodel.Row;
|
27 |
import org.apache.poi.ss.usermodel.Row;
|
| 27 |
import org.apache.poi.ss.usermodel.Sheet;
|
28 |
import org.apache.poi.ss.usermodel.Sheet;
|
| 28 |
import org.apache.poi.ss.usermodel.Workbook;
|
29 |
import org.apache.poi.ss.usermodel.Workbook;
|
| 29 |
import org.apache.thrift.TException;
|
30 |
import org.apache.thrift.TException;
|
| - |
|
31 |
import org.slf4j.Logger;
|
| - |
|
32 |
import org.slf4j.LoggerFactory;
|
| 30 |
|
33 |
|
| 31 |
public class CourierDetailsGenerator {
|
34 |
public class CourierDetailsGenerator {
|
| - |
|
35 |
private static Logger logger = LoggerFactory.getLogger(CourierDetailsGenerator.class);
|
| - |
|
36 |
|
| 32 |
private TransactionServiceClient tsc = null;
|
37 |
private TransactionServiceClient tsc = null;
|
| 33 |
private CatalogServiceClient csc = null;
|
38 |
private CatalogServiceClient csc = null;
|
| 34 |
private LogisticsServiceClient lsc = null;
|
39 |
private LogisticsServiceClient lsc = null;
|
| 35 |
|
40 |
|
| 36 |
public CourierDetailsGenerator(){
|
41 |
public CourierDetailsGenerator(){
|
| 37 |
try {
|
42 |
try {
|
| 38 |
tsc = new TransactionServiceClient();
|
43 |
tsc = new TransactionServiceClient();
|
| 39 |
csc = new CatalogServiceClient();
|
44 |
csc = new CatalogServiceClient();
|
| 40 |
lsc = new LogisticsServiceClient();
|
45 |
lsc = new LogisticsServiceClient();
|
| 41 |
} catch (Exception e) {
|
46 |
} catch (Exception e) {
|
| 42 |
e.printStackTrace();
|
47 |
logger.error("Error while initializing one of the thrift clients", e);
|
| 43 |
}
|
48 |
}
|
| 44 |
}
|
49 |
}
|
| 45 |
|
50 |
|
| 46 |
public ByteArrayOutputStream generateCourierDetails(long warehouseId, long providerId){
|
51 |
public ByteArrayOutputStream generateCourierDetails(long warehouseId, long providerId){
|
| 47 |
ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
|
52 |
ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
|
| Line 55... |
Line 60... |
| 55 |
|
60 |
|
| 56 |
try {
|
61 |
try {
|
| 57 |
orders = txnClient.getAllOrders(OrderStatus.BILLED, 0L, new Date().getTime(), warehouseId);
|
62 |
orders = txnClient.getAllOrders(OrderStatus.BILLED, 0L, new Date().getTime(), warehouseId);
|
| 58 |
warehouse = inventoryClient.getWarehouse(warehouseId);
|
63 |
warehouse = inventoryClient.getWarehouse(warehouseId);
|
| 59 |
provider = logisticsClient.getProvider(providerId);
|
64 |
provider = logisticsClient.getProvider(providerId);
|
| 60 |
} catch (TException e1) {
|
65 |
} catch (TException e) {
|
| 61 |
e1.printStackTrace();
|
66 |
logger.error("Error getting information from one of the Thrift Services: ", e);
|
| 62 |
return baosXLS;
|
67 |
return baosXLS;
|
| 63 |
} catch (InventoryServiceException e) {
|
68 |
} catch (InventoryServiceException e) {
|
| 64 |
e.printStackTrace();
|
69 |
logger.error("Error getting warehouse info from the catalog service: ", e);
|
| 65 |
return baosXLS;
|
70 |
return baosXLS;
|
| 66 |
} catch (LogisticsServiceException e) {
|
71 |
} catch (LogisticsServiceException e) {
|
| 67 |
e.printStackTrace();
|
72 |
logger.error("Error getting provider info from the logistics service: ", e);
|
| 68 |
return baosXLS;
|
73 |
return baosXLS;
|
| 69 |
} catch (TransactionServiceException e) {
|
74 |
} catch (TransactionServiceException e) {
|
| 70 |
e.printStackTrace();
|
75 |
logger.error("Error getting orders from the transaction service: ", e);
|
| 71 |
return baosXLS;
|
76 |
return baosXLS;
|
| 72 |
}
|
77 |
}
|
| 73 |
|
78 |
|
| 74 |
Workbook wb = new HSSFWorkbook();
|
79 |
Workbook wb = new HSSFWorkbook();
|
| 75 |
CreationHelper createHelper = wb.getCreationHelper();
|
80 |
CreationHelper createHelper = wb.getCreationHelper();
|
| Line 102... |
Line 107... |
| 102 |
headerRow.createCell(16).setCellValue("Packet Weight(in Kg)");
|
107 |
headerRow.createCell(16).setCellValue("Packet Weight(in Kg)");
|
| 103 |
headerRow.createCell(17).setCellValue("Product Name");
|
108 |
headerRow.createCell(17).setCellValue("Product Name");
|
| 104 |
headerRow.createCell(18).setCellValue("Pickup Location");
|
109 |
headerRow.createCell(18).setCellValue("Pickup Location");
|
| 105 |
headerRow.createCell(19).setCellValue("Customer A/C Code");
|
110 |
headerRow.createCell(19).setCellValue("Customer A/C Code");
|
| 106 |
|
111 |
|
| - |
|
112 |
String accountNo = provider.getDetails().get(DeliveryType.PREPAID).getAccountNo();
|
| 107 |
Date awbDate = new Date();
|
113 |
Date awbDate = new Date();
|
| 108 |
int serialNo = 0;
|
114 |
int serialNo = 0;
|
| 109 |
for(int i = 0; i<orders.size(); i++){
|
115 |
for(int i = 0; i<orders.size(); i++){
|
| 110 |
Order order = orders.get(i);
|
116 |
Order order = orders.get(i);
|
| 111 |
if(order.getLogistics_provider_id()!=providerId)
|
117 |
if(order.getLogistics_provider_id()!=providerId)
|
| Line 135... |
Line 141... |
| 135 |
Cell weightCell = contentRow.createCell(16);
|
141 |
Cell weightCell = contentRow.createCell(16);
|
| 136 |
weightCell.setCellValue(lineItem.getTotal_weight());
|
142 |
weightCell.setCellValue(lineItem.getTotal_weight());
|
| 137 |
weightCell.setCellStyle(weightStyle);
|
143 |
weightCell.setCellStyle(weightStyle);
|
| 138 |
contentRow.createCell(17).setCellValue(lineItem.getBrand() + " " + lineItem.getModel_number() + " " + lineItem.getModel_name() + " " + lineItem.getColor());
|
144 |
contentRow.createCell(17).setCellValue(lineItem.getBrand() + " " + lineItem.getModel_number() + " " + lineItem.getModel_name() + " " + lineItem.getColor());
|
| 139 |
contentRow.createCell(18).setCellValue(warehouse.getLocation());
|
145 |
contentRow.createCell(18).setCellValue(warehouse.getLocation());
|
| 140 |
contentRow.createCell(19).setCellValue(provider.getAccountNo());
|
146 |
contentRow.createCell(19).setCellValue(accountNo);
|
| 141 |
}
|
147 |
}
|
| 142 |
|
148 |
|
| 143 |
// Write the workbook to the output stream
|
149 |
// Write the workbook to the output stream
|
| 144 |
try {
|
150 |
try {
|
| 145 |
wb.write(baosXLS);
|
151 |
wb.write(baosXLS);
|
| 146 |
baosXLS.close();
|
152 |
baosXLS.close();
|
| 147 |
} catch (IOException e) {
|
153 |
} catch (IOException e) {
|
| 148 |
e.printStackTrace();
|
154 |
logger.error("Exception while creating the Courier Details report", e);
|
| 149 |
}
|
155 |
}
|
| 150 |
|
156 |
|
| 151 |
return baosXLS;
|
157 |
return baosXLS;
|
| 152 |
}
|
158 |
}
|
| 153 |
|
159 |
|