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