Subversion Repositories SmartDukaan

Rev

Rev 35204 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35204 Rev 36623
Line 1... Line 1...
1
package com.spice.profitmandi.common.util;
1
package com.spice.profitmandi.common.util;
2
 
2
 
3
import com.google.gson.Gson;
3
import com.google.gson.Gson;
4
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
4
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
5
import com.spice.profitmandi.common.web.client.RestClient;
5
import com.spice.profitmandi.common.web.client.RestClient;
6
import com.spice.profitmandi.thrift.clients.InventoryClient;
-
 
7
import com.spice.profitmandi.thrift.clients.WarehouseClient;
-
 
8
import in.shop2020.model.v1.inventory.InventoryService;
-
 
9
import in.shop2020.model.v1.inventory.StateInfo;
-
 
10
import in.shop2020.model.v1.inventory.Warehouse;
-
 
11
import in.shop2020.model.v1.order.OrderStatusGroups;
-
 
12
import in.shop2020.model.v1.order.RechargeOrderStatus;
-
 
13
import in.shop2020.model.v1.order.RechargePlan;
-
 
14
import in.shop2020.warehouse.InventoryItem;
-
 
15
import in.shop2020.warehouse.WarehouseService;
-
 
16
import org.apache.commons.io.FileUtils;
6
import org.apache.commons.io.FileUtils;
17
import org.apache.commons.lang3.StringEscapeUtils;
7
import org.apache.commons.lang3.StringEscapeUtils;
18
import org.apache.logging.log4j.LogManager;
8
import org.apache.logging.log4j.LogManager;
19
import org.apache.logging.log4j.Logger;
9
import org.apache.logging.log4j.Logger;
20
import org.springframework.core.io.InputStreamSource;
10
import org.springframework.core.io.InputStreamSource;
Line 52... Line 42...
52
    public static final String PRODUCT_PROPERTIES_SNIPPET = "ProductPropertiesSnippet.html";
42
    public static final String PRODUCT_PROPERTIES_SNIPPET = "ProductPropertiesSnippet.html";
53
    public static final String DOCUMENT_STORE = "/profitmandi/documents/";
43
    public static final String DOCUMENT_STORE = "/profitmandi/documents/";
54
    private Gson gson = new Gson();
44
    private Gson gson = new Gson();
55
    private static final Map<Integer, String> helpMap = new HashMap<>(6);
45
    private static final Map<Integer, String> helpMap = new HashMap<>(6);
56
    private static final Map<Integer, String> dthIdAliasMap = new HashMap<>(7);
46
    private static final Map<Integer, String> dthIdAliasMap = new HashMap<>(7);
57
    private static Map<Long, List<RechargePlan>> operatorPlanMap = new HashMap<>(20);
-
 
58
    private static Map<Long, String> mobileProvidersMap;
47
    private static Map<Long, String> mobileProvidersMap;
59
    private static Map<Long, String> dthProvidersMap;
48
    private static Map<Long, String> dthProvidersMap;
60
    private static Map<Long, String> allProviders;
49
    private static Map<Long, String> allProviders;
61
    public static Map<RechargeOrderStatus, String> rechargeStatusMap = new HashMap<>();
-
 
62
    public static OrderStatusGroups ORDER_STATUS_GROUPS = new OrderStatusGroups();
-
 
63
    public static final String SYSTEM_PARTNER = "testpxps@gmail.com";
50
    public static final String SYSTEM_PARTNER = "testpxps@gmail.com";
64
    public static final int SYSTEM_PARTNER_ID = 175120474;
51
    public static final int SYSTEM_PARTNER_ID = 175120474;
65
    private static final RestClient rc = new RestClient();
52
    private static final RestClient rc = new RestClient();
66
    private static final String regex = "^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$";
53
    private static final String regex = "^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$";
67
    public static final LocalTime MAX_TIME = LocalTime.of(23, 59, 59);
54
    public static final LocalTime MAX_TIME = LocalTime.of(23, 59, 59);
Line 106... Line 93...
106
 
93
 
107
    public static LocalDateTime toLocalDateTime(long epochTimeInMillis) {
94
    public static LocalDateTime toLocalDateTime(long epochTimeInMillis) {
108
        return LocalDateTime.ofInstant(Instant.ofEpochMilli(epochTimeInMillis), ZoneId.systemDefault());
95
        return LocalDateTime.ofInstant(Instant.ofEpochMilli(epochTimeInMillis), ZoneId.systemDefault());
109
    }
96
    }
110
 
97
 
111
    public static String getRechargeDisplayStatus(RechargeOrderStatus status) {
-
 
112
        if (status == null) {
-
 
113
            status = RechargeOrderStatus.INIT;
-
 
114
        }
-
 
115
        String displayStatus = (String) rechargeStatusMap.get(status);
-
 
116
        if (displayStatus == null) {
-
 
117
            return "";
-
 
118
        }
-
 
119
        return displayStatus;
-
 
120
    }
-
 
121
 
-
 
122
    public static boolean copyDocument(String documentPath) {
98
    public static boolean copyDocument(String documentPath) {
123
        File source = new File(documentPath);
99
        File source = new File(documentPath);
124
        File dest = new File(DOCUMENT_STORE + source.getName());
100
        File dest = new File(DOCUMENT_STORE + source.getName());
125
        try {
101
        try {
126
            FileUtils.copyFile(source, dest);
102
            FileUtils.copyFile(source, dest);
Line 273... Line 249...
273
        InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "SmartDukaan Care");
249
        InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "SmartDukaan Care");
274
        helper.setFrom(senderAddress);
250
        helper.setFrom(senderAddress);
275
        mailSender.send(message);
251
        mailSender.send(message);
276
    }
252
    }
277
 
253
 
278
    public static String[] getOrderStatus(RechargeOrderStatus status) {
-
 
279
        if (status == null) {
-
 
280
            status = RechargeOrderStatus.INIT;
-
 
281
        }
-
 
282
        if (status.equals(RechargeOrderStatus.PAYMENT_FAILED) || status.equals(RechargeOrderStatus.PAYMENT_PENDING)) {
-
 
283
            return new String[]{"false", "PAYMENT FAILED", "Payment failed at the payment gateway."};
-
 
284
        } else if (status.equals(RechargeOrderStatus.PAYMENT_SUCCESSFUL)
-
 
285
                || status.equals(RechargeOrderStatus.RECHARGE_UNKNOWN)) {
-
 
286
            if (status.equals(RechargeOrderStatus.PAYMENT_SUCCESSFUL)) {
-
 
287
                return new String[]{"false", "PAYMENT SUCCESSFUL",
-
 
288
                        "Your Payment was successful but due to some internal error with the operator's system we are not sure if the recharge was successful."
-
 
289
                                + " We have put your recharge under process."
-
 
290
                                + " As soon as we get a confirmation on this transaction, we will notify you."};
-
 
291
            } else {
-
 
292
                return new String[]{"false", "RECHARGE IN PROCESS",
-
 
293
                        "Your Payment is successful.We have put your recharge under process."
-
 
294
                                + " Please wait while we check with the operator."};
-
 
295
            }
-
 
296
        } else if (status.equals(RechargeOrderStatus.RECHARGE_FAILED)
-
 
297
                || status.equals(RechargeOrderStatus.RECHARGE_FAILED_REFUNDED)) {
-
 
298
            return new String[]{"false", "RECHARGE FAILED",
-
 
299
                    "Your Payment was successful but unfortunately the recharge failed.Don't worry your payment is safe with us."
-
 
300
                            + " The entire Amount has been refunded to your wallet."};
-
 
301
        } else if (status.equals(RechargeOrderStatus.RECHARGE_SUCCESSFUL)) {
-
 
302
            return new String[]{"false", "SUCCESS", "Congratulations! Your device is successfully recharged."};
-
 
303
        } else if (status.equals(RechargeOrderStatus.PARTIALLY_REFUNDED)
-
 
304
                || status.equals(RechargeOrderStatus.REFUNDED)) {
-
 
305
            return new String[]{"false", "PAYMENT REFUNDED",
-
 
306
                    "The payment associated with this recharge order has been refunded."};
-
 
307
        } else {
-
 
308
            return new String[]{"true", "ERROR", "INVALID INPUT"};
-
 
309
        }
-
 
310
    }
-
 
311
 
-
 
312
    public static String getIconUrl(int entityId, String host, int port, String webapp) {
254
    public static String getIconUrl(int entityId, String host, int port, String webapp) {
313
        return "";
255
        return "";
314
    }
256
    }
315
 
257
 
316
 
-
 
317
    private static WarehouseService.Client getWarehouseClient() throws Exception {
-
 
318
        try {
-
 
319
            WarehouseClient client = new WarehouseClient();
-
 
320
            WarehouseService.Client warehouseClient = client.getClient();
-
 
321
            return warehouseClient;
-
 
322
        } catch (Exception e) {
-
 
323
            throw e;
-
 
324
        }
-
 
325
    }
-
 
326
 
-
 
327
    public static Map<String, Warehouse> getWarehouseByImeis(List<String> imeis) throws Exception {
-
 
328
        List<InventoryItem> inventoryItems = getWarehouseClient().getInventoryItemsBySerailNumbers(imeis);
-
 
329
        Map<String, InventoryItem> imeiInventoryItemMap = new HashMap<>();
-
 
330
        for (InventoryItem inventoryItem : inventoryItems) {
-
 
331
            imeiInventoryItemMap.put(inventoryItem.getSerialNumber(), inventoryItem);
-
 
332
        }
-
 
333
        Map<Integer, Warehouse> warehouseMap = new HashMap<>();
-
 
334
        Map<String, Warehouse> serialNumberWarehouseMap = new HashMap<>();
-
 
335
        InventoryClient client = new InventoryClient();
-
 
336
        InventoryService.Client inventoryClient = client.getClient();
-
 
337
        logger.info("[imeiInventoryItemMap] {}", imeiInventoryItemMap);
-
 
338
        for (InventoryItem inventory : new HashSet<>(imeiInventoryItemMap.values())) {
-
 
339
            Warehouse phWarehouse = null;
-
 
340
            if (warehouseMap.containsKey(inventory.getPhysicalWarehouseId())) {
-
 
341
                phWarehouse = warehouseMap.get((int) inventory.getPhysicalWarehouseId());
-
 
342
            } else {
-
 
343
                phWarehouse = inventoryClient.getWarehouse(inventory.getPhysicalWarehouseId());
-
 
344
                warehouseMap.put((int) inventory.getPhysicalWarehouseId(), phWarehouse);
-
 
345
            }
-
 
346
            serialNumberWarehouseMap.put(inventory.getSerialNumber(), phWarehouse);
-
 
347
 
-
 
348
        }
-
 
349
        return serialNumberWarehouseMap;
-
 
350
    }
-
 
351
 
-
 
352
    public static Map<Integer, Warehouse> getWarehousesByIds(Set<Integer> warehouseIds) throws Exception {
-
 
353
        InventoryClient client = new InventoryClient();
-
 
354
        InventoryService.Client inventoryClient = client.getClient();
-
 
355
        Map<Integer, Warehouse> warehouseMap = new HashMap<>();
-
 
356
        for (Integer warehouseId : warehouseIds) {
-
 
357
            warehouseMap.put(warehouseId, inventoryClient.getWarehouse(warehouseId));
-
 
358
        }
-
 
359
        return warehouseMap;
-
 
360
    }
-
 
361
 
-
 
362
    public static String getStateCode(String stateName) throws Exception {
-
 
363
        return getStateInfo(stateName).getStateCode();
-
 
364
    }
-
 
365
 
-
 
366
    public static long getStateId(String stateName) throws ProfitMandiBusinessException {
-
 
367
        try {
-
 
368
            return getStateInfo(stateName).getId();
-
 
369
        } catch (Exception e) {
-
 
370
            e.printStackTrace();
-
 
371
            throw new ProfitMandiBusinessException("State Name", stateName, "Could not fetch state");
-
 
372
        }
-
 
373
    }
-
 
374
 
-
 
375
    public static StateInfo getStateByStateId(long stateId) throws Exception {
-
 
376
        InventoryClient client = new InventoryClient();
-
 
377
        InventoryService.Client inventoryClient = client.getClient();
-
 
378
        Map<Long, StateInfo> map = inventoryClient.getStateMaster();
-
 
379
        return map.get(stateId);
-
 
380
    }
-
 
381
 
-
 
382
    public static StateInfo getStateInfo(String stateName) throws Exception {
-
 
383
        try {
-
 
384
            InventoryClient client = new InventoryClient();
-
 
385
            InventoryService.Client inventoryClient = client.getClient();
-
 
386
            Map<Long, StateInfo> map = inventoryClient.getStateMaster();
-
 
387
            List<StateInfo> stateInfos = new ArrayList<>(map.values());
-
 
388
            logger.info("State Name: {}", stateName);
-
 
389
            for (StateInfo stateInfo : stateInfos) {
-
 
390
                logger.info("State Name from service: {}", stateInfo.getStateName());
-
 
391
                if (stateName.toUpperCase().equals(stateInfo.getStateName().toUpperCase())) {
-
 
392
                    return stateInfo;
-
 
393
                }
-
 
394
            }
-
 
395
            throw new Exception("Not found");
-
 
396
        } catch (Exception e) {
-
 
397
            e.printStackTrace();
-
 
398
            throw e;
-
 
399
        }
-
 
400
    }
-
 
401
 
-
 
402
    public static void main(String[] args) throws Exception {
258
    public static void main(String[] args) throws Exception {
403
        Utils.sendSms("Hello", "9990381569");
259
        Utils.sendSms("Hello", "9990381569");
404
    }
260
    }
405
 
261
 
406
    public static void sendEmbeddedHtmlMail(JavaMailSender mailSender, String[] emailTo, String[] cc, String subject,
262
    public static void sendEmbeddedHtmlMail(JavaMailSender mailSender, String[] emailTo, String[] cc, String subject,