| 23724 |
amit.gupta |
1 |
package com.smartdukaan.cron.scheduled;
|
| 23723 |
amit.gupta |
2 |
|
| 24121 |
govind |
3 |
import java.io.IOException;
|
| 24807 |
amit.gupta |
4 |
import java.io.Serializable;
|
| 23739 |
amit.gupta |
5 |
import java.sql.Timestamp;
|
| 23724 |
amit.gupta |
6 |
import java.time.LocalDate;
|
|
|
7 |
import java.time.LocalDateTime;
|
| 24256 |
amit.gupta |
8 |
import java.time.LocalTime;
|
| 24653 |
govind |
9 |
import java.time.format.DateTimeFormatter;
|
| 23724 |
amit.gupta |
10 |
import java.time.temporal.ChronoUnit;
|
|
|
11 |
import java.util.ArrayList;
|
|
|
12 |
import java.util.Arrays;
|
| 24627 |
amit.gupta |
13 |
import java.util.Collections;
|
| 23723 |
amit.gupta |
14 |
import java.util.HashMap;
|
| 24241 |
amit.gupta |
15 |
import java.util.HashSet;
|
| 23724 |
amit.gupta |
16 |
import java.util.List;
|
| 23723 |
amit.gupta |
17 |
import java.util.Map;
|
| 24242 |
amit.gupta |
18 |
import java.util.Optional;
|
| 24542 |
amit.gupta |
19 |
import java.util.Set;
|
| 23724 |
amit.gupta |
20 |
import java.util.stream.Collectors;
|
| 23723 |
amit.gupta |
21 |
|
| 24121 |
govind |
22 |
import javax.mail.MessagingException;
|
|
|
23 |
import javax.mail.internet.InternetAddress;
|
|
|
24 |
import javax.mail.internet.MimeMessage;
|
|
|
25 |
|
| 23929 |
amit.gupta |
26 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
| 25598 |
amit.gupta |
27 |
import org.apache.commons.lang.StringUtils;
|
| 25300 |
tejbeer |
28 |
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
29 |
import org.apache.http.client.methods.HttpPost;
|
|
|
30 |
import org.apache.http.entity.StringEntity;
|
|
|
31 |
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
32 |
import org.apache.http.impl.client.HttpClients;
|
| 23755 |
amit.gupta |
33 |
import org.apache.logging.log4j.LogManager;
|
|
|
34 |
import org.apache.logging.log4j.Logger;
|
| 25300 |
tejbeer |
35 |
import org.json.JSONObject;
|
| 23723 |
amit.gupta |
36 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23933 |
amit.gupta |
37 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 23724 |
amit.gupta |
38 |
import org.springframework.beans.factory.annotation.Value;
|
| 23929 |
amit.gupta |
39 |
import org.springframework.core.io.ByteArrayResource;
|
| 24692 |
amit.gupta |
40 |
import org.springframework.core.io.InputStreamSource;
|
| 23929 |
amit.gupta |
41 |
import org.springframework.mail.javamail.JavaMailSender;
|
| 24121 |
govind |
42 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
| 23723 |
amit.gupta |
43 |
import org.springframework.stereotype.Component;
|
| 23724 |
amit.gupta |
44 |
import org.springframework.transaction.annotation.Transactional;
|
| 23723 |
amit.gupta |
45 |
|
| 24542 |
amit.gupta |
46 |
import com.google.common.collect.Lists;
|
| 25300 |
tejbeer |
47 |
import com.google.gson.Gson;
|
|
|
48 |
import com.google.gson.GsonBuilder;
|
| 25721 |
tejbeer |
49 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
| 23724 |
amit.gupta |
50 |
import com.spice.profitmandi.common.enumuration.RechargeStatus;
|
| 24681 |
amit.gupta |
51 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
| 24121 |
govind |
52 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 23929 |
amit.gupta |
53 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 25721 |
tejbeer |
54 |
import com.spice.profitmandi.common.model.FocusedModelShortageModel;
|
| 24542 |
amit.gupta |
55 |
import com.spice.profitmandi.common.model.GstRate;
|
| 25590 |
amit.gupta |
56 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 23724 |
amit.gupta |
57 |
import com.spice.profitmandi.common.model.RechargeCredential;
|
| 25821 |
amit.gupta |
58 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
| 24681 |
amit.gupta |
59 |
import com.spice.profitmandi.common.services.ReporticoService;
|
| 24002 |
amit.gupta |
60 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 23929 |
amit.gupta |
61 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
|
|
62 |
import com.spice.profitmandi.common.util.Utils;
|
| 24592 |
amit.gupta |
63 |
import com.spice.profitmandi.common.util.Utils.Attachment;
|
| 25300 |
tejbeer |
64 |
import com.spice.profitmandi.dao.Interface.Campaign;
|
|
|
65 |
import com.spice.profitmandi.dao.convertor.LocalDateTimeJsonConverter;
|
| 25590 |
amit.gupta |
66 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 25800 |
tejbeer |
67 |
import com.spice.profitmandi.dao.entity.catalog.FocusedModel;
|
| 25609 |
amit.gupta |
68 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 24590 |
amit.gupta |
69 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
| 25590 |
amit.gupta |
70 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
| 26283 |
tejbeer |
71 |
import com.spice.profitmandi.dao.entity.cs.Ticket;
|
| 23724 |
amit.gupta |
72 |
import com.spice.profitmandi.dao.entity.dtr.DailyRecharge;
|
| 25300 |
tejbeer |
73 |
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
|
|
|
74 |
import com.spice.profitmandi.dao.entity.dtr.PushNotifications;
|
| 23724 |
amit.gupta |
75 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
|
|
|
76 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProviderCreditWalletHistory;
|
|
|
77 |
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
|
| 26408 |
amit.gupta |
78 |
import com.spice.profitmandi.dao.entity.fofo.ActivatedImei;
|
| 26283 |
tejbeer |
79 |
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
|
| 24542 |
amit.gupta |
80 |
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
|
| 24590 |
amit.gupta |
81 |
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
|
| 23724 |
amit.gupta |
82 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
| 24542 |
amit.gupta |
83 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
|
| 23929 |
amit.gupta |
84 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 24249 |
amit.gupta |
85 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| 24277 |
amit.gupta |
86 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| 23724 |
amit.gupta |
87 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
| 24242 |
amit.gupta |
88 |
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
|
| 24241 |
amit.gupta |
89 |
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
|
| 25982 |
amit.gupta |
90 |
import com.spice.profitmandi.dao.entity.transaction.HdfcPayment;
|
| 24431 |
amit.gupta |
91 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
| 25609 |
amit.gupta |
92 |
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
|
| 24587 |
amit.gupta |
93 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
| 24580 |
amit.gupta |
94 |
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
|
| 24542 |
amit.gupta |
95 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| 25300 |
tejbeer |
96 |
import com.spice.profitmandi.dao.entity.user.Device;
|
| 25927 |
amit.gupta |
97 |
import com.spice.profitmandi.dao.entity.user.FranchiseeVisit;
|
| 25910 |
amit.gupta |
98 |
import com.spice.profitmandi.dao.entity.user.Lead;
|
| 24250 |
amit.gupta |
99 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
| 25598 |
amit.gupta |
100 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 24242 |
amit.gupta |
101 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
| 25609 |
amit.gupta |
102 |
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
|
| 25982 |
amit.gupta |
103 |
import com.spice.profitmandi.dao.model.AddPaymentRequest;
|
|
|
104 |
import com.spice.profitmandi.dao.model.AddPaymentResponse;
|
| 25300 |
tejbeer |
105 |
import com.spice.profitmandi.dao.model.SimpleCampaign;
|
|
|
106 |
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
|
| 25590 |
amit.gupta |
107 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 25300 |
tejbeer |
108 |
import com.spice.profitmandi.dao.repository.catalog.DeviceRepository;
|
| 25721 |
tejbeer |
109 |
import com.spice.profitmandi.dao.repository.catalog.FocusedModelRepository;
|
| 24249 |
amit.gupta |
110 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 24241 |
amit.gupta |
111 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
| 25590 |
amit.gupta |
112 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
|
|
113 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
| 26283 |
tejbeer |
114 |
import com.spice.profitmandi.dao.repository.cs.TicketRepository;
|
| 23724 |
amit.gupta |
115 |
import com.spice.profitmandi.dao.repository.dtr.DailyRechargeRepository;
|
| 23929 |
amit.gupta |
116 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 25927 |
amit.gupta |
117 |
import com.spice.profitmandi.dao.repository.dtr.FranchiseeActivityRepository;
|
|
|
118 |
import com.spice.profitmandi.dao.repository.dtr.FranchiseeVisitRepository;
|
| 25837 |
amit.gupta |
119 |
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
|
| 25910 |
amit.gupta |
120 |
import com.spice.profitmandi.dao.repository.dtr.LeadRepository;
|
| 24653 |
govind |
121 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 25300 |
tejbeer |
122 |
import com.spice.profitmandi.dao.repository.dtr.NotificationCampaignRepository;
|
|
|
123 |
import com.spice.profitmandi.dao.repository.dtr.PushNotificationRepository;
|
| 23724 |
amit.gupta |
124 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderCreditWalletHistoryRepository;
|
|
|
125 |
import com.spice.profitmandi.dao.repository.dtr.RechargeProviderRepository;
|
|
|
126 |
import com.spice.profitmandi.dao.repository.dtr.RechargeTransactionRepository;
|
| 24542 |
amit.gupta |
127 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
|
| 24669 |
govind |
128 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 25721 |
tejbeer |
129 |
import com.spice.profitmandi.dao.repository.dtr.UserCampaignRepository;
|
| 26408 |
amit.gupta |
130 |
import com.spice.profitmandi.dao.repository.fofo.ActivatedImeiRepository;
|
| 25721 |
tejbeer |
131 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
| 24542 |
amit.gupta |
132 |
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
|
| 24590 |
amit.gupta |
133 |
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
|
| 24542 |
amit.gupta |
134 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
| 23724 |
amit.gupta |
135 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
| 24249 |
amit.gupta |
136 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
| 24277 |
amit.gupta |
137 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| 24174 |
govind |
138 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTargetRepository;
|
| 25503 |
amit.gupta |
139 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
|
| 23724 |
amit.gupta |
140 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
| 24242 |
amit.gupta |
141 |
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
|
| 24241 |
amit.gupta |
142 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
|
| 25982 |
amit.gupta |
143 |
import com.spice.profitmandi.dao.repository.transaction.HdfcPaymentRepository;
|
| 23929 |
amit.gupta |
144 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 25609 |
amit.gupta |
145 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
|
| 24431 |
amit.gupta |
146 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
| 24580 |
amit.gupta |
147 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
|
| 24587 |
amit.gupta |
148 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 24542 |
amit.gupta |
149 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 25721 |
tejbeer |
150 |
import com.spice.profitmandi.dao.repository.user.UserRepository;
|
| 25854 |
amit.gupta |
151 |
import com.spice.profitmandi.service.NotificationService;
|
| 24337 |
amit.gupta |
152 |
import com.spice.profitmandi.service.PartnerInvestmentService;
|
| 25694 |
amit.gupta |
153 |
import com.spice.profitmandi.service.integrations.toffee.ToffeeService;
|
| 23929 |
amit.gupta |
154 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 25335 |
amit.gupta |
155 |
import com.spice.profitmandi.service.order.OrderService;
|
| 24431 |
amit.gupta |
156 |
import com.spice.profitmandi.service.pricing.PriceDropService;
|
| 23724 |
amit.gupta |
157 |
import com.spice.profitmandi.service.recharge.provider.OxigenRechargeProviderService;
|
|
|
158 |
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
|
|
|
159 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 24121 |
govind |
160 |
import com.spice.profitmandi.service.slab.TargetSlabService;
|
| 23929 |
amit.gupta |
161 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
|
|
162 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 23739 |
amit.gupta |
163 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 23723 |
amit.gupta |
164 |
|
| 25721 |
tejbeer |
165 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 25982 |
amit.gupta |
166 |
import in.shop2020.model.v1.order.WalletReferenceType;;
|
| 23739 |
amit.gupta |
167 |
|
| 23723 |
amit.gupta |
168 |
@Component
|
| 23724 |
amit.gupta |
169 |
@Transactional(rollbackFor = Throwable.class)
|
| 23723 |
amit.gupta |
170 |
public class ScheduledTasks {
|
|
|
171 |
|
| 23724 |
amit.gupta |
172 |
@Value("${oxigen.recharge.transaction.url}")
|
|
|
173 |
private String oxigenRechargeTransactionUrl;
|
| 23723 |
amit.gupta |
174 |
|
| 23724 |
amit.gupta |
175 |
@Value("${oxigen.recharge.enquiry.url}")
|
|
|
176 |
private String oxigenRechargeEnquiryUrl;
|
| 24533 |
govind |
177 |
|
| 24431 |
amit.gupta |
178 |
@Autowired
|
| 25503 |
amit.gupta |
179 |
private PartnerTypeChangeService partnerTypeChangeService;
|
| 25598 |
amit.gupta |
180 |
|
| 25590 |
amit.gupta |
181 |
@Autowired
|
| 26408 |
amit.gupta |
182 |
private ActivatedImeiRepository activatedImeiRepository;
|
|
|
183 |
|
|
|
184 |
@Autowired
|
| 25910 |
amit.gupta |
185 |
private LeadRepository leadRepository;
|
| 25927 |
amit.gupta |
186 |
|
| 25910 |
amit.gupta |
187 |
@Autowired
|
| 25590 |
amit.gupta |
188 |
private AuthRepository authRepository;
|
| 25503 |
amit.gupta |
189 |
|
|
|
190 |
@Autowired
|
| 24431 |
amit.gupta |
191 |
private PriceDropService priceDropService;
|
| 26283 |
tejbeer |
192 |
|
| 25590 |
amit.gupta |
193 |
@Autowired
|
| 25927 |
amit.gupta |
194 |
private FranchiseeVisitRepository franchiseeVisitRepository;
|
|
|
195 |
|
|
|
196 |
@Autowired
|
|
|
197 |
private FranchiseeActivityRepository franchiseeActivityRepository;
|
|
|
198 |
|
|
|
199 |
@Autowired
|
| 25982 |
amit.gupta |
200 |
private HdfcPaymentRepository hdfcPaymentRepository;
|
|
|
201 |
|
|
|
202 |
@Autowired
|
| 25590 |
amit.gupta |
203 |
private CsService csService;
|
| 25846 |
amit.gupta |
204 |
|
| 25837 |
amit.gupta |
205 |
@Autowired
|
|
|
206 |
private InsurancePolicyRepository insurancePolicyRepository;
|
| 23723 |
amit.gupta |
207 |
|
| 25694 |
amit.gupta |
208 |
@Autowired
|
|
|
209 |
private ToffeeService toffeeService;
|
|
|
210 |
|
| 23724 |
amit.gupta |
211 |
@Value("${oxigen.recharge.auth.key}")
|
|
|
212 |
private String oxigenRechargeAuthKey;
|
|
|
213 |
|
|
|
214 |
@Value("${oxigen.recharge.validation.url}")
|
|
|
215 |
private String oxigenRechargeValidationUrl;
|
|
|
216 |
|
|
|
217 |
@Value("${oxigen.recharge.validation.auth.key}")
|
|
|
218 |
private String oxigenRechargeValidationAuthKey;
|
|
|
219 |
|
|
|
220 |
@Value("${think.walnut.digital.recharge.transaction.mobile.url}")
|
|
|
221 |
private String thinkWalnutDigitalRechargeTransactionMobileUrl;
|
|
|
222 |
|
|
|
223 |
@Value("${think.walnut.digital.recharge.transaction.dth.url}")
|
|
|
224 |
private String thinkWalnutDigitalRechargeTransactionDthUrl;
|
|
|
225 |
|
|
|
226 |
@Value("${think.walnut.digital.recharge.enquiry.url}")
|
|
|
227 |
private String thinkWalnutDigitalRechargeEnquiryUrl;
|
|
|
228 |
|
|
|
229 |
@Value("${think.walnut.digital.recharge.balance.url}")
|
|
|
230 |
private String thinkWalnutDigitalRechargeBalanceUrl;
|
|
|
231 |
|
|
|
232 |
@Value("${think.walnut.digital.recharge.username}")
|
|
|
233 |
private String thinkWalnutDigitalRechargeUserName;
|
|
|
234 |
|
|
|
235 |
@Value("${think.walnut.digital.recharge.password}")
|
|
|
236 |
private String thinkWalnutDigitalRechargePassword;
|
|
|
237 |
|
|
|
238 |
@Value("${think.walnut.digital.recharge.auth.key}")
|
|
|
239 |
private String thinkWalnutDigitalRechargeAuthKey;
|
|
|
240 |
|
| 23723 |
amit.gupta |
241 |
@Autowired
|
| 23724 |
amit.gupta |
242 |
private PurchaseRepository purchaseRepository;
|
|
|
243 |
|
|
|
244 |
@Autowired
|
| 25609 |
amit.gupta |
245 |
private PriceDropIMEIRepository priceDropIMEIRepository;
|
|
|
246 |
|
|
|
247 |
@Autowired
|
|
|
248 |
PriceDropRepository priceDropRepository;
|
|
|
249 |
|
|
|
250 |
@Autowired
|
| 23724 |
amit.gupta |
251 |
private SchemeService schemeService;
|
| 24683 |
amit.gupta |
252 |
|
| 25609 |
amit.gupta |
253 |
private static final String[] STOCK_AGEING_MAIL_LIST = new String[] { "amod.sen@smartdukaan.com",
|
|
|
254 |
"adeel.yazdani@smartdukaan.com", "manoj.singh@smartdukaan.com", "kamini.sharma@smartdukaan.com",
|
|
|
255 |
"mohinder.mutreja@smartdukaan.com", " ankit.bhatia@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
| 25821 |
amit.gupta |
256 |
"chaitnaya.vats@smartdukaan.com", "kuldeep.kumar@smartdukaan.com", "prakash.rai@smartdukaan.com" };
|
| 25609 |
amit.gupta |
257 |
|
|
|
258 |
private static final String[] ITEMWISE_PENDING_INDENT_MAIL_LIST = new String[] { "kamini.sharma@smartdukaan.com",
|
| 25821 |
amit.gupta |
259 |
"prakash.rai@smartdukaan.com", "tarun.verma@smartdukaan.com", "chaitnaya.vats@smartdukaan.com",
|
|
|
260 |
"kuldeep.kumar@smartdukaan.com" };
|
| 25609 |
amit.gupta |
261 |
|
| 25721 |
tejbeer |
262 |
private List<OrderStatus> orderStatusList = Arrays.asList(OrderStatus.SUBMITTED_FOR_PROCESSING);
|
|
|
263 |
|
| 25927 |
amit.gupta |
264 |
private Object[] REPORT_HEADERS = { "Store Code", "Firm Name", "Store Name", "State Manager", "Teritory Manager" };
|
|
|
265 |
|
| 24681 |
amit.gupta |
266 |
@Autowired
|
|
|
267 |
private ReporticoService reporticoService;
|
| 23724 |
amit.gupta |
268 |
|
|
|
269 |
@Autowired
|
| 24337 |
amit.gupta |
270 |
private PartnerInvestmentService partnerInvestmentService;
|
| 25598 |
amit.gupta |
271 |
|
| 25590 |
amit.gupta |
272 |
@Autowired
|
|
|
273 |
private PositionRepository positionRepository;
|
| 24337 |
amit.gupta |
274 |
|
|
|
275 |
@Autowired
|
| 24542 |
amit.gupta |
276 |
private FofoOrderItemRepository fofoOrderItemRepository;
|
| 25865 |
amit.gupta |
277 |
|
| 25854 |
amit.gupta |
278 |
@Autowired
|
|
|
279 |
private NotificationService notificationService;
|
| 24542 |
amit.gupta |
280 |
|
|
|
281 |
@Autowired
|
| 24277 |
amit.gupta |
282 |
private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
|
|
283 |
|
|
|
284 |
@Autowired
|
| 24241 |
amit.gupta |
285 |
private SchemeInOutRepository schemeInOutRepository;
|
|
|
286 |
|
|
|
287 |
@Autowired
|
| 23724 |
amit.gupta |
288 |
private RechargeTransactionRepository rechargeTransactionRepository;
|
|
|
289 |
|
|
|
290 |
@Autowired
|
| 24542 |
amit.gupta |
291 |
private CustomerAddressRepository customerAddressRepository;
|
|
|
292 |
|
|
|
293 |
@Autowired
|
| 23724 |
amit.gupta |
294 |
private RechargeProviderCreditWalletHistoryRepository rechargeProviderCreditWalletHistoryRepository;
|
|
|
295 |
|
|
|
296 |
@Autowired
|
| 24590 |
amit.gupta |
297 |
private FofoLineItemRepository fofoLineItemRepository;
|
|
|
298 |
|
|
|
299 |
@Autowired
|
| 23724 |
amit.gupta |
300 |
private FofoOrderRepository fofoOrderRepository;
|
| 24587 |
amit.gupta |
301 |
|
| 24580 |
amit.gupta |
302 |
@Autowired
|
|
|
303 |
private UserWalletHistoryRepository userWalletHistoryRepository;
|
| 24250 |
amit.gupta |
304 |
|
| 24249 |
amit.gupta |
305 |
@Autowired
|
| 24587 |
amit.gupta |
306 |
private UserWalletRepository userWalletRepository;
|
|
|
307 |
|
|
|
308 |
@Autowired
|
| 24249 |
amit.gupta |
309 |
private InventoryItemRepository inventoryItemRepository;
|
| 23929 |
amit.gupta |
310 |
|
| 23739 |
amit.gupta |
311 |
@Autowired
|
|
|
312 |
private WalletService walletService;
|
| 23724 |
amit.gupta |
313 |
|
|
|
314 |
@Autowired
|
|
|
315 |
private ThinkWalnutDigitalRechargeProviderService thinkWalnutDigitalRechargeProviderService;
|
|
|
316 |
|
|
|
317 |
@Autowired
|
|
|
318 |
private OxigenRechargeProviderService oxigenRechargeProviderService;
|
|
|
319 |
|
|
|
320 |
@Autowired
|
|
|
321 |
private RechargeProviderRepository rechargeProviderRepository;
|
|
|
322 |
|
|
|
323 |
@Autowired
|
| 24242 |
amit.gupta |
324 |
private ScanRecordRepository scanRecordRepository;
|
|
|
325 |
|
|
|
326 |
@Autowired
|
| 23724 |
amit.gupta |
327 |
private DailyRechargeRepository dailyRechargeRepository;
|
|
|
328 |
|
| 23929 |
amit.gupta |
329 |
@Autowired
|
|
|
330 |
private FofoStoreRepository fofoStoreRepository;
|
| 24177 |
govind |
331 |
|
| 24121 |
govind |
332 |
@Autowired
|
|
|
333 |
private TargetSlabService targetService;
|
| 23929 |
amit.gupta |
334 |
|
| 23724 |
amit.gupta |
335 |
@Value("${prod}")
|
|
|
336 |
private boolean prod;
|
|
|
337 |
|
| 23929 |
amit.gupta |
338 |
@Autowired
|
|
|
339 |
private RetailerService retailerService;
|
|
|
340 |
|
|
|
341 |
@Autowired
|
|
|
342 |
private TransactionService transactionService;
|
| 24250 |
amit.gupta |
343 |
|
| 24249 |
amit.gupta |
344 |
@Autowired
|
|
|
345 |
private ItemRepository itemRepository;
|
| 23929 |
amit.gupta |
346 |
|
|
|
347 |
@Autowired
|
|
|
348 |
private OrderRepository orderRepository;
|
| 25351 |
tejbeer |
349 |
|
| 25335 |
amit.gupta |
350 |
@Autowired
|
|
|
351 |
private OrderService orderService;
|
| 23929 |
amit.gupta |
352 |
|
|
|
353 |
@Autowired
|
| 24241 |
amit.gupta |
354 |
private SchemeRepository schemeRepository;
|
|
|
355 |
|
|
|
356 |
@Autowired
|
| 23929 |
amit.gupta |
357 |
private JavaMailSender mailSender;
|
| 24177 |
govind |
358 |
|
| 24174 |
govind |
359 |
@Autowired
|
|
|
360 |
private PartnerTargetRepository partnerTargetRepository;
|
| 24002 |
amit.gupta |
361 |
|
|
|
362 |
@Autowired
|
|
|
363 |
@Qualifier(value = "googleMailSender")
|
| 23932 |
amit.gupta |
364 |
private JavaMailSender googleMailSender;
|
| 23929 |
amit.gupta |
365 |
|
|
|
366 |
@Autowired
|
|
|
367 |
private InventoryService inventoryService;
|
|
|
368 |
|
| 24533 |
govind |
369 |
@Autowired
|
| 24542 |
amit.gupta |
370 |
private AddressRepository addressRepository;
|
|
|
371 |
|
|
|
372 |
@Autowired
|
|
|
373 |
private RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
|
|
374 |
|
| 24653 |
govind |
375 |
@Autowired
|
|
|
376 |
private Mongo mongoClient;
|
| 24683 |
amit.gupta |
377 |
|
| 24669 |
govind |
378 |
@Autowired
|
| 25300 |
tejbeer |
379 |
private DeviceRepository deviceRepository;
|
|
|
380 |
|
|
|
381 |
@Autowired
|
|
|
382 |
private PushNotificationRepository pushNotificationRepository;
|
|
|
383 |
|
|
|
384 |
@Autowired
|
|
|
385 |
private NotificationCampaignRepository notificationCampaignRepository;
|
|
|
386 |
|
|
|
387 |
@Autowired
|
| 25721 |
tejbeer |
388 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
|
|
389 |
|
|
|
390 |
@Autowired
|
|
|
391 |
private FocusedModelRepository focusedModelRepository;
|
|
|
392 |
|
|
|
393 |
@Autowired
|
| 24669 |
govind |
394 |
private UserAccountRepository userAccountRepository;
|
| 24653 |
govind |
395 |
|
| 25721 |
tejbeer |
396 |
@Autowired
|
| 25927 |
amit.gupta |
397 |
private UserRepository userUserRepository;
|
| 25721 |
tejbeer |
398 |
|
|
|
399 |
@Autowired
|
| 25927 |
amit.gupta |
400 |
private com.spice.profitmandi.dao.repository.dtr.UserRepository dtrUserRepository;
|
|
|
401 |
|
|
|
402 |
@Autowired
|
| 25721 |
tejbeer |
403 |
private UserCampaignRepository userCampaignRepository;
|
|
|
404 |
|
|
|
405 |
@Autowired
|
|
|
406 |
private Gson gson;
|
|
|
407 |
|
| 26283 |
tejbeer |
408 |
@Autowired
|
|
|
409 |
private TicketRepository ticketRepository;
|
|
|
410 |
|
| 23755 |
amit.gupta |
411 |
private static final Logger LOGGER = LogManager.getLogger(ScheduledTasks.class);
|
| 23724 |
amit.gupta |
412 |
|
| 25300 |
tejbeer |
413 |
private String FCM_URL = "https://fcm.googleapis.com/fcm/send";
|
|
|
414 |
private String FCM_API_KEY = "AAAASAjNcn4:APA91bG6fWRIgYJI0L9gCjP5ynaXz2hJHYKtD9dfH7Depdv31Nd9APJwhx-OPkAJ1WSz4BGNYG8lHThLFSjDGFxIwUZv241YcAJEGDLgt86mxq9FXJe-yBRu-S0_ZwHqmX-QaVKl5F_A";
|
|
|
415 |
|
| 23724 |
amit.gupta |
416 |
public void generateDailyRecharge() {
|
|
|
417 |
List<RechargeProviderCreditWalletHistory> allCreditHistory = rechargeProviderCreditWalletHistoryRepository
|
|
|
418 |
.selectAll(0, 2000);
|
|
|
419 |
List<RechargeProvider> rechargeProviders = rechargeProviderRepository.selectAll();
|
|
|
420 |
rechargeProviders.stream().forEach(x -> x.setAmount(0));
|
|
|
421 |
|
|
|
422 |
rechargeProviders.stream().forEach(x -> {
|
|
|
423 |
Map<LocalDate, List<RechargeProviderCreditWalletHistory>> dateWiseProviderCreditsMap = allCreditHistory
|
|
|
424 |
.stream().filter(z -> z.getProviderId() == x.getId())
|
|
|
425 |
.collect(Collectors.groupingBy(x1 -> x1.getReceiveTimestamp().toLocalDate()));
|
|
|
426 |
|
|
|
427 |
LOGGER.info("dateWiseProviderCreditsMap -- {}", dateWiseProviderCreditsMap);
|
|
|
428 |
LocalDate endDate = LocalDate.now().plusDays(1);
|
|
|
429 |
float previousDayClosing = 0;
|
|
|
430 |
LocalDate date = LocalDate.of(2018, 4, 6);
|
|
|
431 |
while (date.isBefore(endDate)) {
|
|
|
432 |
List<RechargeTransaction> dateWiseRechargeTransactions = rechargeTransactionRepository
|
|
|
433 |
.selectAllBetweenTimestamp(Arrays.asList(RechargeStatus.values()), date.atStartOfDay(),
|
|
|
434 |
date.plusDays(1).atStartOfDay());
|
|
|
435 |
|
|
|
436 |
List<RechargeTransaction> successfulTransactions = dateWiseRechargeTransactions.stream()
|
|
|
437 |
.filter(y -> y.getStatus().equals(RechargeStatus.SUCCESS)).collect(Collectors.toList());
|
|
|
438 |
|
|
|
439 |
float dailyAmount = 0;
|
|
|
440 |
float totalCommission = 0;
|
|
|
441 |
for (RechargeTransaction rechargeTransaction : successfulTransactions) {
|
|
|
442 |
if (rechargeTransaction.getProviderId() == x.getId()) {
|
|
|
443 |
dailyAmount += rechargeTransaction.getAmount();
|
|
|
444 |
totalCommission += rechargeTransaction.getCommission();
|
|
|
445 |
}
|
|
|
446 |
}
|
|
|
447 |
|
|
|
448 |
List<RechargeProviderCreditWalletHistory> rechargeHistoryList = dateWiseProviderCreditsMap.get(date);
|
|
|
449 |
float dailyWalletRecharge = 0;
|
|
|
450 |
if (rechargeHistoryList != null) {
|
|
|
451 |
for (RechargeProviderCreditWalletHistory rechargeProviderCreditWalletHistory : rechargeHistoryList) {
|
|
|
452 |
if (rechargeProviderCreditWalletHistory.getProviderId() == x.getId()) {
|
|
|
453 |
dailyWalletRecharge += rechargeProviderCreditWalletHistory.getAmount();
|
|
|
454 |
}
|
|
|
455 |
}
|
|
|
456 |
}
|
|
|
457 |
if (dailyAmount > 0 || dailyWalletRecharge > 0) {
|
|
|
458 |
DailyRecharge dailyRecharge = null;
|
|
|
459 |
try {
|
|
|
460 |
dailyRecharge = dailyRechargeRepository.selectByProviderIdAndCreateDate(x.getId(), date);
|
|
|
461 |
} catch (Exception e) {
|
|
|
462 |
LOGGER.info("Could not find Recharge entry");
|
|
|
463 |
}
|
|
|
464 |
if (dailyRecharge == null) {
|
|
|
465 |
dailyRecharge = new DailyRecharge();
|
|
|
466 |
dailyRecharge.setCreateDate(date);
|
|
|
467 |
}
|
|
|
468 |
dailyRecharge.setOpeningBalance(previousDayClosing);
|
|
|
469 |
dailyRecharge.setProviderId(x.getId());
|
|
|
470 |
dailyRecharge.setWalletRechargeAmount(dailyWalletRecharge);
|
|
|
471 |
dailyRecharge.setTotalAmount(dailyAmount);
|
|
|
472 |
dailyRecharge.setTotalCommission(totalCommission);
|
|
|
473 |
float closingBalance = dailyRecharge.getOpeningBalance() + dailyWalletRecharge - dailyAmount;
|
|
|
474 |
dailyRecharge.setClosingBalance(closingBalance);
|
|
|
475 |
dailyRechargeRepository.persist(dailyRecharge);
|
|
|
476 |
x.setAmount(x.getAmount() + dailyRecharge.getClosingBalance() - dailyRecharge.getOpeningBalance());
|
|
|
477 |
previousDayClosing = dailyRecharge.getClosingBalance();
|
|
|
478 |
}
|
|
|
479 |
date = date.plusDays(1);
|
|
|
480 |
}
|
|
|
481 |
rechargeProviderRepository.persist(x);
|
|
|
482 |
});
|
| 23761 |
amit.gupta |
483 |
LOGGER.info("finished generating daily recharge");
|
| 23724 |
amit.gupta |
484 |
}
|
|
|
485 |
|
| 23738 |
amit.gupta |
486 |
public void reconcileRecharge() throws Exception {
|
| 23724 |
amit.gupta |
487 |
LocalDateTime fromDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays(30);
|
|
|
488 |
LocalDateTime toDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
|
|
|
489 |
List<RechargeStatus> nonSuccessRechargeStatuses = new ArrayList<>(Arrays.asList(RechargeStatus.values()));
|
|
|
490 |
LOGGER.info("nonSuccessRechargeStatuses {} ", nonSuccessRechargeStatuses);
|
|
|
491 |
nonSuccessRechargeStatuses.remove(RechargeStatus.SUCCESS);
|
|
|
492 |
nonSuccessRechargeStatuses.remove(RechargeStatus.FAILED);
|
|
|
493 |
RechargeCredential thinkWalnutDigitalRechargeEnquiryCredential = new RechargeCredential();
|
|
|
494 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUrl(thinkWalnutDigitalRechargeEnquiryUrl);
|
|
|
495 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUserName(thinkWalnutDigitalRechargeUserName);
|
|
|
496 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargePassword(thinkWalnutDigitalRechargePassword);
|
|
|
497 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeAuthKey(thinkWalnutDigitalRechargeAuthKey);
|
|
|
498 |
Map<String, RechargeStatus> requestRechargeStatusChanged = new HashMap<>();
|
|
|
499 |
List<RechargeTransaction> rechargeTransactions = rechargeTransactionRepository
|
|
|
500 |
.selectAllBetweenTimestamp(nonSuccessRechargeStatuses, fromDate, toDate);
|
|
|
501 |
for (RechargeTransaction rechargeTransaction : rechargeTransactions) {
|
|
|
502 |
try {
|
|
|
503 |
int providerId = rechargeTransaction.getProviderId();
|
|
|
504 |
if (providerId == 1) {
|
|
|
505 |
oxigenRechargeProviderService.doCheckStatusRequest(oxigenRechargeEnquiryUrl, oxigenRechargeAuthKey,
|
|
|
506 |
rechargeTransaction);
|
|
|
507 |
} else if (providerId == 2) {
|
|
|
508 |
thinkWalnutDigitalRechargeProviderService
|
|
|
509 |
.doCheckStatusRequest(thinkWalnutDigitalRechargeEnquiryCredential, rechargeTransaction);
|
|
|
510 |
}
|
|
|
511 |
if (rechargeTransaction.getStatus().equals(RechargeStatus.SUCCESS)
|
|
|
512 |
|| rechargeTransaction.getStatus().equals(RechargeStatus.FAILED)) {
|
|
|
513 |
requestRechargeStatusChanged.put(rechargeTransaction.getRequestId(),
|
|
|
514 |
rechargeTransaction.getStatus());
|
|
|
515 |
}
|
|
|
516 |
} catch (Exception e) {
|
|
|
517 |
LOGGER.info("Could not check status for Request {}", rechargeTransaction.getRequestId());
|
|
|
518 |
}
|
|
|
519 |
}
|
| 23738 |
amit.gupta |
520 |
LOGGER.info("Reconcile recharge ran successfully");
|
| 23724 |
amit.gupta |
521 |
}
|
| 24240 |
amit.gupta |
522 |
|
|
|
523 |
// TemporaryMethod
|
| 24237 |
amit.gupta |
524 |
public void migrateInvoice() {
|
|
|
525 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectFromSaleDate(LocalDateTime.now().minusDays(3));
|
|
|
526 |
Map<Integer, List<FofoOrder>> partnerOrdersMap = new HashMap<>();
|
| 24241 |
amit.gupta |
527 |
partnerOrdersMap = fofoOrders.stream()
|
|
|
528 |
.collect(Collectors.groupingBy(FofoOrder::getFofoId, Collectors.toList()));
|
| 24237 |
amit.gupta |
529 |
for (List<FofoOrder> orderList : partnerOrdersMap.values()) {
|
| 24240 |
amit.gupta |
530 |
int sequence = 0;
|
|
|
531 |
String prefix = "";
|
| 24241 |
amit.gupta |
532 |
List<FofoOrder> sortedList = orderList.stream().sorted((x1, x2) -> x1.getId() - x2.getId())
|
|
|
533 |
.collect(Collectors.toList());
|
|
|
534 |
for (FofoOrder order : sortedList) {
|
|
|
535 |
|
| 24240 |
amit.gupta |
536 |
LOGGER.info("Order Id is {}, partner Id is {}", order.getId(), order.getFofoId());
|
| 24241 |
amit.gupta |
537 |
if (!order.getInvoiceNumber().contains("SEC")) {
|
| 24240 |
amit.gupta |
538 |
sequence = Integer.parseInt(order.getInvoiceNumber().split("/")[1]);
|
|
|
539 |
prefix = order.getInvoiceNumber().split("/")[0];
|
|
|
540 |
} else {
|
|
|
541 |
sequence += 1;
|
| 24241 |
amit.gupta |
542 |
String invoiceNumber = prefix + "/" + sequence;
|
| 24240 |
amit.gupta |
543 |
order.setInvoiceNumber(invoiceNumber);
|
|
|
544 |
fofoOrderRepository.persist(order);
|
|
|
545 |
}
|
|
|
546 |
}
|
| 24241 |
amit.gupta |
547 |
|
| 24237 |
amit.gupta |
548 |
}
|
|
|
549 |
}
|
| 23724 |
amit.gupta |
550 |
|
| 24241 |
amit.gupta |
551 |
// Temporary Method
|
| 24252 |
amit.gupta |
552 |
public void evaluateExcessSchemeOut() throws Exception {
|
| 24244 |
amit.gupta |
553 |
Map<Integer, String> userNameMap = retailerService.getAllFofoRetailerIdNameMap();
|
|
|
554 |
Map<Integer, Float> userAmountMap = new HashMap<>();
|
| 24252 |
amit.gupta |
555 |
|
| 25837 |
amit.gupta |
556 |
List<List<?>> rows = new ArrayList<>();
|
| 24271 |
amit.gupta |
557 |
List<String> headers = Arrays.asList("Scheme", "Item", "Partner", "Amount", "Credited On", "Invoice Number",
|
|
|
558 |
"Sale On", "Scheme Start", "Scheme End", "Active On", "Expired On");
|
| 24241 |
amit.gupta |
559 |
schemeRepository.selectAll().stream().forEach(x -> {
|
| 24250 |
amit.gupta |
560 |
if (x.getType().equals(SchemeType.OUT)) {
|
|
|
561 |
List<SchemeInOut> sioList = schemeInOutRepository
|
|
|
562 |
.selectBySchemeIds(new HashSet<>(Arrays.asList(x.getId())));
|
|
|
563 |
if (x.getActiveTimestamp() != null) {
|
|
|
564 |
LocalDateTime endDateTime = x.getEndDateTime();
|
|
|
565 |
if (x.getExpireTimestamp() != null && x.getExpireTimestamp().isBefore(x.getEndDateTime())) {
|
|
|
566 |
endDateTime = x.getExpireTimestamp();
|
| 24249 |
amit.gupta |
567 |
}
|
| 24250 |
amit.gupta |
568 |
for (SchemeInOut sio : sioList) {
|
|
|
569 |
InventoryItem inventoryItem = null;
|
| 24266 |
amit.gupta |
570 |
inventoryItem = inventoryItemRepository.selectById(sio.getInventoryItemId());
|
| 24271 |
amit.gupta |
571 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndSerialNumber(
|
|
|
572 |
inventoryItem.getFofoId(), inventoryItem.getSerialNumber(), null, null, 0, 1).get(0);
|
| 24250 |
amit.gupta |
573 |
Optional<ScanRecord> record = scanRecordRepository
|
|
|
574 |
.selectByInventoryItemId(sio.getInventoryItemId()).stream()
|
|
|
575 |
.filter(y -> y.getType().equals(ScanType.SALE)).findFirst();
|
|
|
576 |
if (record.isPresent()) {
|
|
|
577 |
int fofoId = record.get().getFofoId();
|
|
|
578 |
if (record.get().getCreateTimestamp().isAfter(endDateTime)
|
|
|
579 |
|| record.get().getCreateTimestamp().isBefore(x.getStartDateTime())) {
|
|
|
580 |
if (!userAmountMap.containsKey(fofoId)) {
|
|
|
581 |
userAmountMap.put(fofoId, 0f);
|
|
|
582 |
}
|
|
|
583 |
userAmountMap.put(fofoId, sio.getAmount() + userAmountMap.get(fofoId));
|
|
|
584 |
try {
|
| 24252 |
amit.gupta |
585 |
rows.add(Arrays.asList(x.getDescription(),
|
| 24250 |
amit.gupta |
586 |
itemRepository.selectById(inventoryItem.getItemId()).getItemDescription(),
|
| 24252 |
amit.gupta |
587 |
userNameMap.get(fofoId), sio.getAmount(),
|
| 24253 |
amit.gupta |
588 |
FormattingUtils.formatDate(sio.getCreateTimestamp()),
|
|
|
589 |
fofoOrder.getInvoiceNumber(),
|
|
|
590 |
FormattingUtils.formatDate(record.get().getCreateTimestamp()),
|
|
|
591 |
FormattingUtils.formatDate(x.getStartDateTime()),
|
|
|
592 |
FormattingUtils.formatDate(x.getEndDateTime()),
|
|
|
593 |
FormattingUtils.formatDate(x.getActiveTimestamp()),
|
|
|
594 |
FormattingUtils.formatDate(x.getExpireTimestamp())));
|
| 24250 |
amit.gupta |
595 |
} catch (Exception e) {
|
|
|
596 |
e.printStackTrace();
|
|
|
597 |
}
|
| 24242 |
amit.gupta |
598 |
}
|
| 24241 |
amit.gupta |
599 |
}
|
|
|
600 |
}
|
|
|
601 |
}
|
|
|
602 |
}
|
|
|
603 |
});
|
| 24246 |
amit.gupta |
604 |
userAmountMap.entrySet().stream()
|
|
|
605 |
.forEach(x -> LOGGER.info("{} to be deducted from {}({}) for wrongly disbursed due to technical error.",
|
|
|
606 |
x.getValue(), userNameMap.get(x.getKey())));
|
| 24241 |
amit.gupta |
607 |
|
| 24252 |
amit.gupta |
608 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
| 24271 |
amit.gupta |
609 |
Utils.sendMailWithAttachment(googleMailSender,
|
|
|
610 |
new String[] { "amit.gupta@shop2020.in", "adeel.yazdani@smartdukaan.com" }, null,
|
|
|
611 |
"Partner Excess Amount", "PFA", "ListofSchemes.csv", new ByteArrayResource(baos.toByteArray()));
|
| 24252 |
amit.gupta |
612 |
|
| 24241 |
amit.gupta |
613 |
}
|
| 24271 |
amit.gupta |
614 |
|
| 25584 |
amit.gupta |
615 |
public void processScheme(int offset, boolean dryRun) throws Exception {
|
| 24462 |
amit.gupta |
616 |
LocalDateTime startDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(offset);
|
| 24259 |
amit.gupta |
617 |
LocalDateTime endDate = startDate.plusDays(30);
|
| 25584 |
amit.gupta |
618 |
processScheme(startDate, endDate, dryRun);
|
| 24256 |
amit.gupta |
619 |
}
|
| 24533 |
govind |
620 |
|
| 25584 |
amit.gupta |
621 |
public void processScheme(int offset, int durationDays, boolean dryRun) throws Exception {
|
| 24462 |
amit.gupta |
622 |
LocalDateTime startDate = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT).minusDays(offset);
|
| 24461 |
amit.gupta |
623 |
LocalDateTime endDate = startDate.plusDays(durationDays);
|
| 25584 |
amit.gupta |
624 |
processScheme(startDate, endDate, dryRun);
|
| 24461 |
amit.gupta |
625 |
}
|
| 24271 |
amit.gupta |
626 |
|
| 25584 |
amit.gupta |
627 |
public void processScheme(boolean dryRun) throws Exception {
|
| 24256 |
amit.gupta |
628 |
LocalDateTime fromDate = LocalDateTime.now().minusDays(30);
|
| 25584 |
amit.gupta |
629 |
processScheme(fromDate, LocalDateTime.now(), dryRun);
|
| 24256 |
amit.gupta |
630 |
}
|
| 24271 |
amit.gupta |
631 |
|
| 25584 |
amit.gupta |
632 |
public void processScheme(LocalDateTime startDate, LocalDateTime endDate, boolean dryRun) throws Exception {
|
| 23724 |
amit.gupta |
633 |
LOGGER.info("Started execution at {}", LocalDateTime.now());
|
| 25312 |
amit.gupta |
634 |
System.out.println(
|
|
|
635 |
"InventoryId\tSerialNumber\tItem Id\tScheme Id\tScheme Name\tScheme Type\tAmount Type\tDP\tTaxable\tScheme Amount\tAmount Paid");
|
| 24561 |
amit.gupta |
636 |
try {
|
| 24587 |
amit.gupta |
637 |
List<Purchase> purchases = purchaseRepository.selectAllBetweenPurchaseDate(startDate, endDate);
|
|
|
638 |
for (Purchase purchase : purchases) {
|
|
|
639 |
schemeService.processSchemeIn(purchase.getId(), purchase.getFofoId());
|
|
|
640 |
}
|
| 24271 |
amit.gupta |
641 |
|
| 24587 |
amit.gupta |
642 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectBetweenSaleDate(startDate, endDate);
|
|
|
643 |
for (FofoOrder fofoOrder : fofoOrders) {
|
|
|
644 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoOrder.getFofoId());
|
|
|
645 |
}
|
|
|
646 |
} catch (Exception e) {
|
| 24561 |
amit.gupta |
647 |
e.printStackTrace();
|
| 24565 |
amit.gupta |
648 |
throw e;
|
| 24561 |
amit.gupta |
649 |
}
|
| 25312 |
amit.gupta |
650 |
List<UserWalletHistory> uwhs = userWalletHistoryRepository.selectAllByDateType(startDate, endDate,
|
|
|
651 |
Arrays.asList(WalletReferenceType.SCHEME_IN, WalletReferenceType.SCHEME_OUT));
|
| 25043 |
amit.gupta |
652 |
System.out.println("Amount\tReference\tReferenceType\tTimestamp\tDescription");
|
| 25312 |
amit.gupta |
653 |
for (UserWalletHistory uwh : uwhs) {
|
|
|
654 |
System.out.println(String.format("%d\t%d\t%s\t%s\t%s", uwh.getAmount(), uwh.getReference(),
|
|
|
655 |
uwh.getReferenceType(), uwh.getTimestamp().toString(), uwh.getDescription()));
|
| 25043 |
amit.gupta |
656 |
}
|
| 23724 |
amit.gupta |
657 |
LOGGER.info("Schemes process successfully.");
|
| 25598 |
amit.gupta |
658 |
if (dryRun) {
|
| 25584 |
amit.gupta |
659 |
throw new Exception();
|
|
|
660 |
}
|
| 23724 |
amit.gupta |
661 |
}
|
| 23929 |
amit.gupta |
662 |
|
| 23739 |
amit.gupta |
663 |
public void processRechargeCashback() throws Throwable {
|
| 23761 |
amit.gupta |
664 |
LocalDateTime cashbackTime = LocalDateTime.now();
|
| 23929 |
amit.gupta |
665 |
int referenceId = (int) Timestamp.valueOf(cashbackTime).getTime() / 1000;
|
|
|
666 |
List<RechargeTransaction> pendingTransactions = rechargeTransactionRepository
|
|
|
667 |
.getPendingCashBackRehargeTransactions();
|
|
|
668 |
Map<Object, Double> totalRetailerCashbacks = pendingTransactions.stream().collect(
|
|
|
669 |
Collectors.groupingBy(x -> x.getRetailerId(), Collectors.summingDouble(x -> x.getCommission())));
|
|
|
670 |
for (Map.Entry<Object, Double> totalRetailerCashback : totalRetailerCashbacks.entrySet()) {
|
|
|
671 |
int retailerId = (Integer) totalRetailerCashback.getKey();
|
| 23739 |
amit.gupta |
672 |
float amount = totalRetailerCashback.getValue().floatValue();
|
| 23929 |
amit.gupta |
673 |
if (Math.round(amount) > 0) {
|
|
|
674 |
walletService.addAmountToWallet(retailerId, referenceId, WalletReferenceType.CASHBACK,
|
|
|
675 |
"Recharge Cashback", Math.round(amount));
|
| 23762 |
amit.gupta |
676 |
}
|
| 23739 |
amit.gupta |
677 |
}
|
| 23929 |
amit.gupta |
678 |
for (RechargeTransaction rt : pendingTransactions) {
|
| 23761 |
amit.gupta |
679 |
rt.setCashbackTimestamp(cashbackTime);
|
|
|
680 |
rt.setCashbackReference(referenceId);
|
|
|
681 |
rechargeTransactionRepository.persist(rt);
|
|
|
682 |
}
|
| 23739 |
amit.gupta |
683 |
LOGGER.info("Cashbacks for Recharge processed Successfully");
|
|
|
684 |
}
|
| 23724 |
amit.gupta |
685 |
|
| 25598 |
amit.gupta |
686 |
private class SaleRoles {
|
|
|
687 |
|
|
|
688 |
private List<String> l1;
|
|
|
689 |
private List<String> l2;
|
|
|
690 |
|
|
|
691 |
public SaleRoles() {
|
|
|
692 |
l1 = new ArrayList<>();
|
|
|
693 |
l2 = new ArrayList<>();
|
|
|
694 |
}
|
|
|
695 |
|
|
|
696 |
public List<String> getL1() {
|
|
|
697 |
return l1;
|
|
|
698 |
}
|
|
|
699 |
|
|
|
700 |
public List<String> getL2() {
|
|
|
701 |
return l2;
|
|
|
702 |
}
|
|
|
703 |
|
|
|
704 |
}
|
|
|
705 |
|
| 24271 |
amit.gupta |
706 |
public void sendPartnerInvestmentDetails(List<String> sendTo) throws Exception {
|
| 24277 |
amit.gupta |
707 |
LocalDate yesterDay = LocalDate.now().minusDays(1);
|
| 25267 |
amit.gupta |
708 |
List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
|
| 23929 |
amit.gupta |
709 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService
|
|
|
710 |
.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
| 25351 |
tejbeer |
711 |
|
| 25598 |
amit.gupta |
712 |
List<String> headers = Arrays.asList("Code", "Firm Name", "Store Name", "State Manager", "Teritory/Team Lead",
|
| 26265 |
amit.gupta |
713 |
"Wallet Amount", "In Stock Amount", "Activated Stock", "Return In Transit Stock", "Unbilled Amount", "Grn Pending Amount",
|
| 26376 |
amit.gupta |
714 |
"Min Investment", "Investment Amount", "Investment Short", "Unbilled Qty", "Short Days");
|
| 25837 |
amit.gupta |
715 |
List<List<?>> rows = new ArrayList<>();
|
| 25895 |
amit.gupta |
716 |
Map<Integer, List<?>> partnerRowsMap = new HashMap<>();
|
| 25598 |
amit.gupta |
717 |
|
| 25837 |
amit.gupta |
718 |
Map<Integer, List<Serializable>> partnerIdSalesHeaderMap = this.getPartnerIdSalesHeaders();
|
| 26376 |
amit.gupta |
719 |
|
|
|
720 |
Map<Integer, Integer> shortDaysMap = partnerDailyInvestmentRepository.selectAll(LocalDate.now().withDayOfMonth(1), LocalDate.now())
|
|
|
721 |
.stream().collect(Collectors.groupingBy(x->x.getFofoId(),
|
|
|
722 |
Collectors.summingInt(x-> x.getShortPercentage() > 10 ? 1 : 0)));
|
| 25598 |
amit.gupta |
723 |
|
| 24002 |
amit.gupta |
724 |
for (FofoStore fofoStore : fofoStores) {
|
| 26376 |
amit.gupta |
725 |
int fofoId = fofoStore.getId();
|
|
|
726 |
PartnerDailyInvestment partnerDailyInvestment = partnerInvestmentService.getInvestment(fofoId,1);
|
| 25598 |
amit.gupta |
727 |
partnerDailyInvestment.setDate(yesterDay);
|
| 26376 |
amit.gupta |
728 |
|
| 25598 |
amit.gupta |
729 |
try {
|
|
|
730 |
partnerDailyInvestmentRepository.persist(partnerDailyInvestment);
|
| 26376 |
amit.gupta |
731 |
shortDaysMap.put(fofoId, shortDaysMap.get(fofoId) + (partnerDailyInvestment.getShortPercentage() > 10 ? 1 : 0));
|
| 25598 |
amit.gupta |
732 |
} catch (Exception e) {
|
|
|
733 |
// ignore the exceptions during persist
|
|
|
734 |
}
|
|
|
735 |
|
| 24002 |
amit.gupta |
736 |
CustomRetailer retailer = customRetailerMap.get(fofoStore.getId());
|
| 25837 |
amit.gupta |
737 |
if (retailer == null || partnerIdSalesHeaderMap.get(fofoStore.getId()) == null) {
|
| 24002 |
amit.gupta |
738 |
LOGGER.info("Could not find retailer with retailer Id {}", fofoStore.getId());
|
|
|
739 |
continue;
|
|
|
740 |
}
|
| 25837 |
amit.gupta |
741 |
List<Serializable> row = partnerIdSalesHeaderMap.get(fofoStore.getId());
|
| 25927 |
amit.gupta |
742 |
row.addAll(
|
|
|
743 |
Arrays.asList(partnerDailyInvestment.getWalletAmount(), partnerDailyInvestment.getInStockAmount(),
|
| 26265 |
amit.gupta |
744 |
partnerDailyInvestment.getActivatedStockAmount() == 0 ? "-":"("+partnerDailyInvestment.getActivatedStockAmount()+")",
|
| 25927 |
amit.gupta |
745 |
0, partnerDailyInvestment.getUnbilledAmount(), partnerDailyInvestment.getGrnPendingAmount(),
|
|
|
746 |
partnerDailyInvestment.getMinInvestment(), partnerDailyInvestment.getTotalInvestment(),
|
| 26376 |
amit.gupta |
747 |
partnerDailyInvestment.getShortInvestment(), partnerDailyInvestment.getUnbilledQty(),shortDaysMap.get(fofoId)));
|
| 25837 |
amit.gupta |
748 |
partnerRowsMap.put(fofoStore.getId(), row);
|
| 24002 |
amit.gupta |
749 |
rows.add(row);
|
|
|
750 |
|
| 23929 |
amit.gupta |
751 |
}
|
| 25312 |
amit.gupta |
752 |
|
| 24271 |
amit.gupta |
753 |
String fileName = "InvestmentSummary-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
| 25598 |
amit.gupta |
754 |
|
| 25927 |
amit.gupta |
755 |
if (sendTo == null) {
|
| 25895 |
amit.gupta |
756 |
for (Map.Entry<String, Set<Integer>> storeGuyEntry : csService.getAuthUserPartnerIdMapping().entrySet()) {
|
|
|
757 |
List<List<?>> filteredRows = storeGuyEntry.getValue().stream().map(x -> partnerRowsMap.get(x))
|
|
|
758 |
.filter(x -> x != null).collect(Collectors.toList());
|
|
|
759 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, filteredRows);
|
|
|
760 |
String[] sendToArray = new String[] { storeGuyEntry.getKey() };
|
|
|
761 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Franchise Investment Summary", "PFA",
|
|
|
762 |
fileName, new ByteArrayResource(baos.toByteArray()));
|
|
|
763 |
}
|
|
|
764 |
sendTo = Arrays.asList("tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com",
|
| 26376 |
amit.gupta |
765 |
"prakash.rai@smartdukaan.com", "amit.gupta@shop2020.in");
|
| 25341 |
amit.gupta |
766 |
}
|
| 25312 |
amit.gupta |
767 |
|
| 25604 |
amit.gupta |
768 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
|
|
769 |
String[] sendToArray = sendTo.toArray(new String[sendTo.size()]);
|
| 25609 |
amit.gupta |
770 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Franchise Investment Summary", "PFA",
|
|
|
771 |
fileName, new ByteArrayResource(baos.toByteArray()));
|
| 24271 |
amit.gupta |
772 |
|
| 23929 |
amit.gupta |
773 |
}
|
| 24177 |
govind |
774 |
|
| 25837 |
amit.gupta |
775 |
private Map<Integer, List<Serializable>> getPartnerIdSalesHeaders() {
|
| 25598 |
amit.gupta |
776 |
Map<String, SaleRoles> partnerEmailSalesMap = new HashMap<>();
|
|
|
777 |
|
|
|
778 |
List<Position> positions = positionRepository
|
|
|
779 |
.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES);
|
|
|
780 |
Map<Integer, AuthUser> authUsersMap = authRepository.selectAllActiveUser().stream()
|
|
|
781 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
782 |
Map<Integer, List<CustomRetailer>> positionIdRetailerMap = csService.getPositionCustomRetailerMap(positions);
|
|
|
783 |
for (Position position : positions) {
|
|
|
784 |
List<CustomRetailer> crList = positionIdRetailerMap.get(position.getId());
|
| 25609 |
amit.gupta |
785 |
if (crList == null)
|
|
|
786 |
continue;
|
| 25598 |
amit.gupta |
787 |
for (CustomRetailer cr : crList) {
|
|
|
788 |
if (!partnerEmailSalesMap.containsKey(cr.getEmail())) {
|
|
|
789 |
partnerEmailSalesMap.put(cr.getEmail(), new SaleRoles());
|
|
|
790 |
}
|
|
|
791 |
SaleRoles saleRoles = partnerEmailSalesMap.get(cr.getEmail());
|
|
|
792 |
AuthUser authUser = authUsersMap.get(position.getAuthUserId());
|
| 26059 |
amit.gupta |
793 |
if(authUser==null) {
|
|
|
794 |
continue;
|
|
|
795 |
}
|
| 25598 |
amit.gupta |
796 |
String name = authUser.getFirstName() + " " + authUser.getLastName();
|
|
|
797 |
if (position.getEscalationType().equals(EscalationType.L1)) {
|
|
|
798 |
saleRoles.getL1().add(name);
|
|
|
799 |
} else if (position.getEscalationType().equals(EscalationType.L2)) {
|
|
|
800 |
saleRoles.getL2().add(name);
|
|
|
801 |
}
|
|
|
802 |
}
|
|
|
803 |
}
|
| 25837 |
amit.gupta |
804 |
|
|
|
805 |
Set<CustomRetailer> allCrList = new HashSet<>();
|
|
|
806 |
for (List<CustomRetailer> cr : positionIdRetailerMap.values()) {
|
|
|
807 |
allCrList.addAll(cr);
|
|
|
808 |
}
|
|
|
809 |
|
|
|
810 |
Map<Integer, FofoStore> fofoStoresMap = fofoStoreRepository.selectActiveStores().stream()
|
|
|
811 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
812 |
|
|
|
813 |
Map<Integer, List<Serializable>> partnerIdSalesHeadersMap = new HashMap<>();
|
|
|
814 |
|
|
|
815 |
for (CustomRetailer cr : allCrList) {
|
|
|
816 |
FofoStore fofoStore = fofoStoresMap.get(cr.getPartnerId());
|
| 25927 |
amit.gupta |
817 |
if (fofoStore == null) {
|
| 25870 |
amit.gupta |
818 |
LOGGER.info("Could not find Store {} in active Store", cr.getBusinessName());
|
|
|
819 |
continue;
|
|
|
820 |
}
|
| 25865 |
amit.gupta |
821 |
String code = fofoStore.getCode() + "";
|
| 25837 |
amit.gupta |
822 |
String storeName = "SmartDukaan-" + fofoStore.getCode().replaceAll("[a-zA-Z]", "");
|
|
|
823 |
String businessName = cr.getBusinessName();
|
|
|
824 |
try {
|
|
|
825 |
String stateManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL2(), ", ");
|
|
|
826 |
String territoryManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL1(), ", ");
|
|
|
827 |
List<Serializable> row = new ArrayList<>(
|
|
|
828 |
Arrays.asList(code, businessName, storeName, stateManager, territoryManager));
|
|
|
829 |
partnerIdSalesHeadersMap.put(cr.getPartnerId(), row);
|
|
|
830 |
|
|
|
831 |
} catch (Exception e) {
|
|
|
832 |
LOGGER.warn("Could not find partner with email - {}", cr.getEmail());
|
|
|
833 |
}
|
|
|
834 |
}
|
|
|
835 |
return partnerIdSalesHeadersMap;
|
|
|
836 |
|
| 25598 |
amit.gupta |
837 |
}
|
|
|
838 |
|
| 24271 |
amit.gupta |
839 |
public void sendPartnerInvestmentDetails() throws Exception {
|
| 25565 |
amit.gupta |
840 |
this.sendPartnerInvestmentDetails(null);
|
| 24271 |
amit.gupta |
841 |
}
|
|
|
842 |
|
| 25312 |
amit.gupta |
843 |
public void sendTargetVsSalesReport(List<String> sendTo) throws Exception {
|
| 24177 |
govind |
844 |
|
| 25312 |
amit.gupta |
845 |
if (sendTo == null) {
|
| 25827 |
amit.gupta |
846 |
sendTo = Arrays.asList("tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com",
|
|
|
847 |
"amit.gupta@shop2020.in", "amod.sen@smartdukaan.com", "prakash.rai@smartdukaan.com");
|
| 25312 |
amit.gupta |
848 |
}
|
| 25837 |
amit.gupta |
849 |
Map<Integer, List<Serializable>> partnerSalesTargetRowsMap = targetService.getDailySaleReportVsTarget();
|
| 25315 |
amit.gupta |
850 |
|
| 25837 |
amit.gupta |
851 |
Map<Integer, List<Serializable>> partnerIdSalesHeadersMap = this.getPartnerIdSalesHeaders();
|
| 24177 |
govind |
852 |
|
| 25837 |
amit.gupta |
853 |
List<String> headers = Arrays.asList("Code", "Firm Name", "Store Name", "State Manager", "Teritory Manager",
|
|
|
854 |
"Current Category", "Target Value", "Target Achieved", "Achived Percentage", "Remaining Target",
|
|
|
855 |
"Today's Target", "Today's achievement");
|
| 25609 |
amit.gupta |
856 |
|
| 25837 |
amit.gupta |
857 |
List<List<?>> rows = new ArrayList<>();
|
|
|
858 |
Map<Integer, List<? extends Serializable>> partnerRowMap = new HashMap<>();
|
|
|
859 |
for (Map.Entry<Integer, List<Serializable>> partnerSalesTargetRowEntry : partnerSalesTargetRowsMap.entrySet()) {
|
|
|
860 |
List<Serializable> row = partnerIdSalesHeadersMap.get(partnerSalesTargetRowEntry.getKey());
|
|
|
861 |
if (row == null) {
|
|
|
862 |
LOGGER.warn("Could not find headers for partner ID - {}", partnerSalesTargetRowEntry.getKey());
|
| 25315 |
amit.gupta |
863 |
}
|
| 25837 |
amit.gupta |
864 |
row.addAll(partnerSalesTargetRowEntry.getValue());
|
|
|
865 |
partnerRowMap.put(partnerSalesTargetRowEntry.getKey(), row);
|
|
|
866 |
rows.add(row);
|
| 24177 |
govind |
867 |
}
|
| 25503 |
amit.gupta |
868 |
|
| 25318 |
amit.gupta |
869 |
String fileName = "TargetVsSales-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
| 25894 |
amit.gupta |
870 |
Map<String, Set<String>> storeGuysMap = csService.getAuthUserPartnerEmailMapping();
|
|
|
871 |
for (Map.Entry<String, Set<String>> storeGuyEntry : storeGuysMap.entrySet()) {
|
| 25827 |
amit.gupta |
872 |
if (storeGuyEntry.getValue().size() == 0)
|
|
|
873 |
continue;
|
| 25927 |
amit.gupta |
874 |
List<List<?>> storeGuyRows = storeGuyEntry.getValue().stream().filter(x -> partnerRowMap.containsKey(x))
|
|
|
875 |
.map(x -> partnerRowMap.get(x)).collect(Collectors.toList());
|
| 25827 |
amit.gupta |
876 |
ByteArrayOutputStream authUserStream = FileUtil.getCSVByteStream(headers, storeGuyRows);
|
|
|
877 |
Attachment attache = new Attachment(fileName, new ByteArrayResource(authUserStream.toByteArray()));
|
|
|
878 |
System.out.println(storeGuyEntry.getValue());
|
|
|
879 |
Utils.sendMailWithAttachments(googleMailSender, new String[] { storeGuyEntry.getKey() }, null,
|
|
|
880 |
"Franchise Stock Report", "PFA", attache);
|
|
|
881 |
}
|
| 24240 |
amit.gupta |
882 |
|
| 25312 |
amit.gupta |
883 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
|
|
884 |
String[] sendToArray = sendTo.toArray(new String[sendTo.size()]);
|
|
|
885 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Target vs Sales Summary", "PFA", fileName,
|
|
|
886 |
new ByteArrayResource(baos.toByteArray()));
|
| 24174 |
govind |
887 |
}
|
| 24683 |
amit.gupta |
888 |
|
| 24697 |
amit.gupta |
889 |
public void sendAgeingReport(String... sendTo) throws Exception {
|
| 24692 |
amit.gupta |
890 |
|
|
|
891 |
InputStreamSource isr = reporticoService.getReportInputStreamSource(ReporticoProject.WAREHOUSENEW,
|
|
|
892 |
"itemstockageing.xml");
|
| 24708 |
amit.gupta |
893 |
InputStreamSource isr1 = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
|
| 24754 |
amit.gupta |
894 |
"ItemwiseOverallPendingIndent.xml");
|
| 24683 |
amit.gupta |
895 |
Attachment attachment = new Attachment(
|
| 25445 |
amit.gupta |
896 |
"ageing-report-" + FormattingUtils.formatDate(LocalDateTime.now().minusDays(1)) + ".csv", isr);
|
| 24707 |
amit.gupta |
897 |
Attachment attachment1 = new Attachment(
|
| 25445 |
amit.gupta |
898 |
"pending-indent-" + FormattingUtils.formatDate(LocalDateTime.now().minusDays(1)) + ".csv", isr1);
|
| 25418 |
amit.gupta |
899 |
|
| 25609 |
amit.gupta |
900 |
Utils.sendMailWithAttachments(googleMailSender, STOCK_AGEING_MAIL_LIST, null, "Stock Ageing Report", "PFA",
|
|
|
901 |
attachment);
|
|
|
902 |
Utils.sendMailWithAttachments(googleMailSender, ITEMWISE_PENDING_INDENT_MAIL_LIST, null,
|
|
|
903 |
"Itemwise Pending indent", "PFA", attachment1);
|
|
|
904 |
|
| 25598 |
amit.gupta |
905 |
// Reports to be sent to mapped partners
|
| 25597 |
amit.gupta |
906 |
Map<String, Set<String>> storeGuysMap = csService.getAuthUserPartnerEmailMapping();
|
| 25503 |
amit.gupta |
907 |
|
|
|
908 |
for (Map.Entry<String, Set<String>> storeGuyEntry : storeGuysMap.entrySet()) {
|
| 25418 |
amit.gupta |
909 |
Map<String, String> params = new HashMap<>();
|
| 25503 |
amit.gupta |
910 |
if (storeGuyEntry.getValue().size() == 0)
|
|
|
911 |
continue;
|
| 25418 |
amit.gupta |
912 |
params.put("MANUAL_email", String.join(",", storeGuyEntry.getValue()));
|
|
|
913 |
InputStreamSource isr3 = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
|
|
|
914 |
"focostockreport.xml", params);
|
|
|
915 |
Attachment attache = new Attachment(
|
| 25609 |
amit.gupta |
916 |
"Franchise-stock-report" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv", isr3);
|
| 25584 |
amit.gupta |
917 |
System.out.println(storeGuyEntry.getValue());
|
| 25609 |
amit.gupta |
918 |
Utils.sendMailWithAttachments(googleMailSender, new String[] { storeGuyEntry.getKey() }, null,
|
|
|
919 |
"Franchise Stock Report", "PFA", attache);
|
| 25418 |
amit.gupta |
920 |
}
|
| 25503 |
amit.gupta |
921 |
|
| 24681 |
amit.gupta |
922 |
}
|
| 24533 |
govind |
923 |
|
| 24697 |
amit.gupta |
924 |
public void sendAgeingReport() throws Exception {
|
| 25807 |
amit.gupta |
925 |
sendAgeingReport("kamini.sharma@smartdukaan.com", "prakash.rai@smartdukaan.com", "tarun.verma@smartdukaan.com",
|
| 25609 |
amit.gupta |
926 |
"chaitnaya.vats@smartdukaan.com");
|
| 24697 |
amit.gupta |
927 |
}
|
|
|
928 |
|
| 24533 |
govind |
929 |
public void moveImeisToPriceDropImeis() throws Exception {
|
| 24431 |
amit.gupta |
930 |
List<PriceDrop> priceDrops = priceDropRepository.selectAll();
|
| 24533 |
govind |
931 |
for (PriceDrop priceDrop : priceDrops) {
|
| 24431 |
amit.gupta |
932 |
priceDropService.priceDropStatus(priceDrop.getId());
|
|
|
933 |
}
|
|
|
934 |
}
|
| 23929 |
amit.gupta |
935 |
|
| 24542 |
amit.gupta |
936 |
public void walletmismatch() throws Exception {
|
|
|
937 |
LocalDate curDate = LocalDate.now();
|
| 24553 |
amit.gupta |
938 |
List<PartnerDailyInvestment> pdis = partnerDailyInvestmentRepository.selectAll(curDate.minusDays(2));
|
| 24552 |
amit.gupta |
939 |
System.out.println(pdis.size());
|
| 24542 |
amit.gupta |
940 |
for (PartnerDailyInvestment pdi : pdis) {
|
| 24549 |
amit.gupta |
941 |
int fofoId = pdi.getFofoId();
|
| 24542 |
amit.gupta |
942 |
for (PartnerDailyInvestment investment : Lists
|
|
|
943 |
.reverse(partnerDailyInvestmentRepository.selectAll(fofoId, null, null))) {
|
| 24552 |
amit.gupta |
944 |
float statementAmount = walletService.getOpeningTill(fofoId,
|
| 24555 |
amit.gupta |
945 |
investment.getDate().plusDays(1).atTime(LocalTime.of(4, 0)));
|
| 24552 |
amit.gupta |
946 |
CustomRetailer retailer = retailerService.getFofoRetailer(fofoId);
|
| 24841 |
govind |
947 |
LOGGER.info("{}\t{}\t{}\t{}\t{}", fofoId, retailer.getBusinessName(), retailer.getMobileNumber(),
|
|
|
948 |
investment.getDate().toString(), investment.getWalletAmount(), statementAmount);
|
| 24551 |
amit.gupta |
949 |
|
| 24542 |
amit.gupta |
950 |
}
|
| 24549 |
amit.gupta |
951 |
}
|
| 24542 |
amit.gupta |
952 |
|
|
|
953 |
}
|
|
|
954 |
|
|
|
955 |
public void gst() throws Exception {
|
| 24548 |
amit.gupta |
956 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectBetweenSaleDate(LocalDate.of(2019, 1, 26).atStartOfDay(),
|
|
|
957 |
LocalDate.of(2019, 1, 27).atTime(LocalTime.MAX));
|
|
|
958 |
for (FofoOrder fofoOrder : fofoOrders) {
|
|
|
959 |
int retailerAddressId = retailerRegisteredAddressRepository
|
|
|
960 |
.selectAddressIdByRetailerId(fofoOrder.getFofoId());
|
| 24542 |
amit.gupta |
961 |
|
|
|
962 |
Address retailerAddress = addressRepository.selectById(retailerAddressId);
|
|
|
963 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
|
|
964 |
Integer stateId = null;
|
|
|
965 |
if (customerAddress.getState().equals(retailerAddress.getState())) {
|
|
|
966 |
try {
|
|
|
967 |
stateId = Long.valueOf(Utils.getStateInfo(customerAddress.getState()).getId()).intValue();
|
|
|
968 |
} catch (Exception e) {
|
|
|
969 |
LOGGER.error("Unable to get state rates");
|
|
|
970 |
}
|
|
|
971 |
}
|
|
|
972 |
Map<Integer, GstRate> itemIdStateTaxRateMap = null;
|
|
|
973 |
Map<Integer, Float> itemIdIgstTaxRateMap = null;
|
| 24548 |
amit.gupta |
974 |
|
|
|
975 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
|
|
976 |
Set<Integer> itemIds = fofoOrderItems.stream().map(x -> x.getItemId()).collect(Collectors.toSet());
|
| 24542 |
amit.gupta |
977 |
if (stateId != null) {
|
|
|
978 |
itemIdStateTaxRateMap = Utils.getStateTaxRate(new ArrayList<>(itemIds), stateId);
|
|
|
979 |
} else {
|
|
|
980 |
itemIdIgstTaxRateMap = Utils.getIgstTaxRate(new ArrayList<>(itemIds));
|
|
|
981 |
}
|
|
|
982 |
|
| 24548 |
amit.gupta |
983 |
for (FofoOrderItem foi : fofoOrderItems) {
|
| 24542 |
amit.gupta |
984 |
if (stateId == null) {
|
|
|
985 |
foi.setIgstRate(itemIdIgstTaxRateMap.get(foi.getItemId()));
|
|
|
986 |
} else {
|
|
|
987 |
foi.setCgstRate(itemIdStateTaxRateMap.get(foi.getItemId()).getCgstRate());
|
|
|
988 |
foi.setSgstRate(itemIdStateTaxRateMap.get(foi.getItemId()).getSgstRate());
|
|
|
989 |
}
|
|
|
990 |
fofoOrderItemRepository.persist(foi);
|
|
|
991 |
}
|
|
|
992 |
}
|
| 24548 |
amit.gupta |
993 |
|
| 24542 |
amit.gupta |
994 |
}
|
|
|
995 |
|
| 24580 |
amit.gupta |
996 |
public void schemewalletmismatch() {
|
|
|
997 |
LocalDate dateToReconcile = LocalDate.of(2018, 4, 1);
|
| 24587 |
amit.gupta |
998 |
while (dateToReconcile.isBefore(LocalDate.now())) {
|
| 24580 |
amit.gupta |
999 |
reconcileSchemes(dateToReconcile);
|
| 24587 |
amit.gupta |
1000 |
// reconcileOrders(dateTime);
|
|
|
1001 |
// reconcileRecharges(dateTime);
|
| 24580 |
amit.gupta |
1002 |
dateToReconcile = dateToReconcile.plusDays(1);
|
|
|
1003 |
}
|
|
|
1004 |
}
|
|
|
1005 |
|
|
|
1006 |
private void reconcileSchemes(LocalDate date) {
|
|
|
1007 |
LocalDateTime startDate = date.atStartOfDay();
|
|
|
1008 |
LocalDateTime endDate = startDate.plusDays(1);
|
|
|
1009 |
List<SchemeInOut> siosCreated = schemeInOutRepository.selectAllByCreateDate(startDate, endDate);
|
|
|
1010 |
List<SchemeInOut> siosRefunded = schemeInOutRepository.selectAllByRefundDate(startDate, endDate);
|
| 24587 |
amit.gupta |
1011 |
double totalSchemeDisbursed = siosCreated.stream().mapToDouble(x -> x.getAmount()).sum();
|
|
|
1012 |
double totalSchemeRolledback = siosRefunded.stream().mapToDouble(x -> x.getAmount()).sum();
|
| 24580 |
amit.gupta |
1013 |
double netSchemeDisbursed = totalSchemeDisbursed - totalSchemeRolledback;
|
| 24587 |
amit.gupta |
1014 |
List<WalletReferenceType> walletReferenceTypes = Arrays.asList(WalletReferenceType.SCHEME_IN,
|
|
|
1015 |
WalletReferenceType.SCHEME_OUT);
|
|
|
1016 |
List<UserWalletHistory> history = userWalletHistoryRepository.selectAllByDateType(startDate, endDate,
|
|
|
1017 |
walletReferenceTypes);
|
|
|
1018 |
double schemeAmountWalletTotal = history.stream().mapToDouble(x -> x.getAmount()).sum();
|
|
|
1019 |
if (Math.abs(netSchemeDisbursed - schemeAmountWalletTotal) > 10d) {
|
| 24580 |
amit.gupta |
1020 |
LOGGER.info("Scheme Amount mismatched for Date {}", date);
|
| 24587 |
amit.gupta |
1021 |
|
|
|
1022 |
Map<Integer, Double> inventoryItemSchemeIO = siosCreated.stream().collect(Collectors
|
|
|
1023 |
.groupingBy(x -> x.getInventoryItemId(), Collectors.summingDouble(SchemeInOut::getAmount)));
|
|
|
1024 |
|
|
|
1025 |
Map<Integer, Double> userSchemeMap = inventoryItemRepository.selectByIds(inventoryItemSchemeIO.keySet())
|
|
|
1026 |
.stream().collect(Collectors.groupingBy(x -> x.getFofoId(),
|
|
|
1027 |
Collectors.summingDouble(x -> inventoryItemSchemeIO.get(x.getId()))));
|
|
|
1028 |
|
|
|
1029 |
Map<Integer, Double> inventoryItemSchemeIORefunded = siosRefunded.stream().collect(Collectors
|
|
|
1030 |
.groupingBy(x -> x.getInventoryItemId(), Collectors.summingDouble(SchemeInOut::getAmount)));
|
|
|
1031 |
|
|
|
1032 |
Map<Integer, Double> userSchemeRefundedMap = inventoryItemRepository
|
|
|
1033 |
.selectByIds(inventoryItemSchemeIORefunded.keySet()).stream()
|
|
|
1034 |
.collect(Collectors.groupingBy(x -> x.getFofoId(),
|
|
|
1035 |
Collectors.summingDouble(x -> inventoryItemSchemeIORefunded.get(x.getId()))));
|
|
|
1036 |
|
|
|
1037 |
Map<Integer, Double> finalUserSchemeAmountMap = new HashMap<>();
|
| 26092 |
amit.gupta |
1038 |
|
| 24587 |
amit.gupta |
1039 |
for (Map.Entry<Integer, Double> schemeAmount : userSchemeRefundedMap.entrySet()) {
|
|
|
1040 |
if (!finalUserSchemeAmountMap.containsKey(schemeAmount.getKey())) {
|
|
|
1041 |
finalUserSchemeAmountMap.put(schemeAmount.getKey(), schemeAmount.getValue());
|
|
|
1042 |
} else {
|
|
|
1043 |
finalUserSchemeAmountMap.put(schemeAmount.getKey(),
|
|
|
1044 |
finalUserSchemeAmountMap.get(schemeAmount.getKey()) + schemeAmount.getValue());
|
|
|
1045 |
}
|
|
|
1046 |
}
|
| 24590 |
amit.gupta |
1047 |
Map<Integer, Integer> userWalletMap = userWalletRepository
|
|
|
1048 |
.selectByRetailerIds(finalUserSchemeAmountMap.keySet()).stream()
|
|
|
1049 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
|
|
1050 |
|
| 24587 |
amit.gupta |
1051 |
Map<Integer, Double> walletAmountMap = history.stream().collect(Collectors.groupingBy(
|
|
|
1052 |
UserWalletHistory::getWalletId, Collectors.summingDouble((UserWalletHistory::getAmount))));
|
|
|
1053 |
for (Map.Entry<Integer, Double> userAmount : walletAmountMap.entrySet()) {
|
|
|
1054 |
double diff = Math.abs(finalUserSchemeAmountMap.get(userAmount.getKey()) - userAmount.getValue());
|
|
|
1055 |
if (diff > 5) {
|
|
|
1056 |
LOGGER.info("Partner scheme mismatched for Userid {}", userWalletMap.get(userAmount.getKey()));
|
|
|
1057 |
}
|
|
|
1058 |
}
|
| 24580 |
amit.gupta |
1059 |
}
|
| 24587 |
amit.gupta |
1060 |
|
| 24580 |
amit.gupta |
1061 |
}
|
| 24590 |
amit.gupta |
1062 |
|
| 24592 |
amit.gupta |
1063 |
public void dryRunSchemeReco() throws Exception {
|
| 24635 |
amit.gupta |
1064 |
Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
|
|
|
1065 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
|
|
1066 |
|
| 24592 |
amit.gupta |
1067 |
List<UserWalletHistory> userWalletHistory = new ArrayList<>();
|
|
|
1068 |
List<SchemeInOut> rolledbackSios = new ArrayList<>();
|
| 24635 |
amit.gupta |
1069 |
Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
|
|
|
1070 |
.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
|
|
|
1071 |
Set<String> serialNumbersConsidered = new HashSet<>();
|
|
|
1072 |
|
| 25096 |
amit.gupta |
1073 |
LocalDateTime startDate = LocalDate.of(2018, 3, 1).atStartOfDay();
|
| 24635 |
amit.gupta |
1074 |
LocalDateTime endDate = LocalDate.now().atStartOfDay();
|
|
|
1075 |
List<Purchase> purchases = purchaseRepository.selectAllBetweenPurchaseDate(startDate, endDate);
|
|
|
1076 |
|
| 24683 |
amit.gupta |
1077 |
Map<Integer, String> storeNameMap = fofoStoreRepository.getStoresMap();
|
| 24635 |
amit.gupta |
1078 |
purchases.stream().forEach(purchase -> {
|
|
|
1079 |
float amountToRollback = 0;
|
|
|
1080 |
String description = "Adjustment of Duplicate Scheme for Purchase Invoice "
|
|
|
1081 |
+ purchase.getPurchaseReference();
|
|
|
1082 |
Map<Integer, String> inventorySerialNumberMap = inventoryItemRepository.selectByPurchaseId(purchase.getId())
|
|
|
1083 |
.stream().filter(ii -> ii.getSerialNumber() != null)
|
|
|
1084 |
.collect(Collectors.toMap(InventoryItem::getId, InventoryItem::getSerialNumber));
|
|
|
1085 |
if (inventorySerialNumberMap.size() > 0) {
|
|
|
1086 |
for (Map.Entry<Integer, String> inventorySerialNumberEntry : inventorySerialNumberMap.entrySet()) {
|
|
|
1087 |
String serialNumber = inventorySerialNumberEntry.getValue();
|
|
|
1088 |
int inventoryItemId = inventorySerialNumberEntry.getKey();
|
|
|
1089 |
if (serialNumbersConsidered.contains(serialNumber)) {
|
|
|
1090 |
// This will rollback scheme for differenct orders for same serial
|
|
|
1091 |
List<SchemeInOut> sios = schemeInOutRepository
|
|
|
1092 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
|
|
1093 |
.filter(x -> x.getRolledBackTimestamp() == null
|
|
|
1094 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.IN))
|
|
|
1095 |
.collect(Collectors.toList());
|
|
|
1096 |
Collections.reverse(sios);
|
|
|
1097 |
for (SchemeInOut sio : sios) {
|
|
|
1098 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
|
|
1099 |
amountToRollback += sio.getAmount();
|
|
|
1100 |
// sio.setSchemeType(SchemeType.OUT);
|
|
|
1101 |
sio.setSerialNumber(serialNumber);
|
|
|
1102 |
rolledbackSios.add(sio);
|
|
|
1103 |
}
|
|
|
1104 |
description = description.concat(" " + serialNumber + " ");
|
|
|
1105 |
} else {
|
|
|
1106 |
serialNumbersConsidered.add(serialNumber);
|
|
|
1107 |
List<Integer> schemesConsidered = new ArrayList<>();
|
|
|
1108 |
List<SchemeInOut> sios = schemeInOutRepository
|
|
|
1109 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
|
|
1110 |
.filter(x -> x.getRolledBackTimestamp() == null
|
|
|
1111 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.IN))
|
|
|
1112 |
.collect(Collectors.toList());
|
|
|
1113 |
Collections.reverse(sios);
|
|
|
1114 |
for (SchemeInOut sio : sios) {
|
|
|
1115 |
if (!schemesConsidered.contains(sio.getSchemeId())) {
|
|
|
1116 |
schemesConsidered.add(sio.getSchemeId());
|
|
|
1117 |
continue;
|
|
|
1118 |
}
|
|
|
1119 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
|
|
1120 |
amountToRollback += sio.getAmount();
|
|
|
1121 |
// sio.setSchemeType(SchemeType.OUT);
|
|
|
1122 |
sio.setSerialNumber(serialNumber);
|
| 24681 |
amit.gupta |
1123 |
sio.setStoreCode(storeNameMap.get(purchase.getFofoId()));
|
|
|
1124 |
sio.setReference(purchase.getId());
|
| 24635 |
amit.gupta |
1125 |
rolledbackSios.add(sio);
|
|
|
1126 |
}
|
|
|
1127 |
}
|
|
|
1128 |
|
|
|
1129 |
}
|
|
|
1130 |
}
|
|
|
1131 |
if (amountToRollback > 0) {
|
| 24683 |
amit.gupta |
1132 |
// Address address =
|
|
|
1133 |
// addressRepository.selectAllByRetailerId(purchase.getFofoId(), 0, 10).get(0);
|
| 24635 |
amit.gupta |
1134 |
UserWalletHistory uwh = new UserWalletHistory();
|
|
|
1135 |
uwh.setAmount(Math.round(amountToRollback));
|
|
|
1136 |
uwh.setDescription(description);
|
|
|
1137 |
uwh.setTimestamp(LocalDateTime.now());
|
| 24681 |
amit.gupta |
1138 |
uwh.setReferenceType(WalletReferenceType.SCHEME_IN);
|
| 24635 |
amit.gupta |
1139 |
uwh.setReference(purchase.getId());
|
|
|
1140 |
uwh.setWalletId(userWalletMap.get(purchase.getFofoId()));
|
|
|
1141 |
uwh.setFofoId(purchase.getFofoId());
|
| 24681 |
amit.gupta |
1142 |
uwh.setStoreCode(storeNameMap.get(purchase.getFofoId()));
|
| 24635 |
amit.gupta |
1143 |
userWalletHistory.add(uwh);
|
|
|
1144 |
}
|
|
|
1145 |
});
|
|
|
1146 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
|
|
1147 |
Arrays.asList("User Id", "Store Code", "Reference Type", "Reference", "Amount", "Description",
|
|
|
1148 |
"Timestamp"),
|
|
|
1149 |
userWalletHistory.stream()
|
|
|
1150 |
.map(x -> Arrays.asList(x.getWalletId(), x.getStoreCode(), x.getReferenceType(),
|
|
|
1151 |
x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
|
|
|
1152 |
.collect(Collectors.toList()));
|
|
|
1153 |
|
|
|
1154 |
ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
|
| 24683 |
amit.gupta |
1155 |
Arrays.asList("Scheme ID", "SchemeType", "Reference", "Store Code", "Serial Number", "Amount",
|
|
|
1156 |
"Created", "Rolledback"),
|
| 24635 |
amit.gupta |
1157 |
rolledbackSios.stream()
|
| 24681 |
amit.gupta |
1158 |
.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getReference(), x.getStoreCode(),
|
| 24635 |
amit.gupta |
1159 |
x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
|
|
|
1160 |
.collect(Collectors.toList()));
|
|
|
1161 |
|
| 25043 |
amit.gupta |
1162 |
Utils.sendMailWithAttachments(googleMailSender, new String[] { "amit.gupta@shop2020.in" }, null,
|
| 24636 |
amit.gupta |
1163 |
"Partner Excess Amount Scheme In", "PFA",
|
| 24635 |
amit.gupta |
1164 |
new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
|
| 24636 |
amit.gupta |
1165 |
new Attachment("SchemeInRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
|
| 24635 |
amit.gupta |
1166 |
|
| 25096 |
amit.gupta |
1167 |
throw new Exception();
|
| 24635 |
amit.gupta |
1168 |
|
|
|
1169 |
}
|
|
|
1170 |
|
|
|
1171 |
public void dryRunOutSchemeReco() throws Exception {
|
|
|
1172 |
List<UserWalletHistory> userWalletHistory = new ArrayList<>();
|
|
|
1173 |
List<SchemeInOut> rolledbackSios = new ArrayList<>();
|
| 24606 |
amit.gupta |
1174 |
Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
|
|
|
1175 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
| 24590 |
amit.gupta |
1176 |
Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
|
|
|
1177 |
.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
|
| 25028 |
amit.gupta |
1178 |
LocalDateTime startDate = LocalDate.of(2019, 5, 1).atStartOfDay();
|
| 24632 |
amit.gupta |
1179 |
LocalDateTime endDate = LocalDate.now().atStartOfDay();
|
| 24631 |
amit.gupta |
1180 |
List<FofoOrder> allOrders = fofoOrderRepository.selectBetweenSaleDate(startDate, endDate);
|
|
|
1181 |
// Collections.reverse(allOrders);
|
|
|
1182 |
// List<FofoOrder> allOrders =
|
| 24653 |
govind |
1183 |
// List<FofoOrder> allOrders =
|
| 24631 |
amit.gupta |
1184 |
// Arrays.asList(fofoOrderRepository.selectByInvoiceNumber("UPGZ019/25"));
|
| 24625 |
amit.gupta |
1185 |
Set<String> serialNumbersConsidered = new HashSet<>();
|
| 24590 |
amit.gupta |
1186 |
allOrders.stream().forEach(fofoOrder -> {
|
| 24592 |
amit.gupta |
1187 |
String description = "Adjustment of Duplicate Scheme for Sale Invoice " + fofoOrder.getInvoiceNumber();
|
| 24598 |
amit.gupta |
1188 |
Map<Integer, String> inventorySerialNumberMap = new HashMap<>();
|
| 24592 |
amit.gupta |
1189 |
float amountToRollback = 0;
|
| 24590 |
amit.gupta |
1190 |
List<FofoOrderItem> orderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
|
|
1191 |
orderItems.forEach(x -> {
|
| 24606 |
amit.gupta |
1192 |
inventorySerialNumberMap.putAll(x.getFofoLineItems().stream().filter(li -> li.getSerialNumber() != null)
|
| 24598 |
amit.gupta |
1193 |
.collect(Collectors.toMap(FofoLineItem::getInventoryItemId, FofoLineItem::getSerialNumber)));
|
| 24590 |
amit.gupta |
1194 |
});
|
| 24606 |
amit.gupta |
1195 |
if (inventorySerialNumberMap.size() > 0) {
|
| 24631 |
amit.gupta |
1196 |
for (Map.Entry<Integer, String> inventorySerialNumberEntry : inventorySerialNumberMap.entrySet()) {
|
|
|
1197 |
String serialNumber = inventorySerialNumberEntry.getValue();
|
|
|
1198 |
int inventoryItemId = inventorySerialNumberEntry.getKey();
|
|
|
1199 |
if (serialNumbersConsidered.contains(serialNumber)) {
|
|
|
1200 |
// This will rollback scheme for differenct orders for same serial
|
|
|
1201 |
List<SchemeInOut> sios = schemeInOutRepository
|
| 24633 |
amit.gupta |
1202 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
| 24635 |
amit.gupta |
1203 |
.filter(x -> x.getRolledBackTimestamp() == null
|
|
|
1204 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
|
| 24631 |
amit.gupta |
1205 |
.collect(Collectors.toList());
|
|
|
1206 |
Collections.reverse(sios);
|
|
|
1207 |
for (SchemeInOut sio : sios) {
|
|
|
1208 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
|
|
1209 |
amountToRollback += sio.getAmount();
|
|
|
1210 |
// sio.setSchemeType(SchemeType.OUT);
|
|
|
1211 |
sio.setSerialNumber(serialNumber);
|
|
|
1212 |
sio.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
| 24681 |
amit.gupta |
1213 |
sio.setReference(fofoOrder.getId());
|
| 24631 |
amit.gupta |
1214 |
rolledbackSios.add(sio);
|
| 24623 |
amit.gupta |
1215 |
}
|
| 24635 |
amit.gupta |
1216 |
description = description.concat(" " + serialNumber + " ");
|
| 24631 |
amit.gupta |
1217 |
} else {
|
|
|
1218 |
serialNumbersConsidered.add(serialNumber);
|
|
|
1219 |
List<Integer> schemesConsidered = new ArrayList<>();
|
|
|
1220 |
List<SchemeInOut> sios = schemeInOutRepository
|
| 24633 |
amit.gupta |
1221 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItemId))).stream()
|
| 24635 |
amit.gupta |
1222 |
.filter(x -> x.getRolledBackTimestamp() == null
|
|
|
1223 |
&& schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
|
| 24631 |
amit.gupta |
1224 |
.collect(Collectors.toList());
|
|
|
1225 |
Collections.reverse(sios);
|
|
|
1226 |
for (SchemeInOut sio : sios) {
|
|
|
1227 |
if (!schemesConsidered.contains(sio.getSchemeId())) {
|
|
|
1228 |
schemesConsidered.add(sio.getSchemeId());
|
|
|
1229 |
continue;
|
|
|
1230 |
}
|
|
|
1231 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
|
|
1232 |
amountToRollback += sio.getAmount();
|
|
|
1233 |
// sio.setSchemeType(SchemeType.OUT);
|
| 24681 |
amit.gupta |
1234 |
sio.setReference(fofoOrder.getId());
|
| 24631 |
amit.gupta |
1235 |
sio.setSerialNumber(serialNumber);
|
|
|
1236 |
sio.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
|
|
1237 |
rolledbackSios.add(sio);
|
|
|
1238 |
}
|
| 24615 |
amit.gupta |
1239 |
}
|
| 24631 |
amit.gupta |
1240 |
|
| 24604 |
amit.gupta |
1241 |
}
|
| 24590 |
amit.gupta |
1242 |
}
|
| 24631 |
amit.gupta |
1243 |
if (amountToRollback > 0) {
|
|
|
1244 |
UserWalletHistory uwh = new UserWalletHistory();
|
|
|
1245 |
uwh.setAmount(Math.round(amountToRollback));
|
|
|
1246 |
uwh.setDescription(description);
|
|
|
1247 |
uwh.setTimestamp(LocalDateTime.now());
|
|
|
1248 |
uwh.setReferenceType(WalletReferenceType.SCHEME_OUT);
|
|
|
1249 |
uwh.setReference(fofoOrder.getId());
|
|
|
1250 |
uwh.setWalletId(userWalletMap.get(fofoOrder.getFofoId()));
|
|
|
1251 |
uwh.setFofoId(fofoOrder.getFofoId());
|
|
|
1252 |
uwh.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
|
|
1253 |
userWalletHistory.add(uwh);
|
|
|
1254 |
}
|
| 24590 |
amit.gupta |
1255 |
});
|
| 24598 |
amit.gupta |
1256 |
|
| 24592 |
amit.gupta |
1257 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
| 24681 |
amit.gupta |
1258 |
Arrays.asList("Wallet Id", "Store Code", "Reference Type", "Reference", "Amount", "Description",
|
| 24615 |
amit.gupta |
1259 |
"Timestamp"),
|
|
|
1260 |
userWalletHistory.stream()
|
|
|
1261 |
.map(x -> Arrays.asList(x.getWalletId(), x.getStoreCode(), x.getReferenceType(),
|
|
|
1262 |
x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
|
| 24592 |
amit.gupta |
1263 |
.collect(Collectors.toList()));
|
|
|
1264 |
|
|
|
1265 |
ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
|
|
|
1266 |
Arrays.asList("Scheme ID", "SchemeType", "Store Code", "Serial Number", "Amount", "Created",
|
|
|
1267 |
"Rolledback"),
|
|
|
1268 |
rolledbackSios.stream()
|
|
|
1269 |
.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
|
|
|
1270 |
x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
|
|
|
1271 |
.collect(Collectors.toList()));
|
|
|
1272 |
|
| 25043 |
amit.gupta |
1273 |
Utils.sendMailWithAttachments(googleMailSender, new String[] { "amit.gupta@shop2020.in" }, null,
|
| 24681 |
amit.gupta |
1274 |
"Partner Excess Amount Scheme Out", "PFA",
|
| 24598 |
amit.gupta |
1275 |
new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
|
|
|
1276 |
new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
|
| 24631 |
amit.gupta |
1277 |
|
| 25267 |
amit.gupta |
1278 |
throw new Exception();
|
| 24590 |
amit.gupta |
1279 |
}
|
| 24615 |
amit.gupta |
1280 |
|
| 24611 |
amit.gupta |
1281 |
public void dryRunSchemeOutReco1() throws Exception {
|
| 24615 |
amit.gupta |
1282 |
List<Integer> references = Arrays.asList(6744, 7347, 8320, 8891, 9124, 9217, 9263, 9379);
|
| 24611 |
amit.gupta |
1283 |
List<UserWalletHistory> userWalletHistory = new ArrayList<>();
|
|
|
1284 |
List<SchemeInOut> rolledbackSios = new ArrayList<>();
|
|
|
1285 |
Map<Integer, Integer> userWalletMap = userWalletRepository.selectAll().stream()
|
|
|
1286 |
.collect(Collectors.toMap(UserWallet::getUserId, UserWallet::getId));
|
|
|
1287 |
Map<Integer, SchemeType> schemeTypeMap = schemeRepository.selectAll().stream()
|
|
|
1288 |
.collect(Collectors.toMap(Scheme::getId, Scheme::getType));
|
|
|
1289 |
references.stream().forEach(reference -> {
|
|
|
1290 |
FofoOrder fofoOrder = null;
|
|
|
1291 |
try {
|
|
|
1292 |
fofoOrder = fofoOrderRepository.selectByOrderId(reference);
|
| 24615 |
amit.gupta |
1293 |
} catch (Exception e) {
|
|
|
1294 |
|
| 24611 |
amit.gupta |
1295 |
}
|
|
|
1296 |
String description = "Adjustment of Duplicate Scheme for Sale Invoice " + fofoOrder.getInvoiceNumber();
|
|
|
1297 |
Map<Integer, String> inventorySerialNumberMap = new HashMap<>();
|
|
|
1298 |
float amountToRollback = 0;
|
|
|
1299 |
List<FofoOrderItem> orderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
|
|
1300 |
orderItems.forEach(x -> {
|
|
|
1301 |
inventorySerialNumberMap.putAll(x.getFofoLineItems().stream().filter(li -> li.getSerialNumber() != null)
|
|
|
1302 |
.collect(Collectors.toMap(FofoLineItem::getInventoryItemId, FofoLineItem::getSerialNumber)));
|
|
|
1303 |
});
|
|
|
1304 |
if (inventorySerialNumberMap.size() > 0) {
|
| 24615 |
amit.gupta |
1305 |
List<SchemeInOut> sios = schemeInOutRepository
|
|
|
1306 |
.selectByInventoryItemIds(inventorySerialNumberMap.keySet()).stream()
|
|
|
1307 |
.filter(x -> schemeTypeMap.get(x.getSchemeId()).equals(SchemeType.OUT))
|
| 24611 |
amit.gupta |
1308 |
.collect(Collectors.toList());
|
|
|
1309 |
LOGGER.info("Found {} duplicate schemeouts for Orderid {}", sios.size(), fofoOrder.getId());
|
|
|
1310 |
UserWalletHistory uwh = new UserWalletHistory();
|
| 24615 |
amit.gupta |
1311 |
Map<Integer, List<SchemeInOut>> inventoryIdSouts = sios.stream()
|
|
|
1312 |
.collect(Collectors.groupingBy(SchemeInOut::getInventoryItemId, Collectors.toList()));
|
| 24611 |
amit.gupta |
1313 |
for (Map.Entry<Integer, List<SchemeInOut>> inventorySioEntry : inventoryIdSouts.entrySet()) {
|
|
|
1314 |
List<SchemeInOut> outList = inventorySioEntry.getValue();
|
| 24615 |
amit.gupta |
1315 |
if (outList.size() > 1) {
|
|
|
1316 |
|
| 24611 |
amit.gupta |
1317 |
}
|
|
|
1318 |
}
|
|
|
1319 |
uwh.setAmount(Math.round(amountToRollback));
|
|
|
1320 |
uwh.setDescription(description);
|
|
|
1321 |
uwh.setTimestamp(LocalDateTime.now());
|
|
|
1322 |
uwh.setReferenceType(WalletReferenceType.SCHEME_OUT);
|
|
|
1323 |
uwh.setReference(fofoOrder.getId());
|
|
|
1324 |
uwh.setWalletId(userWalletMap.get(fofoOrder.getFofoId()));
|
|
|
1325 |
uwh.setFofoId(fofoOrder.getFofoId());
|
|
|
1326 |
uwh.setStoreCode(fofoOrder.getInvoiceNumber().split("/")[0]);
|
|
|
1327 |
userWalletHistory.add(uwh);
|
|
|
1328 |
}
|
|
|
1329 |
});
|
| 24615 |
amit.gupta |
1330 |
|
| 24611 |
amit.gupta |
1331 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
|
|
1332 |
Arrays.asList("User Id", "Reference Type", "Reference", "Amount", "Description", "Timestamp"),
|
|
|
1333 |
userWalletHistory.stream().map(x -> Arrays.asList(x.getWalletId(), x.getReferenceType(),
|
|
|
1334 |
x.getReference(), x.getAmount(), x.getDescription(), x.getTimestamp()))
|
| 24615 |
amit.gupta |
1335 |
.collect(Collectors.toList()));
|
|
|
1336 |
|
| 24611 |
amit.gupta |
1337 |
ByteArrayOutputStream baosOuts = FileUtil.getCSVByteStream(
|
|
|
1338 |
Arrays.asList("Scheme ID", "SchemeType", "Store Code", "Serial Number", "Amount", "Created",
|
|
|
1339 |
"Rolledback"),
|
|
|
1340 |
rolledbackSios.stream()
|
| 24615 |
amit.gupta |
1341 |
.map(x -> Arrays.asList(x.getSchemeId(), x.getSchemeType(), x.getStoreCode(),
|
|
|
1342 |
x.getSerialNumber(), x.getAmount(), x.getCreateTimestamp(), x.getRolledBackTimestamp()))
|
|
|
1343 |
.collect(Collectors.toList()));
|
|
|
1344 |
|
| 24623 |
amit.gupta |
1345 |
Utils.sendMailWithAttachments(googleMailSender,
|
|
|
1346 |
new String[] { "amit.gupta@shop2020.in", "neeraj.gupta@smartdukaan.com" }, null,
|
| 24611 |
amit.gupta |
1347 |
"Partner Excess Amount", "PFA",
|
|
|
1348 |
new Attachment[] { new Attachment("WalletSummary.csv", new ByteArrayResource(baos.toByteArray())),
|
|
|
1349 |
new Attachment("SchemeOutRolledback.csv", new ByteArrayResource(baosOuts.toByteArray())) });
|
| 24631 |
amit.gupta |
1350 |
|
| 24628 |
amit.gupta |
1351 |
throw new Exception();
|
| 24615 |
amit.gupta |
1352 |
|
| 24611 |
amit.gupta |
1353 |
}
|
| 24615 |
amit.gupta |
1354 |
|
| 25837 |
amit.gupta |
1355 |
public void sendDailySalesNotificationToPartner(Integer fofoIdInt)
|
| 24653 |
govind |
1356 |
throws ProfitMandiBusinessException, MessagingException, IOException {
|
| 25927 |
amit.gupta |
1357 |
|
| 24653 |
govind |
1358 |
LocalDateTime now = LocalDateTime.now();
|
| 25837 |
amit.gupta |
1359 |
LocalDateTime from = now.with(LocalTime.MIN);
|
| 25925 |
amit.gupta |
1360 |
String timeString = "Today %s";
|
| 25927 |
amit.gupta |
1361 |
// Send yesterday's report
|
|
|
1362 |
if (now.getHour() < 13) {
|
| 25925 |
amit.gupta |
1363 |
timeString = "Yesterday %s";
|
| 25910 |
amit.gupta |
1364 |
from = now.minusDays(1);
|
|
|
1365 |
now = from.with(LocalTime.MAX);
|
| 25927 |
amit.gupta |
1366 |
|
| 25910 |
amit.gupta |
1367 |
}
|
| 24855 |
amit.gupta |
1368 |
List<Integer> fofoIds = null;
|
| 25043 |
amit.gupta |
1369 |
if (fofoIdInt == null) {
|
|
|
1370 |
fofoIds = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive()).map(x -> x.getId())
|
|
|
1371 |
.collect(Collectors.toList());
|
| 24856 |
amit.gupta |
1372 |
} else {
|
| 24855 |
amit.gupta |
1373 |
fofoIds = Arrays.asList(fofoIdInt);
|
|
|
1374 |
}
|
| 25912 |
amit.gupta |
1375 |
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("h:m a");
|
| 24683 |
amit.gupta |
1376 |
|
| 25865 |
amit.gupta |
1377 |
Map<Integer, Double> salesByFofoIdMap = new HashMap<>();
|
|
|
1378 |
Map<Integer, Float> partnerPolicyAmountMap = insurancePolicyRepository.selectAmountSumGroupByRetailerId(now,
|
|
|
1379 |
null);
|
|
|
1380 |
Map<Integer, Long> partnerPolicyQtyMap = insurancePolicyRepository.selectQtyGroupByRetailerId(now, null);
|
|
|
1381 |
Map<Integer, Double> partnerOrderAmountMap = fofoOrderItemRepository.selectSumAmountGroupByRetailer(from, now,
|
|
|
1382 |
0, true);
|
|
|
1383 |
Map<Integer, Long> partnerOrderQtyMap = fofoOrderItemRepository.selectQtyGroupByRetailer(from, now, 0, true);
|
|
|
1384 |
Map<Integer, SaleTargetReportModel> saleTargetReportModelMap = new HashMap<>();
|
|
|
1385 |
for (int fofoId : fofoIds) {
|
|
|
1386 |
SaleTargetReportModel model = new SaleTargetReportModel();
|
| 25927 |
amit.gupta |
1387 |
model.setInsuranceSale(
|
|
|
1388 |
partnerPolicyAmountMap.containsKey(fofoId) ? partnerPolicyAmountMap.get(fofoId).doubleValue() : 0);
|
| 25865 |
amit.gupta |
1389 |
model.setInsruanceQty(partnerPolicyQtyMap.containsKey(fofoId) ? partnerPolicyQtyMap.get(fofoId) : 0);
|
|
|
1390 |
model.setSmartphoneSale(partnerOrderAmountMap.containsKey(fofoId) ? partnerOrderAmountMap.get(fofoId) : 0);
|
|
|
1391 |
model.setSmartphoneQty(partnerOrderQtyMap.containsKey(fofoId) ? partnerOrderQtyMap.get(fofoId) : 0);
|
|
|
1392 |
model.setTotalSale(salesByFofoIdMap.containsKey(fofoId) ? salesByFofoIdMap.get(fofoId) : 0);
|
| 25880 |
amit.gupta |
1393 |
model.setFofoId(fofoId);
|
| 25865 |
amit.gupta |
1394 |
saleTargetReportModelMap.put(fofoId, model);
|
|
|
1395 |
}
|
| 25880 |
amit.gupta |
1396 |
|
| 25865 |
amit.gupta |
1397 |
Map<Integer, List<Serializable>> partnerSalesHeadersMap = this.getPartnerIdSalesHeaders();
|
| 24653 |
govind |
1398 |
for (Integer fofoId : fofoIds) {
|
| 25865 |
amit.gupta |
1399 |
SaleTargetReportModel model = saleTargetReportModelMap.get(fofoId);
|
| 25821 |
amit.gupta |
1400 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
1401 |
sendNotificationModel.setCampaignName("Sales update alert");
|
| 25884 |
tejbeer |
1402 |
sendNotificationModel.setTitle("Sale Update");
|
| 25927 |
amit.gupta |
1403 |
sendNotificationModel
|
|
|
1404 |
.setMessage(String.format("Smartphones Rs.%.0f, Insurance Rs.%.0f, Total Rs.%.0f till %s.",
|
|
|
1405 |
model.getSmartphoneSale(), model.getInsuranceSale(), model.getTotalSale(),
|
|
|
1406 |
String.format(timeString, now.format(timeFormatter))));
|
| 25821 |
amit.gupta |
1407 |
sendNotificationModel.setType("url");
|
| 26418 |
tejbeer |
1408 |
sendNotificationModel.setUrl("http://app.smartdukaan.com/pages/home/notifications");
|
| 25821 |
amit.gupta |
1409 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
|
|
1410 |
sendNotificationModel.setMessageType(MessageType.notification);
|
| 25872 |
tejbeer |
1411 |
int userId = userAccountRepository.selectUserIdByRetailerId(fofoId);
|
|
|
1412 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
| 25854 |
amit.gupta |
1413 |
notificationService.sendNotification(sendNotificationModel);
|
| 24653 |
govind |
1414 |
}
|
| 25865 |
amit.gupta |
1415 |
String saleReport = this.getDailySalesReportHtml(partnerSalesHeadersMap, saleTargetReportModelMap);
|
| 24653 |
govind |
1416 |
LOGGER.info(saleReport);
|
| 25837 |
amit.gupta |
1417 |
String cc[] = { "tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com", "prakash.rai@smartdukaan.com",
|
| 25846 |
amit.gupta |
1418 |
"chaitnaya.vats@smartdukaan.com" };
|
| 25837 |
amit.gupta |
1419 |
|
| 25912 |
amit.gupta |
1420 |
String subject = String.format("Sale till %s", String.format(timeString, now.format(timeFormatter)));
|
| 25821 |
amit.gupta |
1421 |
this.sendMailOfHtmlFomat("amit.gupta@shop2020.in", saleReport, cc, subject);
|
| 24653 |
govind |
1422 |
}
|
|
|
1423 |
|
| 25865 |
amit.gupta |
1424 |
public static class SaleTargetReportModel {
|
|
|
1425 |
private double totalSale;
|
| 25880 |
amit.gupta |
1426 |
private int fofoId;
|
|
|
1427 |
|
|
|
1428 |
public int getFofoId() {
|
|
|
1429 |
return fofoId;
|
|
|
1430 |
}
|
|
|
1431 |
|
|
|
1432 |
public void setFofoId(int fofoId) {
|
|
|
1433 |
this.fofoId = fofoId;
|
|
|
1434 |
}
|
|
|
1435 |
|
| 25865 |
amit.gupta |
1436 |
private double smartphoneSale;
|
|
|
1437 |
private long smartphoneQty;
|
|
|
1438 |
private double insuranceSale;
|
|
|
1439 |
private long insruanceQty;
|
|
|
1440 |
|
|
|
1441 |
@Override
|
|
|
1442 |
public int hashCode() {
|
|
|
1443 |
final int prime = 31;
|
|
|
1444 |
int result = 1;
|
| 25880 |
amit.gupta |
1445 |
result = prime * result + fofoId;
|
| 25865 |
amit.gupta |
1446 |
result = prime * result + (int) (insruanceQty ^ (insruanceQty >>> 32));
|
|
|
1447 |
long temp;
|
|
|
1448 |
temp = Double.doubleToLongBits(insuranceSale);
|
|
|
1449 |
result = prime * result + (int) (temp ^ (temp >>> 32));
|
|
|
1450 |
result = prime * result + (int) (smartphoneQty ^ (smartphoneQty >>> 32));
|
|
|
1451 |
temp = Double.doubleToLongBits(smartphoneSale);
|
|
|
1452 |
result = prime * result + (int) (temp ^ (temp >>> 32));
|
|
|
1453 |
temp = Double.doubleToLongBits(totalSale);
|
|
|
1454 |
result = prime * result + (int) (temp ^ (temp >>> 32));
|
|
|
1455 |
return result;
|
|
|
1456 |
}
|
|
|
1457 |
|
|
|
1458 |
@Override
|
|
|
1459 |
public boolean equals(Object obj) {
|
|
|
1460 |
if (this == obj)
|
|
|
1461 |
return true;
|
|
|
1462 |
if (obj == null)
|
|
|
1463 |
return false;
|
|
|
1464 |
if (getClass() != obj.getClass())
|
|
|
1465 |
return false;
|
|
|
1466 |
SaleTargetReportModel other = (SaleTargetReportModel) obj;
|
| 25880 |
amit.gupta |
1467 |
if (fofoId != other.fofoId)
|
|
|
1468 |
return false;
|
| 25865 |
amit.gupta |
1469 |
if (insruanceQty != other.insruanceQty)
|
|
|
1470 |
return false;
|
|
|
1471 |
if (Double.doubleToLongBits(insuranceSale) != Double.doubleToLongBits(other.insuranceSale))
|
|
|
1472 |
return false;
|
|
|
1473 |
if (smartphoneQty != other.smartphoneQty)
|
|
|
1474 |
return false;
|
|
|
1475 |
if (Double.doubleToLongBits(smartphoneSale) != Double.doubleToLongBits(other.smartphoneSale))
|
|
|
1476 |
return false;
|
|
|
1477 |
if (Double.doubleToLongBits(totalSale) != Double.doubleToLongBits(other.totalSale))
|
|
|
1478 |
return false;
|
|
|
1479 |
return true;
|
|
|
1480 |
}
|
|
|
1481 |
|
|
|
1482 |
public double getTotalSale() {
|
|
|
1483 |
return totalSale;
|
|
|
1484 |
}
|
|
|
1485 |
|
|
|
1486 |
public void setTotalSale(double totalSale) {
|
|
|
1487 |
this.totalSale = totalSale;
|
|
|
1488 |
}
|
|
|
1489 |
|
|
|
1490 |
public double getSmartphoneSale() {
|
|
|
1491 |
return smartphoneSale;
|
|
|
1492 |
}
|
|
|
1493 |
|
|
|
1494 |
public void setSmartphoneSale(double smartphoneSale) {
|
|
|
1495 |
this.smartphoneSale = smartphoneSale;
|
|
|
1496 |
}
|
|
|
1497 |
|
|
|
1498 |
public long getSmartphoneQty() {
|
|
|
1499 |
return smartphoneQty;
|
|
|
1500 |
}
|
|
|
1501 |
|
|
|
1502 |
public void setSmartphoneQty(long smartphoneQty) {
|
|
|
1503 |
this.smartphoneQty = smartphoneQty;
|
|
|
1504 |
}
|
|
|
1505 |
|
|
|
1506 |
public double getInsuranceSale() {
|
|
|
1507 |
return insuranceSale;
|
|
|
1508 |
}
|
|
|
1509 |
|
|
|
1510 |
public void setInsuranceSale(double insuranceSale) {
|
|
|
1511 |
this.insuranceSale = insuranceSale;
|
|
|
1512 |
}
|
|
|
1513 |
|
|
|
1514 |
public long getInsruanceQty() {
|
|
|
1515 |
return insruanceQty;
|
|
|
1516 |
}
|
|
|
1517 |
|
|
|
1518 |
public void setInsruanceQty(long insruanceQty) {
|
|
|
1519 |
this.insruanceQty = insruanceQty;
|
|
|
1520 |
}
|
|
|
1521 |
|
|
|
1522 |
@Override
|
|
|
1523 |
public String toString() {
|
| 25880 |
amit.gupta |
1524 |
return "SaleTargetReportModel [totalSale=" + totalSale + ", fofoId=" + fofoId + ", smartphoneSale="
|
|
|
1525 |
+ smartphoneSale + ", smartphoneQty=" + smartphoneQty + ", insuranceSale=" + insuranceSale
|
|
|
1526 |
+ ", insruanceQty=" + insruanceQty + "]";
|
| 25865 |
amit.gupta |
1527 |
}
|
|
|
1528 |
|
|
|
1529 |
}
|
|
|
1530 |
|
|
|
1531 |
private String getDailySalesReportHtml(Map<Integer, List<Serializable>> partnerSalesHeadersMap,
|
| 25872 |
tejbeer |
1532 |
Map<Integer, SaleTargetReportModel> saleReportTargetMap) throws ProfitMandiBusinessException {
|
| 24653 |
govind |
1533 |
StringBuilder sb = new StringBuilder();
|
| 25872 |
tejbeer |
1534 |
|
| 25832 |
amit.gupta |
1535 |
sb.append("<html><body><p>Sale Report:</p><br/><table style='border:1px solid black';cellspacing=0>");
|
| 24653 |
govind |
1536 |
sb.append("<tbody>\n" + " <tr>\n"
|
| 25865 |
amit.gupta |
1537 |
+ " <th style='border:1px solid black;padding: 5px'>%s</th>\n"
|
|
|
1538 |
+ " <th style='border:1px solid black;padding: 5px'>%s</th>\n"
|
|
|
1539 |
+ " <th style='border:1px solid black;padding: 5px'>%s</th>\n"
|
|
|
1540 |
+ " <th style='border:1px solid black;padding: 5px'>%s</th>\n"
|
|
|
1541 |
+ " <th style='border:1px solid black;padding: 5px'>%s</th>\n"
|
| 24653 |
govind |
1542 |
+ " <th style='border:1px solid black;padding: 5px'>Sale</th>\n"
|
| 25865 |
amit.gupta |
1543 |
+ " <th style='border:1px solid black;padding: 5px'>Smartphone Sale</th>\n"
|
|
|
1544 |
+ " <th style='border:1px solid black;padding: 5px'>SmartPhone Qty</th>\n"
|
|
|
1545 |
+ " <th style='border:1px solid black;padding: 5px'>Insurance Sale</th>\n"
|
|
|
1546 |
+ " <th style='border:1px solid black;padding: 5px'>Insurance Qty</th>\n"
|
| 24653 |
govind |
1547 |
+ " </tr>");
|
| 25880 |
amit.gupta |
1548 |
List<Integer> sortedPartnerSalesHeaders = partnerSalesHeadersMap.entrySet().stream()
|
|
|
1549 |
.sorted((x, y) -> ((String) (x.getValue().get(3))).compareTo((String) (y.getValue().get(3))))
|
| 25927 |
amit.gupta |
1550 |
.map(x -> x.getKey()).collect(Collectors.toList());
|
|
|
1551 |
for (Integer fofoId : sortedPartnerSalesHeaders) {
|
| 25865 |
amit.gupta |
1552 |
sb.append("<tr>");
|
| 25880 |
amit.gupta |
1553 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).get(0)
|
|
|
1554 |
+ "</td>");
|
|
|
1555 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).get(1)
|
|
|
1556 |
+ "</td>");
|
|
|
1557 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).get(2)
|
|
|
1558 |
+ "</td>");
|
|
|
1559 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).get(3)
|
|
|
1560 |
+ "</td>");
|
|
|
1561 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).get(4)
|
|
|
1562 |
+ "</td>");
|
|
|
1563 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
|
|
1564 |
+ saleReportTargetMap.get(fofoId).getTotalSale() + "</td>");
|
|
|
1565 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
|
|
1566 |
+ saleReportTargetMap.get(fofoId).getSmartphoneSale() + "</td>");
|
|
|
1567 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
|
|
1568 |
+ saleReportTargetMap.get(fofoId).getSmartphoneQty() + "</td>");
|
|
|
1569 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
|
|
1570 |
+ saleReportTargetMap.get(fofoId).getInsuranceSale() + "</td>");
|
|
|
1571 |
sb.append("<td style='border:1px solid black;padding: 5px'>"
|
|
|
1572 |
+ saleReportTargetMap.get(fofoId).getInsruanceQty() + "</td>");
|
| 25865 |
amit.gupta |
1573 |
sb.append("</tr>");
|
| 24653 |
govind |
1574 |
|
|
|
1575 |
}
|
| 24683 |
amit.gupta |
1576 |
|
| 24653 |
govind |
1577 |
sb.append("</tbody></table></body></html>");
|
| 25865 |
amit.gupta |
1578 |
return String.format(sb.toString(), REPORT_HEADERS);
|
| 24653 |
govind |
1579 |
}
|
| 24841 |
govind |
1580 |
|
|
|
1581 |
private void sendMailOfHtmlFomat(String email, String body, String cc[], String subject)
|
|
|
1582 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
|
|
1583 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
1584 |
MimeMessageHelper helper = new MimeMessageHelper(message);
|
|
|
1585 |
helper.setSubject(subject);
|
|
|
1586 |
helper.setText(body, true);
|
|
|
1587 |
helper.setTo(email);
|
|
|
1588 |
if (cc != null) {
|
|
|
1589 |
helper.setCc(cc);
|
|
|
1590 |
}
|
|
|
1591 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
|
|
1592 |
helper.setFrom(senderAddress);
|
|
|
1593 |
mailSender.send(message);
|
|
|
1594 |
}
|
| 25300 |
tejbeer |
1595 |
|
| 25351 |
tejbeer |
1596 |
public void sendNotification() throws Exception {
|
| 25300 |
tejbeer |
1597 |
List<PushNotifications> pushNotifications = pushNotificationRepository.selectAllByTimestamp();
|
|
|
1598 |
if (!pushNotifications.isEmpty()) {
|
|
|
1599 |
for (PushNotifications pushNotification : pushNotifications) {
|
| 25351 |
tejbeer |
1600 |
Device device = deviceRepository.selectById(pushNotification.getDeviceId());
|
| 25300 |
tejbeer |
1601 |
NotificationCampaign notificationCampaign = notificationCampaignRepository
|
|
|
1602 |
.selectById(pushNotification.getNotificationCampaignid());
|
|
|
1603 |
Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls()
|
|
|
1604 |
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeJsonConverter()).create();
|
|
|
1605 |
|
|
|
1606 |
SimpleCampaignParams scp = gson.fromJson(notificationCampaign.getImplementationParams(),
|
|
|
1607 |
SimpleCampaignParams.class);
|
|
|
1608 |
Campaign campaign = new SimpleCampaign(scp);
|
| 25351 |
tejbeer |
1609 |
String result_url = campaign.getUrl() + "&user_id=" + device.getUser_id();
|
| 25300 |
tejbeer |
1610 |
JSONObject json = new JSONObject();
|
| 25351 |
tejbeer |
1611 |
json.put("to", device.getFcmId());
|
| 25300 |
tejbeer |
1612 |
JSONObject jsonObj = new JSONObject();
|
|
|
1613 |
jsonObj.put("message", campaign.getMessage());
|
|
|
1614 |
jsonObj.put("title", campaign.getTitle());
|
|
|
1615 |
jsonObj.put("type", campaign.getType());
|
|
|
1616 |
jsonObj.put("url", result_url);
|
|
|
1617 |
jsonObj.put("time_to_live", campaign.getExpireTimestamp());
|
|
|
1618 |
jsonObj.put("image", campaign.getImageUrl());
|
|
|
1619 |
jsonObj.put("largeIcon", "large_icon");
|
|
|
1620 |
jsonObj.put("smallIcon", "small_icon");
|
|
|
1621 |
jsonObj.put("vibrate", 1);
|
|
|
1622 |
jsonObj.put("pid", pushNotification.getId());
|
|
|
1623 |
jsonObj.put("sound", 1);
|
|
|
1624 |
jsonObj.put("priority", "high");
|
|
|
1625 |
json.put("data", jsonObj);
|
| 25351 |
tejbeer |
1626 |
try {
|
|
|
1627 |
CloseableHttpClient client = HttpClients.createDefault();
|
|
|
1628 |
HttpPost httpPost = new HttpPost(FCM_URL);
|
| 25300 |
tejbeer |
1629 |
|
| 25351 |
tejbeer |
1630 |
httpPost.setHeader("Content-Type", "application/json; utf-8");
|
|
|
1631 |
httpPost.setHeader("authorization", "key=" + FCM_API_KEY);
|
|
|
1632 |
StringEntity entity = new StringEntity(json.toString());
|
|
|
1633 |
httpPost.setEntity(entity);
|
|
|
1634 |
CloseableHttpResponse response = client.execute(httpPost);
|
|
|
1635 |
LOGGER.info("response" + response);
|
| 25300 |
tejbeer |
1636 |
|
| 25351 |
tejbeer |
1637 |
if (response.getStatusLine().getStatusCode() == 200) {
|
|
|
1638 |
pushNotification.setSentTimestamp(LocalDateTime.now());
|
|
|
1639 |
} else {
|
| 25356 |
tejbeer |
1640 |
pushNotification.setSentTimestamp(LocalDateTime.of(1970, 1, 1, 00, 00));
|
| 25778 |
amit.gupta |
1641 |
LOGGER.info("message" + "not sent");
|
| 25351 |
tejbeer |
1642 |
}
|
| 25300 |
tejbeer |
1643 |
|
| 25351 |
tejbeer |
1644 |
} catch (Exception e) {
|
|
|
1645 |
e.printStackTrace();
|
| 25300 |
tejbeer |
1646 |
LOGGER.info("message" + "not sent");
|
|
|
1647 |
}
|
|
|
1648 |
}
|
|
|
1649 |
}
|
|
|
1650 |
}
|
|
|
1651 |
|
| 25553 |
amit.gupta |
1652 |
public void grouping() throws Exception {
|
| 25609 |
amit.gupta |
1653 |
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("MM-dd-yyyy hh:mm");
|
|
|
1654 |
List<PriceDropIMEI> priceDropImeis = priceDropIMEIRepository.selectByStatus(PriceDropImeiStatus.APPROVED);
|
|
|
1655 |
System.out.println(String.join("\t",
|
|
|
1656 |
Arrays.asList("IMEI", "ItemId", "Brand", "Model Name", "Model Number", "Franchise Id", "Franchise Name",
|
| 25694 |
amit.gupta |
1657 |
"Grn On", "Price Dropped On", "Approved On", "Returned On", "Price Drop Paid", "Is Doa")));
|
| 25609 |
amit.gupta |
1658 |
Map<Integer, CustomRetailer> retailersMap = retailerService.getFofoRetailers();
|
|
|
1659 |
for (PriceDropIMEI priceDropIMEI : priceDropImeis) {
|
| 25694 |
amit.gupta |
1660 |
if (priceDropIMEI.getPartnerId() == 0)
|
|
|
1661 |
continue;
|
| 25609 |
amit.gupta |
1662 |
HashSet<String> imeis = new HashSet<>();
|
|
|
1663 |
PriceDrop priceDrop = priceDropRepository.selectById(priceDropIMEI.getPriceDropId());
|
|
|
1664 |
imeis.add(priceDropIMEI.getImei());
|
|
|
1665 |
List<InventoryItem> inventoryItems = inventoryItemRepository
|
|
|
1666 |
.selectByFofoIdSerialNumbers(priceDropIMEI.getPartnerId(), imeis, false);
|
| 25694 |
amit.gupta |
1667 |
if (inventoryItems.size() == 0) {
|
|
|
1668 |
LOGGER.info("Need to investigate partnerId - {} imeis - {}", priceDropIMEI.getPartnerId(), imeis);
|
| 25613 |
amit.gupta |
1669 |
continue;
|
| 25612 |
amit.gupta |
1670 |
}
|
| 25609 |
amit.gupta |
1671 |
InventoryItem inventoryItem = inventoryItems.get(0);
|
|
|
1672 |
CustomRetailer customRetailer = retailersMap.get(inventoryItem.getFofoId());
|
|
|
1673 |
if (inventoryItem.getLastScanType().equals(ScanType.DOA_OUT)
|
|
|
1674 |
|| inventoryItem.getLastScanType().equals(ScanType.PURCHASE_RET)) {
|
|
|
1675 |
// check if pricedrop has been rolled out
|
|
|
1676 |
List<UserWalletHistory> uwh = walletService.getAllByReference(inventoryItem.getFofoId(),
|
|
|
1677 |
priceDropIMEI.getPriceDropId(), WalletReferenceType.PRICE_DROP);
|
|
|
1678 |
if (uwh.size() > 0) {
|
| 25615 |
amit.gupta |
1679 |
Item item = itemRepository.selectById(inventoryItem.getItemId());
|
| 25609 |
amit.gupta |
1680 |
System.out.println(String.join("\t",
|
|
|
1681 |
Arrays.asList(priceDropIMEI.getImei(), inventoryItem.getItemId() + "", item.getBrand(),
|
|
|
1682 |
item.getModelName(), item.getModelNumber(), inventoryItem.getFofoId() + "",
|
|
|
1683 |
customRetailer.getBusinessName(), inventoryItem.getCreateTimestamp().format(dtf),
|
|
|
1684 |
priceDrop.getAffectedOn().format(dtf),
|
|
|
1685 |
priceDropIMEI.getUpdateTimestamp().format(dtf),
|
| 26344 |
amit.gupta |
1686 |
inventoryItem.getUpdateTimestamp().format(dtf), priceDrop.getAutoPartnerPayout() + "",
|
| 25609 |
amit.gupta |
1687 |
inventoryItem.getLastScanType().equals(ScanType.DOA_OUT) + "")));
|
|
|
1688 |
}
|
|
|
1689 |
}
|
|
|
1690 |
}
|
| 25503 |
amit.gupta |
1691 |
}
|
| 25694 |
amit.gupta |
1692 |
|
|
|
1693 |
public void testToffee() throws Exception {
|
| 25846 |
amit.gupta |
1694 |
LOGGER.info("Insurance Sum Summary --- {}",
|
|
|
1695 |
insurancePolicyRepository.selectAmountSumGroupByRetailerId(LocalDateTime.MIN, LocalDateTime.MAX));
|
|
|
1696 |
LOGGER.info("Insurance Qty Summary --- {}",
|
|
|
1697 |
insurancePolicyRepository.selectQtyGroupByRetailerId(LocalDateTime.MIN, LocalDateTime.MAX));
|
| 25854 |
amit.gupta |
1698 |
LOGGER.info("SmartPhone Amount Summary --- {}",
|
| 25856 |
amit.gupta |
1699 |
fofoOrderItemRepository.selectSumAmountGroupByRetailer(LocalDateTime.MIN, LocalDateTime.MAX, 0, true));
|
| 25854 |
amit.gupta |
1700 |
LOGGER.info("Smartphone Qty Summary --- {}",
|
|
|
1701 |
fofoOrderItemRepository.selectQtyGroupByRetailer(LocalDateTime.MIN, LocalDateTime.MAX, 0, true));
|
| 25800 |
tejbeer |
1702 |
// LOGGER.info("{}", toffeeService.getAuthToken());
|
| 25846 |
amit.gupta |
1703 |
/*
|
|
|
1704 |
* LOGGER.info("{}", toffeeService.getProducts()); // LOGGER.info("{}",
|
|
|
1705 |
* toffeeService.getPincodes("36103000PR")); PremiumCalculationRequestModel pcrm
|
|
|
1706 |
* = new PremiumCalculationRequestModel(); pcrm.setProductDetails("36103000PR");
|
|
|
1707 |
* // pcrm.setProductDetails("36103000PR");
|
|
|
1708 |
* pcrm.setDurations(Arrays.asList("3 Months", "6 Months", "1 Year"));
|
|
|
1709 |
* pcrm.setSumInsured("15000");
|
|
|
1710 |
* System.out.println(toffeeService.getPremiumCalculation(pcrm));
|
|
|
1711 |
*/
|
| 25694 |
amit.gupta |
1712 |
}
|
|
|
1713 |
|
|
|
1714 |
public void schemeRollback(List<String> schemeIds) throws Exception {
|
|
|
1715 |
List<Integer> schemeIdsInt = schemeIds.stream().map(x -> Integer.parseInt(x)).collect(Collectors.toList());
|
| 25708 |
amit.gupta |
1716 |
Map<Integer, Scheme> schemesMap = schemeRepository.selectBySchemeIds(schemeIdsInt, 0, schemeIds.size()).stream()
|
| 25694 |
amit.gupta |
1717 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
1718 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectBySchemeIds(new HashSet<>(schemeIdsInt));
|
|
|
1719 |
for (SchemeInOut sio : schemeInOuts) {
|
|
|
1720 |
Scheme scheme = schemesMap.get(sio.getSchemeId());
|
|
|
1721 |
if (scheme.getType().equals(SchemeType.IN)) {
|
|
|
1722 |
|
|
|
1723 |
} else if (scheme.getType().equals(SchemeType.OUT)) {
|
|
|
1724 |
InventoryItem inventoryItem = inventoryItemRepository.selectById(sio.getInventoryItemId());
|
|
|
1725 |
List<ScanRecord> sr = scanRecordRepository.selectByInventoryItemId(sio.getInventoryItemId());
|
|
|
1726 |
ScanRecord scanRecord = sr.stream().filter(x -> x.getType().equals(ScanType.SALE))
|
|
|
1727 |
.max((x1, x2) -> x1.getCreateTimestamp().compareTo(x2.getCreateTimestamp())).get();
|
|
|
1728 |
if (scanRecord.getCreateTimestamp().isAfter(scheme.getEndDateTime())
|
|
|
1729 |
|| scanRecord.getCreateTimestamp().isBefore(scheme.getStartDateTime())) {
|
|
|
1730 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
|
|
1731 |
FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(scanRecord.getOrderId());
|
| 25709 |
amit.gupta |
1732 |
String rollbackReason = "Scheme reversed for "
|
|
|
1733 |
+ itemRepository.selectById(inventoryItem.getItemId()).getItemDescription() + "/Inv - "
|
| 25694 |
amit.gupta |
1734 |
+ fofoOrder.getInvoiceNumber();
|
|
|
1735 |
walletService.rollbackAmountFromWallet(scanRecord.getFofoId(), sio.getAmount(),
|
|
|
1736 |
scanRecord.getOrderId(), WalletReferenceType.SCHEME_OUT, rollbackReason);
|
|
|
1737 |
System.out.printf("Amount %f,SchemeId %d,Reason %s\n", sio.getAmount(), sio.getSchemeId(),
|
|
|
1738 |
rollbackReason);
|
|
|
1739 |
}
|
|
|
1740 |
}
|
|
|
1741 |
}
|
| 25721 |
tejbeer |
1742 |
// throw new Exception();
|
| 25694 |
amit.gupta |
1743 |
}
|
| 25721 |
tejbeer |
1744 |
|
|
|
1745 |
public void checkfocusedModelInPartnerStock() throws Exception {
|
|
|
1746 |
|
|
|
1747 |
List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive()).map(x -> x.getId())
|
|
|
1748 |
.collect(Collectors.toList());
|
|
|
1749 |
Map<Integer, List<FocusedModelShortageModel>> focusedModelShortageReportMap = new HashMap<>();
|
|
|
1750 |
for (Integer fofoId : fofoIds) {
|
|
|
1751 |
if (!focusedModelShortageReportMap.containsKey(fofoId)) {
|
|
|
1752 |
focusedModelShortageReportMap.put(fofoId, new ArrayList<>());
|
|
|
1753 |
}
|
|
|
1754 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
|
|
|
1755 |
Map<Integer, Integer> processingOrderMap = null;
|
|
|
1756 |
Map<Integer, Integer> catalogIdAndQtyMap = null;
|
|
|
1757 |
Map<Integer, Integer> grnPendingOrdersMap = null;
|
|
|
1758 |
|
|
|
1759 |
Map<Integer, Integer> currentInventorySnapshot = currentInventorySnapshotRepository.selectByFofoId(fofoId)
|
|
|
1760 |
.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getAvailability()));
|
|
|
1761 |
|
|
|
1762 |
if (!currentInventorySnapshot.isEmpty()) {
|
|
|
1763 |
catalogIdAndQtyMap = itemRepository.selectByIds(currentInventorySnapshot.keySet()).stream()
|
|
|
1764 |
.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
|
|
|
1765 |
Collectors.summingInt(x -> currentInventorySnapshot.get(x.getId()))));
|
|
|
1766 |
|
|
|
1767 |
}
|
|
|
1768 |
|
|
|
1769 |
Map<Integer, Integer> grnPendingOrders = orderRepository.selectPendingGrnOrders(fofoId).stream()
|
|
|
1770 |
.collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
|
|
|
1771 |
Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
|
|
1772 |
if (!grnPendingOrders.isEmpty()) {
|
|
|
1773 |
grnPendingOrdersMap = itemRepository.selectByIds(grnPendingOrders.keySet()).stream()
|
|
|
1774 |
.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
|
|
|
1775 |
Collectors.summingInt(x -> grnPendingOrders.get(x.getId()))));
|
|
|
1776 |
|
|
|
1777 |
}
|
|
|
1778 |
|
|
|
1779 |
Map<Integer, Integer> processingOrder = orderRepository.selectOrders(fofoId, orderStatusList).stream()
|
|
|
1780 |
.collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
|
|
|
1781 |
Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
|
|
1782 |
if (!processingOrder.isEmpty()) {
|
|
|
1783 |
processingOrderMap = itemRepository.selectByIds(processingOrder.keySet()).stream()
|
|
|
1784 |
.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
|
|
|
1785 |
Collectors.summingInt(x -> processingOrder.get(x.getId()))));
|
|
|
1786 |
|
|
|
1787 |
}
|
|
|
1788 |
|
| 25800 |
tejbeer |
1789 |
List<String> brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
|
|
|
1790 |
.collect(Collectors.toList());
|
|
|
1791 |
|
|
|
1792 |
List<Integer> focusedModelCatalogId = focusedModelRepository.selectAll().stream().map(x -> x.getCatalogId())
|
|
|
1793 |
.collect(Collectors.toList());
|
|
|
1794 |
Map<String, Object> equalsMap = new HashMap<>();
|
|
|
1795 |
equalsMap.put("categoryId", 10006);
|
|
|
1796 |
equalsMap.put("brand", brands);
|
|
|
1797 |
|
|
|
1798 |
Map<String, List<?>> notEqualsMap = new HashMap<>();
|
|
|
1799 |
|
|
|
1800 |
Map<String, Object> equalsJoinMap = new HashMap<>();
|
|
|
1801 |
equalsJoinMap.put("catalogId", focusedModelCatalogId);
|
|
|
1802 |
|
|
|
1803 |
Map<String, List<?>> notEqualsJoinMap = new HashMap<>();
|
|
|
1804 |
|
|
|
1805 |
List<Integer> catalogIds = itemRepository
|
|
|
1806 |
.selectItems(FocusedModel.class, "catalogItemId", "catalogId", equalsMap, notEqualsMap,
|
|
|
1807 |
equalsJoinMap, notEqualsJoinMap, "minimumQty")
|
|
|
1808 |
.stream().map(x -> x.getCatalogId()).collect(Collectors.toList());
|
|
|
1809 |
|
|
|
1810 |
Map<Integer, Integer> focusedCatalogIdAndQtyMap = focusedModelRepository.selectByCatalogIdsl(catalogIds)
|
|
|
1811 |
.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getMinimumQty()));
|
|
|
1812 |
|
|
|
1813 |
/*
|
|
|
1814 |
* Map<Integer, Integer> focusedCatalogIdAndQtyMap =
|
|
|
1815 |
* focusedModelRepository.selectAll().stream() .collect(Collectors.toMap(x ->
|
|
|
1816 |
* x.getCatalogId(), x -> x.getMinimumQty()));
|
|
|
1817 |
*/
|
|
|
1818 |
|
| 25721 |
tejbeer |
1819 |
LOGGER.info("focusedCatalogIdAndQtyMap" + focusedCatalogIdAndQtyMap);
|
|
|
1820 |
|
|
|
1821 |
for (Map.Entry<Integer, Integer> entry : focusedCatalogIdAndQtyMap.entrySet()) {
|
|
|
1822 |
int inStockQty = 0;
|
|
|
1823 |
int processingQty = 0;
|
|
|
1824 |
int grnPendingQty = 0;
|
|
|
1825 |
if (processingOrderMap != null) {
|
|
|
1826 |
processingQty = (processingOrderMap.get(entry.getKey()) == null) ? 0
|
|
|
1827 |
: processingOrderMap.get(entry.getKey());
|
|
|
1828 |
|
|
|
1829 |
}
|
|
|
1830 |
if (grnPendingOrdersMap != null) {
|
|
|
1831 |
grnPendingQty = (grnPendingOrdersMap.get(entry.getKey()) == null) ? 0
|
|
|
1832 |
: grnPendingOrdersMap.get(entry.getKey());
|
|
|
1833 |
|
|
|
1834 |
}
|
|
|
1835 |
if (catalogIdAndQtyMap != null) {
|
|
|
1836 |
inStockQty = (catalogIdAndQtyMap.get(entry.getKey()) == null) ? 0
|
|
|
1837 |
: catalogIdAndQtyMap.get(entry.getKey());
|
|
|
1838 |
|
|
|
1839 |
}
|
|
|
1840 |
int totalQty = processingQty + grnPendingQty + inStockQty;
|
|
|
1841 |
|
|
|
1842 |
if (totalQty < entry.getValue()) {
|
|
|
1843 |
|
|
|
1844 |
int shortageQty = entry.getValue() - totalQty;
|
|
|
1845 |
List<Item> item = itemRepository.selectAllByCatalogItemId(entry.getKey());
|
|
|
1846 |
|
|
|
1847 |
FocusedModelShortageModel fm = new FocusedModelShortageModel();
|
|
|
1848 |
fm.setFofoId(fofoId);
|
|
|
1849 |
fm.setStoreName(customRetailer.getBusinessName());
|
|
|
1850 |
|
|
|
1851 |
fm.setItemName(item.get(0).getBrand() + item.get(0).getModelNumber() + item.get(0).getModelName());
|
|
|
1852 |
fm.setShortageQty(shortageQty);
|
|
|
1853 |
|
|
|
1854 |
focusedModelShortageReportMap.get(fofoId).add(fm);
|
|
|
1855 |
}
|
|
|
1856 |
|
|
|
1857 |
}
|
|
|
1858 |
List<FocusedModelShortageModel> focusedModelShortageModel = focusedModelShortageReportMap.get(fofoId);
|
|
|
1859 |
|
|
|
1860 |
if (!focusedModelShortageModel.isEmpty()) {
|
|
|
1861 |
String subject = "Stock Alert";
|
|
|
1862 |
String messageText = this.getMessage(focusedModelShortageModel);
|
|
|
1863 |
|
| 25732 |
tejbeer |
1864 |
this.sendMailWithAttachments(subject, messageText, customRetailer.getEmail());
|
| 25721 |
tejbeer |
1865 |
String notificationMessage = this.getNotificationMessage(focusedModelShortageModel);
|
|
|
1866 |
|
|
|
1867 |
LOGGER.info("notificationMessage" + notificationMessage);
|
|
|
1868 |
|
| 25872 |
tejbeer |
1869 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
1870 |
sendNotificationModel.setCampaignName("Stock Alert");
|
|
|
1871 |
sendNotificationModel.setTitle("Alert");
|
|
|
1872 |
sendNotificationModel.setMessage(notificationMessage);
|
|
|
1873 |
sendNotificationModel.setType("url");
|
| 26418 |
tejbeer |
1874 |
sendNotificationModel.setUrl("http://app.smartdukaan.com/pages/home/notifications");
|
| 25872 |
tejbeer |
1875 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
|
|
|
1876 |
sendNotificationModel.setMessageType(MessageType.notification);
|
| 25732 |
tejbeer |
1877 |
int userId = userAccountRepository.selectUserIdByRetailerId(fofoId);
|
| 25872 |
tejbeer |
1878 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
|
|
1879 |
notificationService.sendNotification(sendNotificationModel);
|
| 25721 |
tejbeer |
1880 |
|
|
|
1881 |
}
|
| 25732 |
tejbeer |
1882 |
|
| 25721 |
tejbeer |
1883 |
}
|
| 25800 |
tejbeer |
1884 |
if (!focusedModelShortageReportMap.isEmpty())
|
| 25721 |
tejbeer |
1885 |
|
| 25800 |
tejbeer |
1886 |
{
|
|
|
1887 |
String fileName = "Stock Alert-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
|
|
|
1888 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
| 25837 |
amit.gupta |
1889 |
Map<String, List<List<?>>> emailRowsMap = new HashMap<>();
|
| 25721 |
tejbeer |
1890 |
|
| 25800 |
tejbeer |
1891 |
focusedModelShortageReportMap.entrySet().forEach(x -> {
|
|
|
1892 |
storeGuyMap.entrySet().forEach(y -> {
|
|
|
1893 |
|
|
|
1894 |
if (y.getValue().contains(x.getKey())) {
|
|
|
1895 |
if (!emailRowsMap.containsKey(y.getKey())) {
|
|
|
1896 |
emailRowsMap.put(y.getKey(), new ArrayList<>());
|
|
|
1897 |
}
|
|
|
1898 |
List<List<? extends Serializable>> fms = x.getValue().stream().map(r -> Arrays
|
|
|
1899 |
.asList(r.getFofoId(), r.getStoreName(), r.getItemName(), r.getShortageQty()))
|
|
|
1900 |
.collect(Collectors.toList());
|
|
|
1901 |
emailRowsMap.get(y.getKey()).addAll(fms);
|
|
|
1902 |
|
| 25721 |
tejbeer |
1903 |
}
|
|
|
1904 |
|
| 25800 |
tejbeer |
1905 |
});
|
| 25721 |
tejbeer |
1906 |
|
|
|
1907 |
});
|
|
|
1908 |
|
| 25800 |
tejbeer |
1909 |
List<String> headers = Arrays.asList("Partner Id", "Partner Name", "Model Name", "Shortage Qty");
|
| 25837 |
amit.gupta |
1910 |
emailRowsMap.entrySet().forEach(entry -> {
|
| 25721 |
tejbeer |
1911 |
|
| 25800 |
tejbeer |
1912 |
ByteArrayOutputStream baos = null;
|
|
|
1913 |
try {
|
| 25837 |
amit.gupta |
1914 |
baos = FileUtil.getCSVByteStream(headers, entry.getValue());
|
| 25800 |
tejbeer |
1915 |
} catch (Exception e2) {
|
|
|
1916 |
e2.printStackTrace();
|
|
|
1917 |
}
|
| 25837 |
amit.gupta |
1918 |
String[] sendToArray = new String[] { entry.getKey() };
|
| 25800 |
tejbeer |
1919 |
try {
|
|
|
1920 |
Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Stock Alert", "PFA", fileName,
|
|
|
1921 |
new ByteArrayResource(baos.toByteArray()));
|
|
|
1922 |
} catch (Exception e1) { // TODO Auto-generated catch block
|
|
|
1923 |
e1.printStackTrace();
|
|
|
1924 |
}
|
| 25721 |
tejbeer |
1925 |
|
| 25800 |
tejbeer |
1926 |
});
|
|
|
1927 |
}
|
| 25721 |
tejbeer |
1928 |
}
|
|
|
1929 |
|
|
|
1930 |
private String getNotificationMessage(List<FocusedModelShortageModel> focusedModelShortageModel) {
|
|
|
1931 |
StringBuilder sb = new StringBuilder();
|
|
|
1932 |
sb.append("Focused Model Shortage in Your Stock : \n");
|
|
|
1933 |
for (FocusedModelShortageModel entry : focusedModelShortageModel) {
|
|
|
1934 |
|
|
|
1935 |
sb.append(entry.getItemName() + "-" + entry.getShortageQty());
|
|
|
1936 |
sb.append(String.format("%n", ""));
|
|
|
1937 |
}
|
|
|
1938 |
return sb.toString();
|
|
|
1939 |
}
|
|
|
1940 |
|
|
|
1941 |
private void sendMailWithAttachments(String subject, String messageText, String email) throws Exception {
|
|
|
1942 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
1943 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
|
|
1944 |
|
|
|
1945 |
helper.setSubject(subject);
|
|
|
1946 |
helper.setText(messageText, true);
|
|
|
1947 |
helper.setTo(email);
|
| 26032 |
amit.gupta |
1948 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smatdukaan Alerts");
|
| 25721 |
tejbeer |
1949 |
helper.setFrom(senderAddress);
|
|
|
1950 |
mailSender.send(message);
|
|
|
1951 |
|
|
|
1952 |
}
|
|
|
1953 |
|
|
|
1954 |
private String getMessage(List<FocusedModelShortageModel> focusedModelShortageModel) {
|
|
|
1955 |
StringBuilder sb = new StringBuilder();
|
|
|
1956 |
sb.append("<html><body><p>Alert</p><p>Focused Model Shortage in Your Stock:-</p>"
|
|
|
1957 |
+ "<br/><table style='border:1px solid black ;padding: 5px';>");
|
|
|
1958 |
sb.append("<tbody>\n" + " <tr>\n"
|
|
|
1959 |
+ " <th style='border:1px solid black;padding: 5px'>Item</th>\n"
|
|
|
1960 |
+ " <th style='border:1px solid black;padding: 5px'>Shortage Qty</th>\n"
|
|
|
1961 |
+ " </tr>");
|
|
|
1962 |
for (FocusedModelShortageModel entry : focusedModelShortageModel) {
|
|
|
1963 |
|
|
|
1964 |
sb.append("<tr>");
|
|
|
1965 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getItemName() + "</td>");
|
|
|
1966 |
|
|
|
1967 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + entry.getShortageQty() + "</td>");
|
|
|
1968 |
|
|
|
1969 |
sb.append("</tr>");
|
|
|
1970 |
|
|
|
1971 |
}
|
|
|
1972 |
|
|
|
1973 |
sb.append("</tbody></table></body></html>");
|
|
|
1974 |
|
|
|
1975 |
return sb.toString();
|
|
|
1976 |
}
|
|
|
1977 |
|
| 25927 |
amit.gupta |
1978 |
public void notifyLead() throws Exception {
|
|
|
1979 |
List<Lead> leadsToNotify = leadRepository.selectLeadsScheduledBetweenDate(LocalDateTime.now().minusDays(15),
|
|
|
1980 |
LocalDateTime.now().plusHours(4));
|
|
|
1981 |
Map<Integer, String> authUserEmailMap = authRepository.selectAllActiveUser().stream()
|
|
|
1982 |
.collect(Collectors.toMap(x -> x.getId(), x -> x.getEmailId()));
|
| 25936 |
amit.gupta |
1983 |
System.out.printf("authUserEmailMap - %s", authUserEmailMap);
|
| 25927 |
amit.gupta |
1984 |
Map<String, Integer> dtrEmailMap = dtrUserRepository
|
|
|
1985 |
.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.values())).stream()
|
|
|
1986 |
.collect(Collectors.toMap(x -> x.getEmailId(), x -> x.getId()));
|
| 25936 |
amit.gupta |
1987 |
|
|
|
1988 |
System.out.printf("dtrEmailMap - %s", dtrEmailMap);
|
|
|
1989 |
|
| 25927 |
amit.gupta |
1990 |
Map<Integer, Integer> authUserKeyMap = new HashMap<>();
|
|
|
1991 |
|
|
|
1992 |
for (Map.Entry<Integer, String> authUserEmail : authUserEmailMap.entrySet()) {
|
|
|
1993 |
int authId = authUserEmail.getKey();
|
|
|
1994 |
String email = authUserEmail.getValue();
|
|
|
1995 |
authUserKeyMap.put(authId, dtrEmailMap.get(email));
|
|
|
1996 |
}
|
| 25929 |
amit.gupta |
1997 |
System.out.println(authUserKeyMap);
|
|
|
1998 |
System.out.println(leadsToNotify);
|
|
|
1999 |
|
| 25927 |
amit.gupta |
2000 |
String templateMessage = "Lead followup for %s %s, %s is due by %s";
|
|
|
2001 |
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("h:m a");
|
|
|
2002 |
for (Lead lead : leadsToNotify) {
|
|
|
2003 |
if (authUserKeyMap.get(lead.getAuthId()) == null) {
|
|
|
2004 |
continue;
|
|
|
2005 |
}
|
|
|
2006 |
String notificationMessage = String.format(templateMessage, lead.getFirstName(), lead.getLastName(),
|
| 25941 |
amit.gupta |
2007 |
lead.getAddress(), timeFormatter.format(lead.getLeadActivity().getSchelduleTimestamp()));
|
| 25927 |
amit.gupta |
2008 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
2009 |
sendNotificationModel.setCampaignName("Lead Reminder");
|
|
|
2010 |
sendNotificationModel.setTitle("Leads followup Reminder");
|
|
|
2011 |
sendNotificationModel.setMessage(notificationMessage);
|
|
|
2012 |
sendNotificationModel.setType("url");
|
| 26121 |
amit.gupta |
2013 |
sendNotificationModel.setUrl("http://app.smartdukaan.com/pages/home/notifications");
|
| 25927 |
amit.gupta |
2014 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
|
|
|
2015 |
sendNotificationModel.setMessageType(MessageType.reminder);
|
| 26320 |
tejbeer |
2016 |
sendNotificationModel.setUserIds(Arrays.asList(authUserKeyMap.get(lead.getAssignTo())));
|
| 25929 |
amit.gupta |
2017 |
System.out.println(sendNotificationModel);
|
| 25927 |
amit.gupta |
2018 |
notificationService.sendNotification(sendNotificationModel);
|
|
|
2019 |
}
|
|
|
2020 |
}
|
|
|
2021 |
public void notifyVisits() throws Exception {
|
|
|
2022 |
List<FranchiseeVisit> franchiseeVisits = franchiseeVisitRepository.selectVisitsScheduledBetweenDate(LocalDateTime.now().minusDays(15),
|
|
|
2023 |
LocalDateTime.now().plusHours(4));
|
|
|
2024 |
Map<Integer, String> authUserEmailMap = authRepository.selectAllActiveUser().stream()
|
|
|
2025 |
.collect(Collectors.toMap(x -> x.getId(), x -> x.getEmailId()));
|
|
|
2026 |
Map<String, Integer> dtrEmailMap = dtrUserRepository
|
|
|
2027 |
.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.values())).stream()
|
|
|
2028 |
.collect(Collectors.toMap(x -> x.getEmailId(), x -> x.getId()));
|
|
|
2029 |
Map<Integer, Integer> authUserKeyMap = new HashMap<>();
|
| 25910 |
amit.gupta |
2030 |
|
| 25927 |
amit.gupta |
2031 |
for (Map.Entry<Integer, String> authUserEmail : authUserEmailMap.entrySet()) {
|
|
|
2032 |
int authId = authUserEmail.getKey();
|
|
|
2033 |
String email = authUserEmail.getValue();
|
|
|
2034 |
authUserKeyMap.put(authId, dtrEmailMap.get(email));
|
|
|
2035 |
}
|
|
|
2036 |
String visitTemplate = "Planned visit to franchisee %s is due by %s";
|
|
|
2037 |
String followupTemplate = "Lead followup for franchisee %s is due by %s";
|
|
|
2038 |
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("MMM 7, EEEE h:m a");
|
|
|
2039 |
for (FranchiseeVisit visit : franchiseeVisits) {
|
|
|
2040 |
if (authUserKeyMap.containsKey(visit.getAuthId())) {
|
|
|
2041 |
continue;
|
|
|
2042 |
}
|
|
|
2043 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
2044 |
String message = null;
|
|
|
2045 |
if(visit.getFranchiseActivityId()==0) {
|
|
|
2046 |
message = String.format(visitTemplate, visit.getPartnerName(), timeFormatter.format(visit.getSchelduleTimestamp()));
|
|
|
2047 |
sendNotificationModel.setCampaignName("Franchisee visit Reminder");
|
|
|
2048 |
} else {
|
|
|
2049 |
message = String.format(followupTemplate, visit.getPartnerName(), timeFormatter.format(visit.getSchelduleTimestamp()));
|
|
|
2050 |
sendNotificationModel.setCampaignName("Franchisee followup Reminder");
|
|
|
2051 |
}
|
|
|
2052 |
sendNotificationModel.setMessage(message);
|
|
|
2053 |
sendNotificationModel.setType("url");
|
| 26122 |
amit.gupta |
2054 |
sendNotificationModel.setUrl("http://app.smartdukaan.com/pages/home/notifications");
|
| 25927 |
amit.gupta |
2055 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
|
|
|
2056 |
sendNotificationModel.setMessageType(MessageType.reminder);
|
|
|
2057 |
sendNotificationModel.setUserIds(Arrays.asList(authUserKeyMap.get(visit.getAuthId())));
|
|
|
2058 |
notificationService.sendNotification(sendNotificationModel);
|
|
|
2059 |
}
|
| 25910 |
amit.gupta |
2060 |
}
|
| 25927 |
amit.gupta |
2061 |
|
| 25982 |
amit.gupta |
2062 |
public AddPaymentResponse addPayment(AddPaymentRequest addPaymentRequest) throws Exception {
|
|
|
2063 |
HdfcPayment hdfcPayment = hdfcPaymentRepository.selectByTransactionId(addPaymentRequest.getTransactionId());
|
|
|
2064 |
AddPaymentResponse response = new AddPaymentResponse();
|
|
|
2065 |
if (hdfcPayment == null) {
|
|
|
2066 |
hdfcPayment = new HdfcPayment();
|
|
|
2067 |
hdfcPayment.setAmount(addPaymentRequest.getAmount());
|
|
|
2068 |
hdfcPayment.setCreateTimestamp(LocalDateTime.now());
|
|
|
2069 |
hdfcPayment.setCreditTimestamp(addPaymentRequest.getCreditDateTime());
|
|
|
2070 |
hdfcPayment.setFromAccountNumber(addPaymentRequest.getFromAccountNumber());
|
|
|
2071 |
hdfcPayment.setFromBankName(addPaymentRequest.getFromBankName());
|
|
|
2072 |
hdfcPayment.setMmid(addPaymentRequest.getMmid());
|
|
|
2073 |
hdfcPayment.setRemitterName(addPaymentRequest.getRemitterName());
|
|
|
2074 |
hdfcPayment.setTransactionId(addPaymentRequest.getTransactionId());
|
|
|
2075 |
hdfcPayment.setTransferMode(addPaymentRequest.getTransferMode());
|
|
|
2076 |
hdfcPayment.setUtr(addPaymentRequest.getUtr());
|
|
|
2077 |
hdfcPayment.setVirtualAccount(hdfcPayment.getVirtualAccount());
|
|
|
2078 |
hdfcPaymentRepository.persist(hdfcPayment);
|
|
|
2079 |
String virtualAccount = hdfcPayment.getVirtualAccount();
|
|
|
2080 |
String retailerIdString = virtualAccount.substring(6);
|
|
|
2081 |
int retailerId = Integer.parseInt(retailerIdString);
|
|
|
2082 |
String description = String.format("Paid through %s, Utr# %s", hdfcPayment.getTransferMode(),
|
|
|
2083 |
hdfcPayment.getUtr());
|
|
|
2084 |
walletService.addAmountToWallet(retailerId, hdfcPayment.getId(), WalletReferenceType.ADVANCE_AMOUNT,
|
|
|
2085 |
description, (float) hdfcPayment.getAmount());
|
|
|
2086 |
response.setCode("100");
|
|
|
2087 |
response.setStatus("Success");
|
|
|
2088 |
} else {
|
|
|
2089 |
response.setCode("200");
|
|
|
2090 |
response.setStatus("Duplicate");
|
|
|
2091 |
}
|
|
|
2092 |
response.setTransactionId("");
|
|
|
2093 |
|
|
|
2094 |
return response;
|
|
|
2095 |
}
|
| 25927 |
amit.gupta |
2096 |
|
| 25982 |
amit.gupta |
2097 |
|
| 25910 |
amit.gupta |
2098 |
|
| 26283 |
tejbeer |
2099 |
public void ticketClosed() throws Exception {
|
|
|
2100 |
|
|
|
2101 |
List<Ticket> tickets = ticketRepository.selectAllNotClosedTicketsWithStatus(ActivityType.RESOLVED);
|
|
|
2102 |
for (Ticket ticket : tickets) {
|
|
|
2103 |
if (ticket.getUpdateTimestamp().toLocalDate().isBefore(LocalDate.now().minusDays(7))) {
|
|
|
2104 |
ticket.setCloseTimestamp(LocalDateTime.now());
|
|
|
2105 |
ticket.setLastActivity(ActivityType.RESOLVED_ACCEPTED);
|
|
|
2106 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
|
|
2107 |
ticketRepository.persist(ticket);
|
|
|
2108 |
}
|
|
|
2109 |
}
|
|
|
2110 |
|
|
|
2111 |
}
|
|
|
2112 |
|
| 26418 |
tejbeer |
2113 |
}
|