Subversion Repositories SmartDukaan

Rev

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

Rev 36451 Rev 36521
Line 148... Line 148...
148
 
148
 
149
    @Override
149
    @Override
150
    public void evictOfferCaches(int offerId) {
150
    public void evictOfferCaches(int offerId) {
151
        Offer offer = offerRepository.selectById(offerId);
151
        Offer offer = offerRepository.selectById(offerId);
152
        YearMonth ym = YearMonth.from(offer.getStartDate());
152
        YearMonth ym = YearMonth.from(offer.getStartDate());
-
 
153
        redisCacheManager.getCache("monthOfferIds").evict(ym);
153
        redisCacheManager.getCache("offer.definition").evict(offerId);
154
        redisCacheManager.getCache("offer.definition").evict(offerId);
154
        redisCacheManager.getCache("allOffers").evict(ym);
-
 
155
        redisCacheManager.getCache("catalog.published_yearmonth").evict(ym);
155
        redisCacheManager.getCache("catalog.published_yearmonth").evict(ym);
156
        redisCacheManager.getCache("offer.slabpayout").evict(offerId);
156
        redisCacheManager.getCache("offer.slabpayout").evict(offerId);
157
        redisCacheManager.getCache("offer.achievement").clear();
157
        redisCacheManager.getCache("offer.achievement").clear();
158
        redisShortCacheManager.getCache("todayOffers").clear();
158
        redisShortCacheManager.getCache("todayOffers").clear();
159
    }
159
    }
160
 
160
 
161
    @Override
161
    @Override
-
 
162
    public void evictOfferDefinitionCache(int offerId) {
-
 
163
        redisCacheManager.getCache("offer.definition").evict(offerId);
-
 
164
    }
-
 
165
 
-
 
166
    @Override
162
    public void addOfferService(CreateOfferRequest createOfferRequest) throws ProfitMandiBusinessException {
167
    public void addOfferService(CreateOfferRequest createOfferRequest) throws ProfitMandiBusinessException {
163
        LOGGER.info("createOfferRequest  -- {}", createOfferRequest);
168
        LOGGER.info("createOfferRequest  -- {}", createOfferRequest);
164
        this.createOffer(createOfferRequest);
169
        this.createOffer(createOfferRequest);
165
        this.createTargetSlabs(createOfferRequest);
170
        this.createTargetSlabs(createOfferRequest);
166
    }
171
    }
Line 264... Line 269...
264
            }
269
            }
265
        }
270
        }
266
    }
271
    }
267
 
272
 
268
    @Override
273
    @Override
269
    @Cacheable(value = "allOffers", cacheManager = "redisCacheManager")
274
    @Cacheable(value = "monthOfferIds", cacheManager = "redisCacheManager")
270
    public Map<Integer, CreateOfferRequest> getAllOffers(YearMonth yearMonth) throws ProfitMandiBusinessException {
275
    public Set<Integer> getMonthOfferIds(YearMonth yearMonth) throws ProfitMandiBusinessException {
271
        List<Offer> allOffers = offerRepository.selectAll(yearMonth, false);
276
        List<Offer> allOffers = offerRepository.selectAll(yearMonth, false);
272
        List<CreateOfferRequest> createOfferRequests = new ArrayList<>();
277
        return allOffers.stream().map(Offer::getId).collect(Collectors.toSet());
-
 
278
    }
-
 
279
 
-
 
280
    @Override
-
 
281
    public Map<Integer, CreateOfferRequest> getAllOffers(YearMonth yearMonth) throws ProfitMandiBusinessException {
273
        for (Offer offer : allOffers) {
282
        Set<Integer> ids = offerServiceProxy.getMonthOfferIds(yearMonth);
274
            CreateOfferRequest createOfferRequest = this.getCreateOfferRequest(offer);
283
        Map<Integer, CreateOfferRequest> result = new HashMap<>();
-
 
284
        for (Integer id : ids) {
275
            createOfferRequests.add(createOfferRequest);
285
            result.put(id, offerServiceProxy.getOfferDefinition(id));
276
        }
286
        }
277
        return createOfferRequests.stream().collect(Collectors.toMap(CreateOfferRequest::getId, x -> x));
287
        return result;
278
    }
288
    }
279
 
289
 
280
    private CreateOfferRequest deepCopy(CreateOfferRequest source) {
290
    private CreateOfferRequest deepCopy(CreateOfferRequest source) {
281
        return gson.fromJson(gson.toJson(source), CreateOfferRequest.class);
291
        return gson.fromJson(gson.toJson(source), CreateOfferRequest.class);
282
    }
292
    }
Line 523... Line 533...
523
                this.addOfferService(createOfferRequest);
533
                this.addOfferService(createOfferRequest);
524
            }
534
            }
525
            ymListToEvict.add(YearMonth.from(createOfferRequest.getStartDate()));
535
            ymListToEvict.add(YearMonth.from(createOfferRequest.getStartDate()));
526
        }
536
        }
527
        for (YearMonth ymToEvict : ymListToEvict) {
537
        for (YearMonth ymToEvict : ymListToEvict) {
528
            redisCacheManager.getCache("allOffers").evict(ymToEvict);
538
            redisCacheManager.getCache("monthOfferIds").evict(ymToEvict);
529
        }
539
        }
530
    }
540
    }
531
 
541
 
532
    private Map<CreateOfferRequest, List<PartnerTargetModel>> parseFromExcel(InputStream inputStream)
542
    private Map<CreateOfferRequest, List<PartnerTargetModel>> parseFromExcel(InputStream inputStream)
533
            throws ProfitMandiBusinessException {
543
            throws ProfitMandiBusinessException {
Line 1936... Line 1946...
1936
            throw new ProfitMandiBusinessException("Offer not found", "Offer not found", "");
1946
            throw new ProfitMandiBusinessException("Offer not found", "Offer not found", "");
1937
        }
1947
        }
1938
        if (offer.isActive()) {
1948
        if (offer.isActive()) {
1939
            throw new ProfitMandiBusinessException("Cannot delete a published offer", "Cannot delete a published offer", "");
1949
            throw new ProfitMandiBusinessException("Cannot delete a published offer", "Cannot delete a published offer", "");
1940
        }
1950
        }
-
 
1951
        this.evictOfferCaches(offerId);
1941
        List<TargetSlabEntity> targetSlabs = offerTargetSlabRepository.selectByOfferIds(Collections.singletonList(offerId));
1952
        List<TargetSlabEntity> targetSlabs = offerTargetSlabRepository.selectByOfferIds(Collections.singletonList(offerId));
1942
        for (TargetSlabEntity targetSlab : targetSlabs) {
1953
        for (TargetSlabEntity targetSlab : targetSlabs) {
1943
            genericRepository.delete(targetSlab);
1954
            genericRepository.delete(targetSlab);
1944
        }
1955
        }
1945
        genericRepository.delete(offer);
1956
        genericRepository.delete(offer);