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