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