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