| 22980 |
ashik.ali |
1 |
package com.spice.profitmandi.service.user;
|
|
|
2 |
|
| 26528 |
amit.gupta |
3 |
import com.google.common.hash.Hashing;
|
| 30097 |
tejbeer |
4 |
import com.spice.profitmandi.common.enumuration.ActivationType;
|
|
|
5 |
import com.spice.profitmandi.common.enumuration.FofoType;
|
| 22980 |
ashik.ali |
6 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 30017 |
amit.gupta |
7 |
import com.spice.profitmandi.common.model.*;
|
| 23329 |
ashik.ali |
8 |
import com.spice.profitmandi.common.util.StringUtils;
|
|
|
9 |
import com.spice.profitmandi.common.util.Utils;
|
| 22980 |
ashik.ali |
10 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 30017 |
amit.gupta |
11 |
import com.spice.profitmandi.dao.entity.dtr.*;
|
|
|
12 |
import com.spice.profitmandi.dao.entity.fofo.*;
|
| 24349 |
amit.gupta |
13 |
import com.spice.profitmandi.dao.entity.inventory.State;
|
| 30017 |
amit.gupta |
14 |
import com.spice.profitmandi.dao.entity.user.*;
|
| 23063 |
ashik.ali |
15 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
| 23106 |
ashik.ali |
16 |
import com.spice.profitmandi.dao.enumuration.dtr.RetailerType;
|
| 23136 |
ashik.ali |
17 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
| 23365 |
ashik.ali |
18 |
import com.spice.profitmandi.dao.enumuration.fofo.PaymentOptionType;
|
| 29042 |
tejbeer |
19 |
import com.spice.profitmandi.dao.enumuration.transaction.PartnerVerificationApprovalStatus;
|
| 22980 |
ashik.ali |
20 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 30017 |
amit.gupta |
21 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
| 23365 |
ashik.ali |
22 |
import com.spice.profitmandi.dao.repository.fofo.FofoPartnerPaymentOptionRepository;
|
|
|
23 |
import com.spice.profitmandi.dao.repository.fofo.PaymentOptionRepository;
|
| 30719 |
tejbeer |
24 |
import com.spice.profitmandi.dao.repository.fofo.PincodePartnerRepository;
|
| 24349 |
amit.gupta |
25 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
| 30017 |
amit.gupta |
26 |
import com.spice.profitmandi.dao.repository.user.*;
|
| 27877 |
amit.gupta |
27 |
import com.spice.profitmandi.service.offers.PartnerCriteria;
|
| 23043 |
ashik.ali |
28 |
import in.shop2020.model.v1.user.CartStatus;
|
| 30017 |
amit.gupta |
29 |
import org.apache.logging.log4j.LogManager;
|
|
|
30 |
import org.apache.logging.log4j.Logger;
|
|
|
31 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
32 |
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
33 |
import org.springframework.cache.annotation.Cacheable;
|
|
|
34 |
import org.springframework.stereotype.Component;
|
| 23043 |
ashik.ali |
35 |
|
| 30017 |
amit.gupta |
36 |
import java.nio.charset.StandardCharsets;
|
|
|
37 |
import java.time.LocalDateTime;
|
|
|
38 |
import java.util.*;
|
|
|
39 |
import java.util.function.Function;
|
|
|
40 |
import java.util.stream.Collectors;
|
|
|
41 |
import java.util.stream.Stream;
|
|
|
42 |
|
| 22980 |
ashik.ali |
43 |
@Component
|
|
|
44 |
public class RetailerServiceImpl implements RetailerService {
|
| 23955 |
govind |
45 |
|
| 23568 |
govind |
46 |
private static final Logger LOGGER = LogManager.getLogger(RetailerServiceImpl.class);
|
| 23955 |
govind |
47 |
|
| 22980 |
ashik.ali |
48 |
@Autowired
|
|
|
49 |
private RetailerRepository retailerRepository;
|
| 23955 |
govind |
50 |
|
| 22980 |
ashik.ali |
51 |
@Autowired
|
| 28024 |
tejbeer |
52 |
private RetailerBlockBrandsRepository retailerBlockBrandsRepository;
|
|
|
53 |
|
|
|
54 |
@Autowired
|
| 22980 |
ashik.ali |
55 |
private UserAccountRepository userAccountRepository;
|
| 23955 |
govind |
56 |
|
| 22980 |
ashik.ali |
57 |
@Autowired
|
| 28024 |
tejbeer |
58 |
private Mongo mongoClient;
|
|
|
59 |
|
|
|
60 |
@Autowired
|
| 22980 |
ashik.ali |
61 |
private UserRepository userRepository;
|
| 23955 |
govind |
62 |
|
| 22980 |
ashik.ali |
63 |
@Autowired
|
| 23043 |
ashik.ali |
64 |
private CartRepository cartRepository;
|
| 23955 |
govind |
65 |
|
| 23043 |
ashik.ali |
66 |
@Autowired
|
| 22980 |
ashik.ali |
67 |
private RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
| 23955 |
govind |
68 |
|
| 22980 |
ashik.ali |
69 |
@Autowired
|
|
|
70 |
private AddressRepository addressRepository;
|
| 23955 |
govind |
71 |
|
| 22980 |
ashik.ali |
72 |
@Autowired
|
|
|
73 |
private ShopRepository shopRepository;
|
| 23955 |
govind |
74 |
|
| 22980 |
ashik.ali |
75 |
@Autowired
|
|
|
76 |
private ShopAddressRepository shopAddressRepository;
|
| 23955 |
govind |
77 |
|
| 22980 |
ashik.ali |
78 |
@Autowired
|
|
|
79 |
private UserRoleRepository userRoleRepository;
|
| 23955 |
govind |
80 |
|
| 22980 |
ashik.ali |
81 |
@Autowired
|
|
|
82 |
private DocumentRepository documentRepository;
|
| 23955 |
govind |
83 |
|
| 23043 |
ashik.ali |
84 |
@Autowired
|
| 23329 |
ashik.ali |
85 |
private PrivateDealUserRepository privateDealUserRepository;
|
| 23955 |
govind |
86 |
|
| 23329 |
ashik.ali |
87 |
@Autowired
|
|
|
88 |
private PrivateDealUserAddressMappingRepository privateDealUserAddressMappingRepository;
|
| 23955 |
govind |
89 |
|
| 23329 |
ashik.ali |
90 |
@Autowired
|
|
|
91 |
private CounterRepository counterRepository;
|
| 25295 |
amit.gupta |
92 |
|
| 24349 |
amit.gupta |
93 |
@Autowired
|
|
|
94 |
private StateRepository stateRepository;
|
| 23955 |
govind |
95 |
|
| 23329 |
ashik.ali |
96 |
@Autowired
|
| 23043 |
ashik.ali |
97 |
@Qualifier("userUserRepository")
|
|
|
98 |
private com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
|
| 23955 |
govind |
99 |
|
| 23329 |
ashik.ali |
100 |
@Autowired
|
|
|
101 |
private DistrictMasterRepository districtMasterRepository;
|
| 23955 |
govind |
102 |
|
| 23329 |
ashik.ali |
103 |
@Autowired
|
|
|
104 |
private FofoStoreRepository fofoStoreRepository;
|
| 23955 |
govind |
105 |
|
| 23329 |
ashik.ali |
106 |
@Autowired
|
| 23365 |
ashik.ali |
107 |
private PaymentOptionRepository paymentOptionRepository;
|
| 23955 |
govind |
108 |
|
| 23365 |
ashik.ali |
109 |
@Autowired
|
|
|
110 |
private FofoPartnerPaymentOptionRepository fofoPartnerPaymentOptionRepository;
|
| 23955 |
govind |
111 |
|
| 23842 |
ashik.ali |
112 |
@Autowired
|
|
|
113 |
private RoleRepository roleRepository;
|
| 23955 |
govind |
114 |
|
| 28908 |
tejbeer |
115 |
@Autowired
|
|
|
116 |
private StoreTimelineTatService storeTimelineTatService;
|
|
|
117 |
|
|
|
118 |
@Autowired
|
|
|
119 |
private PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
|
|
|
120 |
|
| 29042 |
tejbeer |
121 |
@Autowired
|
|
|
122 |
private PartnerOnboardingVerificationRepository partnerOnboardingVerificationRepository;
|
|
|
123 |
|
| 30719 |
tejbeer |
124 |
@Autowired
|
|
|
125 |
private PincodePartnerRepository pincodePartnerRepository;
|
|
|
126 |
|
| 22980 |
ashik.ali |
127 |
@Override
|
|
|
128 |
public Map<String, Object> getByEmailIdOrMobileNumber(String emailIdOrMobileNumber)
|
|
|
129 |
throws ProfitMandiBusinessException {
|
| 23202 |
ashik.ali |
130 |
User user = null;
|
| 28024 |
tejbeer |
131 |
int fofoId = Utils.SYSTEM_PARTNER_ID;
|
|
|
132 |
|
| 23955 |
govind |
133 |
try {
|
| 23202 |
ashik.ali |
134 |
user = userRepository.selectByEmailIdOrMobileNumber(emailIdOrMobileNumber);
|
| 23955 |
govind |
135 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
136 |
|
| 23202 |
ashik.ali |
137 |
}
|
| 23955 |
govind |
138 |
if (user == null) {
|
|
|
139 |
try {
|
| 23329 |
ashik.ali |
140 |
user = userRepository.selectBySecondryEmailId(emailIdOrMobileNumber);
|
| 23955 |
govind |
141 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
142 |
|
| 23329 |
ashik.ali |
143 |
}
|
| 23202 |
ashik.ali |
144 |
}
|
| 22980 |
ashik.ali |
145 |
Map<String, Object> map = new HashMap<>();
|
| 25295 |
amit.gupta |
146 |
map.put("stateNames", stateRepository.selectAll().stream().map(x -> x.getName()).collect(Collectors.toList()));
|
| 23955 |
govind |
147 |
|
|
|
148 |
if (user != null) {
|
|
|
149 |
|
| 23329 |
ashik.ali |
150 |
List<UserRole> userRoles = userRoleRepository.selectByUserId(user.getId());
|
| 23955 |
govind |
151 |
|
| 23781 |
ashik.ali |
152 |
Role role = roleRepository.selectByName(RoleType.FOFO.toString());
|
| 23955 |
govind |
153 |
|
| 23329 |
ashik.ali |
154 |
map.put("userRoles", userRoles);
|
|
|
155 |
map.put("user", user);
|
| 23955 |
govind |
156 |
// map.put("retailer", retailer);
|
| 23781 |
ashik.ali |
157 |
map.put("fofoRole", this.containsRoleType(userRoles, role.getId()));
|
| 23955 |
govind |
158 |
|
| 23329 |
ashik.ali |
159 |
map.put("userRoleNames", this.toString(userRoles));
|
| 23955 |
govind |
160 |
try {
|
| 23329 |
ashik.ali |
161 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(user.getId());
|
|
|
162 |
Retailer retailer = retailerRepository.selectById(retailerId);
|
| 23955 |
govind |
163 |
|
| 23329 |
ashik.ali |
164 |
map.put("retailer", retailer);
|
| 23955 |
govind |
165 |
|
| 28024 |
tejbeer |
166 |
List<String> retailerBlockBrands = null;
|
|
|
167 |
Set<String> brands = null;
|
|
|
168 |
if (retailer.getId() != fofoId) {
|
|
|
169 |
brands = mongoClient.getMongoBrands(retailer.getId(), null, 3).stream()
|
|
|
170 |
.map(x -> (String) x.get("name")).collect(Collectors.toSet());
|
| 28189 |
tejbeer |
171 |
retailerBlockBrands = retailerBlockBrandsRepository.selectAllByRetailer(retailer.getId()).stream()
|
|
|
172 |
.map(x -> x.getBlockBrands()).collect(Collectors.toList());
|
|
|
173 |
|
| 28024 |
tejbeer |
174 |
LOGGER.info("loginDetailsFofoId" + retailer.getId());
|
|
|
175 |
} else {
|
|
|
176 |
LOGGER.info("fofoId" + fofoId);
|
|
|
177 |
brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
|
|
|
178 |
.collect(Collectors.toSet());
|
|
|
179 |
}
|
|
|
180 |
map.put("brands", brands);
|
|
|
181 |
map.put("retailerBlockBrands", retailerBlockBrands);
|
| 23955 |
govind |
182 |
if (this.containsRoleType(userRoles, role.getId())) {
|
|
|
183 |
try {
|
| 23329 |
ashik.ali |
184 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(retailerId);
|
|
|
185 |
map.put("fofoStore", fofoStore);
|
| 23955 |
govind |
186 |
// map.put("counterSize", fofoStore.getCounterSize().toString());
|
|
|
187 |
// LOGGER.info("fofoStore" + fofoStore);
|
|
|
188 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 23329 |
ashik.ali |
189 |
LOGGER.error("FofoStore code not found");
|
|
|
190 |
}
|
|
|
191 |
}
|
| 23955 |
govind |
192 |
|
|
|
193 |
try {
|
| 23329 |
ashik.ali |
194 |
PrivateDealUser privateDealUser = privateDealUserRepository.selectById(retailer.getId());
|
| 23955 |
govind |
195 |
if (privateDealUser.getCounterId() != null) {
|
| 23329 |
ashik.ali |
196 |
Counter counter = counterRepository.selectById(privateDealUser.getCounterId());
|
|
|
197 |
map.put("gstNumber", counter.getGstin());
|
| 23955 |
govind |
198 |
// LOGGER.info("gstNumber" + counter.getGstin());
|
| 23329 |
ashik.ali |
199 |
}
|
| 23955 |
govind |
200 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 23329 |
ashik.ali |
201 |
LOGGER.error("PrivateDealUser not found");
|
|
|
202 |
}
|
| 23955 |
govind |
203 |
try {
|
|
|
204 |
int retailerAddressId = retailerRegisteredAddressRepository
|
|
|
205 |
.selectAddressIdByRetailerId(retailer.getId());
|
| 23329 |
ashik.ali |
206 |
Address retailerAddress = addressRepository.selectById(retailerAddressId);
|
|
|
207 |
map.put("retailerAddress", retailerAddress);
|
| 24349 |
amit.gupta |
208 |
State state = stateRepository.selectByName(retailerAddress.getState());
|
| 23955 |
govind |
209 |
// LOGGER.info("retailerAddress.." + retailerAddress);
|
|
|
210 |
List<DistrictMaster> districtMasters = districtMasterRepository
|
| 24349 |
amit.gupta |
211 |
.selectByStateShortName(state.getShortName());
|
| 23329 |
ashik.ali |
212 |
map.put("districtMasters", districtMasters);
|
| 23955 |
govind |
213 |
// LOGGER.info("districtMasters" + districtMasters);
|
| 23329 |
ashik.ali |
214 |
List<Shop> shops = shopRepository.selectByRetailerId(retailer.getId());
|
| 23955 |
govind |
215 |
map.put("shops", shops);
|
| 23329 |
ashik.ali |
216 |
this.addAddress(shops);
|
| 23955 |
govind |
217 |
// LOGGER.info("shops" + shops);
|
|
|
218 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 23329 |
ashik.ali |
219 |
LOGGER.error("Retailer Registered Address not found");
|
|
|
220 |
}
|
| 23955 |
govind |
221 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 23329 |
ashik.ali |
222 |
LOGGER.error("Retailer not found in user_account");
|
| 23043 |
ashik.ali |
223 |
}
|
|
|
224 |
}
|
| 23955 |
govind |
225 |
|
| 22980 |
ashik.ali |
226 |
return map;
|
|
|
227 |
}
|
| 23955 |
govind |
228 |
|
|
|
229 |
private boolean containsRoleType(List<UserRole> userRoles, int roleId) {
|
|
|
230 |
for (UserRole userRole : userRoles) {
|
|
|
231 |
if (userRole.getRoleId() == roleId) {
|
| 23329 |
ashik.ali |
232 |
return true;
|
|
|
233 |
}
|
|
|
234 |
}
|
|
|
235 |
return false;
|
|
|
236 |
}
|
| 23955 |
govind |
237 |
|
|
|
238 |
private List<UserRole> addRole(List<UserRole> userRoles, int userId, int roleId) {
|
|
|
239 |
if (userRoles == null) {
|
| 23329 |
ashik.ali |
240 |
userRoles = new ArrayList<>();
|
|
|
241 |
}
|
| 23955 |
govind |
242 |
if (!this.containsRoleType(userRoles, roleId)) {
|
| 23329 |
ashik.ali |
243 |
UserRole userRole = new UserRole();
|
|
|
244 |
userRole.setUserId(userId);
|
| 23781 |
ashik.ali |
245 |
userRole.setRoleId(roleId);
|
| 23329 |
ashik.ali |
246 |
try {
|
|
|
247 |
userRoleRepository.persist(userRole);
|
|
|
248 |
} catch (ProfitMandiBusinessException e) {
|
|
|
249 |
LOGGER.error("UserRole is already exist");
|
|
|
250 |
}
|
|
|
251 |
userRoles.add(userRole);
|
|
|
252 |
}
|
|
|
253 |
return userRoles;
|
| 23955 |
govind |
254 |
|
| 23329 |
ashik.ali |
255 |
}
|
| 23955 |
govind |
256 |
|
| 25295 |
amit.gupta |
257 |
private List<UserRole> removeRole(List<UserRole> userRoles, int userId, int roleId) {
|
|
|
258 |
if (userRoles == null) {
|
|
|
259 |
userRoles = new ArrayList<>();
|
|
|
260 |
return userRoles;
|
|
|
261 |
}
|
|
|
262 |
try {
|
|
|
263 |
userRoles.remove(userRoleRepository.deleteByRoleUserId(userId, roleId));
|
|
|
264 |
} catch (Exception e) {
|
|
|
265 |
|
|
|
266 |
}
|
|
|
267 |
return userRoles;
|
|
|
268 |
|
|
|
269 |
}
|
|
|
270 |
|
| 22980 |
ashik.ali |
271 |
@SuppressWarnings("unchecked")
|
|
|
272 |
@Override
|
| 23025 |
ashik.ali |
273 |
public Map<String, Object> updateRetailerDetails(UpdateRetailerRequest updateRetailerRequest)
|
|
|
274 |
throws ProfitMandiBusinessException {
|
|
|
275 |
Map<String, Object> map = this.getByEmailIdOrMobileNumber(updateRetailerRequest.getEmailIdOrMobileNumber());
|
| 23955 |
govind |
276 |
User user = (User) map.get("user");
|
| 28024 |
tejbeer |
277 |
|
| 23329 |
ashik.ali |
278 |
user = this.createUser(user, updateRetailerRequest);
|
| 28024 |
tejbeer |
279 |
|
| 23329 |
ashik.ali |
280 |
map.put("user", user);
|
| 23955 |
govind |
281 |
List<UserRole> userRoles = (List<UserRole>) map.get("userRoles");
|
| 23781 |
ashik.ali |
282 |
Role roleUser = roleRepository.selectByName(RoleType.USER.toString());
|
|
|
283 |
userRoles = this.addRole(userRoles, user.getId(), roleUser.getId());
|
| 23955 |
govind |
284 |
Retailer retailer = (Retailer) map.get("retailer");
|
| 23329 |
ashik.ali |
285 |
retailer = this.updateRetailer(user, retailer, updateRetailerRequest);
|
| 28024 |
tejbeer |
286 |
|
| 23329 |
ashik.ali |
287 |
map.put("retailer", retailer);
|
| 23955 |
govind |
288 |
|
| 28189 |
tejbeer |
289 |
List<String> retailerBlockBrands = retailerBlockBrandsRepository.selectAllByRetailer(retailer.getId()).stream()
|
|
|
290 |
.map(x -> x.getBlockBrands()).collect(Collectors.toList());
|
| 28024 |
tejbeer |
291 |
|
| 28189 |
tejbeer |
292 |
LOGGER.info("retailerBlockBrands" + retailerBlockBrands);
|
|
|
293 |
|
| 28024 |
tejbeer |
294 |
if (!retailerBlockBrands.isEmpty()) {
|
|
|
295 |
retailerBlockBrandsRepository.deleteBrands(retailer.getId());
|
|
|
296 |
}
|
|
|
297 |
|
|
|
298 |
for (String blockBrand : updateRetailerRequest.getBlocksBrands()) {
|
|
|
299 |
RetailerBlockBrands retailerBlockBrand = new RetailerBlockBrands();
|
|
|
300 |
|
|
|
301 |
retailerBlockBrand.setFofoId(retailer.getId());
|
|
|
302 |
retailerBlockBrand.setBlockBrands(blockBrand);
|
|
|
303 |
retailerBlockBrandsRepository.persist(retailerBlockBrand);
|
|
|
304 |
|
|
|
305 |
}
|
|
|
306 |
map.put("retailerBlockBrands", retailerBlockBrands);
|
|
|
307 |
|
| 23781 |
ashik.ali |
308 |
Role roleRetailer = roleRepository.selectByName(RoleType.RETAILER.toString());
|
| 23955 |
govind |
309 |
|
| 23781 |
ashik.ali |
310 |
userRoles = this.addRole(userRoles, user.getId(), roleRetailer.getId());
|
| 23955 |
govind |
311 |
|
| 23781 |
ashik.ali |
312 |
Role roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
|
| 23955 |
govind |
313 |
|
|
|
314 |
if (updateRetailerRequest.isFofo()) {
|
| 23781 |
ashik.ali |
315 |
userRoles = this.addRole(userRoles, user.getId(), roleFofo.getId());
|
| 25295 |
amit.gupta |
316 |
} else {
|
|
|
317 |
userRoles = this.removeRole(userRoles, user.getId(), roleFofo.getId());
|
| 23061 |
ashik.ali |
318 |
}
|
| 25295 |
amit.gupta |
319 |
map.put("fofoRole", this.containsRoleType(userRoles, roleFofo.getId()));
|
| 23955 |
govind |
320 |
|
|
|
321 |
if (this.containsRoleType(userRoles, roleFofo.getId())) {
|
| 23365 |
ashik.ali |
322 |
this.createDefaultPaymentOption(retailer.getId());
|
| 23329 |
ashik.ali |
323 |
}
|
| 23955 |
govind |
324 |
|
| 23329 |
ashik.ali |
325 |
map.put("userRoles", userRoles);
|
|
|
326 |
map.put("userRoleNames", this.toString(userRoles));
|
| 23955 |
govind |
327 |
|
|
|
328 |
Address retailerAddress = (Address) map.get("retailerAddress");
|
|
|
329 |
retailerAddress = this.updateRetailerAddress(retailerAddress, updateRetailerRequest.getAddress(),
|
|
|
330 |
retailer.getId());
|
| 23329 |
ashik.ali |
331 |
map.put("retailerAddress", retailerAddress);
|
| 23955 |
govind |
332 |
|
|
|
333 |
if (updateRetailerRequest.isFofo()) {
|
|
|
334 |
FofoStore fofoStore = this.createFofoStoreCodeByRetailerId(retailer.getId(),
|
|
|
335 |
updateRetailerRequest.getDistrictName(), retailerAddress.getState(), updateRetailerRequest);
|
| 23378 |
ashik.ali |
336 |
map.put("fofoStore", fofoStore);
|
| 25297 |
amit.gupta |
337 |
fofoStore.setActive(updateRetailerRequest.isActive());
|
| 23061 |
ashik.ali |
338 |
}
|
| 23955 |
govind |
339 |
|
|
|
340 |
this.createPrivateDealUser(user, updateRetailerRequest.isFofo(), updateRetailerRequest.getGstNumber(), retailer,
|
|
|
341 |
retailerAddress.getId());
|
| 23329 |
ashik.ali |
342 |
map.put("gstNumber", updateRetailerRequest.getGstNumber());
|
|
|
343 |
this.updateSaholicUser(retailer.getId(), retailerAddress.getId());
|
| 23955 |
govind |
344 |
|
|
|
345 |
List<Shop> shops = (List<Shop>) map.get("shops");
|
|
|
346 |
if (shops == null) {
|
| 23060 |
ashik.ali |
347 |
shops = new ArrayList<>();
|
| 23061 |
ashik.ali |
348 |
map.put("shops", shops);
|
| 23060 |
ashik.ali |
349 |
}
|
| 23079 |
ashik.ali |
350 |
this.updateRetailerShops(shops, updateRetailerRequest.getShops(), retailer.getId(), retailerAddress);
|
| 23955 |
govind |
351 |
|
| 23025 |
ashik.ali |
352 |
return map;
|
| 23955 |
govind |
353 |
|
| 23025 |
ashik.ali |
354 |
}
|
| 23955 |
govind |
355 |
|
|
|
356 |
private void createDefaultPaymentOption(int fofoId) {
|
| 23365 |
ashik.ali |
357 |
List<Integer> paymentOptionIds = fofoPartnerPaymentOptionRepository.selectPaymentOptionIdsByFofoId(fofoId);
|
| 23955 |
govind |
358 |
if (paymentOptionIds.isEmpty()) {
|
| 23365 |
ashik.ali |
359 |
PaymentOption paymentOption = null;
|
| 23955 |
govind |
360 |
try {
|
| 23365 |
ashik.ali |
361 |
paymentOption = paymentOptionRepository.selectByName(PaymentOptionType.CASH.toString());
|
| 23955 |
govind |
362 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 23365 |
ashik.ali |
363 |
paymentOption = new PaymentOption();
|
|
|
364 |
paymentOption.setName(PaymentOptionType.CASH.toString());
|
|
|
365 |
paymentOptionRepository.persist(paymentOption);
|
|
|
366 |
}
|
|
|
367 |
FofoPartnerPaymentOption fofoPartnerPaymentOption = new FofoPartnerPaymentOption();
|
|
|
368 |
fofoPartnerPaymentOption.setFofoId(fofoId);
|
|
|
369 |
fofoPartnerPaymentOption.setPaymentOptionId(paymentOption.getId());
|
|
|
370 |
fofoPartnerPaymentOptionRepository.persist(fofoPartnerPaymentOption);
|
|
|
371 |
}
|
| 23955 |
govind |
372 |
|
| 23365 |
ashik.ali |
373 |
}
|
| 23955 |
govind |
374 |
|
|
|
375 |
private User createUser(User user, UpdateRetailerRequest updateRetailerRequest) {
|
|
|
376 |
if (user == null) {
|
| 23329 |
ashik.ali |
377 |
user = new User();
|
|
|
378 |
user.setCity("");
|
|
|
379 |
user.setPinCode(0);
|
|
|
380 |
user.setState("");
|
|
|
381 |
user.setPassword("");
|
|
|
382 |
user.setMobile_verified(false);
|
|
|
383 |
user.setReferral_url("");
|
|
|
384 |
user.setGroup_id(1);
|
|
|
385 |
user.setStatus(1);
|
|
|
386 |
user.setActivated(true);
|
|
|
387 |
user.setCreateTimestamp(LocalDateTime.now());
|
|
|
388 |
}
|
| 24705 |
amit.gupta |
389 |
user.setActivated(updateRetailerRequest.isActive());
|
| 23329 |
ashik.ali |
390 |
user.setFirstName(updateRetailerRequest.getUserFirstName());
|
|
|
391 |
user.setLastName(updateRetailerRequest.getUserLastName());
|
|
|
392 |
user.setMobileNumber(updateRetailerRequest.getUserMobileNumber());
|
|
|
393 |
user.setEmailId(updateRetailerRequest.getUserEmailId());
|
|
|
394 |
user.setUsername(updateRetailerRequest.getUserEmailId());
|
| 23509 |
amit.gupta |
395 |
user.setUpdateTimestamp(LocalDateTime.now());
|
|
|
396 |
userRepository.persist(user);
|
| 23329 |
ashik.ali |
397 |
return user;
|
| 23955 |
govind |
398 |
|
| 23329 |
ashik.ali |
399 |
}
|
| 23955 |
govind |
400 |
|
|
|
401 |
private int createSaholicUser(User user, String retailerName) {
|
| 23043 |
ashik.ali |
402 |
com.spice.profitmandi.dao.entity.user.User saholicUser = null;
|
|
|
403 |
try {
|
| 23063 |
ashik.ali |
404 |
saholicUser = userUserRepository.selectByEmailId(user.getEmailId());
|
| 23955 |
govind |
405 |
} catch (ProfitMandiBusinessException e) {
|
| 23043 |
ashik.ali |
406 |
LOGGER.info("User doesnt exist in old system");
|
|
|
407 |
}
|
| 23955 |
govind |
408 |
if (saholicUser == null) {
|
| 23043 |
ashik.ali |
409 |
Cart cart = new Cart();
|
|
|
410 |
cart.setCartStatus(CartStatus.ACTIVE);
|
|
|
411 |
cartRepository.persist(cart);
|
|
|
412 |
saholicUser = new com.spice.profitmandi.dao.entity.user.User();
|
| 23063 |
ashik.ali |
413 |
saholicUser.setEmailId(user.getEmailId());
|
| 23043 |
ashik.ali |
414 |
saholicUser.setName(retailerName);
|
|
|
415 |
saholicUser.setActiveCartId(cart.getId());
|
| 23300 |
amit.gupta |
416 |
saholicUser.setCreateTimestamp(LocalDateTime.now());
|
| 23043 |
ashik.ali |
417 |
userUserRepository.persist(saholicUser);
|
| 23955 |
govind |
418 |
|
| 23269 |
ashik.ali |
419 |
UserAccount ua = new UserAccount();
|
|
|
420 |
ua.setAccountKey(saholicUser.getId());
|
|
|
421 |
ua.setUserId(user.getId());
|
|
|
422 |
ua.setType(AccountType.saholic);
|
| 23063 |
ashik.ali |
423 |
userAccountRepository.persist(ua);
|
|
|
424 |
|
| 23269 |
ashik.ali |
425 |
UserAccount ua2 = new UserAccount();
|
|
|
426 |
ua2.setAccountKey(saholicUser.getActiveCartId());
|
|
|
427 |
ua2.setUserId(user.getId());
|
|
|
428 |
ua2.setType(AccountType.cartId);
|
| 23063 |
ashik.ali |
429 |
userAccountRepository.persist(ua2);
|
| 23955 |
govind |
430 |
LOGGER.info("created....");
|
| 23043 |
ashik.ali |
431 |
}
|
|
|
432 |
return saholicUser.getId();
|
|
|
433 |
}
|
| 23955 |
govind |
434 |
|
| 26522 |
amit.gupta |
435 |
private com.spice.profitmandi.dao.entity.user.User createSaholicUser(
|
|
|
436 |
LoginRequestResponseModel loginRequestResponseModel) {
|
|
|
437 |
com.spice.profitmandi.dao.entity.user.User saholicUser = null;
|
|
|
438 |
try {
|
|
|
439 |
saholicUser = userUserRepository.selectByEmailId(loginRequestResponseModel.getEmail());
|
| 28198 |
tejbeer |
440 |
saholicUser.setCreateTimestamp(LocalDateTime.now());
|
| 26522 |
amit.gupta |
441 |
} catch (ProfitMandiBusinessException e) {
|
|
|
442 |
LOGGER.info("User doesnt exist in old system");
|
|
|
443 |
}
|
|
|
444 |
if (saholicUser == null) {
|
|
|
445 |
Cart cart = new Cart();
|
|
|
446 |
cart.setCartStatus(CartStatus.ACTIVE);
|
|
|
447 |
cartRepository.persist(cart);
|
|
|
448 |
saholicUser = new com.spice.profitmandi.dao.entity.user.User();
|
| 26528 |
amit.gupta |
449 |
saholicUser.setPassword(getHash256(loginRequestResponseModel.getPassword()));
|
| 26522 |
amit.gupta |
450 |
saholicUser.setEmailId(loginRequestResponseModel.getEmail());
|
|
|
451 |
saholicUser.setName(loginRequestResponseModel.getCustomerName());
|
|
|
452 |
saholicUser.setActiveCartId(cart.getId());
|
|
|
453 |
saholicUser.setCreateTimestamp(LocalDateTime.now());
|
|
|
454 |
loginRequestResponseModel.setPassword(null);
|
|
|
455 |
userUserRepository.persist(saholicUser);
|
|
|
456 |
}
|
|
|
457 |
return saholicUser;
|
|
|
458 |
}
|
|
|
459 |
|
| 23955 |
govind |
460 |
private Retailer updateRetailer(User user, Retailer retailer, UpdateRetailerRequest updateRetailerRequest)
|
|
|
461 |
throws ProfitMandiBusinessException {
|
|
|
462 |
if (retailer == null) {
|
|
|
463 |
LOGGER.info("createSaholicUser.....");
|
| 23063 |
ashik.ali |
464 |
int saholicUserId = this.createSaholicUser(user, updateRetailerRequest.getName());
|
| 23043 |
ashik.ali |
465 |
retailer = new Retailer();
|
|
|
466 |
retailer.setId(saholicUserId);
|
|
|
467 |
}
|
| 23329 |
ashik.ali |
468 |
retailer.setActive(updateRetailerRequest.isActive());
|
| 24704 |
amit.gupta |
469 |
user.setActivated(updateRetailerRequest.isActive());//
|
| 23955 |
govind |
470 |
// this.createRole(user.getId(), RoleType.RETAILER);
|
| 23025 |
ashik.ali |
471 |
retailer.setName(updateRetailerRequest.getName());
|
|
|
472 |
retailer.setNumber(updateRetailerRequest.getNumber());
|
| 23955 |
govind |
473 |
if (updateRetailerRequest.getNumber() == null || updateRetailerRequest.getNumber().isEmpty()) {
|
| 23107 |
ashik.ali |
474 |
retailer.setType(RetailerType.UNREGISTERED_SHOP);
|
| 23955 |
govind |
475 |
} else {
|
| 23107 |
ashik.ali |
476 |
retailer.setType(RetailerType.GSTIN);
|
|
|
477 |
}
|
| 23955 |
govind |
478 |
if (updateRetailerRequest.getDocumentId() > 0) {
|
|
|
479 |
if (retailer.getDocumentId() != null && retailer.getDocumentId() != updateRetailerRequest.getDocumentId()) {
|
| 24374 |
amit.gupta |
480 |
try {
|
|
|
481 |
documentRepository.deleteById(retailer.getDocumentId());
|
| 25295 |
amit.gupta |
482 |
} catch (Exception e) {
|
| 24374 |
amit.gupta |
483 |
e.printStackTrace();
|
|
|
484 |
}
|
| 23489 |
ashik.ali |
485 |
}
|
| 23497 |
ashik.ali |
486 |
retailer.setDocumentId(updateRetailerRequest.getDocumentId());
|
|
|
487 |
documentRepository.markDocumentAsPersisted(updateRetailerRequest.getDocumentId());
|
| 23025 |
ashik.ali |
488 |
}
|
|
|
489 |
retailerRepository.persist(retailer);
|
| 23059 |
ashik.ali |
490 |
return retailer;
|
| 23025 |
ashik.ali |
491 |
}
|
| 23955 |
govind |
492 |
|
|
|
493 |
private void updateSaholicUser(int retailerId, int retailerAddressId) {
|
| 23329 |
ashik.ali |
494 |
try {
|
|
|
495 |
com.spice.profitmandi.dao.entity.user.User user = userUserRepository.selectById(retailerId);
|
|
|
496 |
user.setAddressId(retailerAddressId);
|
|
|
497 |
} catch (ProfitMandiBusinessException e) {
|
| 23955 |
govind |
498 |
|
| 23329 |
ashik.ali |
499 |
}
|
|
|
500 |
}
|
| 23955 |
govind |
501 |
|
|
|
502 |
private void createPrivateDealUser(User user, boolean fofo, String gstNumber, Retailer retailer,
|
|
|
503 |
int retailerAddressId) {
|
| 23329 |
ashik.ali |
504 |
PrivateDealUser privateDealUser = null;
|
| 23955 |
govind |
505 |
try {
|
| 23329 |
ashik.ali |
506 |
privateDealUser = privateDealUserRepository.selectById(retailer.getId());
|
| 23955 |
govind |
507 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 23329 |
ashik.ali |
508 |
LOGGER.error("PrivateDealUser not found");
|
|
|
509 |
}
|
| 23955 |
govind |
510 |
|
|
|
511 |
// = privateDealUserRepository.selectById(saholicUser.getId());
|
|
|
512 |
if (privateDealUser == null) {
|
|
|
513 |
Integer counterId = this.createCounter(user.getEmailId(), gstNumber, user.getMobileNumber(),
|
|
|
514 |
retailer.getName(), retailerAddressId);
|
| 23473 |
ashik.ali |
515 |
try {
|
|
|
516 |
this.createPrivateDealUser(retailer.getId(), counterId, fofo);
|
| 23955 |
govind |
517 |
} catch (Exception e) {
|
| 23473 |
ashik.ali |
518 |
LOGGER.error("ERROR : ", e);
|
|
|
519 |
}
|
| 23955 |
govind |
520 |
} else {
|
|
|
521 |
if (privateDealUser.getCounterId() == null) {
|
|
|
522 |
Integer counterId = this.createCounter(user.getEmailId(), gstNumber, user.getMobileNumber(),
|
|
|
523 |
retailer.getName(), retailerAddressId);
|
| 23329 |
ashik.ali |
524 |
privateDealUser.setCounterId(counterId);
|
|
|
525 |
privateDealUser.setFofo(fofo);
|
|
|
526 |
privateDealUserRepository.persist(privateDealUser);
|
| 23955 |
govind |
527 |
} else {
|
| 23329 |
ashik.ali |
528 |
Counter counter = null;
|
| 23955 |
govind |
529 |
try {
|
| 23329 |
ashik.ali |
530 |
counter = counterRepository.selectById(privateDealUser.getCounterId());
|
| 23955 |
govind |
531 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 23329 |
ashik.ali |
532 |
LOGGER.error("Counter not found with id [{}]", privateDealUser.getCounterId());
|
|
|
533 |
}
|
| 23955 |
govind |
534 |
if (counter == null) {
|
|
|
535 |
this.createCounter(user.getEmailId(), gstNumber, user.getMobileNumber(), retailer.getName(),
|
|
|
536 |
retailerAddressId);
|
|
|
537 |
} else {
|
| 23329 |
ashik.ali |
538 |
counter.setGstin(gstNumber);
|
|
|
539 |
counterRepository.persist(counter);
|
|
|
540 |
}
|
|
|
541 |
privateDealUser.setFofo(fofo);
|
|
|
542 |
privateDealUserRepository.persist(privateDealUser);
|
|
|
543 |
}
|
|
|
544 |
}
|
| 23955 |
govind |
545 |
|
| 23329 |
ashik.ali |
546 |
PrivateDealUserAddressMapping privateDealUserAddressMapping = new PrivateDealUserAddressMapping();
|
|
|
547 |
privateDealUserAddressMapping.setUserId(retailer.getId());
|
|
|
548 |
privateDealUserAddressMapping.setAddressId(retailerAddressId);
|
|
|
549 |
privateDealUserAddressMappingRepository.persist(privateDealUserAddressMapping);
|
|
|
550 |
}
|
| 23955 |
govind |
551 |
|
|
|
552 |
// Specifically set isFofo to true that has to be used by old system
|
|
|
553 |
private void createPrivateDealUser(int retailerId, int counterId, boolean fofo) {
|
| 23329 |
ashik.ali |
554 |
PrivateDealUser privateDealUser = new PrivateDealUser();
|
|
|
555 |
privateDealUser.setActive(true);
|
|
|
556 |
privateDealUser.setBulkShipmentAmountLimit(fofo ? 1000000 : 50000);
|
|
|
557 |
privateDealUser.setId(retailerId);
|
|
|
558 |
privateDealUser.setCounterId(counterId);
|
|
|
559 |
privateDealUser.setFofo(fofo);
|
|
|
560 |
privateDealUserRepository.persist(privateDealUser);
|
|
|
561 |
}
|
| 23955 |
govind |
562 |
|
|
|
563 |
private Integer createCounter(String emailId, String gstNumber, String mobileNumber, String name, int addressId) {
|
|
|
564 |
if (gstNumber != null && !gstNumber.isEmpty()) {
|
| 23329 |
ashik.ali |
565 |
Counter counter = new Counter();
|
|
|
566 |
counter.setEmailId(emailId);
|
|
|
567 |
counter.setGstin(gstNumber);
|
|
|
568 |
counter.setMobileNumber(mobileNumber);
|
|
|
569 |
counter.setName(name);
|
|
|
570 |
counter.setAddressId(addressId);
|
|
|
571 |
counterRepository.persist(counter);
|
|
|
572 |
return counter.getId();
|
| 23955 |
govind |
573 |
} else {
|
| 23329 |
ashik.ali |
574 |
return null;
|
|
|
575 |
}
|
|
|
576 |
}
|
| 23955 |
govind |
577 |
|
|
|
578 |
private Address updateRetailerAddress(Address address, CustomAddress customAddress, int retailerId)
|
|
|
579 |
throws ProfitMandiBusinessException {
|
|
|
580 |
if (address == null) {
|
| 23043 |
ashik.ali |
581 |
address = new Address();
|
|
|
582 |
address.setRetaierId(retailerId);
|
|
|
583 |
this.updateAddress(address, customAddress);
|
| 23955 |
govind |
584 |
// addressRepository.persist(addressRetailer);
|
|
|
585 |
|
| 23043 |
ashik.ali |
586 |
final RetailerRegisteredAddress retailerRegisteredAddress = new RetailerRegisteredAddress();
|
|
|
587 |
retailerRegisteredAddress.setRetailerId(retailerId);
|
|
|
588 |
retailerRegisteredAddress.setAddressId(address.getId());
|
|
|
589 |
retailerRegisteredAddressRepository.persist(retailerRegisteredAddress);
|
| 23955 |
govind |
590 |
} else {
|
|
|
591 |
this.updateAddress(address, customAddress);
|
|
|
592 |
RetailerRegisteredAddress retailerRegisteredAddress = retailerRegisteredAddressRepository
|
|
|
593 |
.selectByRetailerId(retailerId);
|
|
|
594 |
retailerRegisteredAddress.setAddressId(address.getId());
|
|
|
595 |
retailerRegisteredAddressRepository.persist(retailerRegisteredAddress);
|
| 23043 |
ashik.ali |
596 |
}
|
| 23059 |
ashik.ali |
597 |
return address;
|
| 23043 |
ashik.ali |
598 |
}
|
| 23955 |
govind |
599 |
|
| 27411 |
amit.gupta |
600 |
private void updateAddress(Address address, CustomAddress customAddress) throws ProfitMandiBusinessException {
|
| 23025 |
ashik.ali |
601 |
address.setName(customAddress.getName());
|
| 23829 |
amit.gupta |
602 |
address.setPhoneNumber(customAddress.getPhoneNumber());
|
| 23025 |
ashik.ali |
603 |
address.setLine1(customAddress.getLine1());
|
|
|
604 |
address.setLine2(customAddress.getLine2());
|
|
|
605 |
address.setCity(customAddress.getCity());
|
|
|
606 |
address.setPinCode(customAddress.getPinCode());
|
| 27411 |
amit.gupta |
607 |
State state = stateRepository.selectByName(customAddress.getState());
|
| 27877 |
amit.gupta |
608 |
if (state == null) {
|
|
|
609 |
throw new ProfitMandiBusinessException("State name", "Invalid State - Pls Contact Technology",
|
|
|
610 |
"Invalid State - Pls Contact Technology");
|
| 27411 |
amit.gupta |
611 |
}
|
|
|
612 |
address.setState(state.getName());
|
| 23025 |
ashik.ali |
613 |
addressRepository.persist(address);
|
| 23955 |
govind |
614 |
LOGGER.info("Address Updated" + address);
|
| 23025 |
ashik.ali |
615 |
}
|
| 23955 |
govind |
616 |
|
|
|
617 |
private void updateRetailerShops(List<Shop> shops, Set<CustomShop> customShops, int retailerId,
|
|
|
618 |
Address sameAsRetailerAddressValue) throws ProfitMandiBusinessException {
|
|
|
619 |
if (shops.isEmpty()) {
|
|
|
620 |
for (CustomShop customShop : customShops) {
|
| 23043 |
ashik.ali |
621 |
Shop shop = new Shop();
|
| 23079 |
ashik.ali |
622 |
this.createOrUpdateShop(shop, customShop, retailerId, sameAsRetailerAddressValue);
|
| 23043 |
ashik.ali |
623 |
shops.add(shop);
|
|
|
624 |
}
|
| 23955 |
govind |
625 |
} else {
|
|
|
626 |
for (Shop shop : shops) {
|
|
|
627 |
for (CustomShop customShop : customShops) {
|
|
|
628 |
if (shop.getId() == customShop.getShopId()) {
|
| 23079 |
ashik.ali |
629 |
this.createOrUpdateShop(shop, customShop, retailerId, sameAsRetailerAddressValue);
|
| 23025 |
ashik.ali |
630 |
}
|
|
|
631 |
}
|
|
|
632 |
}
|
| 23955 |
govind |
633 |
for (CustomShop customShop : customShops) {
|
|
|
634 |
if (customShop.getShopId() == 0) {
|
| 23043 |
ashik.ali |
635 |
Shop shop = new Shop();
|
| 23079 |
ashik.ali |
636 |
this.createOrUpdateShop(shop, customShop, retailerId, sameAsRetailerAddressValue);
|
| 23043 |
ashik.ali |
637 |
shops.add(shop);
|
|
|
638 |
}
|
|
|
639 |
}
|
| 23025 |
ashik.ali |
640 |
}
|
|
|
641 |
}
|
| 23955 |
govind |
642 |
|
|
|
643 |
private void createOrUpdateShop(Shop shop, CustomShop customShop, int retailerId,
|
|
|
644 |
Address sameAsRetailerAddressValue) throws ProfitMandiBusinessException {
|
| 23043 |
ashik.ali |
645 |
shop.setRetailerId(retailerId);
|
|
|
646 |
shop.setName(customShop.getName());
|
| 23955 |
govind |
647 |
if (customShop.getDocumentId() > 0) {
|
|
|
648 |
if (shop.getDocumentId() != null && shop.getDocumentId() != customShop.getDocumentId()) {
|
| 24374 |
amit.gupta |
649 |
try {
|
|
|
650 |
documentRepository.deleteById(shop.getDocumentId());
|
| 25295 |
amit.gupta |
651 |
} catch (Exception e) {
|
| 24374 |
amit.gupta |
652 |
e.printStackTrace();
|
|
|
653 |
}
|
| 23489 |
ashik.ali |
654 |
}
|
| 23497 |
ashik.ali |
655 |
shop.setDocumentId(customShop.getDocumentId());
|
|
|
656 |
documentRepository.markDocumentAsPersisted(customShop.getDocumentId());
|
| 23043 |
ashik.ali |
657 |
}
|
| 23955 |
govind |
658 |
if (shop.getAddressId() == null) {
|
| 23079 |
ashik.ali |
659 |
Address address = null;
|
| 23955 |
govind |
660 |
if (customShop.isSameAsRetailerAddress()) {
|
| 23079 |
ashik.ali |
661 |
address = sameAsRetailerAddressValue;
|
| 23955 |
govind |
662 |
} else {
|
|
|
663 |
// shop.setDocumentId(customShop.getDocumentId());
|
| 23079 |
ashik.ali |
664 |
address = new Address();
|
|
|
665 |
this.updateAddress(address, customShop.getAddress());
|
|
|
666 |
}
|
| 23043 |
ashik.ali |
667 |
shop.setAddressId(address.getId());
|
|
|
668 |
shop.setAddress(address);
|
|
|
669 |
shopRepository.persist(shop);
|
| 23131 |
ashik.ali |
670 |
ShopAddress shopAddress = null;
|
| 23955 |
govind |
671 |
try {
|
| 23131 |
ashik.ali |
672 |
shopAddress = shopAddressRepository.selectByShopId(shop.getId());
|
|
|
673 |
shopAddress.setAddressId(address.getId());
|
| 23955 |
govind |
674 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 23131 |
ashik.ali |
675 |
shopAddress = new ShopAddress();
|
|
|
676 |
shopAddress.setAddressId(address.getId());
|
|
|
677 |
shopAddress.setShopId(shop.getId());
|
|
|
678 |
}
|
| 23043 |
ashik.ali |
679 |
shopAddressRepository.persist(shopAddress);
|
| 23955 |
govind |
680 |
} else {
|
| 24375 |
amit.gupta |
681 |
Address address = null;
|
|
|
682 |
try {
|
|
|
683 |
address = addressRepository.selectById(shop.getAddressId());
|
|
|
684 |
CustomAddress customAddress = customShop.getAddress();
|
|
|
685 |
if (!(address.getName().equals(customAddress.getName())
|
|
|
686 |
&& address.getLine1().equals(customAddress.getLine1())
|
|
|
687 |
&& address.getLine2().equals(customAddress.getLine2())
|
|
|
688 |
&& address.getCity().equals(customAddress.getCity())
|
|
|
689 |
&& address.getPinCode().equals(customAddress.getPinCode())
|
|
|
690 |
&& address.getState().equals(customAddress.getState()))) {
|
|
|
691 |
address = new Address();
|
|
|
692 |
ShopAddress shopAddress = shopAddressRepository.selectByShopId(shop.getId());
|
|
|
693 |
this.updateAddress(address, customAddress);
|
|
|
694 |
shopAddress.setAddressId(address.getId());
|
|
|
695 |
shopAddressRepository.persist(shopAddress);
|
|
|
696 |
shop.setAddress(address);
|
|
|
697 |
shopRepository.persist(shop);
|
|
|
698 |
}
|
| 25295 |
amit.gupta |
699 |
} catch (Exception e) {
|
| 24375 |
amit.gupta |
700 |
if (customShop.isSameAsRetailerAddress()) {
|
|
|
701 |
address = sameAsRetailerAddressValue;
|
|
|
702 |
} else {
|
|
|
703 |
// shop.setDocumentId(customShop.getDocumentId());
|
|
|
704 |
address = new Address();
|
|
|
705 |
this.updateAddress(address, customShop.getAddress());
|
|
|
706 |
}
|
|
|
707 |
shop.setAddressId(address.getId());
|
|
|
708 |
shop.setAddress(address);
|
|
|
709 |
shopRepository.persist(shop);
|
|
|
710 |
ShopAddress shopAddress = null;
|
|
|
711 |
try {
|
|
|
712 |
shopAddress = shopAddressRepository.selectByShopId(shop.getId());
|
|
|
713 |
shopAddress.setAddressId(address.getId());
|
|
|
714 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
715 |
shopAddress = new ShopAddress();
|
|
|
716 |
shopAddress.setAddressId(address.getId());
|
|
|
717 |
shopAddress.setShopId(shop.getId());
|
|
|
718 |
}
|
| 25295 |
amit.gupta |
719 |
shopAddressRepository.persist(shopAddress);
|
|
|
720 |
}
|
| 23955 |
govind |
721 |
|
| 23043 |
ashik.ali |
722 |
}
|
| 23955 |
govind |
723 |
|
| 23043 |
ashik.ali |
724 |
}
|
| 23955 |
govind |
725 |
|
|
|
726 |
private void addAddress(List<Shop> shops) {
|
| 22980 |
ashik.ali |
727 |
Set<Integer> shopIds = this.toShopIds(shops);
|
| 23955 |
govind |
728 |
if (shopIds.isEmpty()) {
|
| 22980 |
ashik.ali |
729 |
return;
|
|
|
730 |
}
|
|
|
731 |
List<ShopAddress> shopAddresses = shopAddressRepository.selectByShopIds(shopIds);
|
|
|
732 |
Map<Integer, Address> addressIdAddressMap = this.toAddressIdAddressMap(shopAddresses);
|
| 23955 |
govind |
733 |
|
|
|
734 |
for (Shop shop : shops) {
|
| 22980 |
ashik.ali |
735 |
shop.setAddress(addressIdAddressMap.get(shop.getAddressId()));
|
|
|
736 |
}
|
|
|
737 |
}
|
|
|
738 |
|
| 23955 |
govind |
739 |
private Map<Integer, Address> toAddressIdAddressMap(List<ShopAddress> shopAddresses) {
|
| 22980 |
ashik.ali |
740 |
Map<Integer, Address> addressIdAddressMap = new HashMap<>();
|
|
|
741 |
List<Integer> addressIds = this.toAddressIds(shopAddresses);
|
|
|
742 |
List<Address> addresses = addressRepository.selectByIds(addressIds);
|
| 23955 |
govind |
743 |
for (Address address : addresses) {
|
| 22980 |
ashik.ali |
744 |
addressIdAddressMap.put(address.getId(), address);
|
|
|
745 |
}
|
|
|
746 |
return addressIdAddressMap;
|
|
|
747 |
}
|
| 23955 |
govind |
748 |
|
|
|
749 |
private List<Integer> toAddressIds(List<ShopAddress> shopAddresses) {
|
|
|
750 |
Function<ShopAddress, Integer> shopAddressToAddressIdFunction = new Function<ShopAddress, Integer>() {
|
| 22980 |
ashik.ali |
751 |
@Override
|
|
|
752 |
public Integer apply(ShopAddress shopAddress) {
|
|
|
753 |
return shopAddress.getAddressId();
|
|
|
754 |
}
|
|
|
755 |
};
|
|
|
756 |
return shopAddresses.stream().map(shopAddressToAddressIdFunction).collect(Collectors.toList());
|
|
|
757 |
}
|
| 23955 |
govind |
758 |
|
|
|
759 |
private Set<Integer> toShopIds(List<Shop> shops) {
|
|
|
760 |
Function<Shop, Integer> shopToAddressIdFunction = new Function<Shop, Integer>() {
|
| 22980 |
ashik.ali |
761 |
@Override
|
|
|
762 |
public Integer apply(Shop shop) {
|
|
|
763 |
return shop.getId();
|
|
|
764 |
}
|
|
|
765 |
};
|
|
|
766 |
return shops.stream().map(shopToAddressIdFunction).collect(Collectors.toSet());
|
|
|
767 |
}
|
| 23955 |
govind |
768 |
|
|
|
769 |
private String toString(List<UserRole> userRoles) {
|
| 23781 |
ashik.ali |
770 |
Set<Integer> roleIds = new HashSet<>();
|
| 23955 |
govind |
771 |
for (UserRole userRole : userRoles) {
|
| 23781 |
ashik.ali |
772 |
roleIds.add(userRole.getRoleId());
|
|
|
773 |
}
|
|
|
774 |
List<Role> roles = roleRepository.selectByIds(roleIds);
|
| 23955 |
govind |
775 |
Function<Role, String> roleToNameFunction = new Function<Role, String>() {
|
| 23781 |
ashik.ali |
776 |
public String apply(Role role) {
|
|
|
777 |
return String.valueOf(role.getName());
|
| 22980 |
ashik.ali |
778 |
};
|
|
|
779 |
};
|
| 23781 |
ashik.ali |
780 |
Set<String> userRoleStrings = roles.stream().map(roleToNameFunction).collect(Collectors.toSet());
|
| 22980 |
ashik.ali |
781 |
return String.join(", ", userRoleStrings);
|
|
|
782 |
}
|
| 23955 |
govind |
783 |
|
|
|
784 |
private FofoStore createFofoStoreCodeByRetailerId(int retailerId, String districtName, String stateName,
|
|
|
785 |
UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException {
|
| 23378 |
ashik.ali |
786 |
FofoStore fofoStore = null;
|
| 23955 |
govind |
787 |
try {
|
| 23378 |
ashik.ali |
788 |
fofoStore = fofoStoreRepository.selectByRetailerId(retailerId);
|
| 30097 |
tejbeer |
789 |
fofoStore.setActivationType(ActivationType.ACTIVE);
|
|
|
790 |
|
| 23955 |
govind |
791 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
792 |
|
| 23378 |
ashik.ali |
793 |
}
|
| 23955 |
govind |
794 |
|
|
|
795 |
if (fofoStore != null) {
|
|
|
796 |
fofoStore.setCounterSize(updateRetailerRequest.getCountersize());
|
|
|
797 |
fofoStore.setMinimumInvestment(updateRetailerRequest.getMinInvestment());
|
| 26209 |
tejbeer |
798 |
fofoStore.setWarehouseId(updateRetailerRequest.getWarehouseId());
|
| 28825 |
tejbeer |
799 |
fofoStore.setFofoType(updateRetailerRequest.getFofoType());
|
| 23955 |
govind |
800 |
|
|
|
801 |
} else {
|
| 23378 |
ashik.ali |
802 |
int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId);
|
|
|
803 |
Address retailerAddress = addressRepository.selectById(retailerAddressId);
|
| 23955 |
govind |
804 |
|
| 30527 |
tejbeer |
805 |
// StateInfo stateInfo = null;
|
|
|
806 |
State stateInfo = null;
|
| 23378 |
ashik.ali |
807 |
try {
|
| 30527 |
tejbeer |
808 |
|
|
|
809 |
stateInfo = stateRepository.selectByName(retailerAddress.getState());
|
|
|
810 |
// stateInfo = Utils.getStateInfo(retailerAddress.getState());
|
| 23378 |
ashik.ali |
811 |
} catch (Exception e) {
|
|
|
812 |
// TODO Auto-generated catch block
|
|
|
813 |
e.printStackTrace();
|
| 23955 |
govind |
814 |
// throw new ProfitMandiBusinessException();
|
| 23378 |
ashik.ali |
815 |
}
|
| 23955 |
govind |
816 |
DistrictMaster districtMaster = districtMasterRepository.selectByNameAndStateShortName(districtName,
|
|
|
817 |
stateInfo.getShortName());
|
|
|
818 |
|
| 23378 |
ashik.ali |
819 |
fofoStore = new FofoStore();
|
|
|
820 |
fofoStore.setId(retailerId);
|
| 24023 |
amit.gupta |
821 |
fofoStore.setCounterSize(updateRetailerRequest.getCountersize());
|
|
|
822 |
fofoStore.setMinimumInvestment(updateRetailerRequest.getMinInvestment());
|
| 26209 |
tejbeer |
823 |
fofoStore.setWarehouseId(updateRetailerRequest.getWarehouseId());
|
| 23786 |
amit.gupta |
824 |
String latestStoreCode = fofoStoreRepository.selectLatestStore().getCode();
|
|
|
825 |
int latestCodeCounter = Integer.parseInt(latestStoreCode.replaceAll("[A-Z]", ""));
|
| 23955 |
govind |
826 |
String fofoStoreCode = StringUtils.generateFofoStoreSequence(
|
|
|
827 |
districtMaster.getStateShortName() + districtMaster.getShortName(), latestCodeCounter + 1);
|
| 23378 |
ashik.ali |
828 |
fofoStore.setCode(fofoStoreCode);
|
| 28189 |
tejbeer |
829 |
fofoStore.setBagsLastCredited(LocalDateTime.now());
|
| 28825 |
tejbeer |
830 |
fofoStore.setFofoType(updateRetailerRequest.getFofoType());
|
| 30097 |
tejbeer |
831 |
fofoStore.setActivationType(ActivationType.ACTIVE);
|
| 23378 |
ashik.ali |
832 |
fofoStoreRepository.persist(fofoStore);
|
| 28908 |
tejbeer |
833 |
|
|
|
834 |
// Auto fill in onboarding Panel
|
|
|
835 |
PartnerOnBoardingPanel pobp = partnerOnBoardingPanelRepository
|
|
|
836 |
.selectByPhoneNumber(Long.parseLong(retailerAddress.getPhoneNumber()));
|
|
|
837 |
if (pobp != null) {
|
|
|
838 |
|
| 29042 |
tejbeer |
839 |
PartnerVerificationpanel partnerVerificationpanel = partnerOnboardingVerificationRepository
|
|
|
840 |
.selectByOnboardingId(pobp.getId());
|
|
|
841 |
|
|
|
842 |
if (partnerVerificationpanel != null) {
|
|
|
843 |
if (partnerVerificationpanel.getApproval().equals(PartnerVerificationApprovalStatus.YES)) {
|
|
|
844 |
pobp.setCode(fofoStore.getCode());
|
|
|
845 |
|
|
|
846 |
storeTimelineTatService.onCodeCreated(pobp.getId());
|
|
|
847 |
|
|
|
848 |
}
|
|
|
849 |
|
|
|
850 |
}
|
|
|
851 |
|
| 28908 |
tejbeer |
852 |
}
|
| 30719 |
tejbeer |
853 |
|
|
|
854 |
PincodePartner pincodePartner = pincodePartnerRepository
|
|
|
855 |
.selectPartnerByPincode(retailerAddress.getPinCode(), fofoStore.getId());
|
|
|
856 |
if (pincodePartner == null) {
|
|
|
857 |
PincodePartner pinPartner = new PincodePartner();
|
|
|
858 |
pinPartner.setFofoId(fofoStore.getId());
|
|
|
859 |
pinPartner.setPincode(retailerAddress.getPinCode());
|
|
|
860 |
pincodePartnerRepository.perist(pinPartner);
|
|
|
861 |
}
|
| 23378 |
ashik.ali |
862 |
}
|
| 23955 |
govind |
863 |
|
| 23378 |
ashik.ali |
864 |
return fofoStore;
|
|
|
865 |
}
|
| 23955 |
govind |
866 |
|
| 23329 |
ashik.ali |
867 |
@Override
|
| 23955 |
govind |
868 |
public FofoStore createFofoStoreCodeByUserId(int userId, String districtName, String stateName,
|
|
|
869 |
UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException {
|
| 23329 |
ashik.ali |
870 |
User user = userRepository.selectById(userId);
|
|
|
871 |
// = userAccountRepository.selectRetailerIdByUserId(user.getId());
|
|
|
872 |
UserAccount userAccounts = userAccountRepository.selectSaholicByUserId(user.getId());
|
|
|
873 |
Retailer retailer = retailerRepository.selectById(userAccounts.getAccountKey());
|
| 23781 |
ashik.ali |
874 |
Role roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
|
| 23955 |
govind |
875 |
try {
|
| 23781 |
ashik.ali |
876 |
userRoleRepository.selectByUserIdAndRoleId(user.getId(), roleFofo.getId());
|
| 23955 |
govind |
877 |
} catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
| 23329 |
ashik.ali |
878 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.USER_ID, user.getId(), "USR_1013");
|
|
|
879 |
}
|
| 23955 |
govind |
880 |
return this.createFofoStoreCodeByRetailerId(retailer.getId(), districtName, stateName, updateRetailerRequest);
|
|
|
881 |
|
| 23329 |
ashik.ali |
882 |
}
|
| 23955 |
govind |
883 |
|
| 23329 |
ashik.ali |
884 |
@Override
|
|
|
885 |
public List<DistrictMaster> getAllDistrictMaster(String stateName) {
|
| 30525 |
tejbeer |
886 |
// StateInfo stateInfo = null;
|
|
|
887 |
State stateInfo = null;
|
| 23329 |
ashik.ali |
888 |
try {
|
| 30525 |
tejbeer |
889 |
// stateInfo = Utils.getStateInfo(stateName);
|
|
|
890 |
|
|
|
891 |
stateInfo = stateRepository.selectByName(stateName);
|
| 23329 |
ashik.ali |
892 |
} catch (Exception e) {
|
|
|
893 |
e.printStackTrace();
|
| 23955 |
govind |
894 |
// throw new ProfitMandiBusinessException();
|
| 23329 |
ashik.ali |
895 |
}
|
|
|
896 |
return districtMasterRepository.selectByStateShortName(stateInfo.getShortName());
|
|
|
897 |
}
|
| 22980 |
ashik.ali |
898 |
|
| 23509 |
amit.gupta |
899 |
@Override
|
|
|
900 |
public Map<Integer, CustomRetailer> getFofoRetailers(List<Integer> fofoIds) {
|
|
|
901 |
List<com.spice.profitmandi.dao.entity.user.User> saholicUsers = userUserRepository.selectByIds(fofoIds);
|
| 25295 |
amit.gupta |
902 |
Map<Integer, com.spice.profitmandi.dao.entity.user.User> userAddressMap = saholicUsers.stream()
|
|
|
903 |
.filter(x -> x.getAddressId() != null).collect(Collectors.toMap(x -> x.getAddressId(), x -> x));
|
| 23903 |
amit.gupta |
904 |
List<Address> addresses = addressRepository.selectByIds(new ArrayList<>(userAddressMap.keySet()));
|
| 23509 |
amit.gupta |
905 |
Map<Integer, CustomRetailer> customRetailersMap = new HashMap<>();
|
| 25295 |
amit.gupta |
906 |
for (Address address : addresses) {
|
| 23903 |
amit.gupta |
907 |
com.spice.profitmandi.dao.entity.user.User user = userAddressMap.get(address.getId());
|
| 23509 |
amit.gupta |
908 |
CustomRetailer customRetailer = new CustomRetailer();
|
| 23903 |
amit.gupta |
909 |
customRetailer.setEmail(user.getEmailId());
|
| 23509 |
amit.gupta |
910 |
customRetailer.setBusinessName(address.getName());
|
|
|
911 |
customRetailer.setMobileNumber(address.getPhoneNumber());
|
| 23532 |
amit.gupta |
912 |
try {
|
| 26151 |
amit.gupta |
913 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(address.getRetaierId());
|
|
|
914 |
customRetailer.setCode(fs.getCode());
|
| 31180 |
tejbeer |
915 |
customRetailer.setCounterSize(fs.getCounterSize());
|
|
|
916 |
|
| 26151 |
amit.gupta |
917 |
customRetailer.setWarehouseId(fs.getWarehouseId());
|
| 26977 |
amit.gupta |
918 |
customRetailer.setPartnerId(fs.getId());
|
| 30219 |
tejbeer |
919 |
customRetailer.setFofoType(fs.getFofoType());
|
| 26125 |
amit.gupta |
920 |
} catch (Exception e) {
|
|
|
921 |
continue;
|
|
|
922 |
}
|
|
|
923 |
try {
|
| 23796 |
amit.gupta |
924 |
customRetailer.setCartId(user.getActiveCartId());
|
| 23532 |
amit.gupta |
925 |
PrivateDealUser pdu = privateDealUserRepository.selectById(address.getRetaierId());
|
|
|
926 |
Counter counter = counterRepository.selectById(pdu.getCounterId());
|
|
|
927 |
customRetailer.setGstNumber(counter.getGstin());
|
| 23955 |
govind |
928 |
} catch (Exception e) {
|
| 23532 |
amit.gupta |
929 |
customRetailer.setGstNumber(null);
|
|
|
930 |
}
|
|
|
931 |
CustomAddress address1 = new CustomAddress();
|
|
|
932 |
address1.setCity(address.getCity());
|
|
|
933 |
address1.setState(address.getState());
|
|
|
934 |
address1.setLine1(address.getLine1());
|
|
|
935 |
address1.setLine2(address.getLine2());
|
|
|
936 |
address1.setPinCode(address.getPinCode());
|
|
|
937 |
address1.setName(address.getName());
|
|
|
938 |
customRetailer.setAddress(address1);
|
| 26522 |
amit.gupta |
939 |
customRetailer.setDisplayName(
|
|
|
940 |
customRetailer.getBusinessName() + "-" + customRetailer.getCode() + "- " + address1.getCity());
|
| 26977 |
amit.gupta |
941 |
customRetailersMap.put(customRetailer.getPartnerId(), customRetailer);
|
| 23509 |
amit.gupta |
942 |
}
|
|
|
943 |
return customRetailersMap;
|
|
|
944 |
}
|
| 25295 |
amit.gupta |
945 |
|
| 23781 |
ashik.ali |
946 |
@Override
|
| 30749 |
amit.gupta |
947 |
@Cacheable(value = "getFofoRetailer", cacheManager = "thirtyMinsTimeOutCacheManager")
|
| 25295 |
amit.gupta |
948 |
public CustomRetailer getFofoRetailer(int fofoId) throws ProfitMandiBusinessException {
|
| 23957 |
tejbeer |
949 |
com.spice.profitmandi.dao.entity.user.User saholicUser = userUserRepository.selectById(fofoId);
|
| 26089 |
amit.gupta |
950 |
FofoStore store = fofoStoreRepository.selectByRetailerId(fofoId);
|
| 23957 |
tejbeer |
951 |
Address address = null;
|
|
|
952 |
try {
|
|
|
953 |
address = addressRepository.selectById(saholicUser.getAddressId());
|
|
|
954 |
} catch (ProfitMandiBusinessException e1) {
|
|
|
955 |
// TODO Auto-generated catch block
|
|
|
956 |
e1.printStackTrace();
|
|
|
957 |
}
|
|
|
958 |
Map<Integer, CustomRetailer> customRetailersMap = new HashMap<>();
|
| 25295 |
amit.gupta |
959 |
CustomRetailer customRetailer = new CustomRetailer();
|
|
|
960 |
customRetailer.setEmail(saholicUser.getEmailId());
|
|
|
961 |
customRetailer.setBusinessName(address.getName());
|
|
|
962 |
customRetailer.setMobileNumber(address.getPhoneNumber());
|
|
|
963 |
try {
|
|
|
964 |
customRetailer.setCartId(saholicUser.getActiveCartId());
|
|
|
965 |
PrivateDealUser pdu = privateDealUserRepository.selectById(address.getRetaierId());
|
|
|
966 |
Counter counter = counterRepository.selectById(pdu.getCounterId());
|
|
|
967 |
customRetailer.setGstNumber(counter.getGstin());
|
|
|
968 |
} catch (Exception e) {
|
|
|
969 |
customRetailer.setGstNumber(null);
|
|
|
970 |
}
|
|
|
971 |
CustomAddress address1 = new CustomAddress();
|
|
|
972 |
address1.setCity(address.getCity());
|
|
|
973 |
address1.setState(address.getState());
|
|
|
974 |
address1.setLine1(address.getLine1());
|
|
|
975 |
address1.setLine2(address.getLine2());
|
|
|
976 |
address1.setPinCode(address.getPinCode());
|
| 26653 |
amit.gupta |
977 |
address1.setPhoneNumber(address.getPhoneNumber());
|
| 25295 |
amit.gupta |
978 |
address1.setName(address.getName());
|
| 26125 |
amit.gupta |
979 |
customRetailer.setDisplayName(address.getName() + " - " + address.getCity());
|
| 25295 |
amit.gupta |
980 |
customRetailer.setAddress(address1);
|
|
|
981 |
customRetailer.setPartnerId(address.getRetaierId());
|
| 26089 |
amit.gupta |
982 |
customRetailer.setCode(store.getCode());
|
| 26112 |
amit.gupta |
983 |
customRetailer.setWarehouseId(store.getWarehouseId());
|
| 25295 |
amit.gupta |
984 |
customRetailersMap.put(address.getRetaierId(), customRetailer);
|
| 23957 |
tejbeer |
985 |
return customRetailer;
|
| 25295 |
amit.gupta |
986 |
|
| 23957 |
tejbeer |
987 |
}
|
| 26125 |
amit.gupta |
988 |
|
| 25383 |
tejbeer |
989 |
@Override
|
| 27877 |
amit.gupta |
990 |
public Map<Integer, CustomRetailer> getFofoRetailerUserId(List<Integer> fofoIds) {
|
| 25383 |
tejbeer |
991 |
List<com.spice.profitmandi.dao.entity.user.User> saholicUsers = userUserRepository.selectByIds(fofoIds);
|
|
|
992 |
Map<Integer, com.spice.profitmandi.dao.entity.user.User> userAddressMap = saholicUsers.stream()
|
|
|
993 |
.filter(x -> x.getAddressId() != null).collect(Collectors.toMap(x -> x.getAddressId(), x -> x));
|
|
|
994 |
List<Address> addresses = addressRepository.selectByIds(new ArrayList<>(userAddressMap.keySet()));
|
|
|
995 |
Map<Integer, CustomRetailer> customRetailersMap = new HashMap<>();
|
|
|
996 |
for (Address address : addresses) {
|
|
|
997 |
com.spice.profitmandi.dao.entity.user.User user = userAddressMap.get(address.getId());
|
|
|
998 |
CustomRetailer customRetailer = new CustomRetailer();
|
|
|
999 |
customRetailer.setEmail(user.getEmailId());
|
|
|
1000 |
customRetailer.setBusinessName(address.getName());
|
|
|
1001 |
customRetailer.setMobileNumber(address.getPhoneNumber());
|
| 27877 |
amit.gupta |
1002 |
int userId = 0;
|
| 25383 |
tejbeer |
1003 |
try {
|
| 27877 |
amit.gupta |
1004 |
userId = userAccountRepository.selectUserIdByRetailerId(user.getId());
|
| 28024 |
tejbeer |
1005 |
} catch (ProfitMandiBusinessException e) {
|
| 27877 |
amit.gupta |
1006 |
continue;
|
|
|
1007 |
}
|
|
|
1008 |
try {
|
| 25383 |
tejbeer |
1009 |
customRetailer.setCartId(user.getActiveCartId());
|
|
|
1010 |
PrivateDealUser pdu = privateDealUserRepository.selectById(address.getRetaierId());
|
|
|
1011 |
Counter counter = counterRepository.selectById(pdu.getCounterId());
|
|
|
1012 |
customRetailer.setGstNumber(counter.getGstin());
|
|
|
1013 |
} catch (Exception e) {
|
|
|
1014 |
customRetailer.setGstNumber(null);
|
|
|
1015 |
}
|
|
|
1016 |
CustomAddress address1 = new CustomAddress();
|
|
|
1017 |
address1.setCity(address.getCity());
|
|
|
1018 |
address1.setState(address.getState());
|
|
|
1019 |
address1.setLine1(address.getLine1());
|
|
|
1020 |
address1.setLine2(address.getLine2());
|
|
|
1021 |
address1.setPinCode(address.getPinCode());
|
|
|
1022 |
address1.setName(address.getName());
|
|
|
1023 |
customRetailer.setAddress(address1);
|
|
|
1024 |
customRetailer.setPartnerId(address.getRetaierId());
|
|
|
1025 |
customRetailer.setDisplayName(customRetailer.getBusinessName() + "-" + address1.getCity());
|
|
|
1026 |
customRetailersMap.put(userId, customRetailer);
|
|
|
1027 |
}
|
|
|
1028 |
return customRetailersMap;
|
|
|
1029 |
}
|
| 25295 |
amit.gupta |
1030 |
|
| 23957 |
tejbeer |
1031 |
@Override
|
| 23781 |
ashik.ali |
1032 |
public Map<Integer, String> getAllFofoRetailerIdEmailIdMap() {
|
|
|
1033 |
Role roleFofo = null;
|
|
|
1034 |
try {
|
|
|
1035 |
roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
|
|
|
1036 |
} catch (ProfitMandiBusinessException e) {
|
|
|
1037 |
// TODO Auto-generated catch block
|
|
|
1038 |
e.printStackTrace();
|
|
|
1039 |
}
|
|
|
1040 |
Role roleRetailer = null;
|
|
|
1041 |
try {
|
|
|
1042 |
roleRetailer = roleRepository.selectByName(RoleType.RETAILER.toString());
|
|
|
1043 |
} catch (ProfitMandiBusinessException e) {
|
|
|
1044 |
// TODO Auto-generated catch block
|
|
|
1045 |
e.printStackTrace();
|
|
|
1046 |
}
|
|
|
1047 |
Set<Integer> roleIds = new HashSet<>();
|
|
|
1048 |
roleIds.add(roleFofo.getId());
|
|
|
1049 |
roleIds.add(roleRetailer.getId());
|
|
|
1050 |
List<Integer> userIds = userRoleRepository.selectUserIdsByRoleIds(roleIds);
|
|
|
1051 |
List<User> users = userRepository.selectAllByIds(new HashSet<>(userIds));
|
|
|
1052 |
Map<Integer, Integer> userIdRetailerIdMap = this.getUserIdRetailerIdMap(userIds);
|
|
|
1053 |
Map<Integer, String> retailerIdEmailIdMap = new HashMap<>();
|
| 23955 |
govind |
1054 |
for (User user : users) {
|
| 23781 |
ashik.ali |
1055 |
retailerIdEmailIdMap.put(userIdRetailerIdMap.get(user.getId()), user.getEmailId());
|
|
|
1056 |
}
|
|
|
1057 |
return retailerIdEmailIdMap;
|
|
|
1058 |
}
|
| 23955 |
govind |
1059 |
|
|
|
1060 |
private Map<Integer, Integer> getUserIdRetailerIdMap(List<Integer> userIds) {
|
| 23781 |
ashik.ali |
1061 |
List<UserAccount> userAccounts = userAccountRepository.selectAllSaholicByUserIds(new HashSet<>(userIds));
|
|
|
1062 |
Map<Integer, Integer> userIdRetailerIdMap = new HashMap<>();
|
| 23955 |
govind |
1063 |
for (UserAccount userAccount : userAccounts) {
|
| 23781 |
ashik.ali |
1064 |
userIdRetailerIdMap.put(userAccount.getUserId(), userAccount.getAccountKey());
|
|
|
1065 |
}
|
|
|
1066 |
return userIdRetailerIdMap;
|
|
|
1067 |
}
|
| 25295 |
amit.gupta |
1068 |
|
|
|
1069 |
private Map<Integer, String> getUserIdEmailIdMap(Set<Integer> userIds) {
|
| 23880 |
ashik.ali |
1070 |
List<User> users = userRepository.selectAllByIds(userIds);
|
|
|
1071 |
Map<Integer, String> userIdEmailIdMap = new HashMap<>();
|
| 23955 |
govind |
1072 |
for (User user : users) {
|
| 23880 |
ashik.ali |
1073 |
userIdEmailIdMap.put(user.getId(), user.getEmailId());
|
|
|
1074 |
}
|
|
|
1075 |
return userIdEmailIdMap;
|
|
|
1076 |
}
|
| 23509 |
amit.gupta |
1077 |
|
| 23880 |
ashik.ali |
1078 |
@Override
|
|
|
1079 |
public Map<Integer, String> getAllFofoRetailerIdEmailIdMap(Set<Integer> retailerIds) {
|
|
|
1080 |
List<UserAccount> userAccounts = userAccountRepository.selectAllSaholicByRetailerIds(retailerIds);
|
|
|
1081 |
Set<Integer> userIds = new HashSet<>();
|
| 23955 |
govind |
1082 |
for (UserAccount userAccount : userAccounts) {
|
| 23880 |
ashik.ali |
1083 |
userIds.add(userAccount.getUserId());
|
|
|
1084 |
}
|
|
|
1085 |
Map<Integer, String> retailerIdEmailIdMap = new HashMap<>();
|
|
|
1086 |
Map<Integer, String> userIdEmailIdMap = this.getUserIdEmailIdMap(userIds);
|
| 23955 |
govind |
1087 |
for (UserAccount userAccount : userAccounts) {
|
| 23880 |
ashik.ali |
1088 |
retailerIdEmailIdMap.put(userAccount.getAccountKey(), userIdEmailIdMap.get(userAccount.getUserId()));
|
|
|
1089 |
}
|
|
|
1090 |
return retailerIdEmailIdMap;
|
|
|
1091 |
}
|
| 25295 |
amit.gupta |
1092 |
|
| 24168 |
amit.gupta |
1093 |
@Override
|
| 24349 |
amit.gupta |
1094 |
public Map<Integer, String> getAllFofoRetailerIdNameMap(List<Integer> storeIds) {
|
| 24168 |
amit.gupta |
1095 |
Map<Integer, CustomRetailer> retailersMap = this.getFofoRetailers(storeIds);
|
|
|
1096 |
Map<Integer, String> retailerIdNameMap = new HashMap<>();
|
| 25295 |
amit.gupta |
1097 |
for (Map.Entry<Integer, CustomRetailer> entry : retailersMap.entrySet()) {
|
|
|
1098 |
retailerIdNameMap.put(entry.getKey(),
|
|
|
1099 |
entry.getValue().getBusinessName() + "-" + entry.getValue().getAddress().getCity());
|
| 24168 |
amit.gupta |
1100 |
}
|
|
|
1101 |
return retailerIdNameMap;
|
|
|
1102 |
}
|
|
|
1103 |
|
|
|
1104 |
@Override
|
| 30749 |
amit.gupta |
1105 |
@Cacheable(value = "FofoRetailerIdNameMap", cacheManager = "thirtyMinsTimeOutCacheManager")
|
| 24168 |
amit.gupta |
1106 |
public Map<Integer, String> getAllFofoRetailerIdNameMap() {
|
| 24349 |
amit.gupta |
1107 |
List<FofoStore> stores = fofoStoreRepository.selectAll();
|
| 25295 |
amit.gupta |
1108 |
List<Integer> storeIds = stores.stream().map(x -> x.getId()).collect(Collectors.toList());
|
| 24349 |
amit.gupta |
1109 |
return this.getAllFofoRetailerIdNameMap(storeIds);
|
|
|
1110 |
}
|
|
|
1111 |
|
|
|
1112 |
@Override
|
|
|
1113 |
public List<MapWrapper<Integer, String>> getAllFofoRetailerIdNameList() {
|
|
|
1114 |
List<MapWrapper<Integer, String>> mapWrappers = new ArrayList<>();
|
| 24168 |
amit.gupta |
1115 |
// TODO Auto-generated method stub
|
| 24349 |
amit.gupta |
1116 |
Map<Integer, String> fofoIdNameMap = this.getAllFofoRetailerIdNameMap();
|
| 25295 |
amit.gupta |
1117 |
fofoIdNameMap.forEach((fofoId, name) -> {
|
| 24349 |
amit.gupta |
1118 |
MapWrapper<Integer, String> idWrapper = new MapWrapper<>();
|
|
|
1119 |
idWrapper.setKey(fofoId);
|
|
|
1120 |
idWrapper.setValue(name);
|
|
|
1121 |
mapWrappers.add(idWrapper);
|
|
|
1122 |
});
|
|
|
1123 |
return mapWrappers;
|
|
|
1124 |
}
|
|
|
1125 |
|
|
|
1126 |
@Override
|
| 30749 |
amit.gupta |
1127 |
@Cacheable(value = "retailerNames", cacheManager = "thirtyMinsTimeOutCacheManager")
|
| 26962 |
amit.gupta |
1128 |
public Map<Integer, CustomRetailer> getFofoRetailers(boolean activeOnly) {
|
| 24349 |
amit.gupta |
1129 |
// TODO Auto-generated method stub
|
| 31556 |
amit.gupta |
1130 |
Stream<FofoStore> storeStream = fofoStoreRepository.selectAll().stream().filter(x -> !x.isInternal());
|
| 27861 |
tejbeer |
1131 |
if (activeOnly) {
|
|
|
1132 |
storeStream = storeStream.filter(x -> x.isActive());
|
| 26962 |
amit.gupta |
1133 |
}
|
|
|
1134 |
List<Integer> storeIds = storeStream.map(x -> x.getId()).collect(Collectors.toList());
|
| 24349 |
amit.gupta |
1135 |
return this.getFofoRetailers(storeIds);
|
| 24168 |
amit.gupta |
1136 |
}
|
| 25295 |
amit.gupta |
1137 |
|
| 26522 |
amit.gupta |
1138 |
@Override
|
| 30749 |
amit.gupta |
1139 |
@Cacheable(value = "allFofoRetailers", cacheManager = "thirtyMinsTimeOutCacheManager")
|
| 27861 |
tejbeer |
1140 |
public Map<Integer, CustomRetailer> getAllFofoRetailers() {
|
|
|
1141 |
// TODO Auto-generated method stub
|
|
|
1142 |
Stream<FofoStore> storeStream = fofoStoreRepository.selectAll().stream();
|
|
|
1143 |
|
|
|
1144 |
List<Integer> storeIds = storeStream.map(x -> x.getId()).collect(Collectors.toList());
|
|
|
1145 |
return this.getFofoRetailers(storeIds);
|
|
|
1146 |
}
|
|
|
1147 |
|
|
|
1148 |
@Override
|
| 26522 |
amit.gupta |
1149 |
public LoginRequestResponseModel registerWebUser(LoginRequestResponseModel loginRequestModel)
|
|
|
1150 |
throws ProfitMandiBusinessException {
|
|
|
1151 |
|
|
|
1152 |
com.spice.profitmandi.dao.entity.user.User saholicUser = this.createSaholicUser(loginRequestModel);
|
|
|
1153 |
loginRequestModel.setUserId(saholicUser.getId());
|
|
|
1154 |
|
|
|
1155 |
this.createRetailerAddress(loginRequestModel);
|
|
|
1156 |
|
|
|
1157 |
this.createPrivateDealUser(loginRequestModel);
|
|
|
1158 |
this.updateSaholicUser(saholicUser.getId(), loginRequestModel.getBusinessAddress().getId());
|
|
|
1159 |
|
|
|
1160 |
return loginRequestModel;
|
|
|
1161 |
|
|
|
1162 |
}
|
|
|
1163 |
|
|
|
1164 |
private void createPrivateDealUser(LoginRequestResponseModel loginRequestModel) {
|
|
|
1165 |
|
|
|
1166 |
Integer counterId = this.createCounter(loginRequestModel.getEmail(), loginRequestModel.getGstNumber(),
|
|
|
1167 |
loginRequestModel.getBusinessAddress().getPhoneNumber(),
|
|
|
1168 |
loginRequestModel.getBusinessAddress().getName(), loginRequestModel.getBusinessAddress().getId());
|
|
|
1169 |
try {
|
|
|
1170 |
this.createPrivateDealUser(loginRequestModel.getUserId(), counterId, false);
|
|
|
1171 |
} catch (Exception e) {
|
|
|
1172 |
LOGGER.error("ERROR : ", e);
|
|
|
1173 |
}
|
|
|
1174 |
|
|
|
1175 |
PrivateDealUserAddressMapping privateDealUserAddressMapping = new PrivateDealUserAddressMapping();
|
|
|
1176 |
privateDealUserAddressMapping.setUserId(loginRequestModel.getUserId());
|
|
|
1177 |
privateDealUserAddressMapping.setAddressId(loginRequestModel.getBusinessAddress().getId());
|
|
|
1178 |
privateDealUserAddressMappingRepository.persist(privateDealUserAddressMapping);
|
|
|
1179 |
|
|
|
1180 |
}
|
|
|
1181 |
|
|
|
1182 |
private void createRetailerAddress(LoginRequestResponseModel loginRequestResponseModel)
|
|
|
1183 |
throws ProfitMandiBusinessException {
|
|
|
1184 |
Address businessAddress = loginRequestResponseModel.getBusinessAddress();
|
|
|
1185 |
businessAddress.setRetaierId(loginRequestResponseModel.getUserId());
|
|
|
1186 |
addressRepository.persist(businessAddress);
|
|
|
1187 |
}
|
| 26536 |
amit.gupta |
1188 |
|
| 26528 |
amit.gupta |
1189 |
private String getHash256(String originalString) {
|
| 26533 |
amit.gupta |
1190 |
String hashString = Hashing.sha256().hashString(originalString, StandardCharsets.UTF_8).toString();
|
|
|
1191 |
LOGGER.info("Hash String {}", hashString);
|
|
|
1192 |
return hashString;
|
| 26528 |
amit.gupta |
1193 |
}
|
| 26533 |
amit.gupta |
1194 |
|
|
|
1195 |
@Override
|
| 30749 |
amit.gupta |
1196 |
@Cacheable(value = "fofoIdUrl", cacheManager = "thirtyMinsTimeOutCacheManager")
|
| 26533 |
amit.gupta |
1197 |
public Map<Integer, String> getAllFofoRetailerIdUrlMap() {
|
| 26536 |
amit.gupta |
1198 |
Map<Integer, String> fofoRetailerUrlMap = new HashMap<>();
|
|
|
1199 |
List<FofoStore> stores = fofoStoreRepository.selectAll().stream().filter(x -> x.isActive())
|
|
|
1200 |
.collect(Collectors.toList());
|
|
|
1201 |
Map<Integer, com.spice.profitmandi.dao.entity.user.User> userMap = userUserRepository
|
|
|
1202 |
.selectByIds(stores.stream().map(x -> x.getId()).collect(Collectors.toList())).stream()
|
|
|
1203 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
1204 |
for (FofoStore store : stores) {
|
| 26537 |
amit.gupta |
1205 |
LOGGER.info("Store is {}", store);
|
| 26544 |
amit.gupta |
1206 |
String districtShortName = store.getCode().replaceAll("\\d+", "").substring(2);
|
| 26593 |
amit.gupta |
1207 |
String stateShortName = store.getCode().replaceAll("\\d+", "").substring(0, 2);
|
| 26539 |
amit.gupta |
1208 |
DistrictMaster districtMaster = null;
|
| 26544 |
amit.gupta |
1209 |
LOGGER.info("Store shortname is {}", districtShortName);
|
| 26593 |
amit.gupta |
1210 |
districtMaster = districtMasterRepository.selectByShortnameNameAndStateShortName(districtShortName,
|
|
|
1211 |
stateShortName);
|
| 26543 |
amit.gupta |
1212 |
if (districtMaster == null) {
|
| 26544 |
amit.gupta |
1213 |
districtMaster = districtMasterRepository.selectByShortnameNameAndStateShortName("FB", "HR");
|
| 26539 |
amit.gupta |
1214 |
}
|
| 26542 |
amit.gupta |
1215 |
LOGGER.info("Store id - {}", store.getId());
|
| 28825 |
tejbeer |
1216 |
// com.spice.profitmandi.dao.entity.user.User user = userMap.get(store.getId());
|
| 26536 |
amit.gupta |
1217 |
String urlString = districtMaster.getStateShortName() + "/"
|
| 27877 |
amit.gupta |
1218 |
+ Utils.getHyphenatedString(districtMaster.getName()) + "/" + store.getCode();
|
| 28346 |
amit.gupta |
1219 |
fofoRetailerUrlMap.put(store.getId(), urlString.toLowerCase());
|
| 26541 |
amit.gupta |
1220 |
LOGGER.info("Store is {} end", store);
|
| 26536 |
amit.gupta |
1221 |
|
|
|
1222 |
}
|
|
|
1223 |
return fofoRetailerUrlMap;
|
| 26533 |
amit.gupta |
1224 |
}
|
|
|
1225 |
|
|
|
1226 |
@Override
|
| 30749 |
amit.gupta |
1227 |
@Cacheable(value = "storeCodeRetailerMap", cacheManager = "thirtyMinsTimeOutCacheManager")
|
| 26590 |
amit.gupta |
1228 |
public Map<String, Integer> getStoreCodeRetailerMap() {
|
| 26533 |
amit.gupta |
1229 |
Map<Integer, String> map = this.getAllFofoRetailerIdUrlMap();
|
| 26596 |
amit.gupta |
1230 |
Map<String, Integer> returnMap = map.entrySet().stream().collect(Collectors.toMap(x -> {
|
| 26593 |
amit.gupta |
1231 |
String[] splitString = x.getValue().split("/");
|
| 27877 |
amit.gupta |
1232 |
return splitString[splitString.length - 1];
|
| 26593 |
amit.gupta |
1233 |
}, x -> x.getKey()));
|
| 26596 |
amit.gupta |
1234 |
LOGGER.info("returnMap {}", returnMap);
|
|
|
1235 |
return returnMap;
|
| 26533 |
amit.gupta |
1236 |
}
|
| 27877 |
amit.gupta |
1237 |
|
|
|
1238 |
@Override
|
|
|
1239 |
public String getPartnerCriteriaString(PartnerCriteria partnerCriteria) {
|
|
|
1240 |
|
|
|
1241 |
StringBuilder sb = new StringBuilder();
|
|
|
1242 |
if (partnerCriteria.getFofoIds().size() > 0) {
|
|
|
1243 |
List<Integer> fofoIds = partnerCriteria.getFofoIds();
|
|
|
1244 |
Map<Integer, CustomRetailer> customRetailers = this.getFofoRetailerUserId(fofoIds);
|
| 28024 |
tejbeer |
1245 |
List<String> businessNames = customRetailers.values().stream().map(x -> x.getBusinessName())
|
|
|
1246 |
.collect(Collectors.toList());
|
| 27877 |
amit.gupta |
1247 |
sb.append(String.join(", ", businessNames));
|
|
|
1248 |
|
|
|
1249 |
} else {
|
|
|
1250 |
sb.append("All");
|
| 28024 |
tejbeer |
1251 |
if (partnerCriteria.getPartnerTypes().size() > 0) {
|
|
|
1252 |
sb.append(" ").append(String.join(", ", partnerCriteria.getPartnerTypes().stream()
|
|
|
1253 |
.map(x -> x.getValue()).collect(Collectors.toList())));
|
| 27877 |
amit.gupta |
1254 |
}
|
|
|
1255 |
sb.append(" partners ");
|
| 28024 |
tejbeer |
1256 |
if (partnerCriteria.getRegionIds().size() > 0) {
|
| 27877 |
amit.gupta |
1257 |
sb.append("from ");
|
| 28024 |
tejbeer |
1258 |
sb.append(String.join(", ", partnerCriteria.getRegionIds().stream()
|
|
|
1259 |
.map(x -> ProfitMandiConstants.WAREHOUSE_MAP.get(x)).collect(Collectors.toList())));
|
| 27877 |
amit.gupta |
1260 |
}
|
| 30723 |
amit.gupta |
1261 |
if (partnerCriteria.getExcludeFofoIds() != null && partnerCriteria.getExcludeFofoIds().size() > 0) {
|
|
|
1262 |
sb.append("excluding ");
|
| 31180 |
tejbeer |
1263 |
Map<Integer, CustomRetailer> customRetailers = this
|
|
|
1264 |
.getFofoRetailerUserId(partnerCriteria.getExcludeFofoIds());
|
| 30723 |
amit.gupta |
1265 |
List<String> businessNames = customRetailers.values().stream().map(x -> x.getBusinessName())
|
|
|
1266 |
.collect(Collectors.toList());
|
|
|
1267 |
sb.append(String.join(", ", businessNames));
|
|
|
1268 |
}
|
| 27877 |
amit.gupta |
1269 |
}
|
|
|
1270 |
return sb.toString();
|
|
|
1271 |
}
|
| 30097 |
tejbeer |
1272 |
|
| 30219 |
tejbeer |
1273 |
@Override
|
|
|
1274 |
public Map<Integer, CustomRetailer> getFofoRetailersPaginated(boolean activeOnly, int offset, int limit,
|
|
|
1275 |
FofoType fofoType) {
|
| 30097 |
tejbeer |
1276 |
|
| 30219 |
tejbeer |
1277 |
Stream<FofoStore> storeStream = fofoStoreRepository.selectByStatusFofoType(activeOnly, fofoType, offset, limit)
|
|
|
1278 |
.stream();
|
|
|
1279 |
|
|
|
1280 |
List<Integer> storeIds = storeStream.map(x -> x.getId()).collect(Collectors.toList());
|
|
|
1281 |
return this.getFofoRetailers(storeIds);
|
|
|
1282 |
}
|
|
|
1283 |
|
| 22980 |
ashik.ali |
1284 |
}
|