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