Subversion Repositories SmartDukaan

Rev

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

Rev 25033 Rev 25043
Line 3... Line 3...
3
import java.io.IOException;
3
import java.io.IOException;
4
import java.io.InputStream;
4
import java.io.InputStream;
5
import java.io.Serializable;
5
import java.io.Serializable;
6
import java.sql.Timestamp;
6
import java.sql.Timestamp;
7
import java.text.MessageFormat;
7
import java.text.MessageFormat;
8
import java.time.Duration;
-
 
9
import java.time.LocalDate;
8
import java.time.LocalDate;
10
import java.time.LocalDateTime;
9
import java.time.LocalDateTime;
11
import java.time.LocalTime;
10
import java.time.LocalTime;
12
import java.time.ZoneOffset;
11
import java.time.ZoneOffset;
13
import java.time.format.DateTimeFormatter;
12
import java.time.format.DateTimeFormatter;
Line 17... Line 16...
17
import java.util.Collections;
16
import java.util.Collections;
18
import java.util.HashMap;
17
import java.util.HashMap;
19
import java.util.HashSet;
18
import java.util.HashSet;
20
import java.util.List;
19
import java.util.List;
21
import java.util.Map;
20
import java.util.Map;
22
import java.util.Map.Entry;
-
 
23
import java.util.Optional;
21
import java.util.Optional;
24
import java.util.Set;
22
import java.util.Set;
25
import java.util.stream.Collectors;
23
import java.util.stream.Collectors;
26
 
24
 
27
import javax.mail.MessagingException;
25
import javax.mail.MessagingException;
Line 55... Line 53...
55
import com.spice.profitmandi.common.services.ReporticoService;
53
import com.spice.profitmandi.common.services.ReporticoService;
56
import com.spice.profitmandi.common.util.FileUtil;
54
import com.spice.profitmandi.common.util.FileUtil;
57
import com.spice.profitmandi.common.util.FormattingUtils;
55
import com.spice.profitmandi.common.util.FormattingUtils;
58
import com.spice.profitmandi.common.util.Utils;
56
import com.spice.profitmandi.common.util.Utils;
59
import com.spice.profitmandi.common.util.Utils.Attachment;
57
import com.spice.profitmandi.common.util.Utils.Attachment;
60
import com.spice.profitmandi.dao.entity.auth.AuthUser;
-
 
61
import com.spice.profitmandi.dao.entity.catalog.Scheme;
58
import com.spice.profitmandi.dao.entity.catalog.Scheme;
62
import com.spice.profitmandi.dao.entity.cs.Ticket;
-
 
63
import com.spice.profitmandi.dao.entity.cs.TicketAssigned;
-
 
64
import com.spice.profitmandi.dao.entity.dtr.DailyRecharge;
59
import com.spice.profitmandi.dao.entity.dtr.DailyRecharge;
65
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaigns;
60
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaigns;
66
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
61
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
67
import com.spice.profitmandi.dao.entity.dtr.RechargeProviderCreditWalletHistory;
62
import com.spice.profitmandi.dao.entity.dtr.RechargeProviderCreditWalletHistory;
68
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
63
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
69
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
-
 
70
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
64
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
71
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
65
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
72
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
66
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
73
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
67
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
74
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
68
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
Line 82... Line 76...
82
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
76
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
83
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
77
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
84
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
78
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
85
import com.spice.profitmandi.dao.entity.user.Address;
79
import com.spice.profitmandi.dao.entity.user.Address;
86
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
80
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
87
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
-
 
88
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
81
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
89
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
-
 
90
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
82
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
91
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
83
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
92
import com.spice.profitmandi.dao.repository.cs.TicketAssignedRepository;
-
 
93
import com.spice.profitmandi.dao.repository.cs.TicketRepository;
-
 
94
import com.spice.profitmandi.dao.repository.cs.TicketSubCategoryRepository;
-
 
95
import com.spice.profitmandi.dao.repository.dtr.DailyRechargeRepository;
84
import com.spice.profitmandi.dao.repository.dtr.DailyRechargeRepository;
96
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
85
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
97
import com.spice.profitmandi.dao.repository.dtr.Mongo;
86
import com.spice.profitmandi.dao.repository.dtr.Mongo;
98
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderCreditWalletHistoryRepository;
87
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderCreditWalletHistoryRepository;
99
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderRepository;
88
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderRepository;
Line 518... Line 507...
518
			}
507
			}
519
		} catch (Exception e) {
508
		} catch (Exception e) {
520
			e.printStackTrace();
509
			e.printStackTrace();
521
			throw e;
510
			throw e;
522
		}
511
		}
-
 
512
		List<UserWalletHistory> uwhs =userWalletHistoryRepository.selectAllByDateType(startDate, endDate, Arrays.asList(WalletReferenceType.SCHEME_IN, WalletReferenceType.SCHEME_OUT));
-
 
513
		System.out.println("Amount\tReference\tReferenceType\tTimestamp\tDescription");
-
 
514
		for(UserWalletHistory uwh : uwhs) {
-
 
515
			System.out.println(String.format("%d\t%d\t%s\t%d\t%s", uwh.getAmount(), uwh.getReference(), uwh.getReferenceType(), uwh.getTimestamp().toString(), uwh.getDescription()));
-
 
516
		}
523
		LOGGER.info("Schemes process successfully.");
517
		LOGGER.info("Schemes process successfully.");
-
 
518
		throw new Exception();
524
	}
519
	}
525
 
520
 
526
	public void processRechargeCashback() throws Throwable {
521
	public void processRechargeCashback() throws Throwable {
527
		LocalDateTime cashbackTime = LocalDateTime.now();
522
		LocalDateTime cashbackTime = LocalDateTime.now();
528
		int referenceId = (int) Timestamp.valueOf(cashbackTime).getTime() / 1000;
523
		int referenceId = (int) Timestamp.valueOf(cashbackTime).getTime() / 1000;
Line 936... Line 931...
936
				rolledbackSios.stream()
931
				rolledbackSios.stream()
937
						.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getReference(), x.getStoreCode(),
932
						.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getReference(), x.getStoreCode(),
938
								x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
933
								x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
939
						.collect(Collectors.toList()));
934
						.collect(Collectors.toList()));
940
 
935
 
941
		Utils.sendMailWithAttachments(googleMailSender,
-
 
942
				new String[] { "amit.gupta@shop2020.in"}, null,
936
		Utils.sendMailWithAttachments(googleMailSender, new String[] { "amit.gupta@shop2020.in" }, null,
943
				"Partner Excess Amount Scheme In", "PFA",
937
				"Partner Excess Amount Scheme In", "PFA",
944
				new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
938
				new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
945
						new Attachment("SchemeInRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
939
						new Attachment("SchemeInRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
946
 
940
 
947
		//throw new Exception();
941
		// throw new Exception();
948
 
942
 
949
	}
943
	}
950
 
944
 
951
	public void dryRunOutSchemeReco() throws Exception {
945
	public void dryRunOutSchemeReco() throws Exception {
952
		List<UserWalletHistory> userWalletHistory = new ArrayList<>();
946
		List<UserWalletHistory> userWalletHistory = new ArrayList<>();
Line 1048... Line 1042...
1048
				rolledbackSios.stream()
1042
				rolledbackSios.stream()
1049
						.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
1043
						.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
1050
								x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
1044
								x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
1051
						.collect(Collectors.toList()));
1045
						.collect(Collectors.toList()));
1052
 
1046
 
1053
		Utils.sendMailWithAttachments(googleMailSender,
-
 
1054
				new String[] { "amit.gupta@shop2020.in"}, null,
1047
		Utils.sendMailWithAttachments(googleMailSender, new String[] { "amit.gupta@shop2020.in" }, null,
1055
				"Partner Excess Amount Scheme Out", "PFA",
1048
				"Partner Excess Amount Scheme Out", "PFA",
1056
				new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
1049
				new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
1057
						new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
1050
						new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
1058
 
1051
 
1059
		//throw new Exception();
1052
		// throw new Exception();
1060
	}
1053
	}
1061
 
1054
 
1062
	public void dryRunSchemeOutReco1() throws Exception {
1055
	public void dryRunSchemeOutReco1() throws Exception {
1063
		List<Integer> references = Arrays.asList(6744, 7347, 8320, 8891, 9124, 9217, 9263, 9379);
1056
		List<Integer> references = Arrays.asList(6744, 7347, 8320, 8891, 9124, 9217, 9263, 9379);
1064
		List<UserWalletHistory> userWalletHistory = new ArrayList<>();
1057
		List<UserWalletHistory> userWalletHistory = new ArrayList<>();
Line 1137... Line 1130...
1137
			throws ProfitMandiBusinessException, MessagingException, IOException {
1130
			throws ProfitMandiBusinessException, MessagingException, IOException {
1138
		LocalDateTime now = LocalDateTime.now();
1131
		LocalDateTime now = LocalDateTime.now();
1139
		LocalDateTime from = LocalDateTime.of(now.getYear(), now.getMonth(), now.getDayOfMonth(), 00, 00);
1132
		LocalDateTime from = LocalDateTime.of(now.getYear(), now.getMonth(), now.getDayOfMonth(), 00, 00);
1140
		Map<Integer, Double> salesByFofoIdMap = new HashMap<>();
1133
		Map<Integer, Double> salesByFofoIdMap = new HashMap<>();
1141
		List<Integer> fofoIds = null;
1134
		List<Integer> fofoIds = null;
1142
		if(fofoIdInt==null) {
1135
		if (fofoIdInt == null) {
1143
			fofoIds = fofoStoreRepository.selectAll().stream().filter(x->x.isActive()).map(x->x.getId()).collect(Collectors.toList());
1136
			fofoIds = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive()).map(x -> x.getId())
-
 
1137
					.collect(Collectors.toList());
1144
		} else {
1138
		} else {
1145
			fofoIds = Arrays.asList(fofoIdInt);
1139
			fofoIds = Arrays.asList(fofoIdInt);
1146
		}
1140
		}
1147
		List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository
1141
		List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository
1148
				.selectAllGeEqAndLeEqStartDateAndEndDate(now);
1142
				.selectAllGeEqAndLeEqStartDateAndEndDate(now);
Line 1172... Line 1166...
1172
			notification.setTitle("Daily Sale Update");
1166
			notification.setTitle("Daily Sale Update");
1173
			if (dailyAverageSale != null && dailyAverageSale.get(fofoId) != null) {
1167
			if (dailyAverageSale != null && dailyAverageSale.get(fofoId) != null) {
1174
				notification.setMessage(String.format("Rs.%.0f till %s. Today's Target is Rs.%.0f", sale,
1168
				notification.setMessage(String.format("Rs.%.0f till %s. Today's Target is Rs.%.0f", sale,
1175
						now.format(timeFormatter), dailyAverageSale.get(fofoId)));
1169
						now.format(timeFormatter), dailyAverageSale.get(fofoId)));
1176
			} else {
1170
			} else {
1177
				notification.setMessage(String.format("Rs.%.0f till %s", sale,
1171
				notification.setMessage(String.format("Rs.%.0f till %s", sale, now.format(timeFormatter)));
1178
						now.format(timeFormatter)));
-
 
1179
			}
1172
			}
1180
			// notification.setMessage("Your sale is "+salesbyfofoId.get(fofoId));
1173
			// notification.setMessage("Your sale is "+salesbyfofoId.get(fofoId));
1181
			notification.setType("url");
1174
			notification.setType("url");
1182
			notification.setUrl("http://app.profitmandi.com/pages/home/notifications");
1175
			notification.setUrl("http://app.profitmandi.com/pages/home/notifications");
1183
			LOGGER.info("UserID" + userAccountRepository.selectUserIdByRetailerId(fofoId));
1176
			LOGGER.info("UserID" + userAccountRepository.selectUserIdByRetailerId(fofoId));
Line 1214... Line 1207...
1214
				+ "	    					<th style='border:1px solid black;padding: 5px'>Partner</th>\n"
1207
				+ "	    					<th style='border:1px solid black;padding: 5px'>Partner</th>\n"
1215
				+ "	    					<th style='border:1px solid black;padding: 5px'>Daily Target</th>\n"
1208
				+ "	    					<th style='border:1px solid black;padding: 5px'>Daily Target</th>\n"
1216
				+ "	    					<th style='border:1px solid black;padding: 5px'>Sale</th>\n"
1209
				+ "	    					<th style='border:1px solid black;padding: 5px'>Sale</th>\n"
1217
				+ "	    				</tr>");
1210
				+ "	    				</tr>");
1218
		for (Integer fofoId : salesByFofoIdMap.keySet()) {
1211
		for (Integer fofoId : salesByFofoIdMap.keySet()) {
1219
			try
1212
			try {
1220
			{
-
 
1221
			String PartnerName=retailerService.getFofoRetailer(fofoId).getBusinessName();
1213
				String PartnerName = retailerService.getFofoRetailer(fofoId).getBusinessName();
1222
			sb.append("<tr>");
1214
				sb.append("<tr>");
1223
			sb.append("<td style='border:1px solid black;padding: 5px'>"
1215
				sb.append("<td style='border:1px solid black;padding: 5px'>" + PartnerName + "</td>");
1224
					+ PartnerName + "</td>");
-
 
1225
			if (dailyTarget != null && dailyTarget.get(fofoId) != null) {
1216
				if (dailyTarget != null && dailyTarget.get(fofoId) != null) {
1226
				sb.append("<td style='border:1px solid black;padding: 5px'>" + dailyTarget.get(fofoId) + "</td>");
1217
					sb.append("<td style='border:1px solid black;padding: 5px'>" + dailyTarget.get(fofoId) + "</td>");
1227
			} else {
1218
				} else {
1228
				sb.append("<td style='border:1px solid black;padding: 5px'>" + 0.0 + "</td>");
1219
					sb.append("<td style='border:1px solid black;padding: 5px'>" + 0.0 + "</td>");
1229
			}
1220
				}
1230
			sb.append("<td style='border:1px solid black;padding: 5px'>" + salesByFofoIdMap.get(fofoId) + "</td>");
1221
				sb.append("<td style='border:1px solid black;padding: 5px'>" + salesByFofoIdMap.get(fofoId) + "</td>");
1231
 
1222
 
1232
			sb.append("</tr>");
1223
				sb.append("</tr>");
1233
			}
-
 
1234
			catch(Exception e)
1224
			} catch (Exception e) {
1235
			{
-
 
1236
				e.printStackTrace();
1225
				e.printStackTrace();
1237
			}
1226
			}
1238
			
1227
 
1239
		}
1228
		}
1240
 
1229
 
1241
		sb.append("</tbody></table></body></html>");
1230
		sb.append("</tbody></table></body></html>");
1242
		return sb.toString();
1231
		return sb.toString();
1243
	}
1232
	}