| Line 5... |
Line 5... |
| 5 |
|
5 |
|
| 6 |
import in.shop2020.logistics.PickUpType;
|
6 |
import in.shop2020.logistics.PickUpType;
|
| 7 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
7 |
import in.shop2020.model.v1.catalog.CatalogServiceException;
|
| 8 |
import in.shop2020.model.v1.catalog.Item;
|
8 |
import in.shop2020.model.v1.catalog.Item;
|
| 9 |
import in.shop2020.model.v1.order.LineItem;
|
9 |
import in.shop2020.model.v1.order.LineItem;
|
| 10 |
import in.shop2020.model.v1.order.Order;
|
- |
|
| 11 |
import in.shop2020.model.v1.order.OrderSource;
|
10 |
import in.shop2020.model.v1.order.OrderSource;
|
| 12 |
import in.shop2020.model.v1.order.OrderStatus;
|
- |
|
| 13 |
import in.shop2020.model.v1.order.OrderType;
|
11 |
import in.shop2020.model.v1.order.OrderType;
|
| 14 |
import in.shop2020.model.v1.order.ProductCondition;
|
12 |
import in.shop2020.model.v1.order.ProductCondition;
|
| 15 |
import in.shop2020.model.v1.order.Transaction;
|
13 |
import in.shop2020.model.v1.order.Transaction;
|
| 16 |
import in.shop2020.model.v1.order.TransactionService.Client;
|
14 |
import in.shop2020.model.v1.order.TransactionService.Client;
|
| 17 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
15 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 18 |
import in.shop2020.model.v1.order.TransactionStatus;
|
16 |
import in.shop2020.model.v1.order.TransactionStatus;
|
| 19 |
import in.shop2020.model.v1.user.Address;
|
- |
|
| 20 |
import in.shop2020.model.v1.user.ItemPriceQuantity;
|
17 |
import in.shop2020.model.v1.user.ItemPriceQuantity;
|
| 21 |
import in.shop2020.model.v1.user.User;
|
18 |
import in.shop2020.model.v1.user.User;
|
| 22 |
import in.shop2020.payments.Attribute;
|
19 |
import in.shop2020.payments.Attribute;
|
| 23 |
import in.shop2020.payments.Payment;
|
20 |
import in.shop2020.payments.Payment;
|
| 24 |
import in.shop2020.payments.PaymentException;
|
21 |
import in.shop2020.payments.PaymentException;
|
| Line 46... |
Line 43... |
| 46 |
* @author mandeep
|
43 |
* @author mandeep
|
| 47 |
*
|
44 |
*
|
| 48 |
*/
|
45 |
*/
|
| 49 |
@SuppressWarnings("serial")
|
46 |
@SuppressWarnings("serial")
|
| 50 |
public class BulkOrderController extends ValidationAwareSupport {
|
47 |
public class BulkOrderController extends ValidationAwareSupport {
|
| 51 |
private static final int RTGS_GATEWAY_ID = 6;
|
- |
|
| 52 |
private static final int WALLET_GATEWAY_ID = 8;
|
48 |
private static final int WALLET_GATEWAY_ID = 8;
|
| 53 |
|
49 |
|
| 54 |
private static Log log = LogFactory.getLog(BulkOrderController.class);
|
50 |
private static Log log = LogFactory.getLog(BulkOrderController.class);
|
| 55 |
private SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
51 |
private SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
| 56 |
|
52 |
|
| 57 |
private static final String IFSC_CODE = "ifscCode";
|
- |
|
| 58 |
private static final String RTGS_BRANCH = "rtgsBranch";
|
- |
|
| 59 |
private static final String RTGS_BANK = "rtgsBank";
|
- |
|
| 60 |
private static final String RTGS_ID = "rtgsId";
|
- |
|
| 61 |
private static final String PAY_METHOD = "payMethod";
|
53 |
private static final String PAY_METHOD = "payMethod";
|
| 62 |
|
54 |
|
| 63 |
private String id;
|
55 |
private String id;
|
| 64 |
private String transactionId;
|
56 |
private String transactionId;
|
| 65 |
private String customerEmailId;
|
57 |
private String customerEmailId;
|
| Line 87... |
Line 79... |
| 87 |
private Client transactionClient;
|
79 |
private Client transactionClient;
|
| 88 |
private in.shop2020.model.v1.user.UserContextService.Client userClient;
|
80 |
private in.shop2020.model.v1.user.UserContextService.Client userClient;
|
| 89 |
private in.shop2020.payments.PaymentService.Client paymentClient;
|
81 |
private in.shop2020.payments.PaymentService.Client paymentClient;
|
| 90 |
private in.shop2020.model.v1.catalog.CatalogService.Client catalogClient;
|
82 |
private in.shop2020.model.v1.catalog.CatalogService.Client catalogClient;
|
| 91 |
|
83 |
|
| 92 |
public BulkOrderController() {
|
- |
|
| 93 |
super();
|
- |
|
| 94 |
try {
|
- |
|
| 95 |
this.userClient = new UserClient().getClient();
|
- |
|
| 96 |
this.paymentClient = new PaymentClient().getClient();
|
- |
|
| 97 |
this.transactionClient = new TransactionClient().getClient();
|
- |
|
| 98 |
this.catalogClient = new CatalogClient().getClient();
|
- |
|
| 99 |
} catch (Exception e){
|
- |
|
| 100 |
log.error("Error occured while initialising client");
|
- |
|
| 101 |
e.printStackTrace();
|
- |
|
| 102 |
}
|
- |
|
| 103 |
}
|
- |
|
| 104 |
|
84 |
|
| 105 |
public String index() {
|
85 |
public String index() {
|
| 106 |
return "index";
|
86 |
return "index";
|
| 107 |
}
|
87 |
}
|
| 108 |
|
88 |
|
| 109 |
public String editNew() throws Throwable {
|
89 |
public String editNew() throws Throwable {
|
| - |
|
90 |
this.userClient = new UserClient().getClient();
|
| - |
|
91 |
this.transactionClient = new TransactionClient().getClient();
|
| 110 |
User user = userClient.getUserByEmail(customerEmailId);
|
92 |
User user = userClient.getUserByEmail(customerEmailId);
|
| 111 |
this.userWalletAmount = this.transactionClient.getUserWallet(user.getUserId()).getAmount();
|
93 |
this.userWalletAmount = this.transactionClient.getUserWallet(user.getUserId()).getAmount();
|
| 112 |
return "editNew";
|
94 |
return "editNew";
|
| 113 |
}
|
95 |
}
|
| 114 |
|
96 |
|
| 115 |
public String show() {
|
97 |
public String show() throws Throwable {
|
| - |
|
98 |
this.paymentClient = new PaymentClient().getClient();
|
| - |
|
99 |
this.transactionClient = new TransactionClient().getClient();
|
| 116 |
try {
|
100 |
try {
|
| 117 |
transactionId = id;
|
101 |
transactionId = id;
|
| 118 |
|
102 |
|
| 119 |
transaction = this.transactionClient.getTransaction(Long.valueOf(transactionId));
|
103 |
transaction = this.transactionClient.getTransaction(Long.valueOf(transactionId));
|
| 120 |
payment = this.paymentClient.getPaymentForTxnId(Long.valueOf(transactionId)).get(0);
|
104 |
payment = this.paymentClient.getPaymentForTxnId(Long.valueOf(transactionId)).get(0);
|
| Line 130... |
Line 114... |
| 130 |
}
|
114 |
}
|
| 131 |
|
115 |
|
| 132 |
return "show";
|
116 |
return "show";
|
| 133 |
}
|
117 |
}
|
| 134 |
|
118 |
|
| 135 |
public String create() {
|
119 |
public String create() throws Throwable {
|
| - |
|
120 |
this.userClient = new UserClient().getClient();
|
| - |
|
121 |
this.paymentClient = new PaymentClient().getClient();
|
| - |
|
122 |
this.transactionClient = new TransactionClient().getClient();
|
| - |
|
123 |
this.catalogClient = new CatalogClient().getClient();
|
| 136 |
log.info("Creating orders for " + lineItems);
|
124 |
log.info("Creating orders for " + lineItems);
|
| 137 |
boolean hasError = true;
|
125 |
boolean hasError = true;
|
| 138 |
|
126 |
|
| 139 |
try {
|
127 |
try {
|
| 140 |
User user = this.userClient.getUserByEmail(customerEmailId);
|
128 |
User user = this.userClient.getUserByEmail(customerEmailId);
|
| Line 196... |
Line 184... |
| 196 |
|
184 |
|
| 197 |
id = transactionId;
|
185 |
id = transactionId;
|
| 198 |
return show();
|
186 |
return show();
|
| 199 |
}
|
187 |
}
|
| 200 |
|
188 |
|
| 201 |
public String getModelName() {
|
189 |
public String getModelName() throws Throwable {
|
| - |
|
190 |
this.catalogClient = new CatalogClient().getClient();
|
| 202 |
output = "Invalid Item Id: " + itemId;
|
191 |
output = "Invalid Item Id: " + itemId;
|
| 203 |
|
192 |
|
| 204 |
try {
|
193 |
try {
|
| 205 |
|
194 |
|
| 206 |
Item item = this.catalogClient.getItem(Long.parseLong(itemId));
|
195 |
Item item = this.catalogClient.getItem(Long.parseLong(itemId));
|
| Line 221... |
Line 210... |
| 221 |
As it is always going to be wallet
|
210 |
As it is always going to be wallet
|
| 222 |
**/
|
211 |
**/
|
| 223 |
private void createPayment(User user) throws NumberFormatException, PaymentException, TException {
|
212 |
private void createPayment(User user) throws NumberFormatException, PaymentException, TException {
|
| 224 |
List<Attribute> paymentAttributes = new ArrayList<Attribute>();
|
213 |
List<Attribute> paymentAttributes = new ArrayList<Attribute>();
|
| 225 |
paymentAttributes.add(new Attribute(PAY_METHOD, "7890"));
|
214 |
paymentAttributes.add(new Attribute(PAY_METHOD, "7890"));
|
| 226 |
/*
|
- |
|
| 227 |
* paymentAttributes.add(new Attribute(RTGS_ID, rtgsId));
|
- |
|
| 228 |
* paymentAttributes.add(new Attribute(RTGS_BANK, rtgsBank));
|
- |
|
| 229 |
* paymentAttributes.add(new Attribute(RTGS_BRANCH, rtgsBranch));
|
- |
|
| 230 |
* paymentAttributes.add(new Attribute(IFSC_CODE, ifscCode));
|
- |
|
| 231 |
*/
|
- |
|
| 232 |
|
- |
|
| 233 |
long paymentId = this.paymentClient.createPayment(user.getUserId(), Double.valueOf(amount), WALLET_GATEWAY_ID, Long.valueOf(transactionId),
|
215 |
long paymentId = this.paymentClient.createPayment(user.getUserId(), Double.valueOf(amount), WALLET_GATEWAY_ID, Long.valueOf(transactionId),
|
| 234 |
false);
|
216 |
false);
|
| 235 |
this.paymentClient.updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null, PaymentStatus.SUCCESS, null,
|
217 |
this.paymentClient.updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null, PaymentStatus.SUCCESS, null,
|
| 236 |
paymentAttributes);
|
218 |
paymentAttributes);
|
| 237 |
}
|
219 |
}
|
| 238 |
|
220 |
|
| 239 |
/*
|
- |
|
| 240 |
* private long createTransaction(User user) throws
|
- |
|
| 241 |
* TransactionServiceException, TException, CatalogServiceException {
|
- |
|
| 242 |
* Transaction txn = new Transaction();
|
- |
|
| 243 |
* txn.setShoppingCartid(user.getActiveCartId());
|
- |
|
| 244 |
* txn.setCustomer_id(user.getUserId()); txn.setCreatedOn(new
|
- |
|
| 245 |
* Date().getTime()); txn.setTransactionStatus(TransactionStatus.INIT);
|
- |
|
| 246 |
* txn.setStatusDescription("New Order"); txn.setOrders(createOrders(user));
|
- |
|
| 247 |
* Client transaction_client = new TransactionClient().getClient(); return
|
- |
|
| 248 |
* transaction_client.createTransaction(txn); }
|
- |
|
| 249 |
*/
|
- |
|
| 250 |
|
- |
|
| 251 |
private List<Order> createOrders(User user) throws CatalogServiceException, TException {
|
- |
|
| 252 |
List<Order> orders = new ArrayList<Order>();
|
- |
|
| 253 |
|
- |
|
| 254 |
// Extracting default address
|
- |
|
| 255 |
Address defaultAddress = null;
|
- |
|
| 256 |
for (Address address : user.getAddresses()) {
|
- |
|
| 257 |
if (address.getId() == user.getDefaultAddressId()) {
|
- |
|
| 258 |
defaultAddress = address;
|
- |
|
| 259 |
break;
|
- |
|
| 260 |
}
|
- |
|
| 261 |
}
|
- |
|
| 262 |
|
- |
|
| 263 |
for (LineItem lineItem : lineItems) {
|
- |
|
| 264 |
enrichLineItem(lineItem);
|
- |
|
| 265 |
|
- |
|
| 266 |
Order t_order = new Order();
|
- |
|
| 267 |
t_order.setCustomer_id(user.getUserId());
|
- |
|
| 268 |
t_order.setCustomer_email(user.getEmail());
|
- |
|
| 269 |
t_order.setCustomer_name(defaultAddress.getName());
|
- |
|
| 270 |
t_order.setCustomer_pincode(defaultAddress.getPin());
|
- |
|
| 271 |
t_order.setCustomer_address1(defaultAddress.getLine1());
|
- |
|
| 272 |
t_order.setCustomer_address2(defaultAddress.getLine2());
|
- |
|
| 273 |
t_order.setCustomer_city(defaultAddress.getCity());
|
- |
|
| 274 |
t_order.setCustomer_state(defaultAddress.getState());
|
- |
|
| 275 |
t_order.setCustomer_mobilenumber(defaultAddress.getPhone());
|
- |
|
| 276 |
t_order.setTotal_amount(lineItem.getTotal_price());
|
- |
|
| 277 |
t_order.setTotal_weight(lineItem.getTotal_weight());
|
- |
|
| 278 |
t_order.setLineitems(Collections.singletonList(lineItem));
|
- |
|
| 279 |
t_order.setStatus(OrderStatus.PAYMENT_PENDING);
|
- |
|
| 280 |
t_order.setStatusDescription("Payment Pending");
|
- |
|
| 281 |
t_order.setCreated_timestamp(new Date().getTime());
|
- |
|
| 282 |
t_order.setSource(1);// Source : Website
|
- |
|
| 283 |
t_order.setProductCondition(ProductCondition.findByValue(productCondition));
|
- |
|
| 284 |
// t_order.setProductCondition(ProductCondition.findByValue(productCondition.intValue()));
|
- |
|
| 285 |
|
- |
|
| 286 |
orders.add(t_order);
|
- |
|
| 287 |
}
|
- |
|
| 288 |
|
- |
|
| 289 |
return orders;
|
- |
|
| 290 |
}
|
- |
|
| 291 |
|
- |
|
| 292 |
private LineItem enrichLineItem(LineItem lineItem) throws CatalogServiceException, TException {
|
- |
|
| 293 |
|
- |
|
| 294 |
Item item = this.catalogClient.getItem(lineItem.getItem_id());
|
- |
|
| 295 |
|
- |
|
| 296 |
lineItem.setProductGroup(item.getProductGroup());
|
- |
|
| 297 |
lineItem.setBrand(item.getBrand());
|
- |
|
| 298 |
lineItem.setModel_number(item.getModelNumber());
|
- |
|
| 299 |
lineItem.setModel_name(item.getModelName());
|
- |
|
| 300 |
lineItem.setExtra_info(item.getFeatureDescription());
|
- |
|
| 301 |
lineItem.setItem_id(item.getId());
|
- |
|
| 302 |
lineItem.setUnit_weight(item.getWeight());
|
- |
|
| 303 |
lineItem.setTotal_weight(item.getWeight() * lineItem.getQuantity());
|
- |
|
| 304 |
lineItem.setDealText(item.getBestDealText());
|
- |
|
| 305 |
lineItem.setTotal_price(lineItem.getUnit_price() * lineItem.getQuantity());
|
- |
|
| 306 |
|
- |
|
| 307 |
if (item.getColor() == null || "NA".equals(item.getColor())) {
|
- |
|
| 308 |
lineItem.setColor("");
|
- |
|
| 309 |
} else {
|
- |
|
| 310 |
lineItem.setColor(item.getColor());
|
- |
|
| 311 |
}
|
- |
|
| 312 |
|
- |
|
| 313 |
return lineItem;
|
- |
|
| 314 |
}
|
- |
|
| 315 |
|
- |
|
| 316 |
private boolean validate() {
|
- |
|
| 317 |
return false;
|
- |
|
| 318 |
}
|
- |
|
| 319 |
|
- |
|
| 320 |
public String convertDate(long date) {
|
221 |
public String convertDate(long date) {
|
| 321 |
return SDF.format(new Date(date));
|
222 |
return SDF.format(new Date(date));
|
| 322 |
}
|
223 |
}
|
| 323 |
|
224 |
|
| 324 |
public String extractProductName(LineItem lineItem) {
|
225 |
public String extractProductName(LineItem lineItem) {
|
| Line 494... |
Line 395... |
| 494 |
// blc.setOutput();
|
395 |
// blc.setOutput();
|
| 495 |
blc.setPickUp("COURIER");
|
396 |
blc.setPickUp("COURIER");
|
| 496 |
blc.setOrderType("B2Cbulk");
|
397 |
blc.setOrderType("B2Cbulk");
|
| 497 |
// blc.setTinNumber();
|
398 |
// blc.setTinNumber();
|
| 498 |
blc.setProductCondition(ProductCondition.GOOD.getValue());
|
399 |
blc.setProductCondition(ProductCondition.GOOD.getValue());
|
| 499 |
|
- |
|
| 500 |
blc.index();
|
400 |
blc.index();
|
| 501 |
/*
|
- |
|
| 502 |
* = "ifscCode"; private static final String RTGS_BRANCH = "rtgsBranch";
|
- |
|
| 503 |
* private static final String RTGS_BANK = "rtgsBank"; private static
|
- |
|
| 504 |
* final String RTGS_ID = "rtgsId"; private String customerEmailId;
|
- |
|
| 505 |
* private String rtgsId; private String rtgsBank; private String
|
- |
|
| 506 |
* rtgsBranch; private String ifscCode; private String amount; private
|
- |
|
| 507 |
* String itemId; private String output; private String pickUp; private
|
- |
|
| 508 |
* String orderType; private String tinNumber; private int
|
- |
|
| 509 |
* productCondition; private int taxType;
|
- |
|
| 510 |
*/
|
- |
|
| 511 |
// blc.set
|
- |
|
| 512 |
}
|
401 |
}
|
| 513 |
|
402 |
|
| 514 |
public double getWalletAmount() {
|
403 |
public double getWalletAmount() {
|
| 515 |
return this.userWalletAmount;
|
404 |
return this.userWalletAmount;
|
| 516 |
}
|
405 |
}
|