Rev 28371 | Rev 30596 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.web.controller;import com.spice.profitmandi.common.solr.SolrService;import com.spice.profitmandi.common.web.util.ResponseSender;import com.spice.profitmandi.dao.entity.dtr.WebOffer;import com.spice.profitmandi.dao.entity.dtr.WebOfferProduct;import com.spice.profitmandi.dao.repository.dtr.WebOfferProductRepository;import com.spice.profitmandi.dao.repository.dtr.WebOfferRepository;import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;import org.json.JSONObject;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.*;import javax.servlet.http.HttpServletRequest;import javax.transaction.Transactional;import java.time.LocalDateTime;import java.util.List;import java.util.Map;import java.util.Optional;import java.util.stream.Collectors;@Controller@Transactional(rollbackOn = Throwable.class)public class WebOffersController {private static final Logger LOGGER = LogManager.getLogger(WebOffersController.class);@AutowiredResponseSender<?> responseSender;@AutowiredWebOfferRepository webOfferRepository;@AutowiredWebOfferProductRepository webOfferProductRepository;@AutowiredSolrService solrService;@RequestMapping(value = "/web-offers", method = RequestMethod.GET)public String getOfferListing(HttpServletRequest request, Model model) {List<WebOffer> webListing = webOfferRepository.selectAllWebListing(Optional.of(true));model.addAttribute("webListings", webListing);return "web-offer";}@RequestMapping(value = "/web-offer/add", method = RequestMethod.POST)public String addWebListing(HttpServletRequest request, @RequestBody WebOffer webOffer, Model model) {webOffer.setCreatedDate(LocalDateTime.now());webOffer.setDetailedText("");webOfferRepository.persist(webOffer);return getOfferListing(request, model);}@RequestMapping(value = "/web-offer/{webOfferId}", method = RequestMethod.GET)public String getWebProductListing(HttpServletRequest request, Model model, @PathVariable int webOfferId)throws Exception {List<WebOfferProduct> webOfferProducts = webOfferProductRepository.selectAllByWebOfferId(webOfferId);if (webOfferProducts.size() > 0) {Map<Integer, JSONObject> entityMap = solrService.getContentByCatalogIds(webOfferProducts.stream().map(x -> x.getEntityId()).collect(Collectors.toList()));webOfferProducts.stream().forEach(x -> x.setProductName(entityMap.get(x.getEntityId()).getString("title_s")));}WebOffer webOffer = webOfferRepository.selectById(webOfferId);model.addAttribute("productListings", webOfferProducts);model.addAttribute("webListing", webOffer);return "web-offer-product";}@RequestMapping(value = "/web-offer-product/add", method = RequestMethod.POST)public String addWebOfferProduct(HttpServletRequest request,@RequestBody List<WebOfferProduct> webOfferProducts, Model model) throws Exception {webOfferProducts.stream().forEach(webOfferProduct -> {boolean exists = webOfferProductRepository.isExists(webOfferProduct.getWebOfferId(),webOfferProduct.getEntityId());if (!exists) {webOfferProductRepository.persist(webOfferProduct);}});return getWebProductListing(request, model, webOfferProducts.get(0).getWebOfferId());}@RequestMapping(value = "/web-offer-product/remove", method = RequestMethod.DELETE)public String addWebOfferProduct(HttpServletRequest request,@RequestParam int webOfferProductId, Model model) throws Exception {WebOfferProduct webOfferProduct = webOfferProductRepository.selectById(webOfferProductId);webOfferProductRepository.delete(webOfferProduct);return getWebProductListing(request, model, webOfferProduct.getWebOfferId());}/* @RequestMapping(value = "/web-listing/order/{webListingId}", method = RequestMethod.POST)public String orderWebProductListing(HttpServletRequest request, Model model, @PathVariable int webListingId,@RequestBody List<Integer> webListingProductIds) throws Exception {List<WebProductListing> productListings = webProductListingRepository.selectAllByWebListingId(webListingId);productListings.forEach(productListing -> {productListing.setRank(webListingProductIds.indexOf(productListing.getId()) + 1);});return getWebProductListing(request, model, webListingId);}@RequestMapping(value = "/web-listing/order-listing", method = RequestMethod.POST)public String orderWebListing(HttpServletRequest request, Model model, @RequestBody List<Integer> webListingIds)throws Exception {LOGGER.info("webListingId" + webListingIds);List<WebListing> webListings = webListingRepository.selectByIds(webListingIds);webListings.forEach(webListing -> {webListing.setRank(webListingIds.indexOf(webListing.getId()) + 1);});return getWebListing(request, model);}*/}