| Line 9... |
Line 9... |
| 9 |
|
9 |
|
| 10 |
import org.springframework.beans.factory.annotation.Autowired;
|
10 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 11 |
import org.springframework.stereotype.Component;
|
11 |
import org.springframework.stereotype.Component;
|
| 12 |
|
12 |
|
| 13 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
13 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| - |
|
14 |
import com.spice.profitmandi.common.model.CustomAddress;
|
| - |
|
15 |
import com.spice.profitmandi.common.model.CustomShop;
|
| - |
|
16 |
import com.spice.profitmandi.common.model.UpdateRetailerRequest;
|
| 14 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
17 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
| 15 |
import com.spice.profitmandi.dao.entity.dtr.Shop;
|
18 |
import com.spice.profitmandi.dao.entity.dtr.Shop;
|
| 16 |
import com.spice.profitmandi.dao.entity.dtr.ShopAddress;
|
19 |
import com.spice.profitmandi.dao.entity.dtr.ShopAddress;
|
| 17 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
20 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 18 |
import com.spice.profitmandi.dao.entity.dtr.UserRole;
|
21 |
import com.spice.profitmandi.dao.entity.dtr.UserRole;
|
| Line 109... |
Line 112... |
| 109 |
}
|
112 |
}
|
| 110 |
return map;
|
113 |
return map;
|
| 111 |
|
114 |
|
| 112 |
}
|
115 |
}
|
| 113 |
|
116 |
|
| - |
|
117 |
@SuppressWarnings("unchecked")
|
| - |
|
118 |
@Override
|
| - |
|
119 |
public Map<String, Object> updateRetailerDetails(UpdateRetailerRequest updateRetailerRequest)
|
| - |
|
120 |
throws ProfitMandiBusinessException {
|
| - |
|
121 |
Map<String, Object> map = this.getByEmailIdOrMobileNumber(updateRetailerRequest.getEmailIdOrMobileNumber());
|
| - |
|
122 |
Retailer retailer = (Retailer)map.get("retailer");
|
| - |
|
123 |
this.updateRetailer(retailer, updateRetailerRequest);
|
| - |
|
124 |
Address retailerAddress = (Address)map.get("retailerAddress");
|
| - |
|
125 |
this.updateAddress(retailerAddress, updateRetailerRequest.getAddress());
|
| - |
|
126 |
List<Shop> shops = (List<Shop>)map.get("shops");
|
| - |
|
127 |
this.updateRetailerShops(shops, updateRetailerRequest.getShops());
|
| - |
|
128 |
return map;
|
| - |
|
129 |
}
|
| - |
|
130 |
|
| - |
|
131 |
private void updateRetailer(Retailer retailer, UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException{
|
| - |
|
132 |
retailer.setName(updateRetailerRequest.getName());
|
| - |
|
133 |
retailer.setNumber(updateRetailerRequest.getNumber());
|
| - |
|
134 |
if(updateRetailerRequest.getDocumentId() > 0){
|
| - |
|
135 |
retailer.setDocumentId(updateRetailerRequest.getDocumentId());
|
| - |
|
136 |
}
|
| - |
|
137 |
retailerRepository.persist(retailer);
|
| - |
|
138 |
}
|
| - |
|
139 |
|
| - |
|
140 |
private void updateAddress(Address address, CustomAddress customAddress){
|
| - |
|
141 |
address.setName(customAddress.getName());
|
| - |
|
142 |
address.setLine1(customAddress.getLine1());
|
| - |
|
143 |
address.setLine2(customAddress.getLine2());
|
| - |
|
144 |
address.setCity(customAddress.getCity());
|
| - |
|
145 |
address.setPinCode(customAddress.getPinCode());
|
| - |
|
146 |
address.setState(customAddress.getState());
|
| - |
|
147 |
addressRepository.persist(address);
|
| - |
|
148 |
}
|
| - |
|
149 |
|
| - |
|
150 |
private void updateRetailerShops(List<Shop> shops, Set<CustomShop> customShops) throws ProfitMandiBusinessException{
|
| - |
|
151 |
|
| - |
|
152 |
//Shop foundShop = null;
|
| - |
|
153 |
for(Shop shop : shops){
|
| - |
|
154 |
for(CustomShop customShop : customShops){
|
| - |
|
155 |
if(shop.getId() == customShop.getShopId()){
|
| - |
|
156 |
if(customShop.getDocumentId() > 0){
|
| - |
|
157 |
shop.setDocumentId(customShop.getDocumentId());
|
| - |
|
158 |
shopRepository.persist(shop);
|
| - |
|
159 |
documentRepository.markDocumentAsPersisted(customShop.getDocumentId());
|
| - |
|
160 |
}
|
| - |
|
161 |
this.updateAddress(shop.getAddress(), customShop.getAddress());
|
| - |
|
162 |
}
|
| - |
|
163 |
}
|
| - |
|
164 |
}
|
| - |
|
165 |
}
|
| - |
|
166 |
|
| - |
|
167 |
|
| 114 |
private void addAddress(List<Shop> shops){
|
168 |
private void addAddress(List<Shop> shops){
|
| 115 |
Set<Integer> shopIds = this.toShopIds(shops);
|
169 |
Set<Integer> shopIds = this.toShopIds(shops);
|
| 116 |
if(shopIds.isEmpty()){
|
170 |
if(shopIds.isEmpty()){
|
| 117 |
return;
|
171 |
return;
|
| 118 |
}
|
172 |
}
|