Subversion Repositories SmartDukaan

Rev

Rev 33546 | Rev 33563 | 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
 
297
                if (!priceModelMap.containsKey(tagListing.getSellingPrice()) && item.getCategoryId()==10006) {
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<>();
33562 amit.gupta 304
                if (similarModelsMap.containsKey(item.getCatalogItemId())) {
33542 amit.gupta 305
                    catalogObj.put("similarModels", similarModelsMap.get(item.getCatalogItemId()));
33546 amit.gupta 306
                } else {
307
                    catalogObj.put("similarModels", Collections.EMPTY_LIST);
33542 amit.gupta 308
                }
33546 amit.gupta 309
 
33542 amit.gupta 310
                catalogObj.put("feature", "");
311
                catalogObj.put("hsnCode", item.getHsnCode());
312
                catalogObj.put("title",
313
                        String.join(" ", Arrays.asList(item.getBrand(), item.getModelName(), item.getModelNumber())
314
                                .stream().filter(s -> s != null && !s.isEmpty()).collect(Collectors.toList())));
315
                catalogObj.put("brand", new String[]{item.getBrand()});
316
                if (item.getBrand().equals("Huawei") || item.getBrand().equals("Honor")) {
317
                    catalogObj.put("brand", new String[]{"Huawei", "Honor"});
318
                }
319
                if (item.getBrand().equals("Mi") || item.getBrand().equals("Xiaomi")
320
                        || item.getBrand().equals("Redmi")) {
321
                    catalogObj.put("brand", new String[]{"Mi", "Xiaomi", "Redmi"});
322
                }
323
                catalogObj.put("identifier", item.getCatalogItemId());
324
                catalogObj.put("items", new HashMap<Integer, Map<String, Object>>());
325
                Map<String, Object> filterMap = new HashMap<>();
326
                filterMap.put("_id", item.getCatalogItemId());
327
                // Don't include if catalog not available
328
                try {
329
                    String imageUrl = contentMongoClient.getEntityById(item.getCatalogItemId()).getDefaultImageUrl();
31624 tejbeer 330
 
33542 amit.gupta 331
                    if (imageUrl != null) {
332
                        catalogObj.put("imageUrl", imageUrl);
333
                    } else {
334
                        catalogObj.put("imageUrl",
335
                                "https://images.smartdukaan.com/uploads/campaigns/" + item.getCatalogItemId() + ".jpg");
336
                    }
337
                } catch (Exception e) {
338
                    try {
339
                        catalogObj.put("imageUrl",
340
                                "https://images.smartdukaan.com/uploads/campaigns/" + item.getCatalogItemId() + ".jpg");
341
                    } catch (Exception e2) {
342
                        e2.printStackTrace();
343
                    }
344
                }
345
                try {
346
                    catalogObj.put("rank", rankingList.indexOf(item.getCatalogItemId()));
347
                } catch (Exception e) {
348
                    // A very big number
349
                    e.printStackTrace();
350
                    catalogObj.put("rank", 50000000);
351
                }
352
                if (featureMap.containsKey(item.getCatalogItemId())
353
                        && featureMap.get(item.getCatalogItemId()) != null) {
354
                    catalogObj.put("feature", featureMap.get(item.getCatalogItemId()));
31612 tejbeer 355
 
33542 amit.gupta 356
                }
31612 tejbeer 357
 
33542 amit.gupta 358
                catalogObj.put("categoryId", CATEGORY_MASTER.contains(item.getCategoryId()) ? item.getCategoryId() : 6);
31612 tejbeer 359
 
33542 amit.gupta 360
                if (item.getCategoryId() == 10006) {
361
                    catalogObj.put("categoryId", 3);
362
                }
363
                catalogObj.put("subCategoryId", item.getCategoryId());
364
                catalogObj.put("create_timestamp",
33562 amit.gupta 365
                        tagListing.getCreatedTimestamp().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
31604 tejbeer 366
 
33542 amit.gupta 367
                if (catalogLabelMap.containsKey(item.getCatalogItemId())
368
                        && catalogLabelMap.get(item.getCatalogItemId()) != null) {
369
                    catalogObj.put("labels", catalogLabelMap.get(item.getCatalogItemId()));
31604 tejbeer 370
 
33542 amit.gupta 371
                }
372
                catalogMap.put(item.getCatalogItemId(), catalogObj);
373
                catalogObj.put("avColor", new HashMap<>());
31604 tejbeer 374
 
33542 amit.gupta 375
            }
31604 tejbeer 376
 
33542 amit.gupta 377
            Map<String, Object> catalogObj = catalogMap.get(item.getCatalogItemId());
378
            Map<Integer, Integer> avColorMap = (Map<Integer, Integer>) catalogObj.get("avColor");
31604 tejbeer 379
 
33542 amit.gupta 380
            if (availabilityItemMap.containsKey(String.valueOf(item.getId()))) {
381
                for (Map.Entry<String, Map<String, Integer>> entry : availabilityItemMap
382
                        .get(String.valueOf(item.getId())).entrySet()) {
383
                    String warehouseId = entry.getKey();
384
                    Map<String, Integer> avMap = entry.getValue();
385
                    if (!avColorMap.containsKey(Integer.parseInt(warehouseId))) {
386
                        avColorMap.put(Integer.parseInt(warehouseId), 0);
387
                    }
388
                    int color = avColorMap.get(Integer.parseInt(warehouseId));
31604 tejbeer 389
 
33542 amit.gupta 390
                    if (avMap.get("netAvailability") > 0) {
391
                        color = 2;
33562 amit.gupta 392
                    } else if (avMap.get("netPo") > 0) {
33542 amit.gupta 393
                        color = Math.max(color, 1);
394
                    } else {
395
                        color = Math.max(color, 0);
396
                    }
397
                    avColorMap.put(Integer.parseInt(warehouseId), color);
31604 tejbeer 398
 
33542 amit.gupta 399
                    catalogObj.put("avColor", avColorMap);
31604 tejbeer 400
 
33542 amit.gupta 401
                }
31604 tejbeer 402
 
33542 amit.gupta 403
            }
31604 tejbeer 404
 
33542 amit.gupta 405
            Map<Integer, Object> itemColorMap = (Map<Integer, Object>) catalogObj.get("items");
31604 tejbeer 406
 
33542 amit.gupta 407
            if (!itemColorMap.containsKey(item.getId())) {
408
                itemColorMap.put(item.getId(), new HashMap<String, Object>() {
409
                    {
410
                        put("color", item.getColor().replace("f_", ""));
411
                        put("tagPricing", new ArrayList<TagListing>());
412
                    }
413
                });
414
            }
415
            Map<String, Object> itemMap = (Map<String, Object>) itemColorMap.get(item.getId());
416
            List<TagListing> tagPricing = (List<TagListing>) itemMap.get("tagPricing");
33562 amit.gupta 417
            tagPricing.add(tagListing);
33542 amit.gupta 418
        }
33562 amit.gupta 419
        //logger.info("catalogObj {}", catalogMap);
31604 tejbeer 420
 
33542 amit.gupta 421
        List<SolrInputDocument> catalogSolrObjs = new ArrayList<>();
422
        for (Entry<Integer, Map<String, Object>> entry : catalogMap.entrySet()) {
423
            int catalogId = entry.getKey();
424
            Map<String, Object> catalogValMap = entry.getValue();
425
            Map<Integer, Object> itemsMap = (Map<Integer, Object>) catalogValMap.get("items");
31604 tejbeer 426
 
33542 amit.gupta 427
            boolean active = false;
428
            // Map<Integer, Object> itemsMap = (Map<String, Object>)
429
            // catalogValMap.get("items");
430
            List<SolrInputDocument> itemObjs = new ArrayList<>();
431
            float mop = 0;
33562 amit.gupta 432
            float dp = 0;
31604 tejbeer 433
 
33542 amit.gupta 434
            for (Entry<Integer, Object> itemEntry : itemsMap.entrySet()) {
435
                int itemId = itemEntry.getKey();
436
                Map<String, Object> itemMap = (Map<String, Object>) itemEntry.getValue();
437
                List<TagListing> tags = (List<TagListing>) itemMap.get("tagPricing");
438
                SolrInputDocument itemObj = new SolrInputDocument();
31604 tejbeer 439
 
33542 amit.gupta 440
                for (TagListing taglist : tags) {
33562 amit.gupta 441
                    active = active || taglist.isActive();
33542 amit.gupta 442
                    itemObj.setField("id", "itemtag-" + itemId + "-" + taglist.getTagId());
443
                    itemObj.setField("color_s", itemMap.get("color"));
444
                    itemObj.setField("itemId_i", itemId);
445
                    itemObj.setField("tagId_i", taglist.getTagId());
446
                    itemObj.setField("mrp_f", taglist.getMrp());
447
                    itemObj.setField("mop_f", taglist.getMop());
448
                    itemObj.setField("sellingPrice_f", taglist.getSellingPrice());
449
                    itemObj.setField("active_b", taglist.isActive());
450
                    itemObj.setField("hot_deal_b", taglist.isHotDeals());
451
                    mop = taglist.getMop();
33562 amit.gupta 452
                    dp = taglist.getSellingPrice();
31604 tejbeer 453
 
33542 amit.gupta 454
                }
455
                itemObjs.add(itemObj);
456
            }
31604 tejbeer 457
 
33562 amit.gupta 458
            float starPrice = dp - 500f;
459
            float endPrice = dp + 1000f;
460
            List<Integer> similalarModels = null;
461
            if((Integer)catalogValMap.get("categoryId")==3) {
462
                similalarModels = new ArrayList<>();
463
                for (Entry<Float, List<Integer>> floatListEntry : priceModelMap.entrySet()) {
464
                    float modelPrice = floatListEntry.getKey();
465
                    if (modelPrice >= starPrice && modelPrice <= endPrice) {
466
                        similalarModels.addAll(floatListEntry.getValue());
467
                    }
468
                    if(modelPrice > endPrice) break;
469
                }
470
                similalarModels.remove(catalogId);
471
            }
472
 
473
 
33542 amit.gupta 474
            logger.info("catalogValMap {}", catalogValMap);
31612 tejbeer 475
 
33542 amit.gupta 476
            logger.info("rank {}", catalogValMap.get("rank"));
31612 tejbeer 477
 
33542 amit.gupta 478
            SolrInputDocument catalogSolrObj = new SolrInputDocument();
31710 tejbeer 479
 
33542 amit.gupta 480
            catalogSolrObj.setField("id", "catalog" + catalogId);
481
            catalogSolrObj.setField("rank_i", catalogValMap.get("rank"));
33562 amit.gupta 482
            catalogSolrObj.setField("similarModels_ii", similalarModels);
33542 amit.gupta 483
            catalogSolrObj.setField("title_s", catalogValMap.get("title"));
484
            // catalogSolrObj.setField("_childDocuments_", itemObjs);
485
            catalogSolrObj.addChildDocuments(itemObjs);
486
            catalogSolrObj.setField("child_b", itemObjs.size() > 0);
487
            catalogSolrObj.setField("catalogId_i", catalogId);
488
            catalogSolrObj.setField("imageUrl_s",
489
                    catalogValMap.get("imageUrl").toString().replace("saholic", "smartdukaan"));
490
            catalogSolrObj.setField("feature_s", catalogValMap.get("feature"));
491
            catalogSolrObj.setField("brand_ss", catalogValMap.get("brand"));
492
            catalogSolrObj.setField("create_s", catalogValMap.get("create_timestamp"));
493
            catalogSolrObj.setField("categoryId_i", catalogValMap.get("categoryId"));
494
            catalogSolrObj.setField("subCategoryId_i", catalogValMap.get("subCategoryId"));
495
            catalogSolrObj.setField("label_ss", catalogValMap.get("labels"));
33562 amit.gupta 496
            for (Integer warehouseId : ProfitMandiConstants.WAREHOUSE_MAP.keySet()) {
497
                catalogSolrObj.setField("w" + warehouseId + "_i", 0);
498
            }
33542 amit.gupta 499
            catalogSolrObj.setField("mop_f", mop);
500
            catalogSolrObj.setField("hsncode_s", catalogValMap.get("hsnCode"));
501
            catalogSolrObj.setField("show_default_b", true);
31710 tejbeer 502
 
33542 amit.gupta 503
            String[] brands = (String[]) catalogValMap.get("brand");
504
            for (String brand : brands) {
505
                if (brand.equals("FOC")) {
506
                    catalogSolrObj.setField("show_default_b", false);
31604 tejbeer 507
 
33542 amit.gupta 508
                }
31604 tejbeer 509
 
33542 amit.gupta 510
                if (brand.equals("Live Demo")) {
511
                    catalogSolrObj.setField("show_default_b", false);
31604 tejbeer 512
 
33542 amit.gupta 513
                }
514
            }
515
            Map<Integer, Integer> avColorMap = (Map<Integer, Integer>) catalogValMap.get("avColor");
33499 amit.gupta 516
 
33542 amit.gupta 517
            for (Entry<Integer, Integer> avColorEntry : avColorMap.entrySet()) {
518
                int whId = avColorEntry.getKey();
33562 amit.gupta 519
                int color = avColorEntry.getValue();
33542 amit.gupta 520
                catalogSolrObj.setField("w" + whId + "_i", color);
521
            }
522
            catalogSolrObj.setField("active_b", active);
523
            logger.info("catalogSolrObj {}", catalogSolrObj.get("rank_i"));
524
            catalogSolrObjs.add(catalogSolrObj);
33499 amit.gupta 525
 
33542 amit.gupta 526
        }
31604 tejbeer 527
 
33542 amit.gupta 528
        logger.info("catalogSolrObjs {}", catalogSolrObjs);
31604 tejbeer 529
 
33542 amit.gupta 530
        String solrPath = "http://" + solrUrl + ":8984/solr/demo";
531
        SolrClient solr = new HttpSolrClient.Builder(solrPath).build();
31604 tejbeer 532
 
33542 amit.gupta 533
        solr.deleteByQuery("*:*");
534
        solr.add(catalogSolrObjs);
535
 
536
        org.apache.solr.client.solrj.response.UpdateResponse updateResponse = solr.commit();
537
        logger.info("solr {}", updateResponse.getStatus());
538
 
539
    }
540
 
541
    public void pushData() throws Exception {
542
        this.populateTagItems();
543
    }
31604 tejbeer 544
}