Subversion Repositories SmartDukaan

Rev

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

Rev 24824 Rev 25378
Line 281... Line 281...
281
	}
281
	}
282
 
282
 
283
	@RequestMapping(value = "/itemsByCatalogId")
283
	@RequestMapping(value = "/itemsByCatalogId")
284
	public String getItemsByCatalogId(HttpServletRequest request, Model model,
284
	public String getItemsByCatalogId(HttpServletRequest request, Model model,
285
			@RequestParam(required = false) int catalogId, @RequestParam(required = false) int itemId)
285
			@RequestParam(required = false) int catalogId, @RequestParam(required = false) int itemId)
286
			throws ProfitMandiBusinessException 
286
			throws ProfitMandiBusinessException {
287
	{
-
 
288
		if (catalogId == 0) {
287
		if (catalogId == 0) {
289
			catalogId = itemRepository.selectById(itemId).getCatalogItemId();
288
			catalogId = itemRepository.selectById(itemId).getCatalogItemId();
290
		}
289
		}
291
		List<Item> items = itemRepository.selectAllByCatalogItemId(catalogId);
290
		List<Item> items = itemRepository.selectAllByCatalogItemId(catalogId);
292
		LOGGER.info("Items {}", items);
291
		LOGGER.info("Items {}", items);
293
		Map<Integer, String> itemsColorMap = items.stream().filter(x->x.getColorNatural().startsWith("f_")).collect(Collectors.toMap(Item::getId, Item::getColor));
292
		Map<Integer, String> itemsColorMap = items.stream().filter(x -> x.getColorNatural().startsWith("f_"))
-
 
293
				.collect(Collectors.toMap(Item::getId, Item::getColor));
294
		Map<Integer, TagListing> tagsMap = tagListingRepository
294
		Map<Integer, TagListing> tagsMap = tagListingRepository
295
				.selectByItemIdsAndTagIds(items.stream().map(x -> x.getId()).collect(Collectors.toSet()), defaultTags)
295
				.selectByItemIdsAndTagIds(items.stream().map(x -> x.getId()).collect(Collectors.toSet()), defaultTags)
296
				.stream().collect(Collectors.toMap(TagListing::getItemId, x->x));
296
				.stream().collect(Collectors.toMap(TagListing::getItemId, x -> x));
297
		LOGGER.info("Items color map {}", itemsColorMap);
297
		LOGGER.info("Items color map {}", itemsColorMap);
298
		JSONArray response = new JSONArray();
298
		JSONArray response = new JSONArray();
299
		itemsColorMap.keySet().stream().forEach(x -> {
299
		itemsColorMap.keySet().stream().forEach(x -> {
300
			response.put(
-
 
301
				new JSONObject()
-
 
302
					.put("color", itemsColorMap.get(x))
300
			response.put(new JSONObject().put("color", itemsColorMap.get(x)).put("id", x).put("active",
303
					.put("id", x)
-
 
304
					.put("active", tagsMap.get(x)==null ? false : tagsMap.get(x).isActive()));
301
					tagsMap.get(x) == null ? false : tagsMap.get(x).isActive()));
305
		});
302
		});
306
		model.addAttribute("response", response.toString());
303
		model.addAttribute("response", response.toString());
307
		return "response";
304
		return "response";
308
 
305
 
309
	}
306
	}
Line 502... Line 499...
502
	public String raisePO(HttpServletRequest request, Model model, @RequestBody String jsonArrayString)
499
	public String raisePO(HttpServletRequest request, Model model, @RequestBody String jsonArrayString)
503
			throws Exception {
500
			throws Exception {
504
		JSONArray jsonArray = new JSONArray(jsonArrayString);
501
		JSONArray jsonArray = new JSONArray(jsonArrayString);
505
		for (int i = 0; i < jsonArray.length(); i++) {
502
		for (int i = 0; i < jsonArray.length(); i++) {
506
			JSONObject obj = jsonArray.getJSONObject(i);
503
			JSONObject obj = jsonArray.getJSONObject(i);
-
 
504
 
507
			TagListing tl = tagListingRepository.selectByItemId(obj.getInt("id"));
505
			TagListing tl = tagListingRepository.selectByItemId(obj.getInt("id"));
-
 
506
			if (tl == null) {
-
 
507
				continue;
-
 
508
			} else {
508
			tl.setActive(obj.getBoolean("active"));
509
				tl.setActive(obj.getBoolean("active"));
509
			tagListingRepository.persist(tl);
510
				tagListingRepository.persist(tl);
-
 
511
			}
510
		}
512
		}
511
		model.addAttribute("response", true);
513
		model.addAttribute("response", true);
512
		return "response";
514
		return "response";
513
	}
515
	}
514
 
516