Subversion Repositories SmartDukaan

Rev

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

Rev 25709 Rev 25721
Line 45... Line 45...
45
import org.springframework.transaction.annotation.Transactional;
45
import org.springframework.transaction.annotation.Transactional;
46
 
46
 
47
import com.google.common.collect.Lists;
47
import com.google.common.collect.Lists;
48
import com.google.gson.Gson;
48
import com.google.gson.Gson;
49
import com.google.gson.GsonBuilder;
49
import com.google.gson.GsonBuilder;
-
 
50
import com.spice.profitmandi.common.enumuration.MessageType;
50
import com.spice.profitmandi.common.enumuration.RechargeStatus;
51
import com.spice.profitmandi.common.enumuration.RechargeStatus;
51
import com.spice.profitmandi.common.enumuration.ReporticoProject;
52
import com.spice.profitmandi.common.enumuration.ReporticoProject;
52
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
53
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
53
import com.spice.profitmandi.common.model.CustomRetailer;
54
import com.spice.profitmandi.common.model.CustomRetailer;
-
 
55
import com.spice.profitmandi.common.model.FocusedModelShortageModel;
54
import com.spice.profitmandi.common.model.GstRate;
56
import com.spice.profitmandi.common.model.GstRate;
55
import com.spice.profitmandi.common.model.ProfitMandiConstants;
57
import com.spice.profitmandi.common.model.ProfitMandiConstants;
56
import com.spice.profitmandi.common.model.RechargeCredential;
58
import com.spice.profitmandi.common.model.RechargeCredential;
57
import com.spice.profitmandi.common.services.ReporticoService;
59
import com.spice.profitmandi.common.services.ReporticoService;
58
import com.spice.profitmandi.common.util.FileUtil;
60
import com.spice.profitmandi.common.util.FileUtil;
Line 60... Line 62...
60
import com.spice.profitmandi.common.util.Utils;
62
import com.spice.profitmandi.common.util.Utils;
61
import com.spice.profitmandi.common.util.Utils.Attachment;
63
import com.spice.profitmandi.common.util.Utils.Attachment;
62
import com.spice.profitmandi.dao.Interface.Campaign;
64
import com.spice.profitmandi.dao.Interface.Campaign;
63
import com.spice.profitmandi.dao.convertor.LocalDateTimeJsonConverter;
65
import com.spice.profitmandi.dao.convertor.LocalDateTimeJsonConverter;
64
import com.spice.profitmandi.dao.entity.auth.AuthUser;
66
import com.spice.profitmandi.dao.entity.auth.AuthUser;
-
 
67
import com.spice.profitmandi.dao.entity.catalog.FocusedModel;
65
import com.spice.profitmandi.dao.entity.catalog.Item;
68
import com.spice.profitmandi.dao.entity.catalog.Item;
66
import com.spice.profitmandi.dao.entity.catalog.Scheme;
69
import com.spice.profitmandi.dao.entity.catalog.Scheme;
67
import com.spice.profitmandi.dao.entity.cs.Position;
70
import com.spice.profitmandi.dao.entity.cs.Position;
68
import com.spice.profitmandi.dao.entity.dtr.DailyRecharge;
71
import com.spice.profitmandi.dao.entity.dtr.DailyRecharge;
69
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
72
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
70
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaigns;
73
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaigns;
71
import com.spice.profitmandi.dao.entity.dtr.PushNotifications;
74
import com.spice.profitmandi.dao.entity.dtr.PushNotifications;
72
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
75
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
73
import com.spice.profitmandi.dao.entity.dtr.RechargeProviderCreditWalletHistory;
76
import com.spice.profitmandi.dao.entity.dtr.RechargeProviderCreditWalletHistory;
74
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
77
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
-
 
78
import com.spice.profitmandi.dao.entity.dtr.UserCampaign;
75
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
79
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
76
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
80
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
77
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
81
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
78
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
82
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
79
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
83
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
Line 95... Line 99...
95
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
99
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
96
import com.spice.profitmandi.dao.model.SimpleCampaign;
100
import com.spice.profitmandi.dao.model.SimpleCampaign;
97
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
101
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
98
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
102
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
99
import com.spice.profitmandi.dao.repository.catalog.DeviceRepository;
103
import com.spice.profitmandi.dao.repository.catalog.DeviceRepository;
-
 
104
import com.spice.profitmandi.dao.repository.catalog.FocusedModelRepository;
100
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
105
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
101
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
106
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
102
import com.spice.profitmandi.dao.repository.cs.CsService;
107
import com.spice.profitmandi.dao.repository.cs.CsService;
103
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
108
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
104
import com.spice.profitmandi.dao.repository.dtr.DailyRechargeRepository;
109
import com.spice.profitmandi.dao.repository.dtr.DailyRechargeRepository;
Line 109... Line 114...
109
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderCreditWalletHistoryRepository;
114
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderCreditWalletHistoryRepository;
110
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderRepository;
115
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderRepository;
111
import com.spice.profitmandi.dao.repository.dtr.RechargeTransactionRepository;
116
import com.spice.profitmandi.dao.repository.dtr.RechargeTransactionRepository;
112
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
117
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
113
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
118
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
-
 
119
import com.spice.profitmandi.dao.repository.dtr.UserCampaignRepository;
-
 
120
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
114
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
121
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
115
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
122
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
116
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
123
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
117
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
124
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
118
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
125
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
Line 126... Line 133...
126
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
133
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
127
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
134
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
128
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
135
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
129
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
136
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
130
import com.spice.profitmandi.dao.repository.user.AddressRepository;
137
import com.spice.profitmandi.dao.repository.user.AddressRepository;
-
 
138
import com.spice.profitmandi.dao.repository.user.UserRepository;
131
import com.spice.profitmandi.service.PartnerInvestmentService;
139
import com.spice.profitmandi.service.PartnerInvestmentService;
132
import com.spice.profitmandi.service.integrations.toffee.ToffeeService;
140
import com.spice.profitmandi.service.integrations.toffee.ToffeeService;
133
import com.spice.profitmandi.service.inventory.InventoryService;
141
import com.spice.profitmandi.service.inventory.InventoryService;
134
import com.spice.profitmandi.service.order.OrderService;
142
import com.spice.profitmandi.service.order.OrderService;
135
import com.spice.profitmandi.service.pricing.PriceDropService;
143
import com.spice.profitmandi.service.pricing.PriceDropService;
Line 139... Line 147...
139
import com.spice.profitmandi.service.slab.TargetSlabService;
147
import com.spice.profitmandi.service.slab.TargetSlabService;
140
import com.spice.profitmandi.service.transaction.TransactionService;
148
import com.spice.profitmandi.service.transaction.TransactionService;
141
import com.spice.profitmandi.service.user.RetailerService;
149
import com.spice.profitmandi.service.user.RetailerService;
142
import com.spice.profitmandi.service.wallet.WalletService;
150
import com.spice.profitmandi.service.wallet.WalletService;
143
 
151
 
-
 
152
import in.shop2020.googleadwords.GoogleAdwordsService.getAdwordsAdKeywordByCriterionIdAndAdGroupId_args;
-
 
153
import in.shop2020.model.v1.order.OrderStatus;
144
import in.shop2020.model.v1.order.WalletReferenceType;;
154
import in.shop2020.model.v1.order.WalletReferenceType;
-
 
155
import in.shop2020.model.v1.user.User;;
145
 
156
 
146
@Component
157
@Component
147
@Transactional(rollbackFor = Throwable.class)
158
@Transactional(rollbackFor = Throwable.class)
148
public class ScheduledTasks {
159
public class ScheduledTasks {
149
 
160
 
Line 216... Line 227...
216
			"chaitnaya.vats@smartdukaan.com", "kuldeep.kumar@smartdukaan.com" };
227
			"chaitnaya.vats@smartdukaan.com", "kuldeep.kumar@smartdukaan.com" };
217
 
228
 
218
	private static final String[] ITEMWISE_PENDING_INDENT_MAIL_LIST = new String[] { "kamini.sharma@smartdukaan.com",
229
	private static final String[] ITEMWISE_PENDING_INDENT_MAIL_LIST = new String[] { "kamini.sharma@smartdukaan.com",
219
			"tarun.verma@smartdukaan.com", "chaitnaya.vats@smartdukaan.com", "kuldeep.kumar@smartdukaan.com" };
230
			"tarun.verma@smartdukaan.com", "chaitnaya.vats@smartdukaan.com", "kuldeep.kumar@smartdukaan.com" };
220
 
231
 
-
 
232
	private List<OrderStatus> orderStatusList = Arrays.asList(OrderStatus.SUBMITTED_FOR_PROCESSING);
-
 
233
 
221
	@Autowired
234
	@Autowired
222
	private ReporticoService reporticoService;
235
	private ReporticoService reporticoService;
223
 
236
 
224
	@Autowired
237
	@Autowired
225
	private PartnerInvestmentService partnerInvestmentService;
238
	private PartnerInvestmentService partnerInvestmentService;
Line 335... Line 348...
335
 
348
 
336
	@Autowired
349
	@Autowired
337
	private NotificationCampaignRepository notificationCampaignRepository;
350
	private NotificationCampaignRepository notificationCampaignRepository;
338
 
351
 
339
	@Autowired
352
	@Autowired
-
 
353
	private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
-
 
354
 
-
 
355
	@Autowired
-
 
356
	private FocusedModelRepository focusedModelRepository;
-
 
357
 
-
 
358
	@Autowired
340
	private UserAccountRepository userAccountRepository;
359
	private UserAccountRepository userAccountRepository;
341
 
360
 
-
 
361
	@Autowired
-
 
362
	private UserRepository userRepository;
-
 
363
 
-
 
364
	@Autowired
-
 
365
	private UserCampaignRepository userCampaignRepository;
-
 
366
 
-
 
367
	@Autowired
-
 
368
	private Gson gson;
-
 
369
 
342
	private static final Logger LOGGER = LogManager.getLogger(ScheduledTasks.class);
370
	private static final Logger LOGGER = LogManager.getLogger(ScheduledTasks.class);
343
 
371
 
344
	private String FCM_URL = "https://fcm.googleapis.com/fcm/send";
372
	private String FCM_URL = "https://fcm.googleapis.com/fcm/send";
345
	private String FCM_API_KEY = "AAAASAjNcn4:APA91bG6fWRIgYJI0L9gCjP5ynaXz2hJHYKtD9dfH7Depdv31Nd9APJwhx-OPkAJ1WSz4BGNYG8lHThLFSjDGFxIwUZv241YcAJEGDLgt86mxq9FXJe-yBRu-S0_ZwHqmX-QaVKl5F_A";
373
	private String FCM_API_KEY = "AAAASAjNcn4:APA91bG6fWRIgYJI0L9gCjP5ynaXz2hJHYKtD9dfH7Depdv31Nd9APJwhx-OPkAJ1WSz4BGNYG8lHThLFSjDGFxIwUZv241YcAJEGDLgt86mxq9FXJe-yBRu-S0_ZwHqmX-QaVKl5F_A";
346
 
374
 
Line 1545... Line 1573...
1545
					System.out.printf("Amount %f,SchemeId %d,Reason %s\n", sio.getAmount(), sio.getSchemeId(),
1573
					System.out.printf("Amount %f,SchemeId %d,Reason %s\n", sio.getAmount(), sio.getSchemeId(),
1546
							rollbackReason);
1574
							rollbackReason);
1547
				}
1575
				}
1548
			}
1576
			}
1549
		}
1577
		}
1550
		//throw new Exception();
1578
		// throw new Exception();
-
 
1579
	}
-
 
1580
 
-
 
1581
	public void checkfocusedModelInPartnerStock() throws Exception {
-
 
1582
 
-
 
1583
		List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive()).map(x -> x.getId())
-
 
1584
				.collect(Collectors.toList());
-
 
1585
		Map<Integer, List<FocusedModelShortageModel>> focusedModelShortageReportMap = new HashMap<>();
-
 
1586
		for (Integer fofoId : fofoIds) {
-
 
1587
			if (!focusedModelShortageReportMap.containsKey(fofoId)) {
-
 
1588
				focusedModelShortageReportMap.put(fofoId, new ArrayList<>());
-
 
1589
			}
-
 
1590
			CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
-
 
1591
			Map<Integer, Integer> processingOrderMap = null;
-
 
1592
			Map<Integer, Integer> catalogIdAndQtyMap = null;
-
 
1593
			Map<Integer, Integer> grnPendingOrdersMap = null;
-
 
1594
 
-
 
1595
			Map<Integer, Integer> currentInventorySnapshot = currentInventorySnapshotRepository.selectByFofoId(fofoId)
-
 
1596
					.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getAvailability()));
-
 
1597
 
-
 
1598
			if (!currentInventorySnapshot.isEmpty()) {
-
 
1599
				catalogIdAndQtyMap = itemRepository.selectByIds(currentInventorySnapshot.keySet()).stream()
-
 
1600
						.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
-
 
1601
								Collectors.summingInt(x -> currentInventorySnapshot.get(x.getId()))));
-
 
1602
 
-
 
1603
			}
-
 
1604
 
-
 
1605
			Map<Integer, Integer> grnPendingOrders = orderRepository.selectPendingGrnOrders(fofoId).stream()
-
 
1606
					.collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
-
 
1607
							Collectors.summingInt(x -> x.getLineItem().getQuantity())));
-
 
1608
			if (!grnPendingOrders.isEmpty()) {
-
 
1609
				grnPendingOrdersMap = itemRepository.selectByIds(grnPendingOrders.keySet()).stream()
-
 
1610
						.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
-
 
1611
								Collectors.summingInt(x -> grnPendingOrders.get(x.getId()))));
-
 
1612
 
-
 
1613
			}
-
 
1614
 
-
 
1615
			Map<Integer, Integer> processingOrder = orderRepository.selectOrders(fofoId, orderStatusList).stream()
-
 
1616
					.collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
-
 
1617
							Collectors.summingInt(x -> x.getLineItem().getQuantity())));
-
 
1618
			if (!processingOrder.isEmpty()) {
-
 
1619
				processingOrderMap = itemRepository.selectByIds(processingOrder.keySet()).stream()
-
 
1620
						.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
-
 
1621
								Collectors.summingInt(x -> processingOrder.get(x.getId()))));
-
 
1622
 
-
 
1623
			}
-
 
1624
 
-
 
1625
			Map<Integer, Integer> focusedCatalogIdAndQtyMap = focusedModelRepository.selectAll().stream()
-
 
1626
					.collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getMinimumQty()));
-
 
1627
			LOGGER.info("focusedCatalogIdAndQtyMap" + focusedCatalogIdAndQtyMap);
-
 
1628
 
-
 
1629
			for (Map.Entry<Integer, Integer> entry : focusedCatalogIdAndQtyMap.entrySet()) {
-
 
1630
				int inStockQty = 0;
-
 
1631
				int processingQty = 0;
-
 
1632
				int grnPendingQty = 0;
-
 
1633
				if (processingOrderMap != null) {
-
 
1634
					processingQty = (processingOrderMap.get(entry.getKey()) == null) ? 0
-
 
1635
							: processingOrderMap.get(entry.getKey());
-
 
1636
 
-
 
1637
				}
-
 
1638
				if (grnPendingOrdersMap != null) {
-
 
1639
					grnPendingQty = (grnPendingOrdersMap.get(entry.getKey()) == null) ? 0
-
 
1640
							: grnPendingOrdersMap.get(entry.getKey());
-
 
1641
 
-
 
1642
				}
-
 
1643
				if (catalogIdAndQtyMap != null) {
-
 
1644
					inStockQty = (catalogIdAndQtyMap.get(entry.getKey()) == null) ? 0
-
 
1645
							: catalogIdAndQtyMap.get(entry.getKey());
-
 
1646
 
-
 
1647
				}
-
 
1648
				int totalQty = processingQty + grnPendingQty + inStockQty;
-
 
1649
 
-
 
1650
				if (totalQty < entry.getValue()) {
-
 
1651
 
-
 
1652
					int shortageQty = entry.getValue() - totalQty;
-
 
1653
					List<Item> item = itemRepository.selectAllByCatalogItemId(entry.getKey());
-
 
1654
 
-
 
1655
					FocusedModelShortageModel fm = new FocusedModelShortageModel();
-
 
1656
					fm.setFofoId(fofoId);
-
 
1657
					fm.setStoreName(customRetailer.getBusinessName());
-
 
1658
 
-
 
1659
					fm.setItemName(item.get(0).getBrand() + item.get(0).getModelNumber() + item.get(0).getModelName());
-
 
1660
					fm.setShortageQty(shortageQty);
-
 
1661
 
-
 
1662
					focusedModelShortageReportMap.get(fofoId).add(fm);
-
 
1663
				}
-
 
1664
 
-
 
1665
			}
-
 
1666
			List<FocusedModelShortageModel> focusedModelShortageModel = focusedModelShortageReportMap.get(fofoId);
-
 
1667
 
-
 
1668
			if (!focusedModelShortageModel.isEmpty()) {
-
 
1669
				String subject = "Stock Alert";
-
 
1670
				String messageText = this.getMessage(focusedModelShortageModel);
-
 
1671
 
-
 
1672
				this.sendMailWithAttachments(subject, messageText, customRetailer.getEmail());
-
 
1673
				String notificationMessage = this.getNotificationMessage(focusedModelShortageModel);
-
 
1674
 
-
 
1675
				LOGGER.info("notificationMessage" + notificationMessage);
-
 
1676
				SimpleCampaignParams scp = new SimpleCampaignParams();
-
 
1677
 
-
 
1678
				scp.setTitle("Alert");
-
 
1679
				scp.setType("url");
-
 
1680
				scp.setUrl("/pages/home/notifications");
-
 
1681
				scp.setMessage(notificationMessage);
-
 
1682
				scp.setExpireTimestamp(LocalDateTime.now().plusDays(2));
-
 
1683
				SimpleCampaign sc = new SimpleCampaign(scp);
-
 
1684
				sc.setSimpleCampaignParams(scp);
-
 
1685
				LOGGER.info("scp" + scp);
-
 
1686
				NotificationCampaign nc = new NotificationCampaign();
-
 
1687
				nc.setName("Stock Alert");
-
 
1688
				nc.setImplementationType("SimpleCampaign");
-
 
1689
				nc.setImplementationParams(gson.toJson(scp));
-
 
1690
				nc.setCreatedTimestamp(LocalDateTime.now());
-
 
1691
				nc.setMessageType(MessageType.notification);
-
 
1692
				notificationCampaignRepository.persist(nc);
-
 
1693
				LOGGER.info("nc" + nc);
-
 
1694
				LOGGER.info("fofoID" + fofoId);
-
 
1695
				int userId = userAccountRepository.selectUserIdByRetailerId(fofoId);
-
 
1696
				LOGGER.info("userId" + userId);
-
 
1697
 
-
 
1698
				UserCampaign uc = new UserCampaign();
-
 
1699
				uc.setCampaignId(nc.getId());
-
 
1700
				uc.setUserId(userId);
-
 
1701
				uc.setPushTimestamp(LocalDateTime.now());
-
 
1702
				userCampaignRepository.persist(uc);
-
 
1703
				List<Device> devices = deviceRepository.selectByUserIdAndModifiedTimestamp(userId,
-
 
1704
						LocalDateTime.now().minusMonths(3), LocalDateTime.now());
-
 
1705
				pushNotification(nc.getId(), devices);
-
 
1706
 
-
 
1707
			}
-
 
1708
 
-
 
1709
		}
-
 
1710
 
-
 
1711
		String fileName = "Stock Alert-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
-
 
1712
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
-
 
1713
		Map<String, List<List<? extends Serializable>>> emailRowsMap = new HashMap<>();
-
 
1714
 
-
 
1715
		focusedModelShortageReportMap.entrySet().forEach(x -> {
-
 
1716
			storeGuyMap.entrySet().forEach(y -> {
-
 
1717
 
-
 
1718
				if (y.getValue().contains(x.getKey())) {
-
 
1719
					if (!emailRowsMap.containsKey(y.getKey())) {
-
 
1720
						emailRowsMap.put(y.getKey(), new ArrayList<>());
-
 
1721
					}
-
 
1722
					List<List<? extends Serializable>> fms = x.getValue().stream().map(
-
 
1723
							r -> Arrays.asList(r.getFofoId(), r.getStoreName(), r.getItemName(), r.getShortageQty()))
-
 
1724
							.collect(Collectors.toList());
-
 
1725
					emailRowsMap.get(y.getKey()).addAll(fms);
-
 
1726
 
-
 
1727
				}
-
 
1728
 
-
 
1729
			});
-
 
1730
 
-
 
1731
		});
-
 
1732
 
-
 
1733
		List<String> headers = Arrays.asList("Partner Id", "Partner Name", "Model Name", "Shortage Qty");
-
 
1734
		emailRowsMap.entrySet().forEach(e -> {
-
 
1735
 
-
 
1736
			ByteArrayOutputStream baos = null;
-
 
1737
			try {
-
 
1738
				baos = FileUtil.getCSVByteStream(headers, e.getValue());
-
 
1739
			} catch (Exception e2) {
-
 
1740
				// TODO Auto-generated catch block
-
 
1741
				e2.printStackTrace();
-
 
1742
			}
-
 
1743
			String[] sendToArray = new String[] { e.getKey() };
-
 
1744
			try {
-
 
1745
 
-
 
1746
				LOGGER.info("email" + e.getKey());
-
 
1747
				LOGGER.info("list" + e.getValue());
-
 
1748
 
-
 
1749
				Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Stock Alert", "PFA", fileName,
-
 
1750
						new ByteArrayResource(baos.toByteArray()));
-
 
1751
			} catch (Exception e1) {
-
 
1752
				// TODO Auto-generated catch block
-
 
1753
				e1.printStackTrace();
-
 
1754
			}
-
 
1755
 
-
 
1756
		});
-
 
1757
 
-
 
1758
	}
-
 
1759
 
-
 
1760
	private String getNotificationMessage(List<FocusedModelShortageModel> focusedModelShortageModel) {
-
 
1761
		StringBuilder sb = new StringBuilder();
-
 
1762
		sb.append("Focused Model Shortage in Your Stock : \n");
-
 
1763
		for (FocusedModelShortageModel entry : focusedModelShortageModel) {
-
 
1764
 
-
 
1765
			sb.append(entry.getItemName() + "-" + entry.getShortageQty());
-
 
1766
			sb.append(String.format("%n", ""));
-
 
1767
		}
-
 
1768
		return sb.toString();
1551
	}
1769
	}
-
 
1770
 
-
 
1771
	public void pushNotification(int cid, List<Device> devices) {
-
 
1772
		for (Device device : devices) {
-
 
1773
			PushNotifications pn = new PushNotifications();
-
 
1774
			pn.setNotificationCampaignid(cid);
-
 
1775
			pn.setDeviceId(device.getId());
-
 
1776
			pn.setUserId(device.getUser_id());
-
 
1777
			pushNotificationRepository.persist(pn);
-
 
1778
		}
-
 
1779
 
-
 
1780
	}
-
 
1781
 
-
 
1782
	private void sendMailWithAttachments(String subject, String messageText, String email) throws Exception {
-
 
1783
		MimeMessage message = mailSender.createMimeMessage();
-
 
1784
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
-
 
1785
 
-
 
1786
		helper.setSubject(subject);
-
 
1787
		helper.setText(messageText, true);
-
 
1788
		helper.setTo(email);
-
 
1789
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "ProfitMandi Admin");
-
 
1790
		helper.setFrom(senderAddress);
-
 
1791
		mailSender.send(message);
-
 
1792
 
-
 
1793
	}
-
 
1794
 
-
 
1795
	private String getMessage(List<FocusedModelShortageModel> focusedModelShortageModel) {
-
 
1796
		StringBuilder sb = new StringBuilder();
-
 
1797
		sb.append("<html><body><p>Alert</p><p>Focused Model Shortage in Your Stock:-</p>"
-
 
1798
				+ "<br/><table style='border:1px solid black ;padding: 5px';>");
-
 
1799
		sb.append("<tbody>\n" + "	    				<tr>\n"
-
 
1800
				+ "	    					<th style='border:1px solid black;padding: 5px'>Item</th>\n"
-
 
1801
				+ "	    					<th style='border:1px solid black;padding: 5px'>Shortage Qty</th>\n"
-
 
1802
				+ "	    				</tr>");
-
 
1803
		for (FocusedModelShortageModel entry : focusedModelShortageModel) {
-
 
1804
 
-
 
1805
			sb.append("<tr>");
-
 
1806
			sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getItemName() + "</td>");
-
 
1807
 
-
 
1808
			sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getShortageQty() + "</td>");
-
 
1809
 
-
 
1810
			sb.append("</tr>");
-
 
1811
 
-
 
1812
		}
-
 
1813
 
-
 
1814
		sb.append("</tbody></table></body></html>");
-
 
1815
 
-
 
1816
		return sb.toString();
-
 
1817
	}
-
 
1818
 
1552
}
1819
}
1553
1820