Subversion Repositories SmartDukaan

Rev

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

Rev 30017 Rev 30596
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import com.spice.profitmandi.common.solr.SolrService;
3
import com.spice.profitmandi.common.solr.SolrService;
4
import com.spice.profitmandi.common.web.util.ResponseSender;
4
import com.spice.profitmandi.common.web.util.ResponseSender;
-
 
5
import com.spice.profitmandi.dao.entity.dtr.WebListing;
5
import com.spice.profitmandi.dao.entity.dtr.WebOffer;
6
import com.spice.profitmandi.dao.entity.dtr.WebOffer;
6
import com.spice.profitmandi.dao.entity.dtr.WebOfferProduct;
7
import com.spice.profitmandi.dao.entity.dtr.WebOfferProduct;
7
import com.spice.profitmandi.dao.repository.dtr.WebOfferProductRepository;
8
import com.spice.profitmandi.dao.repository.dtr.WebOfferProductRepository;
8
import com.spice.profitmandi.dao.repository.dtr.WebOfferRepository;
9
import com.spice.profitmandi.dao.repository.dtr.WebOfferRepository;
9
import org.apache.logging.log4j.LogManager;
10
import org.apache.logging.log4j.LogManager;
Line 26... Line 27...
26
@Transactional(rollbackOn = Throwable.class)
27
@Transactional(rollbackOn = Throwable.class)
27
public class WebOffersController {
28
public class WebOffersController {
28
 
29
 
29
	private static final Logger LOGGER = LogManager.getLogger(WebOffersController.class);
30
	private static final Logger LOGGER = LogManager.getLogger(WebOffersController.class);
30
 
31
 
31
	
-
 
32
	@Autowired
32
	@Autowired
33
	ResponseSender<?> responseSender;
33
	ResponseSender<?> responseSender;
34
	
34
 
35
	@Autowired
35
	@Autowired
36
	WebOfferRepository webOfferRepository;
36
	WebOfferRepository webOfferRepository;
37
	
37
 
38
	@Autowired
38
	@Autowired
39
	WebOfferProductRepository webOfferProductRepository;
39
	WebOfferProductRepository webOfferProductRepository;
40
 
40
 
41
	@Autowired
41
	@Autowired
42
	SolrService solrService;
42
	SolrService solrService;
Line 53... Line 53...
53
		webOffer.setCreatedDate(LocalDateTime.now());
53
		webOffer.setCreatedDate(LocalDateTime.now());
54
		webOffer.setDetailedText("");
54
		webOffer.setDetailedText("");
55
		webOfferRepository.persist(webOffer);
55
		webOfferRepository.persist(webOffer);
56
		return getOfferListing(request, model);
56
		return getOfferListing(request, model);
57
	}
57
	}
-
 
58
 
-
 
59
	@RequestMapping(value = "/getwebOffer/{webOfferId}", method = RequestMethod.GET)
-
 
60
	public String getWebOfferbyId(HttpServletRequest request, Model model, @PathVariable int webOfferId)
-
 
61
			throws Exception {
-
 
62
		WebOffer webOffer = webOfferRepository.selectById(webOfferId);
-
 
63
 
-
 
64
		LOGGER.info("webOffer {}", webOffer);
-
 
65
		model.addAttribute("webOffer", webOffer);
-
 
66
		return "web-offer-edit";
58
	
67
	}
-
 
68
 
59
	@RequestMapping(value = "/web-offer/{webOfferId}", method = RequestMethod.GET)
69
	@RequestMapping(value = "/web-offer/{webOfferId}", method = RequestMethod.GET)
60
	public String getWebProductListing(HttpServletRequest request, Model model, @PathVariable int webOfferId)
70
	public String getWebProductListing(HttpServletRequest request, Model model, @PathVariable int webOfferId)
61
			throws Exception {
71
			throws Exception {
62
		List<WebOfferProduct> webOfferProducts = webOfferProductRepository.selectAllByWebOfferId(webOfferId);
72
		List<WebOfferProduct> webOfferProducts = webOfferProductRepository.selectAllByWebOfferId(webOfferId);
63
		if (webOfferProducts.size() > 0) {
73
		if (webOfferProducts.size() > 0) {
Line 67... Line 77...
67
					.forEach(x -> x.setProductName(entityMap.get(x.getEntityId()).getString("title_s")));
77
					.forEach(x -> x.setProductName(entityMap.get(x.getEntityId()).getString("title_s")));
68
		}
78
		}
69
 
79
 
70
		WebOffer webOffer = webOfferRepository.selectById(webOfferId);
80
		WebOffer webOffer = webOfferRepository.selectById(webOfferId);
71
		model.addAttribute("productListings", webOfferProducts);
81
		model.addAttribute("productListings", webOfferProducts);
72
		model.addAttribute("webListing", webOffer);
82
		model.addAttribute("webOffer", webOffer);
73
		return "web-offer-product";
83
		return "web-offer-product";
74
	}
84
	}
75
	
85
 
76
	@RequestMapping(value = "/web-offer-product/add", method = RequestMethod.POST)
86
	@RequestMapping(value = "/web-offer-product/add", method = RequestMethod.POST)
77
	public String addWebOfferProduct(HttpServletRequest request,
87
	public String addWebOfferProduct(HttpServletRequest request, @RequestBody List<WebOfferProduct> webOfferProducts,
78
			@RequestBody List<WebOfferProduct> webOfferProducts, Model model) throws Exception {
88
			Model model) throws Exception {
79
		webOfferProducts.stream().forEach(webOfferProduct -> {
89
		webOfferProducts.stream().forEach(webOfferProduct -> {
80
			boolean exists = webOfferProductRepository.isExists(webOfferProduct.getWebOfferId(),
90
			boolean exists = webOfferProductRepository.isExists(webOfferProduct.getWebOfferId(),
81
					webOfferProduct.getEntityId());
91
					webOfferProduct.getEntityId());
82
			if (!exists) {
92
			if (!exists) {
83
				webOfferProductRepository.persist(webOfferProduct);
93
				webOfferProductRepository.persist(webOfferProduct);
84
			}
94
			}
85
 
95
 
86
		});
96
		});
87
		return getWebProductListing(request, model, webOfferProducts.get(0).getWebOfferId());
97
		return getWebProductListing(request, model, webOfferProducts.get(0).getWebOfferId());
88
	}
98
	}
89
	
99
 
90
	@RequestMapping(value = "/web-offer-product/remove", method = RequestMethod.DELETE)
100
	@RequestMapping(value = "/web-offer-product/remove", method = RequestMethod.DELETE)
91
	public String addWebOfferProduct(HttpServletRequest request,
101
	public String addWebOfferProduct(HttpServletRequest request, @RequestParam int webOfferProductId, Model model)
92
			@RequestParam int webOfferProductId, Model model) throws Exception {
102
			throws Exception {
93
		WebOfferProduct webOfferProduct = webOfferProductRepository.selectById(webOfferProductId);
103
		WebOfferProduct webOfferProduct = webOfferProductRepository.selectById(webOfferProductId);
94
		webOfferProductRepository.delete(webOfferProduct);
104
		webOfferProductRepository.delete(webOfferProduct);
95
		return getWebProductListing(request, model, webOfferProduct.getWebOfferId());
105
		return getWebProductListing(request, model, webOfferProduct.getWebOfferId());
96
	}
106
	}
97
	
-
 
98
 
107
 
-
 
108
	@RequestMapping(value = "/web-offer-duration/update", method = RequestMethod.POST)
-
 
109
	public String updateWebOfferDuration(HttpServletRequest request, @RequestParam int id,
-
 
110
			@RequestParam LocalDateTime startDate, @RequestParam LocalDateTime endDate, Model model) throws Exception {
-
 
111
		WebOffer webOffer = webOfferRepository.selectById(id);
-
 
112
 
-
 
113
		webOffer.setStartDate(startDate);
-
 
114
		webOffer.setEndDate(endDate);
-
 
115
		return getOfferListing(request, model);
-
 
116
	}
-
 
117
 
99
/*	@RequestMapping(value = "/web-listing/order/{webListingId}", method = RequestMethod.POST)
118
	@RequestMapping(value = "/web-offer/order/{webListingId}", method = RequestMethod.POST)
100
	public String orderWebProductListing(HttpServletRequest request, Model model, @PathVariable int webListingId,
119
	public String orderWebProductListing(HttpServletRequest request, Model model, @PathVariable int webListingId,
-
 
120
 
101
			@RequestBody List<Integer> webListingProductIds) throws Exception {
121
			@RequestBody List<Integer> webListingProductIds) throws Exception {
102
		List<WebProductListing> productListings = webProductListingRepository.selectAllByWebListingId(webListingId);
122
		List<WebOfferProduct> productListings = webOfferProductRepository.selectAllByWebOfferId(webListingId);
103
 
123
 
104
		productListings.forEach(productListing -> {
124
		productListings.forEach(productListing -> {
105
			productListing.setRank(webListingProductIds.indexOf(productListing.getId()) + 1);
125
			productListing.setRank(webListingProductIds.indexOf(productListing.getId()) + 1);
106
		});
126
		});
107
		return getWebProductListing(request, model, webListingId);
127
		return getWebProductListing(request, model, webListingId);
108
	}
128
	}
109
 
129
 
110
	@RequestMapping(value = "/web-listing/order-listing", method = RequestMethod.POST)
-
 
111
	public String orderWebListing(HttpServletRequest request, Model model, @RequestBody List<Integer> webListingIds)
-
 
112
			throws Exception {
-
 
113
		LOGGER.info("webListingId" + webListingIds);
-
 
114
		List<WebListing> webListings = webListingRepository.selectByIds(webListingIds);
-
 
115
		webListings.forEach(webListing -> {
-
 
116
			webListing.setRank(webListingIds.indexOf(webListing.getId()) + 1);
-
 
117
		});
-
 
118
		return getWebListing(request, model);
-
 
119
	}*/
-
 
120
 
-
 
121
 
-
 
122
 
-
 
123
}
130
}