| Line 66... |
Line 66... |
| 66 |
|
66 |
|
| 67 |
import javax.servlet.http.HttpServletRequest;
|
67 |
import javax.servlet.http.HttpServletRequest;
|
| 68 |
import java.time.LocalDate;
|
68 |
import java.time.LocalDate;
|
| 69 |
import java.time.LocalDateTime;
|
69 |
import java.time.LocalDateTime;
|
| 70 |
import java.util.*;
|
70 |
import java.util.*;
|
| - |
|
71 |
import java.util.concurrent.CompletableFuture;
|
| 71 |
import java.util.concurrent.atomic.AtomicInteger;
|
72 |
import java.util.concurrent.atomic.AtomicInteger;
|
| 72 |
import java.util.stream.Collectors;
|
73 |
import java.util.stream.Collectors;
|
| 73 |
|
74 |
|
| 74 |
@Controller
|
75 |
@Controller
|
| 75 |
@Transactional(rollbackFor = Throwable.class)
|
76 |
@Transactional(rollbackFor = Throwable.class)
|
| Line 361... |
Line 362... |
| 361 |
logger.info("endPoint {}", endPoint);
|
362 |
logger.info("endPoint {}", endPoint);
|
| 362 |
logger.info("group Column {}", group);
|
363 |
logger.info("group Column {}", group);
|
| 363 |
|
364 |
|
| 364 |
if (endPoint != null && !endPoint.trim().isEmpty()) {
|
365 |
if (endPoint != null && !endPoint.trim().isEmpty()) {
|
| 365 |
WebListing webListing = webListingRepository.selectByUrl(endPoint);
|
366 |
WebListing webListing = webListingRepository.selectByUrl(endPoint);
|
| 366 |
dealResponse = this.getDealResponses(userInfo, webListing, offset, limit);
|
367 |
dealResponse = this.getDealResponses(userInfo, fs, webListing, offset, limit);
|
| 367 |
|
368 |
|
| 368 |
} else {
|
369 |
} else {
|
| 369 |
|
370 |
|
| 370 |
dealResponse = this.getCatalogResponse(
|
371 |
dealResponse = this.getCatalogResponse(
|
| 371 |
solrService.getSolrDocs(queryTerm, categoryId, offset, limit, sort, brand, subCategoryId, hotDeal, group,true), hotDeal, userInfo.getRetailerId());
|
372 |
solrService.getSolrDocs(queryTerm, categoryId, offset, limit, sort, brand, subCategoryId, hotDeal, group,true), hotDeal, userInfo.getRetailerId());
|
| Line 754... |
Line 755... |
| 754 |
@RequestMapping(value = "/partner/listing", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
755 |
@RequestMapping(value = "/partner/listing", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 755 |
public ResponseEntity<?> getPartnersListing(HttpServletRequest request) throws Exception {
|
756 |
public ResponseEntity<?> getPartnersListing(HttpServletRequest request) throws Exception {
|
| 756 |
List<WebListing> webListings = webListingRepository.selectAllWebListingByType(Optional.of(true), WebListingSource.partner);
|
757 |
List<WebListing> webListings = webListingRepository.selectAllWebListingByType(Optional.of(true), WebListingSource.partner);
|
| 757 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
758 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 758 |
|
759 |
|
| - |
|
760 |
// Pre-fetch FofoStore once (was being called for each webListing)
|
| - |
|
761 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(userInfo.getRetailerId());
|
| - |
|
762 |
|
| 759 |
for (WebListing webListing : webListings) {
|
763 |
// Process all webListings in parallel using CompletableFuture
|
| 760 |
// catalogFavouriteList.contains(webListing.getId())?
|
764 |
List<CompletableFuture<Void>> futures = webListings.stream()
|
| - |
|
765 |
.map(webListing -> CompletableFuture.runAsync(() -> {
|
| - |
|
766 |
try {
|
| 761 |
webListing.setFofoCatalogResponses(getDealResponses(userInfo, webListing, 0, 20));
|
767 |
webListing.setFofoCatalogResponses(getDealResponses(userInfo, fs, webListing, 0, 20));
|
| - |
|
768 |
} catch (Exception e) {
|
| - |
|
769 |
logger.error("Error processing webListing {}: {}", webListing.getId(), e.getMessage());
|
| 762 |
// List<FofoCatalogResponse> responseList= new ArrayList<>();
|
770 |
webListing.setFofoCatalogResponses(new ArrayList<>());
|
| - |
|
771 |
}
|
| 763 |
}
|
772 |
}))
|
| - |
|
773 |
.collect(Collectors.toList());
|
| - |
|
774 |
|
| - |
|
775 |
// Wait for all parallel tasks to complete
|
| - |
|
776 |
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
|
| - |
|
777 |
|
| 764 |
return responseSender.ok(webListings);
|
778 |
return responseSender.ok(webListings);
|
| 765 |
}
|
779 |
}
|
| 766 |
|
780 |
|
| 767 |
private List<FofoCatalogResponse> getDealResponses(UserInfo userInfo, WebListing webListing, int offset,
|
781 |
private List<FofoCatalogResponse> getDealResponses(UserInfo userInfo, FofoStore fs, WebListing webListing, int offset,
|
| 768 |
int limit) throws Exception {
|
782 |
int limit) throws Exception {
|
| 769 |
|
783 |
|
| 770 |
Map<String, String> params = new HashMap<>();
|
784 |
Map<String, String> params = new HashMap<>();
|
| 771 |
List<String> mandatoryQ = new ArrayList<>();
|
785 |
List<String> mandatoryQ = new ArrayList<>();
|
| 772 |
|
786 |
|
| 773 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(userInfo.getRetailerId());
|
- |
|
| 774 |
params.put("sort", "w" + fs.getWarehouseId() + "_i desc");
|
787 |
params.put("sort", "w" + fs.getWarehouseId() + "_i desc");
|
| 775 |
|
788 |
|
| 776 |
List<Integer> webProducts = null;
|
789 |
List<Integer> webProducts = null;
|
| 777 |
if (webListing.getType().equals(WebListingType.solr)) {
|
790 |
if (webListing.getType().equals(WebListingType.solr)) {
|
| 778 |
logger.info("solrtype {}", webListing.getSolrQuery());
|
791 |
logger.info("solrtype {}", webListing.getSolrQuery());
|