| 21615 |
kshitij.so |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 25651 |
tejbeer |
3 |
import java.io.File;
|
|
|
4 |
import java.io.FileInputStream;
|
|
|
5 |
import java.io.FileNotFoundException;
|
| 24288 |
amit.gupta |
6 |
import java.time.LocalDate;
|
| 24276 |
amit.gupta |
7 |
import java.time.LocalDateTime;
|
| 24880 |
govind |
8 |
import java.time.LocalTime;
|
| 25649 |
tejbeer |
9 |
import java.time.ZoneOffset;
|
| 24339 |
amit.gupta |
10 |
import java.util.ArrayList;
|
| 26027 |
amit.gupta |
11 |
import java.util.Arrays;
|
| 26011 |
amit.gupta |
12 |
import java.util.HashMap;
|
| 26090 |
amit.gupta |
13 |
import java.util.HashSet;
|
| 25136 |
amit.gupta |
14 |
import java.util.LinkedHashMap;
|
| 23884 |
amit.gupta |
15 |
import java.util.List;
|
| 24880 |
govind |
16 |
import java.util.Map;
|
| 26055 |
tejbeer |
17 |
import java.util.Map.Entry;
|
| 26071 |
tejbeer |
18 |
import java.util.Optional;
|
| 26090 |
amit.gupta |
19 |
import java.util.Set;
|
| 24880 |
govind |
20 |
import java.util.stream.Collectors;
|
| 23568 |
govind |
21 |
|
| 22086 |
amit.gupta |
22 |
import javax.servlet.http.HttpServletRequest;
|
| 25221 |
amit.gupta |
23 |
import javax.transaction.Transactional;
|
| 22086 |
amit.gupta |
24 |
|
| 23786 |
amit.gupta |
25 |
import org.apache.logging.log4j.LogManager;
|
| 23568 |
govind |
26 |
import org.apache.logging.log4j.Logger;
|
| 22481 |
ashik.ali |
27 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23379 |
ashik.ali |
28 |
import org.springframework.beans.factory.annotation.Value;
|
| 25651 |
tejbeer |
29 |
import org.springframework.core.io.InputStreamResource;
|
|
|
30 |
import org.springframework.http.HttpHeaders;
|
|
|
31 |
import org.springframework.http.HttpStatus;
|
| 25649 |
tejbeer |
32 |
import org.springframework.http.ResponseEntity;
|
| 21615 |
kshitij.so |
33 |
import org.springframework.stereotype.Controller;
|
| 22073 |
ashik.ali |
34 |
import org.springframework.ui.Model;
|
| 21615 |
kshitij.so |
35 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
36 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 25649 |
tejbeer |
37 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 21615 |
kshitij.so |
38 |
|
| 25649 |
tejbeer |
39 |
import com.google.gson.Gson;
|
| 26114 |
amit.gupta |
40 |
import com.google.gson.JsonElement;
|
| 25677 |
amit.gupta |
41 |
import com.mongodb.DBObject;
|
| 25651 |
tejbeer |
42 |
import com.spice.profitmandi.common.enumuration.ContentType;
|
| 25683 |
tejbeer |
43 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
| 26065 |
amit.gupta |
44 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
| 22481 |
ashik.ali |
45 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 25677 |
amit.gupta |
46 |
import com.spice.profitmandi.common.model.BrandStockPrice;
|
| 26055 |
tejbeer |
47 |
import com.spice.profitmandi.common.model.ChartModel;
|
| 26005 |
amit.gupta |
48 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 26055 |
tejbeer |
49 |
import com.spice.profitmandi.common.model.DataModel;
|
|
|
50 |
import com.spice.profitmandi.common.model.DatasetModel;
|
|
|
51 |
import com.spice.profitmandi.common.model.LegendModel;
|
| 25649 |
tejbeer |
52 |
import com.spice.profitmandi.common.model.Notification;
|
| 26055 |
tejbeer |
53 |
import com.spice.profitmandi.common.model.OptionsModel;
|
| 24203 |
amit.gupta |
54 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 26055 |
tejbeer |
55 |
import com.spice.profitmandi.common.model.TitleModel;
|
| 25651 |
tejbeer |
56 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 25649 |
tejbeer |
57 |
import com.spice.profitmandi.dao.Interface.Campaign;
|
| 26011 |
amit.gupta |
58 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
|
|
59 |
import com.spice.profitmandi.dao.entity.auth.Menu;
|
|
|
60 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
| 25651 |
tejbeer |
61 |
import com.spice.profitmandi.dao.entity.dtr.Document;
|
| 25649 |
tejbeer |
62 |
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
|
|
|
63 |
import com.spice.profitmandi.dao.entity.dtr.UserCampaign;
|
| 22654 |
ashik.ali |
64 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 24288 |
amit.gupta |
65 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| 25214 |
amit.gupta |
66 |
import com.spice.profitmandi.dao.entity.fofo.PartnerTargetDetails;
|
| 25566 |
tejbeer |
67 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
| 26024 |
amit.gupta |
68 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 25649 |
tejbeer |
69 |
import com.spice.profitmandi.dao.model.SimpleCampaign;
|
|
|
70 |
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
|
| 25976 |
amit.gupta |
71 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 26011 |
amit.gupta |
72 |
import com.spice.profitmandi.dao.repository.auth.MenuCategoryRepository;
|
|
|
73 |
import com.spice.profitmandi.dao.repository.auth.MenuRepository;
|
| 26090 |
amit.gupta |
74 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 26011 |
amit.gupta |
75 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
|
|
76 |
import com.spice.profitmandi.dao.repository.cs.TicketCategoryRepository;
|
| 25651 |
tejbeer |
77 |
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
|
| 22481 |
ashik.ali |
78 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 24996 |
amit.gupta |
79 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 25649 |
tejbeer |
80 |
import com.spice.profitmandi.dao.repository.dtr.NotificationCampaignRepository;
|
|
|
81 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
|
|
82 |
import com.spice.profitmandi.dao.repository.dtr.UserCampaignRepository;
|
| 24203 |
amit.gupta |
83 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
| 24880 |
govind |
84 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
| 26071 |
tejbeer |
85 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
| 25649 |
tejbeer |
86 |
import com.spice.profitmandi.dao.repository.fofo.HygieneDataRepository;
|
| 24288 |
amit.gupta |
87 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| 25214 |
amit.gupta |
88 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTargetRepository;
|
| 25566 |
tejbeer |
89 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
|
| 26090 |
amit.gupta |
90 |
import com.spice.profitmandi.service.AuthService;
|
| 24336 |
amit.gupta |
91 |
import com.spice.profitmandi.service.PartnerInvestmentService;
|
| 23844 |
amit.gupta |
92 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 25677 |
amit.gupta |
93 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 26005 |
amit.gupta |
94 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 22481 |
ashik.ali |
95 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
96 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
97 |
|
| 21615 |
kshitij.so |
98 |
@Controller
|
| 25222 |
amit.gupta |
99 |
@Transactional(rollbackOn = Throwable.class)
|
| 21615 |
kshitij.so |
100 |
public class DashboardController {
|
| 23923 |
amit.gupta |
101 |
|
| 23379 |
ashik.ali |
102 |
@Value("${web.api.host}")
|
|
|
103 |
private String webApiHost;
|
| 23923 |
amit.gupta |
104 |
|
| 24072 |
amit.gupta |
105 |
@Value("${web.api.scheme}")
|
|
|
106 |
private String webApiScheme;
|
| 24288 |
amit.gupta |
107 |
|
| 24078 |
amit.gupta |
108 |
@Value("${web.api.root}")
|
|
|
109 |
private String webApiRoot;
|
|
|
110 |
|
| 23379 |
ashik.ali |
111 |
@Value("${web.api.port}")
|
|
|
112 |
private int webApiPort;
|
| 21615 |
kshitij.so |
113 |
|
| 22481 |
ashik.ali |
114 |
@Autowired
|
| 22927 |
ashik.ali |
115 |
private CookiesProcessor cookiesProcessor;
|
| 23923 |
amit.gupta |
116 |
|
| 23568 |
govind |
117 |
@Autowired
|
| 26011 |
amit.gupta |
118 |
private MenuRepository menuRepository;
|
| 26012 |
amit.gupta |
119 |
|
| 26011 |
amit.gupta |
120 |
@Autowired
|
|
|
121 |
private MenuCategoryRepository menuCategoryRepository;
|
|
|
122 |
|
|
|
123 |
@Autowired
|
| 26090 |
amit.gupta |
124 |
private CsService csService;
|
|
|
125 |
|
|
|
126 |
@Autowired
|
| 25214 |
amit.gupta |
127 |
private PartnerTargetRepository partnerTargetRepository;
|
|
|
128 |
|
|
|
129 |
@Autowired
|
| 25653 |
amit.gupta |
130 |
private ResponseSender<?> responseSender;
|
| 26012 |
amit.gupta |
131 |
|
| 26005 |
amit.gupta |
132 |
@Autowired
|
|
|
133 |
RetailerService retailerService;
|
| 25214 |
amit.gupta |
134 |
|
|
|
135 |
@Autowired
|
| 23786 |
amit.gupta |
136 |
private RoleManager roleManager;
|
| 23923 |
amit.gupta |
137 |
|
| 23838 |
ashik.ali |
138 |
@Autowired
|
|
|
139 |
private FofoStoreRepository fofoStoreRepository;
|
| 23884 |
amit.gupta |
140 |
|
|
|
141 |
@Autowired
|
| 24880 |
govind |
142 |
private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
| 23923 |
amit.gupta |
143 |
|
| 23884 |
amit.gupta |
144 |
@Autowired
|
| 24880 |
govind |
145 |
private PartnerInvestmentService partnerInvestmentService;
|
| 24288 |
amit.gupta |
146 |
|
| 23884 |
amit.gupta |
147 |
@Autowired
|
| 25653 |
amit.gupta |
148 |
DocumentRepository documentRepository;
|
| 25683 |
tejbeer |
149 |
|
| 25677 |
amit.gupta |
150 |
@Autowired
|
|
|
151 |
InventoryService inventoryService;
|
| 23923 |
amit.gupta |
152 |
|
| 23884 |
amit.gupta |
153 |
@Autowired
|
| 24203 |
amit.gupta |
154 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
|
|
155 |
|
| 24880 |
govind |
156 |
@Autowired
|
|
|
157 |
private FofoOrderItemRepository fofoOrderItemRepository;
|
| 26012 |
amit.gupta |
158 |
|
| 26011 |
amit.gupta |
159 |
@Autowired
|
|
|
160 |
private TicketCategoryRepository ticketCategoryRepository;
|
| 24880 |
govind |
161 |
|
|
|
162 |
@Autowired
|
| 25566 |
tejbeer |
163 |
private PartnerTypeChangeService partnerTypeChangeService;
|
| 25136 |
amit.gupta |
164 |
|
| 24996 |
amit.gupta |
165 |
@Autowired
|
| 25649 |
tejbeer |
166 |
private HygieneDataRepository hygieneDataRepository;
|
|
|
167 |
|
|
|
168 |
@Autowired
|
|
|
169 |
private UserCampaignRepository userCampaignRepository;
|
| 26012 |
amit.gupta |
170 |
|
| 26011 |
amit.gupta |
171 |
@Autowired
|
|
|
172 |
private PositionRepository positionRepository;
|
| 25649 |
tejbeer |
173 |
|
|
|
174 |
@Autowired
|
|
|
175 |
private UserAccountRepository userAccountRepository;
|
|
|
176 |
|
|
|
177 |
@Autowired
|
|
|
178 |
private NotificationCampaignRepository notificationCampaignRepository;
|
|
|
179 |
|
|
|
180 |
@Autowired
|
| 24996 |
amit.gupta |
181 |
private Mongo mongoClient;
|
| 26012 |
amit.gupta |
182 |
|
| 25976 |
amit.gupta |
183 |
@Autowired
|
|
|
184 |
private AuthRepository authRepository;
|
| 24880 |
govind |
185 |
|
| 25649 |
tejbeer |
186 |
@Autowired
|
| 26071 |
tejbeer |
187 |
private FofoOrderRepository fofoOrderRepository;
|
|
|
188 |
|
|
|
189 |
@Autowired
|
| 25649 |
tejbeer |
190 |
private Gson gson;
|
|
|
191 |
|
| 23568 |
govind |
192 |
private static final Logger LOGGER = LogManager.getLogger(DashboardController.class);
|
| 23923 |
amit.gupta |
193 |
|
| 25136 |
amit.gupta |
194 |
@RequestMapping(value = "/12dashboard34", method = RequestMethod.GET)
|
| 25726 |
amit.gupta |
195 |
public String dashboard1(HttpServletRequest request, Model model, @RequestParam int fofoId) throws Exception {
|
| 25740 |
amit.gupta |
196 |
boolean isAdmin = false;
|
|
|
197 |
model.addAttribute("isAdmin", isAdmin);
|
|
|
198 |
|
|
|
199 |
model.addAttribute("webApiHost", webApiHost);
|
|
|
200 |
model.addAttribute("webApiPort", webApiPort);
|
|
|
201 |
model.addAttribute("webApiScheme", webApiScheme);
|
|
|
202 |
model.addAttribute("webApiRoot", webApiRoot);
|
|
|
203 |
if (isAdmin) {
|
|
|
204 |
return "dashboard1";
|
|
|
205 |
} else {
|
|
|
206 |
FofoStore fofoStore = null;
|
|
|
207 |
try {
|
| 26005 |
amit.gupta |
208 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
|
| 25740 |
amit.gupta |
209 |
fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
|
|
|
210 |
if (!fofoStore.isActive()) {
|
|
|
211 |
return "redirect:/login";
|
|
|
212 |
}
|
|
|
213 |
|
|
|
214 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoStore.getId(), LocalDate.now());
|
|
|
215 |
model.addAttribute("partnerType", partnerType);
|
|
|
216 |
model.addAttribute("partnerTypeImage", PartnerType.imageMap.get(partnerType));
|
| 26005 |
amit.gupta |
217 |
model.addAttribute("fofoStore", customRetailer);
|
| 25740 |
amit.gupta |
218 |
model.addAttribute("partnerType", partnerType);
|
|
|
219 |
model.addAttribute("hasGift", hasGift(fofoId));
|
|
|
220 |
model.addAttribute("giftItemId", ProfitMandiConstants.GIFT_ID);
|
|
|
221 |
|
|
|
222 |
model.addAttribute("brandStockPrices", this.getBrandStockPrices(fofoId));
|
|
|
223 |
model.addAttribute("salesMap", this.getSales(fofoId));
|
|
|
224 |
// this.setInvestments
|
|
|
225 |
//
|
|
|
226 |
model.addAttribute("investments", this.getInvestments(fofoId));
|
| 26012 |
amit.gupta |
227 |
model.addAttribute("isInvestmentOk",
|
|
|
228 |
partnerInvestmentService.isInvestmentOk(fofoId, 10, ProfitMandiConstants.CUTOFF_INVESTMENT));
|
| 25740 |
amit.gupta |
229 |
} catch (ProfitMandiBusinessException e) {
|
|
|
230 |
LOGGER.error("FofoStore Code not found of fofoId {}", fofoId);
|
|
|
231 |
|
|
|
232 |
}
|
|
|
233 |
}
|
|
|
234 |
|
|
|
235 |
LocalDateTime currentMonthStart = LocalDateTime.now().withDayOfMonth(1);
|
|
|
236 |
LocalDateTime currentMonthEnd = currentMonthStart.plusMonths(1).withDayOfMonth(1);
|
| 26012 |
amit.gupta |
237 |
double currentMonthRating = hygieneDataRepository.selectRatingAvg(fofoId, currentMonthStart, currentMonthEnd)
|
|
|
238 |
/ 2;
|
|
|
239 |
double lastMonthRating = hygieneDataRepository.selectRatingAvg(fofoId, currentMonthStart, currentMonthEnd) / 2;
|
|
|
240 |
double ratingTillDate = hygieneDataRepository.selectRatingAvg(fofoId, currentMonthStart, currentMonthEnd) / 2;
|
| 25740 |
amit.gupta |
241 |
model.addAttribute("currentMonthRating", (float) Math.round(currentMonthRating * 10) / 10);
|
|
|
242 |
model.addAttribute("lastMonthRating", (float) Math.round(lastMonthRating * 10) / 10);
|
|
|
243 |
model.addAttribute("ratingTillDate", (float) Math.round(ratingTillDate * 10) / 10);
|
|
|
244 |
|
| 26012 |
amit.gupta |
245 |
long hygieneCount = hygieneDataRepository.selectHygieneCount(fofoId, true, currentMonthStart, currentMonthEnd);
|
|
|
246 |
|
|
|
247 |
long invalidHygieneCount = hygieneDataRepository.selectHygieneCount(fofoId, false, currentMonthStart,
|
| 25740 |
amit.gupta |
248 |
currentMonthEnd);
|
|
|
249 |
if (hygieneCount == 0 && invalidHygieneCount == 0) {
|
|
|
250 |
invalidHygieneCount = 1;
|
|
|
251 |
}
|
|
|
252 |
model.addAttribute("hygienePercentage", (hygieneCount * 100) / (invalidHygieneCount + hygieneCount));
|
|
|
253 |
|
|
|
254 |
model.addAttribute("monthDays", LocalDate.now().minusDays(1).lengthOfMonth());
|
|
|
255 |
model.addAttribute("dayOfMonth", LocalDate.now().minusDays(1).getDayOfMonth());
|
|
|
256 |
return "12dashboard34";
|
| 25136 |
amit.gupta |
257 |
}
|
|
|
258 |
|
|
|
259 |
private Map<String, Object> getInvestments(int fofoId) throws Exception {
|
|
|
260 |
Map<String, Object> investments = new LinkedHashMap<>();
|
|
|
261 |
PartnerDailyInvestment investment = partnerInvestmentService.getInvestment(fofoId, 1);
|
| 25649 |
tejbeer |
262 |
LocalDate currentMonthStart = LocalDate.now().withDayOfMonth(1);
|
| 25136 |
amit.gupta |
263 |
LocalDate yesterDate = LocalDate.now().minusDays(1);
|
|
|
264 |
PartnerDailyInvestment yesterdayInvestment = partnerDailyInvestmentRepository.select(fofoId, yesterDate);
|
|
|
265 |
if (yesterdayInvestment == null) {
|
|
|
266 |
yesterdayInvestment = new PartnerDailyInvestment();
|
|
|
267 |
}
|
|
|
268 |
|
|
|
269 |
List<PartnerDailyInvestment> currentMonthInvestments = partnerDailyInvestmentRepository.selectAll(fofoId,
|
|
|
270 |
currentMonthStart, currentMonthStart.withDayOfMonth(currentMonthStart.lengthOfMonth()));
|
|
|
271 |
|
| 25140 |
amit.gupta |
272 |
long okInvestmentDays = currentMonthInvestments.stream().filter(x -> x.getShortPercentage() <= 10)
|
| 25136 |
amit.gupta |
273 |
.collect(Collectors.counting());
|
| 25140 |
amit.gupta |
274 |
investments.put("today", investment.getTotalInvestment());
|
|
|
275 |
investments.put("investment", investment);
|
|
|
276 |
investments.put("inStock", investment.getInStockAmount());
|
| 25182 |
amit.gupta |
277 |
investments.put("minimum", investment.getMinInvestmentString());
|
| 25140 |
amit.gupta |
278 |
investments.put("short", investment.getShortPercentage());
|
| 25649 |
tejbeer |
279 |
investments.put("okDays", okInvestmentDays);
|
| 25136 |
amit.gupta |
280 |
return investments;
|
|
|
281 |
}
|
|
|
282 |
|
| 25221 |
amit.gupta |
283 |
private Map<String, Object> getSales(int fofoId) {
|
| 25653 |
amit.gupta |
284 |
|
| 25221 |
amit.gupta |
285 |
Map<String, Object> salesMap = new LinkedHashMap<>();
|
| 25140 |
amit.gupta |
286 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
| 25214 |
amit.gupta |
287 |
int monthLength = LocalDate.now().lengthOfMonth();
|
| 26012 |
amit.gupta |
288 |
Double todaySale = fofoOrderItemRepository
|
|
|
289 |
.selectSumAmountGroupByRetailer(curDate, curDate.with(LocalTime.MAX), fofoId, false).get(fofoId);
|
|
|
290 |
Double mtdSale = fofoOrderItemRepository
|
|
|
291 |
.selectSumAmountGroupByRetailer(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), fofoId, false)
|
|
|
292 |
.get(fofoId);
|
|
|
293 |
Double lmtdSale = fofoOrderItemRepository
|
|
|
294 |
.selectSumAmountGroupByRetailer(curDate.withDayOfMonth(1).minusMonths(1),
|
|
|
295 |
curDate.with(LocalTime.MAX).minusMonths(1), fofoId, false)
|
|
|
296 |
.get(fofoId);
|
| 25214 |
amit.gupta |
297 |
|
|
|
298 |
List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository
|
|
|
299 |
.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now());
|
| 25544 |
amit.gupta |
300 |
if (partnerTargetDetails.isEmpty()) {
|
| 25372 |
tejbeer |
301 |
partnerTargetDetails = partnerTargetRepository
|
| 25653 |
amit.gupta |
302 |
.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now().minusMonths(3));
|
| 25372 |
tejbeer |
303 |
}
|
| 25214 |
amit.gupta |
304 |
|
| 25653 |
amit.gupta |
305 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoId, LocalDate.now());
|
| 25214 |
amit.gupta |
306 |
|
| 25664 |
amit.gupta |
307 |
int currentRate = (int) (mtdSale / curDate.getDayOfMonth());
|
| 25653 |
amit.gupta |
308 |
|
|
|
309 |
salesMap.put("requiredType", partnerType.next());
|
|
|
310 |
float reqdAmount = partnerTypeChangeService.getMinimumAmount(partnerType.next());
|
|
|
311 |
int requiredRate = (int) ((reqdAmount - mtdSale) / (monthLength - curDate.getDayOfMonth()));
|
|
|
312 |
salesMap.put("requiredRate", requiredRate);
|
|
|
313 |
salesMap.put("requiredTypeImage", PartnerType.imageMap.get(partnerType.next()));
|
|
|
314 |
|
| 25858 |
amit.gupta |
315 |
salesMap.put("todaySale", todaySale == null ? 0 : todaySale);
|
|
|
316 |
salesMap.put("mtdSale", mtdSale == null ? 0 : mtdSale);
|
| 26012 |
amit.gupta |
317 |
salesMap.put("lmtdSale", lmtdSale == null ? 0 : lmtdSale);
|
| 26065 |
amit.gupta |
318 |
|
| 25653 |
amit.gupta |
319 |
PartnerType currentType = partnerTypeChangeService.getPartnerTypeByAmount(currentRate * monthLength);
|
|
|
320 |
salesMap.put("currentRate", currentRate);
|
|
|
321 |
salesMap.put("currentType", currentType);
|
|
|
322 |
salesMap.put("currentTypeImage", PartnerType.imageMap.get(currentType));
|
| 25136 |
amit.gupta |
323 |
return salesMap;
|
|
|
324 |
}
|
|
|
325 |
|
| 25677 |
amit.gupta |
326 |
private List<BrandStockPrice> getBrandStockPrices(int fofoId) throws Exception {
|
|
|
327 |
Map<String, BrandStockPrice> brandStockPricesMap = inventoryService.getBrandWiseStockValue(fofoId);
|
| 25175 |
amit.gupta |
328 |
|
| 25677 |
amit.gupta |
329 |
List<DBObject> mobileBrands = mongoClient.getMongoBrands(fofoId, "", 3);
|
|
|
330 |
List<BrandStockPrice> brandStockPrices = new ArrayList<>();
|
|
|
331 |
|
|
|
332 |
mobileBrands.stream().forEach(x -> {
|
|
|
333 |
String brand = (String) x.get("name");
|
|
|
334 |
if (brandStockPricesMap.containsKey(brand)) {
|
|
|
335 |
BrandStockPrice brandStockPrice = brandStockPricesMap.get(brand);
|
|
|
336 |
brandStockPrice.setBrandUrl((String) x.get("url"));
|
|
|
337 |
brandStockPrice.setRank(((Double) x.get("rank")).intValue());
|
|
|
338 |
brandStockPrices.add(brandStockPrice);
|
|
|
339 |
}
|
|
|
340 |
});
|
|
|
341 |
|
|
|
342 |
return brandStockPrices.stream().filter(x -> x.getTotalQty() > 0).sorted((x, y) -> x.getRank() - y.getRank())
|
|
|
343 |
.collect(Collectors.toList());
|
|
|
344 |
}
|
|
|
345 |
|
| 21615 |
kshitij.so |
346 |
@RequestMapping(value = "/dashboard", method = RequestMethod.GET)
|
| 25653 |
amit.gupta |
347 |
public String dashboard(HttpServletRequest request, Model model) throws Exception {
|
| 22927 |
ashik.ali |
348 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 26011 |
amit.gupta |
349 |
String email = loginDetails.getEmailId();
|
| 25180 |
amit.gupta |
350 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
351 |
model.addAttribute("isAdmin", isAdmin);
|
| 23923 |
amit.gupta |
352 |
|
| 25274 |
amit.gupta |
353 |
model.addAttribute("webApiHost", webApiHost);
|
|
|
354 |
model.addAttribute("webApiPort", webApiPort);
|
|
|
355 |
model.addAttribute("webApiScheme", webApiScheme);
|
| 25544 |
amit.gupta |
356 |
model.addAttribute("webApiRoot", webApiRoot);
|
| 25183 |
amit.gupta |
357 |
if (isAdmin) {
|
| 26011 |
amit.gupta |
358 |
return adminPanel(loginDetails.getFofoId(), email, model);
|
| 25180 |
amit.gupta |
359 |
} else {
|
| 25740 |
amit.gupta |
360 |
FofoStore fofoStore = null;
|
| 25180 |
amit.gupta |
361 |
try {
|
|
|
362 |
fofoStore = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
|
| 25544 |
amit.gupta |
363 |
if (!fofoStore.isActive()) {
|
|
|
364 |
return "redirect:/login";
|
|
|
365 |
}
|
| 25649 |
tejbeer |
366 |
|
| 25740 |
amit.gupta |
367 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoStore.getId(), LocalDate.now());
|
| 25566 |
tejbeer |
368 |
model.addAttribute("partnerType", partnerType);
|
| 25653 |
amit.gupta |
369 |
model.addAttribute("partnerTypeImage", PartnerType.imageMap.get(partnerType));
|
| 25180 |
amit.gupta |
370 |
model.addAttribute("fofoStore", fofoStore);
|
| 25566 |
tejbeer |
371 |
model.addAttribute("partnerType", partnerType);
|
| 25180 |
amit.gupta |
372 |
model.addAttribute("hasGift", hasGift(loginDetails.getFofoId()));
|
|
|
373 |
model.addAttribute("giftItemId", ProfitMandiConstants.GIFT_ID);
|
| 26071 |
tejbeer |
374 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
|
|
375 |
Map<Integer, Double> accesoriesmtdsale = fofoOrderRepository
|
|
|
376 |
.selectSumSaleGroupByFofoIdsForMobileOrAccessories(loginDetails.getFofoId(),
|
|
|
377 |
curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), Optional.of(false));
|
|
|
378 |
LOGGER.info("accesoriesmtdsale" + accesoriesmtdsale);
|
|
|
379 |
Double accesoriesStock = currentInventorySnapshotRepository
|
|
|
380 |
.selectSumStockGroupByFofoIdsForMobileOrAccessories(loginDetails.getFofoId(),
|
|
|
381 |
Optional.of(false))
|
|
|
382 |
.get(loginDetails.getFofoId());
|
| 25180 |
amit.gupta |
383 |
|
| 26071 |
tejbeer |
384 |
model.addAttribute("accesoriesStock", String.format("%.0f", accesoriesStock));
|
| 26065 |
amit.gupta |
385 |
model.addAttribute("brandStockPrices", this.getBrandStockPrices(loginDetails.getFofoId()));
|
| 25180 |
amit.gupta |
386 |
model.addAttribute("salesMap", this.getSales(loginDetails.getFofoId()));
|
| 26055 |
tejbeer |
387 |
ChartModel cm = this.getBrandChart(loginDetails.getFofoId());
|
|
|
388 |
|
|
|
389 |
LOGGER.info("chartMap" + gson.toJson(cm));
|
|
|
390 |
model.addAttribute("chartMap", gson.toJson(cm));
|
| 25544 |
amit.gupta |
391 |
// this.setInvestments
|
|
|
392 |
//
|
| 25180 |
amit.gupta |
393 |
model.addAttribute("investments", this.getInvestments(loginDetails.getFofoId()));
|
| 25544 |
amit.gupta |
394 |
model.addAttribute("isInvestmentOk", partnerInvestmentService.isInvestmentOk(loginDetails.getFofoId(),
|
|
|
395 |
10, ProfitMandiConstants.CUTOFF_INVESTMENT));
|
| 25180 |
amit.gupta |
396 |
} catch (ProfitMandiBusinessException e) {
|
|
|
397 |
LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
|
|
|
398 |
|
|
|
399 |
}
|
| 22481 |
ashik.ali |
400 |
}
|
| 25649 |
tejbeer |
401 |
|
|
|
402 |
LocalDateTime currentMonthStart = LocalDateTime.now().withDayOfMonth(1);
|
| 25747 |
amit.gupta |
403 |
LocalDateTime lastMonthStart = currentMonthStart.minusMonths(1);
|
| 25653 |
amit.gupta |
404 |
LocalDateTime currentMonthEnd = currentMonthStart.plusMonths(1).withDayOfMonth(1);
|
|
|
405 |
double currentMonthRating = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), currentMonthStart,
|
| 25677 |
amit.gupta |
406 |
currentMonthEnd) / 2;
|
| 25747 |
amit.gupta |
407 |
double lastMonthRating = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), lastMonthStart,
|
|
|
408 |
currentMonthStart) / 2;
|
|
|
409 |
double ratingTillDate = hygieneDataRepository.selectRatingAvg(loginDetails.getFofoId(), LocalDateTime.MIN,
|
| 25677 |
amit.gupta |
410 |
currentMonthEnd) / 2;
|
|
|
411 |
model.addAttribute("currentMonthRating", (float) Math.round(currentMonthRating * 10) / 10);
|
|
|
412 |
model.addAttribute("lastMonthRating", (float) Math.round(lastMonthRating * 10) / 10);
|
|
|
413 |
model.addAttribute("ratingTillDate", (float) Math.round(ratingTillDate * 10) / 10);
|
| 25649 |
tejbeer |
414 |
|
| 25653 |
amit.gupta |
415 |
long hygieneCount = hygieneDataRepository.selectHygieneCount(loginDetails.getFofoId(), true, currentMonthStart,
|
|
|
416 |
currentMonthEnd);
|
| 25651 |
tejbeer |
417 |
|
| 25653 |
amit.gupta |
418 |
long invalidHygieneCount = hygieneDataRepository.selectHygieneCount(loginDetails.getFofoId(), false,
|
|
|
419 |
currentMonthStart, currentMonthEnd);
|
|
|
420 |
if (hygieneCount == 0 && invalidHygieneCount == 0) {
|
|
|
421 |
invalidHygieneCount = 1;
|
|
|
422 |
}
|
|
|
423 |
model.addAttribute("hygienePercentage", (hygieneCount * 100) / (invalidHygieneCount + hygieneCount));
|
| 25651 |
tejbeer |
424 |
|
| 25197 |
amit.gupta |
425 |
model.addAttribute("monthDays", LocalDate.now().minusDays(1).lengthOfMonth());
|
|
|
426 |
model.addAttribute("dayOfMonth", LocalDate.now().minusDays(1).getDayOfMonth());
|
| 25140 |
amit.gupta |
427 |
return "dashboard1";
|
| 21615 |
kshitij.so |
428 |
}
|
| 23923 |
amit.gupta |
429 |
|
| 26055 |
tejbeer |
430 |
private ChartModel getBrandChart(int fofoId) {
|
|
|
431 |
|
|
|
432 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
|
|
433 |
|
|
|
434 |
LOGGER.info("cur Date" + curDate.withDayOfMonth(1));
|
|
|
435 |
|
|
|
436 |
LOGGER.info("curDateYear" + curDate.with(LocalTime.MAX));
|
|
|
437 |
|
|
|
438 |
Map<String, Double> brandwisesale = fofoOrderItemRepository
|
|
|
439 |
.selectSumAmountGroupByBrand(curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX), fofoId);
|
|
|
440 |
LOGGER.info("brandwisesale" + brandwisesale);
|
|
|
441 |
|
|
|
442 |
Map<String, Double> lmtdBrandWiseSale = fofoOrderItemRepository.selectSumAmountGroupByBrand(
|
|
|
443 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), fofoId);
|
|
|
444 |
|
|
|
445 |
ChartModel cm = new ChartModel();
|
|
|
446 |
|
|
|
447 |
List<String> labels = new ArrayList<>();
|
|
|
448 |
labels.addAll(brandwisesale.keySet());
|
|
|
449 |
List<Double> values = new ArrayList<>();
|
|
|
450 |
values.addAll(brandwisesale.values());
|
|
|
451 |
|
|
|
452 |
List<Double> lmtdValues = new ArrayList<>();
|
|
|
453 |
lmtdValues.addAll(lmtdBrandWiseSale.values());
|
|
|
454 |
|
|
|
455 |
DatasetModel dsm = new DatasetModel();
|
|
|
456 |
dsm.setLabel("mtd sales");
|
|
|
457 |
|
|
|
458 |
List<String> backgroundColor = new ArrayList<>();
|
|
|
459 |
for (Entry<String, Double> bs : brandwisesale.entrySet()) {
|
|
|
460 |
backgroundColor.add("#3e95cd");
|
|
|
461 |
}
|
|
|
462 |
|
|
|
463 |
dsm.setBackgroundColor(backgroundColor);
|
|
|
464 |
dsm.setData(values);
|
|
|
465 |
|
|
|
466 |
DatasetModel lmtddsm = new DatasetModel();
|
|
|
467 |
lmtddsm.setLabel("lmtd sales");
|
|
|
468 |
|
|
|
469 |
List<String> background = new ArrayList<>();
|
|
|
470 |
for (Entry<String, Double> bs : lmtdBrandWiseSale.entrySet()) {
|
|
|
471 |
background.add("#8e5ea2");
|
|
|
472 |
}
|
|
|
473 |
|
|
|
474 |
lmtddsm.setBackgroundColor(background);
|
|
|
475 |
lmtddsm.setData(lmtdValues);
|
|
|
476 |
|
|
|
477 |
List<DatasetModel> datasets = new ArrayList<>();
|
|
|
478 |
datasets.add(dsm);
|
|
|
479 |
datasets.add(lmtddsm);
|
|
|
480 |
|
|
|
481 |
DataModel dm = new DataModel();
|
|
|
482 |
dm.setDatasets(datasets);
|
|
|
483 |
dm.setLabels(labels);
|
|
|
484 |
|
|
|
485 |
LegendModel lm = new LegendModel();
|
|
|
486 |
lm.setDisplay(true);
|
|
|
487 |
|
|
|
488 |
TitleModel tm = new TitleModel();
|
|
|
489 |
tm.setText("Brand Wise Sale Graph");
|
|
|
490 |
tm.setDisplay(true);
|
|
|
491 |
|
|
|
492 |
OptionsModel om = new OptionsModel();
|
|
|
493 |
om.setLegend(lm);
|
|
|
494 |
om.setTitle(tm);
|
|
|
495 |
|
|
|
496 |
cm.setType("bar");
|
|
|
497 |
cm.setData(dm);
|
|
|
498 |
cm.setOptions(om);
|
|
|
499 |
|
|
|
500 |
return cm;
|
|
|
501 |
|
|
|
502 |
}
|
|
|
503 |
|
| 26011 |
amit.gupta |
504 |
private String adminPanel(int fofoId, String email, Model model) throws ProfitMandiBusinessException {
|
| 26022 |
amit.gupta |
505 |
List<Menu> menus = null;
|
| 26011 |
amit.gupta |
506 |
try {
|
|
|
507 |
AuthUser authUser = authRepository.selectByEmailOrMobile(email);
|
|
|
508 |
List<Position> positions = positionRepository.selectAll(authUser.getId());
|
| 26090 |
amit.gupta |
509 |
if (Arrays.asList("amit.gupta@shop2020.in", "tejbeer.kaur@shop2020.in").contains(email)) {
|
| 26029 |
amit.gupta |
510 |
menus = menuRepository.selectAll();
|
|
|
511 |
} else if (positions.size() > 0) {
|
|
|
512 |
if (positions.stream().filter(x -> x.getEscalationType().equals(EscalationType.L4)).count() > 0) {
|
| 26028 |
amit.gupta |
513 |
menus = menuRepository.selectAll();
|
|
|
514 |
} else {
|
|
|
515 |
List<Integer> menuIds = menuCategoryRepository.selectAllByPositions(positions).stream()
|
|
|
516 |
.map(x -> x.getMenuId()).collect(Collectors.toList());
|
|
|
517 |
LOGGER.info("Menu Ids are {}", menuIds);
|
|
|
518 |
if (menuIds.size() > 0) {
|
|
|
519 |
menus = menuRepository.selectAllByIds(menuIds);
|
|
|
520 |
}
|
| 26022 |
amit.gupta |
521 |
}
|
| 26090 |
amit.gupta |
522 |
List<Position> salesPositions = positions.stream()
|
|
|
523 |
.filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_SALES)
|
|
|
524 |
.collect(Collectors.toList());
|
|
|
525 |
if (salesPositions.size() > 0) {
|
|
|
526 |
Set<CustomRetailer> positionRetailers = new HashSet<>();
|
| 26100 |
amit.gupta |
527 |
csService.getPositionCustomRetailerMap(salesPositions).values().forEach(customRetailers -> {
|
| 26090 |
amit.gupta |
528 |
positionRetailers.addAll(customRetailers);
|
|
|
529 |
});
|
|
|
530 |
model.addAttribute("retailers", gson.toJson(positionRetailers));
|
|
|
531 |
model.addAttribute("reporticoProjectMap", ReporticoProject.salesReporticoProjectMap);
|
| 26152 |
amit.gupta |
532 |
model.addAttribute("warehouses", getWarehouses(positionRetailers));
|
| 26090 |
amit.gupta |
533 |
}
|
| 26114 |
amit.gupta |
534 |
List<Position> warehousePositions = positions.stream()
|
|
|
535 |
.filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_WAREHOUSE)
|
|
|
536 |
.collect(Collectors.toList());
|
|
|
537 |
if (warehousePositions.size() > 0) {
|
|
|
538 |
Set<CustomRetailer> positionRetailers = new HashSet<>();
|
| 26123 |
amit.gupta |
539 |
csService.getPositionCustomRetailerMap(warehousePositions).values().forEach(customRetailers -> {
|
| 26114 |
amit.gupta |
540 |
positionRetailers.addAll(customRetailers);
|
|
|
541 |
});
|
|
|
542 |
model.addAttribute("reporticoProjectMap", ReporticoProject.warehouseReporticoMap);
|
|
|
543 |
model.addAttribute("retailers", gson.toJson(positionRetailers));
|
| 26123 |
amit.gupta |
544 |
model.addAttribute("warehouses", getWarehouses(positionRetailers));
|
| 26114 |
amit.gupta |
545 |
}
|
| 26142 |
amit.gupta |
546 |
model.addAttribute("authId", authUser.getId());
|
| 26028 |
amit.gupta |
547 |
|
| 26022 |
amit.gupta |
548 |
}
|
| 26012 |
amit.gupta |
549 |
} catch (ProfitMandiBusinessException e) {
|
| 26011 |
amit.gupta |
550 |
}
|
| 26028 |
amit.gupta |
551 |
List<Menu> menuList = (menus != null) ? this.prepareMenu(menus) : new ArrayList<>();
|
| 26012 |
amit.gupta |
552 |
|
| 26022 |
amit.gupta |
553 |
model.addAttribute("menu", menuList);
|
| 26012 |
amit.gupta |
554 |
return "admin";
|
|
|
555 |
}
|
|
|
556 |
|
| 26114 |
amit.gupta |
557 |
private String getWarehouses(Set<CustomRetailer> positionRetailers) {
|
|
|
558 |
Map<Integer, String> warehouses = new HashMap<>();
|
|
|
559 |
positionRetailers.stream().map(x->
|
|
|
560 |
warehouses.put(x.getWarehouseId(), ProfitMandiConstants.WAREHOUSE_MAP.get(x.getWarehouseId())));
|
|
|
561 |
return gson.toJson(warehouses);
|
|
|
562 |
|
|
|
563 |
}
|
|
|
564 |
|
| 26012 |
amit.gupta |
565 |
private List<Menu> prepareMenu(List<Menu> menus) {
|
|
|
566 |
List<Menu> returnMenu = new ArrayList<>();
|
|
|
567 |
Map<Menu, List<Menu>> subMenuMap = new HashMap<Menu, List<Menu>>();
|
|
|
568 |
for (Menu menu : menus) {
|
|
|
569 |
if (menu.get_parent() == null) {
|
| 26014 |
amit.gupta |
570 |
if (!subMenuMap.containsKey(menu)) {
|
| 26012 |
amit.gupta |
571 |
subMenuMap.put(menu, new ArrayList<>());
|
| 26011 |
amit.gupta |
572 |
}
|
|
|
573 |
} else {
|
| 26012 |
amit.gupta |
574 |
Menu parentMenu = menu.get_parent();
|
|
|
575 |
if (!subMenuMap.containsKey(parentMenu)) {
|
|
|
576 |
subMenuMap.put(parentMenu, new ArrayList<>());
|
| 26011 |
amit.gupta |
577 |
}
|
| 26012 |
amit.gupta |
578 |
subMenuMap.get(parentMenu).add(menu);
|
| 26011 |
amit.gupta |
579 |
}
|
|
|
580 |
}
|
| 26012 |
amit.gupta |
581 |
subMenuMap.entrySet().stream().forEach(entry -> {
|
|
|
582 |
entry.getKey().setSubMenus(entry.getValue());
|
|
|
583 |
returnMenu.add(entry.getKey());
|
|
|
584 |
});
|
|
|
585 |
return returnMenu;
|
| 26005 |
amit.gupta |
586 |
}
|
|
|
587 |
|
| 24288 |
amit.gupta |
588 |
// This method is currently hardcoded to faciliate watches sold as gift.
|
| 24203 |
amit.gupta |
589 |
private boolean hasGift(int fofoId) {
|
|
|
590 |
try {
|
| 24288 |
amit.gupta |
591 |
return currentInventorySnapshotRepository.selectByItemIdAndFofoId(ProfitMandiConstants.GIFT_ID, fofoId)
|
|
|
592 |
.getAvailability() > 0;
|
| 24203 |
amit.gupta |
593 |
} catch (ProfitMandiBusinessException e) {
|
|
|
594 |
return false;
|
|
|
595 |
}
|
|
|
596 |
}
|
| 24288 |
amit.gupta |
597 |
|
| 22354 |
ashik.ali |
598 |
@RequestMapping(value = "/contactUs", method = RequestMethod.GET)
|
| 23923 |
amit.gupta |
599 |
public String contactUs(HttpServletRequest request, Model model) throws Throwable {
|
| 22354 |
ashik.ali |
600 |
model.addAttribute("appContextPath", request.getContextPath());
|
|
|
601 |
return "contact-us";
|
|
|
602 |
}
|
| 23923 |
amit.gupta |
603 |
|
| 25649 |
tejbeer |
604 |
@RequestMapping(value = "/notifications", method = RequestMethod.GET)
|
| 25683 |
tejbeer |
605 |
public String getNotificationsWithType(HttpServletRequest request,
|
|
|
606 |
@RequestParam(required = false) MessageType messageType,
|
| 25649 |
tejbeer |
607 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
608 |
@RequestParam(name = "limit", defaultValue = "20") int limit, Model model) throws Exception {
|
|
|
609 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 26060 |
tejbeer |
610 |
int userId = 0;
|
|
|
611 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
612 |
if (isAdmin) {
|
|
|
613 |
userId = loginDetails.getFofoId();
|
|
|
614 |
} else {
|
|
|
615 |
userId = userAccountRepository.selectUserIdByRetailerId(loginDetails.getFofoId());
|
|
|
616 |
}
|
| 25683 |
tejbeer |
617 |
List<Notification> notifications = null;
|
|
|
618 |
|
| 26086 |
tejbeer |
619 |
if (messageType == null) {
|
|
|
620 |
messageType = MessageType.notification;
|
| 25683 |
tejbeer |
621 |
}
|
|
|
622 |
|
| 26086 |
tejbeer |
623 |
List<NotificationCampaign> notificationCampaigns = notificationCampaignRepository.getNotifications(messageType,
|
|
|
624 |
userId, offset, limit);
|
|
|
625 |
LOGGER.info("messageType" + messageType);
|
|
|
626 |
notifications = getNotifications(notificationCampaigns, messageType);
|
|
|
627 |
|
| 25683 |
tejbeer |
628 |
model.addAttribute("notifications", notifications);
|
|
|
629 |
|
|
|
630 |
LOGGER.info("notifications" + notifications);
|
|
|
631 |
return "notification-template";
|
|
|
632 |
}
|
|
|
633 |
|
|
|
634 |
public List<Notification> getNotifications(List<NotificationCampaign> nc, MessageType messageType)
|
|
|
635 |
throws ProfitMandiBusinessException {
|
|
|
636 |
List<Notification> notifications = new ArrayList<>();
|
|
|
637 |
Document document = null;
|
|
|
638 |
if (messageType != null) {
|
|
|
639 |
for (NotificationCampaign notificationCampaign : nc) {
|
|
|
640 |
if (notificationCampaign.getMessageType() == messageType) {
|
| 25649 |
tejbeer |
641 |
Notification ns = new Notification();
|
|
|
642 |
SimpleCampaignParams scp = gson.fromJson(notificationCampaign.getImplementationParams(),
|
|
|
643 |
SimpleCampaignParams.class);
|
|
|
644 |
Campaign campaign = new SimpleCampaign(scp);
|
|
|
645 |
LocalDateTime expire = campaign.getExpireTimestamp();
|
|
|
646 |
ns.setCid(Integer.toString(notificationCampaign.getId()));
|
|
|
647 |
ns.setType(campaign.getType());
|
|
|
648 |
ns.setMessage(campaign.getMessage());
|
|
|
649 |
ns.setTitle(campaign.getTitle());
|
| 25651 |
tejbeer |
650 |
if (notificationCampaign.getDocumentId() != null) {
|
|
|
651 |
document = documentRepository.selectById(notificationCampaign.getDocumentId());
|
|
|
652 |
ns.setDocumentName(document.getDisplayName());
|
|
|
653 |
}
|
| 25683 |
tejbeer |
654 |
ns.setUrl(campaign.getUrl());
|
| 25649 |
tejbeer |
655 |
ns.setShowImage(campaign.getShowImage());
|
|
|
656 |
ns.setImageUrl(campaign.getImageUrl());
|
| 25683 |
tejbeer |
657 |
ns.setDocumentId(notificationCampaign.getDocumentId());
|
|
|
658 |
ns.setMessageType(notificationCampaign.getMessageType());
|
| 25649 |
tejbeer |
659 |
ns.setCreated(
|
|
|
660 |
notificationCampaign.getCreatedTimestamp().toEpochSecond(ZoneOffset.ofHoursMinutes(5, 30))
|
|
|
661 |
* 1000);
|
|
|
662 |
if (LocalDateTime.now().isAfter(expire)) {
|
|
|
663 |
ns.setExpired(true);
|
|
|
664 |
} else {
|
|
|
665 |
ns.setExpired(false);
|
|
|
666 |
}
|
|
|
667 |
notifications.add(ns);
|
|
|
668 |
}
|
|
|
669 |
}
|
| 25683 |
tejbeer |
670 |
} else {
|
|
|
671 |
for (NotificationCampaign notificationCampaign : nc) {
|
|
|
672 |
|
|
|
673 |
Notification ns = new Notification();
|
|
|
674 |
SimpleCampaignParams scp = gson.fromJson(notificationCampaign.getImplementationParams(),
|
|
|
675 |
SimpleCampaignParams.class);
|
|
|
676 |
Campaign campaign = new SimpleCampaign(scp);
|
|
|
677 |
LocalDateTime expire = campaign.getExpireTimestamp();
|
|
|
678 |
ns.setCid(Integer.toString(notificationCampaign.getId()));
|
|
|
679 |
ns.setType(campaign.getType());
|
|
|
680 |
ns.setMessage(campaign.getMessage());
|
|
|
681 |
ns.setTitle(campaign.getTitle());
|
|
|
682 |
if (notificationCampaign.getDocumentId() != null) {
|
|
|
683 |
document = documentRepository.selectById(notificationCampaign.getDocumentId());
|
|
|
684 |
ns.setDocumentName(document.getDisplayName());
|
|
|
685 |
}
|
|
|
686 |
ns.setUrl(campaign.getUrl());
|
|
|
687 |
ns.setShowImage(campaign.getShowImage());
|
|
|
688 |
ns.setImageUrl(campaign.getImageUrl());
|
|
|
689 |
ns.setDocumentId(notificationCampaign.getDocumentId());
|
|
|
690 |
ns.setMessageType(notificationCampaign.getMessageType());
|
|
|
691 |
ns.setCreated(notificationCampaign.getCreatedTimestamp().toEpochSecond(ZoneOffset.ofHoursMinutes(5, 30))
|
|
|
692 |
* 1000);
|
|
|
693 |
if (LocalDateTime.now().isAfter(expire)) {
|
|
|
694 |
ns.setExpired(true);
|
|
|
695 |
} else {
|
|
|
696 |
ns.setExpired(false);
|
|
|
697 |
}
|
|
|
698 |
notifications.add(ns);
|
|
|
699 |
}
|
|
|
700 |
|
| 25649 |
tejbeer |
701 |
}
|
| 25683 |
tejbeer |
702 |
return notifications;
|
| 25651 |
tejbeer |
703 |
|
|
|
704 |
}
|
| 25649 |
tejbeer |
705 |
|
| 25651 |
tejbeer |
706 |
@RequestMapping(value = "/notifyDocument/documentId", method = RequestMethod.GET)
|
|
|
707 |
public ResponseEntity<?> retailerDocumentById(HttpServletRequest request,
|
|
|
708 |
@RequestParam(name = ProfitMandiConstants.DOCUMENT_ID) int documentId, @RequestParam int cid)
|
|
|
709 |
throws ProfitMandiBusinessException {
|
|
|
710 |
Document document = documentRepository.selectById(documentId);
|
|
|
711 |
NotificationCampaign nc = notificationCampaignRepository.selectById(cid);
|
|
|
712 |
if (nc.getDocumentId() == null) {
|
|
|
713 |
throw new ProfitMandiBusinessException("cid", nc.getId(), "not available");
|
|
|
714 |
}
|
|
|
715 |
if (nc.getDocumentId() != documentId) {
|
|
|
716 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, documentId, "RTLR_1014");
|
|
|
717 |
}
|
|
|
718 |
return responseSender.ok(document);
|
| 25649 |
tejbeer |
719 |
}
|
|
|
720 |
|
| 25651 |
tejbeer |
721 |
@RequestMapping(value = "/notifyDocument/download", method = RequestMethod.GET)
|
|
|
722 |
public ResponseEntity<?> downloadRetailerDocument(HttpServletRequest request, @RequestParam int cid, Model model)
|
|
|
723 |
throws ProfitMandiBusinessException {
|
|
|
724 |
|
|
|
725 |
NotificationCampaign nc = notificationCampaignRepository.selectById(cid);
|
|
|
726 |
|
|
|
727 |
if (nc.getDocumentId() == null) {
|
|
|
728 |
throw new ProfitMandiBusinessException("cid", nc.getId(), "not available");
|
|
|
729 |
}
|
|
|
730 |
|
|
|
731 |
Document document = documentRepository.selectById(nc.getDocumentId());
|
|
|
732 |
|
|
|
733 |
FileInputStream file = null;
|
|
|
734 |
try {
|
|
|
735 |
file = new FileInputStream(document.getPath() + File.separator + document.getName());
|
|
|
736 |
} catch (FileNotFoundException e) {
|
|
|
737 |
LOGGER.error("Retailer Document file not found : ", e);
|
|
|
738 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.DOCUMENT_ID, document.getId(), "RTLR_1013");
|
|
|
739 |
}
|
|
|
740 |
// ByteArrayOutputStream byteArrayOutputStream = new
|
|
|
741 |
// ByteArrayOutputStream();
|
|
|
742 |
// ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
|
|
|
743 |
|
|
|
744 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
745 |
String contentType = "";
|
|
|
746 |
if (document.getContentType() == ContentType.JPEG) {
|
|
|
747 |
contentType = "image/jpeg";
|
|
|
748 |
} else if (document.getContentType() == ContentType.PNG) {
|
|
|
749 |
contentType = "image/png";
|
|
|
750 |
} else if (document.getContentType() == ContentType.PDF) {
|
|
|
751 |
contentType = "application/pdf";
|
|
|
752 |
}
|
|
|
753 |
headers.set("Content-Type", contentType);
|
|
|
754 |
headers.set("Content-disposition", "inline; filename=" + document.getName());
|
|
|
755 |
headers.setContentLength(document.getSize());
|
|
|
756 |
final InputStreamResource inputStreamResource = new InputStreamResource(file);
|
|
|
757 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
758 |
}
|
|
|
759 |
|
| 21615 |
kshitij.so |
760 |
}
|