| 21615 |
kshitij.so |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 24288 |
amit.gupta |
3 |
import java.time.LocalDate;
|
| 24276 |
amit.gupta |
4 |
import java.time.LocalDateTime;
|
| 24880 |
govind |
5 |
import java.time.LocalTime;
|
| 24339 |
amit.gupta |
6 |
import java.util.ArrayList;
|
| 25136 |
amit.gupta |
7 |
import java.util.LinkedHashMap;
|
| 23884 |
amit.gupta |
8 |
import java.util.List;
|
| 24880 |
govind |
9 |
import java.util.Map;
|
|
|
10 |
import java.util.stream.Collectors;
|
| 23568 |
govind |
11 |
|
| 22086 |
amit.gupta |
12 |
import javax.servlet.http.HttpServletRequest;
|
|
|
13 |
|
| 23786 |
amit.gupta |
14 |
import org.apache.logging.log4j.LogManager;
|
| 23568 |
govind |
15 |
import org.apache.logging.log4j.Logger;
|
| 22481 |
ashik.ali |
16 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23379 |
ashik.ali |
17 |
import org.springframework.beans.factory.annotation.Value;
|
| 21615 |
kshitij.so |
18 |
import org.springframework.stereotype.Controller;
|
| 22481 |
ashik.ali |
19 |
import org.springframework.transaction.annotation.Transactional;
|
| 22073 |
ashik.ali |
20 |
import org.springframework.ui.Model;
|
| 21615 |
kshitij.so |
21 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
22 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
23 |
|
| 24996 |
amit.gupta |
24 |
import com.mongodb.DBObject;
|
| 22481 |
ashik.ali |
25 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 24996 |
amit.gupta |
26 |
import com.spice.profitmandi.common.model.BrandStockPrice;
|
| 24203 |
amit.gupta |
27 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 24880 |
govind |
28 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
|
| 22654 |
ashik.ali |
29 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 24288 |
amit.gupta |
30 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| 24880 |
govind |
31 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 22481 |
ashik.ali |
32 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 24880 |
govind |
33 |
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
|
|
|
34 |
import com.spice.profitmandi.dao.repository.dtr.InsuranceProviderRepository;
|
| 24996 |
amit.gupta |
35 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 24098 |
tejbeer |
36 |
import com.spice.profitmandi.dao.repository.dtr.NotificationPanelRepository;
|
| 24880 |
govind |
37 |
import com.spice.profitmandi.dao.repository.dtr.RechargeTransactionRepository;
|
| 24203 |
amit.gupta |
38 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
| 24880 |
govind |
39 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
| 24288 |
amit.gupta |
40 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| 24336 |
amit.gupta |
41 |
import com.spice.profitmandi.service.PartnerInvestmentService;
|
| 23844 |
amit.gupta |
42 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 23884 |
amit.gupta |
43 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
|
|
44 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
| 22481 |
ashik.ali |
45 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
46 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 24263 |
tejbeer |
47 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 22481 |
ashik.ali |
48 |
|
| 21615 |
kshitij.so |
49 |
@Controller
|
| 22481 |
ashik.ali |
50 |
@Transactional(rollbackFor = Throwable.class)
|
| 21615 |
kshitij.so |
51 |
public class DashboardController {
|
| 23923 |
amit.gupta |
52 |
|
| 23379 |
ashik.ali |
53 |
@Value("${web.api.host}")
|
|
|
54 |
private String webApiHost;
|
| 23923 |
amit.gupta |
55 |
|
| 24072 |
amit.gupta |
56 |
@Value("${web.api.scheme}")
|
|
|
57 |
private String webApiScheme;
|
| 24288 |
amit.gupta |
58 |
|
| 24078 |
amit.gupta |
59 |
@Value("${web.api.root}")
|
|
|
60 |
private String webApiRoot;
|
|
|
61 |
|
| 23379 |
ashik.ali |
62 |
@Value("${web.api.port}")
|
|
|
63 |
private int webApiPort;
|
| 21615 |
kshitij.so |
64 |
|
| 22481 |
ashik.ali |
65 |
@Autowired
|
| 22927 |
ashik.ali |
66 |
private CookiesProcessor cookiesProcessor;
|
| 23923 |
amit.gupta |
67 |
|
| 23568 |
govind |
68 |
@Autowired
|
| 24880 |
govind |
69 |
private ItemRepository itemRepository;
|
|
|
70 |
|
|
|
71 |
@Autowired
|
| 23786 |
amit.gupta |
72 |
private RoleManager roleManager;
|
| 23923 |
amit.gupta |
73 |
|
| 23838 |
ashik.ali |
74 |
@Autowired
|
|
|
75 |
private FofoStoreRepository fofoStoreRepository;
|
| 23884 |
amit.gupta |
76 |
|
|
|
77 |
@Autowired
|
| 24880 |
govind |
78 |
private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
| 23923 |
amit.gupta |
79 |
|
| 23884 |
amit.gupta |
80 |
@Autowired
|
| 24880 |
govind |
81 |
private PartnerInvestmentService partnerInvestmentService;
|
| 24288 |
amit.gupta |
82 |
|
| 23884 |
amit.gupta |
83 |
@Autowired
|
| 24880 |
govind |
84 |
private InsurancePolicyRepository insurancePolicyRepository;
|
| 23923 |
amit.gupta |
85 |
/*
|
|
|
86 |
* @Autowired private ScanRepository scanRepository;
|
|
|
87 |
*/
|
| 24880 |
govind |
88 |
@Autowired
|
|
|
89 |
private RechargeTransactionRepository rechargeTransactionRepository;
|
| 23923 |
amit.gupta |
90 |
|
| 23884 |
amit.gupta |
91 |
@Autowired
|
|
|
92 |
private TransactionService transactionService;
|
| 25136 |
amit.gupta |
93 |
|
| 24996 |
amit.gupta |
94 |
@Autowired
|
|
|
95 |
private InventoryService inventoryService;
|
| 24263 |
tejbeer |
96 |
|
| 24098 |
tejbeer |
97 |
@Autowired
|
| 24263 |
tejbeer |
98 |
private MVCResponseSender mvcResponseSender;
|
|
|
99 |
|
|
|
100 |
@Autowired
|
| 24098 |
tejbeer |
101 |
private NotificationPanelRepository notificationPanelRepository;
|
| 23923 |
amit.gupta |
102 |
|
| 24203 |
amit.gupta |
103 |
@Autowired
|
|
|
104 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
|
|
105 |
|
| 24880 |
govind |
106 |
@Autowired
|
|
|
107 |
private FofoOrderItemRepository fofoOrderItemRepository;
|
|
|
108 |
|
|
|
109 |
@Autowired
|
|
|
110 |
private InsuranceProviderRepository insuranceProviderRepository;
|
| 25136 |
amit.gupta |
111 |
|
| 24996 |
amit.gupta |
112 |
@Autowired
|
|
|
113 |
private Mongo mongoClient;
|
| 24880 |
govind |
114 |
|
| 23568 |
govind |
115 |
private static final Logger LOGGER = LogManager.getLogger(DashboardController.class);
|
| 23923 |
amit.gupta |
116 |
|
| 25136 |
amit.gupta |
117 |
@RequestMapping(value = "/12dashboard34", method = RequestMethod.GET)
|
| 25140 |
amit.gupta |
118 |
public String dashboard1(HttpServletRequest request, Model model) throws Exception {
|
| 25136 |
amit.gupta |
119 |
LOGGER.info("In Dashboard1");
|
|
|
120 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 25179 |
amit.gupta |
121 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
122 |
model.addAttribute("isAdmin", isAdmin);
|
| 25180 |
amit.gupta |
123 |
if (!isAdmin) {
|
| 25179 |
amit.gupta |
124 |
model.addAttribute("brandStockPrices", this.getBrandStockPrices(loginDetails.getFofoId()));
|
|
|
125 |
model.addAttribute("salesMap", this.getSales(loginDetails.getFofoId()));
|
|
|
126 |
model.addAttribute("investments", this.getInvestments(loginDetails.getFofoId()));
|
|
|
127 |
return "dashboard1";
|
|
|
128 |
}
|
| 25136 |
amit.gupta |
129 |
return "dashboard1";
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
private Map<String, Object> getInvestments(int fofoId) throws Exception {
|
|
|
133 |
Map<String, Object> investments = new LinkedHashMap<>();
|
|
|
134 |
PartnerDailyInvestment investment = partnerInvestmentService.getInvestment(fofoId, 1);
|
|
|
135 |
LocalDate currentMonthStart = LocalDate.now().withDayOfMonth(1);
|
|
|
136 |
LocalDate yesterDate = LocalDate.now().minusDays(1);
|
|
|
137 |
PartnerDailyInvestment yesterdayInvestment = partnerDailyInvestmentRepository.select(fofoId, yesterDate);
|
|
|
138 |
if (yesterdayInvestment == null) {
|
|
|
139 |
yesterdayInvestment = new PartnerDailyInvestment();
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
List<PartnerDailyInvestment> currentMonthInvestments = partnerDailyInvestmentRepository.selectAll(fofoId,
|
|
|
143 |
currentMonthStart, currentMonthStart.withDayOfMonth(currentMonthStart.lengthOfMonth()));
|
|
|
144 |
|
| 25140 |
amit.gupta |
145 |
long okInvestmentDays = currentMonthInvestments.stream().filter(x -> x.getShortPercentage() <= 10)
|
| 25136 |
amit.gupta |
146 |
.collect(Collectors.counting());
|
| 25140 |
amit.gupta |
147 |
investments.put("today", investment.getTotalInvestment());
|
|
|
148 |
investments.put("investment", investment);
|
|
|
149 |
investments.put("inStock", investment.getInStockAmount());
|
| 25182 |
amit.gupta |
150 |
investments.put("minimum", investment.getMinInvestmentString());
|
| 25140 |
amit.gupta |
151 |
investments.put("short", investment.getShortPercentage());
|
|
|
152 |
investments.put("okDays", okInvestmentDays);
|
| 25136 |
amit.gupta |
153 |
return investments;
|
|
|
154 |
}
|
|
|
155 |
|
| 25140 |
amit.gupta |
156 |
private Map<String, Double> getSales(int fofoId) {
|
|
|
157 |
Map<String, Double> salesMap = new LinkedHashMap<>();
|
|
|
158 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
|
|
159 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectBetweenCreatedTime(fofoId, curDate,
|
|
|
160 |
curDate.with(LocalTime.MAX));
|
|
|
161 |
List<FofoOrderItem> mtdFofoOrderItems = fofoOrderItemRepository.selectBetweenCreatedTime(fofoId,
|
|
|
162 |
curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX));
|
|
|
163 |
double todaySale = fofoOrderItems.stream()
|
|
|
164 |
.collect(Collectors.summingDouble(x -> x.getSellingPrice() * x.getQuantity()));
|
|
|
165 |
double mtdSale = mtdFofoOrderItems.stream()
|
|
|
166 |
.collect(Collectors.summingDouble(x -> x.getSellingPrice() * x.getQuantity()));
|
|
|
167 |
salesMap.put("todaySale", todaySale);
|
|
|
168 |
salesMap.put("mtdSale", mtdSale);
|
| 25136 |
amit.gupta |
169 |
return salesMap;
|
|
|
170 |
}
|
|
|
171 |
|
| 25152 |
amit.gupta |
172 |
private List<BrandStockPrice> getBrandStockPrices(int fofoId) throws Exception {
|
| 25140 |
amit.gupta |
173 |
Map<String, BrandStockPrice> brandStockPricesMap = inventoryService.getBrandWiseStockValue(fofoId);
|
| 25175 |
amit.gupta |
174 |
|
| 25140 |
amit.gupta |
175 |
List<DBObject> mobileBrands = mongoClient.getMongoBrands(fofoId, "", 3);
|
| 25136 |
amit.gupta |
176 |
List<BrandStockPrice> brandStockPrices = new ArrayList<>();
|
| 25156 |
amit.gupta |
177 |
|
| 25140 |
amit.gupta |
178 |
mobileBrands.stream().forEach(x -> {
|
|
|
179 |
String brand = (String) x.get("name");
|
|
|
180 |
if (brandStockPricesMap.containsKey(brand)) {
|
|
|
181 |
BrandStockPrice brandStockPrice = brandStockPricesMap.get(brand);
|
|
|
182 |
brandStockPrice.setBrandUrl((String) x.get("url"));
|
|
|
183 |
brandStockPrice.setRank(((Double) x.get("rank")).intValue());
|
|
|
184 |
brandStockPrices.add(brandStockPrice);
|
|
|
185 |
}
|
|
|
186 |
});
|
|
|
187 |
|
| 25175 |
amit.gupta |
188 |
return brandStockPrices.stream().filter(x -> x.getTotalQty() > 0).sorted((x, y) -> x.getRank() - y.getRank())
|
|
|
189 |
.collect(Collectors.toList());
|
| 25136 |
amit.gupta |
190 |
}
|
|
|
191 |
|
| 21615 |
kshitij.so |
192 |
@RequestMapping(value = "/dashboard", method = RequestMethod.GET)
|
| 25156 |
amit.gupta |
193 |
public String dashboard(HttpServletRequest request, Model model) throws Exception {
|
| 25140 |
amit.gupta |
194 |
|
| 22927 |
ashik.ali |
195 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 25180 |
amit.gupta |
196 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
197 |
model.addAttribute("isAdmin", isAdmin);
|
| 23923 |
amit.gupta |
198 |
|
| 22481 |
ashik.ali |
199 |
FofoStore fofoStore = null;
|
| 25182 |
amit.gupta |
200 |
if (!isAdmin) {
|
| 25180 |
amit.gupta |
201 |
return "dashboard1";
|
|
|
202 |
} else {
|
|
|
203 |
try {
|
|
|
204 |
fofoStore = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
|
|
|
205 |
model.addAttribute("fofoStore", fofoStore);
|
|
|
206 |
model.addAttribute("webApiHost", webApiHost);
|
|
|
207 |
model.addAttribute("webApiPort", webApiPort);
|
|
|
208 |
model.addAttribute("webApiScheme", webApiScheme);
|
|
|
209 |
model.addAttribute("webApiRoot", webApiRoot);
|
|
|
210 |
model.addAttribute("hasGift", hasGift(loginDetails.getFofoId()));
|
|
|
211 |
model.addAttribute("giftItemId", ProfitMandiConstants.GIFT_ID);
|
|
|
212 |
|
|
|
213 |
model.addAttribute("brandStockPrices", this.getBrandStockPrices(loginDetails.getFofoId()));
|
|
|
214 |
model.addAttribute("salesMap", this.getSales(loginDetails.getFofoId()));
|
|
|
215 |
model.addAttribute("investments", this.getInvestments(loginDetails.getFofoId()));
|
|
|
216 |
model.addAttribute("isInvestmentOk",
|
|
|
217 |
partnerInvestmentService.isInvestmentOk(loginDetails.getFofoId(), 10, 30));
|
|
|
218 |
} catch (ProfitMandiBusinessException e) {
|
|
|
219 |
LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
|
|
|
220 |
|
|
|
221 |
}
|
| 22481 |
ashik.ali |
222 |
}
|
| 25182 |
amit.gupta |
223 |
model.addAttribute("monthDays", LocalDate.now().lengthOfMonth());
|
| 25140 |
amit.gupta |
224 |
return "dashboard1";
|
| 21615 |
kshitij.so |
225 |
}
|
| 23923 |
amit.gupta |
226 |
|
| 24288 |
amit.gupta |
227 |
// This method is currently hardcoded to faciliate watches sold as gift.
|
| 24203 |
amit.gupta |
228 |
private boolean hasGift(int fofoId) {
|
|
|
229 |
try {
|
| 24288 |
amit.gupta |
230 |
return currentInventorySnapshotRepository.selectByItemIdAndFofoId(ProfitMandiConstants.GIFT_ID, fofoId)
|
|
|
231 |
.getAvailability() > 0;
|
| 24203 |
amit.gupta |
232 |
} catch (ProfitMandiBusinessException e) {
|
|
|
233 |
return false;
|
|
|
234 |
}
|
|
|
235 |
}
|
| 24288 |
amit.gupta |
236 |
|
| 22354 |
ashik.ali |
237 |
@RequestMapping(value = "/contactUs", method = RequestMethod.GET)
|
| 23923 |
amit.gupta |
238 |
public String contactUs(HttpServletRequest request, Model model) throws Throwable {
|
| 22354 |
ashik.ali |
239 |
model.addAttribute("appContextPath", request.getContextPath());
|
|
|
240 |
return "contact-us";
|
|
|
241 |
}
|
| 23923 |
amit.gupta |
242 |
|
| 21615 |
kshitij.so |
243 |
}
|