| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.common.util;
|
1 |
package com.spice.profitmandi.common.util;
|
| 2 |
|
2 |
|
| 3 |
import java.io.File;
|
3 |
import java.io.File;
|
| 4 |
import java.io.IOException;
|
4 |
import java.io.IOException;
|
| 5 |
import java.io.InputStream;
|
- |
|
| 6 |
import java.io.Serializable;
|
5 |
import java.io.Serializable;
|
| 7 |
import java.net.URISyntaxException;
|
- |
|
| 8 |
import java.net.URL;
|
- |
|
| 9 |
import java.util.ArrayList;
|
6 |
import java.util.ArrayList;
|
| 10 |
import java.util.Arrays;
|
- |
|
| 11 |
import java.util.Collections;
|
7 |
import java.util.Collections;
|
| 12 |
import java.util.HashMap;
|
8 |
import java.util.HashMap;
|
| 13 |
import java.util.HashSet;
|
9 |
import java.util.HashSet;
|
| 14 |
import java.util.List;
|
10 |
import java.util.List;
|
| 15 |
import java.util.Map;
|
11 |
import java.util.Map;
|
| Line 21... |
Line 17... |
| 21 |
import javax.mail.internet.MimeBodyPart;
|
17 |
import javax.mail.internet.MimeBodyPart;
|
| 22 |
import javax.mail.internet.MimeMessage;
|
18 |
import javax.mail.internet.MimeMessage;
|
| 23 |
import javax.mail.internet.MimeMultipart;
|
19 |
import javax.mail.internet.MimeMultipart;
|
| 24 |
|
20 |
|
| 25 |
import org.apache.commons.io.FileUtils;
|
21 |
import org.apache.commons.io.FileUtils;
|
| 26 |
import org.apache.commons.io.IOUtils;
|
- |
|
| 27 |
import org.apache.commons.lang3.StringEscapeUtils;
|
22 |
import org.apache.commons.lang3.StringEscapeUtils;
|
| 28 |
import org.apache.commons.lang3.StringUtils;
|
- |
|
| 29 |
import org.apache.http.client.utils.URIBuilder;
|
- |
|
| 30 |
import org.apache.logging.log4j.LogManager;
|
23 |
import org.apache.logging.log4j.LogManager;
|
| 31 |
import org.apache.logging.log4j.Logger;
|
24 |
import org.apache.logging.log4j.Logger;
|
| 32 |
import org.apache.thrift.TException;
|
25 |
import org.apache.thrift.TException;
|
| 33 |
import org.apache.thrift.transport.TTransportException;
|
26 |
import org.apache.thrift.transport.TTransportException;
|
| 34 |
import org.springframework.core.io.InputStreamSource;
|
27 |
import org.springframework.core.io.InputStreamSource;
|
| 35 |
import org.springframework.mail.javamail.JavaMailSender;
|
28 |
import org.springframework.mail.javamail.JavaMailSender;
|
| 36 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
29 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
| 37 |
|
30 |
|
| 38 |
import com.google.gson.Gson;
|
31 |
import com.google.gson.Gson;
|
| 39 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
32 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 40 |
import com.spice.profitmandi.common.model.GstRate;
|
- |
|
| 41 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
33 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 42 |
import com.spice.profitmandi.common.web.client.RestClient;
|
34 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 43 |
import com.spice.profitmandi.thrift.clients.CatalogClient;
|
35 |
import com.spice.profitmandi.thrift.clients.CatalogClient;
|
| 44 |
import com.spice.profitmandi.thrift.clients.InventoryClient;
|
36 |
import com.spice.profitmandi.thrift.clients.InventoryClient;
|
| 45 |
import com.spice.profitmandi.thrift.clients.TransactionClient;
|
37 |
import com.spice.profitmandi.thrift.clients.TransactionClient;
|
| 46 |
import com.spice.profitmandi.thrift.clients.UserClient;
|
38 |
import com.spice.profitmandi.thrift.clients.UserClient;
|
| 47 |
import com.spice.profitmandi.thrift.clients.WarehouseClient;
|
39 |
import com.spice.profitmandi.thrift.clients.WarehouseClient;
|
| 48 |
import com.spice.profitmandi.thrift.clients.config.ConfigClient;
|
- |
|
| 49 |
|
40 |
|
| 50 |
import in.shop2020.model.v1.catalog.CatalogService;
|
41 |
import in.shop2020.model.v1.catalog.CatalogService;
|
| 51 |
import in.shop2020.model.v1.inventory.InventoryService;
|
42 |
import in.shop2020.model.v1.inventory.InventoryService;
|
| 52 |
import in.shop2020.model.v1.inventory.StateInfo;
|
43 |
import in.shop2020.model.v1.inventory.StateInfo;
|
| 53 |
import in.shop2020.model.v1.inventory.Warehouse;
|
44 |
import in.shop2020.model.v1.inventory.Warehouse;
|
| Line 73... |
Line 64... |
| 73 |
private static final Map<Integer, String> helpMap = new HashMap<>(6);
|
64 |
private static final Map<Integer, String> helpMap = new HashMap<>(6);
|
| 74 |
private static final Map<Integer, String> dthIdAliasMap = new HashMap<>(7);
|
65 |
private static final Map<Integer, String> dthIdAliasMap = new HashMap<>(7);
|
| 75 |
private static Map<Long, List<RechargePlan>> operatorPlanMap = new HashMap<>(20);
|
66 |
private static Map<Long, List<RechargePlan>> operatorPlanMap = new HashMap<>(20);
|
| 76 |
private static Map<Long, String> mobileProvidersMap;
|
67 |
private static Map<Long, String> mobileProvidersMap;
|
| 77 |
private static Map<Long, String> dthProvidersMap;
|
68 |
private static Map<Long, String> dthProvidersMap;
|
| 78 |
private static final String SMS_GATEWAY = "https://bmg.spicedigital.in/SMSGateway/messagePush";
|
- |
|
| 79 |
private static Map<Long, String> allProviders;
|
69 |
private static Map<Long, String> allProviders;
|
| 80 |
public static Map<RechargeOrderStatus, String> rechargeStatusMap = new HashMap<>();
|
70 |
public static Map<RechargeOrderStatus, String> rechargeStatusMap = new HashMap<>();
|
| 81 |
public static OrderStatusGroups ORDER_STATUS_GROUPS = new OrderStatusGroups();
|
71 |
public static OrderStatusGroups ORDER_STATUS_GROUPS = new OrderStatusGroups();
|
| 82 |
public static final String SYSTEM_PARTNER = "testpxps@gmail.com";
|
72 |
public static final String SYSTEM_PARTNER = "testpxps@gmail.com";
|
| 83 |
private static final RestClient rc = new RestClient();
|
73 |
private static final RestClient rc = new RestClient();
|
| 84 |
|
74 |
|
| 85 |
static {
|
- |
|
| 86 |
helpMap.put(Integer.valueOf(1), "Your VC number starts with 0 and is 11 digits long.");
|
- |
|
| 87 |
helpMap.put(Integer.valueOf(2), "Smart card number starts with 2 and is 12 digits long.");
|
- |
|
| 88 |
helpMap.put(Integer.valueOf(3), "Smart card number starts with 4 and is 11 digits long.");
|
- |
|
| 89 |
helpMap.put(Integer.valueOf(4), "Subscriber ID starts with 1 and is 10 digits long.");
|
- |
|
| 90 |
helpMap.put(Integer.valueOf(5), "For customer ID, SMS ID to 9212012299 from your registered mobile no.");
|
- |
|
| 91 |
helpMap.put(Integer.valueOf(26), "Customer ID starts with 3 and is 10 digits long.");
|
- |
|
| 92 |
|
- |
|
| 93 |
dthIdAliasMap.put(Integer.valueOf(1), "VC Number :");
|
- |
|
| 94 |
dthIdAliasMap.put(Integer.valueOf(2), "Smart Card Number :");
|
- |
|
| 95 |
dthIdAliasMap.put(Integer.valueOf(3), "Smart Card Number :");
|
- |
|
| 96 |
dthIdAliasMap.put(Integer.valueOf(4), "Subscriber Id :");
|
- |
|
| 97 |
dthIdAliasMap.put(Integer.valueOf(5), "Customer Id :");
|
- |
|
| 98 |
dthIdAliasMap.put(Integer.valueOf(0), "Account Number :");
|
- |
|
| 99 |
dthIdAliasMap.put(Integer.valueOf(26), "Customer Id :");
|
- |
|
| 100 |
|
- |
|
| 101 |
rechargeStatusMap.put(RechargeOrderStatus.PAYMENT_FAILED, "Payment Unsuccessful");
|
- |
|
| 102 |
rechargeStatusMap.put(RechargeOrderStatus.PAYMENT_SUCCESSFUL, "Processing Recharge");
|
- |
|
| 103 |
rechargeStatusMap.put(RechargeOrderStatus.RECHARGE_FAILED, "Recharge Failed");
|
- |
|
| 104 |
rechargeStatusMap.put(RechargeOrderStatus.RECHARGE_FAILED_REFUNDED, "Recharge Failed Refunded");
|
- |
|
| 105 |
rechargeStatusMap.put(RechargeOrderStatus.RECHARGE_SUCCESSFUL, "Recharge Successful");
|
- |
|
| 106 |
rechargeStatusMap.put(RechargeOrderStatus.REFUNDED, "Amount Refunded");
|
- |
|
| 107 |
rechargeStatusMap.put(RechargeOrderStatus.PARTIALLY_REFUNDED, "Amount Refunded");
|
- |
|
| 108 |
rechargeStatusMap.put(RechargeOrderStatus.PAYMENT_PENDING, "Payment Failed");
|
- |
|
| 109 |
rechargeStatusMap.put(RechargeOrderStatus.INIT, "Payment Initiated");
|
- |
|
| 110 |
rechargeStatusMap.put(RechargeOrderStatus.RECHARGE_UNKNOWN, "Recharge In Process");
|
- |
|
| 111 |
rechargeStatusMap.put(RechargeOrderStatus.RECHARGE_IN_PROCESS, "Recharge In Process");
|
- |
|
| 112 |
|
- |
|
| 113 |
TransactionClient tcl;
|
- |
|
| 114 |
try {
|
- |
|
| 115 |
tcl = new TransactionClient();
|
- |
|
| 116 |
mobileProvidersMap = tcl.getClient().getServiceProviders(RechargeType.MOBILE, true);
|
- |
|
| 117 |
dthProvidersMap = tcl.getClient().getServiceProviders(RechargeType.DTH, true);
|
- |
|
| 118 |
logger.info("mobileProvidersMap" + mobileProvidersMap);
|
- |
|
| 119 |
logger.info("dthProvidersMap" + dthProvidersMap);
|
- |
|
| 120 |
allProviders = new HashMap<>(mobileProvidersMap);
|
- |
|
| 121 |
logger.info("allProviders" + allProviders);
|
- |
|
| 122 |
allProviders.putAll(dthProvidersMap);
|
- |
|
| 123 |
logger.info("allProviders" + allProviders);
|
- |
|
| 124 |
|
- |
|
| 125 |
for (Long operatorId : mobileProvidersMap.keySet()) {
|
- |
|
| 126 |
List<RechargePlan> plans = tcl.getClient().getPlansForOperator(operatorId.longValue());
|
- |
|
| 127 |
if (!plans.isEmpty())
|
- |
|
| 128 |
operatorPlanMap.put(operatorId, plans);
|
- |
|
| 129 |
}
|
- |
|
| 130 |
} catch (Exception e) {
|
- |
|
| 131 |
logger.error("Could not get providers", e);
|
- |
|
| 132 |
}
|
- |
|
| 133 |
}
|
- |
|
| 134 |
|
- |
|
| 135 |
public static SellerInfo getSellerInfoBySellerId(int sellerId) throws Exception {
|
75 |
public static SellerInfo getSellerInfoBySellerId(int sellerId) throws Exception {
|
| 136 |
TransactionClient tcl = new TransactionClient();
|
76 |
TransactionClient tcl = new TransactionClient();
|
| 137 |
return tcl.getClient().getSellerInfo((long) sellerId);
|
77 |
return tcl.getClient().getSellerInfo((long) sellerId);
|
| 138 |
}
|
78 |
}
|
| 139 |
|
79 |
|
| Line 207... |
Line 147... |
| 207 |
paramsMap.put("password", "Smart@91");
|
147 |
paramsMap.put("password", "Smart@91");
|
| 208 |
paramsMap.put("senderID", "SMTDKN");
|
148 |
paramsMap.put("senderID", "SMTDKN");
|
| 209 |
paramsMap.put("message", text);
|
149 |
paramsMap.put("message", text);
|
| 210 |
paramsMap.put("mobile", mobileNumber);
|
150 |
paramsMap.put("mobile", mobileNumber);
|
| 211 |
paramsMap.put("messageType", "Text");
|
151 |
paramsMap.put("messageType", "Text");
|
| 212 |
rc.getResponse(SMS_GATEWAY, paramsMap, null);
|
152 |
//rc.getResponse(SMS_GATEWAY, paramsMap, null);
|
| 213 |
}
|
153 |
}
|
| 214 |
|
154 |
|
| 215 |
public static void sendMailWithAttachments(JavaMailSender mailSender, String emailTo, String[] cc, String subject,
|
155 |
public static void sendMailWithAttachments(JavaMailSender mailSender, String emailTo, String[] cc, String subject,
|
| 216 |
String body, List<File> attachments) throws Exception {
|
156 |
String body, List<File> attachments) throws Exception {
|
| 217 |
MimeMessage message = mailSender.createMimeMessage();
|
157 |
MimeMessage message = mailSender.createMimeMessage();
|
| Line 354... |
Line 294... |
| 354 |
|
294 |
|
| 355 |
public static String getIconUrl(int entityId, String host, int port, String webapp) {
|
295 |
public static String getIconUrl(int entityId, String host, int port, String webapp) {
|
| 356 |
return "";
|
296 |
return "";
|
| 357 |
}
|
297 |
}
|
| 358 |
|
298 |
|
| 359 |
public static Map<Integer, GstRate> getStateTaxRate(List<Integer> itemIds, int stateId)
|
- |
|
| 360 |
throws ProfitMandiBusinessException {
|
- |
|
| 361 |
List<Long> longItemIds = new ArrayList<>();
|
- |
|
| 362 |
for (int itemId : itemIds) {
|
- |
|
| 363 |
longItemIds.add(Long.valueOf(itemId));
|
- |
|
| 364 |
}
|
- |
|
| 365 |
try {
|
- |
|
| 366 |
CatalogService.Client catalogClient = getCatalogClient();
|
- |
|
| 367 |
Map<Long, in.shop2020.model.v1.catalog.GstRate> totalTaxRateMap = catalogClient.getStateTaxRate(longItemIds,
|
- |
|
| 368 |
stateId);
|
- |
|
| 369 |
Map<Integer, GstRate> itemIdGstRateMap = new HashMap<>();
|
- |
|
| 370 |
for (Map.Entry<Long, in.shop2020.model.v1.catalog.GstRate> totalTaxRateEntry : totalTaxRateMap.entrySet()) {
|
- |
|
| 371 |
GstRate gstRate = new GstRate();
|
- |
|
| 372 |
gstRate.setIgstRate(Double.valueOf(totalTaxRateEntry.getValue().getIgstRate()).floatValue());
|
- |
|
| 373 |
gstRate.setCgstRate(Double.valueOf(totalTaxRateEntry.getValue().getCgstRate()).floatValue());
|
- |
|
| 374 |
gstRate.setSgstRate(Double.valueOf(totalTaxRateEntry.getValue().getSgstRate()).floatValue());
|
- |
|
| 375 |
itemIdGstRateMap.put(totalTaxRateEntry.getKey().intValue(), gstRate);
|
- |
|
| 376 |
}
|
- |
|
| 377 |
return itemIdGstRateMap;
|
- |
|
| 378 |
} catch (Exception e) {
|
- |
|
| 379 |
e.printStackTrace();
|
- |
|
| 380 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.ITEM_ID + ", " + ProfitMandiConstants.STATE_ID,
|
- |
|
| 381 |
itemIds + ", " + stateId, "THRFT_1000");
|
- |
|
| 382 |
}
|
- |
|
| 383 |
}
|
- |
|
| 384 |
|
- |
|
| 385 |
public static Map<Integer, Float> getIgstTaxRate(List<Integer> itemIds) throws ProfitMandiBusinessException {
|
- |
|
| 386 |
List<Long> longItemIds = new ArrayList<>();
|
- |
|
| 387 |
for (int itemId : itemIds) {
|
- |
|
| 388 |
longItemIds.add(Long.valueOf(itemId));
|
- |
|
| 389 |
}
|
- |
|
| 390 |
try {
|
- |
|
| 391 |
CatalogService.Client catalogClient = getCatalogClient();
|
- |
|
| 392 |
Map<Long, Double> totalTaxRateMap = catalogClient.getIgstTaxRate(longItemIds);
|
- |
|
| 393 |
Map<Integer, Float> itemIdIgstRateMap = new HashMap<>();
|
- |
|
| 394 |
for (Map.Entry<Long, Double> totalTaxRateEntry : totalTaxRateMap.entrySet()) {
|
- |
|
| 395 |
itemIdIgstRateMap.put(totalTaxRateEntry.getKey().intValue(), 12f);
|
- |
|
| 396 |
}
|
- |
|
| 397 |
return itemIdIgstRateMap;
|
- |
|
| 398 |
} catch (Exception e) {
|
- |
|
| 399 |
e.printStackTrace();
|
- |
|
| 400 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.ITEM_ID, itemIds, "THRFT_1001");
|
- |
|
| 401 |
}
|
- |
|
| 402 |
}
|
- |
|
| 403 |
|
299 |
|
| 404 |
private static CatalogService.Client getCatalogClient() throws Exception {
|
300 |
private static CatalogService.Client getCatalogClient() throws Exception {
|
| 405 |
try {
|
301 |
try {
|
| 406 |
CatalogClient client = new CatalogClient();
|
302 |
CatalogClient client = new CatalogClient();
|
| 407 |
CatalogService.Client catalogClient = client.getClient();
|
303 |
CatalogService.Client catalogClient = client.getClient();
|