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