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