Subversion Repositories SmartDukaan

Rev

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

Rev 24502 Rev 25962
Line 34... Line 34...
34
import com.spice.profitmandi.dao.model.UserCart;
34
import com.spice.profitmandi.dao.model.UserCart;
35
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
35
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
36
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
36
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
37
import com.spice.profitmandi.dao.util.ContentPojoPopulator;
37
import com.spice.profitmandi.dao.util.ContentPojoPopulator;
38
import com.spice.profitmandi.dao.util.LogisticsService;
38
import com.spice.profitmandi.dao.util.LogisticsService;
-
 
39
import com.spice.profitmandi.service.inventory.ItemBucketService;
39
import com.spice.profitmandi.thrift.clients.UserClient;
40
import com.spice.profitmandi.thrift.clients.UserClient;
40
import com.spice.profitmandi.web.req.AddCartRequest;
41
import com.spice.profitmandi.web.req.AddCartRequest;
41
import com.spice.profitmandi.web.req.CartItems;
42
import com.spice.profitmandi.web.req.CartItems;
42
import com.spice.profitmandi.web.res.CartResponse;
43
import com.spice.profitmandi.web.res.CartResponse;
43
import com.spice.profitmandi.web.res.ValidateCartResponse;
44
import com.spice.profitmandi.web.res.ValidateCartResponse;
Line 61... Line 62...
61
 
62
 
62
	@Autowired
63
	@Autowired
63
	private UserAccountRepository userAccountRepository;
64
	private UserAccountRepository userAccountRepository;
64
 
65
 
65
	@Autowired
66
	@Autowired
-
 
67
	private ItemBucketService itemBucketService;
-
 
68
 
-
 
69
	@Autowired
66
	private ContentPojoPopulator contentPojoPopulator;
70
	private ContentPojoPopulator contentPojoPopulator;
67
 
71
 
68
	@Autowired
72
	@Autowired
69
	private ItemRepository itemRepository;
73
	private ItemRepository itemRepository;
70
 
74
 
71
	public static final Map<String, Integer> MIN_BRAND_QTY_LIMIT = new HashMap<>();
75
	public static final Map<String, Integer> MIN_BRAND_QTY_LIMIT = new HashMap<>();
72
 
76
 
73
	static {
77
	static {
74
		//MIN_BRAND_QTY_LIMIT.put("Realme", 10);
78
		// MIN_BRAND_QTY_LIMIT.put("Realme", 10);
75
		MIN_BRAND_QTY_LIMIT.put("Reliance", 5);
79
		MIN_BRAND_QTY_LIMIT.put("Reliance", 5);
76
	}
80
	}
77
 
81
 
-
 
82
	@RequestMapping(value = ProfitMandiConstants.URL_CART, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
-
 
83
	@ApiImplicitParams({
-
 
84
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
-
 
85
	@ApiOperation(value = "Add items to cart")
-
 
86
	public ResponseEntity<?> validateCart(HttpServletRequest request,
-
 
87
			@RequestParam(value = "pincode", defaultValue = "110001") String pincode, @RequestParam int bucketId)
-
 
88
			throws Throwable {
-
 
89
 
-
 
90
		AddCartRequest cartRequest = new AddCartRequest();
-
 
91
		List<CartItems> ci = new ArrayList<>();
-
 
92
		itemBucketService.getBucketDetails(bucketId).stream().forEach(x -> {
-
 
93
			ci.add(new CartItems(x.getItemId(), x.getQuantity()));
-
 
94
		});
-
 
95
		cartRequest.setCartItems(ci.toArray(new CartItems[0]));
-
 
96
		return this.validateCart(request, cartRequest, "110001");
-
 
97
 
-
 
98
	}
-
 
99
 
78
	@RequestMapping(value = ProfitMandiConstants.URL_CART, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
100
	@RequestMapping(value = ProfitMandiConstants.URL_CART, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
79
	@ApiImplicitParams({
101
	@ApiImplicitParams({
80
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
102
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
81
	@ApiOperation(value = "Add items to cart")
103
	@ApiOperation(value = "Add items to cart")
82
	public ResponseEntity<?> validateCart(HttpServletRequest request, @RequestBody AddCartRequest cartRequest,
104
	public ResponseEntity<?> validateCart(HttpServletRequest request, @RequestBody AddCartRequest cartRequest,
Line 91... Line 113...
91
		List<ItemQuantity> itemQuantities = new ArrayList<ItemQuantity>();
113
		List<ItemQuantity> itemQuantities = new ArrayList<ItemQuantity>();
92
		CartItems[] cartItems = cartRequest.getCartItems();
114
		CartItems[] cartItems = cartRequest.getCartItems();
93
		List<Integer> itemsList = new ArrayList<Integer>();
115
		List<Integer> itemsList = new ArrayList<Integer>();
94
		// Only Keep Non Billable Stock if partner adds both
116
		// Only Keep Non Billable Stock if partner adds both
95
		boolean nogst = false;
117
		boolean nogst = false;
96
		
-
 
97
		
118
 
98
		for (CartItems ci : cartItems) {
119
		for (CartItems ci : cartItems) {
99
			if (ci.getQuantity() > 0 && itemRepository.selectById(ci.getItemId()).getHsnCode().equals("NOGST")) {
120
			if (ci.getQuantity() > 0 && itemRepository.selectById(ci.getItemId()).getHsnCode().equals("NOGST")) {
100
				nogst = true;
121
				nogst = true;
101
			}
122
			}
102
		}
123
		}
Line 113... Line 134...
113
			}
134
			}
114
			itemsList.add(ci.getItemId());
135
			itemsList.add(ci.getItemId());
115
			ItemQuantity iq = new ItemQuantity(ci.getItemId(), ci.getQuantity());
136
			ItemQuantity iq = new ItemQuantity(ci.getItemId(), ci.getQuantity());
116
			itemQuantities.add(iq);
137
			itemQuantities.add(iq);
117
		}
138
		}
118
		if (cartMessage == null)
139
		if (cartMessage == null) {
119
		{
-
 
120
			cartMessage = new JSONObject();
140
			cartMessage = new JSONObject();
121
		}
141
		}
122
 
142
 
123
		Client userClient = null;
143
		Client userClient = null;
124
		try {
144
		try {
Line 137... Line 157...
137
		JSONArray arr = cartObj.getJSONArray("cartItems");
157
		JSONArray arr = cartObj.getJSONArray("cartItems");
138
		int maxEstimate = -2;
158
		int maxEstimate = -2;
139
		boolean allSame = true;
159
		boolean allSame = true;
140
		int removedCount = 0;
160
		int removedCount = 0;
141
		cartObj.put("cartMessagesMerged", 0);
161
		cartObj.put("cartMessagesMerged", 0);
142
		
162
 
143
		for (int j = 0; j < arr.length(); j++) {
163
		for (int j = 0; j < arr.length(); j++) {
144
			JSONObject itemObj = arr.getJSONObject(j - removedCount);
164
			JSONObject itemObj = arr.getJSONObject(j - removedCount);
145
			if (!itemsList.contains(itemObj.getInt("itemId"))) {
165
			if (!itemsList.contains(itemObj.getInt("itemId"))) {
146
				if (itemObj.getInt("quantity") == 0) {
166
				if (itemObj.getInt("quantity") == 0) {
147
					arr.remove(j - removedCount);
167
					arr.remove(j - removedCount);
Line 163... Line 183...
163
						cartObj.put("cartMessagesMerged", cartObj.getInt("cartMessagesMerged") + 1);
183
						cartObj.put("cartMessagesMerged", cartObj.getInt("cartMessagesMerged") + 1);
164
					}
184
					}
165
				}
185
				}
166
			}
186
			}
167
			Item item = itemRepository.selectById(itemObj.getInt("itemId"));
187
			Item item = itemRepository.selectById(itemObj.getInt("itemId"));
168
			if(!brandQtyMap.containsKey(item.getBrand())) {
188
			if (!brandQtyMap.containsKey(item.getBrand())) {
169
				brandQtyMap.put(item.getBrand(), 0);
189
				brandQtyMap.put(item.getBrand(), 0);
170
			}
190
			}
171
			brandQtyMap.put(item.getBrand(), brandQtyMap.get(item.getBrand()) + itemObj.getInt("quantity"));
191
			brandQtyMap.put(item.getBrand(), brandQtyMap.get(item.getBrand()) + itemObj.getInt("quantity"));
172
			try {
192
			try {
173
				ProductPojo pp = contentPojoPopulator.getShortContent(itemObj.getLong("catalogItemId"));
193
				ProductPojo pp = contentPojoPopulator.getShortContent(itemObj.getLong("catalogItemId"));
Line 204... Line 224...
204
			arr.put(listdata.get(i));
224
			arr.put(listdata.get(i));
205
		}
225
		}
206
 
226
 
207
		cartObj.put("cartItems", arr);
227
		cartObj.put("cartItems", arr);
208
		JSONArray cartMessagesArray = new JSONArray();
228
		JSONArray cartMessagesArray = new JSONArray();
209
		for(Map.Entry<String, Integer> minBrandQtyLimit : MIN_BRAND_QTY_LIMIT.entrySet()) {
229
		for (Map.Entry<String, Integer> minBrandQtyLimit : MIN_BRAND_QTY_LIMIT.entrySet()) {
210
			if(brandQtyMap.containsKey(minBrandQtyLimit.getKey())) {
230
			if (brandQtyMap.containsKey(minBrandQtyLimit.getKey())) {
211
				if(brandQtyMap.get(minBrandQtyLimit.getKey()) < minBrandQtyLimit.getValue()) {
231
				if (brandQtyMap.get(minBrandQtyLimit.getKey()) < minBrandQtyLimit.getValue()) {
-
 
232
					cartMessagesArray
212
					cartMessagesArray.put(new JSONObject()
233
							.put(new JSONObject()
-
 
234
									.put("messageText",
-
 
235
											String.format("Minimum qty for %s brand should be %d",
213
					.put("messageText", String.format("Minimum qty for %s brand should be %d", minBrandQtyLimit.getKey(), minBrandQtyLimit.getValue()))
236
													minBrandQtyLimit.getKey(), minBrandQtyLimit.getValue()))
214
					.put("type", "warn"));
237
									.put("type", "warn"));
215
				}
238
				}
216
			}
239
			}
217
		}
240
		}
218
		
241
 
219
		for (String message : Arrays.asList("cartMessageOOS", "cartMessageUndeliverable", "cartMessageChanged",
242
		for (String message : Arrays.asList("cartMessageOOS", "cartMessageUndeliverable", "cartMessageChanged",
220
				"cartMessagesMerged")) {
243
				"cartMessagesMerged")) {
221
			int count = cartObj.getInt(message);
244
			int count = cartObj.getInt(message);
222
			if (count > 0) {
245
			if (count > 0) {
223
				String type = "danger";
246
				String type = "danger";
Line 238... Line 261...
238
					if (count == 1) {
261
					if (count == 1) {
239
						cartMessage.put("messageText", "One item is undeliverable");
262
						cartMessage.put("messageText", "One item is undeliverable");
240
					} else {
263
					} else {
241
						cartMessage.put("messageText", "Few items are underiverable");
264
						cartMessage.put("messageText", "Few items are underiverable");
242
					}
265
					}
243
				} else if(message.equals("cartMessageChanged")){
266
				} else if (message.equals("cartMessageChanged")) {
244
					if (count == 1) {
267
					if (count == 1) {
245
						cartMessage.put("messageText", "One item qty has changed");
268
						cartMessage.put("messageText", "One item qty has changed");
246
					} else {
269
					} else {
247
						cartMessage.put("messageText", "Few items qty have changed");
270
						cartMessage.put("messageText", "Few items qty have changed");
248
					}
271
					}
Line 250... Line 273...
250
				cartMessage.put("type", type);
273
				cartMessage.put("type", type);
251
				cartMessagesArray.put(cartMessage);
274
				cartMessagesArray.put(cartMessage);
252
			}
275
			}
253
		}
276
		}
254
		cartObj.put("cartMessages", cartMessagesArray);
277
		cartObj.put("cartMessages", cartMessagesArray);
255
		//Hardcode maxEstimate to -3 for managing brands quantity
278
		// Hardcode maxEstimate to -3 for managing brands quantity
256
		if (maxEstimate == -1) {
279
		if (maxEstimate == -1) {
257
			cartObj.put("estimateString", "Can't ship here");
280
			cartObj.put("estimateString", "Can't ship here");
258
		} else if (maxEstimate == -2) {
281
		} else if (maxEstimate == -2) {
259
			cartObj.put("estimateString", "Out of Stock");
282
			cartObj.put("estimateString", "Out of Stock");
260
		} else {
283
		} else {