| 21248 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 25300 |
tejbeer |
3 |
import java.io.IOException;
|
| 25488 |
tejbeer |
4 |
import java.time.LocalDate;
|
| 21248 |
ashik.ali |
5 |
import java.time.LocalDateTime;
|
| 25488 |
tejbeer |
6 |
import java.time.YearMonth;
|
| 21855 |
amit.gupta |
7 |
import java.util.ArrayList;
|
| 25300 |
tejbeer |
8 |
import java.util.Base64;
|
| 21428 |
amit.gupta |
9 |
import java.util.HashMap;
|
| 23786 |
amit.gupta |
10 |
import java.util.HashSet;
|
| 21855 |
amit.gupta |
11 |
import java.util.List;
|
| 21277 |
ashik.ali |
12 |
import java.util.Map;
|
| 23786 |
amit.gupta |
13 |
import java.util.Set;
|
| 25488 |
tejbeer |
14 |
import java.util.stream.Collectors;
|
| 21248 |
ashik.ali |
15 |
|
|
|
16 |
import javax.servlet.http.HttpServletRequest;
|
|
|
17 |
|
| 25300 |
tejbeer |
18 |
import org.apache.http.client.ClientProtocolException;
|
| 23786 |
amit.gupta |
19 |
import org.apache.logging.log4j.LogManager;
|
| 23859 |
ashik.ali |
20 |
import org.apache.logging.log4j.Logger;
|
| 21278 |
ashik.ali |
21 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21414 |
kshitij.so |
22 |
import org.springframework.beans.factory.annotation.Value;
|
| 25366 |
tejbeer |
23 |
import org.springframework.http.MediaType;
|
| 21248 |
ashik.ali |
24 |
import org.springframework.http.ResponseEntity;
|
|
|
25 |
import org.springframework.stereotype.Controller;
|
| 21702 |
ashik.ali |
26 |
import org.springframework.transaction.annotation.Transactional;
|
| 26590 |
amit.gupta |
27 |
import org.springframework.web.bind.annotation.PathVariable;
|
| 21366 |
kshitij.so |
28 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 21248 |
ashik.ali |
29 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
30 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
31 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
32 |
|
|
|
33 |
import com.spice.profitmandi.common.ResponseCodeHolder;
|
|
|
34 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 25366 |
tejbeer |
35 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 22930 |
ashik.ali |
36 |
import com.spice.profitmandi.common.model.GoogleLoginRequest;
|
| 21248 |
ashik.ali |
37 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 22492 |
amit.gupta |
38 |
import com.spice.profitmandi.common.model.RegisteredUserInfo;
|
| 21469 |
amit.gupta |
39 |
import com.spice.profitmandi.common.model.UserInfo;
|
| 21282 |
ashik.ali |
40 |
import com.spice.profitmandi.common.util.JWTUtil;
|
| 21855 |
amit.gupta |
41 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 21740 |
ashik.ali |
42 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 25366 |
tejbeer |
43 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 21735 |
ashik.ali |
44 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
| 23858 |
ashik.ali |
45 |
import com.spice.profitmandi.dao.entity.dtr.Role;
|
| 21735 |
ashik.ali |
46 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 25366 |
tejbeer |
47 |
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
|
| 21735 |
ashik.ali |
48 |
import com.spice.profitmandi.dao.entity.dtr.UserRole;
|
| 25622 |
amit.gupta |
49 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
| 22355 |
ashik.ali |
50 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| 25458 |
tejbeer |
51 |
import com.spice.profitmandi.dao.entity.user.Promoter;
|
|
|
52 |
import com.spice.profitmandi.dao.entity.user.Refferal;
|
| 25488 |
tejbeer |
53 |
import com.spice.profitmandi.dao.enumuration.dtr.RefferalStatus;
|
| 21735 |
ashik.ali |
54 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
| 25979 |
tejbeer |
55 |
import com.spice.profitmandi.dao.model.CreateRefferalRequest;
|
| 25488 |
tejbeer |
56 |
import com.spice.profitmandi.dao.model.DateRangeModel;
|
| 21643 |
ashik.ali |
57 |
import com.spice.profitmandi.dao.model.UserCart;
|
| 25366 |
tejbeer |
58 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 25619 |
amit.gupta |
59 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 25458 |
tejbeer |
60 |
import com.spice.profitmandi.dao.repository.dtr.RefferalRepository;
|
| 21735 |
ashik.ali |
61 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| 23786 |
amit.gupta |
62 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
| 21735 |
ashik.ali |
63 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
|
|
64 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
|
|
65 |
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
|
| 25622 |
amit.gupta |
66 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
|
| 22355 |
ashik.ali |
67 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 25458 |
tejbeer |
68 |
import com.spice.profitmandi.dao.repository.user.PromoterRepository;
|
| 24491 |
amit.gupta |
69 |
import com.spice.profitmandi.service.AuthService;
|
| 23798 |
amit.gupta |
70 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 25366 |
tejbeer |
71 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 23787 |
amit.gupta |
72 |
import com.spice.profitmandi.service.user.UserService;
|
| 21469 |
amit.gupta |
73 |
import com.spice.profitmandi.web.enumuration.UserStatus;
|
| 21277 |
ashik.ali |
74 |
import com.spice.profitmandi.web.processor.GoogleLoginProcessor;
|
| 25979 |
tejbeer |
75 |
|
| 25488 |
tejbeer |
76 |
import com.spice.profitmandi.web.req.RefferalEarning;
|
|
|
77 |
import com.spice.profitmandi.web.req.RefferalEarningModel;
|
| 21366 |
kshitij.so |
78 |
import com.spice.profitmandi.web.req.UserRequest;
|
| 25366 |
tejbeer |
79 |
import com.spice.profitmandi.web.res.Partner;
|
| 21248 |
ashik.ali |
80 |
|
| 21469 |
amit.gupta |
81 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
82 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
83 |
|
| 21248 |
ashik.ali |
84 |
/**
|
|
|
85 |
* @author ashikali
|
|
|
86 |
*
|
|
|
87 |
*/
|
|
|
88 |
@Controller
|
| 25366 |
tejbeer |
89 |
@Transactional(rollbackFor = Throwable.class)
|
| 21248 |
ashik.ali |
90 |
public class UserController {
|
| 21469 |
amit.gupta |
91 |
|
| 21448 |
ashik.ali |
92 |
@Autowired
|
| 22930 |
ashik.ali |
93 |
private ResponseSender<?> responseSender;
|
| 21469 |
amit.gupta |
94 |
|
| 23568 |
govind |
95 |
private static final Logger LOGGER = LogManager.getLogger(UserController.class);
|
| 21469 |
amit.gupta |
96 |
|
| 21855 |
amit.gupta |
97 |
@Value("${notifications.api.host}")
|
|
|
98 |
private String nodeHost;
|
| 25366 |
tejbeer |
99 |
|
| 21855 |
amit.gupta |
100 |
@Value("${notifications.api.port}")
|
|
|
101 |
private int nodePort;
|
|
|
102 |
|
| 21414 |
kshitij.so |
103 |
@Value("${admin.token}")
|
|
|
104 |
private String validAdminToken;
|
| 21469 |
amit.gupta |
105 |
|
| 21278 |
ashik.ali |
106 |
@Autowired
|
| 22873 |
ashik.ali |
107 |
private UserRepository userRepository;
|
| 25366 |
tejbeer |
108 |
|
| 22355 |
ashik.ali |
109 |
@Autowired
|
| 22873 |
ashik.ali |
110 |
private com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
|
| 21469 |
amit.gupta |
111 |
|
| 21278 |
ashik.ali |
112 |
@Autowired
|
| 22873 |
ashik.ali |
113 |
private RetailerRepository retailerRepository;
|
| 21485 |
amit.gupta |
114 |
|
|
|
115 |
@Autowired
|
| 22873 |
ashik.ali |
116 |
private UserRoleRepository userRoleRepository;
|
| 21469 |
amit.gupta |
117 |
|
| 21426 |
ashik.ali |
118 |
@Autowired
|
| 25622 |
amit.gupta |
119 |
private PartnerTypeChangeService partnerTypeChangeService;
|
|
|
120 |
|
|
|
121 |
@Autowired
|
| 22873 |
ashik.ali |
122 |
private UserAccountRepository userAccountRepository;
|
| 25366 |
tejbeer |
123 |
|
| 22355 |
ashik.ali |
124 |
@Autowired
|
| 24491 |
amit.gupta |
125 |
private AuthService authService;
|
| 25366 |
tejbeer |
126 |
|
| 24491 |
amit.gupta |
127 |
@Autowired
|
| 22873 |
ashik.ali |
128 |
private AddressRepository addressRepository;
|
| 21469 |
amit.gupta |
129 |
|
| 21426 |
ashik.ali |
130 |
@Autowired
|
| 22873 |
ashik.ali |
131 |
private GoogleLoginProcessor googleLoginProcessor;
|
| 21855 |
amit.gupta |
132 |
|
| 21784 |
amit.gupta |
133 |
@Autowired
|
| 22873 |
ashik.ali |
134 |
private UserService userService;
|
| 25366 |
tejbeer |
135 |
|
| 23786 |
amit.gupta |
136 |
@Autowired
|
| 25619 |
amit.gupta |
137 |
private CsService csService;
|
|
|
138 |
|
|
|
139 |
@Autowired
|
| 23858 |
ashik.ali |
140 |
private RestClient restClient;
|
| 25366 |
tejbeer |
141 |
|
| 23858 |
ashik.ali |
142 |
@Autowired
|
| 23798 |
amit.gupta |
143 |
private RoleManager roleManager;
|
| 25366 |
tejbeer |
144 |
|
| 23786 |
amit.gupta |
145 |
@Autowired
|
|
|
146 |
private RoleRepository roleRepository;
|
| 21469 |
amit.gupta |
147 |
|
| 25366 |
tejbeer |
148 |
@Autowired
|
|
|
149 |
private AuthRepository authRepository;
|
|
|
150 |
|
|
|
151 |
@Autowired
|
|
|
152 |
private RetailerService retailerService;
|
|
|
153 |
|
| 25458 |
tejbeer |
154 |
@Autowired
|
|
|
155 |
private RefferalRepository refferalRepository;
|
|
|
156 |
|
|
|
157 |
@Autowired
|
|
|
158 |
private PromoterRepository promoterRepository;
|
|
|
159 |
|
| 21469 |
amit.gupta |
160 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_GOOGLE_LOGIN, method = RequestMethod.POST)
|
| 25366 |
tejbeer |
161 |
public ResponseEntity<?> googleLogin(HttpServletRequest request, @RequestBody GoogleLoginRequest googleLoginRequest)
|
|
|
162 |
throws ProfitMandiBusinessException {
|
| 26396 |
amit.gupta |
163 |
return responseSender.ok(googleLoginProcessor.process(googleLoginRequest.getToken()));
|
| 21277 |
ashik.ali |
164 |
}
|
| 26590 |
amit.gupta |
165 |
@RequestMapping(value = "/store/token/{storeCode}", method = RequestMethod.POST)
|
|
|
166 |
public ResponseEntity<?> googleLogin(HttpServletRequest request, @PathVariable String storeCode)
|
|
|
167 |
throws ProfitMandiBusinessException {
|
|
|
168 |
return responseSender.ok(googleLoginProcessor.processStore(storeCode));
|
|
|
169 |
}
|
| 21469 |
amit.gupta |
170 |
|
|
|
171 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_TOKEN_IS_EXPIRED, method = RequestMethod.GET)
|
| 25366 |
tejbeer |
172 |
public ResponseEntity<?> tokenIsExpired(HttpServletRequest request, @RequestParam(name = "token") String token)
|
|
|
173 |
throws ProfitMandiBusinessException {
|
| 21469 |
amit.gupta |
174 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 22930 |
ashik.ali |
175 |
return responseSender.ok(JWTUtil.isExpired(token));
|
| 21282 |
ashik.ali |
176 |
}
|
| 21469 |
amit.gupta |
177 |
|
| 22355 |
ashik.ali |
178 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_DETAIL_BY_TOKEN, method = RequestMethod.GET)
|
| 21469 |
amit.gupta |
179 |
@ApiImplicitParams({
|
|
|
180 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
181 |
public ResponseEntity<?> tokenInfo(HttpServletRequest request) throws Throwable {
|
|
|
182 |
Map<String, Object> responseMap = new HashMap<>();
|
|
|
183 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 21483 |
amit.gupta |
184 |
User user = null;
|
| 21855 |
amit.gupta |
185 |
if (userInfo.getUserId() > -1) {
|
| 21483 |
amit.gupta |
186 |
user = userRepository.selectById(userInfo.getUserId());
|
| 26533 |
amit.gupta |
187 |
|
|
|
188 |
String city = user.getCity();
|
| 25366 |
tejbeer |
189 |
if (!(userInfo.getEmail() == null || user.getEmailId().equalsIgnoreCase(userInfo.getEmail()))) {
|
| 24491 |
amit.gupta |
190 |
String userName = null;
|
| 25366 |
tejbeer |
191 |
if (user.getSecondryEmailId() != null && user.getSecondryEmailId().equals(userInfo.getEmail())) {
|
| 24491 |
amit.gupta |
192 |
userName = user.getFirstName() + " " + user.getLastName();
|
|
|
193 |
} else {
|
|
|
194 |
userName = authService.getNameByEmailId(userInfo.getEmail());
|
|
|
195 |
}
|
|
|
196 |
responseMap.put(ProfitMandiConstants.USER_ID, userInfo.getUserId());
|
|
|
197 |
responseMap.put(ProfitMandiConstants.USER_NAME, userName);
|
|
|
198 |
responseMap.put(ProfitMandiConstants.USER_STATUS, "fofoAssociate");
|
|
|
199 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, userInfo.getEmail());
|
| 26570 |
amit.gupta |
200 |
responseMap.put("storeUrl", "");
|
| 24491 |
amit.gupta |
201 |
return responseSender.ok(responseMap);
|
|
|
202 |
}
|
| 21483 |
amit.gupta |
203 |
} else {
|
|
|
204 |
try {
|
|
|
205 |
user = userRepository.selectByEmailId(userInfo.getEmail());
|
|
|
206 |
} catch (ProfitMandiBusinessException e1) {
|
|
|
207 |
}
|
| 25366 |
tejbeer |
208 |
if (user == null) {
|
| 23204 |
ashik.ali |
209 |
try {
|
|
|
210 |
user = userRepository.selectBySecondryEmailId(userInfo.getEmail());
|
|
|
211 |
} catch (ProfitMandiBusinessException e1) {
|
|
|
212 |
LOGGER.info("Uneregistered user", userInfo.getEmail());
|
|
|
213 |
}
|
|
|
214 |
}
|
| 21483 |
amit.gupta |
215 |
}
|
|
|
216 |
if (user != null) {
|
| 23858 |
ashik.ali |
217 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
|
| 21491 |
amit.gupta |
218 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, user.getEmailId());
|
| 21526 |
amit.gupta |
219 |
responseMap.put(ProfitMandiConstants.USER_ID, user.getId());
|
| 22017 |
amit.gupta |
220 |
responseMap.put(ProfitMandiConstants.USER_NAME, user.getFirstName() + " " + user.getLastName());
|
| 23786 |
amit.gupta |
221 |
List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(user.getId());
|
| 25366 |
tejbeer |
222 |
// LOGGER.info("userRoles {} ", userRoles);
|
| 22032 |
ashik.ali |
223 |
|
|
|
224 |
// generate new token if roles have been updated
|
| 23786 |
amit.gupta |
225 |
if (userInfo.getRoleIds() == null || roleIds.size() != userInfo.getRoleIds().size()) {
|
| 23858 |
ashik.ali |
226 |
String[] roleIdStrings = new String[roleIds.size()];
|
| 22603 |
amit.gupta |
227 |
int index = 0;
|
| 23786 |
amit.gupta |
228 |
for (int roleId : roleIds) {
|
| 23858 |
ashik.ali |
229 |
roleIdStrings[index++] = String.valueOf(roleId);
|
| 22603 |
amit.gupta |
230 |
}
|
| 23858 |
ashik.ali |
231 |
String newToken = JWTUtil.create(user.getId(), retailerId, roleIdStrings);
|
| 21483 |
amit.gupta |
232 |
responseMap.put("newAuthToken", newToken);
|
|
|
233 |
}
|
| 23858 |
ashik.ali |
234 |
// if user is retailer
|
| 23786 |
amit.gupta |
235 |
Set<Integer> roleIdsSet = new HashSet<Integer>(roleIds);
|
| 23858 |
ashik.ali |
236 |
if (roleManager.isRetailer(roleIdsSet)) {
|
| 22032 |
ashik.ali |
237 |
UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
|
|
|
238 |
Retailer retailer = retailerRepository.selectById(uc.getUserId());
|
| 22370 |
amit.gupta |
239 |
com.spice.profitmandi.dao.entity.user.User saholicUser = userUserRepository.selectById(uc.getUserId());
|
| 25366 |
tejbeer |
240 |
if (saholicUser.getAddressId() != null) {
|
| 22370 |
amit.gupta |
241 |
Address address = addressRepository.selectById(saholicUser.getAddressId());
|
|
|
242 |
responseMap.put(ProfitMandiConstants.ADDRESS, address);
|
|
|
243 |
}
|
| 21485 |
amit.gupta |
244 |
// if retailer is activated 1 then verified retailer
|
|
|
245 |
// else if migrated is 1 then old retailer
|
| 25366 |
tejbeer |
246 |
// also lets incoporte old process i.e is user is activated then also retailer
|
|
|
247 |
// is verified retailer
|
| 21485 |
amit.gupta |
248 |
// else retailer is not verifed
|
| 22497 |
amit.gupta |
249 |
if (retailer.isActive() || user.isActivated()) {
|
| 23798 |
amit.gupta |
250 |
if (roleManager.isPartner(roleIdsSet)) {
|
| 22017 |
amit.gupta |
251 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.FOFO.getValue());
|
| 26533 |
amit.gupta |
252 |
responseMap.put("storeUrl", retailerService.getAllFofoRetailerIdUrlMap().get(uc.getUserId()));
|
| 22017 |
amit.gupta |
253 |
} else {
|
|
|
254 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.VERIFIED_RETAILER.getValue());
|
|
|
255 |
}
|
| 22032 |
ashik.ali |
256 |
} else if (retailer.isMigrated()) {
|
| 21485 |
amit.gupta |
257 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.RETAILER.getValue());
|
| 21469 |
amit.gupta |
258 |
} else {
|
| 21485 |
amit.gupta |
259 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.NOT_VERIFIED_RETAILER.getValue());
|
| 21469 |
amit.gupta |
260 |
}
|
| 23798 |
amit.gupta |
261 |
} else if (roleManager.isUser(roleIdsSet)) {
|
| 22502 |
amit.gupta |
262 |
responseMap.put("userInfo", getRegisteredUserInfo(user));
|
| 21469 |
amit.gupta |
263 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.REGISTERED.getValue());
|
| 22032 |
ashik.ali |
264 |
}
|
| 21491 |
amit.gupta |
265 |
} else {
|
|
|
266 |
responseMap.put(ProfitMandiConstants.USER_STATUS, UserStatus.NOT_REGISTERED.getValue());
|
|
|
267 |
responseMap.put(ProfitMandiConstants.EMAIL_ID, userInfo.getEmail());
|
| 21469 |
amit.gupta |
268 |
}
|
| 22032 |
ashik.ali |
269 |
|
| 21469 |
amit.gupta |
270 |
return responseSender.ok(responseMap);
|
|
|
271 |
}
|
| 25366 |
tejbeer |
272 |
|
| 22502 |
amit.gupta |
273 |
private RegisteredUserInfo getRegisteredUserInfo(User user) throws Throwable {
|
| 22492 |
amit.gupta |
274 |
RegisteredUserInfo ri = new RegisteredUserInfo();
|
|
|
275 |
ri.setCity(user.getCity());
|
|
|
276 |
ri.setFirstName(user.getFirstName());
|
|
|
277 |
ri.setLastName(user.getLastName());
|
| 22493 |
amit.gupta |
278 |
ri.setPhone(user.getMobileNumber());
|
| 22492 |
amit.gupta |
279 |
ri.setPinCode(user.getPinCode());
|
| 22845 |
amit.gupta |
280 |
ri.setState(user.getState());
|
| 22492 |
amit.gupta |
281 |
return ri;
|
|
|
282 |
}
|
| 21469 |
amit.gupta |
283 |
|
|
|
284 |
@RequestMapping(value = ProfitMandiConstants.URL_USER, method = RequestMethod.POST)
|
| 21501 |
amit.gupta |
285 |
@ApiImplicitParams({
|
| 22032 |
ashik.ali |
286 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
287 |
public ResponseEntity<?> createUser(HttpServletRequest request, @RequestBody UserRequest userRequest)
|
| 22930 |
ashik.ali |
288 |
throws ProfitMandiBusinessException {
|
| 21469 |
amit.gupta |
289 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21368 |
kshitij.so |
290 |
User user = new User();
|
|
|
291 |
user.setFirstName(userRequest.getFirstName());
|
|
|
292 |
user.setLastName(userRequest.getLastName());
|
|
|
293 |
user.setCity(userRequest.getCity());
|
|
|
294 |
user.setPinCode(Integer.valueOf(userRequest.getPinCode()));
|
| 22845 |
amit.gupta |
295 |
user.setState(userRequest.getState());
|
| 21708 |
amit.gupta |
296 |
user.setMobileNumber(userRequest.getMobieNumber());
|
| 21368 |
kshitij.so |
297 |
user.setEmailId(userRequest.getEmailId());
|
|
|
298 |
user.setUsername("");
|
|
|
299 |
user.setPassword("");
|
|
|
300 |
user.setMobile_verified(false);
|
|
|
301 |
user.setReferral_url("");
|
|
|
302 |
user.setGroup_id(1);
|
| 22504 |
amit.gupta |
303 |
user.setStatus(1);
|
| 21368 |
kshitij.so |
304 |
user.setActivated(false);
|
| 21501 |
amit.gupta |
305 |
user.setCreateTimestamp(LocalDateTime.now());
|
|
|
306 |
user.setUpdateTimestamp(LocalDateTime.now());
|
| 22930 |
ashik.ali |
307 |
userRepository.persist(user);
|
| 23858 |
ashik.ali |
308 |
Role role = roleRepository.selectByName(RoleType.USER.toString());
|
| 22930 |
ashik.ali |
309 |
UserRole userRole = new UserRole();
|
| 23858 |
ashik.ali |
310 |
userRole.setRoleId(role.getId());
|
| 22930 |
ashik.ali |
311 |
userRole.setUserId(user.getId());
|
|
|
312 |
userRoleRepository.persist(userRole);
|
|
|
313 |
return responseSender.ok(ResponseCodeHolder.getMessage("USR_OK_1000"));
|
| 25366 |
tejbeer |
314 |
|
| 21278 |
ashik.ali |
315 |
}
|
| 21469 |
amit.gupta |
316 |
|
|
|
317 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ID, method = RequestMethod.GET)
|
| 25366 |
tejbeer |
318 |
public ResponseEntity<?> getById(HttpServletRequest request, @RequestParam(name = "id") int id)
|
|
|
319 |
throws ProfitMandiBusinessException {
|
| 21469 |
amit.gupta |
320 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 22930 |
ashik.ali |
321 |
return responseSender.ok(userRepository.selectById(id));
|
| 21248 |
ashik.ali |
322 |
}
|
| 21469 |
amit.gupta |
323 |
|
|
|
324 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_MOBILE_NUMBER, method = RequestMethod.GET)
|
|
|
325 |
public ResponseEntity<?> getByMobileNumber(HttpServletRequest request,
|
| 25366 |
tejbeer |
326 |
@RequestParam(name = "mobileNumber") String mobileNumber) throws ProfitMandiBusinessException {
|
| 21469 |
amit.gupta |
327 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 22930 |
ashik.ali |
328 |
return responseSender.ok(userRepository.selectByMobileNumber(mobileNumber));
|
| 21248 |
ashik.ali |
329 |
}
|
| 21469 |
amit.gupta |
330 |
|
| 21784 |
amit.gupta |
331 |
@ApiImplicitParams({
|
| 21501 |
amit.gupta |
332 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
333 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ACTIVATE, method = RequestMethod.POST)
|
|
|
334 |
public ResponseEntity<?> activateUser(HttpServletRequest request,
|
| 21784 |
amit.gupta |
335 |
@RequestParam(name = "activationCode") String activationCode) throws Throwable {
|
| 21855 |
amit.gupta |
336 |
int userId = (int) request.getAttribute("userId");
|
| 21784 |
amit.gupta |
337 |
UserCart uc = userAccountRepository.getUserCart(userId);
|
|
|
338 |
return responseSender.ok(userService.updateActivation(userId, uc.getUserId(), activationCode));
|
|
|
339 |
}
|
| 21855 |
amit.gupta |
340 |
|
| 25458 |
tejbeer |
341 |
/*
|
|
|
342 |
* @ApiImplicitParams({
|
|
|
343 |
*
|
|
|
344 |
* @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true,
|
|
|
345 |
* dataType = "string", paramType = "header") })
|
|
|
346 |
*
|
|
|
347 |
* @RequestMapping(value = ProfitMandiConstants.URL_USER_NOTIFICATIONS, method =
|
|
|
348 |
* RequestMethod.GET) public ResponseEntity<?>
|
|
|
349 |
* getNofitications(HttpServletRequest request,
|
|
|
350 |
*
|
|
|
351 |
* @RequestParam(name = "androidId") String androidId, @RequestParam(name =
|
|
|
352 |
* "pageNumber") int pageNumber,
|
|
|
353 |
*
|
|
|
354 |
* @RequestParam(name = "pageSize") int pageSize) throws
|
|
|
355 |
* ProfitMandiBusinessException { int userId = (int)
|
|
|
356 |
* request.getAttribute("userId"); String restResponse = null; Map<String,
|
|
|
357 |
* String> params = new HashMap<>();
|
|
|
358 |
*
|
|
|
359 |
* String uri = "/getAllNotifications"; params.put("user_id", userId + "");
|
|
|
360 |
* params.put("android_id", androidId); params.put("limit", pageSize + "");
|
|
|
361 |
* params.put("offset", "" + ((pageNumber - 1) * pageSize)); try { restResponse
|
|
|
362 |
* = restClient.get(SchemeType.HTTP, nodeHost, nodePort, uri, params); } catch
|
|
|
363 |
* (HttpHostConnectException e) { throw new ProfitMandiBusinessException("", "",
|
|
|
364 |
* "Could not Connect to host"); }
|
|
|
365 |
*
|
|
|
366 |
* JsonArray result_json = Json.parse(restResponse).asArray();
|
|
|
367 |
*
|
|
|
368 |
* List<Notification> notifications = new ArrayList<>();
|
|
|
369 |
*
|
|
|
370 |
* for (JsonValue j : result_json) {
|
|
|
371 |
* notifications.add(toNotifiaction(j.asObject())); }
|
|
|
372 |
*
|
|
|
373 |
* return responseSender.ok(notifications); }
|
|
|
374 |
*
|
|
|
375 |
* private Notification toNotifiaction(JsonObject jsonObject) { Notification n =
|
|
|
376 |
* (Notification) (new Gson().fromJson(jsonObject.toString(),
|
|
|
377 |
* Notification.class)); if (n.getStatus().equals("opened") ||
|
|
|
378 |
* n.getStatus().equals("referrer") || n.getStatus().equals("seen")) {
|
|
|
379 |
* n.setSeen(true); } return n; }
|
|
|
380 |
*/
|
| 21855 |
amit.gupta |
381 |
|
| 21426 |
ashik.ali |
382 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_IS_EXIST_MOBILE_NUMBER, method = RequestMethod.GET)
|
| 21469 |
amit.gupta |
383 |
public ResponseEntity<?> isMobileNumberExist(HttpServletRequest request,
|
|
|
384 |
@RequestParam(name = "mobileNumber") String mobileNumber) {
|
|
|
385 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21448 |
ashik.ali |
386 |
return responseSender.ok(userRepository.isExistByMobileNumber(mobileNumber));
|
| 21426 |
ashik.ali |
387 |
}
|
| 21469 |
amit.gupta |
388 |
|
|
|
389 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_EMAIL_ID, method = RequestMethod.GET)
|
| 25366 |
tejbeer |
390 |
public ResponseEntity<?> getByEmailId(HttpServletRequest request, @RequestParam(name = "emailId") String emailId)
|
|
|
391 |
throws ProfitMandiBusinessException {
|
| 21469 |
amit.gupta |
392 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 23204 |
ashik.ali |
393 |
User user = null;
|
| 25366 |
tejbeer |
394 |
try {
|
| 23204 |
ashik.ali |
395 |
user = userRepository.selectByEmailId(emailId);
|
| 25366 |
tejbeer |
396 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 23204 |
ashik.ali |
397 |
user = userRepository.selectBySecondryEmailId(emailId);
|
|
|
398 |
}
|
|
|
399 |
return responseSender.ok(user);
|
| 21248 |
ashik.ali |
400 |
}
|
| 21469 |
amit.gupta |
401 |
|
|
|
402 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_ROLE_ALL, method = RequestMethod.GET)
|
|
|
403 |
public ResponseEntity<?> getAllRoles(HttpServletRequest request, @RequestParam(name = "id") int id) {
|
|
|
404 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 21448 |
ashik.ali |
405 |
return responseSender.ok(userRoleRepository.selectRolesByUserId(id));
|
| 21248 |
ashik.ali |
406 |
}
|
| 25366 |
tejbeer |
407 |
|
| 23204 |
ashik.ali |
408 |
@ApiImplicitParams({
|
| 25366 |
tejbeer |
409 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 23204 |
ashik.ali |
410 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_SECONDRY_EMAIL_ID_AND_FOFO_STORE_CODE, method = RequestMethod.GET)
|
| 25366 |
tejbeer |
411 |
public ResponseEntity<?> getSecondryEmailAndStoreCode(HttpServletRequest request)
|
|
|
412 |
throws ProfitMandiBusinessException {
|
| 23204 |
ashik.ali |
413 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
|
|
414 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
|
|
415 |
return responseSender.ok(userService.getEmailsAndFofoStoreCodeByUserId(userId));
|
|
|
416 |
}
|
| 25366 |
tejbeer |
417 |
|
| 23204 |
ashik.ali |
418 |
@ApiImplicitParams({
|
| 25366 |
tejbeer |
419 |
@ApiImplicitParam(name = "Auth-Token", value = "-Token", required = true, dataType = "string", paramType = "header") })
|
| 23858 |
ashik.ali |
420 |
@RequestMapping(value = ProfitMandiConstants.URL_USER_SECONDRY_EMAIL_ID, method = RequestMethod.PUT)
|
| 23204 |
ashik.ali |
421 |
public ResponseEntity<?> updateSecondryEmailId(HttpServletRequest request,
|
| 25366 |
tejbeer |
422 |
@RequestParam(name = ProfitMandiConstants.SECONDRY_EMAIL_ID) String secondryEmailId) throws Throwable {
|
|
|
423 |
int userId = (int) request.getAttribute("userId");
|
|
|
424 |
User user = userRepository.selectById(userId);
|
|
|
425 |
user.setSecondryEmailId(secondryEmailId);
|
|
|
426 |
userRepository.persist(user);
|
|
|
427 |
return responseSender.ok(ResponseCodeHolder.getMessage("USR_OK_1001"));
|
|
|
428 |
}
|
| 21414 |
kshitij.so |
429 |
|
|
|
430 |
@RequestMapping(value = ProfitMandiConstants.URL_ADMIN_TOKEN, method = RequestMethod.POST)
|
| 21469 |
amit.gupta |
431 |
public ResponseEntity<?> getAdminToken(HttpServletRequest request,
|
|
|
432 |
@RequestParam(name = "adminToken") String adminToken, @RequestParam(name = "emailId") String emailId) {
|
|
|
433 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
|
|
434 |
if (!adminToken.equals(validAdminToken)) {
|
| 22930 |
ashik.ali |
435 |
return responseSender.forbidden(null);
|
| 21414 |
kshitij.so |
436 |
}
|
| 21469 |
amit.gupta |
437 |
|
| 21414 |
kshitij.so |
438 |
Map<String, Object> responseMap = new HashMap<>(2);
|
| 23204 |
ashik.ali |
439 |
User user = null;
|
| 21469 |
amit.gupta |
440 |
try {
|
| 23204 |
ashik.ali |
441 |
user = userRepository.selectByEmailId(emailId);
|
|
|
442 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 25366 |
tejbeer |
443 |
|
| 23204 |
ashik.ali |
444 |
}
|
| 25366 |
tejbeer |
445 |
|
|
|
446 |
if (user == null) {
|
|
|
447 |
try {
|
| 23204 |
ashik.ali |
448 |
user = userRepository.selectBySecondryEmailId(emailId);
|
| 25366 |
tejbeer |
449 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
450 |
|
| 23204 |
ashik.ali |
451 |
}
|
|
|
452 |
}
|
| 25366 |
tejbeer |
453 |
if (user != null) {
|
| 23858 |
ashik.ali |
454 |
int retailerId = 0;
|
|
|
455 |
try {
|
|
|
456 |
retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
|
|
|
457 |
} catch (ProfitMandiBusinessException e) {
|
|
|
458 |
// TODO Auto-generated catch block
|
|
|
459 |
e.printStackTrace();
|
|
|
460 |
}
|
|
|
461 |
List<Integer> roleIds = userRoleRepository.selectRoleIdsByUserId(user.getId());
|
|
|
462 |
String[] roleIdsString = new String[roleIds.size()];
|
| 21414 |
kshitij.so |
463 |
int index = 0;
|
| 23858 |
ashik.ali |
464 |
for (int roleId : roleIds) {
|
|
|
465 |
roleIdsString[index++] = String.valueOf(roleId);
|
| 21414 |
kshitij.so |
466 |
}
|
| 23858 |
ashik.ali |
467 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(user.getId(), retailerId, roleIdsString));
|
| 21414 |
kshitij.so |
468 |
responseMap.put(ProfitMandiConstants.REGISTERED, true);
|
| 25366 |
tejbeer |
469 |
} else {
|
| 21469 |
amit.gupta |
470 |
responseMap.put(ProfitMandiConstants.TOKEN, JWTUtil.create(emailId));
|
| 21414 |
kshitij.so |
471 |
responseMap.put(ProfitMandiConstants.REGISTERED, false);
|
|
|
472 |
}
|
| 21448 |
ashik.ali |
473 |
return responseSender.ok(responseMap);
|
| 21469 |
amit.gupta |
474 |
|
| 21414 |
kshitij.so |
475 |
}
|
| 25366 |
tejbeer |
476 |
|
| 25300 |
tejbeer |
477 |
@RequestMapping(value = "/mobileappsettings", method = RequestMethod.POST)
|
| 25366 |
tejbeer |
478 |
public ResponseEntity<?> mobileAppSettings(HttpServletRequest request, @RequestParam(name = "t") int timestamp,
|
|
|
479 |
@RequestParam(name = "imeinumber") String imeinumber)
|
|
|
480 |
throws ProfitMandiBusinessException, ClientProtocolException, IOException {
|
|
|
481 |
|
| 26203 |
amit.gupta |
482 |
final String uri = "http://192.168.158.89/mobileappsettings?t=" + timestamp + "&imeinumber=" + imeinumber;
|
| 25300 |
tejbeer |
483 |
final String BASIC_AUTH = "Basic " + Base64.getEncoder().encodeToString("dtr:dtr18Feb2015".getBytes());
|
|
|
484 |
Map<String, String> headers = new HashMap<>();
|
|
|
485 |
Map<String, String> params = new HashMap<>();
|
|
|
486 |
headers.put("Authorization", BASIC_AUTH);
|
|
|
487 |
return responseSender.ok(restClient.post(uri, params, headers));
|
|
|
488 |
}
|
| 22032 |
ashik.ali |
489 |
|
| 25366 |
tejbeer |
490 |
@RequestMapping(value = "/getPartners", method = RequestMethod.GET)
|
|
|
491 |
@ApiImplicitParams({
|
|
|
492 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
493 |
public ResponseEntity<?> getPartners(HttpServletRequest request, @RequestParam(name = "gmailId") String gmailId,
|
|
|
494 |
@RequestParam(value = "offset") int offset, @RequestParam(value = "limit") int limit)
|
|
|
495 |
throws ProfitMandiBusinessException {
|
|
|
496 |
AuthUser authUser = authRepository.selectByGmailId(gmailId);
|
|
|
497 |
|
| 25619 |
amit.gupta |
498 |
Map<String, Set<String>> storeGuyMap = csService.getAuthUserPartnerEmailMapping();
|
| 25366 |
tejbeer |
499 |
|
| 25619 |
amit.gupta |
500 |
Set<String> emails = storeGuyMap.get(authUser.getEmailId().toLowerCase());
|
| 25366 |
tejbeer |
501 |
LOGGER.info("emails" + emails);
|
| 25619 |
amit.gupta |
502 |
List<User> users = userRepository.selectAllByEmails(new ArrayList<>(emails), offset, limit);
|
| 25366 |
tejbeer |
503 |
List<Partner> partners = new ArrayList<>();
|
|
|
504 |
for (User user : users) {
|
| 25458 |
tejbeer |
505 |
|
| 25366 |
tejbeer |
506 |
UserAccount uc = userAccountRepository.selectSaholicByUserId(user.getId());
|
| 25458 |
tejbeer |
507 |
com.spice.profitmandi.dao.entity.user.User userInfo = userUserRepository.selectById(uc.getAccountKey());
|
| 25366 |
tejbeer |
508 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(userInfo.getId());
|
|
|
509 |
|
|
|
510 |
Partner partner = new Partner();
|
|
|
511 |
partner.setBusinessName(customRetailer.getBusinessName());
|
|
|
512 |
partner.setPartnerId(customRetailer.getPartnerId());
|
|
|
513 |
partner.setCartId(customRetailer.getCartId());
|
|
|
514 |
partner.setEmail(customRetailer.getEmail());
|
|
|
515 |
partner.setGstNumber(customRetailer.getGstNumber());
|
|
|
516 |
partner.setDisplayName(customRetailer.getDisplayName());
|
|
|
517 |
partner.setCity(customRetailer.getAddress().getCity());
|
|
|
518 |
partner.setUserId(user.getId());
|
|
|
519 |
partners.add(partner);
|
|
|
520 |
}
|
|
|
521 |
LOGGER.info("partners" + partners);
|
|
|
522 |
return responseSender.ok(partners);
|
|
|
523 |
}
|
|
|
524 |
|
| 25458 |
tejbeer |
525 |
@RequestMapping(value = "/user/refferal", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
526 |
@ApiImplicitParams({
|
|
|
527 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
528 |
public ResponseEntity<?> RefferalUser(HttpServletRequest request,
|
|
|
529 |
@RequestBody CreateRefferalRequest createRefferalRequest) throws Exception {
|
|
|
530 |
Refferal refferal = new Refferal();
|
|
|
531 |
refferal.setFirstName(createRefferalRequest.getFirstName());
|
|
|
532 |
refferal.setLastName(createRefferalRequest.getLastName());
|
|
|
533 |
refferal.setMobile(createRefferalRequest.getMobile());
|
|
|
534 |
refferal.setState(createRefferalRequest.getState());
|
|
|
535 |
refferal.setCity(createRefferalRequest.getCity());
|
|
|
536 |
refferal.setCreatedTimestamp(LocalDateTime.now());
|
|
|
537 |
refferal.setUpdatedTimestamp(LocalDateTime.now());
|
| 25496 |
tejbeer |
538 |
refferal.setStatus(RefferalStatus.pending);
|
| 25458 |
tejbeer |
539 |
if (createRefferalRequest.isFofoAssociate()) {
|
|
|
540 |
AuthUser authUser = authRepository.selectByGmailId(createRefferalRequest.getReffereeEmail());
|
| 25483 |
tejbeer |
541 |
if (authUser == null) {
|
| 25458 |
tejbeer |
542 |
Promoter promoter = promoterRepository.selectByEmailId(createRefferalRequest.getReffereeEmail());
|
|
|
543 |
refferal.setRefereeName(promoter.getName());
|
| 25483 |
tejbeer |
544 |
refferal.setRefereeEmail(promoter.getEmail());
|
| 25458 |
tejbeer |
545 |
refferal.setRefereeMobile(promoter.getMobile());
|
|
|
546 |
} else {
|
|
|
547 |
refferal.setRefereeName(authUser.getFirstName());
|
| 25483 |
tejbeer |
548 |
refferal.setRefereeEmail(authUser.getGmailId());
|
| 25458 |
tejbeer |
549 |
refferal.setRefereeMobile(authUser.getMobileNumber());
|
|
|
550 |
}
|
|
|
551 |
} else {
|
|
|
552 |
User user = userRepository.selectByEmailId(createRefferalRequest.getReffereeEmail());
|
|
|
553 |
refferal.setRefereeName(user.getFirstName());
|
| 25483 |
tejbeer |
554 |
refferal.setRefereeEmail(user.getEmailId());
|
| 25458 |
tejbeer |
555 |
refferal.setRefereeMobile(user.getMobileNumber());
|
|
|
556 |
}
|
|
|
557 |
|
|
|
558 |
refferalRepository.persist(refferal);
|
|
|
559 |
return responseSender.ok(true);
|
|
|
560 |
}
|
| 25488 |
tejbeer |
561 |
|
|
|
562 |
@RequestMapping(value = "/user/refferalAmount", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
563 |
@ApiImplicitParams({
|
|
|
564 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
565 |
public ResponseEntity<?> RefferalAmount(HttpServletRequest request, @RequestParam String refereeEmail)
|
|
|
566 |
throws Exception {
|
|
|
567 |
LocalDateTime ldt = LocalDate.now().atStartOfDay().withDayOfMonth(16);
|
|
|
568 |
DateRangeModel drm = new DateRangeModel();
|
|
|
569 |
List<RefferalEarningModel> refferAmountModel = new ArrayList<RefferalEarningModel>();
|
|
|
570 |
RefferalEarningModel rfm = new RefferalEarningModel();
|
|
|
571 |
long currentMonthEstimaterefferal = 0;
|
|
|
572 |
long currentMonthConfirmedrefferal = 0;
|
|
|
573 |
if (LocalDateTime.now().isBefore(ldt)) {
|
|
|
574 |
List<Refferal> allPendingRefferalBeforeCurrentMonth = refferalRepository
|
|
|
575 |
.selectByEmailIdAndStatusAndbeforeCurrentMonth(refereeEmail, RefferalStatus.pending);
|
|
|
576 |
drm.setStartDate(LocalDateTime.now().minusMonths(1).withDayOfMonth(16));
|
|
|
577 |
drm.setEndDate(LocalDateTime.now().withDayOfMonth(1));
|
|
|
578 |
|
|
|
579 |
List<Refferal> previousMonthapprovedRefferalAfterSixteen = refferalRepository
|
|
|
580 |
.selectByEmailIdAndStatusAndDateRange(refereeEmail, RefferalStatus.approved, drm);
|
|
|
581 |
List<Refferal> previousMonthtransferredRefferalAfterSixteen = refferalRepository
|
|
|
582 |
.selectByEmailIdAndStatusAndDateRange(refereeEmail, RefferalStatus.transferred, drm);
|
|
|
583 |
|
|
|
584 |
drm.setStartDate(LocalDateTime.now().minusMonths(1).withDayOfMonth(1));
|
|
|
585 |
drm.setEndDate(LocalDateTime.now().minusMonths(1).withDayOfMonth(16));
|
|
|
586 |
|
|
|
587 |
List<Refferal> previousMonthapprovedRefferalbeforeSixteen = refferalRepository
|
|
|
588 |
.selectByEmailIdAndStatusAndDateRanges(refereeEmail, RefferalStatus.approved, drm);
|
|
|
589 |
List<Refferal> previousMonthtransferredRefferalbeforeSixteen = refferalRepository
|
|
|
590 |
.selectByEmailIdAndStatusAndDateRanges(refereeEmail, RefferalStatus.transferred, drm);
|
|
|
591 |
long pendingRefferalBeforeCurrentMonth = allPendingRefferalBeforeCurrentMonth.size();
|
|
|
592 |
long previousapprovedRefferalAfterSixteen = previousMonthapprovedRefferalAfterSixteen.size();
|
|
|
593 |
long previoustransferredRefferalAfterSixteen = previousMonthtransferredRefferalAfterSixteen.size();
|
|
|
594 |
long previousapprovedRefferalbeforeSixteen = previousMonthapprovedRefferalbeforeSixteen.size();
|
|
|
595 |
long previoustransferredRefferalbeforeSixteen = previousMonthtransferredRefferalbeforeSixteen.size();
|
|
|
596 |
long previousMonthEstimateRefferal = pendingRefferalBeforeCurrentMonth
|
|
|
597 |
+ previousapprovedRefferalAfterSixteen + previousapprovedRefferalbeforeSixteen;
|
|
|
598 |
long previousMonthConfirmedRefferal = previousapprovedRefferalAfterSixteen
|
|
|
599 |
+ previoustransferredRefferalAfterSixteen + previousapprovedRefferalbeforeSixteen
|
|
|
600 |
+ previoustransferredRefferalbeforeSixteen;
|
| 25490 |
tejbeer |
601 |
rfm = refferAmountEarning(pendingRefferalBeforeCurrentMonth, previousMonthConfirmedRefferal,
|
| 25488 |
tejbeer |
602 |
YearMonth.now().minusMonths(1));
|
|
|
603 |
refferAmountModel.add(rfm);
|
|
|
604 |
LOGGER.info("previousMonthPendingApprovedRefferal" + previousMonthEstimateRefferal);
|
|
|
605 |
LOGGER.info("previousMonthApprovedTransfferedRefferal" + previousMonthConfirmedRefferal);
|
|
|
606 |
|
| 25509 |
tejbeer |
607 |
List<Refferal> pendingofCurrentMonth = refferalRepository
|
|
|
608 |
.selectByEmailIdAndStatusAndBetweenDates(refereeEmail, RefferalStatus.pending, YearMonth.now());
|
| 25488 |
tejbeer |
609 |
List<Refferal> approvedofCurrentMonth = refferalRepository.selectByEmailIdAndStatusAndDatesBetweenTimestamp(
|
|
|
610 |
refereeEmail, RefferalStatus.approved, YearMonth.now());
|
|
|
611 |
List<Refferal> transferredofCurrentMonth = refferalRepository
|
|
|
612 |
.selectByEmailIdAndStatusAndDatesBetweenTimestamp(refereeEmail, RefferalStatus.transferred,
|
|
|
613 |
YearMonth.now());
|
| 25490 |
tejbeer |
614 |
LOGGER.info("pendingofCurrentMonth" + pendingofCurrentMonth);
|
| 25509 |
tejbeer |
615 |
long pendingofCurrentMonthCount = pendingofCurrentMonth.size();
|
| 25488 |
tejbeer |
616 |
currentMonthEstimaterefferal = pendingofCurrentMonth.size() + approvedofCurrentMonth.size();
|
|
|
617 |
currentMonthConfirmedrefferal = approvedofCurrentMonth.size() + transferredofCurrentMonth.size();
|
| 25509 |
tejbeer |
618 |
|
| 25490 |
tejbeer |
619 |
rfm = refferAmountEarning(pendingofCurrentMonthCount, currentMonthConfirmedrefferal, YearMonth.now());
|
| 25488 |
tejbeer |
620 |
|
|
|
621 |
refferAmountModel.add(rfm);
|
|
|
622 |
|
|
|
623 |
} else if (LocalDateTime.now().isAfter(ldt)) {
|
|
|
624 |
drm.setStartDate(LocalDateTime.now().minusMonths(1).withDayOfMonth(1));
|
| 25496 |
tejbeer |
625 |
drm.setEndDate(LocalDateTime.now().minusMonths(1).withDayOfMonth(16));
|
| 25488 |
tejbeer |
626 |
|
|
|
627 |
List<Refferal> previousMonthapprovedRefferalbeforeSixteen = refferalRepository
|
|
|
628 |
.selectByEmailIdAndStatusAndDateRanges(refereeEmail, RefferalStatus.approved, drm);
|
|
|
629 |
List<Refferal> previousMonthtransferredRefferalbeforeSixteen = refferalRepository
|
|
|
630 |
.selectByEmailIdAndStatusAndDateRanges(refereeEmail, RefferalStatus.transferred, drm);
|
|
|
631 |
|
|
|
632 |
drm.setStartDate(LocalDateTime.now().minusMonths(1).withDayOfMonth(16));
|
|
|
633 |
drm.setEndDate(LocalDateTime.now().withDayOfMonth(16));
|
|
|
634 |
|
|
|
635 |
List<Refferal> previousAndcurrentMonthapprovedRefferal = refferalRepository
|
|
|
636 |
.selectByEmailIdAndStatusAndDateRange(refereeEmail, RefferalStatus.approved, drm);
|
|
|
637 |
|
|
|
638 |
LocalDateTime currentMonthdate = LocalDateTime.now().withDayOfMonth(1);
|
|
|
639 |
|
|
|
640 |
List<Refferal> preCurrMonthapproved = previousAndcurrentMonthapprovedRefferal.stream()
|
|
|
641 |
.filter(x -> x.getCreatedTimestamp().isBefore(currentMonthdate)).collect(Collectors.toList());
|
|
|
642 |
List<Refferal> previousAndcurrentMonthtransferredRefferal = refferalRepository
|
|
|
643 |
.selectByEmailIdAndStatusAndDateRange(refereeEmail, RefferalStatus.transferred, drm);
|
|
|
644 |
List<Refferal> preCurrMonthtransferred = previousAndcurrentMonthtransferredRefferal.stream()
|
|
|
645 |
.filter(x -> x.getCreatedTimestamp().isBefore(currentMonthdate)).collect(Collectors.toList());
|
|
|
646 |
|
|
|
647 |
long approvedRefferal = previousMonthapprovedRefferalbeforeSixteen.size()
|
|
|
648 |
+ previousMonthtransferredRefferalbeforeSixteen.size() + preCurrMonthapproved.size()
|
|
|
649 |
+ preCurrMonthtransferred.size();
|
|
|
650 |
rfm = new RefferalEarningModel();
|
|
|
651 |
if (approvedRefferal <= 4) {
|
|
|
652 |
rfm.setActualEarning(approvedRefferal * 5000);
|
|
|
653 |
} else if (approvedRefferal >= 5 && approvedRefferal <= 9) {
|
|
|
654 |
rfm.setActualEarning(approvedRefferal * 10000);
|
|
|
655 |
} else if (approvedRefferal > 10) {
|
|
|
656 |
rfm.setActualEarning(approvedRefferal * 200000);
|
|
|
657 |
}
|
|
|
658 |
rfm.setYearMonth(YearMonth.now().minusMonths(1));
|
| 25490 |
tejbeer |
659 |
rfm.setPendingRefferal(0);
|
| 25509 |
tejbeer |
660 |
rfm.setApprovedRefferal(approvedRefferal);
|
| 25488 |
tejbeer |
661 |
refferAmountModel.add(rfm);
|
|
|
662 |
List<Refferal> allpendingRefferal = refferalRepository.selectByEmailIdAndStatus(refereeEmail,
|
|
|
663 |
RefferalStatus.pending);
|
|
|
664 |
LOGGER.info("allpendingRefferal" + allpendingRefferal);
|
|
|
665 |
|
|
|
666 |
drm.setStartDate(LocalDateTime.now().withDayOfMonth(16));
|
|
|
667 |
drm.setEndDate(LocalDateTime.now().plusMonths(1).withDayOfMonth(1));
|
|
|
668 |
|
|
|
669 |
List<Refferal> currentMonthapprovedRefferalAfterSixteen = refferalRepository
|
|
|
670 |
.selectByEmailIdAndStatusAndDateRange(refereeEmail, RefferalStatus.approved, drm);
|
|
|
671 |
List<Refferal> currentMonthtransferredRefferalAfterSixteen = refferalRepository
|
|
|
672 |
.selectByEmailIdAndStatusAndDateRange(refereeEmail, RefferalStatus.transferred, drm);
|
|
|
673 |
LOGGER.info("currentMonthapprovedRefferalAfterSixteen" + currentMonthapprovedRefferalAfterSixteen);
|
|
|
674 |
drm.setStartDate(LocalDateTime.now().withDayOfMonth(1));
|
|
|
675 |
drm.setEndDate(LocalDateTime.now().withDayOfMonth(16));
|
|
|
676 |
|
|
|
677 |
List<Refferal> currentMonthapprovedRefferalbeforeSixteen = refferalRepository
|
|
|
678 |
.selectByEmailIdAndStatusAndDateRanges(refereeEmail, RefferalStatus.approved, drm);
|
|
|
679 |
List<Refferal> currentMonthtransferredRefferalbeforeSixteen = refferalRepository
|
|
|
680 |
.selectByEmailIdAndStatusAndDateRanges(refereeEmail, RefferalStatus.transferred, drm);
|
|
|
681 |
LOGGER.info("currentMonthapprovedRefferalbeforeSixteen" + currentMonthapprovedRefferalbeforeSixteen);
|
| 25509 |
tejbeer |
682 |
long pendingrefferalcount = allpendingRefferal.size();
|
| 25488 |
tejbeer |
683 |
currentMonthConfirmedrefferal = currentMonthapprovedRefferalAfterSixteen.size()
|
|
|
684 |
+ currentMonthtransferredRefferalAfterSixteen.size()
|
|
|
685 |
+ currentMonthapprovedRefferalbeforeSixteen.size()
|
|
|
686 |
+ currentMonthtransferredRefferalbeforeSixteen.size();
|
| 25509 |
tejbeer |
687 |
|
|
|
688 |
rfm = refferAmountEarning(pendingrefferalcount, currentMonthConfirmedrefferal, YearMonth.now());
|
| 25488 |
tejbeer |
689 |
refferAmountModel.add(rfm);
|
|
|
690 |
LOGGER.info("currentMonthpendingApprovedrefferal" + currentMonthEstimaterefferal);
|
|
|
691 |
|
|
|
692 |
LOGGER.info("currentMonthapprovedTransferredrefferal" + currentMonthConfirmedrefferal);
|
|
|
693 |
|
|
|
694 |
}
|
|
|
695 |
RefferalEarning re = new RefferalEarning();
|
|
|
696 |
re.setTimestamp(LocalDateTime.now());
|
|
|
697 |
re.setRefferalEarningModel(refferAmountModel);
|
|
|
698 |
return responseSender.ok(re);
|
|
|
699 |
}
|
|
|
700 |
|
| 25490 |
tejbeer |
701 |
private RefferalEarningModel refferAmountEarning(long pendingRefferalValue, long confirmedRefferalValue,
|
| 25488 |
tejbeer |
702 |
YearMonth yearMonth) {
|
|
|
703 |
RefferalEarningModel rfm = new RefferalEarningModel();
|
|
|
704 |
rfm.setYearMonth(yearMonth);
|
| 25490 |
tejbeer |
705 |
rfm.setPendingRefferal(pendingRefferalValue);
|
|
|
706 |
rfm.setApprovedRefferal(confirmedRefferalValue);
|
| 25509 |
tejbeer |
707 |
long estimateRefferalValue = pendingRefferalValue + confirmedRefferalValue;
|
| 25488 |
tejbeer |
708 |
if (estimateRefferalValue <= 4) {
|
|
|
709 |
rfm.setMaximumEarning(estimateRefferalValue * 5000);
|
|
|
710 |
} else if (estimateRefferalValue >= 5 && estimateRefferalValue <= 9) {
|
|
|
711 |
rfm.setMaximumEarning(estimateRefferalValue * 10000);
|
| 25640 |
tejbeer |
712 |
} else if (estimateRefferalValue >= 10) {
|
| 25488 |
tejbeer |
713 |
rfm.setMaximumEarning(200000);
|
|
|
714 |
}
|
|
|
715 |
|
|
|
716 |
if (confirmedRefferalValue <= 4) {
|
|
|
717 |
rfm.setMinimumEarning(confirmedRefferalValue * 5000);
|
|
|
718 |
} else if (confirmedRefferalValue >= 5 && confirmedRefferalValue <= 9) {
|
|
|
719 |
rfm.setMinimumEarning(confirmedRefferalValue * 10000);
|
| 25640 |
tejbeer |
720 |
} else if (confirmedRefferalValue >= 10) {
|
| 25488 |
tejbeer |
721 |
rfm.setMinimumEarning(200000);
|
|
|
722 |
}
|
|
|
723 |
return rfm;
|
|
|
724 |
}
|
| 25979 |
tejbeer |
725 |
|
| 25622 |
amit.gupta |
726 |
@RequestMapping(value = "/user/partnerTarget", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
727 |
@ApiImplicitParams({
|
|
|
728 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
729 |
public ResponseEntity<?> PartnerTarget(HttpServletRequest request) throws Exception {
|
|
|
730 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
|
|
731 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
|
|
732 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(retailerId, LocalDate.now());
|
| 25979 |
tejbeer |
733 |
|
| 25622 |
amit.gupta |
734 |
return responseSender.ok(partnerType);
|
|
|
735 |
}
|
| 21248 |
ashik.ali |
736 |
}
|