| 21577 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 21612 |
ashik.ali |
3 |
import java.util.HashSet;
|
| 21577 |
ashik.ali |
4 |
import java.util.List;
|
| 21612 |
ashik.ali |
5 |
import java.util.Set;
|
| 21577 |
ashik.ali |
6 |
|
|
|
7 |
import javax.servlet.http.HttpServletRequest;
|
|
|
8 |
|
|
|
9 |
import org.slf4j.Logger;
|
|
|
10 |
import org.slf4j.LoggerFactory;
|
|
|
11 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
12 |
import org.springframework.stereotype.Controller;
|
|
|
13 |
import org.springframework.ui.Model;
|
| 21581 |
ashik.ali |
14 |
import org.springframework.ui.ModelMap;
|
| 21577 |
ashik.ali |
15 |
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
16 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
17 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
18 |
|
|
|
19 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 21612 |
ashik.ali |
20 |
import com.spice.profitmandi.common.model.CustomCurrentInventorySnapshot;
|
| 21577 |
ashik.ali |
21 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
22 |
import com.spice.profitmandi.dao.entity.FofoItemId;
|
|
|
23 |
import com.spice.profitmandi.dao.repository.CurrentInventorySnapshotRepository;
|
|
|
24 |
import com.spice.profitmandi.web.model.FofoDetails;
|
|
|
25 |
import com.spice.profitmandi.web.util.CookiesFetcher;
|
|
|
26 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
|
|
27 |
|
|
|
28 |
@Controller
|
|
|
29 |
public class InventoryController {
|
|
|
30 |
|
|
|
31 |
private static final Logger LOGGER = LoggerFactory.getLogger(InventoryController.class);
|
|
|
32 |
|
|
|
33 |
@Autowired
|
|
|
34 |
CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
|
|
35 |
|
|
|
36 |
@Autowired
|
|
|
37 |
MVCResponseSender mvcResponseSender;
|
|
|
38 |
|
|
|
39 |
@Autowired
|
|
|
40 |
CookiesFetcher cookiesFetcher;
|
|
|
41 |
|
|
|
42 |
@RequestMapping(value = "/checkCurrentAvailability")
|
| 21581 |
ashik.ali |
43 |
public String getCurrentAvailability(HttpServletRequest request, @ModelAttribute ModelMap model) throws Exception{
|
| 21577 |
ashik.ali |
44 |
FofoDetails fofoDetails;
|
|
|
45 |
try {
|
|
|
46 |
fofoDetails = cookiesFetcher.getCookiesObject(request);
|
|
|
47 |
} catch (ProfitMandiBusinessException e) {
|
| 21581 |
ashik.ali |
48 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
49 |
return "response";
|
| 21577 |
ashik.ali |
50 |
}
|
| 21612 |
ashik.ali |
51 |
List<Object[]> rows = currentInventorySnapshotRepository.selectCustomByFofoId(fofoDetails.getFofoId());
|
|
|
52 |
|
|
|
53 |
model.addAttribute("currentInventorySnapshots", this.getCustomCurrentInventorySnapshots(rows));
|
|
|
54 |
return "dashboard";
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
private Set<CustomCurrentInventorySnapshot> getCustomCurrentInventorySnapshots(List<Object[]> rows){
|
|
|
58 |
Set<CustomCurrentInventorySnapshot> currentInventorySnapshots = new HashSet<>();
|
|
|
59 |
for(Object[] row : rows){
|
|
|
60 |
currentInventorySnapshots.add(this.createCustomCurrentInventorySnapshop(row));
|
| 21577 |
ashik.ali |
61 |
}
|
| 21612 |
ashik.ali |
62 |
return currentInventorySnapshots;
|
| 21577 |
ashik.ali |
63 |
}
|
|
|
64 |
|
| 21612 |
ashik.ali |
65 |
private CustomCurrentInventorySnapshot createCustomCurrentInventorySnapshop(Object[] row)
|
|
|
66 |
{
|
|
|
67 |
CustomCurrentInventorySnapshot currentInventorySnapshot = new CustomCurrentInventorySnapshot();
|
|
|
68 |
currentInventorySnapshot.setItemId((Integer)row[0]);
|
|
|
69 |
currentInventorySnapshot.setAvailability((Integer)row[1]);
|
|
|
70 |
currentInventorySnapshot.setBrand((String)row[2]);
|
|
|
71 |
currentInventorySnapshot.setModelName((String)row[3]);
|
|
|
72 |
currentInventorySnapshot.setModelNumber((String)row[4]);
|
|
|
73 |
currentInventorySnapshot.setColor((String)row[5]);
|
|
|
74 |
return currentInventorySnapshot;
|
|
|
75 |
}
|
| 21577 |
ashik.ali |
76 |
@RequestMapping(value = "/checkItemAvailability")
|
|
|
77 |
public String getItemAvailability(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ITEM_ID) int itemId, @ModelAttribute Model model) throws Exception{
|
|
|
78 |
FofoDetails fofoDetails;
|
|
|
79 |
try {
|
|
|
80 |
fofoDetails = cookiesFetcher.getCookiesObject(request);
|
|
|
81 |
} catch (ProfitMandiBusinessException e) {
|
| 21581 |
ashik.ali |
82 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
83 |
return "response";
|
| 21577 |
ashik.ali |
84 |
}
|
|
|
85 |
try{
|
|
|
86 |
FofoItemId fofoItemId = new FofoItemId();
|
|
|
87 |
fofoItemId.setFofoId(fofoDetails.getFofoId());
|
|
|
88 |
fofoItemId.setItemId(itemId);
|
| 21612 |
ashik.ali |
89 |
Object[] row = currentInventorySnapshotRepository.selectCustomByFofoItemId(fofoItemId);
|
|
|
90 |
model.addAttribute("currentInventorySnapshots", this.createCustomCurrentInventorySnapshop(row));
|
| 21577 |
ashik.ali |
91 |
return "dashboard";
|
|
|
92 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| 21581 |
ashik.ali |
93 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("INVNTRY_SNPSHT", false, "/dashboard"));
|
|
|
94 |
return "response";
|
| 21577 |
ashik.ali |
95 |
}
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
}
|