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