Subversion Repositories SmartDukaan

Rev

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