Subversion Repositories SmartDukaan

Rev

Rev 24203 | Rev 24658 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21577 ashik.ali 1
package com.spice.profitmandi.web.controller;
2
 
22486 ashik.ali 3
import java.io.ByteArrayInputStream;
4
import java.io.ByteArrayOutputStream;
5
import java.io.InputStream;
23886 amit.gupta 6
import java.time.LocalDateTime;
24465 tejbeer 7
import java.util.ArrayList;
8
import java.util.Comparator;
9
import java.util.HashSet;
21577 ashik.ali 10
import java.util.List;
21654 ashik.ali 11
import java.util.Map;
24465 tejbeer 12
import java.util.Set;
13
import java.util.stream.Collectors;
21577 ashik.ali 14
 
15
import javax.servlet.http.HttpServletRequest;
21987 kshitij.so 16
import javax.servlet.http.HttpServletResponse;
21577 ashik.ali 17
 
23886 amit.gupta 18
import org.apache.logging.log4j.LogManager;
23568 govind 19
import org.apache.logging.log4j.Logger;
24465 tejbeer 20
import org.json.JSONObject;
21577 ashik.ali 21
import org.springframework.beans.factory.annotation.Autowired;
23784 ashik.ali 22
import org.springframework.beans.factory.annotation.Qualifier;
21987 kshitij.so 23
import org.springframework.beans.factory.annotation.Value;
22486 ashik.ali 24
import org.springframework.core.io.InputStreamResource;
23886 amit.gupta 25
import org.springframework.format.annotation.DateTimeFormat;
26
import org.springframework.format.annotation.DateTimeFormat.ISO;
22486 ashik.ali 27
import org.springframework.http.HttpHeaders;
28
import org.springframework.http.HttpStatus;
22472 ashik.ali 29
import org.springframework.http.ResponseEntity;
21577 ashik.ali 30
import org.springframework.stereotype.Controller;
21654 ashik.ali 31
import org.springframework.transaction.annotation.Transactional;
21577 ashik.ali 32
import org.springframework.ui.Model;
22472 ashik.ali 33
import org.springframework.web.bind.annotation.RequestBody;
21577 ashik.ali 34
import org.springframework.web.bind.annotation.RequestMapping;
22472 ashik.ali 35
import org.springframework.web.bind.annotation.RequestMethod;
21577 ashik.ali 36
import org.springframework.web.bind.annotation.RequestParam;
37
 
21987 kshitij.so 38
import com.google.gson.Gson;
21577 ashik.ali 39
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
24465 tejbeer 40
import com.spice.profitmandi.common.model.CatalogListingModel;
21612 ashik.ali 41
import com.spice.profitmandi.common.model.CustomCurrentInventorySnapshot;
24106 tejbeer 42
import com.spice.profitmandi.common.model.CustomRetailer;
22472 ashik.ali 43
import com.spice.profitmandi.common.model.InventoryItemAgingModel;
24106 tejbeer 44
import com.spice.profitmandi.common.model.ItemFeatureDataModel;
45
import com.spice.profitmandi.common.model.NotificationDataModel;
21577 ashik.ali 46
import com.spice.profitmandi.common.model.ProfitMandiConstants;
22472 ashik.ali 47
import com.spice.profitmandi.common.util.ExcelUtils;
21987 kshitij.so 48
import com.spice.profitmandi.common.util.Utils;
24123 tejbeer 49
import com.spice.profitmandi.dao.entity.catalog.Item;
24106 tejbeer 50
import com.spice.profitmandi.dao.entity.catalog.TagRanking;
51
import com.spice.profitmandi.dao.entity.dtr.NotificationData;
24465 tejbeer 52
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
53
import com.spice.profitmandi.dao.entity.fofo.LiveDemoSerialNumber;
24106 tejbeer 54
import com.spice.profitmandi.dao.entity.transaction.AddWalletRequest;
55
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
24123 tejbeer 56
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
24106 tejbeer 57
import com.spice.profitmandi.dao.repository.catalog.TagRankingRepository;
24465 tejbeer 58
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
24203 amit.gupta 59
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
24465 tejbeer 60
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
61
import com.spice.profitmandi.dao.repository.fofo.LiveDemoBillingRespository;
22927 ashik.ali 62
import com.spice.profitmandi.service.inventory.InventoryService;
24465 tejbeer 63
import com.spice.profitmandi.service.user.RetailerService;
22139 amit.gupta 64
import com.spice.profitmandi.web.model.LoginDetails;
22069 ashik.ali 65
import com.spice.profitmandi.web.util.CookiesProcessor;
24106 tejbeer 66
import com.spice.profitmandi.web.util.MVCResponseSender;
21577 ashik.ali 67
 
68
@Controller
24123 tejbeer 69
@Transactional(rollbackFor = Throwable.class)
21577 ashik.ali 70
public class InventoryController {
21987 kshitij.so 71
 
23568 govind 72
	private static final Logger LOGGER = LogManager.getLogger(InventoryController.class);
21987 kshitij.so 73
 
21577 ashik.ali 74
	@Autowired
22927 ashik.ali 75
	private CookiesProcessor cookiesProcessor;
24123 tejbeer 76
 
22354 ashik.ali 77
	@Autowired
23784 ashik.ali 78
	@Qualifier("fofoInventoryService")
22927 ashik.ali 79
	private InventoryService inventoryService;
24465 tejbeer 80
 
24203 amit.gupta 81
	@Autowired
82
	private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
24123 tejbeer 83
 
24106 tejbeer 84
	@Autowired
85
	private TagRankingRepository tagRankingRepository;
24123 tejbeer 86
 
24106 tejbeer 87
	@Autowired
24465 tejbeer 88
	private InventoryItemRepository inventoryItemRepository;
89
 
90
	@Autowired
91
	private LiveDemoBillingRespository liveDemoBillingRespository;
92
 
93
	@Autowired
24123 tejbeer 94
	private ItemRepository itemRepository;
95
 
96
	@Autowired
24465 tejbeer 97
	private RetailerService retailerService;
98
 
99
	@Autowired
24106 tejbeer 100
	private MVCResponseSender mvcResponseSender;
24123 tejbeer 101
 
24465 tejbeer 102
	@Autowired
103
	FofoStoreRepository fofoStoreRepository;
104
 
21987 kshitij.so 105
	@Value("${saholic.api.host}")
106
	private String host;
23786 amit.gupta 107
 
21987 kshitij.so 108
	@Value("${saholic.api.port}")
109
	private int port;
23786 amit.gupta 110
 
21987 kshitij.so 111
	@Value("${saholic.api.webapp}")
112
	private String webapp;
113
 
23786 amit.gupta 114
	@RequestMapping(value = "/getCurrentInventorySnapshot")
115
	public String getCurrentAvailability(HttpServletRequest request,
116
			@RequestParam(name = "offset", defaultValue = "0") int offset,
117
			@RequestParam(name = "limit", defaultValue = "10") int limit,
24123 tejbeer 118
			@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
23786 amit.gupta 119
			throws ProfitMandiBusinessException {
22927 ashik.ali 120
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23786 amit.gupta 121
		Map<String, Object> map = inventoryService.getCurrentInventorySnapshot(loginDetails.getFofoId(), offset, limit,
122
				searchTerm);
22927 ashik.ali 123
		model.addAllAttributes(map);
21987 kshitij.so 124
		return "inventory-snapshot";
21612 ashik.ali 125
	}
21987 kshitij.so 126
 
23786 amit.gupta 127
	@RequestMapping(value = "/getBadInventorySnapshot")
128
	public String getBadAvailability(HttpServletRequest request,
129
			@RequestParam(name = "offset", defaultValue = "0") int offset,
130
			@RequestParam(name = "limit", defaultValue = "10") int limit,
131
			@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
132
			throws ProfitMandiBusinessException {
24123 tejbeer 133
		if (searchTerm == null) {
134
			searchTerm = "";
24052 amit.gupta 135
		}
22927 ashik.ali 136
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23786 amit.gupta 137
		Map<String, Object> map = inventoryService.getBadInventorySnapshot(loginDetails.getFofoId(), offset, limit,
138
				searchTerm);
22927 ashik.ali 139
		model.addAllAttributes(map);
21987 kshitij.so 140
		return "bad-inventory-snapshot";
141
	}
142
 
23786 amit.gupta 143
	@RequestMapping(value = "/getPaginatedCurrentInventorySnapshot")
144
	public String getPaginatedCurrentInventorySnapshot(HttpServletRequest request,
145
			@RequestParam(name = "offset", defaultValue = "0") int offset,
146
			@RequestParam(name = "limit", defaultValue = "10") int limit,
147
			@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
148
			throws ProfitMandiBusinessException {
24123 tejbeer 149
		if (searchTerm == null) {
150
			searchTerm = "";
24052 amit.gupta 151
		}
22927 ashik.ali 152
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23786 amit.gupta 153
		Map<String, Object> map = inventoryService.getPaginatedCurrentInventorySnapshot(loginDetails.getFofoId(),
154
				offset, limit, searchTerm);
22927 ashik.ali 155
		model.addAllAttributes(map);
21987 kshitij.so 156
		return "inventory-snapshot-paginated";
157
	}
23786 amit.gupta 158
 
159
	@RequestMapping(value = "/getCatalog")
160
	public String getCatalog(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset,
161
			@RequestParam(name = "limit", defaultValue = "10") int limit,
162
			@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
163
			throws ProfitMandiBusinessException {
22927 ashik.ali 164
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
24123 tejbeer 165
		if (searchTerm == null) {
166
			searchTerm = "";
24052 amit.gupta 167
		}
24465 tejbeer 168
 
22927 ashik.ali 169
		Map<String, Object> map = inventoryService.getCatalog(loginDetails.getFofoId(), offset, limit, searchTerm);
170
		model.addAllAttributes(map);
24203 amit.gupta 171
		model.addAttribute("hasGift", hasGift(loginDetails.getFofoId()));
21987 kshitij.so 172
		return "catalog";
173
	}
23786 amit.gupta 174
 
24465 tejbeer 175
	// This method is currently hardcoded to faciliate watches sold as gift.
24203 amit.gupta 176
	private boolean hasGift(int fofoId) {
177
		try {
24465 tejbeer 178
			return currentInventorySnapshotRepository.selectByItemIdAndFofoId(ProfitMandiConstants.GIFT_ID, fofoId)
179
					.getAvailability() > 0;
24203 amit.gupta 180
		} catch (ProfitMandiBusinessException e) {
181
			return false;
182
		}
183
	}
184
 
23786 amit.gupta 185
	@RequestMapping(value = "/getPaginatedCatalog")
186
	public String getCatalogPaginated(HttpServletRequest request,
187
			@RequestParam(name = "offset", defaultValue = "0") int offset,
188
			@RequestParam(name = "limit", defaultValue = "10") int limit,
189
			@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
190
			throws ProfitMandiBusinessException {
22927 ashik.ali 191
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
24123 tejbeer 192
		if (searchTerm == null) {
193
			searchTerm = "";
24052 amit.gupta 194
		}
23786 amit.gupta 195
		Map<String, Object> map = inventoryService.getPaginatedCatalog(loginDetails.getFofoId(), offset, limit,
196
				searchTerm);
22927 ashik.ali 197
		model.addAllAttributes(map);
21987 kshitij.so 198
		return "catalog-paginated";
199
	}
200
 
23786 amit.gupta 201
	@RequestMapping(value = "/checkItemAvailability")
202
	public String getItemAvailability(HttpServletRequest request,
203
			@RequestParam(name = ProfitMandiConstants.ITEM_ID) int itemId, Model model)
204
			throws ProfitMandiBusinessException {
22927 ashik.ali 205
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23786 amit.gupta 206
		CustomCurrentInventorySnapshot customCurrentInventorySnapshot = inventoryService.checkItemAvailability(itemId,
207
				loginDetails.getFofoId());
208
		customCurrentInventorySnapshot
209
				.setIconUrl(Utils.getIconUrl(customCurrentInventorySnapshot.getCatalogItemId(), host, port, webapp));
22927 ashik.ali 210
		model.addAttribute("currentInventorySnapshot", new Gson().toJson(customCurrentInventorySnapshot));
211
		return "current-item-availability";
23786 amit.gupta 212
 
21577 ashik.ali 213
	}
23786 amit.gupta 214
 
23192 ashik.ali 215
	@RequestMapping(value = "/cart", method = RequestMethod.POST)
23786 amit.gupta 216
	public String addToCart(HttpServletRequest request, @RequestParam(name = "cartData") String cartData, Model model)
217
			throws ProfitMandiBusinessException {
22927 ashik.ali 218
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23786 amit.gupta 219
 
22927 ashik.ali 220
		Map<String, Object> map = inventoryService.addToCart(cartData, loginDetails.getFofoId());
221
		model.addAllAttributes(map);
21987 kshitij.so 222
		return "cart";
223
	}
23786 amit.gupta 224
 
23192 ashik.ali 225
	@RequestMapping(value = "/validate-cart", method = RequestMethod.POST)
23786 amit.gupta 226
	public String validateCart(HttpServletRequest request, HttpServletResponse response,
227
			@RequestParam(name = "cartData") String cartData, Model model) throws ProfitMandiBusinessException {
22927 ashik.ali 228
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23786 amit.gupta 229
 
22927 ashik.ali 230
		Map<String, Object> map = inventoryService.validateCart(cartData, loginDetails.getFofoId());
231
		model.addAllAttributes(map);
21987 kshitij.so 232
		return "validate-cart";
233
	}
234
 
23786 amit.gupta 235
	@RequestMapping(value = "/grnHistory")
24123 tejbeer 236
	public String getGrnHistory(HttpServletRequest request, @RequestParam(required = false) LocalDateTime startTime,
23886 amit.gupta 237
			@RequestParam(required = false) LocalDateTime endTime,
23786 amit.gupta 238
			@RequestParam(name = "offset", defaultValue = "0") int offset,
239
			@RequestParam(name = "limit", defaultValue = "10") int limit,
240
			@RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE, defaultValue = "") String purchaseReference,
241
			@RequestParam(name = "searchType", defaultValue = "") String searchType, Model model)
242
			throws ProfitMandiBusinessException {
22927 ashik.ali 243
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
24123 tejbeer 244
		Map<String, Object> map = inventoryService.getGrnHistory(loginDetails.getFofoId(), startTime, endTime, offset,
245
				limit, purchaseReference, searchType);
22927 ashik.ali 246
		model.addAllAttributes(map);
21987 kshitij.so 247
		return "grn-history";
21636 ashik.ali 248
	}
21987 kshitij.so 249
 
23786 amit.gupta 250
	@RequestMapping(value = "/getPaginatedGrnHistory")
251
	public String getPaginatedGrnHistory(HttpServletRequest request,
23886 amit.gupta 252
			@RequestParam(required = false) LocalDateTime startTime,
253
			@RequestParam(required = false) LocalDateTime endTime,
23786 amit.gupta 254
			@RequestParam(name = "offset", defaultValue = "0") int offset,
255
			@RequestParam(name = "limit", defaultValue = "10") int limit,
256
			@RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE, defaultValue = "") String purchaseReference,
257
			@RequestParam(name = "searchType", defaultValue = "") String searchType, Model model)
258
			throws ProfitMandiBusinessException {
22927 ashik.ali 259
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
24123 tejbeer 260
		Map<String, Object> map = inventoryService.getPaginatedGrnHistory(loginDetails.getFofoId(), startTime, endTime,
261
				offset, limit);
22927 ashik.ali 262
		model.addAllAttributes(map);
21987 kshitij.so 263
		return "grn-history-paginated";
264
	}
265
 
23786 amit.gupta 266
	@RequestMapping(value = "/grnHistoryDetailByPurchaseId")
267
	public String grnHistoryByPurchaseId(HttpServletRequest request,
268
			@RequestParam(name = ProfitMandiConstants.PURCHASE_ID) int purchaseId, Model model)
269
			throws ProfitMandiBusinessException {
22927 ashik.ali 270
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23786 amit.gupta 271
		Map<String, Object> map = inventoryService.getGrnHistoryDetail(loginDetails.getFofoId(), purchaseId, host, port,
272
				webapp);
22927 ashik.ali 273
		model.addAllAttributes(map);
21987 kshitij.so 274
		return "grn-details";
21636 ashik.ali 275
	}
21987 kshitij.so 276
 
23786 amit.gupta 277
	@RequestMapping(value = "/grnHistoryDetailByPurchaseReference")
278
	public String grnHistoryByPurchaseReference(HttpServletRequest request,
279
			@RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE) String purchaseReference, Model model)
280
			throws ProfitMandiBusinessException {
22927 ashik.ali 281
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23786 amit.gupta 282
		Map<String, Object> map = inventoryService.getGrnHistoryDetail(loginDetails.getFofoId(), purchaseReference,
283
				host, port, webapp);
22927 ashik.ali 284
		model.addAllAttributes(map);
21987 kshitij.so 285
		return "grn-details";
21654 ashik.ali 286
	}
23786 amit.gupta 287
 
22472 ashik.ali 288
	@RequestMapping(value = "/getInventoryItemAgingByInterval", method = RequestMethod.POST)
23786 amit.gupta 289
	public String getInventoryItemAgingByInterval(HttpServletRequest request, @RequestBody List<Integer> intervals,
290
			Model model, @RequestParam(name = "searchContent", defaultValue = "") String searchContent,
291
			@RequestParam(name = "offset", defaultValue = "0") int offset,
292
			@RequestParam(name = "limit", defaultValue = "10") int limit) throws ProfitMandiBusinessException {
22927 ashik.ali 293
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23786 amit.gupta 294
		Map<String, Object> map = inventoryService.getPaginatedItemAgingByInterval(loginDetails.getFofoId(), intervals,
295
				searchContent, offset, limit);
22927 ashik.ali 296
		model.addAllAttributes(map);
22523 ashik.ali 297
		return "item-aging";
298
	}
23786 amit.gupta 299
 
22523 ashik.ali 300
	@RequestMapping(value = "/downloadInventoryItemAgingByInterval", method = RequestMethod.POST)
23786 amit.gupta 301
	public ResponseEntity<?> downloadInventoryItemAgingByInterval(HttpServletRequest request,
302
			@RequestBody List<Integer> intervals, Model model) throws ProfitMandiBusinessException {
22927 ashik.ali 303
		LOGGER.info("Request received at url{} with body {}", request.getRequestURI(), intervals);
304
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
23786 amit.gupta 305
 
306
		List<InventoryItemAgingModel> inventoryItemAgingModels = inventoryService
307
				.getItemAgingByInterval(fofoDetails.getFofoId(), intervals);
308
 
22486 ashik.ali 309
		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
310
		ExcelUtils.writeInventoryItemAgingModels(inventoryItemAgingModels, intervals, byteArrayOutputStream);
23786 amit.gupta 311
 
312
		final HttpHeaders headers = new HttpHeaders();
313
		// private static final String CONTENT_TYPE_XLSX =
314
		// "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
315
		headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
316
		// headers.set("Content-Type", "application/vnd.ms-excel");
22486 ashik.ali 317
		headers.set("Content-disposition", "inline; filename=InventoryItemAging.xlsx");
23786 amit.gupta 318
		headers.setContentLength(byteArrayOutputStream.toByteArray().length);
319
		final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
320
		final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
321
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
322
 
24123 tejbeer 323
		// return
324
		// responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
22472 ashik.ali 325
	}
24123 tejbeer 326
 
24106 tejbeer 327
	@RequestMapping(value = "/featurePanel", method = RequestMethod.GET)
24123 tejbeer 328
	public String FeaturePanel(HttpServletRequest request,
329
			@RequestParam(name = "offset", defaultValue = "0") int offset,
24106 tejbeer 330
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Exception {
21987 kshitij.so 331
 
24106 tejbeer 332
		List<TagRanking> tagRanking = null;
333
 
334
		long size = 0;
24123 tejbeer 335
		tagRanking = tagRankingRepository.selectAllTagRanking(offset, limit);
336
		size = tagRankingRepository.selectAllCount();
24106 tejbeer 337
		LOGGER.info("tagRanking" + tagRanking);
338
		if (!tagRanking.isEmpty()) {
24465 tejbeer 339
			model.addAttribute("tagRanking", tagRanking);
24106 tejbeer 340
			model.addAttribute("start", offset + 1);
341
			model.addAttribute("size", size);
342
			model.addAttribute("url", "/getPaginatedfeature");
343
 
344
			if (tagRanking.size() < limit) {
345
				model.addAttribute("end", offset + tagRanking.size());
346
			} else {
347
				model.addAttribute("end", offset + limit);
348
			}
349
		} else {
350
			model.addAttribute("tagRanking", tagRanking);
351
			model.addAttribute("size", size);
352
		}
353
 
354
		return "feature";
355
 
356
	}
24123 tejbeer 357
 
24106 tejbeer 358
	@RequestMapping(value = "/getPaginatedfeature", method = RequestMethod.GET)
359
	public String getPaginatedFeaturePanel(HttpServletRequest request,
360
			@RequestParam(name = "offset", defaultValue = "0") int offset,
361
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
362
			throws ProfitMandiBusinessException {
363
		LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
364
		List<TagRanking> tagRanking = null;
365
 
366
		long size = 0;
24123 tejbeer 367
		tagRanking = tagRankingRepository.selectAllTagRanking(offset, limit);
24106 tejbeer 368
		if (!tagRanking.isEmpty()) {
24123 tejbeer 369
 
24106 tejbeer 370
			model.addAttribute("tagRanking", tagRanking);
371
			model.addAttribute("start", offset + 1);
372
			model.addAttribute("size", size);
373
			model.addAttribute("url", "/getPaginatedfeature");
374
 
375
		} else {
376
			model.addAttribute("tagRanking", tagRanking);
377
		}
378
		return "feature-paginated";
379
	}
24123 tejbeer 380
 
24106 tejbeer 381
	@RequestMapping(value = "/itemfeature", method = RequestMethod.POST)
24123 tejbeer 382
	public String Itemfeature(HttpServletRequest request, @RequestBody ItemFeatureDataModel itemFeatureDatatModel,
383
			Model model) throws Exception {
24106 tejbeer 384
 
385
		TagRanking tagRanking = new TagRanking();
386
		tagRanking.setRankPoints(itemFeatureDatatModel.getRankPoints());
387
		tagRanking.setCatalogItemId(itemFeatureDatatModel.getCatalogItemId());
388
		tagRanking.setFeature(itemFeatureDatatModel.getFeature());
24123 tejbeer 389
 
390
		LOGGER.info("tagRanking" + tagRanking);
391
		tagRankingRepository.persist(tagRanking);
24106 tejbeer 392
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
393
		return "response";
394
	}
395
 
24465 tejbeer 396
	@RequestMapping(value = "/getDemolistbyfofoId", method = RequestMethod.GET)
397
	public String DemoListbyFofoId(HttpServletRequest request,
398
			@RequestParam(required = false, defaultValue = "0") int fofoId, Model model) throws Exception {
399
 
400
		List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
401
				.collect(Collectors.toList());
402
		Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
403
		String customRetailers = JSONObject.valueToString(customRetailersMap.values());
404
		List<String> serailNumberList = liveDemoBillingRespository.selectAllSerialNumber();
405
		LOGGER.info("serailNumberList" + serailNumberList);
406
		List<InventoryItem> inventoryItem = null;
407
		List<InventoryItem> inventoryItem1 = new ArrayList<>();
408
		if (fofoId > 0) {
409
			List<Item> items = itemRepository.selectAllByBrand("Live Demo");
410
			Set<Integer> itemIds = new HashSet<>();
411
			for (Item Item : items) {
412
				itemIds.add(Item.getId());
413
			}
414
			inventoryItem = inventoryItemRepository.selectByFofoIdItemIds(fofoId, itemIds);
415
 
416
			Set<String> serial = new HashSet<>();
417
			for (InventoryItem invItem : inventoryItem) {
418
				if(!serailNumberList.contains(invItem.getSerialNumber()))
419
				{
420
					inventoryItem1.add(invItem);
421
				}
422
 
423
			}
424
 
425
 
426
			LOGGER.info("inventoyItem" + inventoryItem1);
427
			model.addAttribute("customRetailers", customRetailers);
428
			model.addAttribute("liveDemo", inventoryItem1);
429
 
430
			CustomRetailer fofoIdsAndRetailerName = retailerService.getFofoRetailer(fofoId);
431
 
432
			model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
433
 
434
		}
435
 
436
		else {
437
			model.addAttribute("customRetailers", customRetailers);
438
			model.addAttribute("liveDemo", inventoryItem1);
439
		}
440
 
441
		return "live_demo_billing";
442
 
443
	}
444
 
445
	@RequestMapping(value = "/enableliveDemoSerailNumber", method = RequestMethod.POST)
446
	public String EnableliveDemoSerailNumber(HttpServletRequest request, @RequestParam String serial_number,
447
			Model model) throws Exception {
448
 
449
		LiveDemoSerialNumber liveDemoSerialNumber = new LiveDemoSerialNumber();
450
		liveDemoSerialNumber.setSerialNumber(serial_number);
451
 
452
		liveDemoBillingRespository.persist(liveDemoSerialNumber);
453
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
454
		return "response";
455
	}
456
 
21577 ashik.ali 457
}