Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
21339 kshitij.so 1
package com.spice.profitmandi.web.controller;
2
 
3
import com.eclipsesource.json.Json;
4
import com.eclipsesource.json.JsonArray;
5
import com.eclipsesource.json.JsonObject;
6
import com.eclipsesource.json.JsonValue;
7
import com.google.gson.Gson;
21356 kshitij.so 8
import com.google.gson.reflect.TypeToken;
25010 amit.gupta 9
import com.mongodb.BasicDBObject;
24163 amit.gupta 10
import com.mongodb.DBObject;
21643 ashik.ali 11
import com.spice.profitmandi.common.enumuration.SchemeType;
21339 kshitij.so 12
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
33929 tejus.loha 13
import com.spice.profitmandi.common.model.BrandAndAddToCartEligibleModel;
21339 kshitij.so 14
import com.spice.profitmandi.common.model.ProfitMandiConstants;
22289 amit.gupta 15
import com.spice.profitmandi.common.model.UserInfo;
27030 amit.gupta 16
import com.spice.profitmandi.common.solr.SolrService;
21643 ashik.ali 17
import com.spice.profitmandi.common.web.client.RestClient;
22319 amit.gupta 18
import com.spice.profitmandi.common.web.util.ResponseSender;
30686 amit.gupta 19
import com.spice.profitmandi.dao.entity.catalog.*;
31507 tejbeer 20
import com.spice.profitmandi.dao.entity.dtr.WebListing;
30595 tejbeer 21
import com.spice.profitmandi.dao.entity.dtr.WebOffer;
33929 tejus.loha 22
import com.spice.profitmandi.dao.entity.fofo.*;
30669 amit.gupta 23
import com.spice.profitmandi.dao.entity.inventory.SaholicCISTable;
27032 amit.gupta 24
import com.spice.profitmandi.dao.entity.inventory.SaholicPOItem;
31572 tejbeer 25
import com.spice.profitmandi.dao.enumuration.dtr.WebListingSource;
31507 tejbeer 26
import com.spice.profitmandi.dao.enumuration.dtr.WebListingType;
31954 amit.gupta 27
import com.spice.profitmandi.dao.model.AmountModel;
30188 amit.gupta 28
import com.spice.profitmandi.dao.model.CreateOfferRequest;
22361 amit.gupta 29
import com.spice.profitmandi.dao.model.UserCart;
30686 amit.gupta 30
import com.spice.profitmandi.dao.repository.catalog.*;
32978 amit.gupta 31
import com.spice.profitmandi.dao.repository.dtr.*;
31625 tejbeer 32
import com.spice.profitmandi.dao.repository.fofo.CatalogFavouriteRepository;
34260 vikas.jang 33
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
26846 tejbeer 34
import com.spice.profitmandi.dao.repository.fofo.SuggestedPoDetailRepository;
26847 tejbeer 35
import com.spice.profitmandi.dao.repository.fofo.SuggestedPoRepository;
30669 amit.gupta 36
import com.spice.profitmandi.dao.repository.inventory.SaholicCISTableRepository;
33929 tejus.loha 37
import com.spice.profitmandi.dao.repository.onboarding.BrandCommitRepository;
23798 amit.gupta 38
import com.spice.profitmandi.service.authentication.RoleManager;
31507 tejbeer 39
import com.spice.profitmandi.service.catalog.BrandsService;
30686 amit.gupta 40
import com.spice.profitmandi.service.inventory.*;
31954 amit.gupta 41
import com.spice.profitmandi.service.pricecircular.PriceCircularItemModelNew;
30123 amit.gupta 42
import com.spice.profitmandi.service.pricecircular.PriceCircularModel;
43
import com.spice.profitmandi.service.pricecircular.PriceCircularService;
22287 amit.gupta 44
import com.spice.profitmandi.service.pricing.PricingService;
26695 amit.gupta 45
import com.spice.profitmandi.service.scheme.SchemeService;
21356 kshitij.so 46
import com.spice.profitmandi.web.res.DealBrands;
21339 kshitij.so 47
import com.spice.profitmandi.web.res.DealObjectResponse;
48
import com.spice.profitmandi.web.res.DealsResponse;
49
import io.swagger.annotations.ApiImplicitParam;
50
import io.swagger.annotations.ApiImplicitParams;
51
import io.swagger.annotations.ApiOperation;
30686 amit.gupta 52
import org.apache.commons.lang3.StringUtils;
53
import org.apache.http.conn.HttpHostConnectException;
54
import org.apache.logging.log4j.LogManager;
55
import org.apache.logging.log4j.Logger;
56
import org.json.JSONArray;
57
import org.json.JSONObject;
58
import org.springframework.beans.factory.annotation.Autowired;
59
import org.springframework.beans.factory.annotation.Value;
60
import org.springframework.http.HttpStatus;
61
import org.springframework.http.MediaType;
62
import org.springframework.http.ResponseEntity;
63
import org.springframework.stereotype.Controller;
64
import org.springframework.transaction.annotation.Transactional;
33929 tejus.loha 65
import org.springframework.web.bind.annotation.*;
21339 kshitij.so 66
 
30686 amit.gupta 67
import javax.servlet.http.HttpServletRequest;
31954 amit.gupta 68
import java.time.LocalDate;
31625 tejbeer 69
import java.time.LocalDateTime;
30686 amit.gupta 70
import java.util.*;
71
import java.util.concurrent.atomic.AtomicInteger;
72
import java.util.stream.Collectors;
73
 
21339 kshitij.so 74
@Controller
22319 amit.gupta 75
@Transactional(rollbackFor = Throwable.class)
21339 kshitij.so 76
public class DealsController {
77
 
32339 tejbeer 78
    private static final Logger logger = LogManager.getLogger(DealsController.class);
79
    private static final List<Integer> TAG_IDS = Arrays.asList(4);
21339 kshitij.so 80
 
32339 tejbeer 81
    @Value("${python.api.host}")
82
    private String host;
23816 amit.gupta 83
 
32339 tejbeer 84
    @Value("${new.solr.url}")
85
    private String solrUrl;
26889 amit.gupta 86
 
32339 tejbeer 87
    @Value("${python.api.port}")
88
    private int port;
23816 amit.gupta 89
 
32339 tejbeer 90
    @Autowired
91
    RestClient restClient;
27051 amit.gupta 92
 
32339 tejbeer 93
    @Autowired
94
    SolrService solrService;
26889 amit.gupta 95
 
32339 tejbeer 96
    @Autowired
33873 ranu 97
    com.spice.profitmandi.web.services.SolrService webSolrService;
98
 
99
    @Autowired
32339 tejbeer 100
    InventoryService inventoryService;
26924 amit.gupta 101
 
32339 tejbeer 102
    // This is now unused as we are not supporting multiple companies.
103
    @Value("${gadgetCops.invoice.cc}")
104
    private String[] ccGadgetCopInvoiceTo;
22319 amit.gupta 105
 
32339 tejbeer 106
    @Autowired
107
    private PricingService pricingService;
23816 amit.gupta 108
 
32339 tejbeer 109
    @Autowired
110
    private CategoryRepository categoryRepository;
25010 amit.gupta 111
 
32339 tejbeer 112
    @Autowired
113
    private SchemeService schemeService;
26695 amit.gupta 114
 
32339 tejbeer 115
    @Autowired
116
    private SaholicInventoryService saholicInventoryService;
26889 amit.gupta 117
 
32339 tejbeer 118
    @Autowired
119
    private Mongo mongoClient;
25879 amit.gupta 120
 
32339 tejbeer 121
    @Autowired
122
    private ItemBucketService itemBucketService;
23816 amit.gupta 123
 
32339 tejbeer 124
    @Autowired
125
    private UserAccountRepository userAccountRepository;
27051 amit.gupta 126
 
32339 tejbeer 127
    @Autowired
128
    private FofoStoreRepository fofoStoreRepository;
23816 amit.gupta 129
 
32339 tejbeer 130
    @Autowired
131
    private ResponseSender<?> responseSender;
23816 amit.gupta 132
 
32339 tejbeer 133
    @Autowired
134
    private TagListingRepository tagListingRepository;
23816 amit.gupta 135
 
32339 tejbeer 136
    @Autowired
137
    private ItemRepository itemRepository;
138
    @Autowired
139
    private PriceCircularService priceCircularService;
23816 amit.gupta 140
 
32339 tejbeer 141
    @Autowired
142
    private RoleManager roleManagerService;
23816 amit.gupta 143
 
32339 tejbeer 144
    @Autowired
32978 amit.gupta 145
    private SuggestedPoDetailRepository suggestedPoDetailRepository;
26846 tejbeer 146
 
32339 tejbeer 147
    @Autowired
148
    private SuggestedPoRepository suggestedPoRepository;
26847 tejbeer 149
 
32339 tejbeer 150
    @Autowired
151
    private WebOfferRepository webOfferRepository;
30595 tejbeer 152
 
32339 tejbeer 153
    @Autowired
154
    private ComboModelRepository comboModelRepository;
30683 tejbeer 155
 
32339 tejbeer 156
    @Autowired
157
    private ComboMappedModelRepository comboMappedModelRepository;
30683 tejbeer 158
 
32339 tejbeer 159
    @Autowired
160
    private BrandsService brandsService;
31547 tejbeer 161
 
32339 tejbeer 162
    @Autowired
163
    private WebListingRepository webListingRepository;
31547 tejbeer 164
 
32339 tejbeer 165
    @Autowired
166
    private WebProductListingRepository webProductListingRepository;
31547 tejbeer 167
 
32339 tejbeer 168
    @Autowired
169
    private CatalogFavouriteRepository catalogFavouriteRepository;
31625 tejbeer 170
 
33929 tejus.loha 171
    @Autowired
172
    PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
173
 
174
    @Autowired
175
    PartnerDealerRepository partnerDealerRepository;
176
 
177
    @Autowired
178
    BrandCommitRepository brandCommitRepository;
179
 
180
    @Autowired
181
    CatalogRepository catalogRepository;
182
 
34260 vikas.jang 183
    @Autowired
184
    private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
185
 
32339 tejbeer 186
    List<String> filterableParams = Arrays.asList("brand");
24949 amit.gupta 187
 
32339 tejbeer 188
    @RequestMapping(value = "/fofo/buckets", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
189
    public ResponseEntity<?> getBuckets(HttpServletRequest request) throws ProfitMandiBusinessException {
190
        logger.info("Request " + request.getParameterMap());
191
        return responseSender.ok(itemBucketService.getBuckets(Optional.of(true)));
192
    }
25879 amit.gupta 193
 
32339 tejbeer 194
    @RequestMapping(value = "/fofo/bucket", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
195
    public ResponseEntity<?> getBucketDetails(HttpServletRequest request, @RequestParam int id) throws ProfitMandiBusinessException {
196
        List<ItemQuantityPojo> iqPojo = itemBucketService.getBucketDetails(id);
197
        Map<Integer, Integer> itemIdsQtyMap = iqPojo.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
198
        Set<Integer> catalogIds = itemRepository.selectByIds(itemIdsQtyMap.keySet()).stream().map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
199
        RestClient rc = new RestClient();
200
        Map<String, String> params = new HashMap<>();
201
        List<String> mandatoryQ = new ArrayList<>();
202
        mandatoryQ.add(
203
                String.format("+catalogId_i:(%s) +{!parent which=\"id:catalog*\"}", StringUtils.join(catalogIds, " ")));
204
        params.put("start", "0");
205
        params.put("rows", "100");
206
        params.put("q", StringUtils.join(mandatoryQ, " "));
207
        params.put("fl", "*, [child parentFilter=id:catalog*]");
25879 amit.gupta 208
 
32339 tejbeer 209
        params.put("wt", "json");
210
        String response = null;
211
        try {
212
            response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
213
        } catch (HttpHostConnectException e) {
214
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
215
        }
216
        JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
217
        JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
218
        List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, itemIdsQtyMap, false);
26051 amit.gupta 219
 
32339 tejbeer 220
        Bucket bucket = itemBucketService.getBuckets(Optional.of(true)).stream().filter(x -> x.getId() == id).collect(Collectors.toList()).get(0);
221
        bucket.setFofoCatalogResponses(dealResponse);
222
        return responseSender.ok(bucket);
223
    }
25879 amit.gupta 224
 
32339 tejbeer 225
    @RequestMapping(value = "/fofo/suggestedPo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
226
    public ResponseEntity<?> getSuggestedPo(HttpServletRequest request, @RequestParam int id) throws ProfitMandiBusinessException {
34436 ranu 227
        int userId = (int) request.getAttribute("userId");
228
        UserCart uc = userAccountRepository.getUserCart(userId);
229
        int fofoId = uc.getUserId();
230
        SuggestedPo  suggestedPo = suggestedPoRepository.selectAllOpenPoByFofoId(fofoId).get(0);
231
        if(suggestedPo == null){
232
            throw new ProfitMandiBusinessException("", "", "Open po is not available in list");
233
        }
234
        List<SuggestedPoDetail> mpd = suggestedPoDetailRepository.selectByPoId(suggestedPo.getId());
32339 tejbeer 235
        Map<Integer, Integer> itemIdsQtyMap = mpd.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
26846 tejbeer 236
 
32339 tejbeer 237
        Set<Integer> catalogIds = itemRepository.selectByIds(itemIdsQtyMap.keySet()).stream().map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
238
        RestClient rc = new RestClient();
239
        Map<String, String> params = new HashMap<>();
240
        List<String> mandatoryQ = new ArrayList<>();
241
        mandatoryQ.add(
242
                String.format("+catalogId_i:(%s) +{!parent which=\"id:catalog*\"}", StringUtils.join(catalogIds, " ")));
243
        params.put("start", "0");
244
        params.put("rows", "100");
245
        params.put("q", StringUtils.join(mandatoryQ, " "));
246
        params.put("fl", "*, [child parentFilter=id:catalog*]");
26846 tejbeer 247
 
32339 tejbeer 248
        params.put("wt", "json");
249
        String response = null;
250
        try {
251
            response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
252
        } catch (HttpHostConnectException e) {
253
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
254
        }
255
        JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
256
        JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
257
        List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, itemIdsQtyMap, false);
26846 tejbeer 258
 
32339 tejbeer 259
        return responseSender.ok(dealResponse);
260
    }
26846 tejbeer 261
 
34436 ranu 262
    @RequestMapping(value = "/suggestedPo/status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
32339 tejbeer 263
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
264
    @ApiOperation(value = "")
265
    public ResponseEntity<?> changeSuggestedPoStatus(HttpServletRequest request, @RequestParam int id) throws ProfitMandiBusinessException {
266
        SuggestedPo suggestedPo = suggestedPoRepository.selectById(id);
267
        suggestedPo.setStatus("closed");
33873 ranu 268
        //suggestedPo.setStatus(SuggestedPoStatus.valueOf("closed"));
26847 tejbeer 269
 
32339 tejbeer 270
        return responseSender.ok(true);
271
    }
26847 tejbeer 272
 
32339 tejbeer 273
    @RequestMapping(value = "/fofo/fovourites", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
274
    public ResponseEntity<?> getFavourites(HttpServletRequest request) throws Exception {
31625 tejbeer 275
 
32339 tejbeer 276
        int userId = (int) request.getAttribute("userId");
277
        UserCart uc = userAccountRepository.getUserCart(userId);
278
        int fofoId = uc.getUserId();
279
        List<FofoCatalogResponse> dealResponse = new ArrayList<>();
280
        Set<Integer> catalogIds = catalogFavouriteRepository.selectBypartnerId(fofoId).stream().map(x -> x.getCatalogId()).collect(Collectors.toSet());
281
        if (!catalogIds.isEmpty()) {
33929 tejus.loha 282
            dealResponse = webSolrService.dealResponse(catalogIds, fofoId);
32339 tejbeer 283
        }
284
        return responseSender.ok(dealResponse);
285
    }
31625 tejbeer 286
 
32339 tejbeer 287
    @RequestMapping(value = "/favourites/manage", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
288
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
289
    @ApiOperation(value = "")
290
    public ResponseEntity<?> mangeFavourites(HttpServletRequest request, @RequestParam int catalogId) throws ProfitMandiBusinessException {
31625 tejbeer 291
 
32339 tejbeer 292
        int userId = (int) request.getAttribute("userId");
293
        UserCart uc = userAccountRepository.getUserCart(userId);
294
        int fofoId = uc.getUserId();
31625 tejbeer 295
 
32339 tejbeer 296
        CatalogFavourite catalogFavourite = catalogFavouriteRepository.selectBypartnerAndCatalogId(fofoId, catalogId);
31625 tejbeer 297
 
32339 tejbeer 298
        if (catalogFavourite == null) {
299
            catalogFavourite = new CatalogFavourite();
300
            catalogFavourite.setCatalogId(catalogId);
301
            catalogFavourite.setFofoId(fofoId);
302
            catalogFavourite.setCreatedTimestamp(LocalDateTime.now());
303
            catalogFavouriteRepository.persist(catalogFavourite);
31625 tejbeer 304
 
32978 amit.gupta 305
        } else {
32339 tejbeer 306
            catalogFavouriteRepository.deleteByPartnerAndCatalogId(fofoId, catalogId);
307
        }
308
        return responseSender.ok(true);
309
    }
31625 tejbeer 310
 
33249 ranu 311
    private String getCommaSeparateTags(int userId) throws ProfitMandiBusinessException {
32339 tejbeer 312
        UserCart uc = userAccountRepository.getUserCart(userId);
313
        List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
314
        List<String> strTagIds = new ArrayList<>();
315
        for (Integer tagId : tagIds) {
316
            strTagIds.add(String.valueOf(tagId));
317
        }
318
        return String.join(",", strTagIds);
319
    }
22273 amit.gupta 320
 
33575 amit.gupta 321
    @RequestMapping(value = "/fofo/similar-models/{modelId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
322
    public ResponseEntity<?> similarModels(HttpServletRequest httpServletRequest, @PathVariable int modelId) throws Throwable {
323
        UserInfo userInfo = (UserInfo) httpServletRequest.getAttribute("userInfo");
324
        //FofoStore fs = fofoStoreRepository.selectByRetailerId(userInfo.getRetailerId());
325
 
326
        JSONObject jsonObject = solrService.getContentByCatalogIds(Arrays.asList(modelId)).get(modelId);
327
 
328
        JSONArray similarModelsArray = jsonObject.getJSONArray("similarModels_ii");
329
        List<Integer> similarCatalogIds = new ArrayList<>();
330
        for (int j = 0; j < similarModelsArray.length(); j++) {
331
            similarCatalogIds.add(similarModelsArray.getInt(j));
332
        }
333
 
334
        Map<String, String> params = new HashMap<>();
335
        List<String> mandatoryQ = new ArrayList<>();
336
 
337
        mandatoryQ.add(String.format(
338
                "+{!parent which=\"catalogId_i:(" + StringUtils.join(similarCatalogIds, " ") + ")\"} AND active_b:true AND show_default_b:true"));
339
 
340
        params.put("q", StringUtils.join(mandatoryQ, " "));
341
        params.put("fl", "*, [child parentFilter=id:catalog* childFilter=active_b:true ]");
342
        params.put("wt", "json");
343
        params.put("rows", similarCatalogIds.size() + "");
344
        try {
345
            String response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
346
            JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
347
            JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
33576 amit.gupta 348
            return responseSender.ok(this.getCatalogResponse(docs, false, userInfo.getRetailerId()).stream().filter(x -> x.isInStock()).collect(Collectors.toList()));
33575 amit.gupta 349
        } catch (HttpHostConnectException e) {
350
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
351
        }
352
    }
353
 
32339 tejbeer 354
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
355
    @RequestMapping(value = "/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
33573 amit.gupta 356
    public ResponseEntity<?> getFofo(HttpServletRequest request, @RequestParam(value = "categoryId", required = false, defaultValue = "3") String categoryId, @RequestParam(value = "offset") int offset,
34024 vikas.jang 357
                                     @RequestParam(value = "limit") int limit, @RequestParam(value = "sort", required = false) String sort, @RequestParam(value = "brand", required = false) String brand, @RequestParam(value = "subCategoryId", required = false) int subCategoryId, @RequestParam(value = "q", required = false) String queryTerm, @RequestParam(value = "hotDeal", required = false) boolean hotDeal, @RequestParam(value = "endPoint", required = false) String endPoint,@RequestParam(value = "group", required = false) boolean group) throws Throwable {
33543 amit.gupta 358
        List<FofoCatalogResponse> dealResponse;
32339 tejbeer 359
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
360
        FofoStore fs = fofoStoreRepository.selectByRetailerId(userInfo.getRetailerId());
361
        sort = "w" + fs.getWarehouseId() + "_i desc";
31548 tejbeer 362
 
32339 tejbeer 363
        logger.info("endPoint {}", endPoint);
34024 vikas.jang 364
        logger.info("group Column {}", group);
31552 tejbeer 365
 
32339 tejbeer 366
        if (endPoint != null && !endPoint.trim().isEmpty()) {
367
            WebListing webListing = webListingRepository.selectByUrl(endPoint);
368
            dealResponse = this.getDealResponses(userInfo, webListing, offset, limit);
31552 tejbeer 369
 
32339 tejbeer 370
        } else {
31552 tejbeer 371
 
32339 tejbeer 372
            dealResponse = this.getCatalogResponse(
34024 vikas.jang 373
                    solrService.getSolrDocs(queryTerm, categoryId, offset, limit, sort, brand, subCategoryId, hotDeal, group), hotDeal, userInfo.getRetailerId());
32339 tejbeer 374
        }
33573 amit.gupta 375
 
376
        Map<Integer, List<Integer>> similarModelMap = dealResponse.stream().filter(x -> x.getSimilarModelIds() != null && x.getSimilarModelIds().size() > 0)
377
                .collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getSimilarModelIds()));
378
        Set<Integer> similarModelIds = similarModelMap.values().stream().flatMap(x -> x.stream()).collect(Collectors.toSet());
379
        logger.info("similarModelIds - {}", similarModelIds);
33575 amit.gupta 380
        if (similarModelIds.size() > 0) {
33573 amit.gupta 381
 
33576 amit.gupta 382
            Map<Integer, FofoCatalogResponse> similarCatalogResponsesMap = this.getSimpleDocs(fs, similarModelIds).stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
33573 amit.gupta 383
            logger.info("Similar Catalog ResponseMap - {}", similarCatalogResponsesMap.keySet());
384
 
385
            for (FofoCatalogResponse deal : dealResponse) {
386
                if (similarModelMap.containsKey(deal.getCatalogId())) {
387
                    List<Integer> similarCatalogIds = similarModelMap.get(deal.getCatalogId());
388
                    logger.info("Similar Catalog Ids - {}", similarCatalogIds);
33575 amit.gupta 389
                    List<FofoCatalogResponse> similarModels = similarCatalogIds.stream().filter(x -> similarCatalogResponsesMap.containsKey(x)).map(x -> similarCatalogResponsesMap.get(x)).collect(Collectors.toList());
33573 amit.gupta 390
                    deal.setSimilarModels(similarModels);
391
                }
392
            }
393
        }
32339 tejbeer 394
        return responseSender.ok(dealResponse);
395
    }
25015 amit.gupta 396
 
33576 amit.gupta 397
    private List<FofoCatalogResponse> getSimpleDocs(FofoStore fofoStore, Set<Integer> catalogIds) throws Exception {
33575 amit.gupta 398
        List<FofoCatalogResponse> fofoCatalogResponses = new ArrayList<>();
399
 
400
 
401
        Map<String, String> params = new HashMap<>();
402
        List<String> mandatoryQ = new ArrayList<>();
403
 
404
        mandatoryQ.add(String.format(
405
                "+{!parent which=\"catalogId_i:(" + StringUtils.join(catalogIds, " ") + ")\"} AND active_b:true AND show_default_b:true"));
406
 
407
        params.put("q", StringUtils.join(mandatoryQ, " "));
408
        params.put("fl", "*, [child parentFilter=id:catalog* childFilter=active_b:true ]");
409
        params.put("wt", "json");
410
        params.put("rows", catalogIds.size() + "");
411
 
33576 amit.gupta 412
        String response = restClient.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
413
        JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
414
        JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
415
        int warehouseId = fofoStoreRepository.selectByRetailerId(fofoStore.getId()).getWarehouseId();
416
        Map<Integer, List<SaholicPOItem>> poItemAvailabilityMap = saholicInventoryService.getSaholicPOItems().get(warehouseId);
417
        for (int i = 0; i < docs.length(); i++) {
418
            JSONObject doc = docs.getJSONObject(i);
419
            FofoCatalogResponse fofoCatalogResponse = this.toFofoCatalogResponse(doc);
420
            if (doc.has("_childDocuments_")) {
421
                String modelColorClass = "grey";
422
                FofoAvailabilityInfo fdiAnyColour = null;
423
                // Iterating itemIds
424
                for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
425
                    JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
426
                    int itemId = childItem.getInt("itemId_i");
427
 
428
                    List<SaholicCISTable> currentAvailability = saholicCISTableRepository.selectByItemWarehouse(itemId, warehouseId);
429
                    List<SaholicPOItem> poItemAvailability = null;
430
                    if (poItemAvailabilityMap != null) {
431
                        poItemAvailability = poItemAvailabilityMap.get(itemId);
432
                    }
433
 
434
                    for (SaholicCISTable saholicCISTable : currentAvailability) {
435
                        saholicCISTable.setWarehouseName(
436
                                ProfitMandiConstants.WAREHOUSE_MAP.get(saholicCISTable.getWarehouseFrom()));
437
                    }
438
 
439
 
440
                    String poColor = "grey";
441
                    boolean active = false;
442
                    if (currentAvailability != null && currentAvailability.stream().collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)) > 0) {
443
                        poColor = "green";
444
                        modelColorClass = "green";
445
                    } else if (poItemAvailability != null && poItemAvailability.stream().collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty)) > 0) {
446
                        if (currentAvailability != null && poItemAvailability.stream().collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty)) + currentAvailability.stream().collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)) <= 0) {
447
                            poColor = "grey";
448
                        } else {
449
                            poColor = "yellow";
450
                            if (!modelColorClass.equals("green")) {
451
                                modelColorClass = poColor;
452
                            }
453
                        }
454
                    }
455
 
456
                }
457
                fofoCatalogResponse.setInStock(!modelColorClass.equals("grey"));
33575 amit.gupta 458
            }
33576 amit.gupta 459
 
460
            fofoCatalogResponses.add(fofoCatalogResponse);
33575 amit.gupta 461
        }
33576 amit.gupta 462
 
33575 amit.gupta 463
        return fofoCatalogResponses;
464
    }
465
 
466
    private FofoCatalogResponse toFofoCatalogResponse(JSONObject doc) {
467
        FofoCatalogResponse fofoCatalogResponse = new FofoCatalogResponse();
468
        fofoCatalogResponse.setCatalogId(doc.getInt("catalogId_i"));
469
        fofoCatalogResponse.setImageUrl(doc.getString("imageUrl_s"));
470
        fofoCatalogResponse.setTitle(doc.getString("title_s"));
471
        fofoCatalogResponse.setMop(doc.getFloat("mop_f"));
472
        fofoCatalogResponse.setDp(doc.getFloat("dp_f"));
473
        fofoCatalogResponse.setBrand(doc.getJSONArray("brand_ss").getString(0));
474
        return fofoCatalogResponse;
475
    }
476
 
32339 tejbeer 477
    @RequestMapping(value = "/online-deals", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
478
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
479
    @ApiOperation(value = "Get online deals")
33575 amit.gupta 480
    public ResponseEntity<?> getOnlineDeals(HttpServletRequest request, @RequestParam(value = "categoryId") String
481
            categoryId, @RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String
482
                                                    limit, @RequestParam(value = "sort", required = false) String
483
                                                    sort, @RequestParam(value = "direction", required = false) String
484
                                                    direction, @RequestParam(value = "filterData", required = false) String filterData) throws Throwable {
32339 tejbeer 485
        logger.info("Request " + request.getParameterMap());
486
        String response = null;
487
        int userId = (int) request.getAttribute("userId");
22289 amit.gupta 488
 
32339 tejbeer 489
        String uri = "/deals/" + userId;
490
        RestClient rc = new RestClient();
491
        Map<String, String> params = new HashMap<>();
492
        params.put("offset", offset);
493
        params.put("limit", limit);
494
        params.put("categoryId", categoryId);
495
        params.put("direction", direction);
496
        params.put("sort", sort);
497
        params.put("source", "online");
498
        params.put("filterData", filterData);
499
        /*
500
         * if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
501
         * params.put("tag_ids", getCommaSeparateTags(userId)); }
502
         */
503
        List<Object> responseObject = new ArrayList<>();
504
        try {
505
            response = rc.get(SchemeType.HTTP, host, port, uri, params);
506
        } catch (HttpHostConnectException e) {
507
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
508
        }
22931 ashik.ali 509
 
32339 tejbeer 510
        JsonArray result_json = Json.parse(response).asArray();
511
        for (JsonValue j : result_json) {
512
            // logger.info("res " + j.asArray());
513
            List<Object> innerObject = new ArrayList<>();
514
            for (JsonValue jsonObject : j.asArray()) {
515
                innerObject.add(toDealObject(jsonObject.asObject()));
516
            }
517
            if (innerObject.size() > 0) {
518
                responseObject.add(innerObject);
519
            }
520
        }
521
        return responseSender.ok(responseObject);
522
    }
22272 amit.gupta 523
 
32339 tejbeer 524
    private Object toDealObject(JsonObject jsonObject) {
525
        if (jsonObject.get("dealObject") != null && jsonObject.get("dealObject").asInt() == 1) {
526
            return new Gson().fromJson(jsonObject.toString(), DealObjectResponse.class);
527
        }
528
        return new Gson().fromJson(jsonObject.toString(), DealsResponse.class);
529
    }
22319 amit.gupta 530
 
32339 tejbeer 531
    @RequestMapping(value = ProfitMandiConstants.URL_BRANDS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
532
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
533
    @ApiOperation(value = "Get brand list and count for category")
33575 amit.gupta 534
    public ResponseEntity<?> getBrands(HttpServletRequest request, @RequestParam(value = "category_id") String
535
            category_id) throws ProfitMandiBusinessException {
32339 tejbeer 536
        logger.info("Request " + request.getParameterMap());
537
        String response = null;
538
        // TODO: move to properties
539
        String uri = ProfitMandiConstants.URL_BRANDS;
540
        RestClient rc = new RestClient();
541
        Map<String, String> params = new HashMap<>();
542
        params.put("category_id", category_id);
543
        List<DealBrands> dealBrandsResponse = null;
544
        try {
545
            response = rc.get(SchemeType.HTTP, host, port, uri, params);
546
        } catch (HttpHostConnectException e) {
547
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
548
        }
23816 amit.gupta 549
 
32339 tejbeer 550
        dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
551
        }.getType());
23022 ashik.ali 552
 
32339 tejbeer 553
        return responseSender.ok(dealBrandsResponse);
554
    }
22319 amit.gupta 555
 
32339 tejbeer 556
    @RequestMapping(value = ProfitMandiConstants.URL_UNIT_DEAL, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
557
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
558
    @ApiOperation(value = "Get unit deal object")
33575 amit.gupta 559
    public ResponseEntity<?> getUnitDeal(HttpServletRequest request, @PathVariable(value = "id") long id) throws
560
            ProfitMandiBusinessException {
32339 tejbeer 561
        String response = null;
562
        // TODO: move to properties
563
        String uri = "getDealById/" + id;
564
        System.out.println("Unit deal " + uri);
565
        RestClient rc = new RestClient();
566
        Map<String, String> params = new HashMap<>();
567
        DealsResponse dealsResponse = null;
568
        try {
569
            response = rc.get(SchemeType.HTTP, host, port, uri, params);
570
        } catch (HttpHostConnectException e) {
571
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
572
        }
23816 amit.gupta 573
 
32339 tejbeer 574
        JsonObject result_json = Json.parse(response).asObject();
575
        if (!result_json.isEmpty()) {
576
            dealsResponse = new Gson().fromJson(response, DealsResponse.class);
577
            Iterator<AvailabilityInfo> iter = dealsResponse.getAvailabilityInfo().iterator();
578
            while (iter.hasNext()) {
579
                AvailabilityInfo ai = iter.next();
580
                if (ai.getAvailability() <= 0)
581
                    iter.remove();
582
            }
583
        }
584
        return responseSender.ok(dealsResponse);
585
    }
23816 amit.gupta 586
 
32339 tejbeer 587
    @RequestMapping(value = "/partnerdeals/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
588
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
589
    @ApiOperation(value = "Get unit deal object")
33575 amit.gupta 590
    public ResponseEntity<?> getUnitFocoDeal(HttpServletRequest request, @PathVariable(value = "id") long id) throws
591
            Exception {
32339 tejbeer 592
        List<FofoCatalogResponse> dealResponse = new ArrayList<>();
593
        List<Integer> tagIds = Arrays.asList(4);
594
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
595
        if (roleManagerService.isPartner(userInfo.getRoleIds())) {
596
            String categoryId = "(3 OR 6)";
597
            UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
598
            RestClient rc = new RestClient();
599
            Map<String, String> params = new HashMap<>();
600
            List<String> mandatoryQ = new ArrayList<>();
601
            String catalogString = "catalog" + id;
24091 tejbeer 602
 
32339 tejbeer 603
            mandatoryQ.add(String.format("+(categoryId_i:%s) +(id:%s) +{!parent which=\"id:%s\"} tagId_i:(%s)", categoryId, catalogString, catalogString, StringUtils.join(tagIds, " ")));
24149 amit.gupta 604
 
32339 tejbeer 605
            params.put("q", StringUtils.join(mandatoryQ, " "));
606
            params.put("fl", "*, [child parentFilter=id:catalog*]");
607
            params.put("sort", "rank_i asc, create_s desc");
608
            params.put("wt", "json");
609
            String response = null;
610
            try {
33487 amit.gupta 611
                response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
32339 tejbeer 612
            } catch (HttpHostConnectException e) {
613
                throw new ProfitMandiBusinessException("", "", "Could not connect to host");
614
            }
615
            JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
616
            JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
617
            dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
618
        } else {
619
            return responseSender.badRequest(
620
                    new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
621
        }
622
        return responseSender.ok(dealResponse.get(0));
623
    }
24091 tejbeer 624
 
34436 ranu 625
 
626
    @RequestMapping(value = "/suggestedPoDeals", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
627
    public ResponseEntity<?> suggestedPoDeals(HttpServletRequest request,@RequestBody Set<Integer>catalogIds) throws Exception {
628
 
629
        int userId = (int) request.getAttribute("userId");
630
        UserCart uc = userAccountRepository.getUserCart(userId);
631
        int fofoId = uc.getUserId();
632
        List<FofoCatalogResponse> dealResponse = new ArrayList<>();
633
        if (!catalogIds.isEmpty()) {
634
            dealResponse = webSolrService.dealResponse(catalogIds, fofoId);
635
        }
636
        return responseSender.ok(dealResponse);
637
    }
638
 
32339 tejbeer 639
    @RequestMapping(value = "/fofo/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
33575 amit.gupta 640
    public ResponseEntity<?> getBrandsToDisplay(HttpServletRequest request,
641
                                                @RequestParam(required = false, defaultValue = "0") int categoryId) throws Exception {
32339 tejbeer 642
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
643
        logger.info("userInfo [{}]", userInfo);
32717 ranu 644
        List<BrandCatalog> brandsDisplay = brandsService.getBrandsToDisplay(categoryId);
645
        //List<DBObject> brandsDisplay = mongoClient.getMongoBrands(userInfo.getRetailerId(), userInfo.getEmail(), categoryId);
32339 tejbeer 646
        return new ResponseEntity<>(brandsDisplay, HttpStatus.OK);
647
    }
25879 amit.gupta 648
 
32339 tejbeer 649
    @RequestMapping(value = "/fofo/brandCatalog", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
33575 amit.gupta 650
    public ResponseEntity<?> getBrands(HttpServletRequest request,
651
                                       @RequestParam(required = false, defaultValue = "0") int categoryId) throws Exception {
32339 tejbeer 652
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
653
        logger.info("userInfo [{}]", userInfo);
31507 tejbeer 654
 
32339 tejbeer 655
        List<BrandCatalog> brandsDisplay = brandsService.getBrands(userInfo.getRetailerId(), userInfo.getEmail(), categoryId);
656
        return new ResponseEntity<>(brandsDisplay, HttpStatus.OK);
657
    }
31507 tejbeer 658
 
32339 tejbeer 659
    @RequestMapping(value = "/fofo/accessory/all-categories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
660
    public ResponseEntity<?> getSubCategoriesToDisplay(HttpServletRequest request) throws Exception {
661
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
662
        logger.info("userInfo [{}]", userInfo);
663
        List<DBObject> subCategoriesDisplay = this.getSubCategoriesToDisplay();
664
        return new ResponseEntity<>(subCategoriesDisplay, HttpStatus.OK);
665
    }
23816 amit.gupta 666
 
32339 tejbeer 667
    private List<DBObject> getSubCategoriesToDisplay() throws Exception {
668
        List<DBObject> subCategories = new ArrayList<>();
669
        RestClient rc = new RestClient();
670
        Map<String, String> params = new HashMap<>();
671
        params.put("q", "categoryId_i:6");
672
        params.put("group", "true");
673
        params.put("group.field", "subCategoryId_i");
674
        params.put("wt", "json");
675
        params.put("rows", "50");
676
        params.put("fl", "subCategoryId_i");
677
        String response = null;
678
        try {
33487 amit.gupta 679
            response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
32339 tejbeer 680
        } catch (HttpHostConnectException e) {
681
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
682
        }
683
        JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("grouped");
684
        JSONArray groups = solrResponseJSONObj.getJSONObject("subCategoryId_i").getJSONArray("groups");
685
        List<Integer> categoryIds = new ArrayList<>();
686
        for (int i = 0; i < groups.length(); i++) {
687
            JSONObject groupObject = groups.getJSONObject(i);
688
            int subCategoryId = groupObject.getInt("groupValue");
689
            int quantity = groupObject.getJSONObject("doclist").getInt("numFound");
690
            categoryIds.add(subCategoryId);
691
        }
25015 amit.gupta 692
 
32339 tejbeer 693
        List<Category> categories = categoryRepository.selectByIds(categoryIds);
694
        AtomicInteger i = new AtomicInteger(0);
695
        categories.forEach(x -> {
696
            DBObject dbObject = new BasicDBObject();
697
            dbObject.put("name", x.getLabel());
698
            dbObject.put("subCategoryId", x.getId());
699
            dbObject.put("rank", i.incrementAndGet());
700
            dbObject.put("categoryId", 6);
701
            dbObject.put("url", "https://images.smartdukaan.com/uploads/campaigns/" + x.getId() + ".png");
702
            subCategories.add(dbObject);
703
        });
25015 amit.gupta 704
 
32339 tejbeer 705
        return subCategories;
25015 amit.gupta 706
 
32339 tejbeer 707
    }
25010 amit.gupta 708
 
32339 tejbeer 709
    @RequestMapping(value = "/banners/{bannerType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
710
    public ResponseEntity<?> getBanners(@PathVariable String bannerType) {
711
        return new ResponseEntity<>(mongoClient.getBannersByType(bannerType), HttpStatus.OK);
712
    }
23816 amit.gupta 713
 
32339 tejbeer 714
    @RequestMapping(value = "/deals/subCategories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
715
    public ResponseEntity<?> getSubcategoriesToDisplay() {
716
        return new ResponseEntity<>(mongoClient.getSubcategoriesToDisplay(), HttpStatus.OK);
717
    }
23816 amit.gupta 718
 
32339 tejbeer 719
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
720
    @RequestMapping(value = "/deals/skus/{skus}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
721
    public ResponseEntity<?> getDealsBySkus(@PathVariable String skus) throws ProfitMandiBusinessException {
722
        StringBuffer sb = new StringBuffer("/getDealsForNotification/");
723
        String uri = sb.append(skus).toString();
724
        RestClient rc = new RestClient();
725
        String response;
726
        try {
727
            response = rc.get(SchemeType.HTTP, host, port, uri, new HashMap<>());
728
        } catch (HttpHostConnectException e) {
729
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
730
        }
731
        JsonArray result_json = Json.parse(response).asArray();
732
        List<Object> responseObject = new ArrayList<>();
733
        for (JsonValue j : result_json) {
734
            // logger.info("res " + j.asArray());
735
            List<Object> innerObject = new ArrayList<>();
736
            for (JsonValue jsonObject : j.asArray()) {
737
                innerObject.add(toDealObject(jsonObject.asObject()));
738
            }
739
            if (innerObject.size() > 0) {
740
                responseObject.add(innerObject);
741
            }
742
        }
743
        return responseSender.ok(responseObject);
744
    }
21339 kshitij.so 745
 
32339 tejbeer 746
    @RequestMapping(value = "/partner/listing", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
747
    public ResponseEntity<?> getPartnersListing(HttpServletRequest request) throws Exception {
748
        List<WebListing> webListings = webListingRepository.selectAllWebListingByType(Optional.of(true), WebListingSource.partner);
749
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
750
        for (WebListing webListing : webListings) {
31642 tejbeer 751
 
33573 amit.gupta 752
            webListing.setFofoCatalogResponses(getDealResponses(userInfo, webListing, 0, 20));
32339 tejbeer 753
        }
754
        return responseSender.ok(webListings);
755
    }
31547 tejbeer 756
 
33576 amit.gupta 757
    private List<FofoCatalogResponse> getDealResponses(UserInfo userInfo, WebListing webListing, int offset,
758
                                                       int limit) throws Exception {
31572 tejbeer 759
 
32339 tejbeer 760
        RestClient rc = new RestClient();
761
        Map<String, String> params = new HashMap<>();
762
        List<String> mandatoryQ = new ArrayList<>();
31670 tejbeer 763
 
32339 tejbeer 764
        FofoStore fs = fofoStoreRepository.selectByRetailerId(userInfo.getRetailerId());
31670 tejbeer 765
 
32339 tejbeer 766
        params.put("sort", "w" + fs.getWarehouseId() + "_i desc");
31576 tejbeer 767
 
32339 tejbeer 768
        List<Integer> webProducts = null;
769
        if (webListing.getType().equals(WebListingType.solr)) {
770
            logger.info("solrtype {}", webListing.getSolrQuery());
771
            mandatoryQ.add(String.format("+{!parent which=\"" + webListing.getSolrQuery() + "\"} AND active_b:true AND show_default_b:true"));
772
        } else {
773
            logger.info("solrtype2 {}", webListing.getSolrQuery());
31675 tejbeer 774
 
33573 amit.gupta 775
            webProducts = webProductListingRepository.selectAllByWebListingId(webListing.getId(), offset, limit).stream().filter(x -> x.getRank() > 0).map(x -> x.getEntityId()).collect(Collectors.toList());
31572 tejbeer 776
 
32339 tejbeer 777
            if (webProducts.size() == 0) {
778
                return new ArrayList<>();
779
            }
31572 tejbeer 780
 
32339 tejbeer 781
            mandatoryQ.add(String.format(
33575 amit.gupta 782
                    "+{!parent which=\"catalogId_i:(" + StringUtils.join(webProducts, " ") + ")\"} AND active_b:true AND show_default_b:true"));
31642 tejbeer 783
 
32339 tejbeer 784
        }
785
        params.put("q", StringUtils.join(mandatoryQ, " "));
786
        params.put("fl", "*, [child parentFilter=id:catalog* childFilter=active_b:true ]");
31612 tejbeer 787
 
32339 tejbeer 788
        params.put("start", String.valueOf(offset));
789
        params.put("rows", String.valueOf(limit));
790
        params.put("wt", "json");
791
        String response = null;
792
        try {
793
            response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
794
        } catch (HttpHostConnectException e) {
795
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
796
        }
797
        JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
798
        JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
799
        List<FofoCatalogResponse> dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
31671 tejbeer 800
 
32339 tejbeer 801
        if (webProducts != null && webListing.getUrl().equals("new-launches")) {
802
            List<Integer> webProductsFinal = webProducts;
803
            dealResponse = dealResponse.stream().sorted(Comparator.comparing(x -> webProductsFinal.indexOf(x.getCatalogId()))).collect(Collectors.toList());
31671 tejbeer 804
 
32339 tejbeer 805
        }
31547 tejbeer 806
 
32339 tejbeer 807
        return dealResponse;
808
    }
30669 amit.gupta 809
 
32339 tejbeer 810
    @Autowired
811
    private SaholicCISTableRepository saholicCISTableRepository;
27053 amit.gupta 812
 
33575 amit.gupta 813
    private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal, int fofoId) throws
814
            Exception {
32339 tejbeer 815
        List<FofoCatalogResponse> dealResponse = new ArrayList<>();
816
        List<Integer> tagIds = Arrays.asList(4);
817
        List<Integer> itemIds = new ArrayList<>();
34260 vikas.jang 818
        Map<Integer, Integer> partnerStockAvailabilityMap = null;
32339 tejbeer 819
        if (docs.length() > 0) {
820
            for (int i = 0; i < docs.length(); i++) {
821
                JSONObject doc = docs.getJSONObject(i);
822
                if (doc.has("_childDocuments_")) {
823
                    for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
824
                        JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
825
                        int itemId = childItem.getInt("itemId_i");
826
                        itemIds.add(itemId);
827
                    }
828
                }
829
            }
830
            if (itemIds.size() == 0) {
831
                return dealResponse;
832
            }
833
        }
834
        // get warehouse Id
835
        int warehouseId = fofoStoreRepository.selectByRetailerId(fofoId).getWarehouseId();
836
        Map<Integer, List<SaholicPOItem>> poItemAvailabilityMap = saholicInventoryService.getSaholicPOItems().get(warehouseId);
837
        List<Integer> catalogIds = new ArrayList<>();
838
        for (int i = 0; i < docs.length(); i++) {
839
            JSONObject doc = docs.getJSONObject(i);
840
            catalogIds.add(doc.getInt("catalogId_i"));
841
        }
842
        List<CreateOfferRequest> allSchemOffers = null;
843
        Map<Integer, PriceCircularItemModelNew> priceCircularItemModelMap = new HashMap<>();
844
        if (catalogIds.size() > 0) {
845
            PriceCircularModel priceCircularModel = priceCircularService.getPriceCircularByOffer(fofoId, catalogIds, LocalDate.now());
846
            allSchemOffers = priceCircularModel.getOffers();
30188 amit.gupta 847
 
32339 tejbeer 848
            List<PriceCircularItemModelNew> priceCircularItemModelNews = priceCircularModel.getPriceCircularItemModelNews();
849
            if (priceCircularItemModelNews != null) {
850
                priceCircularItemModelMap = priceCircularItemModelNews.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
851
            }
852
        }
31629 tejbeer 853
 
33575 amit.gupta 854
        /*List<CatalogFavourite> catalogFavourites = catalogFavouriteRepository.selectBypartnerId(fofoId);
32339 tejbeer 855
        List<Integer> catalogFavouriteIds = new ArrayList<>();
856
        if (!catalogFavourites.isEmpty()) {
857
            catalogFavouriteIds = catalogFavourites.stream().map(x -> x.getCatalogId()).collect(Collectors.toList());
858
        }
31629 tejbeer 859
 
32339 tejbeer 860
        if (!catalogFavourites.isEmpty()) {
861
            catalogFavourites.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
33575 amit.gupta 862
        }*/
30595 tejbeer 863
 
34260 vikas.jang 864
        if (fofoId > 0) {
865
            partnerStockAvailabilityMap = currentInventorySnapshotRepository.selectItemsStock(fofoId).stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getAvailability()));
866
            logger.info("partnerStockAvailabilityMap: {}",partnerStockAvailabilityMap);
867
        }
868
 
32339 tejbeer 869
        for (int i = 0; i < docs.length(); i++) {
870
            Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
871
            JSONObject doc = docs.getJSONObject(i);
872
            FofoCatalogResponse fofoCatalogResponse = new FofoCatalogResponse();
873
            fofoCatalogResponse.setCatalogId(doc.getInt("catalogId_i"));
874
            fofoCatalogResponse.setImageUrl(doc.getString("imageUrl_s"));
875
            fofoCatalogResponse.setTitle(doc.getString("title_s"));
33975 tejus.loha 876
            fofoCatalogResponse.setSuperCatalogTitle(doc.getString("superCatalog_s"));
877
            fofoCatalogResponse.setSuperCatalogId(doc.getInt("superCatalog_i"));
878
            fofoCatalogResponse.setSuperCatalogVariants(doc.getString("superCatalogVariants_s"));
31629 tejbeer 879
 
33575 amit.gupta 880
            /*if (catalogFavouriteIds.contains(fofoCatalogResponse.getCatalogId())) {
32339 tejbeer 881
                fofoCatalogResponse.setFavourite(true);
33575 amit.gupta 882
            }*/
30683 tejbeer 883
 
32339 tejbeer 884
            List<WebOffer> webOffers = webOfferRepository.selectAllActiveOffers().get(fofoCatalogResponse.getCatalogId());
31612 tejbeer 885
 
33573 amit.gupta 886
            //logger.info("webOffers {}", webOffers);
32339 tejbeer 887
            if (webOffers != null && webOffers.size() > 0) {
888
                fofoCatalogResponse.setWebOffers(webOffers);
889
                fofoCatalogResponse.setOffers(webOffers.stream().map(x -> x.getTitle()).collect(Collectors.toList()));
30683 tejbeer 890
 
32339 tejbeer 891
            }
30683 tejbeer 892
 
32339 tejbeer 893
            List<ComboModel> comboModels = comboModelRepository.selectByWarehouseId(warehouseId).stream().filter(x -> x.getCatalogId() == fofoCatalogResponse.getCatalogId()).collect(Collectors.toList());
30683 tejbeer 894
 
33573 amit.gupta 895
            //logger.info("comboModels {}", comboModels);
32344 tejbeer 896
 
32339 tejbeer 897
            if (comboModels != null && comboModels.size() > 0) {
898
                fofoCatalogResponse.setComboModels(comboModels);
899
            }
30683 tejbeer 900
 
32339 tejbeer 901
            try {
902
                fofoCatalogResponse.setFeature(doc.getString("feature_s"));
903
            } catch (Exception e) {
904
                fofoCatalogResponse.setFeature(null);
905
                logger.info("Could not find Feature_s for {}", fofoCatalogResponse.getCatalogId());
906
            }
30683 tejbeer 907
 
32339 tejbeer 908
            fofoCatalogResponse.setBrand(doc.getJSONArray("brand_ss").getString(0));
909
            logger.info("labelss {}", doc.has("label_ss"));
30683 tejbeer 910
 
32339 tejbeer 911
            if (doc.has("label_ss")) {
912
                logger.info("label {}", doc.getJSONArray("label_ss"));
30683 tejbeer 913
 
32339 tejbeer 914
                JSONArray arr = doc.getJSONArray("label_ss");
915
                Set<String> labels = new HashSet<String>();
916
                for (int j = 0; j < arr.length(); j++) {
917
                    labels.add(arr.getString(j));
918
                }
31612 tejbeer 919
 
32339 tejbeer 920
                fofoCatalogResponse.setLabels(new ArrayList<>(labels));
31612 tejbeer 921
 
32339 tejbeer 922
            }
33573 amit.gupta 923
            if (doc.has("similarModels_ii")) {
924
                JSONArray similarModelsArray = doc.getJSONArray("similarModels_ii");
925
                List<Integer> similarCatalogIds = new ArrayList<>();
926
                for (int j = 0; j < similarModelsArray.length(); j++) {
927
                    similarCatalogIds.add(similarModelsArray.getInt(j));
928
                }
929
                fofoCatalogResponse.setSimilarModelIds(similarCatalogIds);
930
            }
31612 tejbeer 931
 
32339 tejbeer 932
            if (doc.has("_childDocuments_")) {
933
                String modelColorClass = "grey";
934
                FofoAvailabilityInfo fdiAnyColour = null;
935
                // Iterating itemIds
936
                for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
937
                    PriceCircularItemModelNew priceCircularItemModel = priceCircularItemModelMap.get(fofoCatalogResponse.getCatalogId());
938
                    JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
939
                    int itemId = childItem.getInt("itemId_i");
940
                    float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
34260 vikas.jang 941
                    int partnerAvailability = partnerStockAvailabilityMap.get(itemId) == null ? 0 : partnerStockAvailabilityMap.get(itemId);
32339 tejbeer 942
                    if (!fofoAvailabilityInfoMap.containsKey(itemId)) {
943
                        FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
944
                        List<SaholicCISTable> currentAvailability = saholicCISTableRepository.selectByItemWarehouse(itemId, warehouseId);
945
                        List<SaholicPOItem> poItemAvailability = null;
946
                        if (poItemAvailabilityMap != null) {
947
                            poItemAvailability = poItemAvailabilityMap.get(itemId);
948
                        }
31612 tejbeer 949
 
32339 tejbeer 950
                        if (priceCircularItemModel != null) {
33410 ranu 951
                            fdi.setNlc((float) priceCircularItemModel.getNetNlc());
32339 tejbeer 952
                        }
31612 tejbeer 953
 
32339 tejbeer 954
                        for (SaholicCISTable saholicCISTable : currentAvailability) {
955
                            saholicCISTable.setWarehouseName(
956
                                    ProfitMandiConstants.WAREHOUSE_MAP.get(saholicCISTable.getWarehouseFrom()));
957
                        }
31612 tejbeer 958
 
32339 tejbeer 959
                        Map<Integer, SaholicCISTable> map = currentAvailability.stream().collect(Collectors.toMap(SaholicCISTable::getWarehouseFrom, x -> x));
960
                        if (poItemAvailability != null) {
961
                            for (SaholicPOItem saholicPOItem : poItemAvailability) {
962
                                if (map.containsKey(saholicPOItem.getWarehouseFrom())) {
963
                                    map.get(saholicPOItem.getWarehouseFrom()).setPopendingQty(saholicPOItem.getUnfulfilledQty());
964
                                } else {
965
                                    SaholicCISTable saholicCISTable = new SaholicCISTable();
966
                                    saholicCISTable.setAvailability(0);
967
                                    saholicCISTable.setReserved(0);
968
                                    saholicCISTable.setItemId(itemId);
969
                                    saholicCISTable.setWarehouseId(warehouseId);
970
                                    saholicCISTable.setPopendingQty(saholicPOItem.getUnfulfilledQty());
971
                                    saholicCISTable.setWarehouseFrom(saholicPOItem.getWarehouseFrom());
972
                                    saholicCISTable.setWarehouseName(
973
                                            ProfitMandiConstants.WAREHOUSE_MAP.get(saholicPOItem.getWarehouseFrom()));
974
                                    map.put(saholicPOItem.getWarehouseFrom(), saholicCISTable);
975
                                }
976
                            }
977
                        }
978
                        fdi.setSaholicCISTableList(new ArrayList<>(map.values()));
979
                        String poColor = "grey";
980
                        boolean active = false;
981
                        if (currentAvailability != null && currentAvailability.stream().collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)) > 0) {
982
                            poColor = "green";
983
                            modelColorClass = "green";
32978 amit.gupta 984
                        } else if (poItemAvailability != null && poItemAvailability.stream().collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty)) > 0) {
985
                            if (currentAvailability != null && poItemAvailability.stream().collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty)) + currentAvailability.stream().collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)) <= 0) {
986
                                poColor = "grey";
987
                            } else {
988
                                poColor = "yellow";
989
                                if (modelColorClass != "green") {
990
                                    modelColorClass = poColor;
32339 tejbeer 991
                                }
992
                            }
32978 amit.gupta 993
                        }
32339 tejbeer 994
                        fdi.setColorClass(poColor);
995
                        fdi.setSellingPrice(sellingPrice);
996
                        fdi.setActive(active);
997
                        fdi.setMrp(childItem.getDouble("mrp_f"));
998
                        fdi.setMop((float) childItem.getDouble("mop_f"));
999
                        fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
1000
                        if (fdi.getColor().equalsIgnoreCase("any colour")) {
1001
                            fdiAnyColour = fdi;
1002
                        }
33929 tejus.loha 1003
                        fdi.setBrand((String) doc.getJSONArray("brand_ss").get(0));
1004
                        fdi.setCategoryId(doc.getInt("subCategoryId_i"));
32339 tejbeer 1005
                        fdi.setTagId(childItem.getInt("tagId_i"));
1006
                        fdi.setItem_id(itemId);
34196 ranu 1007
                        fdi.setCatalog_id(doc.getInt("catalogId_i"));
32978 amit.gupta 1008
                        Float cashBack = schemeService.getCatalogSchemeCashBack(fofoId, Arrays.asList(fofoCatalogResponse.getCatalogId())).get(fofoCatalogResponse.getCatalogId());
32339 tejbeer 1009
                        cashBack = cashBack == null ? 0 : cashBack;
1010
                        fdi.setCashback(cashBack);
1011
                        fdi.setMinBuyQuantity(1);
1012
                        if (hotDeal) {
1013
                            if (currentAvailability != null) {
1014
                                fdi.setAvailability(currentAvailability.stream().collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)));
1015
                            } else {
1016
                                fdi.setAvailability(0);
1017
                            }
34260 vikas.jang 1018
                            fdi.setPartnerAvailability(partnerAvailability);
32339 tejbeer 1019
                        } else {
1020
                            // Lets consider that its out of stock
32591 amit.gupta 1021
                            fdi.setAvailability(400);
32339 tejbeer 1022
                            Item item = null;
1023
                            try {
1024
                                item = itemRepository.selectById(itemId);
1025
                            } catch (Exception e) {
1026
                                e.printStackTrace();
1027
                                continue;
1028
                            }
1029
                            // In case its tampered glass moq should be
1030
                            if (item.getCategoryId() == 10020) {
1031
                                fdi.setMinBuyQuantity(5);
1032
                            }
1033
                        }
1034
                        fdi.setQuantityStep(1);
32590 amit.gupta 1035
                        fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 400));
32339 tejbeer 1036
                        fofoAvailabilityInfoMap.put(itemId, fdi);
1037
                    }
1038
                }
1039
                if (fdiAnyColour != null) {
1040
                    fdiAnyColour.setColorClass(modelColorClass);
1041
                }
33576 amit.gupta 1042
                fofoCatalogResponse.setInStock(!modelColorClass.equals("grey"));
32339 tejbeer 1043
            }
1044
            if (fofoAvailabilityInfoMap.values().size() > 0) {
1045
                List<FofoAvailabilityInfo> availabilityList = fofoAvailabilityInfoMap.values().stream().sorted(Comparator.comparing(FofoAvailabilityInfo::getAvailability).reversed()).collect(Collectors.toList());
1046
                fofoCatalogResponse.setItems(availabilityList);
1047
                if (priceCircularItemModelMap.containsKey(fofoCatalogResponse.getCatalogId())) {
1048
                    PriceCircularItemModelNew priceCircularItemModel = priceCircularItemModelMap.get(fofoCatalogResponse.getCatalogId());
1049
                    if (priceCircularItemModel.getSlabPayouts() != null) {
1050
                        List<CreateOfferRequest> schemeOffers = new ArrayList<>();
1051
                        List<Map<Integer, AmountModel>> slabPayouts = priceCircularItemModel.getSlabPayouts();
1052
                        Iterator<Map<Integer, AmountModel>> iterator = slabPayouts.iterator();
1053
                        int iteratorCount = 0;
1054
                        while (iterator.hasNext()) {
1055
                            Map<Integer, AmountModel> slabPayoutMap = iterator.next();
1056
                            if (slabPayoutMap != null) {
1057
                                schemeOffers.add(allSchemOffers.get(iteratorCount));
1058
                            } else {
1059
                                iterator.remove();
1060
                            }
1061
                            iteratorCount++;
1062
                        }
1063
                        fofoCatalogResponse.setSchemeOffers(schemeOffers);
1064
                    }
1065
                    fofoCatalogResponse.setPriceCircularItemModel(priceCircularItemModel);
1066
                }
1067
                dealResponse.add(fofoCatalogResponse);
1068
            }
1069
        }
1070
        return dealResponse;
30686 amit.gupta 1071
 
32339 tejbeer 1072
    }
30693 amit.gupta 1073
 
33575 amit.gupta 1074
    private List<FofoCatalogResponse> getCatalogSingleSkuResponse(JSONArray
1075
                                                                          docs, Map<Integer, Integer> itemFilter, boolean hotDeal) throws ProfitMandiBusinessException {
32339 tejbeer 1076
        List<FofoCatalogResponse> dealResponse = new ArrayList<>();
1077
        List<Integer> tagIds = Arrays.asList(4);
24091 tejbeer 1078
 
33873 ranu 1079
        Map<Integer, TagListing> itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemFilter.keySet(), new HashSet<>(tagIds)).stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x));
24091 tejbeer 1080
 
32339 tejbeer 1081
        for (int i = 0; i < docs.length(); i++) {
1082
            Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
1083
            JSONObject doc = docs.getJSONObject(i);
26589 amit.gupta 1084
 
32339 tejbeer 1085
            for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
1086
                JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
1087
                int itemId = childItem.getInt("itemId_i");
1088
                TagListing tl = itemTagListingMap.get(itemId);
1089
                if (tl == null) {
1090
                    continue;
1091
                }
1092
                if (hotDeal) {
1093
                    if (!tl.isHotDeals()) {
1094
                        continue;
1095
                    }
1096
                }
1097
                float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
1098
                if (fofoAvailabilityInfoMap.containsKey(itemId)) {
1099
                    if (fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
1100
                        fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
1101
                        fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
1102
                    }
1103
                } else {
1104
                    FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
1105
                    fdi.setSellingPrice((float) childItem.getDouble("sellingPrice_f"));
1106
                    fdi.setMop((float) childItem.getDouble("mop_f"));
1107
                    fdi.setMop((float) tl.getMrp());
1108
                    fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
1109
                    fdi.setTagId(childItem.getInt("tagId_i"));
1110
                    fdi.setItem_id(itemId);
34196 ranu 1111
                    fdi.setCatalog_id(doc.getInt("catalogId_i"));
32339 tejbeer 1112
                    Item item = itemRepository.selectById(itemId);
1113
                    // In case its tampered glass moq should be 5
1114
                    if (item.getCategoryId() == 10020) {
1115
                        fdi.setMinBuyQuantity(10);
1116
                    } else {
1117
                        fdi.setMinBuyQuantity(1);
1118
                    }
1119
                    fdi.setAvailability(itemFilter.get(itemId));
1120
                    fdi.setQuantityStep(1);
1121
                    fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
1122
                    fofoAvailabilityInfoMap.put(itemId, fdi);
1123
                }
1124
            }
1125
            if (fofoAvailabilityInfoMap.values().size() > 0) {
1126
                for (FofoAvailabilityInfo fofoAvailabilityInfo : fofoAvailabilityInfoMap.values()) {
1127
                    FofoCatalogResponse ffdr = new FofoCatalogResponse();
1128
                    ffdr.setCatalogId(doc.getInt("catalogId_i"));
1129
                    ffdr.setImageUrl(doc.getString("imageUrl_s"));
1130
                    ffdr.setTitle(doc.getString("title_s"));
1131
                    try {
1132
                        ffdr.setFeature(doc.getString("feature_s"));
1133
                    } catch (Exception e) {
1134
                        ffdr.setFeature(null);
1135
                        logger.info("Could not find Feature_s for {}", ffdr.getCatalogId());
1136
                    }
1137
                    ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
1138
                    ffdr.setItems(Arrays.asList(fofoAvailabilityInfo));
1139
                    dealResponse.add(ffdr);
1140
                }
1141
            }
1142
        }
1143
        return dealResponse;
25880 amit.gupta 1144
 
32339 tejbeer 1145
    }
25880 amit.gupta 1146
 
32339 tejbeer 1147
    @RequestMapping(value = "/combo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
1148
    public ResponseEntity<?> getBanners(@RequestParam int catalogId, @RequestParam int warehouseId) {
1149
        List<ComboModel> comboModels = comboModelRepository.selectByCatalogIdAndWarehouseId(catalogId, warehouseId);
1150
        return responseSender.ok(comboModels);
1151
    }
32344 tejbeer 1152
 
1153
    @RequestMapping(value = "/checkCombo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
33575 amit.gupta 1154
    public ResponseEntity<?> checkCombo(HttpServletRequest request, @RequestParam int catalogId,
1155
                                        @RequestParam int warehouseId, @RequestParam int qty) throws Exception {
32344 tejbeer 1156
        boolean isCombo = false;
1157
        ComboModel comboModel = comboModelRepository.selectByCatalogIdWarehouseIdAndQty(catalogId, warehouseId, qty);
1158
        if (comboModel != null) {
1159
            isCombo = true;
1160
        }
1161
 
1162
        return responseSender.ok(isCombo);
1163
    }
1164
 
33929 tejus.loha 1165
    @GetMapping(value = "/partner/wodCompleteBrands", produces = MediaType.APPLICATION_JSON_VALUE)
1166
    public ResponseEntity<?> getWodcompletBrands(HttpServletRequest request) throws Exception {
1167
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
34630 tejus.loha 1168
        BrandAndAddToCartEligibleModel brandAndAddToCartEligibleModel = brandsService.wodcompletBrands(userInfo.getRetailerId());
1169
        return responseSender.ok(brandAndAddToCartEligibleModel);
33929 tejus.loha 1170
 
1171
    }
1172
 
25967 amit.gupta 1173
}