| Line 10... |
Line 10... |
| 10 |
|
10 |
|
| 11 |
import org.slf4j.Logger;
|
11 |
import org.slf4j.Logger;
|
| 12 |
import org.slf4j.LoggerFactory;
|
12 |
import org.slf4j.LoggerFactory;
|
| 13 |
import org.springframework.beans.factory.annotation.Autowired;
|
13 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 14 |
import org.springframework.beans.factory.annotation.Qualifier;
|
14 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| - |
|
15 |
import org.springframework.jdbc.object.UpdatableSqlQuery;
|
| 15 |
import org.springframework.stereotype.Component;
|
16 |
import org.springframework.stereotype.Component;
|
| 16 |
|
17 |
|
| 17 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
18 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 18 |
import com.spice.profitmandi.common.model.CustomAddress;
|
19 |
import com.spice.profitmandi.common.model.CustomAddress;
|
| 19 |
import com.spice.profitmandi.common.model.CustomShop;
|
20 |
import com.spice.profitmandi.common.model.CustomShop;
|
| Line 21... |
Line 22... |
| 21 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
22 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
| 22 |
import com.spice.profitmandi.dao.entity.dtr.RetailerRegisteredAddress;
|
23 |
import com.spice.profitmandi.dao.entity.dtr.RetailerRegisteredAddress;
|
| 23 |
import com.spice.profitmandi.dao.entity.dtr.Shop;
|
24 |
import com.spice.profitmandi.dao.entity.dtr.Shop;
|
| 24 |
import com.spice.profitmandi.dao.entity.dtr.ShopAddress;
|
25 |
import com.spice.profitmandi.dao.entity.dtr.ShopAddress;
|
| 25 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
26 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| - |
|
27 |
import com.spice.profitmandi.dao.entity.dtr.UserAccounts;
|
| 26 |
import com.spice.profitmandi.dao.entity.dtr.UserRole;
|
28 |
import com.spice.profitmandi.dao.entity.dtr.UserRole;
|
| 27 |
import com.spice.profitmandi.dao.entity.user.Address;
|
29 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| 28 |
import com.spice.profitmandi.dao.entity.user.Cart;
|
30 |
import com.spice.profitmandi.dao.entity.user.Cart;
|
| - |
|
31 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
| 29 |
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
|
32 |
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
|
| 30 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
|
33 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
|
| 31 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
34 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| 32 |
import com.spice.profitmandi.dao.repository.dtr.ShopAddressRepository;
|
35 |
import com.spice.profitmandi.dao.repository.dtr.ShopAddressRepository;
|
| 33 |
import com.spice.profitmandi.dao.repository.dtr.ShopRepository;
|
36 |
import com.spice.profitmandi.dao.repository.dtr.ShopRepository;
|
| Line 117... |
Line 120... |
| 117 |
throws ProfitMandiBusinessException {
|
120 |
throws ProfitMandiBusinessException {
|
| 118 |
Map<String, Object> map = this.getByEmailIdOrMobileNumber(updateRetailerRequest.getEmailIdOrMobileNumber());
|
121 |
Map<String, Object> map = this.getByEmailIdOrMobileNumber(updateRetailerRequest.getEmailIdOrMobileNumber());
|
| 119 |
User user = (User)map.get("user");
|
122 |
User user = (User)map.get("user");
|
| 120 |
Retailer retailer = (Retailer)map.get("retailer");
|
123 |
Retailer retailer = (Retailer)map.get("retailer");
|
| 121 |
if(retailer == null){
|
124 |
if(retailer == null){
|
| 122 |
retailer = this.updateRetailer(user.getEmailId(), retailer, updateRetailerRequest);
|
125 |
retailer = this.updateRetailer(user, retailer, updateRetailerRequest);
|
| 123 |
map.put("retailer", retailer);
|
126 |
map.put("retailer", retailer);
|
| 124 |
}
|
127 |
}
|
| 125 |
Address retailerAddress = (Address)map.get("retailerAddress");
|
128 |
Address retailerAddress = (Address)map.get("retailerAddress");
|
| 126 |
if(retailerAddress == null){
|
129 |
if(retailerAddress == null){
|
| 127 |
retailerAddress = this.updateRetailerAddress(retailerAddress, updateRetailerRequest.getAddress(), retailer.getId());
|
130 |
retailerAddress = this.updateRetailerAddress(retailerAddress, updateRetailerRequest.getAddress(), retailer.getId());
|
| Line 134... |
Line 137... |
| 134 |
}
|
137 |
}
|
| 135 |
this.updateRetailerShops(shops, updateRetailerRequest.getShops(), retailer.getId());
|
138 |
this.updateRetailerShops(shops, updateRetailerRequest.getShops(), retailer.getId());
|
| 136 |
return map;
|
139 |
return map;
|
| 137 |
}
|
140 |
}
|
| 138 |
|
141 |
|
| 139 |
private int createSaholicUser(String emailId, String retailerName){
|
142 |
private int createSaholicUser(User user, String retailerName){
|
| 140 |
com.spice.profitmandi.dao.entity.user.User saholicUser = null;
|
143 |
com.spice.profitmandi.dao.entity.user.User saholicUser = null;
|
| 141 |
try {
|
144 |
try {
|
| 142 |
saholicUser = userUserRepository.selectByEmailId(emailId);
|
145 |
saholicUser = userUserRepository.selectByEmailId(user.getEmailId());
|
| 143 |
}catch (ProfitMandiBusinessException e) {
|
146 |
}catch (ProfitMandiBusinessException e) {
|
| 144 |
LOGGER.info("User doesnt exist in old system");
|
147 |
LOGGER.info("User doesnt exist in old system");
|
| 145 |
}
|
148 |
}
|
| 146 |
if(saholicUser == null){
|
149 |
if(saholicUser == null){
|
| 147 |
Cart cart = new Cart();
|
150 |
Cart cart = new Cart();
|
| 148 |
cart.setCartStatus(CartStatus.ACTIVE);
|
151 |
cart.setCartStatus(CartStatus.ACTIVE);
|
| 149 |
cartRepository.persist(cart);
|
152 |
cartRepository.persist(cart);
|
| 150 |
saholicUser = new com.spice.profitmandi.dao.entity.user.User();
|
153 |
saholicUser = new com.spice.profitmandi.dao.entity.user.User();
|
| 151 |
saholicUser.setEmailId(emailId);
|
154 |
saholicUser.setEmailId(user.getEmailId());
|
| 152 |
saholicUser.setName(retailerName);
|
155 |
saholicUser.setName(retailerName);
|
| 153 |
saholicUser.setActiveCartId(cart.getId());
|
156 |
saholicUser.setActiveCartId(cart.getId());
|
| 154 |
userUserRepository.persist(saholicUser);
|
157 |
userUserRepository.persist(saholicUser);
|
| - |
|
158 |
|
| - |
|
159 |
UserAccounts ua = new UserAccounts();
|
| - |
|
160 |
ua.setAccount_key(String.valueOf(saholicUser.getId()));
|
| - |
|
161 |
ua.setUser_id(user.getId());
|
| - |
|
162 |
ua.setAccount_type(AccountType.saholic);
|
| - |
|
163 |
userAccountRepository.persist(ua);
|
| - |
|
164 |
|
| - |
|
165 |
UserAccounts ua2 = new UserAccounts();
|
| - |
|
166 |
ua2.setAccount_key(String.valueOf(saholicUser.getActiveCartId()));
|
| - |
|
167 |
ua2.setUser_id(user.getId());
|
| - |
|
168 |
ua2.setAccount_type(AccountType.cartId);
|
| - |
|
169 |
userAccountRepository.persist(ua2);
|
| 155 |
}
|
170 |
}
|
| 156 |
return saholicUser.getId();
|
171 |
return saholicUser.getId();
|
| 157 |
}
|
172 |
}
|
| 158 |
|
173 |
|
| 159 |
private Retailer updateRetailer(String emailId, Retailer retailer, UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException{
|
174 |
private Retailer updateRetailer(User user, Retailer retailer, UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException{
|
| 160 |
if(retailer == null){
|
175 |
if(retailer == null){
|
| 161 |
int saholicUserId = this.createSaholicUser(emailId, updateRetailerRequest.getName());
|
176 |
int saholicUserId = this.createSaholicUser(user, updateRetailerRequest.getName());
|
| 162 |
retailer = new Retailer();
|
177 |
retailer = new Retailer();
|
| 163 |
retailer.setId(saholicUserId);
|
178 |
retailer.setId(saholicUserId);
|
| 164 |
}
|
179 |
}
|
| 165 |
retailer.setName(updateRetailerRequest.getName());
|
180 |
retailer.setName(updateRetailerRequest.getName());
|
| 166 |
retailer.setNumber(updateRetailerRequest.getNumber());
|
181 |
retailer.setNumber(updateRetailerRequest.getNumber());
|