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