Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
31604 tejbeer 1
package com.spice.profitmandi.dao.service.solr;
2
 
33245 ranu 3
import com.google.gson.Gson;
4
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
33562 amit.gupta 5
import com.spice.profitmandi.common.model.ProfitMandiConstants;
33245 ranu 6
import com.spice.profitmandi.dao.entity.catalog.TagListing;
7
import com.spice.profitmandi.dao.entity.catalog.TagRanking;
8
import com.spice.profitmandi.dao.entity.dtr.WebProductListing;
33542 amit.gupta 9
import com.spice.profitmandi.dao.entity.similarModel.SimilarModel;
33245 ranu 10
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
11
import com.spice.profitmandi.dao.repository.catalog.TagRankingRepository;
12
import com.spice.profitmandi.dao.repository.dtr.Mongo;
13
import com.spice.profitmandi.dao.repository.dtr.WebListingRepository;
14
import com.spice.profitmandi.dao.repository.dtr.WebProductListingRepository;
33542 amit.gupta 15
import com.spice.profitmandi.dao.repository.similarModel.SimilarModelRepository;
33245 ranu 16
import com.spice.profitmandi.service.tag.ItemTagModel;
17
import in.shop2020.model.v1.catalog.status;
31604 tejbeer 18
import org.apache.logging.log4j.LogManager;
19
import org.apache.logging.log4j.Logger;
20
import org.apache.solr.client.solrj.SolrClient;
21
import org.apache.solr.client.solrj.impl.HttpSolrClient;
22
import org.apache.solr.common.SolrInputDocument;
23
import org.json.JSONArray;
24
import org.json.JSONException;
25
import org.json.JSONObject;
26
import org.springframework.beans.factory.annotation.Autowired;
31613 tejbeer 27
import org.springframework.beans.factory.annotation.Value;
31604 tejbeer 28
import org.springframework.stereotype.Component;
29
 
33245 ranu 30
import java.io.BufferedReader;
31
import java.io.IOException;
32
import java.io.InputStream;
33
import java.io.InputStreamReader;
34
import java.net.HttpURLConnection;
35
import java.net.URL;
36
import java.net.URLConnection;
37
import java.time.ZoneId;
38
import java.util.*;
39
import java.util.Map.Entry;
40
import java.util.stream.Collectors;
41
import java.util.zip.GZIPInputStream;
31604 tejbeer 42
 
43
@Component
44
public class FofoSolr {
45
 
33542 amit.gupta 46
    @Autowired
47
    private Gson gson;
31604 tejbeer 48
 
33542 amit.gupta 49
    @Autowired
50
    private TagListingRepository tagListingRepository;
31604 tejbeer 51
 
33542 amit.gupta 52
    @Autowired
53
    TagRankingRepository tagRankingRepository;
31604 tejbeer 54
 
33542 amit.gupta 55
    @Autowired
56
    private Mongo contentMongoClient;
31604 tejbeer 57
 
33542 amit.gupta 58
    @Autowired
59
    private WebListingRepository webListingRepository;
31612 tejbeer 60
 
33542 amit.gupta 61
    @Autowired
62
    private WebProductListingRepository webProductListingRepository;
31612 tejbeer 63
 
33542 amit.gupta 64
    @Value("${new.solr.url}")
65
    private String solrUrl;
31613 tejbeer 66
 
33542 amit.gupta 67
    @Value("${reportico.url}")
68
    private String reporticoUrl;
33486 amit.gupta 69
 
33542 amit.gupta 70
    private static final Logger logger = LogManager.getLogger(FofoSolr.class);
31604 tejbeer 71
 
33542 amit.gupta 72
    private static final List<Integer> CATEGORY_MASTER = Arrays.asList(10006, 10010, 14202, 14203);
31604 tejbeer 73
 
33542 amit.gupta 74
    private static String getUrlContent(String urlString) {
75
        BufferedReader reader = null;
76
        try {
77
            URL url = new URL(urlString);
78
            URLConnection conn = url.openConnection();
79
            conn.setConnectTimeout(5000);
80
            conn.setReadTimeout(5000);
81
            reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
82
            return reader.lines().collect(Collectors.joining(System.lineSeparator()));
83
        } catch (IOException e) {
84
            e.printStackTrace();
85
        } finally {
86
            if (reader != null) {
87
                try {
88
                    reader.close();
89
                } catch (IOException e) {
90
                    e.printStackTrace();
91
                }
92
            }
93
        }
94
        return null;
95
    }
31604 tejbeer 96
 
33542 amit.gupta 97
    public JSONArray getAvailability() throws IOException, JSONException {
98
        String url = reporticoUrl + "?execute_mode=EXECUTE&xmlin=warehousecisnew.xml&project=FOCOR&project_password=focor&target_format=JSON";
99
        HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
100
        connection.setRequestProperty("Accept-Encoding", "gzip");
101
        BufferedReader reader = null;
31604 tejbeer 102
 
33542 amit.gupta 103
        try {
104
            InputStream inputStream = connection.getInputStream();
31604 tejbeer 105
 
33542 amit.gupta 106
            if ("gzip".equals(connection.getContentEncoding())) {
107
                inputStream = new GZIPInputStream(inputStream);
108
            }
31604 tejbeer 109
 
33542 amit.gupta 110
            reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
111
            StringBuilder responseBuilder = new StringBuilder();
112
            String line;
31604 tejbeer 113
 
33542 amit.gupta 114
            while ((line = reader.readLine()) != null) {
115
                responseBuilder.append(line);
116
            }
31604 tejbeer 117
 
33542 amit.gupta 118
            JSONObject responseJson = new JSONObject(responseBuilder.toString());
119
            return responseJson.getJSONArray("data");
120
        } finally {
121
            if (reader != null) {
122
                try {
123
                    reader.close();
124
                } catch (IOException e) {
125
                    // Ignore
126
                }
127
            }
128
        }
129
    }
31604 tejbeer 130
 
33542 amit.gupta 131
    public JSONArray getPendingPO() throws IOException, JSONException {
132
        String url = reporticoUrl + "?execute_mode=EXECUTE&xmlin=UnfulfilledPOItemsNew.xml&project=FOCOR&project_password=focor&target_format=JSON";
133
        HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
134
        connection.setRequestProperty("Accept-Encoding", "gzip");
135
        BufferedReader reader = null;
31604 tejbeer 136
 
33542 amit.gupta 137
        try {
138
            InputStream inputStream = connection.getInputStream();
31604 tejbeer 139
 
33542 amit.gupta 140
            if ("gzip".equals(connection.getContentEncoding())) {
141
                inputStream = new GZIPInputStream(inputStream);
142
            }
31604 tejbeer 143
 
33542 amit.gupta 144
            reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
145
            StringBuilder responseBuilder = new StringBuilder();
146
            String line;
31604 tejbeer 147
 
33542 amit.gupta 148
            while ((line = reader.readLine()) != null) {
149
                responseBuilder.append(line);
150
            }
31604 tejbeer 151
 
33542 amit.gupta 152
            JSONObject responseJson = new JSONObject(responseBuilder.toString());
153
            return responseJson.getJSONArray("data");
154
        } finally {
155
            if (reader != null) {
156
                try {
157
                    reader.close();
158
                } catch (IOException e) {
159
                    // Ignore
160
                }
161
            }
162
        }
163
    }
31604 tejbeer 164
 
33542 amit.gupta 165
    public Map<String, Map<String, Map<String, Integer>>> getItemMap() throws Exception {
166
        JSONArray availabilityJSONArray = this.getAvailability();
167
        JSONArray pendingPOJSONArray = this.getPendingPO();
168
        Map<String, Map<String, Map<String, Integer>>> availabilityItemMap = new HashMap<>();
31604 tejbeer 169
 
33542 amit.gupta 170
        for (int i = 0; i < availabilityJSONArray.length(); i++) {
171
            JSONObject rawAvailability = availabilityJSONArray.getJSONObject(i);
172
            if (!availabilityItemMap.containsKey(rawAvailability.getString("Itemid"))) {
173
                availabilityItemMap.put(rawAvailability.getString("Itemid"),
174
                        new HashMap<String, Map<String, Integer>>());
175
            }
176
            if (!availabilityItemMap.get(rawAvailability.getString("Itemid"))
177
                    .containsKey(rawAvailability.getString("Warehouseid"))) {
178
                availabilityItemMap.get(rawAvailability.getString("Itemid"))
179
                        .put(rawAvailability.getString("Warehouseid"), new HashMap<String, Integer>());
180
                availabilityItemMap.get(rawAvailability.getString("Itemid"))
181
                        .get(rawAvailability.getString("Warehouseid")).put("netAvailability", 0);
182
                availabilityItemMap.get(rawAvailability.getString("Itemid"))
183
                        .get(rawAvailability.getString("Warehouseid")).put("netPo", 0);
184
            }
185
            int netAvailability = availabilityItemMap.get(rawAvailability.getString("Itemid"))
186
                    .get(rawAvailability.getString("Warehouseid")).get("netAvailability")
187
                    + rawAvailability.getInt("Netavailability");
188
            availabilityItemMap.get(rawAvailability.getString("Itemid")).get(rawAvailability.getString("Warehouseid"))
189
                    .put("netAvailability", netAvailability);
190
        }
31604 tejbeer 191
 
33542 amit.gupta 192
        for (int i = 0; i < pendingPOJSONArray.length(); i++) {
193
            JSONObject rawPendingPo = pendingPOJSONArray.getJSONObject(i);
31604 tejbeer 194
 
33542 amit.gupta 195
            String itemId = rawPendingPo.getString("Itemid");
196
            String warehouseId = rawPendingPo.getString("Warehouseid");
197
            if (!availabilityItemMap.containsKey(itemId)) {
198
                availabilityItemMap.put(itemId, new HashMap<String, Map<String, Integer>>());
199
            }
200
            if (!availabilityItemMap.get(itemId).containsKey(warehouseId)) {
201
                availabilityItemMap.get(itemId).put(warehouseId, new HashMap<String, Integer>() {
202
                    {
203
                        put("netAvailability", 0);
204
                        put("netPo", 0);
205
                    }
206
                });
207
            }
208
            availabilityItemMap.get(itemId).get(warehouseId).put("netPo",
209
                    availabilityItemMap.get(itemId).get(warehouseId).get("netPo") + rawPendingPo.getInt("Unfulfilled"));
31604 tejbeer 210
 
33542 amit.gupta 211
        }
212
        return availabilityItemMap;
31604 tejbeer 213
 
33542 amit.gupta 214
    }
31604 tejbeer 215
 
33245 ranu 216
    public Map<Integer, List<String>> getLabels() throws ProfitMandiBusinessException {
33542 amit.gupta 217
        List<String> labels = Arrays.asList("partner-best-sellers", "partner-price-drop", "new-launches",
218
                "upgrade-offer", "special-support");
31612 tejbeer 219
 
33542 amit.gupta 220
        Map<Integer, String> webListing = webListingRepository.selectByUrls(labels).stream()
221
                .collect(Collectors.toMap(x -> x.getId(), x -> x.getUrl()));
31612 tejbeer 222
 
33542 amit.gupta 223
        Map<Integer, List<WebProductListing>> webProductListingMap = webProductListingRepository
224
                .selectAllByWebListingIds(new ArrayList<>(webListing.keySet())).stream()
225
                .collect(Collectors.groupingBy(x -> x.getWebListingId()));
31612 tejbeer 226
 
33542 amit.gupta 227
        Map<Integer, List<String>> catalogLabelMap = new HashMap<>();
228
        for (Entry<Integer, List<WebProductListing>> webProductListingEntry : webProductListingMap.entrySet()) {
31612 tejbeer 229
 
33542 amit.gupta 230
            for (WebProductListing webProduct : webProductListingEntry.getValue()) {
31612 tejbeer 231
 
33542 amit.gupta 232
                if (!catalogLabelMap.containsKey(webProduct.getEntityId())) {
31612 tejbeer 233
 
33542 amit.gupta 234
                    catalogLabelMap.put(webProduct.getEntityId(), new ArrayList<>());
31612 tejbeer 235
 
33542 amit.gupta 236
                }
31612 tejbeer 237
 
33542 amit.gupta 238
                List<String> itemLabels = catalogLabelMap.get(webProduct.getEntityId());
239
                itemLabels.add(webListing.get(webProduct.getWebListingId()));
240
                catalogLabelMap.put(webProduct.getEntityId(), itemLabels);
31612 tejbeer 241
 
33542 amit.gupta 242
            }
31612 tejbeer 243
 
33542 amit.gupta 244
        }
31612 tejbeer 245
 
33542 amit.gupta 246
        return catalogLabelMap;
247
    }
31612 tejbeer 248
 
33542 amit.gupta 249
    @Autowired
250
    SimilarModelRepository similarModelRepository;
31604 tejbeer 251
 
33542 amit.gupta 252
    public void populateTagItems() throws Exception {
253
        Map<String, Map<String, Map<String, Integer>>> availabilityItemMap = getItemMap();
254
        List<TagRanking> tagRankingList = tagRankingRepository.getAllTagRanking();
255
        List<Integer> rankingList = new ArrayList<>();
256
        Map<Integer, String> featureMap = new HashMap<>();
257
        for (TagRanking tagRanking : tagRankingList) {
258
            rankingList.add(tagRanking.getCatalogItemId());
259
            featureMap.put(tagRanking.getCatalogItemId(), tagRanking.getFeature());
260
        }
261
        //Get Similar Models
262
        List<SimilarModel> similarModels = similarModelRepository.selectAll();
31612 tejbeer 263
 
33562 amit.gupta 264
        Map<Integer, List<Integer>> similarModelsMap = similarModels.stream().collect(Collectors.groupingBy(SimilarModel::getCatalogId, Collectors.mapping(x -> x.getSimilarCatalogId(), Collectors.toList())));
31612 tejbeer 265
 
33542 amit.gupta 266
        Map<Integer, Map<String, Object>> catalogMap = new HashMap<>();
31612 tejbeer 267
 
33542 amit.gupta 268
        List<status> statuses = Arrays.asList(status.ACTIVE, status.PAUSED_BY_RISK, status.PARTIALLY_ACTIVE);
31612 tejbeer 269
 
33542 amit.gupta 270
        Map<Integer, List<String>> catalogLabelMap = this.getLabels();
31604 tejbeer 271
 
33542 amit.gupta 272
        logger.info("catalogLabelMap {}", catalogLabelMap);
31604 tejbeer 273
 
33542 amit.gupta 274
        /*
275
         * List<ItemTagModel> tuples =
276
         * tagListingRepository.getAllItemTagByStatus(statuses).stream() .filter(x ->
277
         * x.getItem().getCatalogItemId() == 1023747).collect(Collectors.toList());
278
         */
31604 tejbeer 279
 
33562 amit.gupta 280
        List<ItemTagModel> itemTagModels = tagListingRepository.getAllItemTagByStatus(statuses);
31604 tejbeer 281
 
33542 amit.gupta 282
        Map<String, Object> projection = new HashMap<>();
283
        projection.put("defaultImageUrl", 1);
31604 tejbeer 284
 
33542 amit.gupta 285
        List<String> excludeBrands = Arrays.asList("Dummy", "FOC HANDSET");
31604 tejbeer 286
 
33562 amit.gupta 287
        Map<Float, List<Integer>> priceModelMap = new TreeMap<>();
288
        for (ItemTagModel itemTagModel : itemTagModels) {
289
            TagListing tagListing = itemTagModel.getTagListing();
290
            com.spice.profitmandi.dao.entity.catalog.Item item = itemTagModel.getItem();
33542 amit.gupta 291
            if (excludeBrands.contains(item.getBrand())) {
292
                continue;
293
            }
31604 tejbeer 294
 
33542 amit.gupta 295
            if (!catalogMap.containsKey(item.getCatalogItemId())) {
33562 amit.gupta 296
 
33563 amit.gupta 297
                if (!priceModelMap.containsKey(tagListing.getSellingPrice()) && item.getCategoryId() == 10006) {
33562 amit.gupta 298
                    priceModelMap.put(tagListing.getSellingPrice(), new ArrayList<>());
299
                }
300
                List<Integer> priceModels = priceModelMap.get(tagListing.getSellingPrice());
301
                priceModels.add(item.getCatalogItemId());
302
 
33542 amit.gupta 303
                Map<String, Object> catalogObj = new HashMap<>();
33546 amit.gupta 304
 
33542 amit.gupta 305
                catalogObj.put("feature", "");
306
                catalogObj.put("hsnCode", item.getHsnCode());
307
                catalogObj.put("title",
308
                        String.join(" ", Arrays.asList(item.getBrand(), item.getModelName(), item.getModelNumber())
309
                                .stream().filter(s -> s != null && !s.isEmpty()).collect(Collectors.toList())));
310
                catalogObj.put("brand", new String[]{item.getBrand()});
311
                if (item.getBrand().equals("Huawei") || item.getBrand().equals("Honor")) {
312
                    catalogObj.put("brand", new String[]{"Huawei", "Honor"});
313
                }
314
                if (item.getBrand().equals("Mi") || item.getBrand().equals("Xiaomi")
315
                        || item.getBrand().equals("Redmi")) {
316
                    catalogObj.put("brand", new String[]{"Mi", "Xiaomi", "Redmi"});
317
                }
318
                catalogObj.put("identifier", item.getCatalogItemId());
319
                catalogObj.put("items", new HashMap<Integer, Map<String, Object>>());
320
                Map<String, Object> filterMap = new HashMap<>();
321
                filterMap.put("_id", item.getCatalogItemId());
322
                // Don't include if catalog not available
323
                try {
324
                    String imageUrl = contentMongoClient.getEntityById(item.getCatalogItemId()).getDefaultImageUrl();
31624 tejbeer 325
 
33542 amit.gupta 326
                    if (imageUrl != null) {
327
                        catalogObj.put("imageUrl", imageUrl);
328
                    } else {
329
                        catalogObj.put("imageUrl",
330
                                "https://images.smartdukaan.com/uploads/campaigns/" + item.getCatalogItemId() + ".jpg");
331
                    }
332
                } catch (Exception e) {
333
                    try {
334
                        catalogObj.put("imageUrl",
335
                                "https://images.smartdukaan.com/uploads/campaigns/" + item.getCatalogItemId() + ".jpg");
336
                    } catch (Exception e2) {
337
                        e2.printStackTrace();
338
                    }
339
                }
340
                try {
341
                    catalogObj.put("rank", rankingList.indexOf(item.getCatalogItemId()));
342
                } catch (Exception e) {
343
                    // A very big number
344
                    e.printStackTrace();
345
                    catalogObj.put("rank", 50000000);
346
                }
347
                if (featureMap.containsKey(item.getCatalogItemId())
348
                        && featureMap.get(item.getCatalogItemId()) != null) {
349
                    catalogObj.put("feature", featureMap.get(item.getCatalogItemId()));
31612 tejbeer 350
 
33542 amit.gupta 351
                }
31612 tejbeer 352
 
33542 amit.gupta 353
                catalogObj.put("categoryId", CATEGORY_MASTER.contains(item.getCategoryId()) ? item.getCategoryId() : 6);
31612 tejbeer 354
 
33542 amit.gupta 355
                if (item.getCategoryId() == 10006) {
356
                    catalogObj.put("categoryId", 3);
357
                }
358
                catalogObj.put("subCategoryId", item.getCategoryId());
359
                catalogObj.put("create_timestamp",
33562 amit.gupta 360
                        tagListing.getCreatedTimestamp().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
31604 tejbeer 361
 
33542 amit.gupta 362
                if (catalogLabelMap.containsKey(item.getCatalogItemId())
363
                        && catalogLabelMap.get(item.getCatalogItemId()) != null) {
364
                    catalogObj.put("labels", catalogLabelMap.get(item.getCatalogItemId()));
31604 tejbeer 365
 
33542 amit.gupta 366
                }
367
                catalogMap.put(item.getCatalogItemId(), catalogObj);
368
                catalogObj.put("avColor", new HashMap<>());
31604 tejbeer 369
 
33542 amit.gupta 370
            }
31604 tejbeer 371
 
33542 amit.gupta 372
            Map<String, Object> catalogObj = catalogMap.get(item.getCatalogItemId());
373
            Map<Integer, Integer> avColorMap = (Map<Integer, Integer>) catalogObj.get("avColor");
31604 tejbeer 374
 
33542 amit.gupta 375
            if (availabilityItemMap.containsKey(String.valueOf(item.getId()))) {
376
                for (Map.Entry<String, Map<String, Integer>> entry : availabilityItemMap
377
                        .get(String.valueOf(item.getId())).entrySet()) {
378
                    String warehouseId = entry.getKey();
379
                    Map<String, Integer> avMap = entry.getValue();
380
                    if (!avColorMap.containsKey(Integer.parseInt(warehouseId))) {
381
                        avColorMap.put(Integer.parseInt(warehouseId), 0);
382
                    }
383
                    int color = avColorMap.get(Integer.parseInt(warehouseId));
31604 tejbeer 384
 
33542 amit.gupta 385
                    if (avMap.get("netAvailability") > 0) {
386
                        color = 2;
33562 amit.gupta 387
                    } else if (avMap.get("netPo") > 0) {
33542 amit.gupta 388
                        color = Math.max(color, 1);
389
                    } else {
390
                        color = Math.max(color, 0);
391
                    }
392
                    avColorMap.put(Integer.parseInt(warehouseId), color);
31604 tejbeer 393
 
33542 amit.gupta 394
                    catalogObj.put("avColor", avColorMap);
31604 tejbeer 395
 
33542 amit.gupta 396
                }
31604 tejbeer 397
 
33542 amit.gupta 398
            }
31604 tejbeer 399
 
33542 amit.gupta 400
            Map<Integer, Object> itemColorMap = (Map<Integer, Object>) catalogObj.get("items");
31604 tejbeer 401
 
33542 amit.gupta 402
            if (!itemColorMap.containsKey(item.getId())) {
403
                itemColorMap.put(item.getId(), new HashMap<String, Object>() {
404
                    {
405
                        put("color", item.getColor().replace("f_", ""));
406
                        put("tagPricing", new ArrayList<TagListing>());
407
                    }
408
                });
409
            }
410
            Map<String, Object> itemMap = (Map<String, Object>) itemColorMap.get(item.getId());
411
            List<TagListing> tagPricing = (List<TagListing>) itemMap.get("tagPricing");
33562 amit.gupta 412
            tagPricing.add(tagListing);
33542 amit.gupta 413
        }
33562 amit.gupta 414
        //logger.info("catalogObj {}", catalogMap);
31604 tejbeer 415
 
33542 amit.gupta 416
        List<SolrInputDocument> catalogSolrObjs = new ArrayList<>();
417
        for (Entry<Integer, Map<String, Object>> entry : catalogMap.entrySet()) {
418
            int catalogId = entry.getKey();
419
            Map<String, Object> catalogValMap = entry.getValue();
420
            Map<Integer, Object> itemsMap = (Map<Integer, Object>) catalogValMap.get("items");
31604 tejbeer 421
 
33542 amit.gupta 422
            boolean active = false;
423
            // Map<Integer, Object> itemsMap = (Map<String, Object>)
424
            // catalogValMap.get("items");
425
            List<SolrInputDocument> itemObjs = new ArrayList<>();
426
            float mop = 0;
33562 amit.gupta 427
            float dp = 0;
31604 tejbeer 428
 
33542 amit.gupta 429
            for (Entry<Integer, Object> itemEntry : itemsMap.entrySet()) {
430
                int itemId = itemEntry.getKey();
431
                Map<String, Object> itemMap = (Map<String, Object>) itemEntry.getValue();
432
                List<TagListing> tags = (List<TagListing>) itemMap.get("tagPricing");
433
                SolrInputDocument itemObj = new SolrInputDocument();
31604 tejbeer 434
 
33542 amit.gupta 435
                for (TagListing taglist : tags) {
33562 amit.gupta 436
                    active = active || taglist.isActive();
33542 amit.gupta 437
                    itemObj.setField("id", "itemtag-" + itemId + "-" + taglist.getTagId());
438
                    itemObj.setField("color_s", itemMap.get("color"));
439
                    itemObj.setField("itemId_i", itemId);
440
                    itemObj.setField("tagId_i", taglist.getTagId());
441
                    itemObj.setField("mrp_f", taglist.getMrp());
442
                    itemObj.setField("mop_f", taglist.getMop());
443
                    itemObj.setField("sellingPrice_f", taglist.getSellingPrice());
444
                    itemObj.setField("active_b", taglist.isActive());
445
                    itemObj.setField("hot_deal_b", taglist.isHotDeals());
446
                    mop = taglist.getMop();
33562 amit.gupta 447
                    dp = taglist.getSellingPrice();
31604 tejbeer 448
 
33542 amit.gupta 449
                }
450
                itemObjs.add(itemObj);
451
            }
31604 tejbeer 452
 
33562 amit.gupta 453
            float starPrice = dp - 500f;
454
            float endPrice = dp + 1000f;
455
            List<Integer> similalarModels = null;
33563 amit.gupta 456
            if ((Integer) catalogValMap.get("categoryId") == 3) {
33562 amit.gupta 457
                similalarModels = new ArrayList<>();
458
                for (Entry<Float, List<Integer>> floatListEntry : priceModelMap.entrySet()) {
459
                    float modelPrice = floatListEntry.getKey();
460
                    if (modelPrice >= starPrice && modelPrice <= endPrice) {
461
                        similalarModels.addAll(floatListEntry.getValue());
462
                    }
33563 amit.gupta 463
                    if (modelPrice > endPrice) break;
33562 amit.gupta 464
                }
465
                similalarModels.remove(catalogId);
466
            }
467
 
468
 
33542 amit.gupta 469
            logger.info("catalogValMap {}", catalogValMap);
31612 tejbeer 470
 
33542 amit.gupta 471
            logger.info("rank {}", catalogValMap.get("rank"));
31612 tejbeer 472
 
33542 amit.gupta 473
            SolrInputDocument catalogSolrObj = new SolrInputDocument();
31710 tejbeer 474
 
33542 amit.gupta 475
            catalogSolrObj.setField("id", "catalog" + catalogId);
476
            catalogSolrObj.setField("rank_i", catalogValMap.get("rank"));
33563 amit.gupta 477
            catalogSolrObj.setField("similarModels_ii", similalarModels == null ? Collections.EMPTY_LIST : similalarModels);
33542 amit.gupta 478
            catalogSolrObj.setField("title_s", catalogValMap.get("title"));
479
            // catalogSolrObj.setField("_childDocuments_", itemObjs);
480
            catalogSolrObj.addChildDocuments(itemObjs);
481
            catalogSolrObj.setField("child_b", itemObjs.size() > 0);
482
            catalogSolrObj.setField("catalogId_i", catalogId);
483
            catalogSolrObj.setField("imageUrl_s",
484
                    catalogValMap.get("imageUrl").toString().replace("saholic", "smartdukaan"));
485
            catalogSolrObj.setField("feature_s", catalogValMap.get("feature"));
486
            catalogSolrObj.setField("brand_ss", catalogValMap.get("brand"));
487
            catalogSolrObj.setField("create_s", catalogValMap.get("create_timestamp"));
488
            catalogSolrObj.setField("categoryId_i", catalogValMap.get("categoryId"));
489
            catalogSolrObj.setField("subCategoryId_i", catalogValMap.get("subCategoryId"));
490
            catalogSolrObj.setField("label_ss", catalogValMap.get("labels"));
33562 amit.gupta 491
            for (Integer warehouseId : ProfitMandiConstants.WAREHOUSE_MAP.keySet()) {
492
                catalogSolrObj.setField("w" + warehouseId + "_i", 0);
493
            }
33542 amit.gupta 494
            catalogSolrObj.setField("mop_f", mop);
495
            catalogSolrObj.setField("hsncode_s", catalogValMap.get("hsnCode"));
496
            catalogSolrObj.setField("show_default_b", true);
31710 tejbeer 497
 
33542 amit.gupta 498
            String[] brands = (String[]) catalogValMap.get("brand");
499
            for (String brand : brands) {
500
                if (brand.equals("FOC")) {
501
                    catalogSolrObj.setField("show_default_b", false);
31604 tejbeer 502
 
33542 amit.gupta 503
                }
31604 tejbeer 504
 
33542 amit.gupta 505
                if (brand.equals("Live Demo")) {
506
                    catalogSolrObj.setField("show_default_b", false);
31604 tejbeer 507
 
33542 amit.gupta 508
                }
509
            }
510
            Map<Integer, Integer> avColorMap = (Map<Integer, Integer>) catalogValMap.get("avColor");
33499 amit.gupta 511
 
33542 amit.gupta 512
            for (Entry<Integer, Integer> avColorEntry : avColorMap.entrySet()) {
513
                int whId = avColorEntry.getKey();
33562 amit.gupta 514
                int color = avColorEntry.getValue();
33542 amit.gupta 515
                catalogSolrObj.setField("w" + whId + "_i", color);
516
            }
517
            catalogSolrObj.setField("active_b", active);
518
            logger.info("catalogSolrObj {}", catalogSolrObj.get("rank_i"));
519
            catalogSolrObjs.add(catalogSolrObj);
33499 amit.gupta 520
 
33542 amit.gupta 521
        }
31604 tejbeer 522
 
33542 amit.gupta 523
        logger.info("catalogSolrObjs {}", catalogSolrObjs);
31604 tejbeer 524
 
33542 amit.gupta 525
        String solrPath = "http://" + solrUrl + ":8984/solr/demo";
526
        SolrClient solr = new HttpSolrClient.Builder(solrPath).build();
31604 tejbeer 527
 
33542 amit.gupta 528
        solr.deleteByQuery("*:*");
529
        solr.add(catalogSolrObjs);
530
 
531
        org.apache.solr.client.solrj.response.UpdateResponse updateResponse = solr.commit();
532
        logger.info("solr {}", updateResponse.getStatus());
533
 
534
    }
535
 
536
    public void pushData() throws Exception {
537
        this.populateTagItems();
538
    }
31604 tejbeer 539
}