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