| 27391 |
tejbeer |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import com.google.gson.Gson;
|
| 29943 |
amit.gupta |
4 |
import com.jcraft.jsch.*;
|
| 29900 |
amit.gupta |
5 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
| 27391 |
tejbeer |
6 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
7 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 27876 |
amit.gupta |
8 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 29900 |
amit.gupta |
9 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
| 27876 |
amit.gupta |
10 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 29904 |
amit.gupta |
11 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 27876 |
amit.gupta |
12 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 27391 |
tejbeer |
13 |
import com.spice.profitmandi.dao.entity.catalog.Offer;
|
|
|
14 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
|
|
15 |
import com.spice.profitmandi.dao.enumuration.catalog.ItemCriteriaType;
|
|
|
16 |
import com.spice.profitmandi.dao.model.CreateOfferRequest;
|
| 27876 |
amit.gupta |
17 |
import com.spice.profitmandi.dao.model.OfferRowModel;
|
| 27391 |
tejbeer |
18 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
|
|
19 |
import com.spice.profitmandi.dao.repository.catalog.OfferMarginRepository;
|
|
|
20 |
import com.spice.profitmandi.dao.repository.catalog.OfferPartnerRepository;
|
|
|
21 |
import com.spice.profitmandi.dao.repository.catalog.OfferRepository;
|
|
|
22 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
|
|
23 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 29926 |
amit.gupta |
24 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 27391 |
tejbeer |
25 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
|
| 29900 |
amit.gupta |
26 |
import com.spice.profitmandi.service.NotificationService;
|
| 29785 |
amit.gupta |
27 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 27876 |
amit.gupta |
28 |
import com.spice.profitmandi.service.offers.OfferService;
|
| 27391 |
tejbeer |
29 |
import com.spice.profitmandi.service.user.RetailerService;
|
|
|
30 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
31 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
32 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 29943 |
amit.gupta |
33 |
import org.apache.commons.io.FileUtils;
|
|
|
34 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
|
|
35 |
import org.apache.logging.log4j.LogManager;
|
|
|
36 |
import org.apache.logging.log4j.Logger;
|
|
|
37 |
import org.apache.velocity.app.VelocityEngine;
|
|
|
38 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
39 |
import org.springframework.cache.CacheManager;
|
|
|
40 |
import org.springframework.core.io.InputStreamResource;
|
|
|
41 |
import org.springframework.http.HttpHeaders;
|
|
|
42 |
import org.springframework.http.HttpStatus;
|
|
|
43 |
import org.springframework.http.ResponseEntity;
|
|
|
44 |
import org.springframework.stereotype.Controller;
|
|
|
45 |
import org.springframework.ui.Model;
|
|
|
46 |
import org.springframework.ui.velocity.VelocityEngineUtils;
|
|
|
47 |
import org.springframework.web.bind.annotation.*;
|
|
|
48 |
import org.springframework.web.multipart.MultipartFile;
|
|
|
49 |
import org.xhtmlrenderer.swing.Java2DRenderer;
|
| 27391 |
tejbeer |
50 |
|
| 29943 |
amit.gupta |
51 |
import javax.imageio.ImageIO;
|
|
|
52 |
import javax.servlet.http.HttpServletRequest;
|
|
|
53 |
import javax.transaction.Transactional;
|
|
|
54 |
import java.awt.*;
|
|
|
55 |
import java.awt.image.BufferedImage;
|
|
|
56 |
import java.io.ByteArrayInputStream;
|
|
|
57 |
import java.io.File;
|
|
|
58 |
import java.io.FileNotFoundException;
|
|
|
59 |
import java.io.InputStream;
|
|
|
60 |
import java.time.Instant;
|
|
|
61 |
import java.time.LocalDate;
|
|
|
62 |
import java.time.LocalDateTime;
|
|
|
63 |
import java.time.YearMonth;
|
|
|
64 |
import java.util.List;
|
|
|
65 |
import java.util.*;
|
|
|
66 |
import java.util.stream.Collectors;
|
|
|
67 |
|
| 27391 |
tejbeer |
68 |
@Controller
|
|
|
69 |
@Transactional(rollbackOn = Throwable.class)
|
|
|
70 |
public class OfferController {
|
|
|
71 |
private static final Logger LOGGER = LogManager.getLogger(OfferController.class);
|
|
|
72 |
@Autowired
|
|
|
73 |
private OfferRepository offerRepository;
|
|
|
74 |
|
|
|
75 |
@Autowired
|
|
|
76 |
private OfferMarginRepository offerMarginRepository;
|
|
|
77 |
|
|
|
78 |
@Autowired
|
|
|
79 |
private FofoStoreRepository fofoStoreRepository;
|
|
|
80 |
|
|
|
81 |
@Autowired
|
| 27876 |
amit.gupta |
82 |
private ResponseSender responseSender;
|
|
|
83 |
|
|
|
84 |
@Autowired
|
| 27391 |
tejbeer |
85 |
private OfferPartnerRepository offerPartnerRepository;
|
|
|
86 |
|
| 29900 |
amit.gupta |
87 |
private static final String IMAGE_REMOTE_DIR = "/var/www/dtrdashboard/uploads/campaigns/";
|
|
|
88 |
private static final String IMAGE_STATIC_SERVER_URL = "https://images.smartdukaan.com/uploads/campaigns";
|
| 29926 |
amit.gupta |
89 |
|
| 27391 |
tejbeer |
90 |
@Autowired
|
|
|
91 |
private ItemRepository itemRepository;
|
|
|
92 |
|
|
|
93 |
@Autowired
|
|
|
94 |
private MVCResponseSender mvcResponseSender;
|
|
|
95 |
|
|
|
96 |
@Autowired
|
|
|
97 |
private Gson gson;
|
|
|
98 |
|
|
|
99 |
@Autowired
|
|
|
100 |
private RetailerService retailerService;
|
|
|
101 |
|
|
|
102 |
@Autowired
|
|
|
103 |
private Mongo mongoClient;
|
|
|
104 |
|
|
|
105 |
@Autowired
|
| 29900 |
amit.gupta |
106 |
private NotificationService notificationService;
|
|
|
107 |
|
|
|
108 |
@Autowired
|
| 27391 |
tejbeer |
109 |
private CookiesProcessor cookiesProcessor;
|
|
|
110 |
|
|
|
111 |
@Autowired
|
| 27876 |
amit.gupta |
112 |
private OfferService offerService;
|
| 29900 |
amit.gupta |
113 |
|
| 29809 |
amit.gupta |
114 |
@Autowired
|
|
|
115 |
private CacheManager thirtyMinsTimeOutCacheManager;
|
| 29900 |
amit.gupta |
116 |
|
| 29855 |
amit.gupta |
117 |
@Autowired
|
|
|
118 |
private CacheManager oneDayCacheManager;
|
| 27876 |
amit.gupta |
119 |
|
|
|
120 |
@Autowired
|
| 27391 |
tejbeer |
121 |
private PartnerTypeChangeService partnerTypeChangeService;
|
|
|
122 |
|
|
|
123 |
@RequestMapping(value = "/getCreateOffer", method = RequestMethod.GET)
|
|
|
124 |
public String getCreateOffer(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
|
|
125 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
126 |
List<Integer> fofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId())
|
|
|
127 |
.collect(Collectors.toList());
|
|
|
128 |
|
| 27876 |
amit.gupta |
129 |
Set<String> brands = mongoClient.getMongoBrands(loginDetails.getFofoId(), null, 3).stream()
|
|
|
130 |
.map(x -> (String) x.get("name")).collect(Collectors.toSet());
|
| 27391 |
tejbeer |
131 |
|
| 30426 |
tejbeer |
132 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
| 27391 |
tejbeer |
133 |
|
| 30426 |
tejbeer |
134 |
Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> customRetailerMap.get(x))
|
|
|
135 |
.filter(x -> x != null).collect(Collectors.toList()).stream()
|
|
|
136 |
.collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
137 |
|
| 27391 |
tejbeer |
138 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
|
|
139 |
model.addAttribute("itemCriteriaType", ItemCriteriaType.values());
|
|
|
140 |
model.addAttribute("brands", brands);
|
|
|
141 |
model.addAttribute("partnerCategories", PartnerType.values());
|
| 27876 |
amit.gupta |
142 |
model.addAttribute("warehouseRegion", ProfitMandiConstants.WAREHOUSE_MAP);
|
| 27391 |
tejbeer |
143 |
return "scheme_offer";
|
|
|
144 |
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
@RequestMapping(value = "/createOffer", method = RequestMethod.POST)
|
|
|
148 |
public String createOffer(HttpServletRequest request, @RequestBody CreateOfferRequest createOfferRequest,
|
| 30426 |
tejbeer |
149 |
Model model) throws Exception {
|
| 27876 |
amit.gupta |
150 |
LOGGER.info("createOfferRequest [{}]", createOfferRequest);
|
|
|
151 |
offerService.addOfferService(createOfferRequest);
|
| 29809 |
amit.gupta |
152 |
thirtyMinsTimeOutCacheManager.getCache("allOffers").evict(YearMonth.now());
|
| 27391 |
tejbeer |
153 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
154 |
return "response";
|
|
|
155 |
|
|
|
156 |
}
|
|
|
157 |
|
| 27876 |
amit.gupta |
158 |
@RequestMapping(value = "/offers/published", method = RequestMethod.GET)
|
|
|
159 |
public String getPublishedOffers(HttpServletRequest request, @RequestParam int fofoId, Model model)
|
| 27391 |
tejbeer |
160 |
throws Exception {
|
| 27876 |
amit.gupta |
161 |
LOGGER.info("Published");
|
|
|
162 |
offerService.getPublishedOffers(fofoId, YearMonth.from(LocalDateTime.now()));
|
|
|
163 |
return "scheme_offer/published";
|
| 27391 |
tejbeer |
164 |
|
| 27876 |
amit.gupta |
165 |
}
|
| 27391 |
tejbeer |
166 |
|
| 27876 |
amit.gupta |
167 |
@RequestMapping(value = "/offer/active/{offerId}", method = RequestMethod.GET)
|
| 30426 |
tejbeer |
168 |
public String activateOffer(HttpServletRequest request, @PathVariable(name = "offerId") String offerIdsString,
|
|
|
169 |
Model model, @RequestParam(defaultValue = "true") boolean active)
|
|
|
170 |
throws ProfitMandiBusinessException, Exception {
|
|
|
171 |
List<Integer> offerIds = Arrays.stream(offerIdsString.split(",")).map(x -> Integer.parseInt(x))
|
|
|
172 |
.collect(Collectors.toList());
|
| 29943 |
amit.gupta |
173 |
List<Offer> offers = offerRepository.selectAllByIds(offerIds);
|
|
|
174 |
boolean shouldEvict = false;
|
|
|
175 |
for (Offer offer : offers) {
|
| 29949 |
amit.gupta |
176 |
offer.setAlreadyActive(offer.isActive());
|
|
|
177 |
if (offer.isActive() != active) {
|
| 29943 |
amit.gupta |
178 |
offer.setActive(active);
|
|
|
179 |
shouldEvict = true;
|
|
|
180 |
}
|
|
|
181 |
}
|
|
|
182 |
if (shouldEvict) {
|
| 29900 |
amit.gupta |
183 |
oneDayCacheManager.getCache("catalog.published_yearmonth").evict(YearMonth.now());
|
|
|
184 |
}
|
| 29949 |
amit.gupta |
185 |
for (Offer offer : offers) {
|
|
|
186 |
if (active && !offer.isAlreadyActive()) {
|
|
|
187 |
this.sendNotification(offer);
|
|
|
188 |
}
|
|
|
189 |
}
|
| 27876 |
amit.gupta |
190 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
191 |
return "response";
|
| 29926 |
amit.gupta |
192 |
// CreateOfferRequest createOfferRequest =
|
|
|
193 |
// offerService.getCreateOfferRequest(offer);
|
|
|
194 |
// model.addAttribute("offer", createOfferRequest);
|
|
|
195 |
// return "offer_margin_detail_partner2";
|
| 27876 |
amit.gupta |
196 |
}
|
| 29926 |
amit.gupta |
197 |
|
| 29920 |
amit.gupta |
198 |
@RequestMapping(value = "/offer/testimage/{offerId}", method = RequestMethod.GET)
|
| 29926 |
amit.gupta |
199 |
public String testOffer(HttpServletRequest request, @PathVariable int offerId, Model model,
|
| 30426 |
tejbeer |
200 |
@RequestParam(defaultValue = "true") boolean active) throws ProfitMandiBusinessException, Exception {
|
| 29920 |
amit.gupta |
201 |
Offer offer = offerRepository.selectById(offerId);
|
| 29926 |
amit.gupta |
202 |
// model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
203 |
// return "response";
|
| 29920 |
amit.gupta |
204 |
CreateOfferRequest createOfferRequest = offerService.getCreateOfferRequest(offer);
|
|
|
205 |
model.addAttribute("offer", createOfferRequest);
|
|
|
206 |
return "offer_margin_detail_partner2";
|
|
|
207 |
}
|
| 27391 |
tejbeer |
208 |
|
| 29900 |
amit.gupta |
209 |
@Autowired
|
|
|
210 |
private com.spice.profitmandi.dao.repository.dtr.UserRepository dtrUserRepository;
|
|
|
211 |
|
| 29917 |
amit.gupta |
212 |
@RequestMapping(value = "/offer/active/fofo/{fofoId}", method = RequestMethod.GET)
|
| 29926 |
amit.gupta |
213 |
public String sendOfferNotification(HttpServletRequest request, @PathVariable int fofoId, Model model,
|
| 30426 |
tejbeer |
214 |
@RequestParam(defaultValue = "true") boolean active) throws ProfitMandiBusinessException, Exception {
|
| 29917 |
amit.gupta |
215 |
List<Offer> offers = offerRepository.selectAllPublishedMapByPartner(YearMonth.now()).get(fofoId);
|
| 29926 |
amit.gupta |
216 |
for (Offer offer : offers) {
|
| 29917 |
amit.gupta |
217 |
this.sendNotification(offer);
|
|
|
218 |
}
|
|
|
219 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
220 |
return "response";
|
|
|
221 |
}
|
| 29926 |
amit.gupta |
222 |
|
|
|
223 |
@Autowired
|
|
|
224 |
UserAccountRepository userAccountRepository;
|
|
|
225 |
|
| 29900 |
amit.gupta |
226 |
private void sendNotification(Offer offer) throws Exception {
|
|
|
227 |
String fileName = "offer-" + offer.getId() + ".png";
|
| 29948 |
amit.gupta |
228 |
String htmlFileName = fileName.replace("png", "html");
|
| 29900 |
amit.gupta |
229 |
CreateOfferRequest createOfferRequest = offerService.getCreateOfferRequest(offer);
|
|
|
230 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
231 |
sendNotificationModel.setCampaignName("SchemeOffer");
|
|
|
232 |
sendNotificationModel.setTitle(offer.getName());
|
| 29926 |
amit.gupta |
233 |
sendNotificationModel.setMessage(createOfferRequest.getSchemeType().name() + " of select models, "
|
|
|
234 |
+ FormattingUtils.formatDateMonth(offer.getStartDate()) + " to "
|
|
|
235 |
+ FormattingUtils.formatDateMonth(offer.getEndDate()));
|
| 29900 |
amit.gupta |
236 |
sendNotificationModel.setType("url");
|
|
|
237 |
sendNotificationModel.setImageUrl(IMAGE_STATIC_SERVER_URL + "/" + "image" + LocalDate.now() + "/" + fileName);
|
|
|
238 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
|
|
239 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
|
|
240 |
sendNotificationModel.setMessageType(MessageType.scheme);
|
|
|
241 |
Map<Integer, List<Offer>> offersMap = offerRepository.selectAllPublishedMapByPartner(YearMonth.now());
|
| 30017 |
amit.gupta |
242 |
|
| 29900 |
amit.gupta |
243 |
Map<String, InputStream> fileStreamsMap = new HashMap<>();
|
| 29926 |
amit.gupta |
244 |
Map<String, Object> model = new HashMap<>();
|
|
|
245 |
model.put("offer", createOfferRequest);
|
|
|
246 |
String htmlContent = this.getContentFromTemplate("offer_margin_detail_partner.vm", model);
|
|
|
247 |
LOGGER.info("this.getContentFromTemplate {}", htmlContent);
|
|
|
248 |
fileStreamsMap.put(fileName, this.getImageBuffer(htmlContent));
|
| 30426 |
tejbeer |
249 |
// fileStreamsMap.put(htmlFileName, new
|
|
|
250 |
// ByteArrayInputStream(htmlContent.getBytes()));
|
| 29926 |
amit.gupta |
251 |
|
|
|
252 |
this.uploadFile(fileStreamsMap);
|
| 30017 |
amit.gupta |
253 |
if (createOfferRequest.getPartnerCriteria().getRegionIds().size() > 0
|
|
|
254 |
|| createOfferRequest.getPartnerCriteria().getFofoIds().size() > 0
|
|
|
255 |
|| createOfferRequest.getPartnerCriteria().getRegionIds().size() > 0) {
|
|
|
256 |
List<Integer> fofoIds = offersMap.entrySet().stream().filter(x -> x.getValue().contains(offer))
|
|
|
257 |
.map(x -> x.getKey()).collect(Collectors.toList());
|
|
|
258 |
List<Integer> userIds = userAccountRepository.selectUserIdsByRetailerIds(fofoIds);
|
|
|
259 |
sendNotificationModel.setUserIds(userIds);
|
| 30426 |
tejbeer |
260 |
/*
|
|
|
261 |
* if(createOfferRequest.getPartnerCriteria().getRegionIds().size() > 0) {
|
|
|
262 |
* List<Integer> regionIds =
|
|
|
263 |
* createOfferRequest.getPartnerCriteria().getRegionIds(); }
|
|
|
264 |
*/
|
| 30017 |
amit.gupta |
265 |
notificationService.sendNotification(sendNotificationModel);
|
|
|
266 |
} else {
|
|
|
267 |
notificationService.sendNotificationToAll(sendNotificationModel);
|
|
|
268 |
}
|
| 29900 |
amit.gupta |
269 |
|
|
|
270 |
}
|
| 29926 |
amit.gupta |
271 |
|
|
|
272 |
private InputStream asInputStream(BufferedImage bi) throws Exception {
|
| 29900 |
amit.gupta |
273 |
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
274 |
ImageIO.write(bi, "png", baos);
|
|
|
275 |
return new ByteArrayInputStream(baos.toByteArray());
|
| 29926 |
amit.gupta |
276 |
|
| 29900 |
amit.gupta |
277 |
}
|
|
|
278 |
|
|
|
279 |
private ChannelSftp setupJsch() throws JSchException {
|
|
|
280 |
JSch jsch = new JSch();
|
|
|
281 |
Session jschSession = jsch.getSession("root", "192.168.179.131");
|
| 29926 |
amit.gupta |
282 |
// Session jschSession = jsch.getSession("root", "173.255.254.24");
|
|
|
283 |
LOGGER.info("getClass().getResource(\"id_rsa\") {}",
|
|
|
284 |
getClass().getClassLoader().getResource("id_rsa").getPath());
|
| 29900 |
amit.gupta |
285 |
jsch.addIdentity(getClass().getClassLoader().getResource("id_rsa").getPath());
|
| 29926 |
amit.gupta |
286 |
// jschSession.setPassword("spic@2015static0");
|
| 29900 |
amit.gupta |
287 |
jschSession.setConfig("StrictHostKeyChecking", "no");
|
|
|
288 |
jschSession.connect();
|
|
|
289 |
return (ChannelSftp) jschSession.openChannel("sftp");
|
|
|
290 |
}
|
|
|
291 |
|
|
|
292 |
private void fileUpload(ChannelSftp channelSftp, Map<String, InputStream> streamsFileMap, String destinationPath)
|
|
|
293 |
throws SftpException, FileNotFoundException {
|
|
|
294 |
|
|
|
295 |
channelSftp.cd(destinationPath);
|
|
|
296 |
String folderName = "image" + LocalDate.now();
|
|
|
297 |
|
|
|
298 |
channelSftp.cd(destinationPath);
|
|
|
299 |
SftpATTRS attrs = null;
|
|
|
300 |
|
|
|
301 |
// check if the directory is already existing
|
|
|
302 |
try {
|
|
|
303 |
attrs = channelSftp.stat(folderName);
|
|
|
304 |
} catch (Exception e) {
|
|
|
305 |
System.out.println(destinationPath + "/" + folderName + " not found");
|
|
|
306 |
}
|
|
|
307 |
|
|
|
308 |
// else create a directory
|
|
|
309 |
if (attrs == null) {
|
|
|
310 |
channelSftp.mkdir(folderName);
|
|
|
311 |
channelSftp.chmod(0755, ".");
|
|
|
312 |
}
|
|
|
313 |
channelSftp.cd(folderName);
|
|
|
314 |
|
|
|
315 |
for (Map.Entry<String, InputStream> streamsFileEntry : streamsFileMap.entrySet()) {
|
|
|
316 |
channelSftp.put(streamsFileEntry.getValue(), streamsFileEntry.getKey(), ChannelSftp.OVERWRITE);
|
|
|
317 |
}
|
|
|
318 |
|
|
|
319 |
}
|
| 29926 |
amit.gupta |
320 |
|
| 29900 |
amit.gupta |
321 |
private void uploadFile(Map<String, InputStream> fileStreamsMap) throws Exception {
|
|
|
322 |
ChannelSftp channelSftp = setupJsch();
|
|
|
323 |
channelSftp.connect();
|
|
|
324 |
this.fileUpload(channelSftp, fileStreamsMap, IMAGE_REMOTE_DIR + "");
|
|
|
325 |
channelSftp.exit();
|
|
|
326 |
}
|
| 29926 |
amit.gupta |
327 |
|
|
|
328 |
private InputStream getImageBuffer(String html) throws Exception {
|
|
|
329 |
|
| 29900 |
amit.gupta |
330 |
String fileName = "/tmp/" + Instant.now().toEpochMilli();
|
|
|
331 |
FileUtils.writeStringToFile(new File(fileName), html, "UTF-8");
|
| 29920 |
amit.gupta |
332 |
String address = "file:" + fileName;
|
| 29921 |
amit.gupta |
333 |
Java2DRenderer renderer = new Java2DRenderer(address, 400);
|
| 29926 |
amit.gupta |
334 |
RenderingHints hints = new RenderingHints(RenderingHints.KEY_COLOR_RENDERING,
|
|
|
335 |
RenderingHints.VALUE_COLOR_RENDER_QUALITY);
|
| 29920 |
amit.gupta |
336 |
hints.add(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
|
|
|
337 |
hints.add(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
|
|
|
338 |
hints.add(new RenderingHints(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC));
|
|
|
339 |
renderer.setRenderingHints(hints);
|
|
|
340 |
BufferedImage img = renderer.getImage();
|
|
|
341 |
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
|
|
342 |
ImageIO.write(img, "png", os);
|
|
|
343 |
return new ByteArrayInputStream(os.toByteArray());
|
| 29900 |
amit.gupta |
344 |
}
|
|
|
345 |
|
|
|
346 |
@Autowired
|
|
|
347 |
VelocityEngine velocityEngine;
|
|
|
348 |
|
|
|
349 |
private String getContentFromTemplate(String template, Map<String, Object> model) {
|
|
|
350 |
StringBuffer content = new StringBuffer();
|
|
|
351 |
try {
|
|
|
352 |
content.append(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, template, model));
|
|
|
353 |
} catch (Exception e) {
|
|
|
354 |
e.printStackTrace();
|
|
|
355 |
}
|
|
|
356 |
return content.toString();
|
|
|
357 |
}
|
|
|
358 |
|
| 27876 |
amit.gupta |
359 |
@RequestMapping(value = "/offerHistory", method = RequestMethod.GET)
|
|
|
360 |
public String getPaginatedOffers(HttpServletRequest request, @RequestParam YearMonth yearMonth, Model model)
|
|
|
361 |
throws ProfitMandiBusinessException {
|
| 27391 |
tejbeer |
362 |
|
| 29900 |
amit.gupta |
363 |
List<CreateOfferRequest> publishedOffers = offerService.getAllOffers(yearMonth).values().stream()
|
|
|
364 |
.sorted(Comparator.comparing(CreateOfferRequest::getId).reversed()).collect(Collectors.toList());
|
| 27876 |
amit.gupta |
365 |
model.addAttribute("offers", publishedOffers);
|
|
|
366 |
model.addAttribute("yearMonth", yearMonth);
|
| 27391 |
tejbeer |
367 |
|
|
|
368 |
return "offer_history";
|
|
|
369 |
}
|
|
|
370 |
|
| 27876 |
amit.gupta |
371 |
@RequestMapping(value = "/offer-details", method = RequestMethod.GET)
|
|
|
372 |
public String schemeDetails(HttpServletRequest request, @RequestParam int offerId, Model model)
|
| 27391 |
tejbeer |
373 |
throws ProfitMandiBusinessException {
|
| 29839 |
amit.gupta |
374 |
CreateOfferRequest createOfferRequest = offerService.getOffer(0, offerId);
|
| 27391 |
tejbeer |
375 |
|
| 27876 |
amit.gupta |
376 |
model.addAttribute("offer", createOfferRequest);
|
|
|
377 |
return "offer-details";
|
| 27391 |
tejbeer |
378 |
}
|
|
|
379 |
|
| 27876 |
amit.gupta |
380 |
@RequestMapping(value = "/offerDownload", method = RequestMethod.GET)
|
|
|
381 |
public ResponseEntity<?> dowloadOfferSummary(HttpServletRequest request, @RequestParam int offerId, Model model)
|
|
|
382 |
throws Exception {
|
|
|
383 |
List<List<?>> listOfRows = new ArrayList<>();
|
|
|
384 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
385 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
386 |
headers.set("Content-disposition", "inline; filename=offer-" + offerId + ".csv");
|
| 29785 |
amit.gupta |
387 |
CreateOfferRequest createOfferRequest = offerService.getOffer(0, offerId);
|
| 27876 |
amit.gupta |
388 |
Collection<OfferRowModel> offerRowModels = offerRepository.getOfferRows(createOfferRequest);
|
| 27391 |
tejbeer |
389 |
|
| 27876 |
amit.gupta |
390 |
for (OfferRowModel offerRowModel : offerRowModels) {
|
|
|
391 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(offerRowModel.getFofoId());
|
|
|
392 |
listOfRows.add(Arrays.asList(createOfferRequest.getId(), createOfferRequest.getName(),
|
|
|
393 |
createOfferRequest.getTargetType(), createOfferRequest.getSchemeType(),
|
|
|
394 |
createOfferRequest.getBrandShareTerms(), createOfferRequest.getSellinPercentage(),
|
|
|
395 |
createOfferRequest.getPartnerCriteriaString(), createOfferRequest.getItemCriteriaString(),
|
|
|
396 |
createOfferRequest.getStartDate(), createOfferRequest.getEndDate(),
|
|
|
397 |
createOfferRequest.getCreatedOn(), customRetailer.getPartnerId(), customRetailer.getBusinessName(),
|
|
|
398 |
customRetailer.getCode(), offerRowModel.getTotalSale(), offerRowModel.getEligibleSale(),
|
|
|
399 |
offerRowModel.getAchievedTarget(), offerRowModel.getNextTarget(), offerRowModel.getEligibleSaleDp(),
|
|
|
400 |
offerRowModel.getTotalPurchaseValue(), offerRowModel.getCurrentPayoutTarget(),
|
|
|
401 |
offerRowModel.getPayoutTargetAchieved(), offerRowModel.getAmountType(),
|
|
|
402 |
offerRowModel.getPayoutValue(), offerRowModel.getPayoutValueDp(), offerRowModel.getFinalPayout(),
|
|
|
403 |
String.join(", ", offerRowModel.getPendingImeis())));
|
| 27391 |
tejbeer |
404 |
}
|
| 27876 |
amit.gupta |
405 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
|
|
406 |
Arrays.asList("Id", "Name", "Target Type", "Scheme Type", "Brand %", "Sellin %", "Partner Criteria",
|
|
|
407 |
"Item Criteria", "Start", "End", "Created", "Partner Id", "Partner Name", "Partner Code",
|
|
|
408 |
"Total Sale", "Eligible Sale", "Achieved Target", "Next Target", "Eligible Sale DP",
|
|
|
409 |
"Total Purchase DP", "Current Payout Target", "Payout Target Achieved", "Payout Amount Type",
|
|
|
410 |
"Payout Value", "Payout Value DP", "Amount to be credited", "IMEIs pending for Activation"
|
| 30426 |
tejbeer |
411 |
// "Payout Sale Qty", "Activated Value", "Activated Qty",
|
| 27876 |
amit.gupta |
412 |
), listOfRows);
|
|
|
413 |
final InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
|
|
|
414 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
415 |
return new ResponseEntity<>(inputStreamResource, headers, HttpStatus.OK);
|
| 27391 |
tejbeer |
416 |
}
|
| 29900 |
amit.gupta |
417 |
|
| 27876 |
amit.gupta |
418 |
@RequestMapping(value = "/offerById", method = RequestMethod.GET)
|
|
|
419 |
public String offerById(HttpServletRequest request, int offerId, Model model) throws ProfitMandiBusinessException {
|
| 27391 |
tejbeer |
420 |
Offer offer = offerRepository.selectById(offerId);
|
|
|
421 |
|
|
|
422 |
model.addAttribute("offer", offer);
|
|
|
423 |
|
| 27876 |
amit.gupta |
424 |
return "offer-edit";
|
| 27391 |
tejbeer |
425 |
|
|
|
426 |
}
|
| 29900 |
amit.gupta |
427 |
|
| 29675 |
amit.gupta |
428 |
@RequestMapping(value = "/published-offers/{yearMonth}", method = RequestMethod.GET)
|
| 29900 |
amit.gupta |
429 |
public String publishedOffersOnMonthBefore(HttpServletRequest request, @PathVariable int yearMonth, Model model)
|
|
|
430 |
throws ProfitMandiBusinessException {
|
| 29675 |
amit.gupta |
431 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
432 |
int fofoId = loginDetails.getFofoId();
|
| 29900 |
amit.gupta |
433 |
List<CreateOfferRequest> createOffers = offerService.getPublishedOffers(fofoId,
|
|
|
434 |
YearMonth.from(LocalDate.now()).minusMonths(yearMonth));
|
|
|
435 |
|
| 29675 |
amit.gupta |
436 |
model.addAttribute("publishedOffers", createOffers);
|
| 29900 |
amit.gupta |
437 |
|
| 29675 |
amit.gupta |
438 |
return "published-offers";
|
|
|
439 |
}
|
| 29900 |
amit.gupta |
440 |
|
| 29682 |
amit.gupta |
441 |
@PostMapping(value = "/offers/upload")
|
|
|
442 |
public String uploadOffers(HttpServletRequest request, @RequestPart("file") MultipartFile targetFile, Model model)
|
|
|
443 |
throws Exception {
|
|
|
444 |
offerService.createOffers(targetFile.getInputStream());
|
|
|
445 |
model.addAttribute("response", true);
|
|
|
446 |
return "response";
|
|
|
447 |
}
|
| 29900 |
amit.gupta |
448 |
|
| 29785 |
amit.gupta |
449 |
@Autowired
|
|
|
450 |
RoleManager roleManager;
|
| 27391 |
tejbeer |
451 |
|
| 27876 |
amit.gupta |
452 |
@RequestMapping(value = "/getOfferMargins", method = RequestMethod.GET)
|
|
|
453 |
public String getOfferMargins(HttpServletRequest request,
|
| 30426 |
tejbeer |
454 |
@RequestParam(name = "offerId", defaultValue = "0") int offerId, Model model) throws Exception {
|
| 27876 |
amit.gupta |
455 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 29785 |
amit.gupta |
456 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
| 29900 |
amit.gupta |
457 |
CreateOfferRequest createOfferRequest = offerService.getOffer(isAdmin ? 0 : loginDetails.getFofoId(), offerId);
|
|
|
458 |
|
| 27876 |
amit.gupta |
459 |
model.addAttribute("offer", createOfferRequest);
|
| 27391 |
tejbeer |
460 |
|
| 27876 |
amit.gupta |
461 |
return "offer_margin_detail_partner";
|
| 27391 |
tejbeer |
462 |
|
|
|
463 |
}
|
|
|
464 |
|
| 27895 |
amit.gupta |
465 |
}
|