| 22860 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 23020 |
ashik.ali |
3 |
import java.io.ByteArrayInputStream;
|
|
|
4 |
import java.io.ByteArrayOutputStream;
|
|
|
5 |
import java.io.InputStream;
|
|
|
6 |
import java.time.LocalDateTime;
|
| 23556 |
amit.gupta |
7 |
import java.util.Arrays;
|
|
|
8 |
import java.util.HashSet;
|
| 22860 |
ashik.ali |
9 |
import java.util.List;
|
| 23020 |
ashik.ali |
10 |
import java.util.Map;
|
| 22860 |
ashik.ali |
11 |
|
|
|
12 |
import javax.servlet.http.HttpServletRequest;
|
|
|
13 |
|
| 23568 |
govind |
14 |
import org.apache.logging.log4j.Logger;
|
|
|
15 |
import org.apache.logging.log4j.LogManager;
|
| 22860 |
ashik.ali |
16 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23020 |
ashik.ali |
17 |
import org.springframework.core.io.InputStreamResource;
|
|
|
18 |
import org.springframework.http.HttpHeaders;
|
|
|
19 |
import org.springframework.http.HttpStatus;
|
|
|
20 |
import org.springframework.http.ResponseEntity;
|
| 22860 |
ashik.ali |
21 |
import org.springframework.stereotype.Controller;
|
|
|
22 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
23 |
import org.springframework.ui.Model;
|
|
|
24 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
25 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
26 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
27 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
28 |
|
| 23020 |
ashik.ali |
29 |
import com.spice.profitmandi.common.enumuration.DateTimePattern;
|
| 22860 |
ashik.ali |
30 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
31 |
import com.spice.profitmandi.common.model.CreateSchemeRequest;
|
|
|
32 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 23557 |
amit.gupta |
33 |
import com.spice.profitmandi.common.model.SchemeItems;
|
| 23020 |
ashik.ali |
34 |
import com.spice.profitmandi.common.model.SchemeModel;
|
|
|
35 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
|
|
36 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 22860 |
ashik.ali |
37 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
| 23556 |
amit.gupta |
38 |
import com.spice.profitmandi.dao.entity.fofo.SchemeItem;
|
| 23343 |
ashik.ali |
39 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
| 22860 |
ashik.ali |
40 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
| 23556 |
amit.gupta |
41 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 23506 |
amit.gupta |
42 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
| 23556 |
amit.gupta |
43 |
import com.spice.profitmandi.dao.repository.fofo.SchemeItemRepository;
|
| 23020 |
ashik.ali |
44 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 22860 |
ashik.ali |
45 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
|
|
46 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
47 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
48 |
|
|
|
49 |
@Controller
|
|
|
50 |
@Transactional(rollbackFor=Throwable.class)
|
|
|
51 |
public class SchemeController {
|
|
|
52 |
|
| 23568 |
govind |
53 |
private static final Logger LOGGER = LogManager.getLogger(SchemeController.class);
|
| 22860 |
ashik.ali |
54 |
|
|
|
55 |
@Autowired
|
| 22927 |
ashik.ali |
56 |
private SchemeService schemeService;
|
| 22860 |
ashik.ali |
57 |
|
|
|
58 |
@Autowired
|
| 22927 |
ashik.ali |
59 |
private SchemeRepository schemeRepository;
|
| 22860 |
ashik.ali |
60 |
|
|
|
61 |
@Autowired
|
| 23556 |
amit.gupta |
62 |
private SchemeItemRepository schemeItemRepository;
|
|
|
63 |
|
|
|
64 |
@Autowired
|
| 22927 |
ashik.ali |
65 |
private CookiesProcessor cookiesProcessor;
|
| 23020 |
ashik.ali |
66 |
|
|
|
67 |
@Autowired
|
|
|
68 |
private InventoryService inventoryService;
|
| 23556 |
amit.gupta |
69 |
|
|
|
70 |
@Autowired
|
|
|
71 |
private TagListingRepository tagListingRepository;
|
| 23506 |
amit.gupta |
72 |
|
|
|
73 |
@Autowired
|
|
|
74 |
PurchaseRepository purchaseRepository;
|
| 22860 |
ashik.ali |
75 |
|
|
|
76 |
@RequestMapping(value = "/createScheme", method = RequestMethod.GET)
|
| 22927 |
ashik.ali |
77 |
public String createScheme(HttpServletRequest request, Model model){
|
| 23020 |
ashik.ali |
78 |
//Map<Integer, String> itemIdItemDescriptionMap = inventoryService.getAllItemIdItemDescriptionMap();
|
|
|
79 |
//model.addAttribute("itemIdItemDescriptionMap", itemIdItemDescriptionMap);
|
| 23419 |
ashik.ali |
80 |
model.addAttribute("brands", inventoryService.getAllTagListingBrands());
|
| 22860 |
ashik.ali |
81 |
return "create-scheme";
|
|
|
82 |
}
|
|
|
83 |
|
| 23419 |
ashik.ali |
84 |
@RequestMapping(value = "/getTagListingItemsByBrand", method = RequestMethod.GET)
|
|
|
85 |
public String getTagListingItemsByBrand(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.BRAND) String brand, Model model){
|
|
|
86 |
Map<Integer, String> itemIdItemDescriptionMap = inventoryService.getAllTagListingItemIdItemDescriptionMap(brand);
|
| 23020 |
ashik.ali |
87 |
model.addAttribute("itemIdItemDescriptionMap", itemIdItemDescriptionMap);
|
|
|
88 |
//model.addAttribute("brands", inventoryService.getAllBrands());
|
| 23419 |
ashik.ali |
89 |
return "tag-listing-items-description";
|
| 23020 |
ashik.ali |
90 |
}
|
| 23556 |
amit.gupta |
91 |
|
|
|
92 |
@RequestMapping(value = "/schemes/update-schemes-page", method = RequestMethod.GET)
|
|
|
93 |
public String updateShcemes(HttpServletRequest request) throws ProfitMandiBusinessException {
|
|
|
94 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
95 |
if(!loginDetails.getRoleTypes().contains(RoleType.FOFO_ADMIN)) {
|
|
|
96 |
throw new ProfitMandiBusinessException("User", loginDetails.getEmailId(), "Unauthorised access");
|
|
|
97 |
}
|
|
|
98 |
return "update-schemes-page";
|
|
|
99 |
}
|
| 23020 |
ashik.ali |
100 |
|
| 23556 |
amit.gupta |
101 |
@RequestMapping(value = "/schemes/update", method = RequestMethod.POST)
|
| 23557 |
amit.gupta |
102 |
public String updateShcemes(HttpServletRequest request, @RequestBody SchemeItems schemeItems) throws ProfitMandiBusinessException {
|
|
|
103 |
for(int schemeId : schemeItems.getSchemeIds()) {
|
| 23556 |
amit.gupta |
104 |
if(schemeRepository.selectById(schemeId) != null)
|
| 23557 |
amit.gupta |
105 |
for(int itemId : schemeItems.getItemIds()) {
|
| 23556 |
amit.gupta |
106 |
if(tagListingRepository.selectByItemIdsAndTagIds(new HashSet<>(Arrays.asList(itemId)), new HashSet<>(Arrays.asList(4,7))).size() > 0) {
|
|
|
107 |
SchemeItem si = new SchemeItem();
|
|
|
108 |
si.setItemId(itemId);
|
|
|
109 |
si.setSchemeId(schemeId);
|
|
|
110 |
try {
|
|
|
111 |
schemeItemRepository.persist(si);
|
|
|
112 |
} catch (Exception e) {
|
|
|
113 |
LOGGER.info("Scheme aleady exist");
|
|
|
114 |
}
|
|
|
115 |
} else {
|
|
|
116 |
throw new ProfitMandiBusinessException("ItemId", itemId,"Invalid Item Id");
|
|
|
117 |
}
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
return "response";
|
|
|
121 |
}
|
| 23020 |
ashik.ali |
122 |
|
| 23556 |
amit.gupta |
123 |
|
| 22860 |
ashik.ali |
124 |
@RequestMapping(value = "/createScheme", method = RequestMethod.POST)
|
| 22927 |
ashik.ali |
125 |
public String createScheme(HttpServletRequest request, @RequestBody CreateSchemeRequest createSchemeRequest, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws ProfitMandiBusinessException{
|
|
|
126 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 22860 |
ashik.ali |
127 |
LOGGER.info("CreateSchemeRequest {}", createSchemeRequest);
|
| 22927 |
ashik.ali |
128 |
schemeService.saveScheme(loginDetails.getFofoId(), createSchemeRequest);
|
|
|
129 |
LOGGER.info("Scheme saved successfully");
|
| 23271 |
ashik.ali |
130 |
long size = schemeRepository.selectAllCount();
|
| 22927 |
ashik.ali |
131 |
List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
|
|
|
132 |
model.addAttribute("schemes", schemes);
|
|
|
133 |
model.addAttribute("start", offset + 1);
|
| 23271 |
ashik.ali |
134 |
model.addAttribute("size", size);
|
| 22927 |
ashik.ali |
135 |
if (schemes.size() < limit){
|
|
|
136 |
model.addAttribute("end", offset + schemes.size());
|
| 22860 |
ashik.ali |
137 |
}
|
| 22927 |
ashik.ali |
138 |
else{
|
|
|
139 |
model.addAttribute("end", offset + limit);
|
|
|
140 |
}
|
|
|
141 |
return "schemes";
|
|
|
142 |
|
| 22860 |
ashik.ali |
143 |
}
|
|
|
144 |
|
|
|
145 |
@RequestMapping(value = "/getSchemes", method = RequestMethod.GET)
|
| 23343 |
ashik.ali |
146 |
public String getSchemes(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws ProfitMandiBusinessException{
|
|
|
147 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
148 |
List<Scheme> schemes = null;
|
|
|
149 |
long size = 0;
|
|
|
150 |
if(loginDetails.getRoleTypes().contains(RoleType.FOFO_ADMIN)){
|
|
|
151 |
schemes = schemeRepository.selectAll(offset, limit);
|
|
|
152 |
size = schemeRepository.selectAllCount();
|
|
|
153 |
}else{
|
|
|
154 |
schemes = schemeRepository.selectActiveAll(offset, limit);
|
|
|
155 |
size = schemeRepository.selectAllActiveCount();
|
|
|
156 |
}
|
| 22860 |
ashik.ali |
157 |
model.addAttribute("schemes", schemes);
|
|
|
158 |
model.addAttribute("start", offset + 1);
|
| 23271 |
ashik.ali |
159 |
model.addAttribute("size", size);
|
| 22860 |
ashik.ali |
160 |
if (schemes.size() < limit){
|
|
|
161 |
model.addAttribute("end", offset + schemes.size());
|
|
|
162 |
}
|
|
|
163 |
else{
|
|
|
164 |
model.addAttribute("end", offset + limit);
|
|
|
165 |
}
|
| 23343 |
ashik.ali |
166 |
//model.addAttribute("roleTypes", loginDetails.getRoleTypes());
|
| 22860 |
ashik.ali |
167 |
return "schemes";
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
@RequestMapping(value = "/getPaginatedSchemes", method = RequestMethod.GET)
|
| 23343 |
ashik.ali |
171 |
public String getPaginatedSchemes(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws ProfitMandiBusinessException{
|
|
|
172 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23271 |
ashik.ali |
173 |
LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
|
| 23343 |
ashik.ali |
174 |
List<Scheme> schemes = null;
|
|
|
175 |
if(loginDetails.getRoleTypes().contains(RoleType.FOFO_ADMIN)){
|
|
|
176 |
schemes = schemeRepository.selectAll(offset, limit);
|
|
|
177 |
}else{
|
|
|
178 |
schemes = schemeRepository.selectActiveAll(offset, limit);
|
|
|
179 |
}
|
| 22860 |
ashik.ali |
180 |
model.addAttribute("schemes", schemes);
|
| 23343 |
ashik.ali |
181 |
model.addAttribute("roleTypes", loginDetails.getRoleTypes());
|
| 22860 |
ashik.ali |
182 |
return "schemes-paginated";
|
|
|
183 |
}
|
|
|
184 |
|
| 23020 |
ashik.ali |
185 |
@RequestMapping(value = "/schemes/downloadPage", method = RequestMethod.GET)
|
|
|
186 |
public String downloadPage(HttpServletRequest request, Model model){
|
|
|
187 |
return "schemes-download";
|
|
|
188 |
}
|
|
|
189 |
|
|
|
190 |
@RequestMapping(value = "/schemes/download", method = RequestMethod.GET)
|
|
|
191 |
public ResponseEntity<?> downloadInventoryItemAgingByInterval(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.START_DATE_TIME) String startDateTimeString, @RequestParam(name = ProfitMandiConstants.END_DATE_TIME) String endDateTimeString, Model model) throws ProfitMandiBusinessException{
|
|
|
192 |
LocalDateTime startDateTime = StringUtils.toDateTime(startDateTimeString, DateTimePattern.DD_MM_YYYY_T_HH_MM_SS);
|
|
|
193 |
LocalDateTime endDateTime = StringUtils.toDateTime(endDateTimeString, DateTimePattern.DD_MM_YYYY_T_HH_MM_SS);
|
|
|
194 |
|
|
|
195 |
List<SchemeModel> schemeModels = schemeService.getAllSchemeModels(startDateTime, endDateTime);
|
|
|
196 |
|
|
|
197 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
198 |
ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
|
|
|
199 |
|
|
|
200 |
final HttpHeaders headers=new HttpHeaders();
|
|
|
201 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
202 |
headers.set("Content-disposition", "inline; filename=SchemesReport.xlsx");
|
|
|
203 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
204 |
final InputStream inputStream=new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
205 |
final InputStreamResource inputStreamResource=new InputStreamResource(inputStream);
|
|
|
206 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
207 |
|
|
|
208 |
//return responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
|
|
|
209 |
}
|
|
|
210 |
|
| 22860 |
ashik.ali |
211 |
@RequestMapping(value = "/getSchemeById", method = RequestMethod.GET)
|
| 22927 |
ashik.ali |
212 |
public String getSchemeById(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId, Model model) throws ProfitMandiBusinessException{
|
| 23343 |
ashik.ali |
213 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 22860 |
ashik.ali |
214 |
Scheme scheme = schemeService.getSchemeById(schemeId);
|
|
|
215 |
model.addAttribute("scheme", scheme);
|
| 23343 |
ashik.ali |
216 |
model.addAttribute("roleTypes", loginDetails.getRoleTypes());
|
| 22860 |
ashik.ali |
217 |
return "scheme-details";
|
|
|
218 |
}
|
|
|
219 |
|
|
|
220 |
@RequestMapping(value = "/activeSchemeById", method = RequestMethod.PUT)
|
| 22927 |
ashik.ali |
221 |
public String activeSchemeById(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws ProfitMandiBusinessException{
|
| 22860 |
ashik.ali |
222 |
schemeService.activeSchemeById(schemeId);
|
|
|
223 |
List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
|
|
|
224 |
model.addAttribute("schemes", schemes);
|
|
|
225 |
return "schemes-paginated";
|
|
|
226 |
}
|
|
|
227 |
|
|
|
228 |
|
|
|
229 |
@RequestMapping(value = "/expireSchemeById", method = RequestMethod.PUT)
|
| 22927 |
ashik.ali |
230 |
public String expireSchemeById(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws ProfitMandiBusinessException{
|
| 22860 |
ashik.ali |
231 |
schemeService.expireSchemeById(schemeId);
|
|
|
232 |
List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
|
|
|
233 |
model.addAttribute("schemes", schemes);
|
|
|
234 |
return "schemes-paginated";
|
|
|
235 |
}
|
| 23506 |
amit.gupta |
236 |
|
| 22860 |
ashik.ali |
237 |
}
|