Subversion Repositories SmartDukaan

Rev

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

Rev 24611 Rev 24615
Line 879... Line 879...
879
		}
879
		}
880
 
880
 
881
	}
881
	}
882
 
882
 
883
	public void dryRunSchemeReco() throws Exception {
883
	public void dryRunSchemeReco() throws Exception {
-
 
884
		Set<String> serialSchemeConsidered = new HashSet<>();
884
		List<UserWalletHistory> userWalletHistory = new ArrayList<>();
885
		List<UserWalletHistory> userWalletHistory = new ArrayList<>();
885
		List<SchemeInOut> rolledbackSios = new ArrayList<>();
886
		List<SchemeInOut> rolledbackSios = new ArrayList<>();
886
		Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
887
		Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
887
				.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
888
				.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
888
		Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
889
		Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
Line 905... Line 906...
905
								new ArrayList<String>(inventorySerialNumberMap.values()))
906
								new ArrayList<String>(inventorySerialNumberMap.values()))
906
						.stream().filter(x -> schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
907
						.stream().filter(x -> schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
907
						.collect(Collectors.toList());
908
						.collect(Collectors.toList());
908
				LOGGER.info("Found {} duplicate schemeouts for Orderid {}", sios.size(), fofoOrder.getId());
909
				LOGGER.info("Found {} duplicate schemeouts for Orderid {}", sios.size(), fofoOrder.getId());
909
				UserWalletHistory uwh = new UserWalletHistory();
910
				UserWalletHistory uwh = new UserWalletHistory();
-
 
911
				List<String> toBerolledBack = new ArrayList<>();
910
				for (SchemeInOut sio : sios) {
912
				for (SchemeInOut sio : sios) {
911
					String serialNumber = inventoryItemRepository.selectById(sio.getInventoryItemId())
913
					String serialNumber = inventoryItemRepository.selectById(sio.getInventoryItemId())
912
							.getSerialNumber();
914
							.getSerialNumber();
-
 
915
					if (!serialSchemeConsidered.contains(serialNumber + "," + sio.getSchemeId())) {
-
 
916
						serialSchemeConsidered.add(serialNumber + "," + sio.getSchemeId());
-
 
917
						continue;
-
 
918
					}
913
					sio.setRolledBackTimestamp(LocalDateTime.now());
919
					sio.setRolledBackTimestamp(LocalDateTime.now());
914
					amountToRollback += sio.getAmount();
920
					amountToRollback += sio.getAmount();
915
					sio.setSchemeType(SchemeType.OUT);
921
					sio.setSchemeType(SchemeType.OUT);
916
					sio.setSerialNumber(serialNumber);
922
					sio.setSerialNumber(serialNumber);
917
					sio.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
923
					sio.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
918
					rolledbackSios.add(sio);
924
					rolledbackSios.add(sio);
919
				}
925
				}
-
 
926
				if (amountToRollback > 0) {
920
				uwh.setAmount(Math.round(amountToRollback));
927
					uwh.setAmount(Math.round(amountToRollback));
921
				uwh.setDescription(description);
928
					uwh.setDescription(description);
922
				uwh.setTimestamp(LocalDateTime.now());
929
					uwh.setTimestamp(LocalDateTime.now());
923
				uwh.setReferenceType(WalletReferenceType.SCHEME_OUT);
930
					uwh.setReferenceType(WalletReferenceType.SCHEME_OUT);
924
				uwh.setReference(fofoOrder.getId());
931
					uwh.setReference(fofoOrder.getId());
925
				uwh.setWalletId(userWalletMap.get(fofoOrder.getFofoId()));
932
					uwh.setWalletId(userWalletMap.get(fofoOrder.getFofoId()));
926
				uwh.setFofoId(fofoOrder.getFofoId());
933
					uwh.setFofoId(fofoOrder.getFofoId());
927
				uwh.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
934
					uwh.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
928
				userWalletHistory.add(uwh);
935
					userWalletHistory.add(uwh);
-
 
936
				}
929
			}
937
			}
930
		});
938
		});
931
 
939
 
932
		ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
940
		ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
933
				Arrays.asList("User Id", "Reference Type", "Reference", "Amount", "Description", "Timestamp"),
941
				Arrays.asList("User Id", "Store Code", "Reference Type", "Reference", "Amount", "Description",
-
 
942
						"Timestamp"),
-
 
943
				userWalletHistory.stream()
934
				userWalletHistory.stream().map(x -> Arrays.asList(x.getWalletId(), x.getReferenceType(),
944
						.map(x -> Arrays.asList(x.getWalletId(), x.getStoreCode(), x.getReferenceType(),
935
						x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
945
								x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
936
						.collect(Collectors.toList()));
946
						.collect(Collectors.toList()));
937
 
947
 
938
		ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
948
		ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
939
				Arrays.asList("Scheme ID", "SchemeType", "Store Code", "Serial Number", "Amount", "Created",
949
				Arrays.asList("Scheme ID", "SchemeType", "Store Code", "Serial Number", "Amount", "Created",
940
						"Rolledback"),
950
						"Rolledback"),
Line 946... Line 956...
946
		Utils.sendMailWithAttachments(googleMailSender, new String[] { "amit.gupta@shop2020.in" }, null,
956
		Utils.sendMailWithAttachments(googleMailSender, new String[] { "amit.gupta@shop2020.in" }, null,
947
				"Partner Excess Amount", "PFA",
957
				"Partner Excess Amount", "PFA",
948
				new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
958
				new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
949
						new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
959
						new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
950
	}
960
	}
951
	
961
 
952
	public void dryRunSchemeOutReco1() throws Exception {
962
	public void dryRunSchemeOutReco1() throws Exception {
953
		List<Integer> references = Arrays.asList(6744,7347, 8320, 8891, 9124, 9217, 9263, 9379);
963
		List<Integer> references = Arrays.asList(6744, 7347, 8320, 8891, 9124, 9217, 9263, 9379);
954
		List<UserWalletHistory> userWalletHistory = new ArrayList<>();
964
		List<UserWalletHistory> userWalletHistory = new ArrayList<>();
955
		List<SchemeInOut> rolledbackSios = new ArrayList<>();
965
		List<SchemeInOut> rolledbackSios = new ArrayList<>();
956
		Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
966
		Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
957
				.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
967
				.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
958
		Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
968
		Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
959
				.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
969
				.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
960
		references.stream().forEach(reference -> {
970
		references.stream().forEach(reference -> {
961
			FofoOrder fofoOrder = null;
971
			FofoOrder fofoOrder = null;
962
			try {
972
			try {
963
				fofoOrder = fofoOrderRepository.selectByOrderId(reference);
973
				fofoOrder = fofoOrderRepository.selectByOrderId(reference);
964
			} catch(Exception e) {
974
			} catch (Exception e) {
965
				
975
 
966
			}
976
			}
967
			String description = "Adjustment of Duplicate Scheme for Sale Invoice " + fofoOrder.getInvoiceNumber();
977
			String description = "Adjustment of Duplicate Scheme for Sale Invoice " + fofoOrder.getInvoiceNumber();
968
			Map<Integer, String> inventorySerialNumberMap = new HashMap<>();
978
			Map<Integer, String> inventorySerialNumberMap = new HashMap<>();
969
			float amountToRollback = 0;
979
			float amountToRollback = 0;
970
			List<FofoOrderItem> orderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
980
			List<FofoOrderItem> orderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
971
			orderItems.forEach(x -> {
981
			orderItems.forEach(x -> {
972
				inventorySerialNumberMap.putAll(x.getFofoLineItems().stream().filter(li -> li.getSerialNumber() != null)
982
				inventorySerialNumberMap.putAll(x.getFofoLineItems().stream().filter(li -> li.getSerialNumber() != null)
973
						.collect(Collectors.toMap(FofoLineItem::getInventoryItemId, FofoLineItem::getSerialNumber)));
983
						.collect(Collectors.toMap(FofoLineItem::getInventoryItemId, FofoLineItem::getSerialNumber)));
974
			});
984
			});
975
			if (inventorySerialNumberMap.size() > 0) {
985
			if (inventorySerialNumberMap.size() > 0) {
976
				List<SchemeInOut> sios = schemeInOutRepository.
986
				List<SchemeInOut> sios = schemeInOutRepository
-
 
987
						.selectByInventoryItemIds(inventorySerialNumberMap.keySet()).stream()
977
						selectByInventoryItemIds(inventorySerialNumberMap.keySet()).stream().filter(x -> schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
988
						.filter(x -> schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
978
						.collect(Collectors.toList());
989
						.collect(Collectors.toList());
979
				LOGGER.info("Found {} duplicate schemeouts for Orderid {}", sios.size(), fofoOrder.getId());
990
				LOGGER.info("Found {} duplicate schemeouts for Orderid {}", sios.size(), fofoOrder.getId());
980
				UserWalletHistory uwh = new UserWalletHistory();
991
				UserWalletHistory uwh = new UserWalletHistory();
-
 
992
				Map<Integer, List<SchemeInOut>> inventoryIdSouts = sios.stream()
981
				Map<Integer, List<SchemeInOut>> inventoryIdSouts = sios.stream().collect(Collectors.groupingBy(SchemeInOut::getInventoryItemId, Collectors.toList()));
993
						.collect(Collectors.groupingBy(SchemeInOut::getInventoryItemId, Collectors.toList()));
982
				for (Map.Entry<Integer, List<SchemeInOut>> inventorySioEntry : inventoryIdSouts.entrySet()) {
994
				for (Map.Entry<Integer, List<SchemeInOut>> inventorySioEntry : inventoryIdSouts.entrySet()) {
983
					List<SchemeInOut> outList = inventorySioEntry.getValue();
995
					List<SchemeInOut> outList = inventorySioEntry.getValue();
984
					if(outList.size()>1) {
996
					if (outList.size() > 1) {
985
						
997
 
986
					}
998
					}
987
				}
999
				}
988
				uwh.setAmount(Math.round(amountToRollback));
1000
				uwh.setAmount(Math.round(amountToRollback));
989
				uwh.setDescription(description);
1001
				uwh.setDescription(description);
990
				uwh.setTimestamp(LocalDateTime.now());
1002
				uwh.setTimestamp(LocalDateTime.now());
Line 994... Line 1006...
994
				uwh.setFofoId(fofoOrder.getFofoId());
1006
				uwh.setFofoId(fofoOrder.getFofoId());
995
				uwh.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
1007
				uwh.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
996
				userWalletHistory.add(uwh);
1008
				userWalletHistory.add(uwh);
997
			}
1009
			}
998
		});
1010
		});
999
		
1011
 
1000
		ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
1012
		ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
1001
				Arrays.asList("User Id", "Reference Type", "Reference", "Amount", "Description", "Timestamp"),
1013
				Arrays.asList("User Id", "Reference Type", "Reference", "Amount", "Description", "Timestamp"),
1002
				userWalletHistory.stream().map(x -> Arrays.asList(x.getWalletId(), x.getReferenceType(),
1014
				userWalletHistory.stream().map(x -> Arrays.asList(x.getWalletId(), x.getReferenceType(),
1003
						x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
1015
						x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
1004
				.collect(Collectors.toList()));
1016
						.collect(Collectors.toList()));
1005
		
1017
 
1006
		ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
1018
		ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
1007
				Arrays.asList("Scheme ID", "SchemeType", "Store Code", "Serial Number", "Amount", "Created",
1019
				Arrays.asList("Scheme ID", "SchemeType", "Store Code", "Serial Number", "Amount", "Created",
1008
						"Rolledback"),
1020
						"Rolledback"),
1009
				rolledbackSios.stream()
1021
				rolledbackSios.stream()
1010
				.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
1022
						.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
1011
						x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
1023
								x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
1012
				.collect(Collectors.toList()));
1024
						.collect(Collectors.toList()));
1013
		
1025
 
1014
		Utils.sendMailWithAttachments(googleMailSender, new String[] { "amit.gupta@shop2020.in" }, null,
1026
		Utils.sendMailWithAttachments(googleMailSender, new String[] { "amit.gupta@shop2020.in" }, null,
1015
				"Partner Excess Amount", "PFA",
1027
				"Partner Excess Amount", "PFA",
1016
				new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
1028
				new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
1017
						new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
1029
						new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
1018
		
1030
 
1019
	}
1031
	}
1020
	
-
 
1021
	
1032
 
1022
}
1033
}
1023
 
1034
 
1024
/*
1035
/*
1025
 * public void processSchemeForModel(String string) { pricingService
1036
 * public void processSchemeForModel(String string) { pricingService
1026
 * 
1037
 *