| 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;
|
| 25152 |
amit.gupta |
7 |
import java.util.Arrays;
|
| 25157 |
amit.gupta |
8 |
import java.util.HashMap;
|
| 25136 |
amit.gupta |
9 |
import java.util.LinkedHashMap;
|
| 23884 |
amit.gupta |
10 |
import java.util.List;
|
| 24880 |
govind |
11 |
import java.util.Map;
|
|
|
12 |
import java.util.stream.Collectors;
|
| 23568 |
govind |
13 |
|
| 22086 |
amit.gupta |
14 |
import javax.servlet.http.HttpServletRequest;
|
|
|
15 |
|
| 23786 |
amit.gupta |
16 |
import org.apache.logging.log4j.LogManager;
|
| 23568 |
govind |
17 |
import org.apache.logging.log4j.Logger;
|
| 22481 |
ashik.ali |
18 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23379 |
ashik.ali |
19 |
import org.springframework.beans.factory.annotation.Value;
|
| 21615 |
kshitij.so |
20 |
import org.springframework.stereotype.Controller;
|
| 22481 |
ashik.ali |
21 |
import org.springframework.transaction.annotation.Transactional;
|
| 22073 |
ashik.ali |
22 |
import org.springframework.ui.Model;
|
| 21615 |
kshitij.so |
23 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
24 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
25 |
|
| 24996 |
amit.gupta |
26 |
import com.mongodb.DBObject;
|
| 25152 |
amit.gupta |
27 |
import com.spice.profitmandi.common.enumuration.ItemType;
|
| 22481 |
ashik.ali |
28 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 24996 |
amit.gupta |
29 |
import com.spice.profitmandi.common.model.BrandStockPrice;
|
| 25152 |
amit.gupta |
30 |
import com.spice.profitmandi.common.model.InventoryItemAgingModel;
|
| 24203 |
amit.gupta |
31 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 24880 |
govind |
32 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
|
| 22654 |
ashik.ali |
33 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 24288 |
amit.gupta |
34 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| 24880 |
govind |
35 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 25170 |
amit.gupta |
36 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 22481 |
ashik.ali |
37 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 24880 |
govind |
38 |
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
|
|
|
39 |
import com.spice.profitmandi.dao.repository.dtr.InsuranceProviderRepository;
|
| 24996 |
amit.gupta |
40 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 24098 |
tejbeer |
41 |
import com.spice.profitmandi.dao.repository.dtr.NotificationPanelRepository;
|
| 24880 |
govind |
42 |
import com.spice.profitmandi.dao.repository.dtr.RechargeTransactionRepository;
|
| 24203 |
amit.gupta |
43 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
| 24880 |
govind |
44 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
| 24288 |
amit.gupta |
45 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| 24336 |
amit.gupta |
46 |
import com.spice.profitmandi.service.PartnerInvestmentService;
|
| 23844 |
amit.gupta |
47 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 23884 |
amit.gupta |
48 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
|
|
49 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
| 22481 |
ashik.ali |
50 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
51 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 24263 |
tejbeer |
52 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 22481 |
ashik.ali |
53 |
|
| 21615 |
kshitij.so |
54 |
@Controller
|
| 22481 |
ashik.ali |
55 |
@Transactional(rollbackFor = Throwable.class)
|
| 21615 |
kshitij.so |
56 |
public class DashboardController {
|
| 23923 |
amit.gupta |
57 |
|
| 23379 |
ashik.ali |
58 |
@Value("${web.api.host}")
|
|
|
59 |
private String webApiHost;
|
| 23923 |
amit.gupta |
60 |
|
| 24072 |
amit.gupta |
61 |
@Value("${web.api.scheme}")
|
|
|
62 |
private String webApiScheme;
|
| 24288 |
amit.gupta |
63 |
|
| 24078 |
amit.gupta |
64 |
@Value("${web.api.root}")
|
|
|
65 |
private String webApiRoot;
|
|
|
66 |
|
| 23379 |
ashik.ali |
67 |
@Value("${web.api.port}")
|
|
|
68 |
private int webApiPort;
|
| 21615 |
kshitij.so |
69 |
|
| 22481 |
ashik.ali |
70 |
@Autowired
|
| 22927 |
ashik.ali |
71 |
private CookiesProcessor cookiesProcessor;
|
| 23923 |
amit.gupta |
72 |
|
| 23568 |
govind |
73 |
@Autowired
|
| 24880 |
govind |
74 |
private ItemRepository itemRepository;
|
|
|
75 |
|
|
|
76 |
@Autowired
|
| 23786 |
amit.gupta |
77 |
private RoleManager roleManager;
|
| 23923 |
amit.gupta |
78 |
|
| 23838 |
ashik.ali |
79 |
@Autowired
|
|
|
80 |
private FofoStoreRepository fofoStoreRepository;
|
| 23884 |
amit.gupta |
81 |
|
|
|
82 |
@Autowired
|
| 24880 |
govind |
83 |
private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
| 23923 |
amit.gupta |
84 |
|
| 23884 |
amit.gupta |
85 |
@Autowired
|
| 24880 |
govind |
86 |
private PartnerInvestmentService partnerInvestmentService;
|
| 24288 |
amit.gupta |
87 |
|
| 23884 |
amit.gupta |
88 |
@Autowired
|
| 24880 |
govind |
89 |
private InsurancePolicyRepository insurancePolicyRepository;
|
| 23923 |
amit.gupta |
90 |
/*
|
|
|
91 |
* @Autowired private ScanRepository scanRepository;
|
|
|
92 |
*/
|
| 24880 |
govind |
93 |
@Autowired
|
|
|
94 |
private RechargeTransactionRepository rechargeTransactionRepository;
|
| 23923 |
amit.gupta |
95 |
|
| 23884 |
amit.gupta |
96 |
@Autowired
|
|
|
97 |
private TransactionService transactionService;
|
| 25136 |
amit.gupta |
98 |
|
| 24996 |
amit.gupta |
99 |
@Autowired
|
|
|
100 |
private InventoryService inventoryService;
|
| 24263 |
tejbeer |
101 |
|
| 24098 |
tejbeer |
102 |
@Autowired
|
| 24263 |
tejbeer |
103 |
private MVCResponseSender mvcResponseSender;
|
|
|
104 |
|
|
|
105 |
@Autowired
|
| 24098 |
tejbeer |
106 |
private NotificationPanelRepository notificationPanelRepository;
|
| 23923 |
amit.gupta |
107 |
|
| 24203 |
amit.gupta |
108 |
@Autowired
|
|
|
109 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
|
|
110 |
|
| 24880 |
govind |
111 |
@Autowired
|
|
|
112 |
private FofoOrderItemRepository fofoOrderItemRepository;
|
|
|
113 |
|
|
|
114 |
@Autowired
|
|
|
115 |
private InsuranceProviderRepository insuranceProviderRepository;
|
| 25136 |
amit.gupta |
116 |
|
| 24996 |
amit.gupta |
117 |
@Autowired
|
|
|
118 |
private Mongo mongoClient;
|
| 24880 |
govind |
119 |
|
| 23568 |
govind |
120 |
private static final Logger LOGGER = LogManager.getLogger(DashboardController.class);
|
| 23923 |
amit.gupta |
121 |
|
| 25136 |
amit.gupta |
122 |
@RequestMapping(value = "/12dashboard34", method = RequestMethod.GET)
|
| 25140 |
amit.gupta |
123 |
public String dashboard1(HttpServletRequest request, Model model) throws Exception {
|
| 25136 |
amit.gupta |
124 |
LOGGER.info("In Dashboard1");
|
|
|
125 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 25140 |
amit.gupta |
126 |
model.addAttribute("brandStockPrices", this.getBrandStockPrices(loginDetails.getFofoId()));
|
|
|
127 |
model.addAttribute("salesMap", this.getSales(loginDetails.getFofoId()));
|
| 25136 |
amit.gupta |
128 |
model.addAttribute("investments", this.getInvestments(loginDetails.getFofoId()));
|
|
|
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());
|
|
|
150 |
investments.put("minimum", investment.getMinInvestment());
|
|
|
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);
|
| 25152 |
amit.gupta |
174 |
List<InventoryItemAgingModel> models = inventoryService.getItemAgingByInterval(fofoId, Arrays.asList(30));
|
| 25170 |
amit.gupta |
175 |
|
|
|
176 |
|
| 25164 |
amit.gupta |
177 |
Map<String, Integer> brandWiseQty = models.stream()
|
| 25168 |
amit.gupta |
178 |
.filter(x -> ItemType.SERIALIZED.toString().equals(x.getItemType()) && x.getValues().get(1)!=null)
|
| 25166 |
amit.gupta |
179 |
.collect(Collectors.groupingBy(x -> x.getBrand(), Collectors.summingInt(x ->
|
| 25168 |
amit.gupta |
180 |
x.getValues().get(1).getQuantity())));
|
| 25156 |
amit.gupta |
181 |
Map<String, Double> brandWiseValue = models.stream()
|
| 25168 |
amit.gupta |
182 |
.filter(x -> x.getItemType().equals(ItemType.SERIALIZED.toString()) && x.getValues().get(1)!=null)
|
| 25166 |
amit.gupta |
183 |
.collect(Collectors.groupingBy(x -> x.getBrand(), Collectors.summingDouble(x ->
|
| 25168 |
amit.gupta |
184 |
x.getValues().get(1).getQuantity() * x.getValues().get(1).getPrice())));
|
| 25164 |
amit.gupta |
185 |
|
| 25140 |
amit.gupta |
186 |
List<DBObject> mobileBrands = mongoClient.getMongoBrands(fofoId, "", 3);
|
| 25136 |
amit.gupta |
187 |
List<BrandStockPrice> brandStockPrices = new ArrayList<>();
|
| 25156 |
amit.gupta |
188 |
|
| 25164 |
amit.gupta |
189 |
// Map<String, Integer> brandWiseQty = new HashMap<String, Integer>();
|
|
|
190 |
// Map<String, Double> brandWiseValue = new HashMap<String, Double>();
|
| 25140 |
amit.gupta |
191 |
mobileBrands.stream().forEach(x -> {
|
|
|
192 |
String brand = (String) x.get("name");
|
|
|
193 |
if (brandStockPricesMap.containsKey(brand)) {
|
|
|
194 |
BrandStockPrice brandStockPrice = brandStockPricesMap.get(brand);
|
| 25156 |
amit.gupta |
195 |
if (brandWiseQty.get(brand) != null) {
|
|
|
196 |
brandStockPrice.setAgedQty(brandWiseQty.get(brand));
|
|
|
197 |
brandStockPrice.setAgedValue(brandWiseValue.get(brand));
|
|
|
198 |
}
|
| 25140 |
amit.gupta |
199 |
brandStockPrice.setBrandUrl((String) x.get("url"));
|
|
|
200 |
brandStockPrice.setRank(((Double) x.get("rank")).intValue());
|
|
|
201 |
brandStockPrices.add(brandStockPrice);
|
|
|
202 |
} else {
|
|
|
203 |
}
|
|
|
204 |
});
|
|
|
205 |
|
|
|
206 |
return brandStockPrices.stream().sorted((x, y) -> y.getRank() - x.getRank()).collect(Collectors.toList());
|
| 25136 |
amit.gupta |
207 |
}
|
|
|
208 |
|
| 21615 |
kshitij.so |
209 |
@RequestMapping(value = "/dashboard", method = RequestMethod.GET)
|
| 25156 |
amit.gupta |
210 |
public String dashboard(HttpServletRequest request, Model model) throws Exception {
|
| 25140 |
amit.gupta |
211 |
|
| 22927 |
ashik.ali |
212 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23923 |
amit.gupta |
213 |
|
| 22481 |
ashik.ali |
214 |
FofoStore fofoStore = null;
|
|
|
215 |
try {
|
| 22927 |
ashik.ali |
216 |
fofoStore = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
|
| 22481 |
ashik.ali |
217 |
} catch (ProfitMandiBusinessException e) {
|
| 22927 |
ashik.ali |
218 |
LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
|
| 22481 |
ashik.ali |
219 |
}
|
| 23848 |
ashik.ali |
220 |
model.addAttribute("fofoStore", fofoStore);
|
| 25140 |
amit.gupta |
221 |
model.addAttribute("isAdmin", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 23379 |
ashik.ali |
222 |
model.addAttribute("webApiHost", webApiHost);
|
|
|
223 |
model.addAttribute("webApiPort", webApiPort);
|
| 24072 |
amit.gupta |
224 |
model.addAttribute("webApiScheme", webApiScheme);
|
| 24077 |
amit.gupta |
225 |
model.addAttribute("webApiRoot", webApiRoot);
|
| 24203 |
amit.gupta |
226 |
model.addAttribute("hasGift", hasGift(loginDetails.getFofoId()));
|
|
|
227 |
model.addAttribute("giftItemId", ProfitMandiConstants.GIFT_ID);
|
| 24098 |
tejbeer |
228 |
|
| 25140 |
amit.gupta |
229 |
model.addAttribute("brandStockPrices", this.getBrandStockPrices(loginDetails.getFofoId()));
|
|
|
230 |
model.addAttribute("salesMap", this.getSales(loginDetails.getFofoId()));
|
|
|
231 |
model.addAttribute("investments", this.getInvestments(loginDetails.getFofoId()));
|
|
|
232 |
model.addAttribute("isInvestmentOk", partnerInvestmentService.isInvestmentOk(loginDetails.getFofoId(), 10, 30));
|
|
|
233 |
return "dashboard1";
|
| 21615 |
kshitij.so |
234 |
}
|
| 23923 |
amit.gupta |
235 |
|
| 24288 |
amit.gupta |
236 |
// This method is currently hardcoded to faciliate watches sold as gift.
|
| 24203 |
amit.gupta |
237 |
private boolean hasGift(int fofoId) {
|
|
|
238 |
try {
|
| 24288 |
amit.gupta |
239 |
return currentInventorySnapshotRepository.selectByItemIdAndFofoId(ProfitMandiConstants.GIFT_ID, fofoId)
|
|
|
240 |
.getAvailability() > 0;
|
| 24203 |
amit.gupta |
241 |
} catch (ProfitMandiBusinessException e) {
|
|
|
242 |
return false;
|
|
|
243 |
}
|
|
|
244 |
}
|
| 24288 |
amit.gupta |
245 |
|
| 22354 |
ashik.ali |
246 |
@RequestMapping(value = "/contactUs", method = RequestMethod.GET)
|
| 23923 |
amit.gupta |
247 |
public String contactUs(HttpServletRequest request, Model model) throws Throwable {
|
| 22354 |
ashik.ali |
248 |
model.addAttribute("appContextPath", request.getContextPath());
|
|
|
249 |
return "contact-us";
|
|
|
250 |
}
|
| 23923 |
amit.gupta |
251 |
|
| 21615 |
kshitij.so |
252 |
}
|