Subversion Repositories SmartDukaan

Rev

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

Rev 29252 Rev 29308
Line 37... Line 37...
37
import org.apache.http.entity.StringEntity;
37
import org.apache.http.entity.StringEntity;
38
import org.apache.http.impl.client.CloseableHttpClient;
38
import org.apache.http.impl.client.CloseableHttpClient;
39
import org.apache.http.impl.client.HttpClients;
39
import org.apache.http.impl.client.HttpClients;
40
import org.apache.logging.log4j.LogManager;
40
import org.apache.logging.log4j.LogManager;
41
import org.apache.logging.log4j.Logger;
41
import org.apache.logging.log4j.Logger;
-
 
42
import org.json.JSONArray;
42
import org.json.JSONObject;
43
import org.json.JSONObject;
43
import org.springframework.beans.factory.annotation.Autowired;
44
import org.springframework.beans.factory.annotation.Autowired;
44
import org.springframework.beans.factory.annotation.Qualifier;
45
import org.springframework.beans.factory.annotation.Qualifier;
45
import org.springframework.beans.factory.annotation.Value;
46
import org.springframework.beans.factory.annotation.Value;
46
import org.springframework.core.io.ByteArrayResource;
47
import org.springframework.core.io.ByteArrayResource;
Line 68... Line 69...
68
import com.spice.profitmandi.common.util.FileUtil;
69
import com.spice.profitmandi.common.util.FileUtil;
69
import com.spice.profitmandi.common.util.FormattingUtils;
70
import com.spice.profitmandi.common.util.FormattingUtils;
70
import com.spice.profitmandi.common.util.PdfUtils;
71
import com.spice.profitmandi.common.util.PdfUtils;
71
import com.spice.profitmandi.common.util.Utils;
72
import com.spice.profitmandi.common.util.Utils;
72
import com.spice.profitmandi.common.util.Utils.Attachment;
73
import com.spice.profitmandi.common.util.Utils.Attachment;
-
 
74
import com.spice.profitmandi.common.web.client.RestClient;
73
import com.spice.profitmandi.dao.Interface.Campaign;
75
import com.spice.profitmandi.dao.Interface.Campaign;
74
import com.spice.profitmandi.dao.entity.auth.AuthUser;
76
import com.spice.profitmandi.dao.entity.auth.AuthUser;
75
import com.spice.profitmandi.dao.entity.catalog.FocusedModel;
77
import com.spice.profitmandi.dao.entity.catalog.FocusedModel;
76
import com.spice.profitmandi.dao.entity.catalog.Item;
78
import com.spice.profitmandi.dao.entity.catalog.Item;
77
import com.spice.profitmandi.dao.entity.catalog.Scheme;
79
import com.spice.profitmandi.dao.entity.catalog.Scheme;
Line 103... Line 105...
103
import com.spice.profitmandi.dao.entity.fofo.RazorPay;
105
import com.spice.profitmandi.dao.entity.fofo.RazorPay;
104
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
106
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
105
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
107
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
106
import com.spice.profitmandi.dao.entity.inventory.SaholicCIS;
108
import com.spice.profitmandi.dao.entity.inventory.SaholicCIS;
107
import com.spice.profitmandi.dao.entity.inventory.SaholicPOItem;
109
import com.spice.profitmandi.dao.entity.inventory.SaholicPOItem;
-
 
110
import com.spice.profitmandi.dao.entity.transaction.Order;
108
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
111
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
109
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
112
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
110
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
113
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
111
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
114
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
112
import com.spice.profitmandi.dao.entity.user.Address;
115
import com.spice.profitmandi.dao.entity.user.Address;
Line 193... Line 196...
193
import com.spice.profitmandi.service.transaction.TransactionService;
196
import com.spice.profitmandi.service.transaction.TransactionService;
194
import com.spice.profitmandi.service.user.RetailerService;
197
import com.spice.profitmandi.service.user.RetailerService;
195
import com.spice.profitmandi.service.wallet.WalletService;
198
import com.spice.profitmandi.service.wallet.WalletService;
196
 
199
 
197
import in.shop2020.model.v1.order.OrderStatus;
200
import in.shop2020.model.v1.order.OrderStatus;
198
import in.shop2020.model.v1.order.WalletReferenceType;;
201
import in.shop2020.model.v1.order.WalletReferenceType;
-
 
202
import okhttp3.OkHttpClient;
-
 
203
import okhttp3.Request;
-
 
204
import okhttp3.Response;;
199
 
205
 
200
@Component
206
@Component
201
@Transactional(rollbackFor = Throwable.class)
207
@Transactional(rollbackFor = Throwable.class)
202
public class ScheduledTasks {
208
public class ScheduledTasks {
203
 
209
 
Line 297... Line 303...
297
	private PartnerTypeChangeRepository partnerTypeChangeRepository;
303
	private PartnerTypeChangeRepository partnerTypeChangeRepository;
298
 
304
 
299
	@Autowired
305
	@Autowired
300
	private SchemeService schemeService;
306
	private SchemeService schemeService;
301
 
307
 
-
 
308
	@Value("${delhivery.tracking.token}")
-
 
309
	private String token;
-
 
310
 
302
	private static final String[] STOCK_AGEING_MAIL_LIST = new String[] { "uday.singh@smartudkaan.com",
311
	private static final String[] STOCK_AGEING_MAIL_LIST = new String[] { "uday.singh@smartudkaan.com",
303
			"mohinder.mutreja@smartdukaan.com", "ankit.bhatia@smartdukaan.com", "tarun.verma@smartdukaan.com",
312
			"mohinder.mutreja@smartdukaan.com", "ankit.bhatia@smartdukaan.com", "tarun.verma@smartdukaan.com",
304
			"kuldeep.kumar@smartdukaan.com", "manish.gupta@smartdukaan.com" };
313
			"kuldeep.kumar@smartdukaan.com", "manish.gupta@smartdukaan.com" };
305
 
314
 
306
	private static final String[] ITEMWISE_PENDING_INDENT_MAIL_LIST = new String[] { "kamini.sharma@smartdukaan.com",
315
	private static final String[] ITEMWISE_PENDING_INDENT_MAIL_LIST = new String[] { "kamini.sharma@smartdukaan.com",
Line 488... Line 497...
488
	private PendingOrderService pendingOrderService;
497
	private PendingOrderService pendingOrderService;
489
 
498
 
490
	@Autowired
499
	@Autowired
491
	private CustomerRepository customerRepository;
500
	private CustomerRepository customerRepository;
492
 
501
 
-
 
502
	@Autowired
-
 
503
	private RestClient restClient;
-
 
504
 
493
	private static final Logger LOGGER = LogManager.getLogger(ScheduledTasks.class);
505
	private static final Logger LOGGER = LogManager.getLogger(ScheduledTasks.class);
494
 
506
 
495
	private String FCM_URL = "https://fcm.googleapis.com/fcm/send";
507
	private String FCM_URL = "https://fcm.googleapis.com/fcm/send";
496
	private String FCM_API_KEY = "AAAASAjNcn4:APA91bG6fWRIgYJI0L9gCjP5ynaXz2hJHYKtD9dfH7Depdv31Nd9APJwhx-OPkAJ1WSz4BGNYG8lHThLFSjDGFxIwUZv241YcAJEGDLgt86mxq9FXJe-yBRu-S0_ZwHqmX-QaVKl5F_A";
508
	private String FCM_API_KEY = "AAAASAjNcn4:APA91bG6fWRIgYJI0L9gCjP5ynaXz2hJHYKtD9dfH7Depdv31Nd9APJwhx-OPkAJ1WSz4BGNYG8lHThLFSjDGFxIwUZv241YcAJEGDLgt86mxq9FXJe-yBRu-S0_ZwHqmX-QaVKl5F_A";
497
 
509
 
Line 2593... Line 2605...
2593
			authUserKeyMap.put(authId, dtrEmailMap.get(email));
2605
			authUserKeyMap.put(authId, dtrEmailMap.get(email));
2594
		}
2606
		}
2595
		LOGGER.info("authUserKeyMap", authUserKeyMap);
2607
		LOGGER.info("authUserKeyMap", authUserKeyMap);
2596
		LOGGER.info("leadsToNotify {}", leadsToNotify);
2608
		LOGGER.info("leadsToNotify {}", leadsToNotify);
2597
 
2609
 
2598
		String templateMessage = "Lead followup for %s %s, %s is due by %s";
2610
		String templateMessage = "Lead followup for %s %s, %s, %s is due by %s";
2599
		for (Lead lead : leadsToNotify) {
2611
		for (Lead lead : leadsToNotify) {
2600
			if (authUserKeyMap.get(lead.getAssignTo()) == null) {
2612
			if (authUserKeyMap.get(lead.getAssignTo()) == null) {
2601
				LOGGER.info("Assignee no longer part of system {}", lead.getAssignTo());
2613
				LOGGER.info("Assignee no longer part of system {}", lead.getAssignTo());
2602
				continue;
2614
				continue;
2603
			}
2615
			}
2604
			String notificationMessage = String.format(templateMessage, lead.getFirstName(), lead.getLastName(),
2616
			String notificationMessage = String.format(templateMessage, lead.getFirstName(), lead.getLastName(),
2605
					lead.getAddress(), leadTimeFormatter.format(lead.getScheduledTimestamp()));
2617
					lead.getAddress(), lead.getLeadMobile(), leadTimeFormatter.format(lead.getScheduledTimestamp()));
2606
			SendNotificationModel sendNotificationModel = new SendNotificationModel();
2618
			SendNotificationModel sendNotificationModel = new SendNotificationModel();
2607
			sendNotificationModel.setCampaignName("Lead Reminder");
2619
			sendNotificationModel.setCampaignName("Lead Reminder");
2608
			sendNotificationModel.setTitle("Leads followup Reminder");
2620
			sendNotificationModel.setTitle("Leads followup Reminder");
2609
			sendNotificationModel.setMessage(notificationMessage);
2621
			sendNotificationModel.setMessage(notificationMessage);
2610
			sendNotificationModel.setType("url");
2622
			sendNotificationModel.setType("url");
Line 2982... Line 2994...
2982
 
2994
 
2983
	public void checkCancellationMargin() throws Exception {
2995
	public void checkCancellationMargin() throws Exception {
2984
		LocalDateTime startDate = LocalDate.of(2021, 4, 1).atStartOfDay();
2996
		LocalDateTime startDate = LocalDate.of(2021, 4, 1).atStartOfDay();
2985
		List<FofoOrder> fofoOrders = fofoOrderRepository.selectCancelledBetweenSaleDate(startDate, LocalDateTime.now());
2997
		List<FofoOrder> fofoOrders = fofoOrderRepository.selectCancelledBetweenSaleDate(startDate, LocalDateTime.now());
2986
		LOGGER.info("Total Orders =  {}", fofoOrders.size());
2998
		LOGGER.info("Total Orders =  {}", fofoOrders.size());
2987
		for(FofoOrder fofoOrder : fofoOrders) {
2999
		for (FofoOrder fofoOrder : fofoOrders) {
-
 
3000
			List<UserWalletHistory> history = userWalletHistoryRepository
2988
			List<UserWalletHistory> history = userWalletHistoryRepository.selectAllByreferenceIdandreferenceType(fofoOrder.getId(), WalletReferenceType.SCHEME_OUT);
3001
					.selectAllByreferenceIdandreferenceType(fofoOrder.getId(), WalletReferenceType.SCHEME_OUT);
2989
			history.addAll(userWalletHistoryRepository.selectAllByreferenceIdandreferenceType(fofoOrder.getId(), WalletReferenceType.ACTIVATION_SCHEME));
3002
			history.addAll(userWalletHistoryRepository.selectAllByreferenceIdandreferenceType(fofoOrder.getId(),
-
 
3003
					WalletReferenceType.ACTIVATION_SCHEME));
2990
			int walletSum = history.stream().mapToInt(x->x.getAmount()).sum();
3004
			int walletSum = history.stream().mapToInt(x -> x.getAmount()).sum();
2991
			if(Math.abs(walletSum) > 1) {
3005
			if (Math.abs(walletSum) > 1) {
2992
				//LOGGER.info("Cancelled invoice  {}, Order Id = {}, = havent rolledback, Value = {}", fofoOrder.getInvoiceNumber(), fofoOrder.getId(), walletSum);
3006
				// LOGGER.info("Cancelled invoice {}, Order Id = {}, = havent rolledback, Value
-
 
3007
				// = {}", fofoOrder.getInvoiceNumber(), fofoOrder.getId(), walletSum);
2993
				List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
3008
				List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
2994
				List<FofoLineItem> flis = fofoLineItemRepository.selectByFofoOrderItemId(fofoOrderItems.get(0).getId());
3009
				List<FofoLineItem> flis = fofoLineItemRepository.selectByFofoOrderItemId(fofoOrderItems.get(0).getId());
2995
				FofoLineItem fli = flis.get(0);
3010
				FofoLineItem fli = flis.get(0);
2996
				if(StringUtils.isEmpty(fli.getSerialNumber())) continue;
3011
				if (StringUtils.isEmpty(fli.getSerialNumber()))
-
 
3012
					continue;
-
 
3013
				List<SchemeInOut> schemeInOuts = schemeInOutRepository
2997
				List<SchemeInOut> schemeInOuts =  schemeInOutRepository.selectByInventoryItemIds(new HashSet<>(Arrays.asList(fli.getInventoryItemId())));
3014
						.selectByInventoryItemIds(new HashSet<>(Arrays.asList(fli.getInventoryItemId())));
2998
				InventoryItem inventoryItem = inventoryItemRepository.selectById(fli.getInventoryItemId());
3015
				InventoryItem inventoryItem = inventoryItemRepository.selectById(fli.getInventoryItemId());
2999
				double schemeSum = schemeInOuts.stream().filter(x->x.getRolledBackTimestamp()==null).mapToDouble(x->x.getAmount()).sum();
3016
				double schemeSum = schemeInOuts.stream().filter(x -> x.getRolledBackTimestamp() == null)
-
 
3017
						.mapToDouble(x -> x.getAmount()).sum();
-
 
3018
				/*
3000
				/*if(inventoryItem.getGoodQuantity()==1) {
3019
				 * if(inventoryItem.getGoodQuantity()==1) {
3001
					LOGGER.info("GoodQty, Serial Number {}, InventoryItem = {}, Billed on {}", inventoryItem.getSerialNumber(), inventoryItem.getId(), inventoryItem.getUpdateTimestamp());
3020
				 * LOGGER.info("GoodQty, Serial Number {}, InventoryItem = {}, Billed on {}",
-
 
3021
				 * inventoryItem.getSerialNumber(), inventoryItem.getId(),
-
 
3022
				 * inventoryItem.getUpdateTimestamp()); } else
3002
				} else if(inventoryItem.getBadQuantity()==1){
3023
				 * if(inventoryItem.getBadQuantity()==1){
3003
					LOGGER.info("Bad Qty, Serial Number {}, InventoryItem = {}, Billed on {}", inventoryItem.getSerialNumber(), inventoryItem.getId(), inventoryItem.getUpdateTimestamp());
3024
				 * LOGGER.info("Bad Qty, Serial Number {}, InventoryItem = {}, Billed on {}",
-
 
3025
				 * inventoryItem.getSerialNumber(), inventoryItem.getId(),
-
 
3026
				 * inventoryItem.getUpdateTimestamp()); } else if
3004
				} else if (inventoryItem.getLastScanType().equals(ScanType.SALE)) {
3027
				 * (inventoryItem.getLastScanType().equals(ScanType.SALE)) { LOGGER.
3005
					LOGGER.info("Problem Sold, Serial Number {}, InventoryItem = {}, Billed on {}", inventoryItem.getSerialNumber(), inventoryItem.getId(), inventoryItem.getUpdateTimestamp());
3028
				 * info("Problem Sold, Serial Number {}, InventoryItem = {}, Billed on {}",
-
 
3029
				 * inventoryItem.getSerialNumber(), inventoryItem.getId(),
-
 
3030
				 * inventoryItem.getUpdateTimestamp()); }
3006
				}*/
3031
				 */
-
 
3032
				if (inventoryItem.getLastScanType().equals(ScanType.SALE)
3007
				if (inventoryItem.getLastScanType().equals(ScanType.SALE) || inventoryItem.getLastScanType().equals(ScanType.SALE_RET)) {
3033
						|| inventoryItem.getLastScanType().equals(ScanType.SALE_RET)) {
-
 
3034
					Map<String, Double> map = schemeInOuts.stream()
-
 
3035
							.collect(
-
 
3036
									Collectors.groupingBy(
-
 
3037
											x -> DateTimeFormatter.ofPattern("yyyyMMddHH")
3008
					Map<String, Double> map = schemeInOuts.stream().collect(Collectors.groupingBy(x -> DateTimeFormatter.ofPattern("yyyyMMddHH").format(x.getCreateTimestamp()) + "- " + x.getSchemeId(), Collectors.summingDouble(x->x.getAmount())));
3038
													.format(x.getCreateTimestamp()) + "- " + x.getSchemeId(),
-
 
3039
											Collectors.summingDouble(x -> x.getAmount())));
3009
					for(Map.Entry<String, Double> entry : map.entrySet()) {
3040
					for (Map.Entry<String, Double> entry : map.entrySet()) {
3010
						LOGGER.info("{} = {}",  entry.getKey(), entry.getValue());
3041
						LOGGER.info("{} = {}", entry.getKey(), entry.getValue());
3011
					}
3042
					}
3012
					LOGGER.info("id- {}, imei- {}, lastScan = {}, Scheme sum - {}", inventoryItem.getId(), inventoryItem.getSerialNumber(), inventoryItem.getLastScanType(), schemeSum);
3043
					LOGGER.info("id- {}, imei- {}, lastScan = {}, Scheme sum - {}", inventoryItem.getId(),
-
 
3044
							inventoryItem.getSerialNumber(), inventoryItem.getLastScanType(), schemeSum);
3013
				}
3045
				}
3014
			}
3046
			}
3015
		}
3047
		}
-
 
3048
 
-
 
3049
	}
-
 
3050
 
-
 
3051
	public void markDelhiveryOrderDelivered() throws ProfitMandiBusinessException, IOException {
-
 
3052
		List<Order> orders = orderRepository.selectOrderByProviderIdAndStatus(ProfitMandiConstants.DELHIVERY_PROVIDERID,
-
 
3053
				OrderStatus.SHIPPED_FROM_WH);
-
 
3054
 
-
 
3055
		LOGGER.info("airwayBill" + orders);
-
 
3056
 
-
 
3057
		if (!orders.isEmpty()) {
-
 
3058
			List<String> airwayBill = orders.stream().map(x -> x.getAirwayBillNumber()).collect(Collectors.toList());
-
 
3059
 
-
 
3060
			LOGGER.info("airwayBill" + airwayBill);
-
 
3061
			String url = "https://track.delhivery.com/api/v1/packages/json/";
-
 
3062
 
-
 
3063
			OkHttpClient client = new OkHttpClient();
-
 
3064
 
-
 
3065
			Request request1 = new Request.Builder()
-
 
3066
					.url(url + "?waybill=" + String.join(",", airwayBill) + "&token=" + token).get().build();
-
 
3067
 
-
 
3068
			LOGGER.info("request1" + request1);
-
 
3069
 
-
 
3070
			Response response = client.newCall(request1).execute();
-
 
3071
 
-
 
3072
			LOGGER.info("jsonbj" + response.body());
-
 
3073
 
-
 
3074
			JSONObject jsonObj = new JSONObject(response.body().string());
-
 
3075
 
-
 
3076
			LOGGER.info("jsonObj" + jsonObj);
-
 
3077
 
-
 
3078
			JSONArray ja_data = jsonObj.getJSONArray("ShipmentData");
-
 
3079
			Set<String> airwaybillStatus = new HashSet<>();
-
 
3080
			for (int i = 0; i < ja_data.length(); i++) {
-
 
3081
				JSONObject jsonObject = ja_data.getJSONObject(i);
-
 
3082
				JSONObject shipment = jsonObject.getJSONObject("Shipment");
-
 
3083
 
-
 
3084
				LOGGER.info("shipment" + shipment);
-
 
3085
				JSONObject statusDescription = shipment.getJSONObject("Status");
-
 
3086
				String awb = shipment.getString("AWB");
-
 
3087
 
-
 
3088
				String status = statusDescription.getString("Status");
-
 
3089
				LOGGER.info("status" + status);
-
 
3090
 
-
 
3091
				LOGGER.info("awb" + awb);
-
 
3092
				if (status.equals("Delivered")) {
-
 
3093
					airwaybillStatus.add(awb);
-
 
3094
				}
-
 
3095
 
-
 
3096
			}
-
 
3097
			if (!airwaybillStatus.isEmpty()) {
-
 
3098
				for (String aws : airwaybillStatus) {
-
 
3099
 
-
 
3100
					List<Order> deliverdOrders = orderRepository.selectByAirwayBillNumber(aws);
-
 
3101
					for (Order dlo : deliverdOrders) {
-
 
3102
						dlo.setStatus(OrderStatus.DELIVERY_SUCCESS);
-
 
3103
						dlo.setStatusDescription("Delivered");
-
 
3104
						dlo.setDeliveryTimestamp(LocalDateTime.now());
-
 
3105
					}
-
 
3106
 
-
 
3107
					SendNotificationModel sendNotificationModel = new SendNotificationModel();
-
 
3108
					sendNotificationModel.setCampaignName("Order Delivered");
-
 
3109
					sendNotificationModel.setTitle("Order Delivered");
-
 
3110
					sendNotificationModel.setMessage(String.format("Dear partner, your SmartDukaan ORDER " + aws
-
 
3111
							+ "has been delivered to you in a safe" + "."));
-
 
3112
					sendNotificationModel.setType("url");
-
 
3113
					sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
-
 
3114
					sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
-
 
3115
					sendNotificationModel.setMessageType(MessageType.notification);
-
 
3116
					int userId = userAccountRepository.selectUserIdByRetailerId(orders.get(0).getRetailerId());
-
 
3117
					sendNotificationModel.setUserIds(Arrays.asList(userId));
-
 
3118
					notificationService.sendNotification(sendNotificationModel);
-
 
3119
 
-
 
3120
				}
-
 
3121
			}
-
 
3122
 
3016
		
3123
		}
3017
	}
3124
	}
3018
 
3125
 
3019
}
3126
}
3020
//2284
3127
//2284
3021
3128