Subversion Repositories SmartDukaan

Rev

Rev 32037 | Rev 32344 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 32037 Rev 32339
Line 85... Line 85...
85
 
85
 
86
@Controller
86
@Controller
87
@Transactional(rollbackFor = Throwable.class)
87
@Transactional(rollbackFor = Throwable.class)
88
public class DealsController {
88
public class DealsController {
89
 
89
 
90
	private static final Logger logger = LogManager.getLogger(DealsController.class);
90
    private static final Logger logger = LogManager.getLogger(DealsController.class);
91
	private static final List<Integer> TAG_IDS = Arrays.asList(4);
91
    private static final List<Integer> TAG_IDS = Arrays.asList(4);
92
 
92
 
93
	@Value("${python.api.host}")
93
    @Value("${python.api.host}")
94
	private String host;
94
    private String host;
95
 
95
 
96
	@Value("${new.solr.url}")
96
    @Value("${new.solr.url}")
97
	private String solrUrl;
97
    private String solrUrl;
98
 
98
 
99
	@Value("${python.api.port}")
99
    @Value("${python.api.port}")
100
	private int port;
100
    private int port;
101
 
101
 
102
	@Autowired
102
    @Autowired
103
	RestClient restClient;
103
    RestClient restClient;
104
 
104
 
105
	@Autowired
105
    @Autowired
106
	SolrService solrService;
106
    SolrService solrService;
107
 
107
 
108
	@Autowired
108
    @Autowired
109
	InventoryService inventoryService;
109
    InventoryService inventoryService;
110
 
110
 
111
	// This is now unused as we are not supporting multiple companies.
111
    // This is now unused as we are not supporting multiple companies.
112
	@Value("${gadgetCops.invoice.cc}")
112
    @Value("${gadgetCops.invoice.cc}")
113
	private String[] ccGadgetCopInvoiceTo;
113
    private String[] ccGadgetCopInvoiceTo;
114
 
114
 
115
	@Autowired
115
    @Autowired
116
	private PricingService pricingService;
116
    private PricingService pricingService;
117
 
117
 
118
	@Autowired
118
    @Autowired
119
	private CategoryRepository categoryRepository;
119
    private CategoryRepository categoryRepository;
120
 
120
 
121
	@Autowired
121
    @Autowired
122
	private SchemeService schemeService;
122
    private SchemeService schemeService;
123
 
123
 
124
	@Autowired
124
    @Autowired
125
	private SaholicInventoryService saholicInventoryService;
125
    private SaholicInventoryService saholicInventoryService;
126
 
126
 
127
	@Autowired
127
    @Autowired
128
	private Mongo mongoClient;
128
    private Mongo mongoClient;
129
 
129
 
130
	@Autowired
130
    @Autowired
131
	private ItemBucketService itemBucketService;
131
    private ItemBucketService itemBucketService;
132
 
132
 
133
	@Autowired
133
    @Autowired
134
	private UserAccountRepository userAccountRepository;
134
    private UserAccountRepository userAccountRepository;
135
 
135
 
136
	@Autowired
136
    @Autowired
137
	private FofoStoreRepository fofoStoreRepository;
137
    private FofoStoreRepository fofoStoreRepository;
138
 
138
 
139
	@Autowired
139
    @Autowired
140
	private ResponseSender<?> responseSender;
140
    private ResponseSender<?> responseSender;
141
 
141
 
142
	@Autowired
142
    @Autowired
143
	private TagListingRepository tagListingRepository;
143
    private TagListingRepository tagListingRepository;
144
 
144
 
145
	@Autowired
145
    @Autowired
146
	private ItemRepository itemRepository;
146
    private ItemRepository itemRepository;
147
	@Autowired
147
    @Autowired
148
	private PriceCircularService priceCircularService;
148
    private PriceCircularService priceCircularService;
149
 
149
 
150
	@Autowired
150
    @Autowired
151
	private RoleManager roleManagerService;
151
    private RoleManager roleManagerService;
152
 
152
 
153
	@Autowired
153
    @Autowired
154
	private SuggestedPoDetailRepository monthlyPoDetailRepository;
154
    private SuggestedPoDetailRepository monthlyPoDetailRepository;
155
 
155
 
156
	@Autowired
156
    @Autowired
157
	private SuggestedPoRepository suggestedPoRepository;
157
    private SuggestedPoRepository suggestedPoRepository;
158
 
158
 
159
	@Autowired
159
    @Autowired
160
	private WebOfferRepository webOfferRepository;
160
    private WebOfferRepository webOfferRepository;
161
 
161
 
162
	@Autowired
162
    @Autowired
163
	private ComboModelRepository comboModelRepository;
163
    private ComboModelRepository comboModelRepository;
164
 
164
 
165
	@Autowired
165
    @Autowired
166
	private ComboMappedModelRepository comboMappedModelRepository;
166
    private ComboMappedModelRepository comboMappedModelRepository;
167
 
167
 
168
	@Autowired
168
    @Autowired
169
	private BrandsService brandsService;
169
    private BrandsService brandsService;
170
 
170
 
171
	@Autowired
171
    @Autowired
172
	private WebListingRepository webListingRepository;
172
    private WebListingRepository webListingRepository;
173
 
173
 
174
	@Autowired
174
    @Autowired
175
	private WebProductListingRepository webProductListingRepository;
175
    private WebProductListingRepository webProductListingRepository;
176
 
176
 
177
	@Autowired
177
    @Autowired
178
	private CatalogFavouriteRepository catalogFavouriteRepository;
178
    private CatalogFavouriteRepository catalogFavouriteRepository;
179
 
179
 
180
	List<String> filterableParams = Arrays.asList("brand");
180
    List<String> filterableParams = Arrays.asList("brand");
181
 
181
 
182
	@RequestMapping(value = "/fofo/buckets", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
182
    @RequestMapping(value = "/fofo/buckets", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
183
	public ResponseEntity<?> getBuckets(HttpServletRequest request) throws ProfitMandiBusinessException {
183
    public ResponseEntity<?> getBuckets(HttpServletRequest request) throws ProfitMandiBusinessException {
184
		logger.info("Request " + request.getParameterMap());
184
        logger.info("Request " + request.getParameterMap());
185
		return responseSender.ok(itemBucketService.getBuckets(Optional.of(true)));
185
        return responseSender.ok(itemBucketService.getBuckets(Optional.of(true)));
186
	}
186
    }
187
 
187
 
188
	@RequestMapping(value = "/fofo/bucket", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
188
    @RequestMapping(value = "/fofo/bucket", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
189
	public ResponseEntity<?> getBucketDetails(HttpServletRequest request, @RequestParam int id)
189
    public ResponseEntity<?> getBucketDetails(HttpServletRequest request, @RequestParam int id) throws ProfitMandiBusinessException {
190
			throws ProfitMandiBusinessException {
190
        List<ItemQuantityPojo> iqPojo = itemBucketService.getBucketDetails(id);
191
		List<ItemQuantityPojo> iqPojo = itemBucketService.getBucketDetails(id);
191
        Map<Integer, Integer> itemIdsQtyMap = iqPojo.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
192
		Map<Integer, Integer> itemIdsQtyMap = iqPojo.stream()
192
        Set<Integer> catalogIds = itemRepository.selectByIds(itemIdsQtyMap.keySet()).stream().map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
193
				.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
193
        RestClient rc = new RestClient();
194
		Set<Integer> catalogIds = itemRepository.selectByIds(itemIdsQtyMap.keySet()).stream()
194
        Map<String, String> params = new HashMap<>();
195
				.map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
195
        List<String> mandatoryQ = new ArrayList<>();
196
		RestClient rc = new RestClient();
196
        mandatoryQ.add(
197
		Map<String, String> params = new HashMap<>();
197
                String.format("+catalogId_i:(%s) +{!parent which=\"id:catalog*\"}", StringUtils.join(catalogIds, " ")));
198
		List<String> mandatoryQ = new ArrayList<>();
198
        params.put("start", "0");
199
		mandatoryQ.add(
199
        params.put("rows", "100");
200
				String.format("+catalogId_i:(%s) +{!parent which=\"id:catalog*\"}", StringUtils.join(catalogIds, " ")));
200
        params.put("q", StringUtils.join(mandatoryQ, " "));
201
		params.put("start", "0");
201
        params.put("fl", "*, [child parentFilter=id:catalog*]");
202
		params.put("rows", "100");
202
 
203
		params.put("q", StringUtils.join(mandatoryQ, " "));
203
        params.put("wt", "json");
204
		params.put("fl", "*, [child parentFilter=id:catalog*]");
204
        String response = null;
205
 
205
        try {
206
		params.put("wt", "json");
206
            response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
207
		String response = null;
207
        } catch (HttpHostConnectException e) {
208
		try {
208
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
209
			response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
209
        }
210
		} catch (HttpHostConnectException e) {
210
        JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
211
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
211
        JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
212
		}
212
        List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, itemIdsQtyMap, false);
213
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
213
 
214
		JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
214
        Bucket bucket = itemBucketService.getBuckets(Optional.of(true)).stream().filter(x -> x.getId() == id).collect(Collectors.toList()).get(0);
215
		List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, itemIdsQtyMap, false);
215
        bucket.setFofoCatalogResponses(dealResponse);
216
 
216
        return responseSender.ok(bucket);
217
		Bucket bucket = itemBucketService.getBuckets(Optional.of(true)).stream().filter(x -> x.getId() == id)
217
    }
218
				.collect(Collectors.toList()).get(0);
218
 
219
		bucket.setFofoCatalogResponses(dealResponse);
219
    @RequestMapping(value = "/fofo/suggestedPo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
220
		return responseSender.ok(bucket);
220
    public ResponseEntity<?> getSuggestedPo(HttpServletRequest request, @RequestParam int id) throws ProfitMandiBusinessException {
221
	}
221
 
222
 
222
        List<SuggestedPoDetail> mpd = monthlyPoDetailRepository.selectByPoId(id);
223
	@RequestMapping(value = "/fofo/suggestedPo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
223
        Map<Integer, Integer> itemIdsQtyMap = mpd.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
224
	public ResponseEntity<?> getSuggestedPo(HttpServletRequest request, @RequestParam int id)
224
 
225
			throws ProfitMandiBusinessException {
225
        Set<Integer> catalogIds = itemRepository.selectByIds(itemIdsQtyMap.keySet()).stream().map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
226
 
226
        RestClient rc = new RestClient();
227
		List<SuggestedPoDetail> mpd = monthlyPoDetailRepository.selectByPoId(id);
227
        Map<String, String> params = new HashMap<>();
228
		Map<Integer, Integer> itemIdsQtyMap = mpd.stream()
228
        List<String> mandatoryQ = new ArrayList<>();
229
				.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
229
        mandatoryQ.add(
230
 
230
                String.format("+catalogId_i:(%s) +{!parent which=\"id:catalog*\"}", StringUtils.join(catalogIds, " ")));
231
		Set<Integer> catalogIds = itemRepository.selectByIds(itemIdsQtyMap.keySet()).stream()
231
        params.put("start", "0");
232
				.map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
232
        params.put("rows", "100");
233
		RestClient rc = new RestClient();
233
        params.put("q", StringUtils.join(mandatoryQ, " "));
234
		Map<String, String> params = new HashMap<>();
234
        params.put("fl", "*, [child parentFilter=id:catalog*]");
235
		List<String> mandatoryQ = new ArrayList<>();
235
 
236
		mandatoryQ.add(
236
        params.put("wt", "json");
237
				String.format("+catalogId_i:(%s) +{!parent which=\"id:catalog*\"}", StringUtils.join(catalogIds, " ")));
237
        String response = null;
238
		params.put("start", "0");
238
        try {
239
		params.put("rows", "100");
239
            response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
240
		params.put("q", StringUtils.join(mandatoryQ, " "));
240
        } catch (HttpHostConnectException e) {
241
		params.put("fl", "*, [child parentFilter=id:catalog*]");
241
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
242
 
242
        }
243
		params.put("wt", "json");
243
        JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
244
		String response = null;
244
        JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
245
		try {
245
        List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, itemIdsQtyMap, false);
246
			response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
246
 
247
		} catch (HttpHostConnectException e) {
247
        return responseSender.ok(dealResponse);
248
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
248
    }
249
		}
249
 
250
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
250
    @RequestMapping(value = "/suggestedPo/status", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
251
		JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
251
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
252
		List<FofoCatalogResponse> dealResponse = getCatalogSingleSkuResponse(docs, itemIdsQtyMap, false);
252
    @ApiOperation(value = "")
253
 
253
    public ResponseEntity<?> changeSuggestedPoStatus(HttpServletRequest request, @RequestParam int id) throws ProfitMandiBusinessException {
254
		return responseSender.ok(dealResponse);
254
        SuggestedPo suggestedPo = suggestedPoRepository.selectById(id);
255
	}
255
        suggestedPo.setStatus("closed");
256
 
256
 
257
	@RequestMapping(value = "/suggestedPo/status", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
257
        return responseSender.ok(true);
258
	@ApiImplicitParams({
258
    }
259
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
259
 
260
	@ApiOperation(value = "")
260
    @RequestMapping(value = "/fofo/fovourites", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
261
	public ResponseEntity<?> changeSuggestedPoStatus(HttpServletRequest request, @RequestParam int id)
261
    public ResponseEntity<?> getFavourites(HttpServletRequest request) throws Exception {
262
			throws ProfitMandiBusinessException {
262
 
263
		SuggestedPo suggestedPo = suggestedPoRepository.selectById(id);
263
        int userId = (int) request.getAttribute("userId");
264
		suggestedPo.setStatus("closed");
264
        UserCart uc = userAccountRepository.getUserCart(userId);
265
 
265
        int fofoId = uc.getUserId();
266
		return responseSender.ok(true);
266
        List<FofoCatalogResponse> dealResponse = new ArrayList<>();
267
	}
267
        Set<Integer> catalogIds = catalogFavouriteRepository.selectBypartnerId(fofoId).stream().map(x -> x.getCatalogId()).collect(Collectors.toSet());
268
 
268
        if (!catalogIds.isEmpty()) {
269
	@RequestMapping(value = "/fofo/fovourites", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
269
 
270
	public ResponseEntity<?> getFavourites(HttpServletRequest request) throws Exception {
270
            RestClient rc = new RestClient();
271
 
271
            Map<String, String> params = new HashMap<>();
272
		int userId = (int) request.getAttribute("userId");
272
            List<String> mandatoryQ = new ArrayList<>();
273
		UserCart uc = userAccountRepository.getUserCart(userId);
273
            mandatoryQ.add(String.format("+catalogId_i:(%s) +{!parent which=\"id:catalog*\"}", StringUtils.join(catalogIds, " ")));
274
		int fofoId = uc.getUserId();
274
            params.put("start", "0");
275
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
275
            params.put("rows", "100");
276
		Set<Integer> catalogIds = catalogFavouriteRepository.selectBypartnerId(fofoId).stream()
276
            params.put("q", StringUtils.join(mandatoryQ, " "));
277
				.map(x -> x.getCatalogId()).collect(Collectors.toSet());
277
            params.put("fl", "*, [child parentFilter=id:catalog*]");
278
		if (!catalogIds.isEmpty()) {
278
 
279
 
279
            params.put("wt", "json");
280
			RestClient rc = new RestClient();
280
            String response = null;
281
			Map<String, String> params = new HashMap<>();
281
            try {
282
			List<String> mandatoryQ = new ArrayList<>();
282
                response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
283
			mandatoryQ.add(String.format("+catalogId_i:(%s) +{!parent which=\"id:catalog*\"}",
283
            } catch (HttpHostConnectException e) {
284
					StringUtils.join(catalogIds, " ")));
284
                throw new ProfitMandiBusinessException("", "", "Could not connect to host");
285
			params.put("start", "0");
285
            }
286
			params.put("rows", "100");
286
            JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
287
			params.put("q", StringUtils.join(mandatoryQ, " "));
287
            JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
288
			params.put("fl", "*, [child parentFilter=id:catalog*]");
288
            dealResponse = getCatalogResponse(docs, false, fofoId);
289
 
289
        }
290
			params.put("wt", "json");
290
        return responseSender.ok(dealResponse);
291
			String response = null;
291
    }
292
			try {
292
 
293
				response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
293
    @RequestMapping(value = "/favourites/manage", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
294
			} catch (HttpHostConnectException e) {
294
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
295
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
295
    @ApiOperation(value = "")
296
			}
296
    public ResponseEntity<?> mangeFavourites(HttpServletRequest request, @RequestParam int catalogId) throws ProfitMandiBusinessException {
297
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
297
 
298
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
298
        int userId = (int) request.getAttribute("userId");
299
			dealResponse = getCatalogResponse(docs, false, fofoId);
299
        UserCart uc = userAccountRepository.getUserCart(userId);
300
		}
300
        int fofoId = uc.getUserId();
301
		return responseSender.ok(dealResponse);
301
 
302
	}
302
        CatalogFavourite catalogFavourite = catalogFavouriteRepository.selectBypartnerAndCatalogId(fofoId, catalogId);
303
 
303
 
304
	@RequestMapping(value = "/favourites/manage", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
304
        if (catalogFavourite == null) {
305
	@ApiImplicitParams({
305
            catalogFavourite = new CatalogFavourite();
306
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
306
            catalogFavourite.setCatalogId(catalogId);
307
	@ApiOperation(value = "")
307
            catalogFavourite.setFofoId(fofoId);
308
	public ResponseEntity<?> mangeFavourites(HttpServletRequest request, @RequestParam int catalogId)
308
            catalogFavourite.setCreatedTimestamp(LocalDateTime.now());
309
			throws ProfitMandiBusinessException {
309
            catalogFavouriteRepository.persist(catalogFavourite);
310
 
310
 
311
		int userId = (int) request.getAttribute("userId");
311
        }
312
		UserCart uc = userAccountRepository.getUserCart(userId);
312
 
313
		int fofoId = uc.getUserId();
313
        else {
314
 
314
            catalogFavouriteRepository.deleteByPartnerAndCatalogId(fofoId, catalogId);
315
		CatalogFavourite catalogFavourite = catalogFavouriteRepository.selectBypartnerAndCatalogId(fofoId, catalogId);
315
        }
316
 
316
        return responseSender.ok(true);
317
		if (catalogFavourite == null) {
317
    }
318
			catalogFavourite = new CatalogFavourite();
318
 
319
			catalogFavourite.setCatalogId(catalogId);
319
    private String getCommaSeparateTags(int userId) {
320
			catalogFavourite.setFofoId(fofoId);
320
        UserCart uc = userAccountRepository.getUserCart(userId);
321
			catalogFavourite.setCreatedTimestamp(LocalDateTime.now());
321
        List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
322
			catalogFavouriteRepository.persist(catalogFavourite);
322
        List<String> strTagIds = new ArrayList<>();
323
 
323
        for (Integer tagId : tagIds) {
324
		}
324
            strTagIds.add(String.valueOf(tagId));
325
 
325
        }
326
		else {
326
        return String.join(",", strTagIds);
327
			catalogFavouriteRepository.deleteByPartnerAndCatalogId(fofoId, catalogId);
327
    }
328
		}
328
 
329
		return responseSender.ok(true);
329
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
330
	}
330
    @RequestMapping(value = "/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
331
 
331
    public ResponseEntity<?> getFofo(HttpServletRequest request, @RequestParam(value = "categoryId", required = false, defaultValue = "3") String categoryId, @RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String 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) throws Throwable {
332
	private String getCommaSeparateTags(int userId) {
332
        List<FofoCatalogResponse> dealResponse = new ArrayList<>();
333
		UserCart uc = userAccountRepository.getUserCart(userId);
333
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
334
		List<Integer> tagIds = pricingService.getTagsIdsByRetailerId(uc.getUserId());
334
        FofoStore fs = fofoStoreRepository.selectByRetailerId(userInfo.getRetailerId());
335
		List<String> strTagIds = new ArrayList<>();
335
        sort = "w" + fs.getWarehouseId() + "_i desc";
336
		for (Integer tagId : tagIds) {
336
 
337
			strTagIds.add(String.valueOf(tagId));
337
        logger.info("endPoint {}", endPoint);
338
		}
338
 
339
		return String.join(",", strTagIds);
339
        if (endPoint != null && !endPoint.trim().isEmpty()) {
340
	}
340
            WebListing webListing = webListingRepository.selectByUrl(endPoint);
341
 
341
            dealResponse = this.getDealResponses(userInfo, webListing, offset, limit);
342
	@ApiImplicitParams({
342
 
343
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
343
        } else {
344
	@RequestMapping(value = "/fofo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
344
 
345
	public ResponseEntity<?> getFofo(HttpServletRequest request,
345
            dealResponse = this.getCatalogResponse(
346
			@RequestParam(value = "categoryId", required = false, defaultValue = "3") String categoryId,
346
                    solrService.getSolrDocs(queryTerm, categoryId, offset, limit, sort, brand, subCategoryId, hotDeal), hotDeal, userInfo.getRetailerId());
347
			@RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit,
347
        }
348
			@RequestParam(value = "sort", required = false) String sort,
348
        logger.info("log me");
349
			@RequestParam(value = "brand", required = false) String brand,
349
        return responseSender.ok(dealResponse);
350
			@RequestParam(value = "subCategoryId", required = false) int subCategoryId,
350
    }
351
			@RequestParam(value = "q", required = false) String queryTerm,
351
 
352
			@RequestParam(value = "hotDeal", required = false) boolean hotDeal,
352
    @RequestMapping(value = "/online-deals", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
353
			@RequestParam(value = "endPoint", required = false) String endPoint) throws Throwable {
353
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
354
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
354
    @ApiOperation(value = "Get online deals")
355
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
355
    public ResponseEntity<?> getOnlineDeals(HttpServletRequest request, @RequestParam(value = "categoryId") String categoryId, @RequestParam(value = "offset") String offset, @RequestParam(value = "limit") String limit, @RequestParam(value = "sort", required = false) String sort, @RequestParam(value = "direction", required = false) String direction, @RequestParam(value = "filterData", required = false) String filterData) throws Throwable {
356
		FofoStore fs = fofoStoreRepository.selectByRetailerId(userInfo.getRetailerId());
356
        logger.info("Request " + request.getParameterMap());
357
		sort = "w" + fs.getWarehouseId() + "_i desc";
357
        String response = null;
358
 
358
        int userId = (int) request.getAttribute("userId");
359
		logger.info("endPoint {}", endPoint);
359
 
360
 
360
        String uri = "/deals/" + userId;
361
		if (endPoint != null && !endPoint.trim().isEmpty()) {
361
        RestClient rc = new RestClient();
362
			WebListing webListing = webListingRepository.selectByUrl(endPoint);
362
        Map<String, String> params = new HashMap<>();
363
			dealResponse = this.getDealResponses(userInfo, webListing, offset, limit);
363
        params.put("offset", offset);
364
 
364
        params.put("limit", limit);
365
		} else {
365
        params.put("categoryId", categoryId);
366
 
366
        params.put("direction", direction);
367
			dealResponse = this.getCatalogResponse(
367
        params.put("sort", sort);
368
					solrService.getSolrDocs(queryTerm, categoryId, offset, limit, sort, brand, subCategoryId, hotDeal),
368
        params.put("source", "online");
369
					hotDeal, userInfo.getRetailerId());
369
        params.put("filterData", filterData);
370
		}
370
        /*
371
		logger.info("log me");
371
         * if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
372
		return responseSender.ok(dealResponse);
372
         * params.put("tag_ids", getCommaSeparateTags(userId)); }
373
	}
373
         */
374
 
374
        List<Object> responseObject = new ArrayList<>();
375
	@RequestMapping(value = "/online-deals", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
375
        try {
376
	@ApiImplicitParams({
376
            response = rc.get(SchemeType.HTTP, host, port, uri, params);
377
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
377
        } catch (HttpHostConnectException e) {
378
	@ApiOperation(value = "Get online deals")
378
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
379
	public ResponseEntity<?> getOnlineDeals(HttpServletRequest request,
379
        }
380
			@RequestParam(value = "categoryId") String categoryId, @RequestParam(value = "offset") String offset,
380
 
381
			@RequestParam(value = "limit") String limit, @RequestParam(value = "sort", required = false) String sort,
381
        JsonArray result_json = Json.parse(response).asArray();
382
			@RequestParam(value = "direction", required = false) String direction,
382
        for (JsonValue j : result_json) {
383
			@RequestParam(value = "filterData", required = false) String filterData) throws Throwable {
383
            // logger.info("res " + j.asArray());
384
		logger.info("Request " + request.getParameterMap());
384
            List<Object> innerObject = new ArrayList<>();
385
		String response = null;
385
            for (JsonValue jsonObject : j.asArray()) {
386
		int userId = (int) request.getAttribute("userId");
386
                innerObject.add(toDealObject(jsonObject.asObject()));
387
 
387
            }
388
		String uri = "/deals/" + userId;
388
            if (innerObject.size() > 0) {
389
		RestClient rc = new RestClient();
389
                responseObject.add(innerObject);
390
		Map<String, String> params = new HashMap<>();
390
            }
391
		params.put("offset", offset);
391
        }
392
		params.put("limit", limit);
392
        return responseSender.ok(responseObject);
393
		params.put("categoryId", categoryId);
393
    }
394
		params.put("direction", direction);
394
 
395
		params.put("sort", sort);
395
    private Object toDealObject(JsonObject jsonObject) {
396
		params.put("source", "online");
396
        if (jsonObject.get("dealObject") != null && jsonObject.get("dealObject").asInt() == 1) {
397
		params.put("filterData", filterData);
397
            return new Gson().fromJson(jsonObject.toString(), DealObjectResponse.class);
398
		/*
398
        }
399
		 * if (userInfo.getRoleNames().contains(RoleType.FOFO.toString())) {
399
        return new Gson().fromJson(jsonObject.toString(), DealsResponse.class);
400
		 * params.put("tag_ids", getCommaSeparateTags(userId)); }
400
    }
401
		 */
401
 
402
		List<Object> responseObject = new ArrayList<>();
402
    @RequestMapping(value = ProfitMandiConstants.URL_BRANDS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
403
		try {
403
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
404
			response = rc.get(SchemeType.HTTP, host, port, uri, params);
404
    @ApiOperation(value = "Get brand list and count for category")
405
		} catch (HttpHostConnectException e) {
405
    public ResponseEntity<?> getBrands(HttpServletRequest request, @RequestParam(value = "category_id") String category_id) throws ProfitMandiBusinessException {
406
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
406
        logger.info("Request " + request.getParameterMap());
407
		}
407
        String response = null;
408
 
408
        // TODO: move to properties
409
		JsonArray result_json = Json.parse(response).asArray();
409
        String uri = ProfitMandiConstants.URL_BRANDS;
410
		for (JsonValue j : result_json) {
410
        RestClient rc = new RestClient();
411
			// logger.info("res " + j.asArray());
411
        Map<String, String> params = new HashMap<>();
412
			List<Object> innerObject = new ArrayList<>();
412
        params.put("category_id", category_id);
413
			for (JsonValue jsonObject : j.asArray()) {
413
        List<DealBrands> dealBrandsResponse = null;
414
				innerObject.add(toDealObject(jsonObject.asObject()));
414
        try {
415
			}
415
            response = rc.get(SchemeType.HTTP, host, port, uri, params);
416
			if (innerObject.size() > 0) {
416
        } catch (HttpHostConnectException e) {
417
				responseObject.add(innerObject);
417
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
418
			}
418
        }
419
		}
419
 
420
		return responseSender.ok(responseObject);
420
        dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
421
	}
421
        }.getType());
422
 
422
 
423
	private Object toDealObject(JsonObject jsonObject) {
423
        return responseSender.ok(dealBrandsResponse);
424
		if (jsonObject.get("dealObject") != null && jsonObject.get("dealObject").asInt() == 1) {
424
    }
425
			return new Gson().fromJson(jsonObject.toString(), DealObjectResponse.class);
425
 
426
		}
426
    @RequestMapping(value = ProfitMandiConstants.URL_UNIT_DEAL, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
427
		return new Gson().fromJson(jsonObject.toString(), DealsResponse.class);
427
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
428
	}
428
    @ApiOperation(value = "Get unit deal object")
429
 
429
    public ResponseEntity<?> getUnitDeal(HttpServletRequest request, @PathVariable(value = "id") long id) throws ProfitMandiBusinessException {
430
	@RequestMapping(value = ProfitMandiConstants.URL_BRANDS, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
430
        String response = null;
431
	@ApiImplicitParams({
431
        // TODO: move to properties
432
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
432
        String uri = "getDealById/" + id;
433
	@ApiOperation(value = "Get brand list and count for category")
433
        System.out.println("Unit deal " + uri);
434
	public ResponseEntity<?> getBrands(HttpServletRequest request,
434
        RestClient rc = new RestClient();
435
			@RequestParam(value = "category_id") String category_id) throws ProfitMandiBusinessException {
435
        Map<String, String> params = new HashMap<>();
436
		logger.info("Request " + request.getParameterMap());
436
        DealsResponse dealsResponse = null;
437
		String response = null;
437
        try {
438
		// TODO: move to properties
438
            response = rc.get(SchemeType.HTTP, host, port, uri, params);
439
		String uri = ProfitMandiConstants.URL_BRANDS;
439
        } catch (HttpHostConnectException e) {
440
		RestClient rc = new RestClient();
440
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
441
		Map<String, String> params = new HashMap<>();
441
        }
442
		params.put("category_id", category_id);
442
 
443
		List<DealBrands> dealBrandsResponse = null;
443
        JsonObject result_json = Json.parse(response).asObject();
444
		try {
444
        if (!result_json.isEmpty()) {
445
			response = rc.get(SchemeType.HTTP, host, port, uri, params);
445
            dealsResponse = new Gson().fromJson(response, DealsResponse.class);
446
		} catch (HttpHostConnectException e) {
446
            Iterator<AvailabilityInfo> iter = dealsResponse.getAvailabilityInfo().iterator();
447
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
447
            while (iter.hasNext()) {
448
		}
448
                AvailabilityInfo ai = iter.next();
449
 
449
                if (ai.getAvailability() <= 0)
450
		dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
450
                    iter.remove();
451
		}.getType());
451
            }
452
 
452
        }
453
		return responseSender.ok(dealBrandsResponse);
453
        return responseSender.ok(dealsResponse);
454
	}
454
    }
455
 
455
 
456
	@RequestMapping(value = ProfitMandiConstants.URL_UNIT_DEAL, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
456
    @RequestMapping(value = "/partnerdeals/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
457
	@ApiImplicitParams({
457
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
458
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
458
    @ApiOperation(value = "Get unit deal object")
459
	@ApiOperation(value = "Get unit deal object")
459
    public ResponseEntity<?> getUnitFocoDeal(HttpServletRequest request, @PathVariable(value = "id") long id) throws Exception {
460
	public ResponseEntity<?> getUnitDeal(HttpServletRequest request, @PathVariable(value = "id") long id)
460
        List<FofoCatalogResponse> dealResponse = new ArrayList<>();
461
			throws ProfitMandiBusinessException {
461
        List<Integer> tagIds = Arrays.asList(4);
462
		String response = null;
462
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
463
		// TODO: move to properties
463
        if (roleManagerService.isPartner(userInfo.getRoleIds())) {
464
		String uri = "getDealById/" + id;
464
            String categoryId = "(3 OR 6)";
465
		System.out.println("Unit deal " + uri);
465
            UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
466
		RestClient rc = new RestClient();
466
            RestClient rc = new RestClient();
467
		Map<String, String> params = new HashMap<>();
467
            Map<String, String> params = new HashMap<>();
468
		DealsResponse dealsResponse = null;
468
            List<String> mandatoryQ = new ArrayList<>();
469
		try {
469
            String catalogString = "catalog" + id;
470
			response = rc.get(SchemeType.HTTP, host, port, uri, params);
470
 
471
		} catch (HttpHostConnectException e) {
471
            mandatoryQ.add(String.format("+(categoryId_i:%s) +(id:%s) +{!parent which=\"id:%s\"} tagId_i:(%s)", categoryId, catalogString, catalogString, StringUtils.join(tagIds, " ")));
472
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
472
 
473
		}
473
            params.put("q", StringUtils.join(mandatoryQ, " "));
474
 
474
            params.put("fl", "*, [child parentFilter=id:catalog*]");
475
		JsonObject result_json = Json.parse(response).asObject();
475
            params.put("sort", "rank_i asc, create_s desc");
476
		if (!result_json.isEmpty()) {
476
            params.put("wt", "json");
477
			dealsResponse = new Gson().fromJson(response, DealsResponse.class);
477
            String response = null;
478
			Iterator<AvailabilityInfo> iter = dealsResponse.getAvailabilityInfo().iterator();
478
            try {
479
			while (iter.hasNext()) {
479
                response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
480
				AvailabilityInfo ai = iter.next();
480
            } catch (HttpHostConnectException e) {
481
				if (ai.getAvailability() <= 0)
481
                throw new ProfitMandiBusinessException("", "", "Could not connect to host");
482
					iter.remove();
482
            }
483
			}
483
            JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
484
		}
484
            JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
485
		return responseSender.ok(dealsResponse);
485
            dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
486
	}
486
        } else {
487
 
487
            return responseSender.badRequest(
488
	@RequestMapping(value = "/partnerdeals/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
488
                    new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
489
	@ApiImplicitParams({
489
        }
490
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
490
        return responseSender.ok(dealResponse.get(0));
491
	@ApiOperation(value = "Get unit deal object")
491
    }
492
	public ResponseEntity<?> getUnitFocoDeal(HttpServletRequest request, @PathVariable(value = "id") long id)
492
 
493
			throws Exception {
493
    @RequestMapping(value = "/fofo/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
494
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
494
    public ResponseEntity<?> getBrandsToDisplay(HttpServletRequest request, @RequestParam(required = false, defaultValue = "0") int categoryId) throws Exception {
495
		List<Integer> tagIds = Arrays.asList(4);
495
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
496
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
496
        logger.info("userInfo [{}]", userInfo);
497
		if (roleManagerService.isPartner(userInfo.getRoleIds())) {
497
        List<DBObject> brandsDisplay = mongoClient.getMongoBrands(userInfo.getRetailerId(), userInfo.getEmail(), categoryId);
498
			String categoryId = "(3 OR 6)";
498
        return new ResponseEntity<>(brandsDisplay, HttpStatus.OK);
499
			UserCart uc = userAccountRepository.getUserCart(userInfo.getUserId());
499
    }
500
			RestClient rc = new RestClient();
500
 
501
			Map<String, String> params = new HashMap<>();
501
    @RequestMapping(value = "/fofo/brandCatalog", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
502
			List<String> mandatoryQ = new ArrayList<>();
502
    public ResponseEntity<?> getBrands(HttpServletRequest request, @RequestParam(required = false, defaultValue = "0") int categoryId) throws Exception {
503
			String catalogString = "catalog" + id;
503
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
504
 
504
        logger.info("userInfo [{}]", userInfo);
505
			mandatoryQ.add(String.format("+(categoryId_i:%s) +(id:%s) +{!parent which=\"id:%s\"} tagId_i:(%s)",
505
 
506
					categoryId, catalogString, catalogString, StringUtils.join(tagIds, " ")));
506
        List<BrandCatalog> brandsDisplay = brandsService.getBrands(userInfo.getRetailerId(), userInfo.getEmail(), categoryId);
507
 
507
        return new ResponseEntity<>(brandsDisplay, HttpStatus.OK);
508
			params.put("q", StringUtils.join(mandatoryQ, " "));
508
    }
509
			params.put("fl", "*, [child parentFilter=id:catalog*]");
509
 
510
			params.put("sort", "rank_i asc, create_s desc");
510
    @RequestMapping(value = "/fofo/accessory/all-categories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
511
			params.put("wt", "json");
511
    public ResponseEntity<?> getSubCategoriesToDisplay(HttpServletRequest request) throws Exception {
512
			String response = null;
512
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
513
			try {
513
        logger.info("userInfo [{}]", userInfo);
514
				response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
514
        List<DBObject> subCategoriesDisplay = this.getSubCategoriesToDisplay();
515
			} catch (HttpHostConnectException e) {
515
        return new ResponseEntity<>(subCategoriesDisplay, HttpStatus.OK);
516
				throw new ProfitMandiBusinessException("", "", "Could not connect to host");
516
    }
517
			}
517
 
518
			JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
518
    private List<DBObject> getSubCategoriesToDisplay() throws Exception {
519
			JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
519
        List<DBObject> subCategories = new ArrayList<>();
520
			dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
520
        RestClient rc = new RestClient();
521
		} else {
521
        Map<String, String> params = new HashMap<>();
522
			return responseSender.badRequest(
522
        params.put("q", "categoryId_i:6");
523
					new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
523
        params.put("group", "true");
524
		}
524
        params.put("group.field", "subCategoryId_i");
525
		return responseSender.ok(dealResponse.get(0));
525
        params.put("wt", "json");
526
	}
526
        params.put("rows", "50");
527
 
527
        params.put("fl", "subCategoryId_i");
528
	@RequestMapping(value = "/fofo/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
528
        String response = null;
529
	public ResponseEntity<?> getBrandsToDisplay(HttpServletRequest request,
529
        try {
530
			@RequestParam(required = false, defaultValue = "0") int categoryId) throws Exception {
530
            response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
531
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
531
        } catch (HttpHostConnectException e) {
532
		logger.info("userInfo [{}]", userInfo);
532
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
533
		List<DBObject> brandsDisplay = mongoClient.getMongoBrands(userInfo.getRetailerId(), userInfo.getEmail(),
533
        }
534
				categoryId);
534
        JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("grouped");
535
		return new ResponseEntity<>(brandsDisplay, HttpStatus.OK);
535
        JSONArray groups = solrResponseJSONObj.getJSONObject("subCategoryId_i").getJSONArray("groups");
536
	}
536
        List<Integer> categoryIds = new ArrayList<>();
537
 
537
        for (int i = 0; i < groups.length(); i++) {
538
	@RequestMapping(value = "/fofo/brandCatalog", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
538
            JSONObject groupObject = groups.getJSONObject(i);
539
	public ResponseEntity<?> getBrands(HttpServletRequest request,
539
            int subCategoryId = groupObject.getInt("groupValue");
540
			@RequestParam(required = false, defaultValue = "0") int categoryId) throws Exception {
540
            int quantity = groupObject.getJSONObject("doclist").getInt("numFound");
541
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
541
            categoryIds.add(subCategoryId);
542
		logger.info("userInfo [{}]", userInfo);
542
        }
543
 
543
 
544
		List<BrandCatalog> brandsDisplay = brandsService.getBrands(userInfo.getRetailerId(), userInfo.getEmail(),
544
        List<Category> categories = categoryRepository.selectByIds(categoryIds);
545
				categoryId);
545
        AtomicInteger i = new AtomicInteger(0);
546
		return new ResponseEntity<>(brandsDisplay, HttpStatus.OK);
546
        categories.forEach(x -> {
547
	}
547
            DBObject dbObject = new BasicDBObject();
548
 
548
            dbObject.put("name", x.getLabel());
549
	@RequestMapping(value = "/fofo/accessory/all-categories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
549
            dbObject.put("subCategoryId", x.getId());
550
	public ResponseEntity<?> getSubCategoriesToDisplay(HttpServletRequest request) throws Exception {
550
            dbObject.put("rank", i.incrementAndGet());
551
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
551
            dbObject.put("categoryId", 6);
552
		logger.info("userInfo [{}]", userInfo);
552
            dbObject.put("url", "https://images.smartdukaan.com/uploads/campaigns/" + x.getId() + ".png");
553
		List<DBObject> subCategoriesDisplay = this.getSubCategoriesToDisplay();
553
            subCategories.add(dbObject);
554
		return new ResponseEntity<>(subCategoriesDisplay, HttpStatus.OK);
554
        });
555
	}
555
 
556
 
556
        return subCategories;
557
	private List<DBObject> getSubCategoriesToDisplay() throws Exception {
557
 
558
		List<DBObject> subCategories = new ArrayList<>();
558
    }
559
		RestClient rc = new RestClient();
559
 
560
		Map<String, String> params = new HashMap<>();
560
    @RequestMapping(value = "/banners/{bannerType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
561
		params.put("q", "categoryId_i:6");
561
    public ResponseEntity<?> getBanners(@PathVariable String bannerType) {
562
		params.put("group", "true");
562
        return new ResponseEntity<>(mongoClient.getBannersByType(bannerType), HttpStatus.OK);
563
		params.put("group.field", "subCategoryId_i");
563
    }
564
		params.put("wt", "json");
564
 
565
		params.put("rows", "50");
565
    @RequestMapping(value = "/deals/subCategories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
566
		params.put("fl", "subCategoryId_i");
566
    public ResponseEntity<?> getSubcategoriesToDisplay() {
567
		String response = null;
567
        return new ResponseEntity<>(mongoClient.getSubcategoriesToDisplay(), HttpStatus.OK);
568
		try {
568
    }
569
			response = rc.get(SchemeType.HTTP, "50.116.10.120", 8984, "solr/demo/select", params);
569
 
570
		} catch (HttpHostConnectException e) {
570
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
571
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
571
    @RequestMapping(value = "/deals/skus/{skus}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
572
		}
572
    public ResponseEntity<?> getDealsBySkus(@PathVariable String skus) throws ProfitMandiBusinessException {
573
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("grouped");
573
        StringBuffer sb = new StringBuffer("/getDealsForNotification/");
574
		JSONArray groups = solrResponseJSONObj.getJSONObject("subCategoryId_i").getJSONArray("groups");
574
        String uri = sb.append(skus).toString();
575
		List<Integer> categoryIds = new ArrayList<>();
575
        RestClient rc = new RestClient();
576
		for (int i = 0; i < groups.length(); i++) {
576
        String response;
577
			JSONObject groupObject = groups.getJSONObject(i);
577
        try {
578
			int subCategoryId = groupObject.getInt("groupValue");
578
            response = rc.get(SchemeType.HTTP, host, port, uri, new HashMap<>());
579
			int quantity = groupObject.getJSONObject("doclist").getInt("numFound");
579
        } catch (HttpHostConnectException e) {
580
			categoryIds.add(subCategoryId);
580
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
581
		}
581
        }
582
 
582
        JsonArray result_json = Json.parse(response).asArray();
583
		List<Category> categories = categoryRepository.selectByIds(categoryIds);
583
        List<Object> responseObject = new ArrayList<>();
584
		AtomicInteger i = new AtomicInteger(0);
584
        for (JsonValue j : result_json) {
585
		categories.forEach(x -> {
585
            // logger.info("res " + j.asArray());
586
			DBObject dbObject = new BasicDBObject();
586
            List<Object> innerObject = new ArrayList<>();
587
			dbObject.put("name", x.getLabel());
587
            for (JsonValue jsonObject : j.asArray()) {
588
			dbObject.put("subCategoryId", x.getId());
588
                innerObject.add(toDealObject(jsonObject.asObject()));
589
			dbObject.put("rank", i.incrementAndGet());
589
            }
590
			dbObject.put("categoryId", 6);
590
            if (innerObject.size() > 0) {
591
			dbObject.put("url", "https://images.smartdukaan.com/uploads/campaigns/" + x.getId() + ".png");
591
                responseObject.add(innerObject);
592
			subCategories.add(dbObject);
592
            }
593
		});
593
        }
594
 
594
        return responseSender.ok(responseObject);
595
		return subCategories;
595
    }
596
 
596
 
597
	}
597
    @RequestMapping(value = "/partner/listing", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
598
 
598
    public ResponseEntity<?> getPartnersListing(HttpServletRequest request) throws Exception {
599
	@RequestMapping(value = "/banners/{bannerType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
599
        List<WebListing> webListings = webListingRepository.selectAllWebListingByType(Optional.of(true), WebListingSource.partner);
600
	public ResponseEntity<?> getBanners(@PathVariable String bannerType) {
600
        UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
601
		return new ResponseEntity<>(mongoClient.getBannersByType(bannerType), HttpStatus.OK);
601
        for (WebListing webListing : webListings) {
602
	}
602
 
603
 
603
            webListing.setFofoCatalogResponses(getDealResponses(userInfo, webListing, "0", "20"));
604
	@RequestMapping(value = "/deals/subCategories", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
604
        }
605
	public ResponseEntity<?> getSubcategoriesToDisplay() {
605
        return responseSender.ok(webListings);
606
		return new ResponseEntity<>(mongoClient.getSubcategoriesToDisplay(), HttpStatus.OK);
606
    }
607
	}
607
 
608
 
608
    private List<FofoCatalogResponse> getDealResponses(UserInfo userInfo, WebListing webListing, String offset, String limit) throws Exception {
609
	@ApiImplicitParams({
609
 
610
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
610
        RestClient rc = new RestClient();
611
	@RequestMapping(value = "/deals/skus/{skus}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
611
        Map<String, String> params = new HashMap<>();
612
	public ResponseEntity<?> getDealsBySkus(@PathVariable String skus) throws ProfitMandiBusinessException {
612
        List<String> mandatoryQ = new ArrayList<>();
613
		StringBuffer sb = new StringBuffer("/getDealsForNotification/");
613
 
614
		String uri = sb.append(skus).toString();
614
        FofoStore fs = fofoStoreRepository.selectByRetailerId(userInfo.getRetailerId());
615
		RestClient rc = new RestClient();
615
 
616
		String response;
616
        params.put("sort", "w" + fs.getWarehouseId() + "_i desc");
617
		try {
617
 
618
			response = rc.get(SchemeType.HTTP, host, port, uri, new HashMap<>());
618
        List<Integer> webProducts = null;
619
		} catch (HttpHostConnectException e) {
619
        if (webListing.getType().equals(WebListingType.solr)) {
620
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
620
            logger.info("solrtype {}", webListing.getSolrQuery());
621
		}
621
            mandatoryQ.add(String.format("+{!parent which=\"" + webListing.getSolrQuery() + "\"} AND active_b:true AND show_default_b:true"));
622
		JsonArray result_json = Json.parse(response).asArray();
622
        } else {
623
		List<Object> responseObject = new ArrayList<>();
623
            logger.info("solrtype2 {}", webListing.getSolrQuery());
624
		for (JsonValue j : result_json) {
624
 
625
			// logger.info("res " + j.asArray());
625
            webProducts = webProductListingRepository.selectAllByWebListingId(webListing.getId(), Integer.parseInt(offset), Integer.parseInt(limit)).stream().filter(x -> x.getRank() > 0).map(x -> x.getEntityId()).collect(Collectors.toList());
626
			List<Object> innerObject = new ArrayList<>();
626
 
627
			for (JsonValue jsonObject : j.asArray()) {
627
            if (webProducts.size() == 0) {
628
				innerObject.add(toDealObject(jsonObject.asObject()));
628
                return new ArrayList<>();
629
			}
629
            }
630
			if (innerObject.size() > 0) {
630
 
631
				responseObject.add(innerObject);
631
            mandatoryQ.add(String.format(
632
			}
632
                    "+{!parent which=\"catalogId_i:" + StringUtils.join(webProducts, " ") + "\"} AND active_b:true AND show_default_b:true"));
633
		}
633
 
634
		return responseSender.ok(responseObject);
634
        }
635
	}
635
        params.put("q", StringUtils.join(mandatoryQ, " "));
636
 
636
        params.put("fl", "*, [child parentFilter=id:catalog* childFilter=active_b:true ]");
637
	@RequestMapping(value = "/partner/listing", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
637
 
638
	public ResponseEntity<?> getPartnersListing(HttpServletRequest request) throws Exception {
638
        params.put("start", String.valueOf(offset));
639
		List<WebListing> webListings = webListingRepository.selectAllWebListingByType(Optional.of(true),
639
        params.put("rows", String.valueOf(limit));
640
				WebListingSource.partner);
640
        params.put("wt", "json");
641
		UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
641
        String response = null;
642
		for (WebListing webListing : webListings) {
642
        try {
643
 
643
            response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
644
			webListing.setFofoCatalogResponses(getDealResponses(userInfo, webListing, "0", "20"));
644
        } catch (HttpHostConnectException e) {
645
		}
645
            throw new ProfitMandiBusinessException("", "", "Could not connect to host");
646
		return responseSender.ok(webListings);
646
        }
647
	}
647
        JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
648
 
648
        JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
649
	private List<FofoCatalogResponse> getDealResponses(UserInfo userInfo, WebListing webListing, String offset,
649
        List<FofoCatalogResponse> dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
650
			String limit) throws Exception {
650
 
651
 
651
        if (webProducts != null && webListing.getUrl().equals("new-launches")) {
652
		RestClient rc = new RestClient();
652
            List<Integer> webProductsFinal = webProducts;
653
		Map<String, String> params = new HashMap<>();
653
            dealResponse = dealResponse.stream().sorted(Comparator.comparing(x -> webProductsFinal.indexOf(x.getCatalogId()))).collect(Collectors.toList());
654
		List<String> mandatoryQ = new ArrayList<>();
654
 
655
      
655
        }
656
		FofoStore fs = fofoStoreRepository.selectByRetailerId(userInfo.getRetailerId());
656
 
657
 
657
        return dealResponse;
658
		params.put("sort", "w" + fs.getWarehouseId() + "_i desc");
658
    }
659
 
659
 
660
		List<Integer> webProducts = null;
660
    @Autowired
661
		if (webListing.getType().equals(WebListingType.solr)) {
661
    private SaholicCISTableRepository saholicCISTableRepository;
662
			logger.info("solrtype {}", webListing.getSolrQuery());
662
 
663
			mandatoryQ.add(String.format("+{!parent which=\"" + webListing.getSolrQuery() + "\"} AND active_b:true AND show_default_b:true"));
663
    private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal, int fofoId) throws Exception {
664
		} else {
664
        List<FofoCatalogResponse> dealResponse = new ArrayList<>();
665
			logger.info("solrtype2 {}", webListing.getSolrQuery());
665
        List<Integer> tagIds = Arrays.asList(4);
666
 
666
        List<Integer> itemIds = new ArrayList<>();
667
			webProducts = webProductListingRepository
667
        if (docs.length() > 0) {
668
					.selectAllByWebListingId(webListing.getId(), Integer.parseInt(offset), Integer.parseInt(limit))
668
            for (int i = 0; i < docs.length(); i++) {
669
					.stream().filter(x -> x.getRank() > 0).map(x -> x.getEntityId()).collect(Collectors.toList());
669
                JSONObject doc = docs.getJSONObject(i);
670
 
670
                if (doc.has("_childDocuments_")) {
671
			if (webProducts.size() == 0) {
671
                    for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
672
				return new ArrayList<>();
672
                        JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
673
			}
673
                        int itemId = childItem.getInt("itemId_i");
674
 
674
                        itemIds.add(itemId);
675
			mandatoryQ.add(String.format(
675
                    }
676
					"+{!parent which=\"catalogId_i:" + StringUtils.join(webProducts, " ") + "\"} AND active_b:true AND show_default_b:true"));
676
                }
677
 
677
            }
678
		}
678
            if (itemIds.size() == 0) {
679
		params.put("q", StringUtils.join(mandatoryQ, " "));
679
                return dealResponse;
680
		params.put("fl", "*, [child parentFilter=id:catalog* childFilter=active_b:true ]");
680
            }
681
 
681
        }
682
		params.put("start", String.valueOf(offset));
682
        // get warehouse Id
683
		params.put("rows", String.valueOf(limit));
683
        int warehouseId = fofoStoreRepository.selectByRetailerId(fofoId).getWarehouseId();
684
		params.put("wt", "json");
684
        Map<Integer, List<SaholicPOItem>> poItemAvailabilityMap = saholicInventoryService.getSaholicPOItems().get(warehouseId);
685
		String response = null;
685
        List<Integer> catalogIds = new ArrayList<>();
686
		try {
686
        for (int i = 0; i < docs.length(); i++) {
687
			response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
687
            Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
688
		} catch (HttpHostConnectException e) {
688
            JSONObject doc = docs.getJSONObject(i);
689
			throw new ProfitMandiBusinessException("", "", "Could not connect to host");
689
            catalogIds.add(doc.getInt("catalogId_i"));
690
		}
690
        }
691
		JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
691
        List<CreateOfferRequest> allSchemOffers = null;
692
		JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
692
        Map<Integer, PriceCircularItemModelNew> priceCircularItemModelMap = new HashMap<>();
693
		List<FofoCatalogResponse> dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
693
        if (catalogIds.size() > 0) {
694
 
694
            PriceCircularModel priceCircularModel = priceCircularService.getPriceCircularByOffer(fofoId, catalogIds, LocalDate.now());
695
		if (webProducts != null && webListing.getUrl().equals("new-launches")) {
695
            allSchemOffers = priceCircularModel.getOffers();
696
			List<Integer> webProductsFinal = webProducts;
696
 
697
			dealResponse = dealResponse.stream()
697
            List<PriceCircularItemModelNew> priceCircularItemModelNews = priceCircularModel.getPriceCircularItemModelNews();
698
					.sorted(Comparator.comparing(x -> webProductsFinal.indexOf(x.getCatalogId())))
698
            if (priceCircularItemModelNews != null) {
699
					.collect(Collectors.toList());
699
                priceCircularItemModelMap = priceCircularItemModelNews.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
700
 
700
            }
701
		}
701
        }
702
 
702
 
703
		return dealResponse;
703
        List<CatalogFavourite> catalogFavourites = catalogFavouriteRepository.selectBypartnerId(fofoId);
704
	}
704
        List<Integer> catalogFavouriteIds = new ArrayList<>();
705
 
705
        if (!catalogFavourites.isEmpty()) {
706
	@Autowired
706
            catalogFavouriteIds = catalogFavourites.stream().map(x -> x.getCatalogId()).collect(Collectors.toList());
707
	private SaholicCISTableRepository saholicCISTableRepository;
707
        }
708
 
708
 
709
	private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal, int fofoId) throws Exception {
709
        if (!catalogFavourites.isEmpty()) {
710
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
710
            catalogFavourites.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
711
		List<Integer> tagIds = Arrays.asList(4);
711
        }
712
		List<Integer> itemIds = new ArrayList<>();
712
 
713
		if (docs.length() > 0) {
713
        for (int i = 0; i < docs.length(); i++) {
714
			for (int i = 0; i < docs.length(); i++) {
714
            Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
715
				JSONObject doc = docs.getJSONObject(i);
715
            JSONObject doc = docs.getJSONObject(i);
716
				if (doc.has("_childDocuments_")) {
716
            FofoCatalogResponse fofoCatalogResponse = new FofoCatalogResponse();
717
					for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
717
            fofoCatalogResponse.setCatalogId(doc.getInt("catalogId_i"));
718
						JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
718
            fofoCatalogResponse.setImageUrl(doc.getString("imageUrl_s"));
719
						int itemId = childItem.getInt("itemId_i");
719
            fofoCatalogResponse.setTitle(doc.getString("title_s"));
720
						itemIds.add(itemId);
720
 
721
					}
721
            if (catalogFavouriteIds.contains(fofoCatalogResponse.getCatalogId())) {
722
				}
722
                fofoCatalogResponse.setFavourite(true);
723
			}
723
            }
724
			if (itemIds.size() == 0) {
724
 
725
				return dealResponse;
725
            List<WebOffer> webOffers = webOfferRepository.selectAllActiveOffers().get(fofoCatalogResponse.getCatalogId());
726
			}
726
 
727
		}
727
            logger.info("webOffers {}", webOffers);
728
		// get warehouse Id
728
            if (webOffers != null && webOffers.size() > 0) {
729
		int warehouseId = fofoStoreRepository.selectByRetailerId(fofoId).getWarehouseId();
729
                fofoCatalogResponse.setWebOffers(webOffers);
730
		Map<Integer, List<SaholicPOItem>> poItemAvailabilityMap = saholicInventoryService.getSaholicPOItems()
730
                fofoCatalogResponse.setOffers(webOffers.stream().map(x -> x.getTitle()).collect(Collectors.toList()));
731
				.get(warehouseId);
731
 
732
		List<Integer> catalogIds = new ArrayList<>();
732
            }
733
		for (int i = 0; i < docs.length(); i++) {
733
 
734
			Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
734
            List<ComboModel> comboModels = comboModelRepository.selectByWarehouseId(warehouseId).stream().filter(x -> x.getCatalogId() == fofoCatalogResponse.getCatalogId()).collect(Collectors.toList());
735
			JSONObject doc = docs.getJSONObject(i);
735
 
736
			catalogIds.add(doc.getInt("catalogId_i"));
736
            logger.info("comboModels {}", comboModels);
737
		}
737
            
738
		List<CreateOfferRequest> allSchemOffers = null;
738
            if (comboModels != null && comboModels.size() > 0) {
739
		Map<Integer, PriceCircularItemModelNew> priceCircularItemModelMap = new HashMap<>();
739
                fofoCatalogResponse.setComboModels(comboModels);
740
		if (catalogIds.size() > 0) {
740
            }
741
			PriceCircularModel priceCircularModel = priceCircularService.getPriceCircularByOffer(fofoId, catalogIds, LocalDate.now());
741
 
742
			allSchemOffers = priceCircularModel.getOffers();
742
            try {
743
 
743
                fofoCatalogResponse.setFeature(doc.getString("feature_s"));
744
			List<PriceCircularItemModelNew> priceCircularItemModelNews = priceCircularModel.getPriceCircularItemModelNews();
744
            } catch (Exception e) {
745
			if (priceCircularItemModelNews != null) {
745
                fofoCatalogResponse.setFeature(null);
746
				priceCircularItemModelMap = priceCircularItemModelNews.stream()
746
                logger.info("Could not find Feature_s for {}", fofoCatalogResponse.getCatalogId());
747
						.collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
747
            }
748
			}
748
 
749
		}
749
            fofoCatalogResponse.setBrand(doc.getJSONArray("brand_ss").getString(0));
750
 
750
            logger.info("labelss {}", doc.has("label_ss"));
751
		List<CatalogFavourite> catalogFavourites = catalogFavouriteRepository.selectBypartnerId(fofoId);
751
 
752
		List<Integer> catalogFavouriteIds = new ArrayList<>();
752
            if (doc.has("label_ss")) {
753
		if (!catalogFavourites.isEmpty()) {
753
                logger.info("label {}", doc.getJSONArray("label_ss"));
754
			catalogFavouriteIds = catalogFavourites.stream().map(x -> x.getCatalogId()).collect(Collectors.toList());
754
 
755
		}
755
                JSONArray arr = doc.getJSONArray("label_ss");
756
 
756
                Set<String> labels = new HashSet<String>();
757
		if (!catalogFavourites.isEmpty()) {
757
                for (int j = 0; j < arr.length(); j++) {
758
			catalogFavourites.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
758
                    labels.add(arr.getString(j));
759
		}
759
                }
760
 
760
 
761
		for (int i = 0; i < docs.length(); i++) {
761
                fofoCatalogResponse.setLabels(new ArrayList<>(labels));
762
			Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
762
 
763
			JSONObject doc = docs.getJSONObject(i);
763
            }
764
			FofoCatalogResponse fofoCatalogResponse = new FofoCatalogResponse();
764
 
765
			fofoCatalogResponse.setCatalogId(doc.getInt("catalogId_i"));
765
            if (doc.has("_childDocuments_")) {
766
			fofoCatalogResponse.setImageUrl(doc.getString("imageUrl_s"));
766
                String modelColorClass = "grey";
767
			fofoCatalogResponse.setTitle(doc.getString("title_s"));
767
                FofoAvailabilityInfo fdiAnyColour = null;
768
 
768
                // Iterating itemIds
769
			if (catalogFavouriteIds.contains(fofoCatalogResponse.getCatalogId())) {
769
                for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
770
				fofoCatalogResponse.setFavourite(true);
770
                    PriceCircularItemModelNew priceCircularItemModel = priceCircularItemModelMap.get(fofoCatalogResponse.getCatalogId());
771
			}
771
                    JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
772
 
772
                    int itemId = childItem.getInt("itemId_i");
773
			List<WebOffer> webOffers = webOfferRepository.selectAllActiveOffers()
773
                    float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
774
					.get(fofoCatalogResponse.getCatalogId());
774
                    if (!fofoAvailabilityInfoMap.containsKey(itemId)) {
775
 
775
                        FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
776
			logger.info("webOffers {}", webOffers);
776
                        List<SaholicCISTable> currentAvailability = saholicCISTableRepository.selectByItemWarehouse(itemId, warehouseId);
777
			if (webOffers != null && webOffers.size() > 0) {
777
                        List<SaholicPOItem> poItemAvailability = null;
778
				fofoCatalogResponse.setWebOffers(webOffers);
778
                        if (poItemAvailabilityMap != null) {
779
				fofoCatalogResponse.setOffers(webOffers.stream().map(x -> x.getTitle()).collect(Collectors.toList()));
779
                            poItemAvailability = poItemAvailabilityMap.get(itemId);
780
 
780
                        }
781
			}
781
 
782
 
782
                        if (priceCircularItemModel != null) {
783
			List<ComboModel> comboModels = comboModelRepository.selectByWarehouseId(warehouseId).stream()
783
                            fdi.setNlc((float) priceCircularItemModel.getNetNlc());
784
					.filter(x -> x.getCatalogId() == fofoCatalogResponse.getCatalogId()).collect(Collectors.toList());
784
                        }
785
 
785
 
786
			for (ComboModel comboModel : comboModels) {
786
                        for (SaholicCISTable saholicCISTable : currentAvailability) {
787
 
787
                            saholicCISTable.setWarehouseName(
788
				List<ComboMappedModel> mappedModels = comboMappedModelRepository.selectByComboId(comboModel.getId());
788
                                    ProfitMandiConstants.WAREHOUSE_MAP.get(saholicCISTable.getWarehouseFrom()));
789
 
789
                        }
790
				comboModel.setComboMappedModels(mappedModels);
790
 
791
 
791
                        Map<Integer, SaholicCISTable> map = currentAvailability.stream().collect(Collectors.toMap(SaholicCISTable::getWarehouseFrom, x -> x));
792
			}
792
                        if (poItemAvailability != null) {
793
 
793
                            for (SaholicPOItem saholicPOItem : poItemAvailability) {
794
			if (comboModels != null && comboModels.size() > 0) {
794
                                if (map.containsKey(saholicPOItem.getWarehouseFrom())) {
795
				fofoCatalogResponse.setComboModels(comboModels);
795
                                    map.get(saholicPOItem.getWarehouseFrom()).setPopendingQty(saholicPOItem.getUnfulfilledQty());
796
			}
796
                                } else {
797
 
797
                                    SaholicCISTable saholicCISTable = new SaholicCISTable();
798
			try {
798
                                    saholicCISTable.setAvailability(0);
799
				fofoCatalogResponse.setFeature(doc.getString("feature_s"));
799
                                    saholicCISTable.setReserved(0);
800
			} catch (Exception e) {
800
                                    saholicCISTable.setItemId(itemId);
801
				fofoCatalogResponse.setFeature(null);
801
                                    saholicCISTable.setWarehouseId(warehouseId);
802
				logger.info("Could not find Feature_s for {}", fofoCatalogResponse.getCatalogId());
802
                                    saholicCISTable.setPopendingQty(saholicPOItem.getUnfulfilledQty());
803
			}
803
                                    saholicCISTable.setWarehouseFrom(saholicPOItem.getWarehouseFrom());
804
 
804
                                    saholicCISTable.setWarehouseName(
805
			fofoCatalogResponse.setBrand(doc.getJSONArray("brand_ss").getString(0));
805
                                            ProfitMandiConstants.WAREHOUSE_MAP.get(saholicPOItem.getWarehouseFrom()));
806
			logger.info("labelss {}", doc.has("label_ss"));
806
                                    map.put(saholicPOItem.getWarehouseFrom(), saholicCISTable);
807
 
807
                                }
808
			if (doc.has("label_ss")) {
808
                            }
809
				logger.info("label {}", doc.getJSONArray("label_ss"));
809
                        }
810
 
810
                        fdi.setSaholicCISTableList(new ArrayList<>(map.values()));
811
				JSONArray arr = doc.getJSONArray("label_ss");
811
                        String poColor = "grey";
812
				Set<String> labels = new HashSet<String>();
812
                        boolean active = false;
813
				for (int j = 0; j < arr.length(); j++) {
813
                        if (currentAvailability != null && currentAvailability.stream().collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)) > 0) {
814
					labels.add(arr.getString(j));
814
                            poColor = "green";
815
				}
815
                            modelColorClass = "green";
816
 
816
                        } else
817
				fofoCatalogResponse.setLabels(new ArrayList<>(labels));
817
                            if (poItemAvailability != null && poItemAvailability.stream().collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty)) > 0) {
818
 
818
                                if (currentAvailability != null && poItemAvailability.stream().collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty)) + currentAvailability.stream().collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)) <= 0) {
819
			}
819
                                    poColor = "grey";
820
 
820
                                } else {
821
			if (doc.has("_childDocuments_")) {
821
                                    poColor = "yellow";
822
				String modelColorClass = "grey";
822
                                    if (modelColorClass != "green") {
823
				FofoAvailabilityInfo fdiAnyColour = null;
823
                                        modelColorClass = poColor;
824
				// Iterating itemIds
824
                                    }
825
				for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
825
                                }
826
					PriceCircularItemModelNew priceCircularItemModel = priceCircularItemModelMap
826
                            }
827
							.get(fofoCatalogResponse.getCatalogId());
827
                        fdi.setColorClass(poColor);
828
					JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
828
                        fdi.setSellingPrice(sellingPrice);
829
					int itemId = childItem.getInt("itemId_i");
829
                        fdi.setActive(active);
830
					float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
830
                        fdi.setMrp(childItem.getDouble("mrp_f"));
831
					if (!fofoAvailabilityInfoMap.containsKey(itemId)) {
831
                        fdi.setMop((float) childItem.getDouble("mop_f"));
832
						FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
832
                        fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
833
						List<SaholicCISTable> currentAvailability = saholicCISTableRepository
833
                        if (fdi.getColor().equalsIgnoreCase("any colour")) {
834
								.selectByItemWarehouse(itemId, warehouseId);
834
                            fdiAnyColour = fdi;
835
						List<SaholicPOItem> poItemAvailability = null;
835
                        }
836
						if (poItemAvailabilityMap != null) {
836
                        fdi.setTagId(childItem.getInt("tagId_i"));
837
							poItemAvailability = poItemAvailabilityMap.get(itemId);
837
                        fdi.setItem_id(itemId);
838
						}
838
                        Float cashBack = schemeService.getCatalogSchemeCashBack().get(fofoCatalogResponse.getCatalogId());
839
						fdi.setNlc((float)priceCircularItemModel.getNetNlc());
839
                        cashBack = cashBack == null ? 0 : cashBack;
840
 
840
                        fdi.setCashback(cashBack);
841
						for (SaholicCISTable saholicCISTable : currentAvailability) {
841
                        fdi.setMinBuyQuantity(1);
842
							saholicCISTable.setWarehouseName(
842
                        if (hotDeal) {
843
									ProfitMandiConstants.WAREHOUSE_MAP.get(saholicCISTable.getWarehouseFrom()));
843
                            if (currentAvailability != null) {
844
						}
844
                                fdi.setAvailability(currentAvailability.stream().collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)));
845
 
845
                            } else {
846
						Map<Integer, SaholicCISTable> map = currentAvailability.stream()
846
                                fdi.setAvailability(0);
847
								.collect(Collectors.toMap(SaholicCISTable::getWarehouseFrom, x -> x));
847
                            }
848
						if (poItemAvailability != null) {
848
                        } else {
849
							for (SaholicPOItem saholicPOItem : poItemAvailability) {
849
                            // Lets consider that its out of stock
850
								if (map.containsKey(saholicPOItem.getWarehouseFrom())) {
850
                            fdi.setAvailability(100);
851
									map.get(saholicPOItem.getWarehouseFrom())
851
                            Item item = null;
852
											.setPopendingQty(saholicPOItem.getUnfulfilledQty());
852
                            try {
853
								} else {
853
                                item = itemRepository.selectById(itemId);
854
									SaholicCISTable saholicCISTable = new SaholicCISTable();
854
                            } catch (Exception e) {
855
									saholicCISTable.setAvailability(0);
855
                                e.printStackTrace();
856
									saholicCISTable.setReserved(0);
856
                                continue;
857
									saholicCISTable.setItemId(itemId);
857
                            }
858
									saholicCISTable.setWarehouseId(warehouseId);
858
                            // In case its tampered glass moq should be
859
									saholicCISTable.setPopendingQty(saholicPOItem.getUnfulfilledQty());
859
                            if (item.getCategoryId() == 10020) {
860
									saholicCISTable.setWarehouseFrom(saholicPOItem.getWarehouseFrom());
860
                                fdi.setMinBuyQuantity(5);
861
									saholicCISTable.setWarehouseName(
861
                            }
862
											ProfitMandiConstants.WAREHOUSE_MAP.get(saholicPOItem.getWarehouseFrom()));
862
                        }
863
									map.put(saholicPOItem.getWarehouseFrom(), saholicCISTable);
863
                        fdi.setQuantityStep(1);
864
								}
864
                        fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
865
							}
865
                        fofoAvailabilityInfoMap.put(itemId, fdi);
866
						}
866
                    }
867
						fdi.setSaholicCISTableList(new ArrayList<>(map.values()));
867
                }
868
						String poColor = "grey";
868
                if (fdiAnyColour != null) {
869
						boolean active = false;
869
                    fdiAnyColour.setColorClass(modelColorClass);
870
						if (currentAvailability != null && currentAvailability.stream()
870
                }
871
								.collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)) > 0) {
871
            }
872
							poColor = "green";
872
            if (fofoAvailabilityInfoMap.values().size() > 0) {
873
							modelColorClass = "green";
873
                List<FofoAvailabilityInfo> availabilityList = fofoAvailabilityInfoMap.values().stream().sorted(Comparator.comparing(FofoAvailabilityInfo::getAvailability).reversed()).collect(Collectors.toList());
874
						} else if (poItemAvailability != null && poItemAvailability.stream()
874
                fofoCatalogResponse.setItems(availabilityList);
875
								.collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty)) > 0) {
875
                if (priceCircularItemModelMap.containsKey(fofoCatalogResponse.getCatalogId())) {
876
							if (currentAvailability != null && poItemAvailability.stream()
876
                    PriceCircularItemModelNew priceCircularItemModel = priceCircularItemModelMap.get(fofoCatalogResponse.getCatalogId());
877
									.collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty))
877
                    if (priceCircularItemModel.getSlabPayouts() != null) {
878
									+ currentAvailability.stream()
878
                        List<CreateOfferRequest> schemeOffers = new ArrayList<>();
879
											.collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)) <= 0) {
879
                        List<Map<Integer, AmountModel>> slabPayouts = priceCircularItemModel.getSlabPayouts();
880
								poColor = "grey";
880
                        Iterator<Map<Integer, AmountModel>> iterator = slabPayouts.iterator();
881
							} else {
881
                        int iteratorCount = 0;
882
								poColor = "yellow";
882
                        while (iterator.hasNext()) {
883
								if (modelColorClass != "green") {
883
                            Map<Integer, AmountModel> slabPayoutMap = iterator.next();
884
									modelColorClass = poColor;
884
                            if (slabPayoutMap != null) {
885
								}
885
                                schemeOffers.add(allSchemOffers.get(iteratorCount));
886
							}
886
                            } else {
887
						}
887
                                iterator.remove();
888
						fdi.setColorClass(poColor);
888
                            }
889
						fdi.setSellingPrice(sellingPrice);
889
                            iteratorCount++;
890
						fdi.setActive(active);
890
                        }
891
						fdi.setMrp(childItem.getDouble("mrp_f"));
891
                        fofoCatalogResponse.setSchemeOffers(schemeOffers);
892
						fdi.setMop((float) childItem.getDouble("mop_f"));
892
                    }
893
						fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
893
                    fofoCatalogResponse.setPriceCircularItemModel(priceCircularItemModel);
894
						if (fdi.getColor().equalsIgnoreCase("any colour")) {
894
                }
895
							fdiAnyColour = fdi;
895
                dealResponse.add(fofoCatalogResponse);
896
						}
896
            }
897
						fdi.setTagId(childItem.getInt("tagId_i"));
897
        }
898
						fdi.setItem_id(itemId);
898
        return dealResponse;
899
						Float cashBack = schemeService.getCatalogSchemeCashBack()
899
 
900
								.get(fofoCatalogResponse.getCatalogId());
900
    }
901
						cashBack = cashBack == null ? 0 : cashBack;
901
 
902
						fdi.setCashback(cashBack);
902
    private List<FofoCatalogResponse> getCatalogSingleSkuResponse(JSONArray docs, Map<Integer, Integer> itemFilter, boolean hotDeal) throws ProfitMandiBusinessException {
903
						fdi.setMinBuyQuantity(1);
903
        Map<Integer, TagListing> itemTagListingMap = null;
904
						if (hotDeal) {
904
        List<FofoCatalogResponse> dealResponse = new ArrayList<>();
905
							if (currentAvailability != null) {
905
        List<Integer> tagIds = Arrays.asList(4);
906
								fdi.setAvailability(currentAvailability.stream()
906
 
907
										.collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)));
907
        itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemFilter.keySet(), new HashSet<>(tagIds)).stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x));
908
							} else {
908
 
909
								fdi.setAvailability(0);
909
        for (int i = 0; i < docs.length(); i++) {
910
							}
910
            Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
911
						} else {
911
            JSONObject doc = docs.getJSONObject(i);
912
							// Lets consider that its out of stock
912
 
913
							fdi.setAvailability(100);
913
            for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
914
							Item item = null;
914
                JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
915
							try {
915
                int itemId = childItem.getInt("itemId_i");
916
								item = itemRepository.selectById(itemId);
916
                TagListing tl = itemTagListingMap.get(itemId);
917
							} catch (Exception e) {
917
                if (tl == null) {
918
								e.printStackTrace();
918
                    continue;
919
								continue;
919
                }
920
							}
920
                if (hotDeal) {
921
							// In case its tampered glass moq should be
921
                    if (!tl.isHotDeals()) {
922
							if (item.getCategoryId() == 10020) {
922
                        continue;
923
								fdi.setMinBuyQuantity(5);
923
                    }
924
							}
924
                }
925
						}
925
                float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
926
						fdi.setQuantityStep(1);
926
                if (fofoAvailabilityInfoMap.containsKey(itemId)) {
927
						fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
927
                    if (fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
928
						fofoAvailabilityInfoMap.put(itemId, fdi);
928
                        fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
929
					}
929
                        fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
930
				}
930
                    }
931
				if (fdiAnyColour != null) {
931
                } else {
932
					fdiAnyColour.setColorClass(modelColorClass);
932
                    FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
933
				}
933
                    fdi.setSellingPrice((float) childItem.getDouble("sellingPrice_f"));
934
			}
934
                    fdi.setMop((float) childItem.getDouble("mop_f"));
935
			if (fofoAvailabilityInfoMap.values().size() > 0) {
935
                    fdi.setMop((float) tl.getMrp());
936
				List<FofoAvailabilityInfo> availabilityList = fofoAvailabilityInfoMap.values().stream()
936
                    fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
937
						.sorted(Comparator.comparing(FofoAvailabilityInfo::getAvailability).reversed())
937
                    fdi.setTagId(childItem.getInt("tagId_i"));
938
						.collect(Collectors.toList());
938
                    fdi.setItem_id(itemId);
939
				fofoCatalogResponse.setItems(availabilityList);
939
                    Item item = itemRepository.selectById(itemId);
940
				if (priceCircularItemModelMap.containsKey(fofoCatalogResponse.getCatalogId())) {
940
                    // In case its tampered glass moq should be 5
941
					PriceCircularItemModelNew priceCircularItemModel = priceCircularItemModelMap
941
                    if (item.getCategoryId() == 10020) {
942
							.get(fofoCatalogResponse.getCatalogId());
942
                        fdi.setMinBuyQuantity(10);
943
					if (priceCircularItemModel.getSlabPayouts() != null) {
943
                    } else {
944
						List<CreateOfferRequest> schemeOffers = new ArrayList<>();
944
                        fdi.setMinBuyQuantity(1);
945
						List<Map<Integer, AmountModel>> slabPayouts = priceCircularItemModel.getSlabPayouts();
945
                    }
946
						Iterator<Map<Integer, AmountModel>> iterator = slabPayouts.iterator();
946
                    fdi.setAvailability(itemFilter.get(itemId));
947
						int iteratorCount = 0;
947
                    fdi.setQuantityStep(1);
948
						while (iterator.hasNext()) {
948
                    fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
949
							Map<Integer, AmountModel> slabPayoutMap = iterator.next();
949
                    fofoAvailabilityInfoMap.put(itemId, fdi);
950
							if (slabPayoutMap != null) {
950
                }
951
								schemeOffers.add(allSchemOffers.get(iteratorCount));
951
            }
952
							} else {
952
            if (fofoAvailabilityInfoMap.values().size() > 0) {
953
								iterator.remove();
953
                for (FofoAvailabilityInfo fofoAvailabilityInfo : fofoAvailabilityInfoMap.values()) {
954
							}
954
                    FofoCatalogResponse ffdr = new FofoCatalogResponse();
955
							iteratorCount++;
955
                    ffdr.setCatalogId(doc.getInt("catalogId_i"));
956
						}
956
                    ffdr.setImageUrl(doc.getString("imageUrl_s"));
957
						fofoCatalogResponse.setSchemeOffers(schemeOffers);
957
                    ffdr.setTitle(doc.getString("title_s"));
958
					}
958
                    try {
959
					fofoCatalogResponse.setPriceCircularItemModel(priceCircularItemModel);
959
                        ffdr.setFeature(doc.getString("feature_s"));
960
				}
960
                    } catch (Exception e) {
961
				dealResponse.add(fofoCatalogResponse);
961
                        ffdr.setFeature(null);
962
			}
962
                        logger.info("Could not find Feature_s for {}", ffdr.getCatalogId());
963
		}
963
                    }
964
		return dealResponse;
964
                    ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
965
 
965
                    ffdr.setItems(Arrays.asList(fofoAvailabilityInfo));
966
	}
966
                    dealResponse.add(ffdr);
967
 
967
                }
968
	private List<FofoCatalogResponse> getCatalogSingleSkuResponse(JSONArray docs, Map<Integer, Integer> itemFilter,
968
            }
969
			boolean hotDeal) throws ProfitMandiBusinessException {
969
        }
970
		Map<Integer, TagListing> itemTagListingMap = null;
970
        return dealResponse;
971
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
971
 
972
		List<Integer> tagIds = Arrays.asList(4);
972
    }
973
 
973
 
974
		itemTagListingMap = tagListingRepository.selectByItemIdsAndTagIds(itemFilter.keySet(), new HashSet<>(tagIds))
974
    @RequestMapping(value = "/combo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
975
				.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x));
975
    public ResponseEntity<?> getBanners(@RequestParam int catalogId, @RequestParam int warehouseId) {
976
 
976
        List<ComboModel> comboModels = comboModelRepository.selectByCatalogIdAndWarehouseId(catalogId, warehouseId);
977
		for (int i = 0; i < docs.length(); i++) {
977
        return responseSender.ok(comboModels);
978
			Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
978
    }
979
			JSONObject doc = docs.getJSONObject(i);
-
 
980
 
-
 
981
			for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
-
 
982
				JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
-
 
983
				int itemId = childItem.getInt("itemId_i");
-
 
984
				TagListing tl = itemTagListingMap.get(itemId);
-
 
985
				if (tl == null) {
-
 
986
					continue;
-
 
987
				}
-
 
988
				if (hotDeal) {
-
 
989
					if (!tl.isHotDeals()) {
-
 
990
						continue;
-
 
991
					}
-
 
992
				}
-
 
993
				float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
-
 
994
				if (fofoAvailabilityInfoMap.containsKey(itemId)) {
-
 
995
					if (fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
-
 
996
						fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
-
 
997
						fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
-
 
998
					}
-
 
999
				} else {
-
 
1000
					FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
-
 
1001
					fdi.setSellingPrice((float) childItem.getDouble("sellingPrice_f"));
-
 
1002
					fdi.setMop((float) childItem.getDouble("mop_f"));
-
 
1003
					fdi.setMop((float) tl.getMrp());
-
 
1004
					fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
-
 
1005
					fdi.setTagId(childItem.getInt("tagId_i"));
-
 
1006
					fdi.setItem_id(itemId);
-
 
1007
					Item item = itemRepository.selectById(itemId);
-
 
1008
					// In case its tampered glass moq should be 5
-
 
1009
					if (item.getCategoryId() == 10020) {
-
 
1010
						fdi.setMinBuyQuantity(10);
-
 
1011
					} else {
-
 
1012
						fdi.setMinBuyQuantity(1);
-
 
1013
					}
-
 
1014
					fdi.setAvailability(itemFilter.get(itemId));
-
 
1015
					fdi.setQuantityStep(1);
-
 
1016
					fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
-
 
1017
					fofoAvailabilityInfoMap.put(itemId, fdi);
-
 
1018
				}
-
 
1019
			}
-
 
1020
			if (fofoAvailabilityInfoMap.values().size() > 0) {
-
 
1021
				for (FofoAvailabilityInfo fofoAvailabilityInfo : fofoAvailabilityInfoMap.values()) {
-
 
1022
					FofoCatalogResponse ffdr = new FofoCatalogResponse();
-
 
1023
					ffdr.setCatalogId(doc.getInt("catalogId_i"));
-
 
1024
					ffdr.setImageUrl(doc.getString("imageUrl_s"));
-
 
1025
					ffdr.setTitle(doc.getString("title_s"));
-
 
1026
					try {
-
 
1027
						ffdr.setFeature(doc.getString("feature_s"));
-
 
1028
					} catch (Exception e) {
-
 
1029
						ffdr.setFeature(null);
-
 
1030
						logger.info("Could not find Feature_s for {}", ffdr.getCatalogId());
-
 
1031
					}
-
 
1032
					ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
-
 
1033
					ffdr.setItems(Arrays.asList(fofoAvailabilityInfo));
-
 
1034
					dealResponse.add(ffdr);
-
 
1035
				}
-
 
1036
			}
-
 
1037
		}
-
 
1038
		return dealResponse;
-
 
1039
 
-
 
1040
	}
-
 
1041
 
-
 
1042
	@RequestMapping(value = "/combo", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
-
 
1043
	public ResponseEntity<?> getBanners(@RequestParam int catalogId, @RequestParam int warehouseId) {
-
 
1044
		List<ComboModel> comboModels = comboModelRepository.selectByCatalogIdAndWarehouseId(catalogId, warehouseId);
-
 
1045
		return responseSender.ok(comboModels);
-
 
1046
	}
-
 
1047
}
979
}
1048
980