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