| 21248 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 26636 |
amit.gupta |
3 |
import com.fasterxml.jackson.annotation.JsonProperty;
|
| 26646 |
amit.gupta |
4 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
| 21248 |
ashik.ali |
5 |
import com.spice.profitmandi.common.ResponseCodeHolder;
|
|
|
6 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 30295 |
amit.gupta |
7 |
import com.spice.profitmandi.common.model.*;
|
|
|
8 |
import com.spice.profitmandi.common.util.Utils;
|
| 21855 |
amit.gupta |
9 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 21740 |
ashik.ali |
10 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 25366 |
tejbeer |
11 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 30295 |
amit.gupta |
12 |
import com.spice.profitmandi.dao.entity.dtr.*;
|
| 29011 |
amit.gupta |
13 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
|
|
14 |
import com.spice.profitmandi.dao.entity.fofo.PartnerOnBoardingPanel;
|
| 25622 |
amit.gupta |
15 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
| 22355 |
ashik.ali |
16 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| 25458 |
tejbeer |
17 |
import com.spice.profitmandi.dao.entity.user.Promoter;
|
|
|
18 |
import com.spice.profitmandi.dao.entity.user.Refferal;
|
| 25488 |
tejbeer |
19 |
import com.spice.profitmandi.dao.enumuration.dtr.RefferalStatus;
|
| 21735 |
ashik.ali |
20 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
| 29892 |
tejbeer |
21 |
import com.spice.profitmandi.dao.enumuration.transaction.PartnerOnBoardingStatus;
|
| 25979 |
tejbeer |
22 |
import com.spice.profitmandi.dao.model.CreateRefferalRequest;
|
| 25488 |
tejbeer |
23 |
import com.spice.profitmandi.dao.model.DateRangeModel;
|
| 21643 |
ashik.ali |
24 |
import com.spice.profitmandi.dao.model.UserCart;
|
| 25366 |
tejbeer |
25 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 25619 |
amit.gupta |
26 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 37781 |
amit |
27 |
import com.spice.profitmandi.dao.repository.cs.DemoPartnerAccessService;
|
| 37866 |
ranu |
28 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
| 30295 |
amit.gupta |
29 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
| 25622 |
amit.gupta |
30 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
|
| 22355 |
ashik.ali |
31 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 25458 |
tejbeer |
32 |
import com.spice.profitmandi.dao.repository.user.PromoterRepository;
|
| 24491 |
amit.gupta |
33 |
import com.spice.profitmandi.service.AuthService;
|
| 35272 |
amit |
34 |
import com.spice.profitmandi.service.authentication.JWTUtil;
|
| 23798 |
amit.gupta |
35 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 25366 |
tejbeer |
36 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 29011 |
amit.gupta |
37 |
import com.spice.profitmandi.service.user.StoreTimelineTatService;
|
| 23787 |
amit.gupta |
38 |
import com.spice.profitmandi.service.user.UserService;
|
| 21469 |
amit.gupta |
39 |
import com.spice.profitmandi.web.enumuration.UserStatus;
|
| 21277 |
ashik.ali |
40 |
import com.spice.profitmandi.web.processor.GoogleLoginProcessor;
|
| 25488 |
tejbeer |
41 |
import com.spice.profitmandi.web.req.RefferalEarning;
|
|
|
42 |
import com.spice.profitmandi.web.req.RefferalEarningModel;
|
| 21366 |
kshitij.so |
43 |
import com.spice.profitmandi.web.req.UserRequest;
|
| 25366 |
tejbeer |
44 |
import com.spice.profitmandi.web.res.Partner;
|
| 21469 |
amit.gupta |
45 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
46 |
import io.swagger.annotations.ApiImplicitParams;
|
| 30295 |
amit.gupta |
47 |
import org.apache.http.client.ClientProtocolException;
|
|
|
48 |
import org.apache.logging.log4j.LogManager;
|
|
|
49 |
import org.apache.logging.log4j.Logger;
|
|
|
50 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
51 |
import org.springframework.beans.factory.annotation.Value;
|
|
|
52 |
import org.springframework.http.MediaType;
|
|
|
53 |
import org.springframework.http.ResponseEntity;
|
|
|
54 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
55 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
|
|
56 |
import org.springframework.stereotype.Controller;
|
|
|
57 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
58 |
import org.springframework.web.bind.annotation.*;
|
| 21469 |
amit.gupta |
59 |
|
| 30295 |
amit.gupta |
60 |
import javax.mail.MessagingException;
|
|
|
61 |
import javax.mail.internet.InternetAddress;
|
|
|
62 |
import javax.mail.internet.MimeMessage;
|
|
|
63 |
import javax.servlet.http.HttpServletRequest;
|
|
|
64 |
import java.io.IOException;
|
|
|
65 |
import java.io.UnsupportedEncodingException;
|
|
|
66 |
import java.time.LocalDate;
|
|
|
67 |
import java.time.LocalDateTime;
|
|
|
68 |
import java.time.YearMonth;
|
|
|
69 |
import java.time.ZoneOffset;
|
|
|
70 |
import java.util.*;
|
|
|
71 |
import java.util.stream.Collectors;
|
|
|
72 |
|
| 21248 |
ashik.ali |
73 |
/**
|
|
|
74 |
* @author ashikali
|
|
|
75 |
*/
|
|
|
76 |
@Controller
|
| 25366 |
tejbeer |
77 |
@Transactional(rollbackFor = Throwable.class)
|
| 21248 |
ashik.ali |
78 |
public class UserController {
|
| 21469 |
amit.gupta |
79 |
|
| 32458 |
amit.gupta |
80 |
@Autowired
|
| 35272 |
amit |
81 |
JWTUtil jwtUtil;
|
|
|
82 |
|
|
|
83 |
@Autowired
|
| 32458 |
amit.gupta |
84 |
private ResponseSender<?> responseSender;
|
| 21469 |
amit.gupta |
85 |
|
| 36324 |
aman |
86 |
// Referrals whose approval (or creation, if approval ts is missing) falls before
|
|
|
87 |
// TIER_POLICY_EFFECTIVE_DATE keep the flat legacy payout; everything from that date
|
|
|
88 |
// onward uses the monthly tier: 1 → 3000, 2 → 4000, 3+ → 5000 (applied to the whole month).
|
|
|
89 |
private static final int LEGACY_PER_REFERRAL_EARNING = 2000;
|
|
|
90 |
private static final LocalDate TIER_POLICY_EFFECTIVE_DATE = LocalDate.of(2026, 1, 19);
|
| 33194 |
amit.gupta |
91 |
|
| 32458 |
amit.gupta |
92 |
private static final Logger LOGGER = LogManager.getLogger(UserController.class);
|
| 21469 |
amit.gupta |
93 |
|
| 32458 |
amit.gupta |
94 |
@Value("${notifications.api.host}")
|
|
|
95 |
private String nodeHost;
|
| 25366 |
tejbeer |
96 |
|
| 32458 |
amit.gupta |
97 |
@Autowired
|
|
|
98 |
private MobileAppSettingsRepository mobileAppSettingsRepository;
|
| 26636 |
amit.gupta |
99 |
|
| 32458 |
amit.gupta |
100 |
@Value("${notifications.api.port}")
|
|
|
101 |
private int nodePort;
|
| 21855 |
amit.gupta |
102 |
|
| 32458 |
amit.gupta |
103 |
@Value("${admin.token}")
|
|
|
104 |
private String validAdminToken;
|
| 21469 |
amit.gupta |
105 |
|
| 32458 |
amit.gupta |
106 |
@Autowired
|
|
|
107 |
private UserRepository userRepository;
|
| 25366 |
tejbeer |
108 |
|
| 32458 |
amit.gupta |
109 |
@Autowired
|
|
|
110 |
private com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
|
| 21469 |
amit.gupta |
111 |
|
| 32458 |
amit.gupta |
112 |
@Autowired
|
|
|
113 |
private RetailerRepository retailerRepository;
|
| 21485 |
amit.gupta |
114 |
|
| 32458 |
amit.gupta |
115 |
@Autowired
|
|
|
116 |
private UserRoleRepository userRoleRepository;
|
| 21469 |
amit.gupta |
117 |
|
| 32458 |
amit.gupta |
118 |
@Autowired
|
|
|
119 |
private PartnerTypeChangeService partnerTypeChangeService;
|
| 25622 |
amit.gupta |
120 |
|
| 32458 |
amit.gupta |
121 |
@Autowired
|
|
|
122 |
private UserAccountRepository userAccountRepository;
|
| 25366 |
tejbeer |
123 |
|
| 32458 |
amit.gupta |
124 |
@Autowired
|
|
|
125 |
private AuthService authService;
|
| 25366 |
tejbeer |
126 |
|
| 32458 |
amit.gupta |
127 |
@Autowired
|
|
|
128 |
private AddressRepository addressRepository;
|
| 21469 |
amit.gupta |
129 |
|
| 32458 |
amit.gupta |
130 |
@Autowired
|
|
|
131 |
private GoogleLoginProcessor googleLoginProcessor;
|
| 21855 |
amit.gupta |
132 |
|
| 32458 |
amit.gupta |
133 |
@Autowired
|
|
|
134 |
private UserService userService;
|
| 25366 |
tejbeer |
135 |
|
| 32458 |
amit.gupta |
136 |
@Autowired
|
|
|
137 |
private CsService csService;
|
| 25619 |
amit.gupta |
138 |
|
| 32458 |
amit.gupta |
139 |
@Autowired
|
| 37781 |
amit |
140 |
private DemoPartnerAccessService demoPartnerAccessService;
|
|
|
141 |
|
|
|
142 |
@Autowired
|
| 37866 |
ranu |
143 |
private PositionRepository positionRepository;
|
|
|
144 |
|
|
|
145 |
@Autowired
|
| 32458 |
amit.gupta |
146 |
private RestClient restClient;
|
| 25366 |
tejbeer |
147 |
|
| 32458 |
amit.gupta |
148 |
@Autowired
|
|
|
149 |
private RoleManager roleManager;
|
| 25366 |
tejbeer |
150 |
|
| 32458 |
amit.gupta |
151 |
@Autowired
|
|
|
152 |
private RoleRepository roleRepository;
|
| 21469 |
amit.gupta |
153 |
|
| 32458 |
amit.gupta |
154 |
@Autowired
|
|
|
155 |
private AuthRepository authRepository;
|
| 26792 |
tejbeer |
156 |
|
| 32458 |
amit.gupta |
157 |
@Autowired
|
|
|
158 |
private ObjectMapper objectMapper;
|
| 26792 |
tejbeer |
159 |
|
| 32458 |
amit.gupta |
160 |
@Autowired
|
|
|
161 |
private RetailerService retailerService;
|
| 25366 |
tejbeer |
162 |
|
| 32458 |
amit.gupta |
163 |
@Autowired
|
|
|
164 |
private RefferalRepository refferalRepository;
|
| 25458 |
tejbeer |
165 |
|
| 32458 |
amit.gupta |
166 |
@Autowired
|
|
|
167 |
private PromoterRepository promoterRepository;
|
| 25458 |
tejbeer |
168 |
|
| 32458 |
amit.gupta |
169 |
@Autowired
|
| 36400 |
amit |
170 |
JavaMailSender gmailRelaySender;
|
| 26792 |
tejbeer |
171 |
|
| 32458 |
amit.gupta |
172 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_GOOGLE_LOGIN, method = RequestMethod.POST)
|
| 34794 |
vikas.jang |
173 |
public ResponseEntity<?> googleLogin(HttpServletRequest request, @RequestBody GoogleLoginRequest loginRequest) throws Exception {
|
|
|
174 |
String email = loginRequest.getEmail() != null ? loginRequest.getEmail() : googleLoginProcessor.process(loginRequest.getToken());
|
|
|
175 |
return responseSender.ok(getAuthTokenMap(email, loginRequest));
|
| 32458 |
amit.gupta |
176 |
}
|
| 26636 |
amit.gupta |
177 |
|
| 35272 |
amit |
178 |
@RequestMapping(value = "/user/token/unregistered", method = RequestMethod.GET)
|
| 35257 |
amit |
179 |
public ResponseEntity<?> unregisteredToken() throws Exception {
|
|
|
180 |
Map<String, Object> responseMap = new HashMap<>();
|
| 35272 |
amit |
181 |
responseMap.put(ProfitMandiConstants.TOKEN, jwtUtil.create());
|
| 35257 |
amit |
182 |
responseMap.put(ProfitMandiConstants.REGISTERED, false);
|
|
|
183 |
return responseSender.ok(responseMap);
|
|
|
184 |
}
|
|
|
185 |
|
| 35170 |
vikas |
186 |
@RequestMapping(value = ProfitMandiConstants.URL_B2B_APP_VERSION, method = RequestMethod.GET)
|
| 35193 |
vikas |
187 |
public ResponseEntity<?> checkForUpdate(HttpServletRequest request, @RequestParam int version) {
|
| 35170 |
vikas |
188 |
Map<String, Object> responseMap = new HashMap<>();
|
|
|
189 |
responseMap.put("appVersion", ProfitMandiConstants.B2B_APP_VERSION);
|
|
|
190 |
responseMap.put("appUrl", ProfitMandiConstants.B2B_APP_URL);
|
| 35193 |
vikas |
191 |
if (version == ProfitMandiConstants.B2B_APP_VERSION) {
|
| 35170 |
vikas |
192 |
responseMap.put("updateAvailable", false);
|
|
|
193 |
} else {
|
|
|
194 |
responseMap.put("updateAvailable", true);
|
|
|
195 |
}
|
|
|
196 |
return responseSender.ok(responseMap);
|
|
|
197 |
}
|
|
|
198 |
|
| 34794 |
vikas.jang |
199 |
private Map<String, Object> getAuthTokenMap(String email, GoogleLoginRequest loginRequest) throws Exception {
|
| 32458 |
amit.gupta |
200 |
String name = authService.getNameByEmailId(email);
|
| 30295 |
amit.gupta |
201 |
|
| 32458 |
amit.gupta |
202 |
Map<String, Object> responseMap = new HashMap<>(2);
|
|
|
203 |
LOGGER.info("User Name from getNameByEmailId({}) is {}", email, name);
|
|
|
204 |
if (name != null) {
|
|
|
205 |
User registeredUser = null;
|
|
|
206 |
AuthUser authUser = authRepository.selectByGmailId(email);
|
| 34794 |
vikas.jang |
207 |
if (loginRequest.getPassword() != null) {
|
|
|
208 |
registeredUser = userService.authenticate(email, loginRequest.getPassword());
|
|
|
209 |
} else if (authUser != null) {
|
| 32458 |
amit.gupta |
210 |
registeredUser = userRepository.selectByEmailId(authUser.getEmailId());
|
|
|
211 |
} else if (promoterRepository.selectMappedByEmailId(email) != null) {
|
|
|
212 |
Promoter promoter = promoterRepository.selectMappedByEmailId(email);
|
|
|
213 |
int userId = userAccountRepository.selectUserIdByRetailerId(promoter.getRetailerId());
|
|
|
214 |
registeredUser = userRepository.selectById(userId);
|
|
|
215 |
} else if (userRepository.isExistBySecondryEmailId(email)) {
|
|
|
216 |
registeredUser = userRepository.selectBySecondryEmailId(email);
|
|
|
217 |
}
|
|
|
218 |
LOGGER.info("4");
|
|
|
219 |
List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(registeredUser.getId());
|
|
|
220 |
String[] roleTypes = new String[roleIds.size()];
|
|
|
221 |
int index = 0;
|
|
|
222 |
for (int roleId : roleIds) {
|
|
|
223 |
roleTypes[index++] = String.valueOf(roleId);
|
|
|
224 |
}
|
|
|
225 |
int retailerId;
|
|
|
226 |
try {
|
|
|
227 |
retailerId = userAccountRepository.selectRetailerIdByUserId(registeredUser.getId());
|
|
|
228 |
} catch (Exception e) {
|
|
|
229 |
Set<Integer> authUserPartnerSet = csService.getAuthUserPartnerIdMapping().get(authUser.getEmailId());
|
|
|
230 |
if (authUserPartnerSet != null && authUserPartnerSet.size() > 0) {
|
|
|
231 |
retailerId = authUserPartnerSet.stream().findFirst().get();
|
|
|
232 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(retailerId);
|
| 34037 |
amit.gupta |
233 |
retailerId = partnerTypeChangeService.getBestPartner(fs.getWarehouseId());
|
| 32458 |
amit.gupta |
234 |
} else {
|
| 34794 |
vikas.jang |
235 |
com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectByEmailId(Utils.SYSTEM_PARTNER);
|
| 32458 |
amit.gupta |
236 |
retailerId = user.getId();
|
|
|
237 |
}
|
|
|
238 |
}
|
|
|
239 |
responseMap.put(ProfitMandiConstants.TOKEN,
|
| 35272 |
amit |
240 |
jwtUtil.create(email, registeredUser.getId(), retailerId, roleTypes));
|
| 32458 |
amit.gupta |
241 |
LOGGER.info("Param value for email, registeredUser.getId(), retailerId, roleTypes are {}, {}, {} and {}",
|
|
|
242 |
email, registeredUser.getId(), retailerId, Arrays.asList(roleTypes));
|
|
|
243 |
responseMap.put(ProfitMandiConstants.REGISTERED, true);
|
|
|
244 |
return responseMap;
|
|
|
245 |
}
|
| 30295 |
amit.gupta |
246 |
|
| 32458 |
amit.gupta |
247 |
User user = null;
|
|
|
248 |
try {
|
| 34794 |
vikas.jang |
249 |
if (loginRequest.getPassword() != null) {
|
|
|
250 |
user = userService.authenticate(email, loginRequest.getPassword());
|
|
|
251 |
} else {
|
|
|
252 |
user = userRepository.selectByEmailId(email);
|
|
|
253 |
}
|
| 32458 |
amit.gupta |
254 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 30295 |
amit.gupta |
255 |
|
| 32458 |
amit.gupta |
256 |
}
|
|
|
257 |
if (user == null) {
|
|
|
258 |
try {
|
|
|
259 |
user = userRepository.selectByEmailId(email);
|
|
|
260 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 35272 |
amit |
261 |
responseMap.put(ProfitMandiConstants.TOKEN, jwtUtil.create(email));
|
| 32458 |
amit.gupta |
262 |
responseMap.put(ProfitMandiConstants.REGISTERED, false);
|
| 35377 |
aman |
263 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.NOT_REGISTERED_GOOGLE_ACCOUNT.getValue());
|
|
|
264 |
return responseMap;
|
| 32458 |
amit.gupta |
265 |
}
|
|
|
266 |
} else {
|
|
|
267 |
List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(user.getId());
|
|
|
268 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
|
|
|
269 |
String[] roleTypes = new String[roleIds.size()];
|
|
|
270 |
int index = 0;
|
|
|
271 |
for (int roleId : roleIds) {
|
|
|
272 |
roleTypes[index++] = String.valueOf(roleId);
|
|
|
273 |
}
|
| 35272 |
amit |
274 |
responseMap.put(ProfitMandiConstants.TOKEN, jwtUtil.create(user.getId(), retailerId, roleTypes));
|
| 32458 |
amit.gupta |
275 |
responseMap.put(ProfitMandiConstants.REGISTERED, true);
|
|
|
276 |
}
|
| 30295 |
amit.gupta |
277 |
|
| 32458 |
amit.gupta |
278 |
return responseMap;
|
|
|
279 |
}
|
| 30295 |
amit.gupta |
280 |
|
| 32458 |
amit.gupta |
281 |
@RequestMapping(value = "/store/token/{storeCode}", method = RequestMethod.GET)
|
|
|
282 |
public ResponseEntity<?> googleLogin(HttpServletRequest request, @PathVariable String storeCode)
|
|
|
283 |
throws ProfitMandiBusinessException {
|
|
|
284 |
LOGGER.info("StoreCode {}", storeCode);
|
|
|
285 |
return responseSender.ok(googleLoginProcessor.processStore(storeCode));
|
|
|
286 |
}
|
| 21469 |
amit.gupta |
287 |
|
| 34794 |
vikas.jang |
288 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_FORGOT_PASSWORD, method = RequestMethod.POST)
|
|
|
289 |
public ResponseEntity<?> forgotPassword(@RequestBody GoogleLoginRequest loginRequest) throws Exception {
|
|
|
290 |
userService.resetPassword(loginRequest.getEmail());
|
|
|
291 |
return responseSender.ok(true);
|
|
|
292 |
}
|
|
|
293 |
|
|
|
294 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_CHANGE_PASSWORD, method = RequestMethod.POST)
|
|
|
295 |
public ResponseEntity<?> changePassword(@RequestBody EmailPassword emailPassword) throws Exception {
|
|
|
296 |
User user = userService.authenticate(emailPassword.getEmail(), emailPassword.getPassword());
|
|
|
297 |
if (user != null){
|
|
|
298 |
boolean response = userService.changePassword(user, emailPassword.getNewPassword());
|
|
|
299 |
return responseSender.ok(response);
|
|
|
300 |
}
|
|
|
301 |
return responseSender.ok(false);
|
|
|
302 |
}
|
|
|
303 |
|
| 32458 |
amit.gupta |
304 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_TOKEN_IS_EXPIRED, method = RequestMethod.GET)
|
|
|
305 |
public ResponseEntity<?> tokenIsExpired(HttpServletRequest request, @RequestParam(name = "token") String token)
|
|
|
306 |
throws ProfitMandiBusinessException {
|
|
|
307 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 35272 |
amit |
308 |
return responseSender.ok(jwtUtil.isExpired(token));
|
| 32458 |
amit.gupta |
309 |
}
|
| 21469 |
amit.gupta |
310 |
|
| 35272 |
amit |
311 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_DETAIL_BY_TOKEN, method = RequestMethod.GET)
|
| 32458 |
amit.gupta |
312 |
@ApiImplicitParams({
|
|
|
313 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
314 |
public ResponseEntity<?> tokenInfo(HttpServletRequest request) throws Throwable {
|
|
|
315 |
Map<String, Object> responseMap = new HashMap<>();
|
|
|
316 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
317 |
LOGGER.info("userinfo1 {}", userInfo);
|
| 35257 |
amit |
318 |
|
| 32458 |
amit.gupta |
319 |
User user = null;
|
| 35257 |
amit |
320 |
// Case 1: When userId is present in token
|
| 32458 |
amit.gupta |
321 |
if (userInfo.getUserId() > -1) {
|
|
|
322 |
user = userRepository.selectById(userInfo.getUserId());
|
| 30552 |
tejbeer |
323 |
|
| 35257 |
amit |
324 |
// Special FOFO Associate handling for smartdukaan domain
|
|
|
325 |
boolean isSmartDukaanEmail = userInfo.getEmail() != null
|
|
|
326 |
&& user.getEmailId() != null
|
|
|
327 |
&& user.getEmailId().contains("@smartdukaan.com");
|
|
|
328 |
if (isSmartDukaanEmail) {
|
|
|
329 |
String userName;
|
| 32458 |
amit.gupta |
330 |
if (user.getSecondryEmailId() != null && user.getSecondryEmailId().equals(userInfo.getEmail())) {
|
|
|
331 |
userName = user.getFirstName() + " " + user.getLastName();
|
|
|
332 |
} else {
|
| 35257 |
amit |
333 |
AuthUser authUser = authRepository.selectByGmailId(userInfo.getEmail());
|
| 32458 |
amit.gupta |
334 |
LOGGER.info("authUser {}", authUser);
|
|
|
335 |
if (authUser == null || !authUser.isActive()) {
|
|
|
336 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.NOT_REGISTERED.getValue());
|
|
|
337 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, userInfo.getEmail());
|
|
|
338 |
return responseSender.ok(responseMap);
|
|
|
339 |
}
|
|
|
340 |
userName = authUser.getName();
|
|
|
341 |
}
|
|
|
342 |
responseMap.put(ProfitMandiConstants.USER_ID, userInfo.getUserId());
|
|
|
343 |
responseMap.put(ProfitMandiConstants.USER_NAME, userName);
|
|
|
344 |
responseMap.put(ProfitMandiConstants.USER_STATUS, "fofoAssociate");
|
|
|
345 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, userInfo.getEmail());
|
|
|
346 |
responseMap.put("storeUrl", "");
|
|
|
347 |
return responseSender.ok(responseMap);
|
|
|
348 |
}
|
|
|
349 |
} else {
|
| 35257 |
amit |
350 |
// Case 2: When userId is not present, try locate by emails
|
| 32458 |
amit.gupta |
351 |
try {
|
|
|
352 |
LOGGER.info("userinfo4 {}", userInfo);
|
|
|
353 |
user = userRepository.selectByEmailId(userInfo.getEmail());
|
|
|
354 |
} catch (ProfitMandiBusinessException e1) {
|
| 35257 |
amit |
355 |
LOGGER.warn("Failed to fetch user by primary email: {}", userInfo.getEmail(), e1);
|
| 32458 |
amit.gupta |
356 |
}
|
|
|
357 |
if (user == null) {
|
|
|
358 |
try {
|
|
|
359 |
LOGGER.info("userinfo8 {}", userInfo);
|
|
|
360 |
user = userRepository.selectBySecondryEmailId(userInfo.getEmail());
|
|
|
361 |
} catch (ProfitMandiBusinessException e1) {
|
| 35257 |
amit |
362 |
LOGGER.info("Unregistered user: {}", userInfo.getEmail());
|
| 32458 |
amit.gupta |
363 |
}
|
|
|
364 |
}
|
|
|
365 |
}
|
| 35257 |
amit |
366 |
|
| 32458 |
amit.gupta |
367 |
if (user != null) {
|
|
|
368 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, user.getEmailId());
|
|
|
369 |
responseMap.put(ProfitMandiConstants.USER_ID, user.getId());
|
|
|
370 |
responseMap.put(ProfitMandiConstants.USER_NAME, user.getFirstName() + " " + user.getLastName());
|
| 32721 |
ranu |
371 |
|
| 32458 |
amit.gupta |
372 |
List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(user.getId());
|
| 35257 |
amit |
373 |
LOGGER.info("userRoles for {}", user.getEmailId());
|
| 22032 |
ashik.ali |
374 |
|
| 32721 |
ranu |
375 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
|
| 32458 |
amit.gupta |
376 |
// generate new token if roles have been updated
|
|
|
377 |
if (userInfo.getRoleIds() == null || roleIds.size() != userInfo.getRoleIds().size()) {
|
| 35257 |
amit |
378 |
String[] roleIdStrings = roleIds.stream().map(String::valueOf).toArray(String[]::new);
|
| 35272 |
amit |
379 |
String newToken = jwtUtil.create(user.getId(), retailerId, roleIdStrings);
|
| 32458 |
amit.gupta |
380 |
responseMap.put("newAuthToken", newToken);
|
|
|
381 |
}
|
| 35257 |
amit |
382 |
|
| 32458 |
amit.gupta |
383 |
// if user is retailer
|
| 35257 |
amit |
384 |
Set<Integer> roleIdsSet = new HashSet<>(roleIds);
|
| 32458 |
amit.gupta |
385 |
if (roleManager.isRetailer(roleIdsSet)) {
|
|
|
386 |
UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
|
|
387 |
Retailer retailer = retailerRepository.selectById(uc.getUserId());
|
|
|
388 |
com.spice.profitmandi.dao.entity.user.User saholicUser = userUserRepository.selectById(uc.getUserId());
|
|
|
389 |
if (saholicUser.getAddressId() != null) {
|
|
|
390 |
Address address = addressRepository.selectById(saholicUser.getAddressId());
|
|
|
391 |
responseMap.put(ProfitMandiConstants.ADDRESS, address);
|
|
|
392 |
}
|
| 34794 |
vikas.jang |
393 |
|
| 32458 |
amit.gupta |
394 |
if (retailer.isActive() || user.isActivated()) {
|
|
|
395 |
if (roleManager.isPartner(roleIdsSet)) {
|
|
|
396 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(saholicUser.getId());
|
|
|
397 |
if (fofoStore.isActive()) {
|
|
|
398 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.FOFO.getValue());
|
|
|
399 |
responseMap.put("storeUrl", retailerService.getAllFofoRetailerIdUrlMap().get(uc.getUserId()));
|
|
|
400 |
responseMap.put("timelineStatus", this.getTimeLineStatus(uc.getUserId()));
|
| 35296 |
amit |
401 |
if(fofoStore.isTrial()) {
|
|
|
402 |
responseMap.put("fofoTrialEndDate", fofoStore.getTrialEnd());
|
| 35373 |
aman |
403 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.FOFO_TRIAL.getValue());
|
| 35296 |
amit |
404 |
}
|
| 32458 |
amit.gupta |
405 |
} else {
|
|
|
406 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.VERIFIED_RETAILER.getValue());
|
|
|
407 |
}
|
|
|
408 |
} else {
|
|
|
409 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.VERIFIED_RETAILER.getValue());
|
|
|
410 |
}
|
|
|
411 |
} else if (retailer.isMigrated()) {
|
|
|
412 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.RETAILER.getValue());
|
|
|
413 |
} else {
|
|
|
414 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.NOT_VERIFIED_RETAILER.getValue());
|
|
|
415 |
}
|
|
|
416 |
} else if (roleManager.isUser(roleIdsSet)) {
|
|
|
417 |
responseMap.put("userInfo", getRegisteredUserInfo(user));
|
|
|
418 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.REGISTERED.getValue());
|
|
|
419 |
}
|
|
|
420 |
} else {
|
|
|
421 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.NOT_REGISTERED.getValue());
|
|
|
422 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, userInfo.getEmail());
|
|
|
423 |
}
|
| 22032 |
ashik.ali |
424 |
|
| 32458 |
amit.gupta |
425 |
return responseSender.ok(responseMap);
|
|
|
426 |
}
|
| 25366 |
tejbeer |
427 |
|
| 32458 |
amit.gupta |
428 |
@Autowired
|
|
|
429 |
FofoStoreRepository fofoStoreRepository;
|
|
|
430 |
@Autowired
|
|
|
431 |
PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
|
|
|
432 |
@Autowired
|
|
|
433 |
StoreTimelineTatService storeTimelineTatService;
|
| 29878 |
tejbeer |
434 |
|
| 32458 |
amit.gupta |
435 |
private boolean getTimeLineStatus(int fofoId) throws ProfitMandiBusinessException {
|
|
|
436 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
|
|
|
437 |
PartnerOnBoardingPanel partnerOnBoardingPanel = partnerOnBoardingPanelRepository.selectByCode(fs.getCode());
|
|
|
438 |
boolean status = true;
|
|
|
439 |
if (partnerOnBoardingPanel != null) {
|
| 29011 |
amit.gupta |
440 |
|
| 32458 |
amit.gupta |
441 |
status = storeTimelineTatService.getTimelineCompleted(partnerOnBoardingPanel.getId());
|
|
|
442 |
}
|
| 29011 |
amit.gupta |
443 |
|
| 32458 |
amit.gupta |
444 |
LOGGER.info("status" + status);
|
|
|
445 |
return status;
|
|
|
446 |
}
|
| 29011 |
amit.gupta |
447 |
|
| 32458 |
amit.gupta |
448 |
private RegisteredUserInfo getRegisteredUserInfo(User user) throws Throwable {
|
|
|
449 |
RegisteredUserInfo ri = new RegisteredUserInfo();
|
|
|
450 |
ri.setCity(user.getCity());
|
|
|
451 |
ri.setFirstName(user.getFirstName());
|
|
|
452 |
ri.setLastName(user.getLastName());
|
|
|
453 |
ri.setPhone(user.getMobileNumber());
|
|
|
454 |
ri.setPinCode(user.getPinCode());
|
|
|
455 |
ri.setState(user.getState());
|
|
|
456 |
return ri;
|
|
|
457 |
}
|
| 21469 |
amit.gupta |
458 |
|
| 32458 |
amit.gupta |
459 |
@RequestMapping(value = ProfitMandiConstants.URL_USER, method = RequestMethod.POST)
|
|
|
460 |
@ApiImplicitParams({
|
|
|
461 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
462 |
public ResponseEntity<?> createUser(HttpServletRequest request, @RequestBody UserRequest userRequest)
|
|
|
463 |
throws ProfitMandiBusinessException {
|
|
|
464 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
|
|
465 |
User user = new User();
|
|
|
466 |
user.setFirstName(userRequest.getFirstName());
|
|
|
467 |
user.setLastName(userRequest.getLastName());
|
|
|
468 |
user.setCity(userRequest.getCity());
|
|
|
469 |
user.setPinCode(Integer.valueOf(userRequest.getPinCode()));
|
|
|
470 |
user.setState(userRequest.getState());
|
|
|
471 |
user.setMobileNumber(userRequest.getMobieNumber());
|
|
|
472 |
user.setEmailId(userRequest.getEmailId());
|
|
|
473 |
user.setUsername("");
|
|
|
474 |
user.setPassword("");
|
|
|
475 |
user.setMobile_verified(false);
|
|
|
476 |
user.setReferral_url("");
|
|
|
477 |
user.setGroup_id(1);
|
|
|
478 |
user.setStatus(1);
|
|
|
479 |
user.setActivated(false);
|
|
|
480 |
user.setCreateTimestamp(LocalDateTime.now());
|
|
|
481 |
user.setUpdateTimestamp(LocalDateTime.now());
|
|
|
482 |
userRepository.persist(user);
|
|
|
483 |
Role role = roleRepository.selectByName(RoleType.USER.toString());
|
|
|
484 |
UserRole userRole = new UserRole();
|
|
|
485 |
userRole.setRoleId(role.getId());
|
|
|
486 |
userRole.setUserId(user.getId());
|
|
|
487 |
userRoleRepository.persist(userRole);
|
|
|
488 |
return responseSender.ok(ResponseCodeHolder.getMessage("USR_OK_1000"));
|
| 25366 |
tejbeer |
489 |
|
| 32458 |
amit.gupta |
490 |
}
|
| 21469 |
amit.gupta |
491 |
|
| 32458 |
amit.gupta |
492 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ID, method = RequestMethod.GET)
|
|
|
493 |
public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id)
|
|
|
494 |
throws ProfitMandiBusinessException {
|
|
|
495 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
|
|
496 |
return responseSender.ok(userRepository.selectById(id));
|
|
|
497 |
}
|
| 21469 |
amit.gupta |
498 |
|
| 32458 |
amit.gupta |
499 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_MOBILE_NUMBER, method = RequestMethod.GET)
|
|
|
500 |
public ResponseEntity<?> getByMobileNumber(HttpServletRequest request,
|
|
|
501 |
@RequestParam(name = "mobileNumber") String mobileNumber) throws ProfitMandiBusinessException {
|
|
|
502 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
|
|
503 |
return responseSender.ok(userRepository.selectByMobileNumber(mobileNumber));
|
|
|
504 |
}
|
| 21469 |
amit.gupta |
505 |
|
| 32458 |
amit.gupta |
506 |
@ApiImplicitParams({
|
|
|
507 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
508 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ACTIVATE, method = RequestMethod.POST)
|
|
|
509 |
public ResponseEntity<?> activateUser(HttpServletRequest request,
|
|
|
510 |
@RequestParam(name = "activationCode") String activationCode) throws Throwable {
|
|
|
511 |
int userId = (int) request.getAttribute("userId");
|
|
|
512 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
|
|
513 |
return responseSender.ok(userService.updateActivation(userId, uc.getUserId(), activationCode));
|
|
|
514 |
}
|
| 21855 |
amit.gupta |
515 |
|
| 32458 |
amit.gupta |
516 |
/*
|
|
|
517 |
* @ApiImplicitParams({
|
|
|
518 |
*
|
|
|
519 |
* @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true,
|
|
|
520 |
* dataType = "string", paramType = "header") })
|
|
|
521 |
*
|
|
|
522 |
* @RequestMapping(value = ProfitMandiConstants.URL_USER_NOTIFICATIONS, method =
|
|
|
523 |
* RequestMethod.GET) public ResponseEntity<?>
|
|
|
524 |
* getNofitications(HttpServletRequest request,
|
|
|
525 |
*
|
|
|
526 |
* @RequestParam(name = "androidId") String androidId, @RequestParam(name =
|
|
|
527 |
* "pageNumber") int pageNumber,
|
|
|
528 |
*
|
|
|
529 |
* @RequestParam(name = "pageSize") int pageSize) throws
|
|
|
530 |
* ProfitMandiBusinessException { int userId = (int)
|
|
|
531 |
* request.getAttribute("userId"); String restResponse = null; Map<String,
|
|
|
532 |
* String> params = new HashMap<>();
|
|
|
533 |
*
|
|
|
534 |
* String uri = "/getAllNotifications"; params.put("user_id", userId + "");
|
|
|
535 |
* params.put("android_id", androidId); params.put("limit", pageSize + "");
|
|
|
536 |
* params.put("offset", "" + ((pageNumber - 1) * pageSize)); try { restResponse
|
|
|
537 |
* = restClient.get(SchemeType.HTTP, nodeHost, nodePort, uri, params); } catch
|
|
|
538 |
* (HttpHostConnectException e) { throw new ProfitMandiBusinessException("", "",
|
|
|
539 |
* "Could not Connect to host"); }
|
|
|
540 |
*
|
|
|
541 |
* JsonArray result_json = Json.parse(restResponse).asArray();
|
|
|
542 |
*
|
|
|
543 |
* List<Notification> notifications = new ArrayList<>();
|
|
|
544 |
*
|
|
|
545 |
* for (JsonValue j : result_json) {
|
|
|
546 |
* notifications.add(toNotifiaction(j.asObject())); }
|
|
|
547 |
*
|
|
|
548 |
* return responseSender.ok(notifications); }
|
|
|
549 |
*
|
|
|
550 |
* private Notification toNotifiaction(JsonObject jsonObject) { Notification n =
|
|
|
551 |
* (Notification) (new Gson().fromJson(jsonObject.toString(),
|
|
|
552 |
* Notification.class)); if (n.getStatus().equals("opened") ||
|
|
|
553 |
* n.getStatus().equals("referrer") || n.getStatus().equals("seen")) {
|
|
|
554 |
* n.setSeen(true); } return n; }
|
|
|
555 |
*/
|
| 21855 |
amit.gupta |
556 |
|
| 32458 |
amit.gupta |
557 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_IS_EXIST_MOBILE_NUMBER, method = RequestMethod.GET)
|
|
|
558 |
public ResponseEntity<?> isMobileNumberExist(HttpServletRequest request,
|
|
|
559 |
@RequestParam(name = "mobileNumber") String mobileNumber) {
|
|
|
560 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
|
|
561 |
return responseSender.ok(userRepository.isExistByMobileNumber(mobileNumber));
|
|
|
562 |
}
|
| 21469 |
amit.gupta |
563 |
|
| 32458 |
amit.gupta |
564 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_EMAIL_ID, method = RequestMethod.GET)
|
|
|
565 |
public ResponseEntity<?> getByEmailId(HttpServletRequest request, @RequestParam(name = "emailId") String emailId)
|
|
|
566 |
throws ProfitMandiBusinessException {
|
|
|
567 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
|
|
568 |
User user = null;
|
|
|
569 |
try {
|
|
|
570 |
user = userRepository.selectByEmailId(emailId);
|
|
|
571 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
572 |
user = userRepository.selectBySecondryEmailId(emailId);
|
|
|
573 |
}
|
|
|
574 |
return responseSender.ok(user);
|
|
|
575 |
}
|
| 21469 |
amit.gupta |
576 |
|
| 32458 |
amit.gupta |
577 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_ALL, method = RequestMethod.GET)
|
|
|
578 |
public ResponseEntity<?> getAllRoles(HttpServletRequest request, @RequestParam(name = "id") int id) {
|
|
|
579 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
|
|
580 |
return responseSender.ok(userRoleRepository.selectRolesByUserId(id));
|
|
|
581 |
}
|
| 25366 |
tejbeer |
582 |
|
| 32458 |
amit.gupta |
583 |
@ApiImplicitParams({
|
|
|
584 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
585 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_SECONDRY_EMAIL_ID_AND_FOFO_STORE_CODE, method = RequestMethod.GET)
|
|
|
586 |
public ResponseEntity<?> getSecondryEmailAndStoreCode(HttpServletRequest request)
|
|
|
587 |
throws ProfitMandiBusinessException {
|
|
|
588 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
|
|
589 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
|
|
590 |
return responseSender.ok(userService.getEmailsAndFofoStoreCodeByUserId(userId));
|
|
|
591 |
}
|
| 25366 |
tejbeer |
592 |
|
| 32458 |
amit.gupta |
593 |
@ApiImplicitParams({
|
|
|
594 |
@ApiImplicitParam(name = "Auth-Token", value = "-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
595 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_SECONDRY_EMAIL_ID, method = RequestMethod.PUT)
|
|
|
596 |
public ResponseEntity<?> updateSecondryEmailId(HttpServletRequest request,
|
|
|
597 |
@RequestParam(name = ProfitMandiConstants.SECONDRY_EMAIL_ID) String secondryEmailId) throws Throwable {
|
|
|
598 |
int userId = (int) request.getAttribute("userId");
|
|
|
599 |
User user = userRepository.selectById(userId);
|
|
|
600 |
user.setSecondryEmailId(secondryEmailId);
|
|
|
601 |
userRepository.persist(user);
|
|
|
602 |
return responseSender.ok(ResponseCodeHolder.getMessage("USR_OK_1001"));
|
|
|
603 |
}
|
| 21414 |
kshitij.so |
604 |
|
| 32458 |
amit.gupta |
605 |
@RequestMapping(value = ProfitMandiConstants.URL_ADMIN_TOKEN, method = RequestMethod.POST)
|
| 34794 |
vikas.jang |
606 |
public ResponseEntity<?> getAdminToken(HttpServletRequest request, @RequestParam(name = "adminToken") String adminToken, @RequestParam(name = "emailId") String emailId) throws Exception {
|
| 32458 |
amit.gupta |
607 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
|
|
608 |
if (!adminToken.equals(validAdminToken)) {
|
|
|
609 |
return responseSender.forbidden(null);
|
|
|
610 |
}
|
| 34794 |
vikas.jang |
611 |
GoogleLoginRequest loginRequest = new GoogleLoginRequest();
|
|
|
612 |
loginRequest.setToken(adminToken);
|
|
|
613 |
loginRequest.setEmail(emailId);
|
|
|
614 |
loginRequest.setType("Internal");
|
| 21469 |
amit.gupta |
615 |
|
| 34794 |
vikas.jang |
616 |
return responseSender.ok(this.getAuthTokenMap(emailId, loginRequest));
|
| 25366 |
tejbeer |
617 |
|
| 32458 |
amit.gupta |
618 |
}
|
| 25366 |
tejbeer |
619 |
|
| 32458 |
amit.gupta |
620 |
@RequestMapping(value = "/mobileappsettings1", method = RequestMethod.POST)
|
|
|
621 |
public ResponseEntity<?> mobileAppSettings1(HttpServletRequest request, @RequestParam(name = "t") int timestamp,
|
|
|
622 |
@RequestParam(name = "imeinumber") String imeinumber)
|
|
|
623 |
throws ProfitMandiBusinessException, ClientProtocolException, IOException {
|
|
|
624 |
LocalDateTime settingsLastUpdated = LocalDateTime.ofEpochSecond(timestamp, 0, ZoneOffset.ofHoursMinutes(5, 30));
|
|
|
625 |
List<MobileAppSetting> mobileAppSettings = mobileAppSettingsRepository.getSettingAftera(settingsLastUpdated);
|
| 26792 |
tejbeer |
626 |
|
| 32458 |
amit.gupta |
627 |
List<MobileAppSettingsWrapper> mobileSettingsWrappersList = mobileAppSettings.stream()
|
|
|
628 |
.map(x -> new MobileAppSettingsWrapper(x)).collect(Collectors.toList());
|
|
|
629 |
SettingsWrapper wrapper = new SettingsWrapper(mobileSettingsWrappersList);
|
| 26792 |
tejbeer |
630 |
|
| 32458 |
amit.gupta |
631 |
LOGGER.info("Wrapper {}", wrapper);
|
|
|
632 |
return responseSender.ok(objectMapper.writeValueAsString(wrapper));
|
|
|
633 |
}
|
| 22032 |
ashik.ali |
634 |
|
| 37866 |
ranu |
635 |
/**
|
|
|
636 |
* React admin partner list. Broader than v1 {@link #getPartners}: Sales, RBM, ABM,
|
|
|
637 |
* Category, Training and BI positions all see their assigned partners (v1 only
|
|
|
638 |
* mapped Sales/RBM/ABM, so the other HO roles got an empty list), and any user
|
|
|
639 |
* with a Technology position sees every active partner across the catalogue —
|
|
|
640 |
* tech ops has no region/partner scope.
|
|
|
641 |
*
|
|
|
642 |
* Angular's /getPartners is intentionally unchanged. This method exists only so
|
|
|
643 |
* the v2 React route can call it without regressing the Angular v1 behaviour.
|
|
|
644 |
*/
|
|
|
645 |
public ResponseEntity<?> getPartnersV2(HttpServletRequest request, String gmailId, int offset, int limit)
|
|
|
646 |
throws ProfitMandiBusinessException {
|
|
|
647 |
AuthUser authUser = authRepository.selectByGmailId(gmailId);
|
|
|
648 |
if (authUser == null) {
|
|
|
649 |
LOGGER.warn("No auth user found for gmailId: {}", gmailId);
|
|
|
650 |
return responseSender.badRequest("No user found for the provided email");
|
|
|
651 |
}
|
|
|
652 |
|
|
|
653 |
// Expanded HO roster for assigned-partner visibility. If you need another
|
|
|
654 |
// category to see partners on the React page, add it here — nothing else.
|
|
|
655 |
List<Integer> partnerVisibleCategoryIds = Arrays.asList(
|
|
|
656 |
ProfitMandiConstants.TICKET_CATEGORY_SALES,
|
|
|
657 |
ProfitMandiConstants.TICKET_CATEGORY_RBM,
|
|
|
658 |
ProfitMandiConstants.TICKET_CATEGORY_ABM,
|
|
|
659 |
ProfitMandiConstants.TICKET_CATEGORY_CATEGORY,
|
|
|
660 |
ProfitMandiConstants.TICKET_CATEGORY_TRAINING,
|
|
|
661 |
ProfitMandiConstants.TICKET_CATEGORY_BUSINESSINTELLIGENT);
|
|
|
662 |
|
|
|
663 |
Set<String> emails = new HashSet<>();
|
|
|
664 |
boolean isTechUser = positionRepository.selectAllByAuthUserId(authUser.getId()).stream()
|
|
|
665 |
.anyMatch(p -> p != null && p.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_TECHNOLOGY);
|
|
|
666 |
|
|
|
667 |
if (isTechUser) {
|
|
|
668 |
// Tech ops override: union of every partner any HO user is mapped to.
|
|
|
669 |
// Using the mapping (not a bare fofo-store scan) keeps the "active +
|
|
|
670 |
// assigned" filter that the rest of the admin uses, so tech sees the
|
|
|
671 |
// same universe operators see, not a wider raw-DB set.
|
|
|
672 |
Map<String, Set<String>> fullMap = csService.getAuthUserPartnerEmailMappingByCategoryIds(partnerVisibleCategoryIds);
|
|
|
673 |
for (Set<String> perUser : fullMap.values()) {
|
|
|
674 |
if (perUser != null) emails.addAll(perUser);
|
|
|
675 |
}
|
|
|
676 |
} else {
|
|
|
677 |
Map<String, Set<String>> storeGuyMap = csService.getAuthUserPartnerEmailMappingByCategoryIds(partnerVisibleCategoryIds);
|
|
|
678 |
Set<String> mine = storeGuyMap.get(authUser.getEmailId().toLowerCase());
|
|
|
679 |
if (mine != null) {
|
|
|
680 |
emails.addAll(mine);
|
|
|
681 |
}
|
|
|
682 |
}
|
|
|
683 |
emails.addAll(demoPartnerAccessService.getDemoPartnerEmails(authUser.getId()));
|
|
|
684 |
|
|
|
685 |
if (emails.isEmpty()) {
|
|
|
686 |
LOGGER.info("No partner emails found for v2 user: {}", gmailId);
|
|
|
687 |
return responseSender.ok(new ArrayList<>());
|
|
|
688 |
}
|
|
|
689 |
|
|
|
690 |
List<User> users = userRepository.selectAllByEmails(new ArrayList<>(emails), offset, limit);
|
|
|
691 |
List<Partner> partners = new ArrayList<>();
|
|
|
692 |
for (User user : users) {
|
|
|
693 |
try {
|
|
|
694 |
Integer accountKey = userAccountRepository.selectSaholicAccountKeySafe(user.getId());
|
|
|
695 |
if (accountKey == null) {
|
|
|
696 |
LOGGER.warn("No usable saholic account for userId: {}", user.getId());
|
|
|
697 |
continue;
|
|
|
698 |
}
|
|
|
699 |
com.spice.profitmandi.dao.entity.user.User userInfo = userUserRepository.selectById(accountKey);
|
|
|
700 |
if (userInfo == null) {
|
|
|
701 |
LOGGER.warn("No user info found for accountKey: {}", accountKey);
|
|
|
702 |
continue;
|
|
|
703 |
}
|
|
|
704 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(userInfo.getId());
|
|
|
705 |
if (customRetailer == null) {
|
|
|
706 |
LOGGER.warn("No custom retailer found for userInfoId: {}", userInfo.getId());
|
|
|
707 |
continue;
|
|
|
708 |
}
|
|
|
709 |
Partner partner = new Partner();
|
|
|
710 |
partner.setBusinessName(customRetailer.getBusinessName());
|
|
|
711 |
partner.setPartnerId(customRetailer.getPartnerId());
|
|
|
712 |
partner.setCartId(customRetailer.getCartId());
|
|
|
713 |
partner.setEmail(customRetailer.getEmail());
|
|
|
714 |
partner.setGstNumber(customRetailer.getGstNumber());
|
|
|
715 |
partner.setDisplayName(customRetailer.getDisplayName());
|
|
|
716 |
partner.setStoreCode(customRetailer.getCode());
|
|
|
717 |
partner.setCity(customRetailer.getAddress() != null ? customRetailer.getAddress().getCity() : null);
|
|
|
718 |
partner.setUserId(user.getId());
|
|
|
719 |
partners.add(partner);
|
|
|
720 |
} catch (Exception e) {
|
|
|
721 |
LOGGER.error("Error processing partner for userId: {}", user.getId(), e);
|
|
|
722 |
}
|
|
|
723 |
}
|
|
|
724 |
return responseSender.ok(partners);
|
|
|
725 |
}
|
|
|
726 |
|
| 32458 |
amit.gupta |
727 |
@RequestMapping(value = "/getPartners", method = RequestMethod.GET)
|
|
|
728 |
@ApiImplicitParams({
|
|
|
729 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
730 |
public ResponseEntity<?> getPartners(HttpServletRequest request, @RequestParam(name = "gmailId") String gmailId,
|
|
|
731 |
@RequestParam(value = "offset") int offset, @RequestParam(value = "limit") int limit)
|
|
|
732 |
throws ProfitMandiBusinessException {
|
|
|
733 |
AuthUser authUser = authRepository.selectByGmailId(gmailId);
|
| 35625 |
aman |
734 |
if (authUser == null) {
|
|
|
735 |
LOGGER.warn("No auth user found for gmailId: {}", gmailId);
|
|
|
736 |
return responseSender.badRequest("No user found for the provided email");
|
|
|
737 |
}
|
| 25366 |
tejbeer |
738 |
|
| 32458 |
amit.gupta |
739 |
Map<String, Set<String>> storeGuyMap = csService.getAuthUserPartnerEmailMapping();
|
| 25366 |
tejbeer |
740 |
|
| 37781 |
amit |
741 |
// Copy: the mapping is a shared cached object and must not carry demo partners.
|
|
|
742 |
Set<String> emails = new HashSet<>();
|
|
|
743 |
if (storeGuyMap.get(authUser.getEmailId().toLowerCase()) != null) {
|
|
|
744 |
emails.addAll(storeGuyMap.get(authUser.getEmailId().toLowerCase()));
|
|
|
745 |
}
|
|
|
746 |
emails.addAll(demoPartnerAccessService.getDemoPartnerEmails(authUser.getId()));
|
| 35625 |
aman |
747 |
LOGGER.info("emails: {}", emails);
|
|
|
748 |
if (emails == null || emails.isEmpty()) {
|
|
|
749 |
LOGGER.info("No partner emails found for user: {}", gmailId);
|
|
|
750 |
return responseSender.ok(new ArrayList<>());
|
|
|
751 |
}
|
| 32458 |
amit.gupta |
752 |
List<User> users = userRepository.selectAllByEmails(new ArrayList<>(emails), offset, limit);
|
|
|
753 |
List<Partner> partners = new ArrayList<>();
|
|
|
754 |
for (User user : users) {
|
| 35625 |
aman |
755 |
try {
|
| 37157 |
amit |
756 |
Integer accountKey = userAccountRepository.selectSaholicAccountKeySafe(user.getId());
|
|
|
757 |
if (accountKey == null) {
|
|
|
758 |
LOGGER.warn("No usable saholic account for userId: {}", user.getId());
|
| 35625 |
aman |
759 |
continue;
|
|
|
760 |
}
|
| 37157 |
amit |
761 |
com.spice.profitmandi.dao.entity.user.User userInfo = userUserRepository.selectById(accountKey);
|
| 35625 |
aman |
762 |
if (userInfo == null) {
|
| 37157 |
amit |
763 |
LOGGER.warn("No user info found for accountKey: {}", accountKey);
|
| 35625 |
aman |
764 |
continue;
|
|
|
765 |
}
|
|
|
766 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(userInfo.getId());
|
|
|
767 |
if (customRetailer == null) {
|
|
|
768 |
LOGGER.warn("No custom retailer found for userInfoId: {}", userInfo.getId());
|
|
|
769 |
continue;
|
|
|
770 |
}
|
| 25458 |
tejbeer |
771 |
|
| 35625 |
aman |
772 |
Partner partner = new Partner();
|
|
|
773 |
partner.setBusinessName(customRetailer.getBusinessName());
|
|
|
774 |
partner.setPartnerId(customRetailer.getPartnerId());
|
|
|
775 |
partner.setCartId(customRetailer.getCartId());
|
|
|
776 |
partner.setEmail(customRetailer.getEmail());
|
|
|
777 |
partner.setGstNumber(customRetailer.getGstNumber());
|
|
|
778 |
partner.setDisplayName(customRetailer.getDisplayName());
|
| 35952 |
vikas |
779 |
partner.setStoreCode(customRetailer.getCode());
|
| 35625 |
aman |
780 |
partner.setCity(customRetailer.getAddress() != null ? customRetailer.getAddress().getCity() : null);
|
|
|
781 |
partner.setUserId(user.getId());
|
|
|
782 |
partners.add(partner);
|
|
|
783 |
} catch (Exception e) {
|
|
|
784 |
LOGGER.error("Error processing partner for userId: {}", user.getId(), e);
|
|
|
785 |
}
|
| 32458 |
amit.gupta |
786 |
}
|
| 35625 |
aman |
787 |
LOGGER.info("partners: {}", partners);
|
| 32458 |
amit.gupta |
788 |
return responseSender.ok(partners);
|
|
|
789 |
}
|
| 25366 |
tejbeer |
790 |
|
| 32458 |
amit.gupta |
791 |
@RequestMapping(value = "/user/refferal", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
792 |
@ApiImplicitParams({
|
|
|
793 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
794 |
public ResponseEntity<?> RefferalUser(HttpServletRequest request,
|
|
|
795 |
@RequestBody CreateRefferalRequest createRefferalRequest) throws Exception {
|
|
|
796 |
Refferal refferal = new Refferal();
|
|
|
797 |
refferal.setFirstName(createRefferalRequest.getFirstName());
|
|
|
798 |
refferal.setLastName(createRefferalRequest.getLastName());
|
|
|
799 |
refferal.setMobile(createRefferalRequest.getMobile());
|
|
|
800 |
refferal.setState(createRefferalRequest.getState());
|
|
|
801 |
refferal.setCity(createRefferalRequest.getCity());
|
|
|
802 |
refferal.setCreatedTimestamp(LocalDateTime.now());
|
|
|
803 |
refferal.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
804 |
refferal.setStatus(RefferalStatus.pending);
|
|
|
805 |
if (createRefferalRequest.isFofoAssociate()) {
|
|
|
806 |
AuthUser authUser = authRepository.selectByGmailId(createRefferalRequest.getReffereeEmail());
|
|
|
807 |
if (authUser == null) {
|
|
|
808 |
Promoter promoter = promoterRepository.selectByEmailId(createRefferalRequest.getReffereeEmail());
|
|
|
809 |
refferal.setRefereeName(promoter.getName());
|
|
|
810 |
refferal.setRefereeEmail(promoter.getEmail());
|
|
|
811 |
refferal.setRefereeMobile(promoter.getMobile());
|
|
|
812 |
} else {
|
|
|
813 |
refferal.setRefereeName(authUser.getFirstName());
|
|
|
814 |
refferal.setRefereeEmail(authUser.getGmailId());
|
|
|
815 |
refferal.setRefereeMobile(authUser.getMobileNumber());
|
|
|
816 |
}
|
|
|
817 |
} else {
|
|
|
818 |
User user = userRepository.selectByEmailId(createRefferalRequest.getReffereeEmail());
|
|
|
819 |
refferal.setRefereeName(user.getFirstName());
|
|
|
820 |
refferal.setRefereeEmail(user.getEmailId());
|
|
|
821 |
refferal.setRefereeMobile(user.getMobileNumber());
|
|
|
822 |
}
|
| 25458 |
tejbeer |
823 |
|
| 32458 |
amit.gupta |
824 |
refferalRepository.persist(refferal);
|
| 29892 |
tejbeer |
825 |
|
| 32458 |
amit.gupta |
826 |
List<PartnerOnBoardingPanel> pobs = partnerOnBoardingPanelRepository
|
|
|
827 |
.selectAllByPhoneNumber((Long.parseLong(refferal.getMobile())));
|
| 29892 |
tejbeer |
828 |
|
| 32458 |
amit.gupta |
829 |
if (!pobs.isEmpty()) {
|
| 29892 |
tejbeer |
830 |
|
| 32458 |
amit.gupta |
831 |
List<PartnerOnBoardingStatus> ponbStatus = pobs.stream().map(x -> x.getStatus())
|
|
|
832 |
.collect(Collectors.toList());
|
| 29892 |
tejbeer |
833 |
|
| 32458 |
amit.gupta |
834 |
if (ponbStatus.contains(PartnerOnBoardingStatus.open)) {
|
|
|
835 |
refferal.setStatus(RefferalStatus.rejected);
|
|
|
836 |
refferal.setRejectedReason("This is already a Smartdukaan Partner.");
|
|
|
837 |
} else if (ponbStatus.contains(PartnerOnBoardingStatus.pending)) {
|
|
|
838 |
refferal.setStatus(RefferalStatus.rejected);
|
|
|
839 |
refferal.setRejectedReason("This is already a Smartdukaan Partner.");
|
|
|
840 |
} else {
|
|
|
841 |
this.sendEmailToValidate(refferal);
|
|
|
842 |
}
|
| 29892 |
tejbeer |
843 |
|
| 32458 |
amit.gupta |
844 |
} else {
|
| 29892 |
tejbeer |
845 |
|
| 32458 |
amit.gupta |
846 |
this.sendEmailToValidate(refferal);
|
| 29892 |
tejbeer |
847 |
|
| 32458 |
amit.gupta |
848 |
}
|
|
|
849 |
return responseSender.ok(true);
|
|
|
850 |
}
|
| 29892 |
tejbeer |
851 |
|
| 32458 |
amit.gupta |
852 |
private void sendEmailToValidate(Refferal refferal) throws MessagingException, UnsupportedEncodingException {
|
| 29892 |
tejbeer |
853 |
|
| 32458 |
amit.gupta |
854 |
String subject = "Referral Validate Request for " + refferal.getRefereeEmail();
|
|
|
855 |
String messageText = this.getMessageForReferral(refferal);
|
| 36400 |
amit |
856 |
MimeMessage message = gmailRelaySender.createMimeMessage();
|
| 32458 |
amit.gupta |
857 |
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
| 37629 |
amit |
858 |
String[] email = {"kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com"};
|
| 32458 |
amit.gupta |
859 |
helper.setSubject(subject);
|
|
|
860 |
helper.setText(messageText, true);
|
|
|
861 |
helper.setTo(email);
|
|
|
862 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smartdukaan Alerts");
|
|
|
863 |
helper.setFrom(senderAddress);
|
| 36400 |
amit |
864 |
gmailRelaySender.send(message);
|
| 26792 |
tejbeer |
865 |
|
| 32458 |
amit.gupta |
866 |
}
|
| 25488 |
tejbeer |
867 |
|
| 32458 |
amit.gupta |
868 |
private String getMessageForReferral(Refferal referral) {
|
| 26792 |
tejbeer |
869 |
|
| 32458 |
amit.gupta |
870 |
StringBuilder sb = new StringBuilder();
|
|
|
871 |
sb.append("<html><body><p>Alert</p><p> Referral Requests:-</p>"
|
|
|
872 |
+ "<br/><table style='border:1px solid black ;padding: 5px';>");
|
|
|
873 |
sb.append("<tbody>\n" + " <tr>\n"
|
|
|
874 |
+ " <th style='border:1px solid black;padding: 5px'>RefereeName</th>\n"
|
|
|
875 |
+ " <th style='border:1px solid black;padding: 5px'>Referee Email</th>\n"
|
|
|
876 |
+ " <th style='border:1px solid black;padding: 5px'>Referral Name</th>\n"
|
|
|
877 |
+ " <th style='border:1px solid black;padding: 5px'>Refferal Mobile</th>\n"
|
|
|
878 |
+ " <th style='border:1px solid black;padding: 5px'>city</th>\n"
|
|
|
879 |
+ " <th style='border:1px solid black;padding: 5px'>state</th>\n"
|
|
|
880 |
+ " </tr>");
|
| 26792 |
tejbeer |
881 |
|
| 32458 |
amit.gupta |
882 |
sb.append("<tr>");
|
|
|
883 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + referral.getRefereeName() + "</td>");
|
| 26792 |
tejbeer |
884 |
|
| 32458 |
amit.gupta |
885 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + referral.getRefereeEmail() + "</td>");
|
|
|
886 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + referral.getFirstName() + "</td>");
|
|
|
887 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + referral.getMobile() + "</td>");
|
|
|
888 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + referral.getCity() + "</td>");
|
|
|
889 |
sb.append("<td style='border:1px solid black;padding: 5px'>" + referral.getState() + "</td>");
|
| 26792 |
tejbeer |
890 |
|
| 32458 |
amit.gupta |
891 |
sb.append("</tr>");
|
| 26792 |
tejbeer |
892 |
|
| 32458 |
amit.gupta |
893 |
sb.append("</tbody></table></body></html>");
|
| 26792 |
tejbeer |
894 |
|
| 32458 |
amit.gupta |
895 |
return sb.toString();
|
|
|
896 |
}
|
| 26792 |
tejbeer |
897 |
|
| 32458 |
amit.gupta |
898 |
@RequestMapping(value = "/user/refferalAmount", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
899 |
@ApiImplicitParams({
|
|
|
900 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
901 |
public ResponseEntity<?> RefferalAmount(HttpServletRequest request, @RequestParam String refereeEmail)
|
|
|
902 |
throws Exception {
|
|
|
903 |
LocalDateTime ldt = LocalDate.now().atStartOfDay().withDayOfMonth(16);
|
|
|
904 |
DateRangeModel drm = new DateRangeModel();
|
|
|
905 |
List<RefferalEarningModel> refferAmountModel = new ArrayList<RefferalEarningModel>();
|
|
|
906 |
RefferalEarningModel rfm = new RefferalEarningModel();
|
|
|
907 |
long currentMonthEstimaterefferal = 0;
|
|
|
908 |
long currentMonthConfirmedrefferal = 0;
|
|
|
909 |
if (LocalDateTime.now().isBefore(ldt)) {
|
|
|
910 |
List<Refferal> allPendingRefferalBeforeCurrentMonth = refferalRepository
|
|
|
911 |
.selectByEmailIdAndStatusAndbeforeCurrentMonth(refereeEmail, RefferalStatus.pending);
|
|
|
912 |
drm.setStartDate(LocalDateTime.now().minusMonths(1).withDayOfMonth(16));
|
|
|
913 |
drm.setEndDate(LocalDateTime.now().withDayOfMonth(1));
|
| 25488 |
tejbeer |
914 |
|
| 32458 |
amit.gupta |
915 |
List<Refferal> previousMonthapprovedRefferalAfterSixteen = refferalRepository
|
|
|
916 |
.selectByEmailIdAndStatusAndDateRange(refereeEmail, RefferalStatus.approved, drm);
|
|
|
917 |
List<Refferal> previousMonthtransferredRefferalAfterSixteen = refferalRepository
|
|
|
918 |
.selectByEmailIdAndStatusAndDateRange(refereeEmail, RefferalStatus.transferred, drm);
|
| 25488 |
tejbeer |
919 |
|
| 32458 |
amit.gupta |
920 |
drm.setStartDate(LocalDateTime.now().minusMonths(1).withDayOfMonth(1));
|
|
|
921 |
drm.setEndDate(LocalDateTime.now().minusMonths(1).withDayOfMonth(16));
|
| 25488 |
tejbeer |
922 |
|
| 32458 |
amit.gupta |
923 |
List<Refferal> previousMonthapprovedRefferalbeforeSixteen = refferalRepository
|
|
|
924 |
.selectByEmailIdAndStatusAndDateRanges(refereeEmail, RefferalStatus.approved, drm);
|
|
|
925 |
List<Refferal> previousMonthtransferredRefferalbeforeSixteen = refferalRepository
|
|
|
926 |
.selectByEmailIdAndStatusAndDateRanges(refereeEmail, RefferalStatus.transferred, drm);
|
|
|
927 |
long pendingRefferalBeforeCurrentMonth = allPendingRefferalBeforeCurrentMonth.size();
|
|
|
928 |
long previousapprovedRefferalAfterSixteen = previousMonthapprovedRefferalAfterSixteen.size();
|
|
|
929 |
long previoustransferredRefferalAfterSixteen = previousMonthtransferredRefferalAfterSixteen.size();
|
|
|
930 |
long previousapprovedRefferalbeforeSixteen = previousMonthapprovedRefferalbeforeSixteen.size();
|
|
|
931 |
long previoustransferredRefferalbeforeSixteen = previousMonthtransferredRefferalbeforeSixteen.size();
|
|
|
932 |
long previousMonthEstimateRefferal = pendingRefferalBeforeCurrentMonth
|
|
|
933 |
+ previousapprovedRefferalAfterSixteen + previousapprovedRefferalbeforeSixteen;
|
|
|
934 |
long previousMonthConfirmedRefferal = previousapprovedRefferalAfterSixteen
|
|
|
935 |
+ previoustransferredRefferalAfterSixteen + previousapprovedRefferalbeforeSixteen
|
|
|
936 |
+ previoustransferredRefferalbeforeSixteen;
|
| 36324 |
aman |
937 |
List<Refferal> previousMonthConfirmedList = new ArrayList<>();
|
|
|
938 |
previousMonthConfirmedList.addAll(previousMonthapprovedRefferalAfterSixteen);
|
|
|
939 |
previousMonthConfirmedList.addAll(previousMonthtransferredRefferalAfterSixteen);
|
|
|
940 |
previousMonthConfirmedList.addAll(previousMonthapprovedRefferalbeforeSixteen);
|
|
|
941 |
previousMonthConfirmedList.addAll(previousMonthtransferredRefferalbeforeSixteen);
|
|
|
942 |
rfm = refferAmountEarning(allPendingRefferalBeforeCurrentMonth, previousMonthConfirmedList,
|
| 32458 |
amit.gupta |
943 |
YearMonth.now().minusMonths(1));
|
|
|
944 |
refferAmountModel.add(rfm);
|
|
|
945 |
LOGGER.info("previousMonthPendingApprovedRefferal" + previousMonthEstimateRefferal);
|
|
|
946 |
LOGGER.info("previousMonthApprovedTransfferedRefferal" + previousMonthConfirmedRefferal);
|
| 25488 |
tejbeer |
947 |
|
| 32458 |
amit.gupta |
948 |
List<Refferal> pendingofCurrentMonth = refferalRepository
|
|
|
949 |
.selectByEmailIdAndStatusAndBetweenDates(refereeEmail, RefferalStatus.pending, YearMonth.now());
|
|
|
950 |
List<Refferal> approvedofCurrentMonth = refferalRepository.selectByEmailIdAndStatusAndDatesBetweenTimestamp(
|
|
|
951 |
refereeEmail, RefferalStatus.approved, YearMonth.now());
|
|
|
952 |
List<Refferal> transferredofCurrentMonth = refferalRepository
|
|
|
953 |
.selectByEmailIdAndStatusAndDatesBetweenTimestamp(refereeEmail, RefferalStatus.transferred,
|
|
|
954 |
YearMonth.now());
|
|
|
955 |
LOGGER.info("pendingofCurrentMonth" + pendingofCurrentMonth);
|
|
|
956 |
long pendingofCurrentMonthCount = pendingofCurrentMonth.size();
|
|
|
957 |
currentMonthEstimaterefferal = pendingofCurrentMonth.size() + approvedofCurrentMonth.size();
|
|
|
958 |
currentMonthConfirmedrefferal = approvedofCurrentMonth.size() + transferredofCurrentMonth.size();
|
| 25509 |
tejbeer |
959 |
|
| 36324 |
aman |
960 |
List<Refferal> currentMonthConfirmedList = new ArrayList<>();
|
|
|
961 |
currentMonthConfirmedList.addAll(approvedofCurrentMonth);
|
|
|
962 |
currentMonthConfirmedList.addAll(transferredofCurrentMonth);
|
| 25488 |
tejbeer |
963 |
|
| 36324 |
aman |
964 |
rfm = refferAmountEarning(pendingofCurrentMonth, currentMonthConfirmedList, YearMonth.now());
|
|
|
965 |
|
| 32458 |
amit.gupta |
966 |
refferAmountModel.add(rfm);
|
| 25488 |
tejbeer |
967 |
|
| 32458 |
amit.gupta |
968 |
} else if (LocalDateTime.now().isAfter(ldt)) {
|
|
|
969 |
drm.setStartDate(LocalDateTime.now().minusMonths(1).withDayOfMonth(1));
|
|
|
970 |
drm.setEndDate(LocalDateTime.now().minusMonths(1).withDayOfMonth(16));
|
| 25488 |
tejbeer |
971 |
|
| 32458 |
amit.gupta |
972 |
List<Refferal> previousMonthapprovedRefferalbeforeSixteen = refferalRepository
|
|
|
973 |
.selectByEmailIdAndStatusAndDateRanges(refereeEmail, RefferalStatus.approved, drm);
|
|
|
974 |
List<Refferal> previousMonthtransferredRefferalbeforeSixteen = refferalRepository
|
|
|
975 |
.selectByEmailIdAndStatusAndDateRanges(refereeEmail, RefferalStatus.transferred, drm);
|
| 25488 |
tejbeer |
976 |
|
| 32458 |
amit.gupta |
977 |
drm.setStartDate(LocalDateTime.now().minusMonths(1).withDayOfMonth(16));
|
|
|
978 |
drm.setEndDate(LocalDateTime.now().withDayOfMonth(16));
|
| 25488 |
tejbeer |
979 |
|
| 32458 |
amit.gupta |
980 |
List<Refferal> previousAndcurrentMonthapprovedRefferal = refferalRepository
|
|
|
981 |
.selectByEmailIdAndStatusAndDateRange(refereeEmail, RefferalStatus.approved, drm);
|
| 25488 |
tejbeer |
982 |
|
| 32458 |
amit.gupta |
983 |
LocalDateTime currentMonthdate = LocalDateTime.now().withDayOfMonth(1);
|
| 25488 |
tejbeer |
984 |
|
| 32458 |
amit.gupta |
985 |
List<Refferal> preCurrMonthapproved = previousAndcurrentMonthapprovedRefferal.stream()
|
|
|
986 |
.filter(x -> x.getCreatedTimestamp().isBefore(currentMonthdate)).collect(Collectors.toList());
|
|
|
987 |
List<Refferal> previousAndcurrentMonthtransferredRefferal = refferalRepository
|
|
|
988 |
.selectByEmailIdAndStatusAndDateRange(refereeEmail, RefferalStatus.transferred, drm);
|
|
|
989 |
List<Refferal> preCurrMonthtransferred = previousAndcurrentMonthtransferredRefferal.stream()
|
|
|
990 |
.filter(x -> x.getCreatedTimestamp().isBefore(currentMonthdate)).collect(Collectors.toList());
|
| 25488 |
tejbeer |
991 |
|
| 33792 |
ranu |
992 |
long approvedRefferalCount = previousMonthapprovedRefferalbeforeSixteen.size()
|
| 32458 |
amit.gupta |
993 |
+ previousMonthtransferredRefferalbeforeSixteen.size() + preCurrMonthapproved.size()
|
|
|
994 |
+ preCurrMonthtransferred.size();
|
| 36324 |
aman |
995 |
List<Refferal> previousMonthSettledList = new ArrayList<>();
|
|
|
996 |
previousMonthSettledList.addAll(previousMonthapprovedRefferalbeforeSixteen);
|
|
|
997 |
previousMonthSettledList.addAll(previousMonthtransferredRefferalbeforeSixteen);
|
|
|
998 |
previousMonthSettledList.addAll(preCurrMonthapproved);
|
|
|
999 |
previousMonthSettledList.addAll(preCurrMonthtransferred);
|
| 32458 |
amit.gupta |
1000 |
rfm = new RefferalEarningModel();
|
| 36324 |
aman |
1001 |
rfm.setActualEarning(computeEarning(previousMonthSettledList));
|
| 27595 |
tejbeer |
1002 |
|
| 32458 |
amit.gupta |
1003 |
rfm.setYearMonth(YearMonth.now().minusMonths(1));
|
|
|
1004 |
rfm.setPendingRefferal(0);
|
| 33792 |
ranu |
1005 |
rfm.setApprovedRefferal(approvedRefferalCount);
|
| 32458 |
amit.gupta |
1006 |
refferAmountModel.add(rfm);
|
|
|
1007 |
List<Refferal> allpendingRefferal = refferalRepository.selectByEmailIdAndStatus(refereeEmail,
|
|
|
1008 |
RefferalStatus.pending);
|
|
|
1009 |
LOGGER.info("allpendingRefferal" + allpendingRefferal);
|
| 25488 |
tejbeer |
1010 |
|
| 32458 |
amit.gupta |
1011 |
drm.setStartDate(LocalDateTime.now().withDayOfMonth(16));
|
|
|
1012 |
drm.setEndDate(LocalDateTime.now().plusMonths(1).withDayOfMonth(1));
|
| 25488 |
tejbeer |
1013 |
|
| 32458 |
amit.gupta |
1014 |
List<Refferal> currentMonthapprovedRefferalAfterSixteen = refferalRepository
|
|
|
1015 |
.selectByEmailIdAndStatusAndDateRange(refereeEmail, RefferalStatus.approved, drm);
|
|
|
1016 |
List<Refferal> currentMonthtransferredRefferalAfterSixteen = refferalRepository
|
|
|
1017 |
.selectByEmailIdAndStatusAndDateRange(refereeEmail, RefferalStatus.transferred, drm);
|
|
|
1018 |
LOGGER.info("currentMonthapprovedRefferalAfterSixteen" + currentMonthapprovedRefferalAfterSixteen);
|
|
|
1019 |
drm.setStartDate(LocalDateTime.now().withDayOfMonth(1));
|
|
|
1020 |
drm.setEndDate(LocalDateTime.now().withDayOfMonth(16));
|
| 25488 |
tejbeer |
1021 |
|
| 32458 |
amit.gupta |
1022 |
List<Refferal> currentMonthapprovedRefferalbeforeSixteen = refferalRepository
|
|
|
1023 |
.selectByEmailIdAndStatusAndDateRanges(refereeEmail, RefferalStatus.approved, drm);
|
|
|
1024 |
List<Refferal> currentMonthtransferredRefferalbeforeSixteen = refferalRepository
|
|
|
1025 |
.selectByEmailIdAndStatusAndDateRanges(refereeEmail, RefferalStatus.transferred, drm);
|
|
|
1026 |
LOGGER.info("currentMonthapprovedRefferalbeforeSixteen" + currentMonthapprovedRefferalbeforeSixteen);
|
|
|
1027 |
long pendingrefferalcount = allpendingRefferal.size();
|
|
|
1028 |
currentMonthConfirmedrefferal = currentMonthapprovedRefferalAfterSixteen.size()
|
|
|
1029 |
+ currentMonthtransferredRefferalAfterSixteen.size()
|
|
|
1030 |
+ currentMonthapprovedRefferalbeforeSixteen.size()
|
|
|
1031 |
+ currentMonthtransferredRefferalbeforeSixteen.size();
|
| 25509 |
tejbeer |
1032 |
|
| 36324 |
aman |
1033 |
List<Refferal> currentMonthConfirmedList = new ArrayList<>();
|
|
|
1034 |
currentMonthConfirmedList.addAll(currentMonthapprovedRefferalAfterSixteen);
|
|
|
1035 |
currentMonthConfirmedList.addAll(currentMonthtransferredRefferalAfterSixteen);
|
|
|
1036 |
currentMonthConfirmedList.addAll(currentMonthapprovedRefferalbeforeSixteen);
|
|
|
1037 |
currentMonthConfirmedList.addAll(currentMonthtransferredRefferalbeforeSixteen);
|
|
|
1038 |
|
|
|
1039 |
rfm = refferAmountEarning(allpendingRefferal, currentMonthConfirmedList, YearMonth.now());
|
| 32458 |
amit.gupta |
1040 |
refferAmountModel.add(rfm);
|
|
|
1041 |
LOGGER.info("currentMonthpendingApprovedrefferal" + currentMonthEstimaterefferal);
|
| 25488 |
tejbeer |
1042 |
|
| 32458 |
amit.gupta |
1043 |
LOGGER.info("currentMonthapprovedTransferredrefferal" + currentMonthConfirmedrefferal);
|
| 25488 |
tejbeer |
1044 |
|
| 32458 |
amit.gupta |
1045 |
}
|
|
|
1046 |
RefferalEarning re = new RefferalEarning();
|
|
|
1047 |
re.setTimestamp(LocalDateTime.now());
|
|
|
1048 |
re.setRefferalEarningModel(refferAmountModel);
|
|
|
1049 |
return responseSender.ok(re);
|
|
|
1050 |
}
|
| 25488 |
tejbeer |
1051 |
|
| 36324 |
aman |
1052 |
private RefferalEarningModel refferAmountEarning(List<Refferal> pendingList, List<Refferal> confirmedList,
|
| 32458 |
amit.gupta |
1053 |
YearMonth yearMonth) {
|
|
|
1054 |
RefferalEarningModel rfm = new RefferalEarningModel();
|
|
|
1055 |
rfm.setYearMonth(yearMonth);
|
| 36324 |
aman |
1056 |
rfm.setPendingRefferal(pendingList.size());
|
|
|
1057 |
rfm.setApprovedRefferal(confirmedList.size());
|
| 25488 |
tejbeer |
1058 |
|
| 36324 |
aman |
1059 |
List<Refferal> potential = new ArrayList<>(confirmedList.size() + pendingList.size());
|
|
|
1060 |
potential.addAll(confirmedList);
|
|
|
1061 |
potential.addAll(pendingList);
|
| 27595 |
tejbeer |
1062 |
|
| 36324 |
aman |
1063 |
rfm.setMaximumEarning(computeEarning(potential));
|
|
|
1064 |
rfm.setMinimumEarning(computeEarning(confirmedList));
|
| 27595 |
tejbeer |
1065 |
|
| 32458 |
amit.gupta |
1066 |
return rfm;
|
|
|
1067 |
}
|
| 25979 |
tejbeer |
1068 |
|
| 36324 |
aman |
1069 |
// 1 → 3000, 2 → 4000, 3+ → 5000; applied to every new-policy referral in the month.
|
|
|
1070 |
private static int tierRate(long count) {
|
|
|
1071 |
if (count == 0) return 0;
|
|
|
1072 |
if (count == 1) return 3000;
|
|
|
1073 |
if (count == 2) return 4000;
|
|
|
1074 |
return 5000;
|
|
|
1075 |
}
|
|
|
1076 |
|
|
|
1077 |
private static boolean isLegacy(Refferal r) {
|
|
|
1078 |
LocalDateTime when = r.getApprovedTimestamp() != null ? r.getApprovedTimestamp() : r.getCreatedTimestamp();
|
|
|
1079 |
return when != null && when.toLocalDate().isBefore(TIER_POLICY_EFFECTIVE_DATE);
|
|
|
1080 |
}
|
|
|
1081 |
|
|
|
1082 |
private static long computeEarning(List<Refferal> referrals) {
|
|
|
1083 |
long legacyCount = referrals.stream().filter(UserController::isLegacy).count();
|
|
|
1084 |
long newCount = referrals.size() - legacyCount;
|
|
|
1085 |
return legacyCount * LEGACY_PER_REFERRAL_EARNING + newCount * tierRate(newCount);
|
|
|
1086 |
}
|
|
|
1087 |
|
| 32458 |
amit.gupta |
1088 |
@RequestMapping(value = "/user/getReferals", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1089 |
@ApiImplicitParams({
|
|
|
1090 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
1091 |
public ResponseEntity<?> getReferals(HttpServletRequest request, @RequestParam RefferalStatus status)
|
|
|
1092 |
throws Exception {
|
|
|
1093 |
int userId = (int) request.getAttribute("userId");
|
| 29890 |
tejbeer |
1094 |
|
| 32458 |
amit.gupta |
1095 |
User user = userRepository.selectById(userId);
|
|
|
1096 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
| 29890 |
tejbeer |
1097 |
|
| 32458 |
amit.gupta |
1098 |
List<Refferal> refferals = refferalRepository.selectByEmailIdAndStatus(user.getEmailId(), status);
|
|
|
1099 |
return responseSender.ok(refferals);
|
|
|
1100 |
}
|
| 29890 |
tejbeer |
1101 |
|
| 32458 |
amit.gupta |
1102 |
@RequestMapping(value = "/user/partnerTarget", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1103 |
@ApiImplicitParams({
|
|
|
1104 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
1105 |
public ResponseEntity<?> PartnerTarget(HttpServletRequest request) throws Exception {
|
|
|
1106 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
|
|
1107 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
|
|
1108 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(retailerId, LocalDate.now());
|
| 25979 |
tejbeer |
1109 |
|
| 32458 |
amit.gupta |
1110 |
return responseSender.ok(partnerType);
|
|
|
1111 |
}
|
| 26636 |
amit.gupta |
1112 |
|
| 32458 |
amit.gupta |
1113 |
@RequestMapping(value = "/user/authUser", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1114 |
@ApiImplicitParams({
|
|
|
1115 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
1116 |
public ResponseEntity<?> authUserDetail(HttpServletRequest request, @RequestParam int userId) throws Exception {
|
|
|
1117 |
User user = userRepository.selectById(userId);
|
|
|
1118 |
AuthUser authUser = authRepository.selectByEmailOrMobile(user.getEmailId());
|
|
|
1119 |
return responseSender.ok(authUser);
|
|
|
1120 |
}
|
| 27425 |
tejbeer |
1121 |
|
| 21248 |
ashik.ali |
1122 |
}
|
| 26636 |
amit.gupta |
1123 |
|
|
|
1124 |
class MobileAppSettingsWrapper {
|
| 32458 |
amit.gupta |
1125 |
@JsonProperty(value = "Mobileappsetting")
|
|
|
1126 |
private MobileAppSetting mobileAppSettings;
|
| 26636 |
amit.gupta |
1127 |
|
| 32458 |
amit.gupta |
1128 |
public MobileAppSettingsWrapper(MobileAppSetting mobileAppSettings) {
|
|
|
1129 |
super();
|
|
|
1130 |
this.mobileAppSettings = mobileAppSettings;
|
|
|
1131 |
}
|
| 26642 |
amit.gupta |
1132 |
|
| 32458 |
amit.gupta |
1133 |
public MobileAppSetting getMobileAppSettings() {
|
|
|
1134 |
return mobileAppSettings;
|
|
|
1135 |
}
|
| 26642 |
amit.gupta |
1136 |
|
| 32458 |
amit.gupta |
1137 |
public void setMobileAppSettings(MobileAppSetting mobileAppSettings) {
|
|
|
1138 |
this.mobileAppSettings = mobileAppSettings;
|
|
|
1139 |
}
|
| 26643 |
amit.gupta |
1140 |
|
| 32458 |
amit.gupta |
1141 |
@Override
|
|
|
1142 |
public String toString() {
|
|
|
1143 |
return "MobileAppSettingsWrapper [mobileAppSettings=" + mobileAppSettings + "]";
|
|
|
1144 |
}
|
| 26644 |
amit.gupta |
1145 |
|
| 26636 |
amit.gupta |
1146 |
}
|
|
|
1147 |
|
|
|
1148 |
class SettingsWrapper {
|
| 32458 |
amit.gupta |
1149 |
private List<MobileAppSettingsWrapper> settings;
|
| 26644 |
amit.gupta |
1150 |
|
| 32458 |
amit.gupta |
1151 |
public SettingsWrapper(List<MobileAppSettingsWrapper> settings) {
|
|
|
1152 |
super();
|
|
|
1153 |
this.settings = settings;
|
|
|
1154 |
}
|
| 26636 |
amit.gupta |
1155 |
|
| 32458 |
amit.gupta |
1156 |
@Override
|
|
|
1157 |
public String toString() {
|
|
|
1158 |
return "SettingsWrapper [settings=" + settings + "]";
|
|
|
1159 |
}
|
| 26642 |
amit.gupta |
1160 |
|
| 32458 |
amit.gupta |
1161 |
public List<MobileAppSettingsWrapper> getSettings() {
|
|
|
1162 |
return settings;
|
|
|
1163 |
}
|
| 26642 |
amit.gupta |
1164 |
|
| 32458 |
amit.gupta |
1165 |
public void setSettings(List<MobileAppSettingsWrapper> settings) {
|
|
|
1166 |
this.settings = settings;
|
|
|
1167 |
}
|
| 26642 |
amit.gupta |
1168 |
|
| 27425 |
tejbeer |
1169 |
}
|