| 22125 |
ashik.ali |
1 |
package com.spice.profitmandi.dao.util;
|
|
|
2 |
|
|
|
3 |
import com.google.gson.Gson;
|
|
|
4 |
import com.google.gson.reflect.TypeToken;
|
|
|
5 |
import com.spice.profitmandi.common.enumuration.ContentType;
|
|
|
6 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 22476 |
ashik.ali |
7 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 22125 |
ashik.ali |
8 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 22352 |
ashik.ali |
9 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 32482 |
amit.gupta |
10 |
import com.spice.profitmandi.dao.entity.dtr.*;
|
| 23365 |
ashik.ali |
11 |
import com.spice.profitmandi.dao.entity.fofo.FofoPartnerPaymentOption;
|
|
|
12 |
import com.spice.profitmandi.dao.entity.fofo.PaymentOption;
|
| 32482 |
amit.gupta |
13 |
import com.spice.profitmandi.dao.entity.user.*;
|
| 22352 |
ashik.ali |
14 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
|
|
15 |
import com.spice.profitmandi.dao.enumuration.dtr.RetailerType;
|
|
|
16 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
| 23365 |
ashik.ali |
17 |
import com.spice.profitmandi.dao.enumuration.fofo.PaymentOptionType;
|
| 22352 |
ashik.ali |
18 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 32482 |
amit.gupta |
19 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
| 23365 |
ashik.ali |
20 |
import com.spice.profitmandi.dao.repository.fofo.FofoPartnerPaymentOptionRepository;
|
|
|
21 |
import com.spice.profitmandi.dao.repository.fofo.PaymentOptionRepository;
|
| 32482 |
amit.gupta |
22 |
import com.spice.profitmandi.dao.repository.user.*;
|
| 22471 |
ashik.ali |
23 |
import in.shop2020.model.v1.user.CartStatus;
|
| 32482 |
amit.gupta |
24 |
import org.apache.commons.io.FileUtils;
|
|
|
25 |
import org.apache.logging.log4j.LogManager;
|
|
|
26 |
import org.apache.logging.log4j.Logger;
|
|
|
27 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
28 |
import org.springframework.stereotype.Component;
|
| 22471 |
ashik.ali |
29 |
|
| 32482 |
amit.gupta |
30 |
import java.io.File;
|
|
|
31 |
import java.io.IOException;
|
|
|
32 |
import java.lang.reflect.Type;
|
|
|
33 |
import java.time.LocalDateTime;
|
|
|
34 |
import java.util.*;
|
|
|
35 |
|
| 22125 |
ashik.ali |
36 |
@Component
|
| 32482 |
amit.gupta |
37 |
public class
|
|
|
38 |
MigrationUtil {
|
| 22125 |
ashik.ali |
39 |
|
|
|
40 |
@Autowired
|
| 22868 |
ashik.ali |
41 |
private DocumentRepository documentRepository;
|
| 22125 |
ashik.ali |
42 |
|
| 22352 |
ashik.ali |
43 |
@Autowired
|
| 22868 |
ashik.ali |
44 |
private UserRepository userRepository;
|
| 22352 |
ashik.ali |
45 |
|
|
|
46 |
@Autowired
|
| 22868 |
ashik.ali |
47 |
private com.spice.profitmandi.dao.repository.user.UserRepository userUserRepository;
|
| 22471 |
ashik.ali |
48 |
|
|
|
49 |
@Autowired
|
| 22868 |
ashik.ali |
50 |
private CartRepository cartRepository;
|
| 22471 |
ashik.ali |
51 |
|
|
|
52 |
@Autowired
|
| 22868 |
ashik.ali |
53 |
private UserAccountRepository userAccountRepository;
|
| 22352 |
ashik.ali |
54 |
|
|
|
55 |
@Autowired
|
| 22868 |
ashik.ali |
56 |
private RetailerRepository retailerRepository;
|
| 22352 |
ashik.ali |
57 |
|
|
|
58 |
@Autowired
|
| 22868 |
ashik.ali |
59 |
private UserRoleRepository userRoleRepository;
|
| 22352 |
ashik.ali |
60 |
|
|
|
61 |
@Autowired
|
| 22868 |
ashik.ali |
62 |
private AddressRepository addressRepository;
|
| 22352 |
ashik.ali |
63 |
|
|
|
64 |
@Autowired
|
| 22868 |
ashik.ali |
65 |
private RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
| 22352 |
ashik.ali |
66 |
|
| 22471 |
ashik.ali |
67 |
@Autowired
|
| 22868 |
ashik.ali |
68 |
private PrivateDealUserRepository privateDealUserRepository;
|
| 22471 |
ashik.ali |
69 |
|
|
|
70 |
@Autowired
|
| 22868 |
ashik.ali |
71 |
private PrivateDealUserAddressMappingRepository privateDealUserAddressMappingRepository;
|
| 22471 |
ashik.ali |
72 |
|
|
|
73 |
@Autowired
|
| 22868 |
ashik.ali |
74 |
private CounterRepository counterRepository;
|
| 22471 |
ashik.ali |
75 |
|
| 22162 |
amit.gupta |
76 |
@Autowired
|
| 23066 |
ashik.ali |
77 |
private ShopRepository shopRepository;
|
|
|
78 |
|
|
|
79 |
@Autowired
|
|
|
80 |
private ShopAddressRepository shopAddressRepository;
|
|
|
81 |
|
|
|
82 |
@Autowired
|
| 23365 |
ashik.ali |
83 |
private FofoPartnerPaymentOptionRepository fofoPartnerPaymentOptionRepository;
|
|
|
84 |
|
|
|
85 |
@Autowired
|
|
|
86 |
private PaymentOptionRepository paymentOptionRepository;
|
|
|
87 |
|
|
|
88 |
@Autowired
|
| 23781 |
ashik.ali |
89 |
private RoleRepository roleRepository;
|
|
|
90 |
|
|
|
91 |
@Autowired
|
| 22868 |
ashik.ali |
92 |
private Mongo mongoClient;
|
| 22162 |
amit.gupta |
93 |
|
|
|
94 |
|
| 23568 |
govind |
95 |
private static final Logger LOGGER = LogManager.getLogger(MigrationUtil.class);
|
| 22125 |
ashik.ali |
96 |
|
| 22352 |
ashik.ali |
97 |
private List<Map<String, String>> getMongoFofoDoc(){
|
| 22162 |
amit.gupta |
98 |
String fofoFormsJsonString = mongoClient.getFofoFormsJsonString();
|
| 22471 |
ashik.ali |
99 |
LOGGER.info("mongoFofoDoc {}", fofoFormsJsonString);
|
| 22125 |
ashik.ali |
100 |
Gson gson = new Gson();
|
|
|
101 |
Type paths = new TypeToken<List<Map<String, String>>>(){}.getType();
|
|
|
102 |
List<Map<String, String>> maps = gson.fromJson(fofoFormsJsonString, paths);
|
| 22352 |
ashik.ali |
103 |
return maps;
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
public void migrateMongoDocToDocumentId() throws ProfitMandiBusinessException{
|
|
|
107 |
List<Map<String, String>> maps = this.getMongoFofoDoc();
|
|
|
108 |
Map<Integer, Map<String, Integer>> fofoIdPathMap = new HashMap<>();
|
| 22125 |
ashik.ali |
109 |
|
|
|
110 |
for(Map<String, String> map : maps){
|
|
|
111 |
int id = 0;
|
|
|
112 |
Map<String, Integer> pathMap = new HashMap<>();
|
|
|
113 |
for(Map.Entry<String, String> entry : map.entrySet()){
|
|
|
114 |
if(entry.getKey().equals("_id")){
|
| 22181 |
amit.gupta |
115 |
id = (int)Double.parseDouble(entry.getValue());
|
| 22125 |
ashik.ali |
116 |
}
|
|
|
117 |
if(entry.getValue().startsWith("/hsps-docs/")){
|
|
|
118 |
|
|
|
119 |
Document document = new Document();
|
|
|
120 |
|
|
|
121 |
try{
|
| 22178 |
amit.gupta |
122 |
File srcFile = new File(entry.getValue());
|
|
|
123 |
String destFileName = entry.getValue().substring(entry.getValue().lastIndexOf('/') + 1);
|
|
|
124 |
String destFilePath = "/uploads/";
|
| 22182 |
amit.gupta |
125 |
File destFile = new File(destFilePath + destFileName);
|
| 22178 |
amit.gupta |
126 |
FileUtils.copyFile(srcFile, destFile);
|
|
|
127 |
ContentType contentType = FileUtil.detectFileType(srcFile);
|
| 22125 |
ashik.ali |
128 |
document.setContentType(contentType);
|
| 22178 |
amit.gupta |
129 |
document.setName(destFileName);
|
|
|
130 |
document.setPath(destFilePath);
|
| 22125 |
ashik.ali |
131 |
document.setPersisted(true);
|
| 22178 |
amit.gupta |
132 |
document.setSize(srcFile.length());
|
| 22125 |
ashik.ali |
133 |
documentRepository.persist(document);
|
|
|
134 |
pathMap.put(entry.getKey(), document.getId());
|
| 22178 |
amit.gupta |
135 |
}catch(IOException ioException) {
|
|
|
136 |
LOGGER.info("IOException occurred");
|
| 22125 |
ashik.ali |
137 |
}
|
|
|
138 |
}
|
|
|
139 |
}
|
|
|
140 |
if(!pathMap.isEmpty()){
|
|
|
141 |
fofoIdPathMap.put(id, pathMap);
|
|
|
142 |
}
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
LOGGER.info("fofoIdPathMap {}", fofoIdPathMap);
|
|
|
146 |
for(Map.Entry<Integer, Map<String, Integer>> entry : fofoIdPathMap.entrySet()){
|
| 22162 |
amit.gupta |
147 |
mongoClient.updateColumnsById(entry.getValue(), entry.getKey());
|
| 22125 |
ashik.ali |
148 |
}
|
|
|
149 |
|
|
|
150 |
}
|
| 22352 |
ashik.ali |
151 |
|
| 23269 |
ashik.ali |
152 |
private Set<Integer> toRetailerIds(List<UserAccount> userAccounts){
|
| 22868 |
ashik.ali |
153 |
Set<Integer> retailerIds = new HashSet<>();
|
| 23269 |
ashik.ali |
154 |
for(UserAccount saholicUserAccount : userAccounts){
|
|
|
155 |
int retailerId = saholicUserAccount.getAccountKey();
|
| 22868 |
ashik.ali |
156 |
retailerIds.add(retailerId);
|
|
|
157 |
}
|
|
|
158 |
return retailerIds;
|
|
|
159 |
}
|
|
|
160 |
|
| 23269 |
ashik.ali |
161 |
private Set<Integer> toUserIds(List<UserAccount> userAccounts, Set<Integer> retailerIds){
|
| 22868 |
ashik.ali |
162 |
Set<Integer> userIds = new HashSet<>();
|
| 23269 |
ashik.ali |
163 |
for(UserAccount saholicUserAccount : userAccounts){
|
|
|
164 |
int retailerId = saholicUserAccount.getAccountKey();
|
| 22868 |
ashik.ali |
165 |
if(retailerIds.contains(retailerId)){
|
| 23269 |
ashik.ali |
166 |
userIds.add(saholicUserAccount.getUserId());
|
| 22416 |
amit.gupta |
167 |
}
|
| 22868 |
ashik.ali |
168 |
}
|
|
|
169 |
return userIds;
|
|
|
170 |
}
|
|
|
171 |
|
| 23781 |
ashik.ali |
172 |
public void migrateUserToRetailer() throws ProfitMandiBusinessException{
|
| 22868 |
ashik.ali |
173 |
|
| 23269 |
ashik.ali |
174 |
List<UserAccount> saholicUserAccounts = userAccountRepository.selectAllSaholicByUserIds(new HashSet<>(userRepository.selectIdAll()));
|
| 22868 |
ashik.ali |
175 |
if(saholicUserAccounts.isEmpty()){
|
|
|
176 |
return;
|
|
|
177 |
}
|
|
|
178 |
Set<Integer> retailerIds = this.toRetailerIds(saholicUserAccounts);
|
|
|
179 |
List<Integer> foundRetailerIds = retailerRepository.selectIdsByIds(retailerIds);
|
|
|
180 |
retailerIds.removeAll(foundRetailerIds);
|
|
|
181 |
for(int retailerId : retailerIds){
|
| 22416 |
amit.gupta |
182 |
Retailer retailer = new Retailer();
|
| 22352 |
ashik.ali |
183 |
try {
|
| 22416 |
amit.gupta |
184 |
retailer.setId(retailerId);
|
|
|
185 |
retailer.setMigrated(true);
|
| 22352 |
ashik.ali |
186 |
retailerRepository.persist(retailer);
|
| 22868 |
ashik.ali |
187 |
LOGGER.info("Retailer migrated {}", retailerId);
|
| 22352 |
ashik.ali |
188 |
} catch (ProfitMandiBusinessException e) {
|
|
|
189 |
LOGGER.info("Error occured while commiting retailer");
|
|
|
190 |
e.printStackTrace();
|
|
|
191 |
}
|
| 22868 |
ashik.ali |
192 |
}
|
|
|
193 |
|
|
|
194 |
Set<Integer> userIds = this.toUserIds(saholicUserAccounts, retailerIds);
|
|
|
195 |
|
| 22886 |
ashik.ali |
196 |
if(userIds.isEmpty()){
|
|
|
197 |
return;
|
|
|
198 |
}
|
| 22868 |
ashik.ali |
199 |
|
| 23781 |
ashik.ali |
200 |
Role roleRetailer = roleRepository.selectByName(RoleType.RETAILER.toString());
|
|
|
201 |
|
|
|
202 |
List<Integer> foundRetailerRoleUserIds = userRoleRepository.selectUserIdsByUserIdsAndRoleId(userIds, roleRetailer.getId());
|
|
|
203 |
|
| 22868 |
ashik.ali |
204 |
Set<Integer> notFoundRetailerRoleUserIds = new HashSet<>(userIds);
|
|
|
205 |
notFoundRetailerRoleUserIds.removeAll(foundRetailerRoleUserIds);
|
|
|
206 |
|
| 23781 |
ashik.ali |
207 |
|
|
|
208 |
|
| 22868 |
ashik.ali |
209 |
for(int userId : notFoundRetailerRoleUserIds){
|
|
|
210 |
UserRole retailerRole = new UserRole();
|
| 23781 |
ashik.ali |
211 |
retailerRole.setRoleId(roleRetailer.getId());
|
| 22868 |
ashik.ali |
212 |
retailerRole.setUserId(userId);
|
|
|
213 |
try {
|
|
|
214 |
userRoleRepository.persist(retailerRole);
|
|
|
215 |
LOGGER.info("UserId {} with Retailer Role migrated", userId);
|
|
|
216 |
} catch (ProfitMandiBusinessException e) {
|
|
|
217 |
e.printStackTrace();
|
| 22352 |
ashik.ali |
218 |
}
|
| 22868 |
ashik.ali |
219 |
}
|
|
|
220 |
|
| 23781 |
ashik.ali |
221 |
Role roleUser = roleRepository.selectByName(RoleType.USER.toString());
|
| 22868 |
ashik.ali |
222 |
|
| 23781 |
ashik.ali |
223 |
List<Integer> foundUserRoleUserIds = userRoleRepository.selectUserIdsByUserIdsAndRoleId(userIds, roleUser.getId());
|
|
|
224 |
|
| 22868 |
ashik.ali |
225 |
Set<Integer> notFoundUserRoleUserIds = new HashSet<>(userIds);
|
|
|
226 |
notFoundUserRoleUserIds.removeAll(foundUserRoleUserIds);
|
|
|
227 |
|
| 23781 |
ashik.ali |
228 |
|
| 22868 |
ashik.ali |
229 |
for(int userId : notFoundUserRoleUserIds){
|
|
|
230 |
UserRole userRole = new UserRole();
|
| 23781 |
ashik.ali |
231 |
userRole.setRoleId(roleUser.getId());
|
| 22868 |
ashik.ali |
232 |
userRole.setUserId(userId);
|
|
|
233 |
try {
|
|
|
234 |
userRoleRepository.persist(userRole);
|
|
|
235 |
LOGGER.info("UserId {} with User Role migrated", userId);
|
|
|
236 |
} catch (ProfitMandiBusinessException e) {
|
|
|
237 |
e.printStackTrace();
|
| 22352 |
ashik.ali |
238 |
}
|
|
|
239 |
}
|
| 22868 |
ashik.ali |
240 |
|
| 22352 |
ashik.ali |
241 |
}
|
|
|
242 |
|
|
|
243 |
public void migrateMongoDocToRetailer() throws ProfitMandiBusinessException{
|
|
|
244 |
List<Map<String, String>> maps = this.getMongoFofoDoc();
|
| 22471 |
ashik.ali |
245 |
//LOGGER.info("mongoFofoDocs {}", maps);
|
| 22352 |
ashik.ali |
246 |
for(Map<String, String> map : maps){
|
|
|
247 |
if(map.containsKey("registeredEmail1")){
|
|
|
248 |
|
| 22476 |
ashik.ali |
249 |
User user = null;
|
|
|
250 |
|
|
|
251 |
try{
|
|
|
252 |
user = userRepository.selectByEmailId(map.get("registeredEmail1"));
|
|
|
253 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| 23202 |
ashik.ali |
254 |
}
|
|
|
255 |
if(user == null){
|
| 23329 |
ashik.ali |
256 |
user = userRepository.selectBySecondryEmailId(map.get("registeredEmail1"));
|
|
|
257 |
}
|
|
|
258 |
if(user == null){
|
| 22476 |
ashik.ali |
259 |
user = new User();
|
|
|
260 |
user.setFirstName("");
|
|
|
261 |
user.setLastName("");
|
|
|
262 |
user.setCity(map.containsKey("city") ? map.get("city") : "");
|
|
|
263 |
user.setPinCode(Integer.valueOf(map.containsKey("pincode") ? map.get("pincode") : ""));
|
|
|
264 |
user.setMobileNumber(map.containsKey("mobile") ? map.get("mobile") : "");
|
|
|
265 |
user.setEmailId(map.get("registeredEmail1"));
|
|
|
266 |
user.setUsername(map.get("registeredEmail1"));
|
|
|
267 |
user.setPassword("");
|
|
|
268 |
user.setMobile_verified(false);
|
|
|
269 |
user.setReferral_url("");
|
|
|
270 |
user.setGroup_id(1);
|
| 22504 |
amit.gupta |
271 |
user.setStatus(1);
|
| 23300 |
amit.gupta |
272 |
user.setActivated(true);
|
| 22476 |
ashik.ali |
273 |
user.setCreateTimestamp(LocalDateTime.now());
|
|
|
274 |
user.setUpdateTimestamp(LocalDateTime.now());
|
|
|
275 |
userRepository.persist(user);
|
|
|
276 |
}
|
|
|
277 |
|
|
|
278 |
|
| 22471 |
ashik.ali |
279 |
//in.shop2020.model.v1.user.User saholicUser = Utils.createSaholicUser(map.get("registeredEmail1"));
|
| 22352 |
ashik.ali |
280 |
|
| 22471 |
ashik.ali |
281 |
com.spice.profitmandi.dao.entity.user.User saholicUser = null;
|
|
|
282 |
boolean foundRetailer = false;
|
| 23067 |
ashik.ali |
283 |
try{
|
|
|
284 |
saholicUser = userUserRepository.selectByEmailId(user.getEmailId());
|
|
|
285 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
286 |
|
|
|
287 |
}
|
| 22471 |
ashik.ali |
288 |
if(saholicUser == null){
|
|
|
289 |
Cart cart = new Cart();
|
|
|
290 |
cart.setCartStatus(CartStatus.ACTIVE);
|
|
|
291 |
cartRepository.persist(cart);
|
|
|
292 |
saholicUser = new com.spice.profitmandi.dao.entity.user.User();
|
|
|
293 |
saholicUser.setEmailId(user.getEmailId());
|
|
|
294 |
saholicUser.setName(map.containsKey("registeredBusinessName") ? map.get("registeredBusinessName") : "");
|
|
|
295 |
saholicUser.setActiveCartId(cart.getId());
|
| 23300 |
amit.gupta |
296 |
saholicUser.setCreateTimestamp(LocalDateTime.now());
|
| 22471 |
ashik.ali |
297 |
userUserRepository.persist(saholicUser);
|
|
|
298 |
}else{
|
|
|
299 |
foundRetailer = true;
|
|
|
300 |
}
|
|
|
301 |
|
| 22476 |
ashik.ali |
302 |
Retailer retailer = null;
|
| 22471 |
ashik.ali |
303 |
|
| 22476 |
ashik.ali |
304 |
try{
|
|
|
305 |
retailer = retailerRepository.selectById(saholicUser.getId());
|
|
|
306 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
307 |
retailer = new Retailer();
|
|
|
308 |
}
|
| 23443 |
amit.gupta |
309 |
retailer.setActive(true);
|
|
|
310 |
retailer.setId(saholicUser.getId());
|
|
|
311 |
retailer.setMigrated(true);
|
|
|
312 |
retailer.setName(map.containsKey("registeredBusinessName") ? map.get("registeredBusinessName") : "");
|
|
|
313 |
retailer.setType(RetailerType.GSTIN);
|
|
|
314 |
retailerRepository.persist(retailer);
|
| 22352 |
ashik.ali |
315 |
|
| 22476 |
ashik.ali |
316 |
|
| 22352 |
ashik.ali |
317 |
Address retailerAddress = new Address();
|
|
|
318 |
|
| 23880 |
ashik.ali |
319 |
List<Address> retailerAddresses = addressRepository.selectAllByRetailerId(retailer.getId(), 1, 100);
|
| 22476 |
ashik.ali |
320 |
if(retailerAddresses.isEmpty()){
|
|
|
321 |
retailerAddress.setCity(map.containsKey(ProfitMandiConstants.CITY) ? map.get(ProfitMandiConstants.CITY) : "");
|
|
|
322 |
retailerAddress.setCountry("India");
|
|
|
323 |
retailerAddress.setEnabled(true);
|
|
|
324 |
retailerAddress.setLandmark("");
|
|
|
325 |
retailerAddress.setLine1(map.containsKey(ProfitMandiConstants.LINE1) ? map.get(ProfitMandiConstants.LINE1) : "");
|
|
|
326 |
retailerAddress.setLine2(map.containsKey(ProfitMandiConstants.LINE2) ? map.get(ProfitMandiConstants.LINE2) : "");
|
|
|
327 |
retailerAddress.setName(map.containsKey("registeredBusinessName") ? map.get("registeredBusinessName") : "");
|
|
|
328 |
retailerAddress.setPhoneNumber(map.containsKey("mobile") ? map.get("mobile") : "");
|
|
|
329 |
retailerAddress.setPinCode(map.containsKey("pincode") ? map.get("pincode") : "");
|
|
|
330 |
retailerAddress.setState(map.containsKey(ProfitMandiConstants.STATE) ? map.get(ProfitMandiConstants.STATE) : "");
|
|
|
331 |
retailerAddress.setRetaierId(retailer.getId());
|
|
|
332 |
addressRepository.persist(retailerAddress);
|
|
|
333 |
}
|
| 22352 |
ashik.ali |
334 |
|
|
|
335 |
|
| 22476 |
ashik.ali |
336 |
RetailerRegisteredAddress retailerRegisteredAddress = null;
|
|
|
337 |
try{
|
|
|
338 |
retailerRegisteredAddress = retailerRegisteredAddressRepository.selectByAddressIdAndRetailerId(retailerAddress.getId(), retailer.getId());
|
| 23075 |
ashik.ali |
339 |
//retailerRegisteredAddress = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailer.getId());
|
| 22476 |
ashik.ali |
340 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
341 |
retailerRegisteredAddress = new RetailerRegisteredAddress();
|
|
|
342 |
retailerRegisteredAddress.setAddressId(retailerAddress.getId());
|
|
|
343 |
retailerRegisteredAddress.setRetailerId(retailer.getId());
|
|
|
344 |
retailerRegisteredAddressRepository.persist(retailerRegisteredAddress);
|
|
|
345 |
}
|
| 22471 |
ashik.ali |
346 |
|
| 22476 |
ashik.ali |
347 |
|
| 23066 |
ashik.ali |
348 |
List<Shop> shops = shopRepository.selectByRetailerId(retailer.getId());
|
|
|
349 |
if(shops.isEmpty()){
|
|
|
350 |
Shop shop = new Shop();
|
|
|
351 |
shop.setName(retailer.getName());
|
|
|
352 |
shop.setAddressId(retailerAddress.getId());
|
|
|
353 |
shop.setDocumentId(retailer.getDocumentId());
|
|
|
354 |
shop.setRetailerId(retailer.getId());
|
|
|
355 |
shopRepository.persist(shop);
|
|
|
356 |
ShopAddress shopAddress = new ShopAddress();
|
|
|
357 |
shopAddress.setAddressId(retailerAddress.getId());
|
|
|
358 |
shopAddress.setShopId(shop.getId());
|
|
|
359 |
shopAddressRepository.persist(shopAddress);
|
|
|
360 |
}
|
|
|
361 |
|
| 23269 |
ashik.ali |
362 |
UserAccount saholicUserAccounts = null;
|
| 22476 |
ashik.ali |
363 |
try{
|
|
|
364 |
saholicUserAccounts = userAccountRepository.selectByUserIdRetailerIdAccountType(user.getId(), retailer.getId(), AccountType.saholic);
|
|
|
365 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| 23269 |
ashik.ali |
366 |
saholicUserAccounts = new UserAccount();
|
|
|
367 |
saholicUserAccounts.setAccountKey(saholicUser.getId());
|
|
|
368 |
saholicUserAccounts.setType(AccountType.saholic);
|
|
|
369 |
saholicUserAccounts.setUserId(user.getId());
|
| 22476 |
ashik.ali |
370 |
userAccountRepository.persist(saholicUserAccounts);
|
| 23269 |
ashik.ali |
371 |
UserAccount cartUserAccounts = new UserAccount();
|
|
|
372 |
cartUserAccounts.setAccountKey(saholicUser.getActiveCartId());
|
|
|
373 |
cartUserAccounts.setType(AccountType.cartId);
|
|
|
374 |
cartUserAccounts.setUserId(user.getId());
|
| 22476 |
ashik.ali |
375 |
userAccountRepository.persist(cartUserAccounts);
|
|
|
376 |
}
|
|
|
377 |
|
| 23781 |
ashik.ali |
378 |
Role roleUser = roleRepository.selectByName(RoleType.USER.toString());
|
| 22476 |
ashik.ali |
379 |
|
|
|
380 |
UserRole userRole = null;
|
| 23781 |
ashik.ali |
381 |
|
| 22476 |
ashik.ali |
382 |
try{
|
| 23781 |
ashik.ali |
383 |
userRole = userRoleRepository.selectByUserIdAndRoleId(user.getId(), roleUser.getId());
|
| 22476 |
ashik.ali |
384 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| 23781 |
ashik.ali |
385 |
Role role = roleRepository.selectByName(RoleType.USER.toString());
|
| 22476 |
ashik.ali |
386 |
userRole = new UserRole();
|
| 23781 |
ashik.ali |
387 |
userRole.setRoleId(role.getId());
|
| 22476 |
ashik.ali |
388 |
userRole.setUserId(user.getId());
|
|
|
389 |
userRoleRepository.persist(userRole);
|
|
|
390 |
}
|
|
|
391 |
|
| 23781 |
ashik.ali |
392 |
Role roleRetailer = roleRepository.selectByName(RoleType.RETAILER.toString());
|
|
|
393 |
|
| 22476 |
ashik.ali |
394 |
UserRole retailerRole = null;
|
|
|
395 |
try{
|
| 23781 |
ashik.ali |
396 |
retailerRole = userRoleRepository.selectByUserIdAndRoleId(user.getId(), roleRetailer.getId());
|
| 22476 |
ashik.ali |
397 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| 23781 |
ashik.ali |
398 |
Role role = roleRepository.selectByName(RoleType.RETAILER.toString());
|
| 22476 |
ashik.ali |
399 |
retailerRole = new UserRole();
|
| 23781 |
ashik.ali |
400 |
retailerRole.setRoleId(role.getId());
|
| 22476 |
ashik.ali |
401 |
retailerRole.setUserId(user.getId());
|
|
|
402 |
userRoleRepository.persist(retailerRole);
|
|
|
403 |
}
|
|
|
404 |
|
| 23781 |
ashik.ali |
405 |
Role roleFofo = roleRepository.selectByName(RoleType.FOFO.toString());
|
|
|
406 |
|
| 22476 |
ashik.ali |
407 |
UserRole fofoRole = null;
|
|
|
408 |
try{
|
| 23781 |
ashik.ali |
409 |
fofoRole = userRoleRepository.selectByUserIdAndRoleId(user.getId(), roleFofo.getId());
|
| 22476 |
ashik.ali |
410 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| 23781 |
ashik.ali |
411 |
Role role = roleRepository.selectByName(RoleType.FOFO.toString());
|
| 22476 |
ashik.ali |
412 |
fofoRole = new UserRole();
|
| 23781 |
ashik.ali |
413 |
fofoRole.setRoleId(role.getId());
|
| 22476 |
ashik.ali |
414 |
fofoRole.setUserId(user.getId());
|
|
|
415 |
userRoleRepository.persist(fofoRole);
|
|
|
416 |
}
|
|
|
417 |
|
| 23365 |
ashik.ali |
418 |
List<Integer> paymentOptionIds = fofoPartnerPaymentOptionRepository.selectPaymentOptionIdsByFofoId(retailer.getId());
|
|
|
419 |
if(paymentOptionIds.isEmpty()){
|
|
|
420 |
PaymentOption paymentOption = null;
|
|
|
421 |
try{
|
|
|
422 |
paymentOption = paymentOptionRepository.selectByName(PaymentOptionType.CASH.toString());
|
|
|
423 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
424 |
paymentOption = new PaymentOption();
|
|
|
425 |
paymentOption.setName(PaymentOptionType.CASH.toString());
|
|
|
426 |
paymentOptionRepository.persist(paymentOption);
|
|
|
427 |
}
|
|
|
428 |
FofoPartnerPaymentOption fofoPartnerPaymentOption = new FofoPartnerPaymentOption();
|
|
|
429 |
fofoPartnerPaymentOption.setFofoId(retailer.getId());
|
|
|
430 |
fofoPartnerPaymentOption.setPaymentOptionId(paymentOption.getId());
|
|
|
431 |
fofoPartnerPaymentOptionRepository.persist(fofoPartnerPaymentOption);
|
|
|
432 |
}
|
|
|
433 |
|
| 22471 |
ashik.ali |
434 |
if(foundRetailer){
|
|
|
435 |
LOGGER.info("\n\n\n****retailer found\n\n\n");
|
| 22608 |
ashik.ali |
436 |
PrivateDealUser privateDealUser = null;
|
|
|
437 |
try{
|
|
|
438 |
privateDealUser = privateDealUserRepository.selectById(saholicUser.getId());
|
|
|
439 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
440 |
LOGGER.error("PrivateDealUser not found : ", profitMandiBusinessException);
|
|
|
441 |
}
|
| 23066 |
ashik.ali |
442 |
|
| 22608 |
ashik.ali |
443 |
//= privateDealUserRepository.selectById(saholicUser.getId());
|
|
|
444 |
if(privateDealUser == null){
|
| 22471 |
ashik.ali |
445 |
Integer counterId = this.createCounter(user.getEmailId(), map.get("gst"), user.getMobileNumber(), retailer.getName(), retailerAddress.getId());
|
| 22608 |
ashik.ali |
446 |
this.createPrivateDealUser(saholicUser.getId(), counterId);
|
|
|
447 |
}else{
|
|
|
448 |
if(privateDealUser.getCounterId() == null){
|
|
|
449 |
Integer counterId = this.createCounter(user.getEmailId(), map.get("gst"), user.getMobileNumber(), retailer.getName(), retailerAddress.getId());
|
|
|
450 |
privateDealUser.setCounterId(counterId);
|
| 23066 |
ashik.ali |
451 |
privateDealUser.setFofo(true);
|
| 22608 |
ashik.ali |
452 |
privateDealUserRepository.persist(privateDealUser);
|
|
|
453 |
}
|
| 22471 |
ashik.ali |
454 |
}
|
|
|
455 |
}else{
|
|
|
456 |
LOGGER.info("retailer not found");
|
|
|
457 |
//gst number intergration with counter
|
|
|
458 |
Integer counterId = this.createCounter(user.getEmailId(), map.get("gst"), user.getMobileNumber(), retailer.getName(), retailerAddress.getId());
|
| 22608 |
ashik.ali |
459 |
PrivateDealUser privateDealUser = null;
|
|
|
460 |
try{
|
|
|
461 |
privateDealUser = privateDealUserRepository.selectById(saholicUser.getId());
|
|
|
462 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
463 |
LOGGER.error("PrivateDealUser not found : ", profitMandiBusinessException);
|
|
|
464 |
}
|
|
|
465 |
/* //= privateDealUserRepository.selectById(saholicUser.getId());
|
|
|
466 |
if(privateDealUser == null){
|
|
|
467 |
int counterId = this.createCounter(user.getEmailId(), map.get("gst"), user.getMobileNumber(), retailer.getName(), retailerAddress.getId());
|
|
|
468 |
this.createPrivateDealUser(saholicUser.getId(), counterId);
|
|
|
469 |
}*/
|
| 22471 |
ashik.ali |
470 |
|
| 22608 |
ashik.ali |
471 |
|
| 22471 |
ashik.ali |
472 |
if(privateDealUser != null){
|
|
|
473 |
//LOGGER.info("PrivateDealUser found with id [{}]", saholicUser.getId());
|
|
|
474 |
privateDealUser.setCounterId(counterId);
|
| 23066 |
ashik.ali |
475 |
privateDealUser.setFofo(true);
|
| 22471 |
ashik.ali |
476 |
privateDealUserRepository.update(privateDealUser);
|
|
|
477 |
}else{
|
|
|
478 |
LOGGER.info("PrivateDealUser not found with id [{}]", saholicUser.getId());
|
| 22608 |
ashik.ali |
479 |
this.createPrivateDealUser(saholicUser.getId(), counterId);
|
| 22471 |
ashik.ali |
480 |
}
|
|
|
481 |
PrivateDealUserAddressMapping privateDealUserAddressMapping = new PrivateDealUserAddressMapping();
|
| 23329 |
ashik.ali |
482 |
privateDealUserAddressMapping.setUserId(retailer.getId());
|
|
|
483 |
privateDealUserAddressMapping.setAddressId(retailerAddress.getId());
|
| 22471 |
ashik.ali |
484 |
privateDealUserAddressMappingRepository.persist(privateDealUserAddressMapping);
|
|
|
485 |
|
|
|
486 |
saholicUser.setAddressId(retailerAddress.getId());
|
|
|
487 |
userUserRepository.persist(saholicUser);
|
|
|
488 |
}
|
| 22352 |
ashik.ali |
489 |
}
|
| 22471 |
ashik.ali |
490 |
|
| 22352 |
ashik.ali |
491 |
}
|
| 22471 |
ashik.ali |
492 |
|
|
|
493 |
|
| 22352 |
ashik.ali |
494 |
}
|
|
|
495 |
|
| 22716 |
amit.gupta |
496 |
//Specifically set isFofo to true that has to be used by old system
|
| 22608 |
ashik.ali |
497 |
private void createPrivateDealUser(int retailerId, int counterId){
|
|
|
498 |
PrivateDealUser privateDealUser = new PrivateDealUser();
|
|
|
499 |
privateDealUser.setActive(true);
|
| 23443 |
amit.gupta |
500 |
privateDealUser.setBulkShipmentAmountLimit(100000);
|
| 22608 |
ashik.ali |
501 |
privateDealUser.setId(retailerId);
|
|
|
502 |
privateDealUser.setCounterId(counterId);
|
| 23066 |
ashik.ali |
503 |
privateDealUser.setFofo(true);
|
| 22608 |
ashik.ali |
504 |
privateDealUserRepository.persist(privateDealUser);
|
|
|
505 |
}
|
|
|
506 |
|
| 22471 |
ashik.ali |
507 |
private Integer createCounter(String emailId, String gstNumber, String mobileNumber, String name, int addressId){
|
|
|
508 |
if(gstNumber != null && !gstNumber.isEmpty()){
|
|
|
509 |
Counter counter = new Counter();
|
|
|
510 |
counter.setEmailId(emailId);
|
|
|
511 |
counter.setGstin(gstNumber);
|
|
|
512 |
counter.setMobileNumber(mobileNumber);
|
|
|
513 |
counter.setName(name);
|
|
|
514 |
counter.setAddressId(addressId);
|
| 23300 |
amit.gupta |
515 |
counter.setCreatedOn(LocalDateTime.now());
|
| 22471 |
ashik.ali |
516 |
counterRepository.persist(counter);
|
|
|
517 |
return counter.getId();
|
|
|
518 |
}else{
|
|
|
519 |
return null;
|
|
|
520 |
}
|
|
|
521 |
}
|
|
|
522 |
|
| 22352 |
ashik.ali |
523 |
public void migratePrivateDealToRetailer(){
|
|
|
524 |
|
|
|
525 |
}
|
| 22125 |
ashik.ali |
526 |
}
|