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