| 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;
|
| 26674 |
tejbeer |
6 |
import java.time.LocalDate;
|
| 23020 |
ashik.ali |
7 |
import java.time.LocalDateTime;
|
| 27897 |
amit.gupta |
8 |
import java.util.ArrayList;
|
| 23556 |
amit.gupta |
9 |
import java.util.Arrays;
|
| 23914 |
govind |
10 |
import java.util.HashMap;
|
| 23556 |
amit.gupta |
11 |
import java.util.HashSet;
|
| 22860 |
ashik.ali |
12 |
import java.util.List;
|
| 23020 |
ashik.ali |
13 |
import java.util.Map;
|
| 25368 |
amit.gupta |
14 |
import java.util.Set;
|
| 28491 |
amit.gupta |
15 |
import java.util.stream.Collectors;
|
| 22860 |
ashik.ali |
16 |
|
|
|
17 |
import javax.servlet.http.HttpServletRequest;
|
| 25368 |
amit.gupta |
18 |
import javax.transaction.Transactional;
|
| 22860 |
ashik.ali |
19 |
|
| 23784 |
ashik.ali |
20 |
import org.apache.logging.log4j.LogManager;
|
| 23568 |
govind |
21 |
import org.apache.logging.log4j.Logger;
|
| 22860 |
ashik.ali |
22 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23784 |
ashik.ali |
23 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 23020 |
ashik.ali |
24 |
import org.springframework.core.io.InputStreamResource;
|
|
|
25 |
import org.springframework.http.HttpHeaders;
|
|
|
26 |
import org.springframework.http.HttpStatus;
|
|
|
27 |
import org.springframework.http.ResponseEntity;
|
| 22860 |
ashik.ali |
28 |
import org.springframework.stereotype.Controller;
|
|
|
29 |
import org.springframework.ui.Model;
|
|
|
30 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
31 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
32 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
33 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
34 |
|
| 23020 |
ashik.ali |
35 |
import com.spice.profitmandi.common.enumuration.DateTimePattern;
|
| 22860 |
ashik.ali |
36 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 23914 |
govind |
37 |
import com.spice.profitmandi.common.model.MapWrapper;
|
| 22860 |
ashik.ali |
38 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 23557 |
amit.gupta |
39 |
import com.spice.profitmandi.common.model.SchemeItems;
|
| 23020 |
ashik.ali |
40 |
import com.spice.profitmandi.common.model.SchemeModel;
|
|
|
41 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
| 27394 |
amit.gupta |
42 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 23020 |
ashik.ali |
43 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 23784 |
ashik.ali |
44 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 28492 |
amit.gupta |
45 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 22860 |
ashik.ali |
46 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
| 27389 |
amit.gupta |
47 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 28136 |
tejbeer |
48 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 28795 |
tejbeer |
49 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| 25505 |
amit.gupta |
50 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
| 28795 |
tejbeer |
51 |
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
|
| 23556 |
amit.gupta |
52 |
import com.spice.profitmandi.dao.entity.fofo.SchemeItem;
|
| 28795 |
tejbeer |
53 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
|
|
54 |
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
|
| 27389 |
amit.gupta |
55 |
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
|
| 28491 |
amit.gupta |
56 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
| 28795 |
tejbeer |
57 |
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
|
| 27876 |
amit.gupta |
58 |
import com.spice.profitmandi.dao.model.CreateOfferRequest;
|
| 25505 |
amit.gupta |
59 |
import com.spice.profitmandi.dao.model.CreateSchemeRequest;
|
| 26674 |
tejbeer |
60 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 22860 |
ashik.ali |
61 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
| 27389 |
amit.gupta |
62 |
import com.spice.profitmandi.dao.repository.catalog.StateGstRateRepository;
|
| 23556 |
amit.gupta |
63 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 26588 |
tejbeer |
64 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
|
|
65 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 28795 |
tejbeer |
66 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
| 26674 |
tejbeer |
67 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
|
| 28795 |
tejbeer |
68 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
|
| 23556 |
amit.gupta |
69 |
import com.spice.profitmandi.dao.repository.fofo.SchemeItemRepository;
|
| 28795 |
tejbeer |
70 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
|
|
|
71 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
| 23798 |
amit.gupta |
72 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 23020 |
ashik.ali |
73 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 27876 |
amit.gupta |
74 |
import com.spice.profitmandi.service.offers.OfferService;
|
| 22860 |
ashik.ali |
75 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 26588 |
tejbeer |
76 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 22860 |
ashik.ali |
77 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
78 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 23570 |
amit.gupta |
79 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 22860 |
ashik.ali |
80 |
|
|
|
81 |
@Controller
|
| 25369 |
amit.gupta |
82 |
@Transactional(rollbackOn = Throwable.class)
|
| 22860 |
ashik.ali |
83 |
public class SchemeController {
|
|
|
84 |
|
| 23568 |
govind |
85 |
private static final Logger LOGGER = LogManager.getLogger(SchemeController.class);
|
| 22860 |
ashik.ali |
86 |
|
|
|
87 |
@Autowired
|
| 22927 |
ashik.ali |
88 |
private SchemeService schemeService;
|
| 27897 |
amit.gupta |
89 |
|
| 27876 |
amit.gupta |
90 |
@Autowired
|
|
|
91 |
private OfferService offerService;
|
| 23786 |
amit.gupta |
92 |
|
| 22860 |
ashik.ali |
93 |
@Autowired
|
| 27389 |
amit.gupta |
94 |
private StateGstRateRepository stateGstRateRepository;
|
| 27612 |
tejbeer |
95 |
|
| 27389 |
amit.gupta |
96 |
@Autowired
|
| 27416 |
amit.gupta |
97 |
private ItemRepository itemRepository;
|
| 27612 |
tejbeer |
98 |
|
| 27416 |
amit.gupta |
99 |
@Autowired
|
| 22927 |
ashik.ali |
100 |
private SchemeRepository schemeRepository;
|
| 22860 |
ashik.ali |
101 |
|
|
|
102 |
@Autowired
|
| 23556 |
amit.gupta |
103 |
private SchemeItemRepository schemeItemRepository;
|
| 23786 |
amit.gupta |
104 |
|
| 23556 |
amit.gupta |
105 |
@Autowired
|
| 23570 |
amit.gupta |
106 |
private MVCResponseSender mvcResponseSender;
|
| 23786 |
amit.gupta |
107 |
|
| 23570 |
amit.gupta |
108 |
@Autowired
|
| 22927 |
ashik.ali |
109 |
private CookiesProcessor cookiesProcessor;
|
| 23786 |
amit.gupta |
110 |
|
| 23020 |
ashik.ali |
111 |
@Autowired
|
| 23784 |
ashik.ali |
112 |
@Qualifier("fofoInventoryService")
|
| 23020 |
ashik.ali |
113 |
private InventoryService inventoryService;
|
| 23556 |
amit.gupta |
114 |
|
|
|
115 |
@Autowired
|
|
|
116 |
private TagListingRepository tagListingRepository;
|
| 23914 |
govind |
117 |
|
| 23798 |
amit.gupta |
118 |
@Autowired
|
|
|
119 |
private RoleManager roleManager;
|
| 23786 |
amit.gupta |
120 |
|
| 23506 |
amit.gupta |
121 |
@Autowired
|
| 27394 |
amit.gupta |
122 |
private ResponseSender<?> responseSender;
|
| 23786 |
amit.gupta |
123 |
|
| 23784 |
ashik.ali |
124 |
@Autowired
|
| 27394 |
amit.gupta |
125 |
private FofoStoreRepository fofoStoreRepository;
|
| 23786 |
amit.gupta |
126 |
|
| 23784 |
ashik.ali |
127 |
@Autowired
|
| 27394 |
amit.gupta |
128 |
private RetailerService retailerService;
|
| 22860 |
ashik.ali |
129 |
|
| 27394 |
amit.gupta |
130 |
@Autowired
|
|
|
131 |
private Mongo mongoClient;
|
| 26588 |
tejbeer |
132 |
|
|
|
133 |
@Autowired
|
| 26674 |
tejbeer |
134 |
private PartnerTypeChangeService partnerTypeChangeService;
|
|
|
135 |
|
| 28795 |
tejbeer |
136 |
@Autowired
|
|
|
137 |
InventoryItemRepository inventoryItemRepository;
|
|
|
138 |
|
|
|
139 |
@Autowired
|
|
|
140 |
PriceDropIMEIRepository priceDropIMEIRepository;
|
|
|
141 |
|
|
|
142 |
@Autowired
|
|
|
143 |
PriceDropRepository priceDropRepository;
|
|
|
144 |
|
|
|
145 |
@Autowired
|
|
|
146 |
SchemeInOutRepository schemeInOutRepository;
|
|
|
147 |
|
| 22860 |
ashik.ali |
148 |
@RequestMapping(value = "/createScheme", method = RequestMethod.GET)
|
| 23786 |
amit.gupta |
149 |
public String createScheme(HttpServletRequest request, Model model) {
|
|
|
150 |
// Map<Integer, String> itemIdItemDescriptionMap =
|
|
|
151 |
// inventoryService.getAllItemIdItemDescriptionMap();
|
|
|
152 |
// model.addAttribute("itemIdItemDescriptionMap", itemIdItemDescriptionMap);
|
| 25368 |
amit.gupta |
153 |
Set<String> brands = inventoryService.getAllTagListingBrands(ProfitMandiConstants.MOBILE_CATEGORY_ID);
|
|
|
154 |
brands.addAll(inventoryService.getAllTagListingBrands(14206));
|
|
|
155 |
model.addAttribute("brands", brands);
|
| 25505 |
amit.gupta |
156 |
model.addAttribute("retailerTypes", PartnerType.values());
|
| 22860 |
ashik.ali |
157 |
return "create-scheme";
|
|
|
158 |
}
|
| 23786 |
amit.gupta |
159 |
|
| 23914 |
govind |
160 |
@RequestMapping(value = "/getTagListingItemsByBrand", method = RequestMethod.POST)
|
|
|
161 |
public String getTagListingItemsByBrand(HttpServletRequest request, @RequestBody List<String> brands, Model model) {
|
|
|
162 |
Map<Integer, String> itemIdItemDescriptionMap = new HashMap<>();
|
|
|
163 |
LOGGER.info("brands" + brands);
|
|
|
164 |
|
|
|
165 |
List<MapWrapper<Integer, String>> itemIdItemDescriptionMaplist = inventoryService
|
|
|
166 |
.getAllTagListingItemIdItemDescriptionMap(new HashSet<>(brands));
|
|
|
167 |
for (MapWrapper<Integer, String> mapWrapper : itemIdItemDescriptionMaplist) {
|
|
|
168 |
itemIdItemDescriptionMap.put(mapWrapper.getKey(), mapWrapper.getValue());
|
|
|
169 |
}
|
| 23020 |
ashik.ali |
170 |
model.addAttribute("itemIdItemDescriptionMap", itemIdItemDescriptionMap);
|
| 23786 |
amit.gupta |
171 |
// model.addAttribute("brands", inventoryService.getAllBrands());
|
| 23914 |
govind |
172 |
|
| 23419 |
ashik.ali |
173 |
return "tag-listing-items-description";
|
| 23020 |
ashik.ali |
174 |
}
|
| 23556 |
amit.gupta |
175 |
|
|
|
176 |
@RequestMapping(value = "/schemes/update-schemes-page", method = RequestMethod.GET)
|
|
|
177 |
public String updateShcemes(HttpServletRequest request) throws ProfitMandiBusinessException {
|
|
|
178 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23799 |
amit.gupta |
179 |
if (!roleManager.isAdmin(loginDetails.getRoleIds())) {
|
| 23556 |
amit.gupta |
180 |
throw new ProfitMandiBusinessException("User", loginDetails.getEmailId(), "Unauthorised access");
|
|
|
181 |
}
|
|
|
182 |
return "update-schemes-page";
|
|
|
183 |
}
|
| 25256 |
amit.gupta |
184 |
|
| 23556 |
amit.gupta |
185 |
@RequestMapping(value = "/schemes/update", method = RequestMethod.POST)
|
| 23786 |
amit.gupta |
186 |
public String updateShcemes(HttpServletRequest request, @RequestBody SchemeItems schemeItems, Model model)
|
|
|
187 |
throws Exception {
|
|
|
188 |
for (int schemeId : schemeItems.getSchemeIds()) {
|
| 23928 |
govind |
189 |
if (schemeRepository.selectById(schemeId) != null)
|
|
|
190 |
for (int itemId : schemeItems.getItemIds()) {
|
|
|
191 |
if (tagListingRepository.selectByItemIdsAndTagIds(new HashSet<>(Arrays.asList(itemId)),
|
|
|
192 |
new HashSet<>(Arrays.asList(4, 7))).size() > 0) {
|
|
|
193 |
SchemeItem si = new SchemeItem();
|
|
|
194 |
si.setItemId(itemId);
|
|
|
195 |
si.setSchemeId(schemeId);
|
|
|
196 |
try {
|
|
|
197 |
schemeItemRepository.persist(si);
|
|
|
198 |
} catch (Exception e) {
|
|
|
199 |
LOGGER.info("Scheme aleady exist");
|
|
|
200 |
}
|
|
|
201 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
202 |
} else {
|
|
|
203 |
model.addAttribute("response", mvcResponseSender.createResponseString(false));
|
|
|
204 |
throw new ProfitMandiBusinessException("ItemId", itemId, "Invalid Item Id");
|
|
|
205 |
}
|
|
|
206 |
}
|
|
|
207 |
}
|
|
|
208 |
return "response";
|
|
|
209 |
}
|
| 25256 |
amit.gupta |
210 |
|
| 23928 |
govind |
211 |
@RequestMapping(value = "/addItemToScheme", method = RequestMethod.POST)
|
|
|
212 |
public String updateScheme(HttpServletRequest request, @RequestBody SchemeItems schemeItems, Model model)
|
|
|
213 |
throws Exception {
|
|
|
214 |
for (int schemeId : schemeItems.getSchemeIds()) {
|
| 23914 |
govind |
215 |
List<Integer> itemIds = schemeItemRepository.selectItemIdsBySchemeId(schemeId);
|
| 23786 |
amit.gupta |
216 |
if (schemeRepository.selectById(schemeId) != null)
|
|
|
217 |
for (int itemId : schemeItems.getItemIds()) {
|
|
|
218 |
if (tagListingRepository.selectByItemIdsAndTagIds(new HashSet<>(Arrays.asList(itemId)),
|
| 23914 |
govind |
219 |
new HashSet<>(Arrays.asList(4, 7))).size() > 0 && (!(itemIds.contains(itemId)))) {
|
| 23786 |
amit.gupta |
220 |
SchemeItem si = new SchemeItem();
|
|
|
221 |
si.setItemId(itemId);
|
|
|
222 |
si.setSchemeId(schemeId);
|
|
|
223 |
try {
|
|
|
224 |
schemeItemRepository.persist(si);
|
|
|
225 |
} catch (Exception e) {
|
| 23914 |
govind |
226 |
LOGGER.info("Scheme already exist");
|
| 23786 |
amit.gupta |
227 |
}
|
|
|
228 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
229 |
} else {
|
|
|
230 |
model.addAttribute("response", mvcResponseSender.createResponseString(false));
|
| 23556 |
amit.gupta |
231 |
}
|
|
|
232 |
}
|
|
|
233 |
}
|
|
|
234 |
return "response";
|
|
|
235 |
}
|
| 23914 |
govind |
236 |
|
|
|
237 |
@RequestMapping(value = "/schemes/delete", method = RequestMethod.DELETE)
|
|
|
238 |
public String deleteShcemes(HttpServletRequest request,
|
|
|
239 |
@RequestParam(name = "schemeId", required = false, defaultValue = "0") int schemeId,
|
|
|
240 |
@RequestParam(name = "itemId", required = false, defaultValue = "0") int itemId, Model model)
|
| 23819 |
govind |
241 |
throws Exception {
|
| 23914 |
govind |
242 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
243 |
if (!(schemeId == 0 && itemId == 0) || (!(schemeId == 0 || itemId == 0))) {
|
|
|
244 |
schemeItemRepository.deletebyItemIdsandSchemeIds(itemId, schemeId);
|
|
|
245 |
|
|
|
246 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
247 |
|
|
|
248 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
|
|
249 |
|
|
|
250 |
}
|
|
|
251 |
return "response";
|
|
|
252 |
}
|
|
|
253 |
|
|
|
254 |
@RequestMapping(value = "/extendAllSchemes", method = RequestMethod.POST)
|
|
|
255 |
public String extendAllScheme(HttpServletRequest request, @RequestBody LocalDateTime extendDatetime, Model model)
|
|
|
256 |
throws Exception {
|
|
|
257 |
|
|
|
258 |
List<Scheme> schemes = schemeRepository.selectActiveAll();
|
|
|
259 |
if (schemes.size() > 0) {
|
|
|
260 |
for (Scheme scheme : schemes) {
|
| 25261 |
amit.gupta |
261 |
if (scheme.getExpireTimestamp() == null) {
|
| 23914 |
govind |
262 |
scheme.setEndDateTime(extendDatetime);
|
|
|
263 |
schemeRepository.persist(scheme);
|
| 23819 |
govind |
264 |
}
|
|
|
265 |
}
|
| 23914 |
govind |
266 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
267 |
return "response";
|
| 23819 |
govind |
268 |
}
|
| 23914 |
govind |
269 |
model.addAttribute("response", mvcResponseSender.createResponseString(false));
|
| 23819 |
govind |
270 |
return "response";
|
|
|
271 |
}
|
| 23786 |
amit.gupta |
272 |
|
| 23914 |
govind |
273 |
@RequestMapping(value = "/extendSchemeById", method = RequestMethod.POST)
|
|
|
274 |
public String extendSchemeById(HttpServletRequest request,
|
| 23819 |
govind |
275 |
|
| 23914 |
govind |
276 |
@RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId,
|
|
|
277 |
@RequestBody LocalDateTime extendDatetime, Model model) throws Exception {
|
|
|
278 |
|
|
|
279 |
LOGGER.info("ExtendDatetime" + extendDatetime);
|
|
|
280 |
LOGGER.info("schemeId" + schemeId);
|
|
|
281 |
Scheme scheme = schemeRepository.selectById(schemeId);
|
|
|
282 |
if ((!(scheme.getActiveTimestamp() == null)) && scheme.getExpireTimestamp() == null) {
|
|
|
283 |
scheme.setEndDateTime(extendDatetime);
|
|
|
284 |
schemeRepository.persist(scheme);
|
|
|
285 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
286 |
return "response";
|
|
|
287 |
}
|
|
|
288 |
model.addAttribute("response", mvcResponseSender.createResponseString(false));
|
|
|
289 |
return "response";
|
|
|
290 |
}
|
|
|
291 |
|
| 22860 |
ashik.ali |
292 |
@RequestMapping(value = "/createScheme", method = RequestMethod.POST)
|
| 23715 |
govind |
293 |
public String createScheme(HttpServletRequest request, @RequestBody CreateSchemeRequest createSchemeRequest,
|
|
|
294 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 23752 |
govind |
295 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
296 |
@RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem,
|
|
|
297 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
| 23715 |
govind |
298 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
299 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 22860 |
ashik.ali |
300 |
LOGGER.info("CreateSchemeRequest {}", createSchemeRequest);
|
| 22927 |
ashik.ali |
301 |
schemeService.saveScheme(loginDetails.getFofoId(), createSchemeRequest);
|
|
|
302 |
LOGGER.info("Scheme saved successfully");
|
| 23271 |
ashik.ali |
303 |
long size = schemeRepository.selectAllCount();
|
| 22927 |
ashik.ali |
304 |
List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
|
|
|
305 |
model.addAttribute("schemes", schemes);
|
|
|
306 |
model.addAttribute("start", offset + 1);
|
| 23271 |
ashik.ali |
307 |
model.addAttribute("size", size);
|
| 23752 |
govind |
308 |
model.addAttribute("searchItem", searchItem);
|
|
|
309 |
model.addAttribute("searchTerm", searchTerm);
|
| 23914 |
govind |
310 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 23715 |
govind |
311 |
if (schemes.size() < limit) {
|
| 22927 |
ashik.ali |
312 |
model.addAttribute("end", offset + schemes.size());
|
| 23786 |
amit.gupta |
313 |
} else {
|
| 22927 |
ashik.ali |
314 |
model.addAttribute("end", offset + limit);
|
|
|
315 |
}
|
|
|
316 |
return "schemes";
|
| 23786 |
amit.gupta |
317 |
|
| 22860 |
ashik.ali |
318 |
}
|
| 23786 |
amit.gupta |
319 |
|
| 22860 |
ashik.ali |
320 |
@RequestMapping(value = "/getSchemes", method = RequestMethod.GET)
|
| 23715 |
govind |
321 |
public String getSchemes(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 27876 |
amit.gupta |
322 |
@RequestParam(required = false) LocalDate date,
|
| 23752 |
govind |
323 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
| 27897 |
amit.gupta |
324 |
@RequestParam(name = "searchItem", required = false, defaultValue = "0") int searchItem,
|
| 26802 |
tejbeer |
325 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm,
|
|
|
326 |
@RequestParam(name = "partnerType", required = false, defaultValue = "") PartnerType partnerType,
|
| 28795 |
tejbeer |
327 |
@RequestParam(name = "searchImei", required = false, defaultValue = "") String searchImei, Model model)
|
|
|
328 |
throws ProfitMandiBusinessException {
|
| 23343 |
ashik.ali |
329 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 26802 |
tejbeer |
330 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
| 27876 |
amit.gupta |
331 |
if (date == null) {
|
|
|
332 |
date = LocalDate.now();
|
|
|
333 |
}
|
|
|
334 |
model.addAttribute("date", date);
|
| 26802 |
tejbeer |
335 |
|
| 23343 |
ashik.ali |
336 |
List<Scheme> schemes = null;
|
| 28796 |
tejbeer |
337 |
List<SchemeInOut> schemeInOut = null;
|
|
|
338 |
|
| 23343 |
ashik.ali |
339 |
long size = 0;
|
| 27876 |
amit.gupta |
340 |
|
| 26802 |
tejbeer |
341 |
if (partnerType == null) {
|
| 27876 |
amit.gupta |
342 |
partnerType = partnerTypeChangeService.getTypeOnDate(loginDetails.getFofoId(),
|
|
|
343 |
date.isAfter(LocalDate.now()) ? LocalDate.now() : date);
|
| 23343 |
ashik.ali |
344 |
}
|
| 27394 |
amit.gupta |
345 |
if (!(searchTerm.equals(""))) {
|
| 26802 |
tejbeer |
346 |
schemes = schemeRepository.selectBySearchTerm(searchTerm, offset, limit);
|
| 27612 |
tejbeer |
347 |
for (Scheme scheme : schemes) {
|
|
|
348 |
if (scheme.getAmountType().equals(AmountType.PERCENTAGE)) {
|
| 27394 |
amit.gupta |
349 |
scheme.setAmountModel(scheme.getAmount() + "%");
|
|
|
350 |
} else {
|
|
|
351 |
scheme.setAmountModel(scheme.getAmount() + "");
|
|
|
352 |
}
|
|
|
353 |
}
|
| 27876 |
amit.gupta |
354 |
if (schemes.size() > 0) {
|
| 26802 |
tejbeer |
355 |
size = schemeRepository.selectAllCount();
|
|
|
356 |
LOGGER.info("schemes" + schemes);
|
|
|
357 |
model.addAttribute("schemes", schemes);
|
|
|
358 |
model.addAttribute("start", offset + 1);
|
|
|
359 |
model.addAttribute("size", size);
|
|
|
360 |
if (schemes.size() < limit) {
|
|
|
361 |
model.addAttribute("end", offset + schemes.size());
|
| 27876 |
amit.gupta |
362 |
} else {
|
| 26802 |
tejbeer |
363 |
model.addAttribute("end", offset + limit);
|
|
|
364 |
}
|
| 27612 |
tejbeer |
365 |
}
|
|
|
366 |
|
|
|
367 |
else {
|
| 26802 |
tejbeer |
368 |
throw new ProfitMandiBusinessException("SchemeId", searchTerm, "SchemeId Not Found");
|
|
|
369 |
}
|
| 27612 |
tejbeer |
370 |
}
|
|
|
371 |
|
| 27897 |
amit.gupta |
372 |
else if (searchItem > 0) {
|
| 27394 |
amit.gupta |
373 |
TagListing tagListing = null;
|
| 28134 |
tejbeer |
374 |
tagListing = tagListingRepository.selectByItemId(searchItem);
|
| 28492 |
amit.gupta |
375 |
Item item = itemRepository.selectById(searchItem);
|
| 28134 |
tejbeer |
376 |
if (tagListing != null) {
|
|
|
377 |
model.addAttribute("dp", tagListing.getSellingPrice());
|
|
|
378 |
model.addAttribute("mop", tagListing.getMop());
|
| 26802 |
tejbeer |
379 |
}
|
| 27897 |
amit.gupta |
380 |
schemes = schemeService.selectSchemeByPartnerType(partnerType, date, searchItem, isAdmin, offset, limit);
|
| 27424 |
tejbeer |
381 |
model.addAttribute("schemes", schemes);
|
| 27612 |
tejbeer |
382 |
if (schemes.size() == 0) {
|
| 28795 |
tejbeer |
383 |
if (isAdmin)
|
|
|
384 |
return "schemes";
|
|
|
385 |
else {
|
| 27612 |
tejbeer |
386 |
|
| 28795 |
tejbeer |
387 |
return "schemes-partner";
|
| 27389 |
amit.gupta |
388 |
}
|
|
|
389 |
}
|
| 28795 |
tejbeer |
390 |
// For 7720(HR) remove investment
|
|
|
391 |
int nlc = this.getNlc(item, loginDetails.getFofoId(), schemes, tagListing, searchItem);
|
| 27897 |
amit.gupta |
392 |
size = schemeService.selectSchemeCount(partnerType, date, searchItem, isAdmin);
|
| 26802 |
tejbeer |
393 |
model.addAttribute("start", offset + 1);
|
|
|
394 |
model.addAttribute("size", size);
|
|
|
395 |
if (schemes.size() < limit) {
|
|
|
396 |
model.addAttribute("end", offset + schemes.size());
|
|
|
397 |
} else {
|
|
|
398 |
model.addAttribute("end", offset + limit);
|
|
|
399 |
}
|
| 28547 |
amit.gupta |
400 |
model.addAttribute("nlc", Math.round(nlc));
|
| 28795 |
tejbeer |
401 |
} else if (!(searchImei.equals(""))) {
|
|
|
402 |
|
|
|
403 |
LOGGER.info("searchImei" + searchImei);
|
|
|
404 |
|
|
|
405 |
InventoryItem inventoryItem = inventoryItemRepository.selectBySerialNumberFofoId(searchImei,
|
|
|
406 |
loginDetails.getFofoId());
|
| 28802 |
tejbeer |
407 |
Item item = itemRepository.selectById(inventoryItem.getItemId());
|
| 28795 |
tejbeer |
408 |
Map<Integer, Scheme> schemeMap = new HashMap<>();
|
|
|
409 |
if (inventoryItem != null) {
|
|
|
410 |
|
|
|
411 |
LOGGER.info("inventoryItem" + inventoryItem);
|
|
|
412 |
|
|
|
413 |
schemeInOut = schemeInOutRepository
|
|
|
414 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItem.getId())));
|
|
|
415 |
|
|
|
416 |
LOGGER.info("schemeInOut" + schemeInOut);
|
|
|
417 |
|
|
|
418 |
if (!schemeInOut.isEmpty()) {
|
|
|
419 |
|
|
|
420 |
List<Integer> schemeIds = schemeInOut.stream().map(x -> x.getSchemeId())
|
|
|
421 |
.collect(Collectors.toList());
|
|
|
422 |
|
|
|
423 |
schemes = schemeRepository.selectBySchemeIds(schemeIds);
|
|
|
424 |
for (Scheme scheme : schemes) {
|
|
|
425 |
if (scheme.getAmountType().equals(AmountType.PERCENTAGE)) {
|
|
|
426 |
scheme.setAmountModel(scheme.getAmount() + "%");
|
|
|
427 |
} else {
|
|
|
428 |
scheme.setAmountModel(scheme.getAmount() + "");
|
|
|
429 |
}
|
|
|
430 |
}
|
|
|
431 |
|
|
|
432 |
schemeMap = schemes.stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
433 |
}
|
|
|
434 |
}
|
|
|
435 |
|
|
|
436 |
model.addAttribute("schemeMap", schemeMap);
|
| 28802 |
tejbeer |
437 |
model.addAttribute("item", item);
|
| 28795 |
tejbeer |
438 |
|
| 28796 |
tejbeer |
439 |
}
|
|
|
440 |
model.addAttribute("schemeInOut", schemeInOut);
|
| 28795 |
tejbeer |
441 |
|
| 27876 |
amit.gupta |
442 |
model.addAttribute("searchItem", searchItem);
|
|
|
443 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
444 |
model.addAttribute("partnerType", partnerType);
|
|
|
445 |
model.addAttribute("isAdmin", isAdmin);
|
| 27612 |
tejbeer |
446 |
model.addAttribute("schemes", schemes);
|
| 27876 |
amit.gupta |
447 |
LOGGER.info("schemes" + schemes);
|
| 23786 |
amit.gupta |
448 |
// model.addAttribute("roleTypes", loginDetails.getRoleTypes());
|
| 27876 |
amit.gupta |
449 |
if (isAdmin)
|
|
|
450 |
return "schemes";
|
|
|
451 |
else {
|
| 27897 |
amit.gupta |
452 |
List<CreateOfferRequest> offers = new ArrayList<>();
|
| 28795 |
tejbeer |
453 |
List<PriceDropIMEI> priceDropImeis = new ArrayList<>();
|
| 28134 |
tejbeer |
454 |
if (searchItem > 0) {
|
| 27897 |
amit.gupta |
455 |
offers = offerService.getPublishedOffers(date, loginDetails.getFofoId(), searchItem);
|
|
|
456 |
}
|
| 28795 |
tejbeer |
457 |
if (!(searchImei.equals(""))) {
|
|
|
458 |
InventoryItem inventoryItem = inventoryItemRepository.selectBySerialNumberFofoId(searchImei,
|
|
|
459 |
loginDetails.getFofoId());
|
|
|
460 |
|
|
|
461 |
priceDropImeis = priceDropIMEIRepository.selectByFofoIdImei(loginDetails.getFofoId(), searchImei);
|
|
|
462 |
for (PriceDropIMEI priceDropIMEI : priceDropImeis) {
|
|
|
463 |
int priceDropId = priceDropIMEI.getPriceDropId();
|
|
|
464 |
PriceDrop pd = priceDropRepository.selectById(priceDropId);
|
|
|
465 |
|
|
|
466 |
priceDropIMEI.setPriceDrop(pd);
|
|
|
467 |
}
|
|
|
468 |
}
|
| 28136 |
tejbeer |
469 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
|
|
|
470 |
|
| 27876 |
amit.gupta |
471 |
model.addAttribute("offers", offers);
|
| 28136 |
tejbeer |
472 |
model.addAttribute("partnerCode", fs.getCode());
|
| 28795 |
tejbeer |
473 |
model.addAttribute("fofoId", fs.getId());
|
|
|
474 |
model.addAttribute("priceDropImeis", priceDropImeis);
|
| 27876 |
amit.gupta |
475 |
return "schemes-partner";
|
|
|
476 |
}
|
| 22860 |
ashik.ali |
477 |
}
|
| 23786 |
amit.gupta |
478 |
|
| 28795 |
tejbeer |
479 |
private int getNlc(Item item, int fofoId, List<Scheme> schemes, TagListing tagListing, int itemId)
|
|
|
480 |
throws ProfitMandiBusinessException {
|
|
|
481 |
|
|
|
482 |
if (item.getBrand().equals("Vivo") && fofoStoreRepository.getWarehousePartnerMap().get(7720).stream()
|
|
|
483 |
.filter(x -> x.getId() == fofoId).count() > 0) {
|
|
|
484 |
schemes = schemes.stream().filter(x -> !x.getType().equals(SchemeType.INVESTMENT))
|
|
|
485 |
.collect(Collectors.toList());
|
|
|
486 |
}
|
|
|
487 |
float nlc = tagListing.getSellingPrice();
|
|
|
488 |
for (Scheme scheme : schemes) {
|
|
|
489 |
if (scheme.getAmountType().equals(AmountType.PERCENTAGE)) {
|
|
|
490 |
if (tagListing != null) {
|
|
|
491 |
float taxRate = stateGstRateRepository.getIgstTaxRate(Arrays.asList(itemId)).get(itemId);
|
|
|
492 |
float taxableSellingPrice = tagListing.getSellingPrice() / (1 + taxRate / 100);
|
|
|
493 |
float amount = taxableSellingPrice * scheme.getAmount() / 100;
|
|
|
494 |
scheme.setAmountModel(
|
|
|
495 |
FormattingUtils.formatDecimalTwoDigits(amount) + " (" + scheme.getAmount() + "%)");
|
|
|
496 |
nlc -= amount;
|
|
|
497 |
}
|
|
|
498 |
|
|
|
499 |
else {
|
|
|
500 |
scheme.setAmountModel(scheme.getAmount() + "%");
|
|
|
501 |
}
|
|
|
502 |
} else {
|
|
|
503 |
scheme.setAmountModel(scheme.getAmount() + "");
|
|
|
504 |
nlc -= scheme.getAmount();
|
|
|
505 |
}
|
|
|
506 |
}
|
|
|
507 |
|
|
|
508 |
return Math.round(nlc);
|
|
|
509 |
|
|
|
510 |
}
|
|
|
511 |
|
| 22860 |
ashik.ali |
512 |
@RequestMapping(value = "/getPaginatedSchemes", method = RequestMethod.GET)
|
| 27876 |
amit.gupta |
513 |
public String getPaginatedSchemes(HttpServletRequest request, @RequestParam(required = false) LocalDate date,
|
| 23786 |
amit.gupta |
514 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 26802 |
tejbeer |
515 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
| 27876 |
amit.gupta |
516 |
@RequestParam(name = "partnerType", required = false, defaultValue = "ALL") PartnerType partnerType,
|
| 26802 |
tejbeer |
517 |
Model model) throws ProfitMandiBusinessException {
|
|
|
518 |
|
| 23343 |
ashik.ali |
519 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 26802 |
tejbeer |
520 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
| 27876 |
amit.gupta |
521 |
if (date == null) {
|
|
|
522 |
date = LocalDate.now();
|
|
|
523 |
}
|
| 23271 |
ashik.ali |
524 |
LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
|
| 27876 |
amit.gupta |
525 |
List<Scheme> schemes = schemeRepository.selectAll();
|
| 26802 |
tejbeer |
526 |
int itemId = 0;
|
| 27394 |
amit.gupta |
527 |
TagListing tagListing = null;
|
| 27897 |
amit.gupta |
528 |
|
| 27612 |
tejbeer |
529 |
for (Scheme scheme : schemes) {
|
|
|
530 |
if (scheme.getAmountType().equals(AmountType.PERCENTAGE)) {
|
|
|
531 |
if (itemId > 0) {
|
| 27394 |
amit.gupta |
532 |
float taxRate = stateGstRateRepository.getIgstTaxRate(Arrays.asList(itemId)).get(itemId);
|
|
|
533 |
float taxableSellingPrice = tagListing.getSellingPrice() / (1 + taxRate / 100);
|
|
|
534 |
float amount = taxableSellingPrice * scheme.getAmount() / 100;
|
| 27612 |
tejbeer |
535 |
scheme.setAmountModel(
|
|
|
536 |
FormattingUtils.formatDecimalTwoDigits(amount) + " (" + scheme.getAmount() + "%)");
|
| 27394 |
amit.gupta |
537 |
} else {
|
|
|
538 |
scheme.setAmountModel(scheme.getAmount() + "%");
|
|
|
539 |
}
|
|
|
540 |
} else {
|
| 27876 |
amit.gupta |
541 |
scheme.setAmountModel("" + scheme.getAmount());
|
| 27394 |
amit.gupta |
542 |
}
|
|
|
543 |
}
|
| 26802 |
tejbeer |
544 |
|
| 22860 |
ashik.ali |
545 |
model.addAttribute("schemes", schemes);
|
| 26912 |
tejbeer |
546 |
model.addAttribute("partnerType", partnerType);
|
| 23914 |
govind |
547 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 22860 |
ashik.ali |
548 |
return "schemes-paginated";
|
|
|
549 |
}
|
| 23786 |
amit.gupta |
550 |
|
| 23020 |
ashik.ali |
551 |
@RequestMapping(value = "/schemes/downloadPage", method = RequestMethod.GET)
|
| 23786 |
amit.gupta |
552 |
public String downloadPage(HttpServletRequest request, Model model) {
|
| 23020 |
ashik.ali |
553 |
return "schemes-download";
|
|
|
554 |
}
|
| 23786 |
amit.gupta |
555 |
|
| 23020 |
ashik.ali |
556 |
@RequestMapping(value = "/schemes/download", method = RequestMethod.GET)
|
| 23786 |
amit.gupta |
557 |
public ResponseEntity<?> downloadInventoryItemAgingByInterval(HttpServletRequest request,
|
| 23914 |
govind |
558 |
@RequestParam(name = ProfitMandiConstants.START_DATE_TIME) String startDateTimeString,
|
|
|
559 |
@RequestParam(name = ProfitMandiConstants.END_DATE_TIME) String endDateTimeString, Model model)
|
| 23786 |
amit.gupta |
560 |
throws ProfitMandiBusinessException {
|
| 23914 |
govind |
561 |
LocalDateTime startDateTime = StringUtils.toDateTime(startDateTimeString,
|
| 24406 |
amit.gupta |
562 |
DateTimePattern.DD_MM_yyyy_T_HH_MM_SS);
|
|
|
563 |
LocalDateTime endDateTime = StringUtils.toDateTime(endDateTimeString, DateTimePattern.DD_MM_yyyy_T_HH_MM_SS);
|
| 23914 |
govind |
564 |
|
| 23020 |
ashik.ali |
565 |
List<SchemeModel> schemeModels = schemeService.getAllSchemeModels(startDateTime, endDateTime);
|
| 23786 |
amit.gupta |
566 |
|
| 23020 |
ashik.ali |
567 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
568 |
ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
|
| 23786 |
amit.gupta |
569 |
|
|
|
570 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
571 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
| 23020 |
ashik.ali |
572 |
headers.set("Content-disposition", "inline; filename=SchemesReport.xlsx");
|
| 23786 |
amit.gupta |
573 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
574 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
575 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
576 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| 23020 |
ashik.ali |
577 |
}
|
| 23786 |
amit.gupta |
578 |
|
| 22860 |
ashik.ali |
579 |
@RequestMapping(value = "/getSchemeById", method = RequestMethod.GET)
|
| 23786 |
amit.gupta |
580 |
public String getSchemeById(HttpServletRequest request,
|
|
|
581 |
@RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId, Model model)
|
|
|
582 |
throws ProfitMandiBusinessException {
|
| 23343 |
ashik.ali |
583 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 22860 |
ashik.ali |
584 |
Scheme scheme = schemeService.getSchemeById(schemeId);
|
|
|
585 |
model.addAttribute("scheme", scheme);
|
| 24445 |
amit.gupta |
586 |
model.addAttribute("isAdmin", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 22860 |
ashik.ali |
587 |
return "scheme-details";
|
| 23914 |
govind |
588 |
|
| 22860 |
ashik.ali |
589 |
}
|
| 23786 |
amit.gupta |
590 |
|
| 22860 |
ashik.ali |
591 |
@RequestMapping(value = "/activeSchemeById", method = RequestMethod.PUT)
|
| 23786 |
amit.gupta |
592 |
public String activeSchemeById(HttpServletRequest request,
|
|
|
593 |
@RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId,
|
|
|
594 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
595 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
596 |
throws ProfitMandiBusinessException {
|
| 22860 |
ashik.ali |
597 |
schemeService.activeSchemeById(schemeId);
|
|
|
598 |
List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
|
|
|
599 |
model.addAttribute("schemes", schemes);
|
|
|
600 |
return "schemes-paginated";
|
|
|
601 |
}
|
| 23786 |
amit.gupta |
602 |
|
| 22860 |
ashik.ali |
603 |
@RequestMapping(value = "/expireSchemeById", method = RequestMethod.PUT)
|
| 23786 |
amit.gupta |
604 |
public String expireSchemeById(HttpServletRequest request,
|
|
|
605 |
@RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId,
|
| 25069 |
amit.gupta |
606 |
@RequestParam(name = ProfitMandiConstants.EXPIRE_TIMESTAMP) LocalDateTime expiryTimestamp,
|
| 23786 |
amit.gupta |
607 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
608 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
609 |
throws ProfitMandiBusinessException {
|
| 25069 |
amit.gupta |
610 |
schemeService.expireSchemeById(schemeId, expiryTimestamp);
|
| 22860 |
ashik.ali |
611 |
List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
|
|
|
612 |
model.addAttribute("schemes", schemes);
|
|
|
613 |
return "schemes-paginated";
|
|
|
614 |
}
|
| 23786 |
amit.gupta |
615 |
|
| 23784 |
ashik.ali |
616 |
@RequestMapping(value = "/getSchemesJson", method = RequestMethod.GET)
|
| 23786 |
amit.gupta |
617 |
public ResponseEntity<?> getSchemesJson(HttpServletRequest request,
|
|
|
618 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
619 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
620 |
throws ProfitMandiBusinessException {
|
| 23784 |
ashik.ali |
621 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
622 |
return responseSender.ok(schemeService.getSchemes(loginDetails.getRoleIds(), offset, limit));
|
|
|
623 |
}
|
| 26802 |
tejbeer |
624 |
|
| 26763 |
tejbeer |
625 |
@RequestMapping(value = "/searchSchemeByCategory")
|
|
|
626 |
public String getSchemeByCategory(HttpServletRequest request,
|
|
|
627 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
628 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
629 |
@RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem,
|
|
|
630 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm,
|
|
|
631 |
@RequestParam(name = "category", required = true, defaultValue = "") PartnerType category, Model model)
|
|
|
632 |
throws ProfitMandiBusinessException {
|
|
|
633 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
634 |
List<Scheme> schemes = null;
|
|
|
635 |
long size = 0;
|
| 26802 |
tejbeer |
636 |
|
|
|
637 |
schemes = schemeRepository.selectByPartnerType(category, offset, limit);
|
|
|
638 |
|
|
|
639 |
if (!(schemes.size() == 0)) {
|
|
|
640 |
size = schemeRepository.selectAllCount();
|
|
|
641 |
LOGGER.info("schemes" + schemes);
|
|
|
642 |
model.addAttribute("schemes", schemes);
|
|
|
643 |
model.addAttribute("start", offset + 1);
|
|
|
644 |
model.addAttribute("size", size);
|
|
|
645 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
646 |
model.addAttribute("searchItem", searchItem);
|
|
|
647 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
|
|
648 |
if (schemes.size() < limit) {
|
|
|
649 |
model.addAttribute("end", offset + schemes.size());
|
|
|
650 |
} else {
|
|
|
651 |
model.addAttribute("end", offset + limit);
|
| 26763 |
tejbeer |
652 |
}
|
| 26802 |
tejbeer |
653 |
}
|
|
|
654 |
|
| 26763 |
tejbeer |
655 |
return "schemes";
|
|
|
656 |
}
|
| 26802 |
tejbeer |
657 |
|
| 26763 |
tejbeer |
658 |
@RequestMapping(value = "/getSchemeByCategoryPaginated")
|
|
|
659 |
public String getSchemeByCategoryPaginated(HttpServletRequest request,
|
|
|
660 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
661 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
662 |
@RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem,
|
|
|
663 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm,
|
|
|
664 |
@RequestParam(name = "category", required = true, defaultValue = "") PartnerType category, Model model)
|
|
|
665 |
throws ProfitMandiBusinessException {
|
|
|
666 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
667 |
LOGGER.info("In search Item....");
|
|
|
668 |
List<Scheme> schemes = null;
|
| 26802 |
tejbeer |
669 |
|
| 26763 |
tejbeer |
670 |
schemes = schemeRepository.selectByPartnerType(category, offset, limit);
|
| 23506 |
amit.gupta |
671 |
|
| 26763 |
tejbeer |
672 |
model.addAttribute("schemes", schemes);
|
|
|
673 |
model.addAttribute("searchItem", searchItem);
|
|
|
674 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
|
|
675 |
return "schemes-paginated";
|
|
|
676 |
}
|
|
|
677 |
|
| 23752 |
govind |
678 |
@RequestMapping(value = "/searchScheme")
|
|
|
679 |
public String getSchemeBySchemeId(HttpServletRequest request,
|
|
|
680 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
681 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
682 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm,
|
|
|
683 |
@RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem, Model model)
|
|
|
684 |
throws ProfitMandiBusinessException {
|
|
|
685 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
686 |
List<Scheme> schemes = null;
|
|
|
687 |
long size = 0;
|
|
|
688 |
if (!(searchTerm.equals("")) && searchItem.equals("")) {
|
|
|
689 |
schemes = schemeRepository.selectBySearchTerm(searchTerm, offset, limit);
|
| 23786 |
amit.gupta |
690 |
if (!(schemes.size() == 0)) {
|
|
|
691 |
size = schemeRepository.selectAllCount();
|
|
|
692 |
LOGGER.info("schemes" + schemes);
|
|
|
693 |
model.addAttribute("schemes", schemes);
|
|
|
694 |
model.addAttribute("start", offset + 1);
|
|
|
695 |
model.addAttribute("size", size);
|
|
|
696 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
697 |
model.addAttribute("searchItem", searchItem);
|
| 23914 |
govind |
698 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 23786 |
amit.gupta |
699 |
if (schemes.size() < limit) {
|
|
|
700 |
model.addAttribute("end", offset + schemes.size());
|
|
|
701 |
} else {
|
|
|
702 |
model.addAttribute("end", offset + limit);
|
|
|
703 |
}
|
| 23752 |
govind |
704 |
} else {
|
| 23786 |
amit.gupta |
705 |
throw new ProfitMandiBusinessException("SchemeId", searchTerm, "SchemeId Not Found");
|
| 23752 |
govind |
706 |
}
|
|
|
707 |
} else if (!(searchItem.equals("")) && searchTerm.equals("")) {
|
|
|
708 |
List<Integer> schemeIds = schemeItemRepository.selectSchemeIdByItemId(Integer.parseInt(searchItem));
|
| 23786 |
amit.gupta |
709 |
if (!(schemeIds.size() == 0)) {
|
| 23752 |
govind |
710 |
LOGGER.info("schemeIds in searchItemScheme" + schemeIds);
|
|
|
711 |
schemes = schemeRepository.selectBySchemeIds(schemeIds, offset, limit);
|
|
|
712 |
size = schemeIds.size();
|
|
|
713 |
LOGGER.info("Size" + size);
|
|
|
714 |
model.addAttribute("schemes", schemes);
|
|
|
715 |
model.addAttribute("start", offset + 1);
|
|
|
716 |
model.addAttribute("size", size);
|
|
|
717 |
model.addAttribute("searchItem", searchItem);
|
|
|
718 |
model.addAttribute("searchTerm", searchTerm);
|
| 23914 |
govind |
719 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 23752 |
govind |
720 |
if (schemes.size() < limit) {
|
|
|
721 |
model.addAttribute("end", offset + schemes.size());
|
|
|
722 |
} else {
|
|
|
723 |
model.addAttribute("end", offset + limit);
|
|
|
724 |
}
|
|
|
725 |
|
|
|
726 |
} else {
|
|
|
727 |
throw new ProfitMandiBusinessException("SchemeIds", searchItem, "SchemeId Not Found");
|
|
|
728 |
}
|
|
|
729 |
} else {
|
| 23798 |
amit.gupta |
730 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
| 23752 |
govind |
731 |
schemes = schemeRepository.selectAll(offset, limit);
|
|
|
732 |
size = schemeRepository.selectAllCount();
|
|
|
733 |
} else {
|
|
|
734 |
schemes = schemeRepository.selectActiveAll(offset, limit);
|
|
|
735 |
size = schemeRepository.selectAllActiveCount();
|
|
|
736 |
}
|
|
|
737 |
model.addAttribute("schemes", schemes);
|
|
|
738 |
model.addAttribute("start", offset + 1);
|
|
|
739 |
model.addAttribute("size", size);
|
|
|
740 |
model.addAttribute("searchItem", searchItem);
|
|
|
741 |
model.addAttribute("searchTerm", searchTerm);
|
| 23914 |
govind |
742 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 23752 |
govind |
743 |
if (schemes.size() < limit) {
|
|
|
744 |
model.addAttribute("end", offset + schemes.size());
|
|
|
745 |
} else {
|
|
|
746 |
model.addAttribute("end", offset + limit);
|
|
|
747 |
}
|
|
|
748 |
}
|
|
|
749 |
return "schemes";
|
|
|
750 |
}
|
|
|
751 |
|
|
|
752 |
@RequestMapping(value = "/searchItemSchemePanigated")
|
|
|
753 |
public String getSchemeByItemPanigated(HttpServletRequest request,
|
|
|
754 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
755 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
756 |
@RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem, Model model)
|
|
|
757 |
throws ProfitMandiBusinessException {
|
| 23914 |
govind |
758 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23752 |
govind |
759 |
LOGGER.info("In search Item....");
|
|
|
760 |
List<Scheme> schemes = null;
|
|
|
761 |
if (!searchItem.equals("")) {
|
|
|
762 |
List<Integer> schemeIds = schemeItemRepository.selectSchemeIdByItemId(Integer.parseInt(searchItem));
|
|
|
763 |
if (schemeIds != null) {
|
|
|
764 |
LOGGER.info(schemeIds);
|
|
|
765 |
schemes = schemeRepository.selectBySchemeIds(schemeIds, offset, limit);
|
|
|
766 |
|
|
|
767 |
}
|
|
|
768 |
}
|
|
|
769 |
model.addAttribute("schemes", schemes);
|
|
|
770 |
model.addAttribute("searchItem", searchItem);
|
| 23914 |
govind |
771 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 23752 |
govind |
772 |
return "schemes-paginated";
|
|
|
773 |
|
|
|
774 |
}
|
| 22860 |
ashik.ali |
775 |
}
|