| 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 |
|
| 23784 |
ashik.ali |
14 |
import org.apache.logging.log4j.LogManager;
|
| 23568 |
govind |
15 |
import org.apache.logging.log4j.Logger;
|
| 22860 |
ashik.ali |
16 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23784 |
ashik.ali |
17 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 23020 |
ashik.ali |
18 |
import org.springframework.core.io.InputStreamResource;
|
|
|
19 |
import org.springframework.http.HttpHeaders;
|
|
|
20 |
import org.springframework.http.HttpStatus;
|
|
|
21 |
import org.springframework.http.ResponseEntity;
|
| 22860 |
ashik.ali |
22 |
import org.springframework.stereotype.Controller;
|
|
|
23 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
24 |
import org.springframework.ui.Model;
|
|
|
25 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
26 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
27 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
28 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
29 |
|
| 23020 |
ashik.ali |
30 |
import com.spice.profitmandi.common.enumuration.DateTimePattern;
|
| 22860 |
ashik.ali |
31 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
32 |
import com.spice.profitmandi.common.model.CreateSchemeRequest;
|
|
|
33 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 23557 |
amit.gupta |
34 |
import com.spice.profitmandi.common.model.SchemeItems;
|
| 23020 |
ashik.ali |
35 |
import com.spice.profitmandi.common.model.SchemeModel;
|
|
|
36 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
|
|
37 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 23784 |
ashik.ali |
38 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 22860 |
ashik.ali |
39 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
| 23556 |
amit.gupta |
40 |
import com.spice.profitmandi.dao.entity.fofo.SchemeItem;
|
| 22860 |
ashik.ali |
41 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
| 23556 |
amit.gupta |
42 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 23784 |
ashik.ali |
43 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
| 23506 |
amit.gupta |
44 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
| 23556 |
amit.gupta |
45 |
import com.spice.profitmandi.dao.repository.fofo.SchemeItemRepository;
|
| 23798 |
amit.gupta |
46 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 23020 |
ashik.ali |
47 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 22860 |
ashik.ali |
48 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
|
|
49 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
50 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 23570 |
amit.gupta |
51 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 22860 |
ashik.ali |
52 |
|
|
|
53 |
@Controller
|
| 23786 |
amit.gupta |
54 |
@Transactional(rollbackFor = Throwable.class)
|
| 22860 |
ashik.ali |
55 |
public class SchemeController {
|
|
|
56 |
|
| 23568 |
govind |
57 |
private static final Logger LOGGER = LogManager.getLogger(SchemeController.class);
|
| 22860 |
ashik.ali |
58 |
|
|
|
59 |
@Autowired
|
| 22927 |
ashik.ali |
60 |
private SchemeService schemeService;
|
| 23786 |
amit.gupta |
61 |
|
| 22860 |
ashik.ali |
62 |
@Autowired
|
| 22927 |
ashik.ali |
63 |
private SchemeRepository schemeRepository;
|
| 22860 |
ashik.ali |
64 |
|
|
|
65 |
@Autowired
|
| 23556 |
amit.gupta |
66 |
private SchemeItemRepository schemeItemRepository;
|
| 23786 |
amit.gupta |
67 |
|
| 23556 |
amit.gupta |
68 |
@Autowired
|
| 23570 |
amit.gupta |
69 |
private MVCResponseSender mvcResponseSender;
|
| 23786 |
amit.gupta |
70 |
|
| 23570 |
amit.gupta |
71 |
@Autowired
|
| 22927 |
ashik.ali |
72 |
private CookiesProcessor cookiesProcessor;
|
| 23786 |
amit.gupta |
73 |
|
| 23020 |
ashik.ali |
74 |
@Autowired
|
| 23784 |
ashik.ali |
75 |
@Qualifier("fofoInventoryService")
|
| 23020 |
ashik.ali |
76 |
private InventoryService inventoryService;
|
| 23556 |
amit.gupta |
77 |
|
|
|
78 |
@Autowired
|
|
|
79 |
private TagListingRepository tagListingRepository;
|
| 23798 |
amit.gupta |
80 |
|
|
|
81 |
@Autowired
|
|
|
82 |
private RoleManager roleManager;
|
| 23786 |
amit.gupta |
83 |
|
| 23506 |
amit.gupta |
84 |
@Autowired
|
|
|
85 |
PurchaseRepository purchaseRepository;
|
| 23786 |
amit.gupta |
86 |
|
| 23784 |
ashik.ali |
87 |
@Autowired
|
|
|
88 |
private RoleRepository roleRepository;
|
| 23786 |
amit.gupta |
89 |
|
| 23784 |
ashik.ali |
90 |
@Autowired
|
|
|
91 |
private ResponseSender<?> responseSender;
|
| 22860 |
ashik.ali |
92 |
|
|
|
93 |
@RequestMapping(value = "/createScheme", method = RequestMethod.GET)
|
| 23786 |
amit.gupta |
94 |
public String createScheme(HttpServletRequest request, Model model) {
|
|
|
95 |
// Map<Integer, String> itemIdItemDescriptionMap =
|
|
|
96 |
// inventoryService.getAllItemIdItemDescriptionMap();
|
|
|
97 |
// model.addAttribute("itemIdItemDescriptionMap", itemIdItemDescriptionMap);
|
| 23419 |
ashik.ali |
98 |
model.addAttribute("brands", inventoryService.getAllTagListingBrands());
|
| 22860 |
ashik.ali |
99 |
return "create-scheme";
|
|
|
100 |
}
|
| 23786 |
amit.gupta |
101 |
|
| 23419 |
ashik.ali |
102 |
@RequestMapping(value = "/getTagListingItemsByBrand", method = RequestMethod.GET)
|
| 23786 |
amit.gupta |
103 |
public String getTagListingItemsByBrand(HttpServletRequest request,
|
|
|
104 |
@RequestParam(name = ProfitMandiConstants.BRAND) String brand, Model model) {
|
|
|
105 |
Map<Integer, String> itemIdItemDescriptionMap = inventoryService
|
|
|
106 |
.getAllTagListingItemIdItemDescriptionMap(brand);
|
| 23020 |
ashik.ali |
107 |
model.addAttribute("itemIdItemDescriptionMap", itemIdItemDescriptionMap);
|
| 23786 |
amit.gupta |
108 |
// model.addAttribute("brands", inventoryService.getAllBrands());
|
| 23419 |
ashik.ali |
109 |
return "tag-listing-items-description";
|
| 23020 |
ashik.ali |
110 |
}
|
| 23556 |
amit.gupta |
111 |
|
|
|
112 |
@RequestMapping(value = "/schemes/update-schemes-page", method = RequestMethod.GET)
|
|
|
113 |
public String updateShcemes(HttpServletRequest request) throws ProfitMandiBusinessException {
|
|
|
114 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23799 |
amit.gupta |
115 |
if (!roleManager.isAdmin(loginDetails.getRoleIds())) {
|
| 23556 |
amit.gupta |
116 |
throw new ProfitMandiBusinessException("User", loginDetails.getEmailId(), "Unauthorised access");
|
|
|
117 |
}
|
|
|
118 |
return "update-schemes-page";
|
|
|
119 |
}
|
| 23786 |
amit.gupta |
120 |
|
| 23556 |
amit.gupta |
121 |
@RequestMapping(value = "/schemes/update", method = RequestMethod.POST)
|
| 23786 |
amit.gupta |
122 |
public String updateShcemes(HttpServletRequest request, @RequestBody SchemeItems schemeItems, Model model)
|
|
|
123 |
throws Exception {
|
|
|
124 |
for (int schemeId : schemeItems.getSchemeIds()) {
|
|
|
125 |
if (schemeRepository.selectById(schemeId) != null)
|
|
|
126 |
for (int itemId : schemeItems.getItemIds()) {
|
|
|
127 |
if (tagListingRepository.selectByItemIdsAndTagIds(new HashSet<>(Arrays.asList(itemId)),
|
|
|
128 |
new HashSet<>(Arrays.asList(4, 7))).size() > 0) {
|
|
|
129 |
SchemeItem si = new SchemeItem();
|
|
|
130 |
si.setItemId(itemId);
|
|
|
131 |
si.setSchemeId(schemeId);
|
|
|
132 |
try {
|
|
|
133 |
schemeItemRepository.persist(si);
|
|
|
134 |
} catch (Exception e) {
|
|
|
135 |
LOGGER.info("Scheme aleady exist");
|
|
|
136 |
}
|
|
|
137 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
138 |
} else {
|
|
|
139 |
model.addAttribute("response", mvcResponseSender.createResponseString(false));
|
|
|
140 |
throw new ProfitMandiBusinessException("ItemId", itemId, "Invalid Item Id");
|
| 23556 |
amit.gupta |
141 |
}
|
|
|
142 |
}
|
|
|
143 |
}
|
|
|
144 |
return "response";
|
|
|
145 |
}
|
| 23819 |
govind |
146 |
@RequestMapping(value = "/schemes/delete", method = RequestMethod.POST)
|
|
|
147 |
public String deleteShcemes(HttpServletRequest request, @RequestBody SchemeItems schemeItems, Model model)
|
|
|
148 |
throws Exception {
|
|
|
149 |
if (schemeItemRepository.selectBySchemeIdsAndItemIds(new HashSet<>(schemeItems.getSchemeIds()),
|
|
|
150 |
new HashSet<>(schemeItems.getItemIds())).size() > 0) {
|
|
|
151 |
for (int schemeId : schemeItems.getSchemeIds()) {
|
|
|
152 |
for (int itemId : schemeItems.getItemIds()) {
|
|
|
153 |
schemeItemRepository.deletebyItemIdsandSchemeIds(itemId, schemeId);
|
|
|
154 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
155 |
}
|
|
|
156 |
}
|
|
|
157 |
} else {
|
|
|
158 |
throw new ProfitMandiBusinessException("ItemId", schemeItems.getItemIds(), "invalid Item Id");
|
|
|
159 |
}
|
|
|
160 |
return "response";
|
|
|
161 |
}
|
| 23786 |
amit.gupta |
162 |
|
| 23819 |
govind |
163 |
|
| 22860 |
ashik.ali |
164 |
@RequestMapping(value = "/createScheme", method = RequestMethod.POST)
|
| 23715 |
govind |
165 |
public String createScheme(HttpServletRequest request, @RequestBody CreateSchemeRequest createSchemeRequest,
|
|
|
166 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 23752 |
govind |
167 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
168 |
@RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem,
|
|
|
169 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
| 23715 |
govind |
170 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
171 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 22860 |
ashik.ali |
172 |
LOGGER.info("CreateSchemeRequest {}", createSchemeRequest);
|
| 22927 |
ashik.ali |
173 |
schemeService.saveScheme(loginDetails.getFofoId(), createSchemeRequest);
|
|
|
174 |
LOGGER.info("Scheme saved successfully");
|
| 23271 |
ashik.ali |
175 |
long size = schemeRepository.selectAllCount();
|
| 22927 |
ashik.ali |
176 |
List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
|
|
|
177 |
model.addAttribute("schemes", schemes);
|
|
|
178 |
model.addAttribute("start", offset + 1);
|
| 23271 |
ashik.ali |
179 |
model.addAttribute("size", size);
|
| 23752 |
govind |
180 |
model.addAttribute("searchItem", searchItem);
|
|
|
181 |
model.addAttribute("searchTerm", searchTerm);
|
| 23715 |
govind |
182 |
if (schemes.size() < limit) {
|
| 22927 |
ashik.ali |
183 |
model.addAttribute("end", offset + schemes.size());
|
| 23786 |
amit.gupta |
184 |
} else {
|
| 22927 |
ashik.ali |
185 |
model.addAttribute("end", offset + limit);
|
|
|
186 |
}
|
|
|
187 |
return "schemes";
|
| 23786 |
amit.gupta |
188 |
|
| 22860 |
ashik.ali |
189 |
}
|
| 23786 |
amit.gupta |
190 |
|
| 22860 |
ashik.ali |
191 |
@RequestMapping(value = "/getSchemes", method = RequestMethod.GET)
|
| 23715 |
govind |
192 |
public String getSchemes(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 23752 |
govind |
193 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
194 |
@RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem,
|
|
|
195 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
| 23715 |
govind |
196 |
throws ProfitMandiBusinessException {
|
| 23343 |
ashik.ali |
197 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
198 |
List<Scheme> schemes = null;
|
|
|
199 |
long size = 0;
|
| 23798 |
amit.gupta |
200 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
| 23343 |
ashik.ali |
201 |
schemes = schemeRepository.selectAll(offset, limit);
|
|
|
202 |
size = schemeRepository.selectAllCount();
|
| 23786 |
amit.gupta |
203 |
} else {
|
| 23343 |
ashik.ali |
204 |
schemes = schemeRepository.selectActiveAll(offset, limit);
|
|
|
205 |
size = schemeRepository.selectAllActiveCount();
|
|
|
206 |
}
|
| 22860 |
ashik.ali |
207 |
model.addAttribute("schemes", schemes);
|
|
|
208 |
model.addAttribute("start", offset + 1);
|
| 23271 |
ashik.ali |
209 |
model.addAttribute("size", size);
|
| 23752 |
govind |
210 |
model.addAttribute("searchItem", searchItem);
|
|
|
211 |
model.addAttribute("searchTerm", searchTerm);
|
| 23715 |
govind |
212 |
if (schemes.size() < limit) {
|
| 22860 |
ashik.ali |
213 |
model.addAttribute("end", offset + schemes.size());
|
| 23786 |
amit.gupta |
214 |
} else {
|
| 22860 |
ashik.ali |
215 |
model.addAttribute("end", offset + limit);
|
|
|
216 |
}
|
| 23786 |
amit.gupta |
217 |
// model.addAttribute("roleTypes", loginDetails.getRoleTypes());
|
| 22860 |
ashik.ali |
218 |
return "schemes";
|
|
|
219 |
}
|
| 23786 |
amit.gupta |
220 |
|
| 22860 |
ashik.ali |
221 |
@RequestMapping(value = "/getPaginatedSchemes", method = RequestMethod.GET)
|
| 23786 |
amit.gupta |
222 |
public String getPaginatedSchemes(HttpServletRequest request,
|
|
|
223 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
224 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
225 |
throws ProfitMandiBusinessException {
|
| 23343 |
ashik.ali |
226 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23271 |
ashik.ali |
227 |
LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
|
| 23343 |
ashik.ali |
228 |
List<Scheme> schemes = null;
|
| 23798 |
amit.gupta |
229 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
| 23343 |
ashik.ali |
230 |
schemes = schemeRepository.selectAll(offset, limit);
|
| 23786 |
amit.gupta |
231 |
} else {
|
| 23343 |
ashik.ali |
232 |
schemes = schemeRepository.selectActiveAll(offset, limit);
|
|
|
233 |
}
|
| 22860 |
ashik.ali |
234 |
model.addAttribute("schemes", schemes);
|
| 23784 |
ashik.ali |
235 |
model.addAttribute("roleIds", loginDetails.getRoleIds());
|
| 22860 |
ashik.ali |
236 |
return "schemes-paginated";
|
|
|
237 |
}
|
| 23786 |
amit.gupta |
238 |
|
| 23020 |
ashik.ali |
239 |
@RequestMapping(value = "/schemes/downloadPage", method = RequestMethod.GET)
|
| 23786 |
amit.gupta |
240 |
public String downloadPage(HttpServletRequest request, Model model) {
|
| 23020 |
ashik.ali |
241 |
return "schemes-download";
|
|
|
242 |
}
|
| 23786 |
amit.gupta |
243 |
|
| 23020 |
ashik.ali |
244 |
@RequestMapping(value = "/schemes/download", method = RequestMethod.GET)
|
| 23786 |
amit.gupta |
245 |
public ResponseEntity<?> downloadInventoryItemAgingByInterval(HttpServletRequest request,
|
|
|
246 |
@RequestParam(name = ProfitMandiConstants.START_DATE_TIME) String startDateTimeString,
|
|
|
247 |
@RequestParam(name = ProfitMandiConstants.END_DATE_TIME) String endDateTimeString, Model model)
|
|
|
248 |
throws ProfitMandiBusinessException {
|
|
|
249 |
LocalDateTime startDateTime = StringUtils.toDateTime(startDateTimeString,
|
| 23884 |
amit.gupta |
250 |
DateTimePattern.DD_MM_YYYY);
|
|
|
251 |
LocalDateTime endDateTime = StringUtils.toDateTime(endDateTimeString, DateTimePattern.DD_MM_YYYY);
|
| 23786 |
amit.gupta |
252 |
|
| 23020 |
ashik.ali |
253 |
List<SchemeModel> schemeModels = schemeService.getAllSchemeModels(startDateTime, endDateTime);
|
| 23786 |
amit.gupta |
254 |
|
| 23020 |
ashik.ali |
255 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
256 |
ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
|
| 23786 |
amit.gupta |
257 |
|
|
|
258 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
259 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
| 23020 |
ashik.ali |
260 |
headers.set("Content-disposition", "inline; filename=SchemesReport.xlsx");
|
| 23786 |
amit.gupta |
261 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
262 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
263 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
264 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
265 |
|
|
|
266 |
// return responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
|
| 23020 |
ashik.ali |
267 |
}
|
| 23786 |
amit.gupta |
268 |
|
| 22860 |
ashik.ali |
269 |
@RequestMapping(value = "/getSchemeById", method = RequestMethod.GET)
|
| 23786 |
amit.gupta |
270 |
public String getSchemeById(HttpServletRequest request,
|
|
|
271 |
@RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId, Model model)
|
|
|
272 |
throws ProfitMandiBusinessException {
|
| 23343 |
ashik.ali |
273 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 22860 |
ashik.ali |
274 |
Scheme scheme = schemeService.getSchemeById(schemeId);
|
|
|
275 |
model.addAttribute("scheme", scheme);
|
| 23855 |
amit.gupta |
276 |
model.addAttribute("isFofoAdmin", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 22860 |
ashik.ali |
277 |
return "scheme-details";
|
|
|
278 |
}
|
| 23786 |
amit.gupta |
279 |
|
| 22860 |
ashik.ali |
280 |
@RequestMapping(value = "/activeSchemeById", method = RequestMethod.PUT)
|
| 23786 |
amit.gupta |
281 |
public String activeSchemeById(HttpServletRequest request,
|
|
|
282 |
@RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId,
|
|
|
283 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
284 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
285 |
throws ProfitMandiBusinessException {
|
| 22860 |
ashik.ali |
286 |
schemeService.activeSchemeById(schemeId);
|
|
|
287 |
List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
|
|
|
288 |
model.addAttribute("schemes", schemes);
|
|
|
289 |
return "schemes-paginated";
|
|
|
290 |
}
|
| 23786 |
amit.gupta |
291 |
|
| 22860 |
ashik.ali |
292 |
@RequestMapping(value = "/expireSchemeById", method = RequestMethod.PUT)
|
| 23786 |
amit.gupta |
293 |
public String expireSchemeById(HttpServletRequest request,
|
|
|
294 |
@RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId,
|
|
|
295 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
296 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
297 |
throws ProfitMandiBusinessException {
|
| 22860 |
ashik.ali |
298 |
schemeService.expireSchemeById(schemeId);
|
|
|
299 |
List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
|
|
|
300 |
model.addAttribute("schemes", schemes);
|
|
|
301 |
return "schemes-paginated";
|
|
|
302 |
}
|
| 23786 |
amit.gupta |
303 |
|
| 23784 |
ashik.ali |
304 |
@RequestMapping(value = "/getSchemesJson", method = RequestMethod.GET)
|
| 23786 |
amit.gupta |
305 |
public ResponseEntity<?> getSchemesJson(HttpServletRequest request,
|
|
|
306 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
307 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
308 |
throws ProfitMandiBusinessException {
|
| 23784 |
ashik.ali |
309 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
310 |
return responseSender.ok(schemeService.getSchemes(loginDetails.getRoleIds(), offset, limit));
|
|
|
311 |
}
|
| 23506 |
amit.gupta |
312 |
|
| 23752 |
govind |
313 |
@RequestMapping(value = "/searchScheme")
|
|
|
314 |
public String getSchemeBySchemeId(HttpServletRequest request,
|
|
|
315 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
316 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
317 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm,
|
|
|
318 |
@RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem, Model model)
|
|
|
319 |
throws ProfitMandiBusinessException {
|
|
|
320 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
321 |
List<Scheme> schemes = null;
|
|
|
322 |
long size = 0;
|
|
|
323 |
if (!(searchTerm.equals("")) && searchItem.equals("")) {
|
|
|
324 |
schemes = schemeRepository.selectBySearchTerm(searchTerm, offset, limit);
|
| 23786 |
amit.gupta |
325 |
if (!(schemes.size() == 0)) {
|
|
|
326 |
size = schemeRepository.selectAllCount();
|
|
|
327 |
LOGGER.info("schemes" + schemes);
|
|
|
328 |
model.addAttribute("schemes", schemes);
|
|
|
329 |
model.addAttribute("start", offset + 1);
|
|
|
330 |
model.addAttribute("size", size);
|
|
|
331 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
332 |
model.addAttribute("searchItem", searchItem);
|
|
|
333 |
if (schemes.size() < limit) {
|
|
|
334 |
model.addAttribute("end", offset + schemes.size());
|
|
|
335 |
} else {
|
|
|
336 |
model.addAttribute("end", offset + limit);
|
|
|
337 |
}
|
| 23752 |
govind |
338 |
} else {
|
| 23786 |
amit.gupta |
339 |
throw new ProfitMandiBusinessException("SchemeId", searchTerm, "SchemeId Not Found");
|
| 23752 |
govind |
340 |
}
|
|
|
341 |
} else if (!(searchItem.equals("")) && searchTerm.equals("")) {
|
|
|
342 |
List<Integer> schemeIds = schemeItemRepository.selectSchemeIdByItemId(Integer.parseInt(searchItem));
|
| 23786 |
amit.gupta |
343 |
if (!(schemeIds.size() == 0)) {
|
| 23752 |
govind |
344 |
LOGGER.info("schemeIds in searchItemScheme" + schemeIds);
|
|
|
345 |
schemes = schemeRepository.selectBySchemeIds(schemeIds, offset, limit);
|
|
|
346 |
size = schemeIds.size();
|
|
|
347 |
LOGGER.info("Size" + size);
|
|
|
348 |
model.addAttribute("schemes", schemes);
|
|
|
349 |
model.addAttribute("start", offset + 1);
|
|
|
350 |
model.addAttribute("size", size);
|
|
|
351 |
model.addAttribute("searchItem", searchItem);
|
|
|
352 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
353 |
if (schemes.size() < limit) {
|
|
|
354 |
model.addAttribute("end", offset + schemes.size());
|
|
|
355 |
} else {
|
|
|
356 |
model.addAttribute("end", offset + limit);
|
|
|
357 |
}
|
|
|
358 |
|
|
|
359 |
} else {
|
|
|
360 |
throw new ProfitMandiBusinessException("SchemeIds", searchItem, "SchemeId Not Found");
|
|
|
361 |
}
|
|
|
362 |
} else {
|
| 23798 |
amit.gupta |
363 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
| 23752 |
govind |
364 |
schemes = schemeRepository.selectAll(offset, limit);
|
|
|
365 |
size = schemeRepository.selectAllCount();
|
|
|
366 |
} else {
|
|
|
367 |
schemes = schemeRepository.selectActiveAll(offset, limit);
|
|
|
368 |
size = schemeRepository.selectAllActiveCount();
|
|
|
369 |
}
|
|
|
370 |
model.addAttribute("schemes", schemes);
|
|
|
371 |
model.addAttribute("start", offset + 1);
|
|
|
372 |
model.addAttribute("size", size);
|
|
|
373 |
model.addAttribute("searchItem", searchItem);
|
|
|
374 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
375 |
if (schemes.size() < limit) {
|
|
|
376 |
model.addAttribute("end", offset + schemes.size());
|
|
|
377 |
} else {
|
|
|
378 |
model.addAttribute("end", offset + limit);
|
|
|
379 |
}
|
|
|
380 |
}
|
|
|
381 |
return "schemes";
|
|
|
382 |
}
|
|
|
383 |
|
|
|
384 |
@RequestMapping(value = "/searchItemSchemePanigated")
|
|
|
385 |
public String getSchemeByItemPanigated(HttpServletRequest request,
|
|
|
386 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
387 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
388 |
@RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem, Model model)
|
|
|
389 |
throws ProfitMandiBusinessException {
|
|
|
390 |
LOGGER.info("In search Item....");
|
|
|
391 |
List<Scheme> schemes = null;
|
|
|
392 |
if (!searchItem.equals("")) {
|
|
|
393 |
List<Integer> schemeIds = schemeItemRepository.selectSchemeIdByItemId(Integer.parseInt(searchItem));
|
|
|
394 |
if (schemeIds != null) {
|
|
|
395 |
LOGGER.info(schemeIds);
|
|
|
396 |
schemes = schemeRepository.selectBySchemeIds(schemeIds, offset, limit);
|
|
|
397 |
|
|
|
398 |
}
|
|
|
399 |
}
|
|
|
400 |
model.addAttribute("schemes", schemes);
|
|
|
401 |
model.addAttribute("searchItem", searchItem);
|
|
|
402 |
return "schemes-paginated";
|
|
|
403 |
|
|
|
404 |
}
|
|
|
405 |
|
| 22860 |
ashik.ali |
406 |
}
|