| Line 7... |
Line 7... |
| 7 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
7 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 8 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
8 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 9 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
9 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
| 10 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
10 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 11 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
11 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 12 |
import com.spice.profitmandi.dao.entity.catalog.Catalog;
|
- |
|
| 13 |
import com.spice.profitmandi.dao.entity.catalog.Offer;
|
12 |
import com.spice.profitmandi.dao.entity.catalog.Offer;
|
| 14 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
13 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
| 15 |
import com.spice.profitmandi.dao.enumuration.catalog.ItemCriteriaType;
|
14 |
import com.spice.profitmandi.dao.enumuration.catalog.ItemCriteriaType;
|
| 16 |
import com.spice.profitmandi.dao.enumuration.catalog.OfferSchemeType;
|
15 |
import com.spice.profitmandi.dao.enumuration.catalog.OfferSchemeType;
|
| 17 |
import com.spice.profitmandi.dao.model.CreateOfferRequest;
|
16 |
import com.spice.profitmandi.dao.model.CreateOfferRequest;
|
| Line 227... |
Line 226... |
| 227 |
return;
|
226 |
return;
|
| 228 |
}
|
227 |
}
|
| 229 |
String fileName = "offer-" + offer.getId() + ".png";
|
228 |
String fileName = "offer-" + offer.getId() + ".png";
|
| 230 |
//String htmlFileName = fileName.replace("png", "html");
|
229 |
//String htmlFileName = fileName.replace("png", "html");
|
| 231 |
CreateOfferRequest createOfferRequest = offerService.getCreateOfferRequest(offer);
|
230 |
CreateOfferRequest createOfferRequest = offerService.getCreateOfferRequest(offer);
|
| 232 |
List<Integer> catalogIds = createOfferRequest.getItemCriteria().getCatalogIds();
|
231 |
boolean isLiveDemo = createOfferRequest.getTargetSlabs().stream()
|
| - |
|
232 |
.map(x -> x.getItemCriteriaPayouts())
|
| 233 |
if (catalogIds.size() > 0) {
|
233 |
.flatMap(List::stream)
|
| - |
|
234 |
.map(ItemCriteriaPayout::getItemCriteria)
|
| 234 |
Catalog catalog = catalogRepository.selectCatalogById(catalogIds.get(0));
|
235 |
.map(ItemCriteria::getCatalogIds)
|
| - |
|
236 |
.flatMap(List::stream)
|
| 235 |
if (catalog.getBrand().equals("Live Demo")) return;
|
237 |
.anyMatch(catalogId -> catalogRepository.selectCatalogById(catalogId).getBrand().equals("Live Demo"));
|
| 236 |
}
|
238 |
if (!isLiveDemo) {
|
| 237 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
239 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
| 238 |
sendNotificationModel.setCampaignName("SchemeOffer");
|
240 |
sendNotificationModel.setCampaignName("SchemeOffer");
|
| 239 |
sendNotificationModel.setTitle(offer.getName());
|
241 |
sendNotificationModel.setTitle(offer.getName());
|
| 240 |
sendNotificationModel.setMessage(createOfferRequest.getSchemeType().name() + " of select models, "
|
242 |
sendNotificationModel.setMessage(createOfferRequest.getSchemeType().name() + " of select models, "
|
| 241 |
+ FormattingUtils.formatDateMonth(offer.getStartDate()) + " to "
|
243 |
+ FormattingUtils.formatDateMonth(offer.getStartDate()) + " to "
|
| 242 |
+ FormattingUtils.formatDateMonth(offer.getEndDate()));
|
244 |
+ FormattingUtils.formatDateMonth(offer.getEndDate()));
|
| 243 |
sendNotificationModel.setType("url");
|
245 |
sendNotificationModel.setType("url");
|
| 244 |
String imageUrl = IMAGE_STATIC_SERVER_URL + "/" + "image" + LocalDate.now() + "/" + fileName;
|
246 |
String imageUrl = IMAGE_STATIC_SERVER_URL + "/" + "image" + LocalDate.now() + "/" + fileName;
|
| 245 |
sendNotificationModel.setImageUrl(imageUrl);
|
247 |
sendNotificationModel.setImageUrl(imageUrl);
|
| 246 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
248 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
| 247 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
249 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
| 248 |
sendNotificationModel.setMessageType(MessageType.scheme);
|
250 |
sendNotificationModel.setMessageType(MessageType.scheme);
|
| 249 |
//Map<Integer, List<Offer>> offersMap = offerRepository.selectAllPublishedMapByPartner(YearMonth.now());
|
251 |
//Map<Integer, List<Offer>> offersMap = offerRepository.selectAllPublishedMapByPartner(YearMonth.now());
|
| 250 |
|
252 |
|
| 251 |
Map<String, InputStream> fileStreamsMap = new HashMap<>();
|
253 |
Map<String, InputStream> fileStreamsMap = new HashMap<>();
|
| 252 |
Map<String, Object> model = new HashMap<>();
|
254 |
Map<String, Object> model = new HashMap<>();
|
| 253 |
model.put("offer", createOfferRequest);
|
255 |
model.put("offer", createOfferRequest);
|
| 254 |
String htmlContent = this.getContentFromTemplate("offer_margin_detail_notify", model);
|
256 |
String htmlContent = this.getContentFromTemplate("offer_margin_detail_notify", model);
|
| 255 |
LOGGER.info("this.getContentFromTemplate {}", htmlContent);
|
257 |
LOGGER.info("this.getContentFromTemplate {}", htmlContent);
|
| 256 |
fileStreamsMap.put(fileName, this.getImageBuffer(htmlContent));
|
258 |
fileStreamsMap.put(fileName, this.getImageBuffer(htmlContent));
|
| 257 |
// fileStreamsMap.put(htmlFileName, new
|
259 |
// fileStreamsMap.put(htmlFileName, new
|
| 258 |
// ByteArrayInputStream(htmlContent.getBytes()));
|
260 |
// ByteArrayInputStream(htmlContent.getBytes()));
|
| 259 |
List<Integer> fofoIds = null;
|
261 |
List<Integer> fofoIds = null;
|
| 260 |
if (isProd) {
|
262 |
if (isProd) {
|
| 261 |
this.uploadFile(fileStreamsMap);
|
263 |
this.uploadFile(fileStreamsMap);
|
| 262 |
}
|
264 |
}
|
| 263 |
|
- |
|
| 264 |
List<Integer> fofoIdSet = new ArrayList<>(offerRepository.getEligibleFofoIds(offer));
|
- |
|
| 265 |
//LOGGER.info(fofoIdSet);
|
- |
|
| 266 |
List<Integer> userIds = userAccountRepository.selectUserIdsByRetailerIds(new ArrayList<>(fofoIdSet));
|
- |
|
| 267 |
sendNotificationModel.setUserIds(userIds);
|
- |
|
| 268 |
notificationService.sendNotification(sendNotificationModel);
|
- |
|
| 269 |
sendWhatsapp(offer, fofoIds, imageUrl);
|
- |
|
| 270 |
|
265 |
|
| - |
|
266 |
List<Integer> fofoIdSet = new ArrayList<>(offerRepository.getEligibleFofoIds(offer));
|
| - |
|
267 |
//LOGGER.info(fofoIdSet);
|
| - |
|
268 |
List<Integer> userIds = userAccountRepository.selectUserIdsByRetailerIds(new ArrayList<>(fofoIdSet));
|
| - |
|
269 |
sendNotificationModel.setUserIds(userIds);
|
| - |
|
270 |
notificationService.sendNotification(sendNotificationModel);
|
| - |
|
271 |
sendWhatsapp(offer, fofoIds, imageUrl);
|
| - |
|
272 |
}
|
| 271 |
}
|
273 |
}
|
| 272 |
|
274 |
|
| 273 |
private void sendWhatsapp(Offer offer, List<Integer> fofoIds, String imageUrl) throws Exception {
|
275 |
private void sendWhatsapp(Offer offer, List<Integer> fofoIds, String imageUrl) throws Exception {
|
| 274 |
if (fofoIds == null) {
|
276 |
if (fofoIds == null) {
|
| 275 |
fofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId()).collect(Collectors.toList());
|
277 |
fofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId()).collect(Collectors.toList());
|