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