Subversion Repositories SmartDukaan

Rev

Rev 32822 | Rev 32841 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 32822 Rev 32832
Line 134... Line 134...
134
import java.util.*;
134
import java.util.*;
135
import java.util.Map.Entry;
135
import java.util.Map.Entry;
136
import java.util.stream.Collectors;
136
import java.util.stream.Collectors;
137
import java.util.stream.Stream;
137
import java.util.stream.Stream;
138
 
138
 
139
 
-
 
140
import static java.util.stream.Collectors.groupingBy;
139
import static java.util.stream.Collectors.groupingBy;
141
import static java.util.stream.Collectors.mapping;
140
import static java.util.stream.Collectors.mapping;
142
 
141
 
143
 
142
 
144
@Component
143
@Component
Line 268... Line 267...
268
    private ServiceConfigRepository serviceConfigRepository;
267
    private ServiceConfigRepository serviceConfigRepository;
269
 
268
 
270
    @Autowired
269
    @Autowired
271
    private RetailerBlockBrandsRepository retailerBlockBrandsRepository;
270
    private RetailerBlockBrandsRepository retailerBlockBrandsRepository;
272
 
271
 
273
    @Value("${delhivery.tracking.token}")
-
 
274
    private String token;
-
 
275
 
-
 
276
    private static final String[] STOCK_AGEING_MAIL_LIST = new String[]{"uday.singh@smartudkaan.com", "mohinder.mutreja@smartdukaan.com", "ankit.bhatia@smartdukaan.com", "tarun.verma@smartdukaan.com", "kuldeep.kumar@smartdukaan.com", "manish.gupta@smartdukaan.com"};
272
    private static final String[] STOCK_AGEING_MAIL_LIST = new String[]{"uday.singh@smartudkaan.com", "mohinder.mutreja@smartdukaan.com", "ankit.bhatia@smartdukaan.com", "tarun.verma@smartdukaan.com", "kuldeep.kumar@smartdukaan.com", "manish.gupta@smartdukaan.com"};
277
 
273
 
278
    private static final String[] ITEMWISE_PENDING_INDENT_MAIL_LIST = new String[]{"kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com", "uday.singh@smartdukaan.com", "kuldeep.kumar@smartdukaan.com", "niranjan.kala@smartdukaan.com"};
274
    private static final String[] ITEMWISE_PENDING_INDENT_MAIL_LIST = new String[]{"kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com", "uday.singh@smartdukaan.com", "kuldeep.kumar@smartdukaan.com", "niranjan.kala@smartdukaan.com"};
279
 
275
 
280
    private static final String[] INDENT_TERTIARY_MAIL_LIST = new String[]{"uday.singh@smartdukaan.com", "kuldeep.kumar@smartdukaan.com", "nishant.ohri@smartdukaan.com"};
276
    private static final String[] INDENT_TERTIARY_MAIL_LIST = new String[]{"uday.singh@smartdukaan.com", "kuldeep.kumar@smartdukaan.com", "nishant.ohri@smartdukaan.com"};
Line 1328... Line 1324...
1328
        partnerTypeChangeService.getTypeOnDate(175139287, LocalDate.of(2023,03, 01));
1324
        partnerTypeChangeService.getTypeOnDate(175139287, LocalDate.of(2023,03, 01));
1329
        partnerTypeChangeService.getTypeOnDate(175139287, LocalDate.of(2023,04, 01));
1325
        partnerTypeChangeService.getTypeOnDate(175139287, LocalDate.of(2023,04, 01));
1330
        FofoStore fs = fofoStoreRepository.selectByRetailerId(175139287);
1326
        FofoStore fs = fofoStoreRepository.selectByRetailerId(175139287);
1331
        this.rolloutMarginForStoreOnMonth(fs, LocalDate.of(2023, 2, 1));
1327
        this.rolloutMarginForStoreOnMonth(fs, LocalDate.of(2023, 2, 1));
1332
        this.rolloutMarginForStoreOnMonth(fs, LocalDate.of(2023, 3, 1));*/
1328
        this.rolloutMarginForStoreOnMonth(fs, LocalDate.of(2023, 3, 1));*/
1333
        this.markBlueDartOrderDelivered();
-
 
1334
        //this.sendMailForSamsungRebilling();
1329
        //this.sendMailForSamsungRebilling();
1335
        /*List<PurchaseReturnItem> purchaseReturnItems = purchaseReturnItemRepository.selectPurchaseReturnByStatuses(Arrays.asList(PurchaseReturnStatus.DEBIT_NOTE_CREATED));
1330
        /*List<PurchaseReturnItem> purchaseReturnItems = purchaseReturnItemRepository.selectPurchaseReturnByStatuses(Arrays.asList(PurchaseReturnStatus.DEBIT_NOTE_CREATED));
1336
        Map<Integer, List<PurchaseReturnItem>> inventoryItemsMap = purchaseReturnItems.stream().collect(Collectors.groupingBy(x -> x.getDebitNoteId()));
1331
        Map<Integer, List<PurchaseReturnItem>> inventoryItemsMap = purchaseReturnItems.stream().collect(Collectors.groupingBy(x -> x.getDebitNoteId()));
1337
        for (Map.Entry<Integer, List<PurchaseReturnItem>> debitNotePurcahseReturnMap : inventoryItemsMap.entrySet()) {
1332
        for (Map.Entry<Integer, List<PurchaseReturnItem>> debitNotePurcahseReturnMap : inventoryItemsMap.entrySet()) {
1338
            List<InventoryItem> inventoryItems = inventoryItemRepository.selectAllByIds(debitNotePurcahseReturnMap.getValue().stream().map(x -> x.getInventoryItemId()).collect(Collectors.toList()));
1333
            List<InventoryItem> inventoryItems = inventoryItemRepository.selectAllByIds(debitNotePurcahseReturnMap.getValue().stream().map(x -> x.getInventoryItemId()).collect(Collectors.toList()));
Line 2968... Line 2963...
2968
        sb.append("</tbody></table></body></html>");
2963
        sb.append("</tbody></table></body></html>");
2969
 
2964
 
2970
        return sb.toString();
2965
        return sb.toString();
2971
    }
2966
    }
2972
 
2967
 
2973
    private String getMessageForUncontacblePartner(List<PartnerCollectionRemark> pcrs) throws
2968
    private String getMessageForRBMEscalatedPartners(List<PartnerCollectionRemark> pcrs) throws
2974
            ProfitMandiBusinessException {
2969
            ProfitMandiBusinessException {
2975
        StringBuilder sb = new StringBuilder();
2970
        StringBuilder sb = new StringBuilder();
2976
        sb.append("<html><body><p>Alert</p><p>Not Responding Partner:-</p>" + "<br/><table style='border:1px solid black ;padding: 5px';>");
2971
        sb.append("<html><body><p>Alert</p><p>Escalated by RBM-L1:-</p>" + "<br/><table style='border:1px solid black ;padding: 5px';>");
-
 
2972
        sb.append("<tbody>" +
-
 
2973
                "<tr>" +
2977
        sb.append("<tbody>\n" + "	    				<tr>\n" + "	    					<th style='border:1px solid black;padding: 5px'>PartnerName</th>\n" + "	    					<th style='border:1px solid black;padding: 5px'>from</th>\n"
2974
                "<th style='border:1px solid black;padding: 5px'>PartnerName</th>" +
-
 
2975
                "<th style='border:1px solid black;padding: 5px'>Escalated Since</th>" +
-
 
2976
                "<th style='border:1px solid black;padding: 5px'>Message</th>" +
-
 
2977
                "</tr>");
2978
 
2978
 
2979
                + "	    				</tr>");
-
 
2980
        for (PartnerCollectionRemark entry : pcrs) {
2979
        for (PartnerCollectionRemark entry : pcrs) {
2981
 
2980
 
2982
            CustomRetailer customRetailer = retailerService.getFofoRetailer(entry.getFofoId());
2981
            CustomRetailer customRetailer = retailerService.getFofoRetailer(entry.getFofoId());
2983
 
2982
 
2984
            sb.append("<tr>");
2983
            sb.append("<tr>");
2985
            sb.append("<td style='border:1px solid black;padding: 5px'>" + customRetailer.getBusinessName() + "(" + customRetailer.getCode() + ")" + "</td>");
2984
            sb.append("<td style='border:1px solid black;padding: 5px'>" + customRetailer.getBusinessName() + "(" + customRetailer.getCode() + ")" + "</td>");
2986
 
-
 
2987
            sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getCreateTimestamp().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + "</td>");
2985
            sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getCreateTimestamp().format(DateTimeFormatter.ofPattern("dd/MM/yyyy")) + "</td>");
-
 
2986
            sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getMessage() + "</td>");
2988
 
2987
 
2989
            sb.append("</tr>");
2988
            sb.append("</tr>");
2990
 
2989
 
2991
        }
2990
        }
2992
 
2991
 
Line 3339... Line 3338...
3339
        String data = "";
3338
        String data = "";
3340
        data = new String(Files.readAllBytes(Paths.get(file)));
3339
        data = new String(Files.readAllBytes(Paths.get(file)));
3341
        return data;
3340
        return data;
3342
    }
3341
    }
3343
 
3342
 
3344
    public void markDelhiveryOrderDelivered() throws Exception {
-
 
3345
        List<Order> orders = orderRepository.selectOrderByProviderIdAndStatus(ProfitMandiConstants.DELHIVERY_PROVIDERID, OrderStatus.SHIPPED_FROM_WH);
-
 
3346
 
-
 
3347
        if (!orders.isEmpty()) {
-
 
3348
            Set<String> airwayBill = orders.stream().map(x -> x.getAirwayBillNumber()).collect(Collectors.toSet());
-
 
3349
 
-
 
3350
            int arraylength = airwayBill.size();
-
 
3351
 
-
 
3352
            if (arraylength >= 75) {
-
 
3353
 
-
 
3354
                airwayBill = airwayBill.stream().limit(74).collect(Collectors.toSet());
-
 
3355
            }
-
 
3356
            LOGGER.info("airwayBill" + airwayBill);
-
 
3357
            String url = "https://track.delhivery.com/api/v1/packages/json/";
-
 
3358
 
-
 
3359
            OkHttpClient client = new OkHttpClient();
-
 
3360
 
-
 
3361
            Request request1 = new Request.Builder().url(url + "?waybill=" + String.join(",", airwayBill) + "&token=" + token).get().build();
-
 
3362
 
-
 
3363
            LOGGER.info("request1" + request1);
-
 
3364
 
-
 
3365
            Response response = client.newCall(request1).execute();
-
 
3366
 
-
 
3367
            LOGGER.info("jsonbj" + response.body());
-
 
3368
 
-
 
3369
            JSONObject jsonObj = new JSONObject(response.body().string());
-
 
3370
 
-
 
3371
            LOGGER.info("jsonObj" + jsonObj);
-
 
3372
 
-
 
3373
            JSONArray shipmentData = jsonObj.getJSONArray("ShipmentData");
-
 
3374
            Set<String> airwaybillStatus = new HashSet<>();
-
 
3375
            for (int i = 0; i < shipmentData.length(); i++) {
-
 
3376
                JSONObject jsonObject = shipmentData.getJSONObject(i);
-
 
3377
                JSONObject shipment = jsonObject.getJSONObject("Shipment");
-
 
3378
 
-
 
3379
                LOGGER.info("shipment" + shipment);
-
 
3380
                JSONObject statusDescription = shipment.getJSONObject("Status");
-
 
3381
                String awb = shipment.getString("AWB");
-
 
3382
 
-
 
3383
                String status = statusDescription.getString("Status");
-
 
3384
                LOGGER.info("status" + status);
-
 
3385
 
-
 
3386
                LOGGER.info("awb" + awb);
-
 
3387
                if (status.equals("Delivered")) {
-
 
3388
                    airwaybillStatus.add(awb);
-
 
3389
                }
-
 
3390
 
-
 
3391
            }
-
 
3392
            markOrderDelivered(airwaybillStatus);
-
 
3393
        }
-
 
3394
    }
-
 
3395
 
-
 
3396
    public void markBlueDartOrderDelivered() throws Exception {
-
 
3397
 
-
 
3398
        String loginId = "DEL81122";
-
 
3399
 
-
 
3400
        String licencekey = "uhfhlg2jpmnqfhfrlsgzfr1nhu1qfvel";
-
 
3401
 
-
 
3402
        List<Order> orders = orderRepository.selectOrderByProviderIdAndStatus(ProfitMandiConstants.BLUEDART_PROVIDERID, OrderStatus.SHIPPED_FROM_WH);
-
 
3403
 
-
 
3404
        if (!orders.isEmpty()) {
-
 
3405
 
-
 
3406
            Set<String> airwayBillNo = orders.stream().map(x -> x.getAirwayBillNumber()).collect(Collectors.toSet());
-
 
3407
 
-
 
3408
            LOGGER.info("airwayBill" + airwayBillNo);
-
 
3409
            String url = "https://api.bluedart.com/servlet/RoutingServlet?handler=tnt&action=custawbquery";
-
 
3410
 
-
 
3411
            String response = restClient.get(url + "&loginid=" + loginId + "&awb=awb&numbers=" + String.join(",", airwayBillNo) + "&format=xml&lickey=" + licencekey + "&verno=1.3&scan=1", null, null);
-
 
3412
 
-
 
3413
            JSONObject updateJson = XML.toJSONObject(response);
-
 
3414
 
-
 
3415
            JSONObject shipmentData = updateJson.getJSONObject("ShipmentData");
-
 
3416
            Object shipmentObject = shipmentData.get("Shipment");
-
 
3417
 
-
 
3418
            Set<String> airwaybillStatus = new HashSet<>();
-
 
3419
 
-
 
3420
            if (shipmentObject instanceof JSONArray) {
-
 
3421
                JSONArray shipments = (JSONArray) shipmentObject;
-
 
3422
                for (int i = 0; i < shipments.length(); i++) {
-
 
3423
                    JSONObject jsonObject = shipments.getJSONObject(i);
-
 
3424
 
-
 
3425
                    Number awb = jsonObject.getNumber("WaybillNo");
-
 
3426
                    String status = jsonObject.getString("Status");
-
 
3427
 
-
 
3428
                    if (status.equals("SHIPMENT DELIVERED")) {
-
 
3429
                        airwaybillStatus.add(awb.toString());
-
 
3430
                    }
-
 
3431
 
-
 
3432
                }
-
 
3433
            } else {
-
 
3434
                JSONObject jsonObject = (JSONObject) shipmentObject;
-
 
3435
                Number awb = jsonObject.getNumber("WaybillNo");
-
 
3436
                String status = jsonObject.getString("Status");
-
 
3437
 
-
 
3438
                if (status.equals("SHIPMENT DELIVERED")) {
-
 
3439
                    airwaybillStatus.add(awb.toString());
-
 
3440
                }
-
 
3441
 
-
 
3442
            }
-
 
3443
 
-
 
3444
            LOGGER.info("airwaybillStatus" + airwaybillStatus);
-
 
3445
 
-
 
3446
            markOrderDelivered(airwaybillStatus);
-
 
3447
        }
-
 
3448
 
-
 
3449
    }
-
 
3450
 
-
 
3451
    private void markOrderDelivered(Set<String> airwaybillStatus) throws Exception {
-
 
3452
        if (!airwaybillStatus.isEmpty()) {
-
 
3453
            for (String aws : airwaybillStatus) {
-
 
3454
 
3343
 
3455
                List<Order> deliverdOrders = orderRepository.selectByAirwayBillNumber(aws);
-
 
3456
 
-
 
3457
                int fofoId = deliverdOrders.get(0).getRetailerId();
-
 
3458
                for (Order dlo : deliverdOrders) {
-
 
3459
                    dlo.setStatus(OrderStatus.DELIVERY_SUCCESS);
-
 
3460
                    dlo.setStatusDescription("Order Delivered");
-
 
3461
                    dlo.setDeliveryTimestamp(LocalDateTime.now());
-
 
3462
                }
-
 
3463
 
-
 
3464
                com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(fofoId);
-
 
3465
 
-
 
3466
                Address address = addressRepository.selectById(user.getAddressId());
-
 
3467
 
-
 
3468
                String title = "Order Delivered";
-
 
3469
 
-
 
3470
                String message = String.format("Dear partner, Your SmartDukaan Order " + aws + " has been delivered to you in a safe sealed bag.");
-
 
3471
 
-
 
3472
                SendNotificationModel sendNotificationModel = new SendNotificationModel();
-
 
3473
                sendNotificationModel.setCampaignName("Order Delivered");
-
 
3474
                sendNotificationModel.setTitle(title);
-
 
3475
                sendNotificationModel.setMessage(message);
-
 
3476
                sendNotificationModel.setType("url");
-
 
3477
                sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
-
 
3478
                sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
-
 
3479
                sendNotificationModel.setMessageType(MessageType.notification);
-
 
3480
                int userId = userAccountRepository.selectUserIdByRetailerId(fofoId);
-
 
3481
                sendNotificationModel.setUserIds(Arrays.asList(userId));
-
 
3482
                notificationService.sendNotification(sendNotificationModel);
-
 
3483
 
-
 
3484
                notificationService.sendWhatsappMessage(message, title, address.getPhoneNumber());
-
 
3485
 
-
 
3486
            }
-
 
3487
        }
-
 
3488
    }
-
 
3489
 
3344
 
3490
    public void partnerWiseCreditAccount() throws Exception {
3345
    public void partnerWiseCreditAccount() throws Exception {
3491
 
3346
 
3492
        List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
3347
        List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
3493
 
3348
 
Line 3546... Line 3401...
3546
    }
3401
    }
3547
 
3402
 
3548
    @Autowired
3403
    @Autowired
3549
    private PartnerCollectionRemarkRepository partnerCollectionRemarkRepository;
3404
    private PartnerCollectionRemarkRepository partnerCollectionRemarkRepository;
3550
 
3405
 
-
 
3406
    //RBM L2 Escalations
3551
    public void reviewUncontactablePartner() throws
3407
    public void reviewUncontactablePartner() throws
3552
            ProfitMandiBusinessException, MessagingException, UnsupportedEncodingException {
3408
            ProfitMandiBusinessException, MessagingException, UnsupportedEncodingException {
3553
 
3409
 
3554
        Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(true);
3410
        Map<Integer, CustomRetailer> customRetailerMap = retailerService.getFofoRetailers(true);
3555
 
3411
 
3556
        List<Integer> pcrms = partnerCollectionRemarkRepository.selectMaxRemarkId(new ArrayList<>(customRetailerMap.keySet()));
3412
        List<Integer> partnerLastCollectionRemarkIds = partnerCollectionRemarkRepository.selectMaxRemarkId(new ArrayList<>(customRetailerMap.keySet()));
3557
 
3413
 
3558
        if (!pcrms.isEmpty()) {
3414
        if (!partnerLastCollectionRemarkIds.isEmpty()) {
3559
            Map<Integer, PartnerCollectionRemark> partnerCollectionRemarksMap = partnerCollectionRemarkRepository.selectByIds(pcrms).stream().filter(x -> x.getRemark().equals(CollectionRemark.NOT_RESPONDING)).collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
3415
            List<PartnerCollectionRemark> partnerCollectionRemarks = partnerCollectionRemarkRepository.selectByIds(partnerLastCollectionRemarkIds);
3560
 
3416
 
-
 
3417
            Map<Integer, PartnerCollectionRemark> rbmEscalatedRemarksMap = partnerCollectionRemarks.stream().filter(x -> x.getRemark().equals(CollectionRemark.COLLECTION_PLAN)).collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
-
 
3418
            Map<Integer, PartnerCollectionRemark> salesEscalatedRemarksMap = partnerCollectionRemarks.stream().filter(x -> x.getRemark().equals(CollectionRemark.SALES_ESCALATION)).collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
-
 
3419
 
-
 
3420
 
3561
            if (!partnerCollectionRemarksMap.isEmpty()) {
3421
            if (!rbmEscalatedRemarksMap.isEmpty()) {
-
 
3422
                //
3562
                for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService.getAuthUserPartnerIdMapping().entrySet()) {
3423
                for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService.getAuthUserPartnerIdMappingByCategoryIds(Arrays.asList(ProfitMandiConstants.TICKET_CATEGORY_RBM), true).entrySet()) {
-
 
3424
                    List<PartnerCollectionRemark> filteredRows = storeGuyEntry.getValue().stream()
3563
                    List<PartnerCollectionRemark> filteredRows = storeGuyEntry.getValue().stream().map(x -> partnerCollectionRemarksMap.get(x)).filter(x -> x != null).collect(Collectors.toList());
3425
                            .map(x -> rbmEscalatedRemarksMap.get(x)).filter(x -> x != null).collect(Collectors.toList());
3564
                    String subject = "UNCONTACTABLE PARTNERS";
3426
                    String subject = "Partners escalated to RBM-L2";
3565
                    String messageText = this.getMessageForUncontacblePartner(filteredRows);
3427
                    String messageText = this.getMessageForRBMEscalatedPartners(filteredRows);
-
 
3428
 
-
 
3429
                    MimeMessage message = mailSender.createMimeMessage();
-
 
3430
                    MimeMessageHelper helper = new MimeMessageHelper(message, true);
-
 
3431
                    String[] email = new String[]{storeGuyEntry.getKey()};
-
 
3432
 
-
 
3433
                    helper.setSubject(subject);
-
 
3434
                    helper.setText(messageText, true);
-
 
3435
                    helper.setTo(email);
-
 
3436
                    InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smartdukaan Alerts");
-
 
3437
                    helper.setFrom(senderAddress);
-
 
3438
                    mailSender.send(message);
-
 
3439
 
-
 
3440
                    LOGGER.info("filteredRows {}", filteredRows);
-
 
3441
 
-
 
3442
                }
-
 
3443
            }
-
 
3444
            if (!salesEscalatedRemarksMap.isEmpty()) {
-
 
3445
                //
-
 
3446
                for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService.getAuthUserPartnerIdMappingByCategoryIds(Arrays.asList(ProfitMandiConstants.TICKET_CATEGORY_SALES, ProfitMandiConstants.TICKET_CATEGORY_RBM), true).entrySet()) {
-
 
3447
                    List<PartnerCollectionRemark> filteredRows = storeGuyEntry.getValue().stream()
-
 
3448
                            .map(x -> salesEscalatedRemarksMap.get(x)).filter(x -> x != null).collect(Collectors.toList());
-
 
3449
                    String subject = "Partners escalated to Sales";
-
 
3450
                    String messageText = this.getMessageForSalesEscalatedPartners(filteredRows);
3566
 
3451
 
3567
                    MimeMessage message = mailSender.createMimeMessage();
3452
                    MimeMessage message = mailSender.createMimeMessage();
3568
                    MimeMessageHelper helper = new MimeMessageHelper(message, true);
3453
                    MimeMessageHelper helper = new MimeMessageHelper(message, true);
3569
                    String[] email = new String[]{storeGuyEntry.getKey()};
3454
                    String[] email = new String[]{storeGuyEntry.getKey()};
3570
 
3455