| 22860 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 23020 |
ashik.ali |
3 |
import java.io.ByteArrayInputStream;
|
|
|
4 |
import java.io.ByteArrayOutputStream;
|
|
|
5 |
import java.io.InputStream;
|
|
|
6 |
import java.time.LocalDateTime;
|
| 23556 |
amit.gupta |
7 |
import java.util.Arrays;
|
|
|
8 |
import java.util.HashSet;
|
| 22860 |
ashik.ali |
9 |
import java.util.List;
|
| 23020 |
ashik.ali |
10 |
import java.util.Map;
|
| 22860 |
ashik.ali |
11 |
|
|
|
12 |
import javax.servlet.http.HttpServletRequest;
|
|
|
13 |
|
|
|
14 |
import org.slf4j.Logger;
|
|
|
15 |
import org.slf4j.LoggerFactory;
|
|
|
16 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23020 |
ashik.ali |
17 |
import org.springframework.core.io.InputStreamResource;
|
|
|
18 |
import org.springframework.http.HttpHeaders;
|
|
|
19 |
import org.springframework.http.HttpStatus;
|
|
|
20 |
import org.springframework.http.ResponseEntity;
|
| 22860 |
ashik.ali |
21 |
import org.springframework.stereotype.Controller;
|
|
|
22 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
23 |
import org.springframework.ui.Model;
|
|
|
24 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
25 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
26 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
27 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
28 |
|
| 23020 |
ashik.ali |
29 |
import com.spice.profitmandi.common.enumuration.DateTimePattern;
|
| 22860 |
ashik.ali |
30 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
31 |
import com.spice.profitmandi.common.model.CreateSchemeRequest;
|
|
|
32 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 23020 |
ashik.ali |
33 |
import com.spice.profitmandi.common.model.SchemeModel;
|
|
|
34 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
|
|
35 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 22860 |
ashik.ali |
36 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
| 23556 |
amit.gupta |
37 |
import com.spice.profitmandi.dao.entity.fofo.SchemeItem;
|
| 23343 |
ashik.ali |
38 |
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
|
| 22860 |
ashik.ali |
39 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
| 23556 |
amit.gupta |
40 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 23506 |
amit.gupta |
41 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
| 23556 |
amit.gupta |
42 |
import com.spice.profitmandi.dao.repository.fofo.SchemeItemRepository;
|
| 23020 |
ashik.ali |
43 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 22860 |
ashik.ali |
44 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
|
|
45 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
46 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
47 |
|
|
|
48 |
@Controller
|
|
|
49 |
@Transactional(rollbackFor=Throwable.class)
|
|
|
50 |
public class SchemeController {
|
|
|
51 |
|
|
|
52 |
private static final Logger LOGGER = LoggerFactory.getLogger(SchemeController.class);
|
|
|
53 |
|
|
|
54 |
@Autowired
|
| 22927 |
ashik.ali |
55 |
private SchemeService schemeService;
|
| 22860 |
ashik.ali |
56 |
|
|
|
57 |
@Autowired
|
| 22927 |
ashik.ali |
58 |
private SchemeRepository schemeRepository;
|
| 22860 |
ashik.ali |
59 |
|
|
|
60 |
@Autowired
|
| 23556 |
amit.gupta |
61 |
private SchemeItemRepository schemeItemRepository;
|
|
|
62 |
|
|
|
63 |
@Autowired
|
| 22927 |
ashik.ali |
64 |
private CookiesProcessor cookiesProcessor;
|
| 23020 |
ashik.ali |
65 |
|
|
|
66 |
@Autowired
|
|
|
67 |
private InventoryService inventoryService;
|
| 23556 |
amit.gupta |
68 |
|
|
|
69 |
@Autowired
|
|
|
70 |
private TagListingRepository tagListingRepository;
|
| 23506 |
amit.gupta |
71 |
|
|
|
72 |
@Autowired
|
|
|
73 |
PurchaseRepository purchaseRepository;
|
| 22860 |
ashik.ali |
74 |
|
|
|
75 |
@RequestMapping(value = "/createScheme", method = RequestMethod.GET)
|
| 22927 |
ashik.ali |
76 |
public String createScheme(HttpServletRequest request, Model model){
|
| 23020 |
ashik.ali |
77 |
//Map<Integer, String> itemIdItemDescriptionMap = inventoryService.getAllItemIdItemDescriptionMap();
|
|
|
78 |
//model.addAttribute("itemIdItemDescriptionMap", itemIdItemDescriptionMap);
|
| 23419 |
ashik.ali |
79 |
model.addAttribute("brands", inventoryService.getAllTagListingBrands());
|
| 22860 |
ashik.ali |
80 |
return "create-scheme";
|
|
|
81 |
}
|
|
|
82 |
|
| 23419 |
ashik.ali |
83 |
@RequestMapping(value = "/getTagListingItemsByBrand", method = RequestMethod.GET)
|
|
|
84 |
public String getTagListingItemsByBrand(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.BRAND) String brand, Model model){
|
|
|
85 |
Map<Integer, String> itemIdItemDescriptionMap = inventoryService.getAllTagListingItemIdItemDescriptionMap(brand);
|
| 23020 |
ashik.ali |
86 |
model.addAttribute("itemIdItemDescriptionMap", itemIdItemDescriptionMap);
|
|
|
87 |
//model.addAttribute("brands", inventoryService.getAllBrands());
|
| 23419 |
ashik.ali |
88 |
return "tag-listing-items-description";
|
| 23020 |
ashik.ali |
89 |
}
|
| 23556 |
amit.gupta |
90 |
|
|
|
91 |
@RequestMapping(value = "/schemes/update-schemes-page", method = RequestMethod.GET)
|
|
|
92 |
public String updateShcemes(HttpServletRequest request) throws ProfitMandiBusinessException {
|
|
|
93 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
94 |
if(!loginDetails.getRoleTypes().contains(RoleType.FOFO_ADMIN)) {
|
|
|
95 |
throw new ProfitMandiBusinessException("User", loginDetails.getEmailId(), "Unauthorised access");
|
|
|
96 |
}
|
|
|
97 |
return "update-schemes-page";
|
|
|
98 |
}
|
| 23020 |
ashik.ali |
99 |
|
| 23556 |
amit.gupta |
100 |
@RequestMapping(value = "/schemes/update", method = RequestMethod.POST)
|
|
|
101 |
public String updateShcemes(HttpServletRequest request, @RequestParam List<Integer> schemeIds, @RequestParam List<Integer> itemIds) throws ProfitMandiBusinessException {
|
|
|
102 |
for(int schemeId : schemeIds) {
|
|
|
103 |
if(schemeRepository.selectById(schemeId) != null)
|
|
|
104 |
for(int itemId : itemIds) {
|
|
|
105 |
if(tagListingRepository.selectByItemIdsAndTagIds(new HashSet<>(Arrays.asList(itemId)), new HashSet<>(Arrays.asList(4,7))).size() > 0) {
|
|
|
106 |
SchemeItem si = new SchemeItem();
|
|
|
107 |
si.setItemId(itemId);
|
|
|
108 |
si.setSchemeId(schemeId);
|
|
|
109 |
try {
|
|
|
110 |
schemeItemRepository.persist(si);
|
|
|
111 |
} catch (Exception e) {
|
|
|
112 |
LOGGER.info("Scheme aleady exist");
|
|
|
113 |
}
|
|
|
114 |
} else {
|
|
|
115 |
throw new ProfitMandiBusinessException("ItemId", itemId,"Invalid Item Id");
|
|
|
116 |
}
|
|
|
117 |
}
|
|
|
118 |
}
|
|
|
119 |
return "response";
|
|
|
120 |
}
|
| 23020 |
ashik.ali |
121 |
|
| 23556 |
amit.gupta |
122 |
|
| 22860 |
ashik.ali |
123 |
@RequestMapping(value = "/createScheme", method = RequestMethod.POST)
|
| 22927 |
ashik.ali |
124 |
public String createScheme(HttpServletRequest request, @RequestBody CreateSchemeRequest createSchemeRequest, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws ProfitMandiBusinessException{
|
|
|
125 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 22860 |
ashik.ali |
126 |
LOGGER.info("CreateSchemeRequest {}", createSchemeRequest);
|
| 22927 |
ashik.ali |
127 |
schemeService.saveScheme(loginDetails.getFofoId(), createSchemeRequest);
|
|
|
128 |
LOGGER.info("Scheme saved successfully");
|
| 23271 |
ashik.ali |
129 |
long size = schemeRepository.selectAllCount();
|
| 22927 |
ashik.ali |
130 |
List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
|
|
|
131 |
model.addAttribute("schemes", schemes);
|
|
|
132 |
model.addAttribute("start", offset + 1);
|
| 23271 |
ashik.ali |
133 |
model.addAttribute("size", size);
|
| 22927 |
ashik.ali |
134 |
if (schemes.size() < limit){
|
|
|
135 |
model.addAttribute("end", offset + schemes.size());
|
| 22860 |
ashik.ali |
136 |
}
|
| 22927 |
ashik.ali |
137 |
else{
|
|
|
138 |
model.addAttribute("end", offset + limit);
|
|
|
139 |
}
|
|
|
140 |
return "schemes";
|
|
|
141 |
|
| 22860 |
ashik.ali |
142 |
}
|
|
|
143 |
|
|
|
144 |
@RequestMapping(value = "/getSchemes", method = RequestMethod.GET)
|
| 23343 |
ashik.ali |
145 |
public String getSchemes(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws ProfitMandiBusinessException{
|
|
|
146 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
147 |
List<Scheme> schemes = null;
|
|
|
148 |
long size = 0;
|
|
|
149 |
if(loginDetails.getRoleTypes().contains(RoleType.FOFO_ADMIN)){
|
|
|
150 |
schemes = schemeRepository.selectAll(offset, limit);
|
|
|
151 |
size = schemeRepository.selectAllCount();
|
|
|
152 |
}else{
|
|
|
153 |
schemes = schemeRepository.selectActiveAll(offset, limit);
|
|
|
154 |
size = schemeRepository.selectAllActiveCount();
|
|
|
155 |
}
|
| 22860 |
ashik.ali |
156 |
model.addAttribute("schemes", schemes);
|
|
|
157 |
model.addAttribute("start", offset + 1);
|
| 23271 |
ashik.ali |
158 |
model.addAttribute("size", size);
|
| 22860 |
ashik.ali |
159 |
if (schemes.size() < limit){
|
|
|
160 |
model.addAttribute("end", offset + schemes.size());
|
|
|
161 |
}
|
|
|
162 |
else{
|
|
|
163 |
model.addAttribute("end", offset + limit);
|
|
|
164 |
}
|
| 23343 |
ashik.ali |
165 |
//model.addAttribute("roleTypes", loginDetails.getRoleTypes());
|
| 22860 |
ashik.ali |
166 |
return "schemes";
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
@RequestMapping(value = "/getPaginatedSchemes", method = RequestMethod.GET)
|
| 23343 |
ashik.ali |
170 |
public String getPaginatedSchemes(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws ProfitMandiBusinessException{
|
|
|
171 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23271 |
ashik.ali |
172 |
LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
|
| 23343 |
ashik.ali |
173 |
List<Scheme> schemes = null;
|
|
|
174 |
if(loginDetails.getRoleTypes().contains(RoleType.FOFO_ADMIN)){
|
|
|
175 |
schemes = schemeRepository.selectAll(offset, limit);
|
|
|
176 |
}else{
|
|
|
177 |
schemes = schemeRepository.selectActiveAll(offset, limit);
|
|
|
178 |
}
|
| 22860 |
ashik.ali |
179 |
model.addAttribute("schemes", schemes);
|
| 23343 |
ashik.ali |
180 |
model.addAttribute("roleTypes", loginDetails.getRoleTypes());
|
| 22860 |
ashik.ali |
181 |
return "schemes-paginated";
|
|
|
182 |
}
|
|
|
183 |
|
| 23020 |
ashik.ali |
184 |
@RequestMapping(value = "/schemes/downloadPage", method = RequestMethod.GET)
|
|
|
185 |
public String downloadPage(HttpServletRequest request, Model model){
|
|
|
186 |
return "schemes-download";
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
@RequestMapping(value = "/schemes/download", method = RequestMethod.GET)
|
|
|
190 |
public ResponseEntity<?> downloadInventoryItemAgingByInterval(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.START_DATE_TIME) String startDateTimeString, @RequestParam(name = ProfitMandiConstants.END_DATE_TIME) String endDateTimeString, Model model) throws ProfitMandiBusinessException{
|
|
|
191 |
LocalDateTime startDateTime = StringUtils.toDateTime(startDateTimeString, DateTimePattern.DD_MM_YYYY_T_HH_MM_SS);
|
|
|
192 |
LocalDateTime endDateTime = StringUtils.toDateTime(endDateTimeString, DateTimePattern.DD_MM_YYYY_T_HH_MM_SS);
|
|
|
193 |
|
|
|
194 |
List<SchemeModel> schemeModels = schemeService.getAllSchemeModels(startDateTime, endDateTime);
|
|
|
195 |
|
|
|
196 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
197 |
ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
|
|
|
198 |
|
|
|
199 |
final HttpHeaders headers=new HttpHeaders();
|
|
|
200 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
201 |
headers.set("Content-disposition", "inline; filename=SchemesReport.xlsx");
|
|
|
202 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
203 |
final InputStream inputStream=new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
204 |
final InputStreamResource inputStreamResource=new InputStreamResource(inputStream);
|
|
|
205 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
206 |
|
|
|
207 |
//return responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
|
|
|
208 |
}
|
|
|
209 |
|
| 22860 |
ashik.ali |
210 |
@RequestMapping(value = "/getSchemeById", method = RequestMethod.GET)
|
| 22927 |
ashik.ali |
211 |
public String getSchemeById(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId, Model model) throws ProfitMandiBusinessException{
|
| 23343 |
ashik.ali |
212 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 22860 |
ashik.ali |
213 |
Scheme scheme = schemeService.getSchemeById(schemeId);
|
|
|
214 |
model.addAttribute("scheme", scheme);
|
| 23343 |
ashik.ali |
215 |
model.addAttribute("roleTypes", loginDetails.getRoleTypes());
|
| 22860 |
ashik.ali |
216 |
return "scheme-details";
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
@RequestMapping(value = "/activeSchemeById", method = RequestMethod.PUT)
|
| 22927 |
ashik.ali |
220 |
public String activeSchemeById(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws ProfitMandiBusinessException{
|
| 22860 |
ashik.ali |
221 |
schemeService.activeSchemeById(schemeId);
|
|
|
222 |
List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
|
|
|
223 |
model.addAttribute("schemes", schemes);
|
|
|
224 |
return "schemes-paginated";
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
|
|
|
228 |
@RequestMapping(value = "/expireSchemeById", method = RequestMethod.PUT)
|
| 22927 |
ashik.ali |
229 |
public String expireSchemeById(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws ProfitMandiBusinessException{
|
| 22860 |
ashik.ali |
230 |
schemeService.expireSchemeById(schemeId);
|
|
|
231 |
List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
|
|
|
232 |
model.addAttribute("schemes", schemes);
|
|
|
233 |
return "schemes-paginated";
|
|
|
234 |
}
|
| 23506 |
amit.gupta |
235 |
|
| 22860 |
ashik.ali |
236 |
}
|