Subversion Repositories SmartDukaan

Rev

Rev 37866 | Details | Compare with Previous | Last modification | View Log | RSS feed

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