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