Subversion Repositories SmartDukaan

Rev

Rev 23063 | Rev 23106 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 23063 Rev 23079
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;
-
 
16
import org.springframework.stereotype.Component;
15
import org.springframework.stereotype.Component;
17
 
16
 
18
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
17
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
19
import com.spice.profitmandi.common.model.CustomAddress;
18
import com.spice.profitmandi.common.model.CustomAddress;
20
import com.spice.profitmandi.common.model.CustomShop;
19
import com.spice.profitmandi.common.model.CustomShop;
Line 133... Line 132...
133
		List<Shop> shops = (List<Shop>)map.get("shops");
132
		List<Shop> shops = (List<Shop>)map.get("shops");
134
		if(shops == null){
133
		if(shops == null){
135
			shops = new ArrayList<>();
134
			shops = new ArrayList<>();
136
			map.put("shops", shops);
135
			map.put("shops", shops);
137
		}
136
		}
138
		this.updateRetailerShops(shops, updateRetailerRequest.getShops(), retailer.getId());
137
		this.updateRetailerShops(shops, updateRetailerRequest.getShops(), retailer.getId(), retailerAddress);
139
		return map;
138
		return map;
140
	}
139
	}
141
	
140
	
142
	private int createSaholicUser(User user, String retailerName){
141
	private int createSaholicUser(User user, String retailerName){
143
		com.spice.profitmandi.dao.entity.user.User saholicUser = null;
142
		com.spice.profitmandi.dao.entity.user.User saholicUser = null;
Line 209... Line 208...
209
		address.setPinCode(customAddress.getPinCode());
208
		address.setPinCode(customAddress.getPinCode());
210
		address.setState(customAddress.getState());
209
		address.setState(customAddress.getState());
211
		addressRepository.persist(address);
210
		addressRepository.persist(address);
212
	}
211
	}
213
	
212
	
214
	private void updateRetailerShops(List<Shop> shops, Set<CustomShop> customShops, int retailerId) throws ProfitMandiBusinessException{
213
	private void updateRetailerShops(List<Shop> shops, Set<CustomShop> customShops, int retailerId, Address sameAsRetailerAddressValue) throws ProfitMandiBusinessException{
215
		if(shops.isEmpty()){
214
		if(shops.isEmpty()){
216
			for(CustomShop customShop : customShops){
215
			for(CustomShop customShop : customShops){
217
				Shop shop = new Shop();
216
				Shop shop = new Shop();
218
				this.createOrUpdateShop(shop, customShop, retailerId);
217
				this.createOrUpdateShop(shop, customShop, retailerId, sameAsRetailerAddressValue);
219
				shops.add(shop);
218
				shops.add(shop);
220
			}
219
			}
221
		}else{
220
		}else{
222
			for(Shop shop : shops){
221
			for(Shop shop : shops){
223
				for(CustomShop customShop : customShops){
222
				for(CustomShop customShop : customShops){
224
					if(shop.getId() == customShop.getShopId()){
223
					if(shop.getId() == customShop.getShopId()){
225
						this.createOrUpdateShop(shop, customShop, retailerId);
224
						this.createOrUpdateShop(shop, customShop, retailerId, sameAsRetailerAddressValue);
226
					}
225
					}
227
				}
226
				}
228
			}
227
			}
229
			for(CustomShop customShop : customShops){
228
			for(CustomShop customShop : customShops){
230
				if(customShop.getShopId() == 0){
229
				if(customShop.getShopId() == 0){
231
					Shop shop = new Shop();
230
					Shop shop = new Shop();
232
					this.createOrUpdateShop(shop, customShop, retailerId);
231
					this.createOrUpdateShop(shop, customShop, retailerId, sameAsRetailerAddressValue);
233
					shops.add(shop);
232
					shops.add(shop);
234
				}
233
				}
235
			}
234
			}
236
		}
235
		}
237
	}
236
	}
238
	
237
	
239
	private void createOrUpdateShop(Shop shop, CustomShop customShop, int retailerId) throws ProfitMandiBusinessException{
238
	private void createOrUpdateShop(Shop shop, CustomShop customShop, int retailerId, Address sameAsRetailerAddressValue) throws ProfitMandiBusinessException{
240
		shop.setRetailerId(retailerId);
239
		shop.setRetailerId(retailerId);
241
		shop.setName(customShop.getName());
240
		shop.setName(customShop.getName());
242
		if(customShop.getDocumentId() > 0){
241
		if(customShop.getDocumentId() > 0){
243
			shop.setDocumentId(customShop.getDocumentId());
242
			shop.setDocumentId(customShop.getDocumentId());
244
			documentRepository.markDocumentAsPersisted(customShop.getDocumentId());
243
			documentRepository.markDocumentAsPersisted(customShop.getDocumentId());
245
		}
244
		}
246
		if(shop.getAddressId() == null){
245
		if(shop.getAddressId() == null){
-
 
246
			Address address = null;
-
 
247
			if(customShop.isSameAsRetailerAddress()){
-
 
248
				address = sameAsRetailerAddressValue;
-
 
249
			}else{
247
			//shop.setDocumentId(customShop.getDocumentId());
250
				//shop.setDocumentId(customShop.getDocumentId());
248
			Address address = new Address();
251
				address = new Address();
249
			this.updateAddress(address, customShop.getAddress());
252
				this.updateAddress(address, customShop.getAddress());
-
 
253
			}
250
			shop.setAddressId(address.getId());
254
			shop.setAddressId(address.getId());
251
			shop.setAddress(address);
255
			shop.setAddress(address);
252
			shopRepository.persist(shop);
256
			shopRepository.persist(shop);
253
			ShopAddress shopAddress = new ShopAddress();
257
			ShopAddress shopAddress = new ShopAddress();
254
			shopAddress.setAddressId(address.getId());
258
			shopAddress.setAddressId(address.getId());
255
			shopAddress.setShopId(shop.getId());
259
			shopAddress.setShopId(shop.getId());
256
			shopAddressRepository.persist(shopAddress);
260
			shopAddressRepository.persist(shopAddress);
257
		}else{
261
		}else{
258
			Address address = addressRepository.selectById(shop.getAddressId());
262
			Address address = addressRepository.selectById(shop.getAddressId());
-
 
263
			CustomAddress customAddress = customShop.getAddress();
-
 
264
			if(address.getName().equals(customAddress.getName()) &&
-
 
265
				address.getLine1().equals(customAddress.getLine1()) &&
-
 
266
				address.getLine2().equals(customAddress.getLine2())	&&
-
 
267
				address.getCity().equals(customAddress.getCity()) &&
-
 
268
				address.getPinCode().equals(customAddress.getPinCode()) &&
-
 
269
				address.getState().equals(customAddress.getState())){
259
			this.updateAddress(address, customShop.getAddress());
270
				this.updateAddress(address, customShop.getAddress());
-
 
271
			}else{
-
 
272
				address = new Address();
-
 
273
				ShopAddress shopAddress = shopAddressRepository.selectByShopId(shop.getId());
-
 
274
				this.updateAddress(address, customAddress);
-
 
275
				shopAddress.setAddressId(address.getId());
-
 
276
				shopAddressRepository.persist(shopAddress);
-
 
277
			}
-
 
278
			
260
			shop.setAddress(address);
279
			shop.setAddress(address);
261
			shopRepository.persist(shop);
280
			shopRepository.persist(shop);
262
		}
281
		}
263
		
282
		
264
	}
283
	}