| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.service.user;
|
1 |
package com.spice.profitmandi.service.user;
|
| 2 |
|
2 |
|
| - |
|
3 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
| 3 |
import com.google.common.hash.Hashing;
|
4 |
import com.google.common.hash.Hashing;
|
| - |
|
5 |
import com.google.gson.Gson;
|
| 4 |
import com.spice.profitmandi.common.enumuration.ActivationType;
|
6 |
import com.spice.profitmandi.common.enumuration.ActivationType;
|
| 5 |
import com.spice.profitmandi.common.enumuration.FofoType;
|
7 |
import com.spice.profitmandi.common.enumuration.FofoType;
|
| 6 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
8 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 7 |
import com.spice.profitmandi.common.model.*;
|
9 |
import com.spice.profitmandi.common.model.*;
|
| 8 |
import com.spice.profitmandi.common.util.StringUtils;
|
10 |
import com.spice.profitmandi.common.util.StringUtils;
|
| Line 22... |
Line 24... |
| 22 |
import com.spice.profitmandi.dao.model.LastMonthCreditedIncomeModel;
|
24 |
import com.spice.profitmandi.dao.model.LastMonthCreditedIncomeModel;
|
| 23 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
25 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
| 24 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
26 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 25 |
import com.spice.profitmandi.dao.repository.fofo.*;
|
27 |
import com.spice.profitmandi.dao.repository.fofo.*;
|
| 26 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
28 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
| - |
|
29 |
import com.spice.profitmandi.dao.repository.trialOnboarding.TrialFormRepository;
|
| 27 |
import com.spice.profitmandi.dao.repository.user.*;
|
30 |
import com.spice.profitmandi.dao.repository.user.*;
|
| 28 |
import com.spice.profitmandi.service.PostOfficeService;
|
31 |
import com.spice.profitmandi.service.PostOfficeService;
|
| 29 |
import com.spice.profitmandi.service.catalog.BrandsService;
|
32 |
import com.spice.profitmandi.service.catalog.BrandsService;
|
| 30 |
import in.shop2020.model.v1.user.CartStatus;
|
33 |
import in.shop2020.model.v1.user.CartStatus;
|
| 31 |
import org.apache.logging.log4j.LogManager;
|
34 |
import org.apache.logging.log4j.LogManager;
|
| 32 |
import org.apache.logging.log4j.Logger;
|
35 |
import org.apache.logging.log4j.Logger;
|
| 33 |
import org.springframework.beans.factory.annotation.Autowired;
|
36 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 34 |
import org.springframework.beans.factory.annotation.Qualifier;
|
37 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 35 |
import org.springframework.cache.annotation.Cacheable;
|
38 |
import org.springframework.cache.annotation.Cacheable;
|
| - |
|
39 |
import org.springframework.mail.javamail.JavaMailSender;
|
| 36 |
import org.springframework.stereotype.Component;
|
40 |
import org.springframework.stereotype.Component;
|
| 37 |
|
41 |
|
| 38 |
import java.nio.charset.StandardCharsets;
|
42 |
import java.nio.charset.StandardCharsets;
|
| 39 |
import java.time.LocalDate;
|
43 |
import java.time.LocalDate;
|
| 40 |
import java.time.LocalDateTime;
|
44 |
import java.time.LocalDateTime;
|
| Line 47... |
Line 51... |
| 47 |
|
51 |
|
| 48 |
@Component
|
52 |
@Component
|
| 49 |
public class RetailerServiceImpl implements RetailerService {
|
53 |
public class RetailerServiceImpl implements RetailerService {
|
| 50 |
|
54 |
|
| 51 |
private static final Logger LOGGER = LogManager.getLogger(RetailerServiceImpl.class);
|
55 |
private static final Logger LOGGER = LogManager.getLogger(RetailerServiceImpl.class);
|
| - |
|
56 |
private static final String[] TRIAL_CODE_CREATION_AUDIENCE = new String[]{"amit.gupta@smartdukaan.com"};
|
| - |
|
57 |
//private static final String [] TRIAL_CODE_CREATION_AUDIENCE = new String[]{};
|
| 52 |
|
58 |
|
| 53 |
@Autowired
|
59 |
@Autowired
|
| 54 |
private RetailerRepository retailerRepository;
|
60 |
private RetailerRepository retailerRepository;
|
| 55 |
|
61 |
|
| 56 |
@Autowired
|
62 |
@Autowired
|
| Line 61... |
Line 67... |
| 61 |
|
67 |
|
| 62 |
@Autowired
|
68 |
@Autowired
|
| 63 |
private Mongo mongoClient;
|
69 |
private Mongo mongoClient;
|
| 64 |
|
70 |
|
| 65 |
@Autowired
|
71 |
@Autowired
|
| - |
|
72 |
Gson gson;
|
| - |
|
73 |
|
| - |
|
74 |
@Autowired
|
| 66 |
private UserRepository userRepository;
|
75 |
private UserRepository userRepository;
|
| - |
|
76 |
@Autowired
|
| - |
|
77 |
ObjectMapper objectMapper;
|
| - |
|
78 |
|
| - |
|
79 |
|
| 67 |
|
80 |
|
| 68 |
@Autowired
|
81 |
@Autowired
|
| 69 |
private CartRepository cartRepository;
|
82 |
private CartRepository cartRepository;
|
| 70 |
|
83 |
|
| 71 |
@Autowired
|
84 |
@Autowired
|
| Line 98... |
Line 111... |
| 98 |
@Autowired
|
111 |
@Autowired
|
| 99 |
private CounterRepository counterRepository;
|
112 |
private CounterRepository counterRepository;
|
| 100 |
|
113 |
|
| 101 |
@Autowired
|
114 |
@Autowired
|
| 102 |
private StateRepository stateRepository;
|
115 |
private StateRepository stateRepository;
|
| - |
|
116 |
@Autowired
|
| - |
|
117 |
private TrialFormRepository trialFormRepository;
|
| 103 |
|
118 |
|
| 104 |
@Autowired
|
119 |
@Autowired
|
| 105 |
@Qualifier("userUserRepository")
|
120 |
@Qualifier("userUserRepository")
|
| 106 |
private com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
|
121 |
private com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
|
| 107 |
|
122 |
|
| Line 147... |
Line 162... |
| 147 |
@Autowired
|
162 |
@Autowired
|
| 148 |
PartnerTypeChangeService partnerTypeChangeService;
|
163 |
PartnerTypeChangeService partnerTypeChangeService;
|
| 149 |
|
164 |
|
| 150 |
@Autowired
|
165 |
@Autowired
|
| 151 |
BrandsService brandsService;
|
166 |
BrandsService brandsService;
|
| - |
|
167 |
@Autowired
|
| - |
|
168 |
private JavaMailSender googleMailSender;
|
| 152 |
|
169 |
|
| 153 |
@Override
|
170 |
@Override
|
| 154 |
public Map<String, Object> getByEmailIdOrMobileNumber(String emailIdOrMobileNumber) throws ProfitMandiBusinessException {
|
171 |
public Map<String, Object> getByEmailIdOrMobileNumber(String emailIdOrMobileNumber) throws ProfitMandiBusinessException {
|
| 155 |
User user = null;
|
172 |
User user = null;
|
| 156 |
int fofoId = Utils.SYSTEM_PARTNER_ID;
|
173 |
int fofoId = Utils.SYSTEM_PARTNER_ID;
|
| Line 167... |
Line 184... |
| 167 |
|
184 |
|
| 168 |
}
|
185 |
}
|
| 169 |
}
|
186 |
}
|
| 170 |
Map<String, Object> map = new HashMap<>();
|
187 |
Map<String, Object> map = new HashMap<>();
|
| 171 |
map.put("stateNames", stateRepository.selectAll().stream().map(x -> x.getName()).collect(Collectors.toList()));
|
188 |
map.put("stateNames", stateRepository.selectAll().stream().map(x -> x.getName()).collect(Collectors.toList()));
|
| 172 |
|
- |
|
| - |
|
189 |
LOGGER.info("user - {}", user);
|
| 173 |
if (user != null) {
|
190 |
if (user != null) {
|
| 174 |
|
191 |
|
| 175 |
List<UserRole> userRoles = userRoleRepository.selectByUserId(user.getId());
|
192 |
List<UserRole> userRoles = userRoleRepository.selectByUserId(user.getId());
|
| 176 |
|
193 |
|
| 177 |
Role role = roleRepository.selectByName(RoleType.FOFO.toString());
|
194 |
Role role = roleRepository.selectByName(RoleType.FOFO.toString());
|
| Line 244... |
Line 261... |
| 244 |
LOGGER.error("Retailer Registered Address not found");
|
261 |
LOGGER.error("Retailer Registered Address not found");
|
| 245 |
}
|
262 |
}
|
| 246 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
263 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 247 |
LOGGER.error("Retailer not found in user_account");
|
264 |
LOGGER.error("Retailer not found in user_account");
|
| 248 |
}
|
265 |
}
|
| - |
|
266 |
} else {
|
| - |
|
267 |
try {
|
| - |
|
268 |
TrialForm trialForm = trialFormRepository.selectByEmailOrMobile(emailIdOrMobileNumber);
|
| - |
|
269 |
map.put("trialForm", gson.toJson(trialForm));
|
| - |
|
270 |
} catch (Exception e) {
|
| - |
|
271 |
LOGGER.error("Retailer not found in user_account");
|
| - |
|
272 |
}
|
| 249 |
}
|
273 |
}
|
| 250 |
|
274 |
|
| 251 |
return map;
|
275 |
return map;
|
| 252 |
}
|
276 |
}
|
| 253 |
|
277 |
|
| Line 853... |
Line 877... |
| 853 |
fofoStore.setCounterSize(updateRetailerRequest.getCountersize());
|
877 |
fofoStore.setCounterSize(updateRetailerRequest.getCountersize());
|
| 854 |
fofoStore.setMinimumInvestment(updateRetailerRequest.getMinInvestment());
|
878 |
fofoStore.setMinimumInvestment(updateRetailerRequest.getMinInvestment());
|
| 855 |
|
879 |
|
| 856 |
fofoStore.setCounterPotential(updateRetailerRequest.getCounterPotential());
|
880 |
fofoStore.setCounterPotential(updateRetailerRequest.getCounterPotential());
|
| 857 |
fofoStore.setWarehouseId(updateRetailerRequest.getWarehouseId());
|
881 |
fofoStore.setWarehouseId(updateRetailerRequest.getWarehouseId());
|
| - |
|
882 |
|
| - |
|
883 |
//Check for Trial users here
|
| 858 |
int nextStoreCodeInt = fofoStoreRepository.selectLatestStore().getCodeInt() + 1;
|
884 |
int nextStoreCodeInt = fofoStoreRepository.selectLatestStore().getCodeInt() + 1;
|
| 859 |
|
885 |
|
| 860 |
String fofoStoreCode = StringUtils.generateFofoStoreSequence(
|
886 |
String fofoStoreCode = StringUtils.generateFofoStoreSequence(
|
| 861 |
districtMaster.getStateShortName() + districtMaster.getShortName(), nextStoreCodeInt);
|
887 |
districtMaster.getStateShortName() + districtMaster.getShortName(), nextStoreCodeInt);
|
| - |
|
888 |
TrialForm trialForm = trialFormRepository.selectByEmailOrMobile(updateRetailerRequest.getUserMobileNumber());
|
| - |
|
889 |
if (trialForm != null) {
|
| - |
|
890 |
fofoStoreCode = "T-" + fofoStoreCode;
|
| - |
|
891 |
fofoStore.setTrial(true);
|
| - |
|
892 |
fofoStore.setTrialStart(LocalDate.now());
|
| - |
|
893 |
fofoStore.setTrialEnd(LocalDate.now().plusDays(31));
|
| - |
|
894 |
trialForm.setStatus(ProfitMandiConstants.Status.APPROVED);
|
| - |
|
895 |
//TODO:Amit G, Send store code notification to retailer.
|
| - |
|
896 |
}
|
| 862 |
fofoStore.setCode(fofoStoreCode);
|
897 |
fofoStore.setCode(fofoStoreCode);
|
| 863 |
fofoStore.setCodeInt(nextStoreCodeInt);
|
898 |
fofoStore.setCodeInt(nextStoreCodeInt);
|
| 864 |
fofoStore.setBagsLastCredited(LocalDateTime.now());
|
899 |
fofoStore.setBagsLastCredited(LocalDateTime.now());
|
| 865 |
if (retailerAddress.getName().contains(ProfitMandiConstants.COMPANY_NAME) || retailerAddress.getName().contains(ProfitMandiConstants.COMPANY_SHORT_NAME)) {
|
900 |
if (retailerAddress.getName().contains(ProfitMandiConstants.COMPANY_NAME) || retailerAddress.getName().contains(ProfitMandiConstants.COMPANY_SHORT_NAME)) {
|
| 866 |
fofoStore.setInternal(true);
|
901 |
fofoStore.setInternal(true);
|
| Line 897... |
Line 932... |
| 897 |
pinPartner.setPincode(retailerAddress.getPinCode());
|
932 |
pinPartner.setPincode(retailerAddress.getPinCode());
|
| 898 |
pincodePartnerRepository.perist(pinPartner);
|
933 |
pincodePartnerRepository.perist(pinPartner);
|
| 899 |
}
|
934 |
}
|
| 900 |
}
|
935 |
}
|
| 901 |
|
936 |
|
| - |
|
937 |
if (fofoStore.isTrial()) {
|
| - |
|
938 |
this.sendTrialStoreCreationMail(fofoStore, updateRetailerRequest);
|
| - |
|
939 |
}
|
| - |
|
940 |
|
| 902 |
return fofoStore;
|
941 |
return fofoStore;
|
| 903 |
}
|
942 |
}
|
| 904 |
|
943 |
|
| - |
|
944 |
private void sendTrialStoreCreationMail(FofoStore fofoStore, UpdateRetailerRequest updateRetailerRequest) {
|
| - |
|
945 |
|
| - |
|
946 |
try {
|
| - |
|
947 |
|
| - |
|
948 |
String subject = String.format("Trial Store Created - %s");
|
| - |
|
949 |
String message = new StringBuffer("New Trial Store Created. Please align for Training and Engagement. Assign ABMs and RBMs and BMs")
|
| - |
|
950 |
.append(String.format("Address - %s, %s\n", updateRetailerRequest.getAddress().getLine1(), updateRetailerRequest.getAddress().getLine2()))
|
| - |
|
951 |
.append(String.format("City - %s, ", updateRetailerRequest.getAddress().getCity()))
|
| - |
|
952 |
.append(String.format("Pincode - %s, ", updateRetailerRequest.getAddress().getPinCode()))
|
| - |
|
953 |
.append(String.format("State - %s", updateRetailerRequest.getAddress().getState())).toString();
|
| - |
|
954 |
|
| - |
|
955 |
LOGGER.info("message" + message);
|
| - |
|
956 |
|
| - |
|
957 |
|
| - |
|
958 |
//String [] mailTo = {"tarun.verma@smartdukaan.com", "neeraj.gupta@smartdukaan.com", "kamini.sharma@smartdukaan.com"}
|
| - |
|
959 |
String[] mailTo = {"amit.gupta@smartdukaan.com"};
|
| - |
|
960 |
Utils.sendMailWithAttachments(googleMailSender, new String[]{}, null, subject, message);
|
| - |
|
961 |
} catch (Exception e) {
|
| - |
|
962 |
|
| - |
|
963 |
e.printStackTrace();
|
| - |
|
964 |
|
| - |
|
965 |
}
|
| - |
|
966 |
|
| - |
|
967 |
}
|
| - |
|
968 |
|
| 905 |
@Override
|
969 |
@Override
|
| 906 |
public FofoStore createFofoStoreCodeByUserId(int userId, String districtName, String
|
970 |
public FofoStore createFofoStoreCodeByUserId(int userId, String districtName, String
|
| 907 |
stateName, UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException {
|
971 |
stateName, UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException {
|
| 908 |
User user = userRepository.selectById(userId);
|
972 |
User user = userRepository.selectById(userId);
|
| 909 |
// = userAccountRepository.selectRetailerIdByUserId(user.getId());
|
973 |
// = userAccountRepository.selectRetailerIdByUserId(user.getId());
|