| 21577 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 22486 |
ashik.ali |
3 |
import java.io.ByteArrayInputStream;
|
|
|
4 |
import java.io.ByteArrayOutputStream;
|
|
|
5 |
import java.io.InputStream;
|
| 26279 |
amit.gupta |
6 |
import java.io.InputStreamReader;
|
| 23886 |
amit.gupta |
7 |
import java.time.LocalDateTime;
|
| 26279 |
amit.gupta |
8 |
import java.time.format.DateTimeFormatter;
|
| 24465 |
tejbeer |
9 |
import java.util.ArrayList;
|
| 25873 |
tejbeer |
10 |
import java.util.Arrays;
|
| 24917 |
tejbeer |
11 |
import java.util.HashMap;
|
| 24465 |
tejbeer |
12 |
import java.util.HashSet;
|
| 24917 |
tejbeer |
13 |
import java.util.Iterator;
|
| 21577 |
ashik.ali |
14 |
import java.util.List;
|
| 21654 |
ashik.ali |
15 |
import java.util.Map;
|
| 24917 |
tejbeer |
16 |
import java.util.Optional;
|
| 24465 |
tejbeer |
17 |
import java.util.Set;
|
|
|
18 |
import java.util.stream.Collectors;
|
| 21577 |
ashik.ali |
19 |
|
|
|
20 |
import javax.servlet.http.HttpServletRequest;
|
| 21987 |
kshitij.so |
21 |
import javax.servlet.http.HttpServletResponse;
|
| 21577 |
ashik.ali |
22 |
|
| 26279 |
amit.gupta |
23 |
import org.apache.commons.csv.CSVFormat;
|
|
|
24 |
import org.apache.commons.csv.CSVParser;
|
|
|
25 |
import org.apache.commons.csv.CSVRecord;
|
| 23886 |
amit.gupta |
26 |
import org.apache.logging.log4j.LogManager;
|
| 23568 |
govind |
27 |
import org.apache.logging.log4j.Logger;
|
| 24739 |
tejbeer |
28 |
import org.apache.thrift.TException;
|
| 24465 |
tejbeer |
29 |
import org.json.JSONObject;
|
| 21577 |
ashik.ali |
30 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23784 |
ashik.ali |
31 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 21987 |
kshitij.so |
32 |
import org.springframework.beans.factory.annotation.Value;
|
| 22486 |
ashik.ali |
33 |
import org.springframework.core.io.InputStreamResource;
|
|
|
34 |
import org.springframework.http.HttpHeaders;
|
|
|
35 |
import org.springframework.http.HttpStatus;
|
| 25140 |
amit.gupta |
36 |
import org.springframework.http.MediaType;
|
| 22472 |
ashik.ali |
37 |
import org.springframework.http.ResponseEntity;
|
| 24917 |
tejbeer |
38 |
import org.springframework.mail.javamail.JavaMailSender;
|
| 21577 |
ashik.ali |
39 |
import org.springframework.stereotype.Controller;
|
| 21654 |
ashik.ali |
40 |
import org.springframework.transaction.annotation.Transactional;
|
| 21577 |
ashik.ali |
41 |
import org.springframework.ui.Model;
|
| 26279 |
amit.gupta |
42 |
import org.springframework.web.bind.annotation.PostMapping;
|
| 22472 |
ashik.ali |
43 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 21577 |
ashik.ali |
44 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 22472 |
ashik.ali |
45 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 21577 |
ashik.ali |
46 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 26279 |
amit.gupta |
47 |
import org.springframework.web.bind.annotation.RequestPart;
|
|
|
48 |
import org.springframework.web.multipart.MultipartFile;
|
| 21577 |
ashik.ali |
49 |
|
| 21987 |
kshitij.so |
50 |
import com.google.gson.Gson;
|
| 25698 |
tejbeer |
51 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
| 21577 |
ashik.ali |
52 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 21612 |
ashik.ali |
53 |
import com.spice.profitmandi.common.model.CustomCurrentInventorySnapshot;
|
| 24106 |
tejbeer |
54 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 22472 |
ashik.ali |
55 |
import com.spice.profitmandi.common.model.InventoryItemAgingModel;
|
| 24106 |
tejbeer |
56 |
import com.spice.profitmandi.common.model.ItemFeatureDataModel;
|
| 24917 |
tejbeer |
57 |
import com.spice.profitmandi.common.model.NotifyItemIdModel;
|
|
|
58 |
import com.spice.profitmandi.common.model.NotifyOrderIdModel;
|
|
|
59 |
import com.spice.profitmandi.common.model.NotifyOrderModel;
|
| 25640 |
tejbeer |
60 |
import com.spice.profitmandi.common.model.OrderCancellationModel;
|
| 25140 |
amit.gupta |
61 |
import com.spice.profitmandi.common.model.PdfModel;
|
| 21577 |
ashik.ali |
62 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 25851 |
amit.gupta |
63 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
| 22472 |
ashik.ali |
64 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
| 25140 |
amit.gupta |
65 |
import com.spice.profitmandi.common.util.PdfUtils;
|
| 24123 |
tejbeer |
66 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 24950 |
tejbeer |
67 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 24106 |
tejbeer |
68 |
import com.spice.profitmandi.dao.entity.catalog.TagRanking;
|
| 25140 |
amit.gupta |
69 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
| 24917 |
tejbeer |
70 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 24465 |
tejbeer |
71 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
|
|
72 |
import com.spice.profitmandi.dao.entity.fofo.LiveDemoSerialNumber;
|
| 26031 |
tejbeer |
73 |
import com.spice.profitmandi.dao.entity.transaction.NotifyCancel;
|
| 24917 |
tejbeer |
74 |
import com.spice.profitmandi.dao.entity.transaction.NotifyColorChange;
|
| 25066 |
tejbeer |
75 |
import com.spice.profitmandi.dao.entity.transaction.NotifyMessage;
|
| 24917 |
tejbeer |
76 |
import com.spice.profitmandi.dao.entity.transaction.NotifyOrder;
|
| 24739 |
tejbeer |
77 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| 24123 |
tejbeer |
78 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 24950 |
tejbeer |
79 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 24106 |
tejbeer |
80 |
import com.spice.profitmandi.dao.repository.catalog.TagRankingRepository;
|
| 24465 |
tejbeer |
81 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 24917 |
tejbeer |
82 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 24203 |
amit.gupta |
83 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
| 24465 |
tejbeer |
84 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
|
|
85 |
import com.spice.profitmandi.dao.repository.fofo.LiveDemoBillingRespository;
|
| 24917 |
tejbeer |
86 |
import com.spice.profitmandi.dao.repository.inventory.NotifyStatus;
|
| 26031 |
tejbeer |
87 |
import com.spice.profitmandi.dao.repository.transaction.NotifyCancelOrderRepository;
|
| 24917 |
tejbeer |
88 |
import com.spice.profitmandi.dao.repository.transaction.NotifyColorChangeRepository;
|
|
|
89 |
import com.spice.profitmandi.dao.repository.transaction.NotifyItemRepository;
|
| 25066 |
tejbeer |
90 |
import com.spice.profitmandi.dao.repository.transaction.NotifyMessageRepository;
|
| 24917 |
tejbeer |
91 |
import com.spice.profitmandi.dao.repository.transaction.NotifyOrderRespository;
|
| 24658 |
tejbeer |
92 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 25851 |
amit.gupta |
93 |
import com.spice.profitmandi.service.NotificationService;
|
| 22927 |
ashik.ali |
94 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 24465 |
tejbeer |
95 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 22139 |
amit.gupta |
96 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 22069 |
ashik.ali |
97 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 24106 |
tejbeer |
98 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 21577 |
ashik.ali |
99 |
|
| 26279 |
amit.gupta |
100 |
|
|
|
101 |
|
| 24658 |
tejbeer |
102 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 24739 |
tejbeer |
103 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 24658 |
tejbeer |
104 |
|
| 21577 |
ashik.ali |
105 |
@Controller
|
| 24123 |
tejbeer |
106 |
@Transactional(rollbackFor = Throwable.class)
|
| 21577 |
ashik.ali |
107 |
public class InventoryController {
|
| 21987 |
kshitij.so |
108 |
|
| 23568 |
govind |
109 |
private static final Logger LOGGER = LogManager.getLogger(InventoryController.class);
|
| 26279 |
amit.gupta |
110 |
|
| 26292 |
amit.gupta |
111 |
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("M/d/yyyy H:m:s");
|
| 21987 |
kshitij.so |
112 |
|
| 21577 |
ashik.ali |
113 |
@Autowired
|
| 22927 |
ashik.ali |
114 |
private CookiesProcessor cookiesProcessor;
|
| 24123 |
tejbeer |
115 |
|
| 22354 |
ashik.ali |
116 |
@Autowired
|
| 23784 |
ashik.ali |
117 |
@Qualifier("fofoInventoryService")
|
| 22927 |
ashik.ali |
118 |
private InventoryService inventoryService;
|
| 24465 |
tejbeer |
119 |
|
| 24203 |
amit.gupta |
120 |
@Autowired
|
| 24950 |
tejbeer |
121 |
TagListingRepository tagListingRepository;
|
|
|
122 |
|
|
|
123 |
@Autowired
|
| 24203 |
amit.gupta |
124 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
| 24123 |
tejbeer |
125 |
|
| 24106 |
tejbeer |
126 |
@Autowired
|
|
|
127 |
private TagRankingRepository tagRankingRepository;
|
| 24123 |
tejbeer |
128 |
|
| 24106 |
tejbeer |
129 |
@Autowired
|
| 24465 |
tejbeer |
130 |
private InventoryItemRepository inventoryItemRepository;
|
|
|
131 |
|
|
|
132 |
@Autowired
|
|
|
133 |
private LiveDemoBillingRespository liveDemoBillingRespository;
|
|
|
134 |
|
|
|
135 |
@Autowired
|
| 24123 |
tejbeer |
136 |
private ItemRepository itemRepository;
|
|
|
137 |
|
|
|
138 |
@Autowired
|
| 24465 |
tejbeer |
139 |
private RetailerService retailerService;
|
|
|
140 |
|
|
|
141 |
@Autowired
|
| 24106 |
tejbeer |
142 |
private MVCResponseSender mvcResponseSender;
|
| 24123 |
tejbeer |
143 |
|
| 24465 |
tejbeer |
144 |
@Autowired
|
|
|
145 |
FofoStoreRepository fofoStoreRepository;
|
|
|
146 |
|
| 24658 |
tejbeer |
147 |
@Autowired
|
|
|
148 |
private OrderRepository orderRepository;
|
|
|
149 |
|
| 24739 |
tejbeer |
150 |
@Autowired
|
| 24917 |
tejbeer |
151 |
private NotifyItemRepository notifyItemRepository;
|
| 24739 |
tejbeer |
152 |
|
| 24917 |
tejbeer |
153 |
@Autowired
|
|
|
154 |
private NotifyColorChangeRepository notifyColorChangeRepository;
|
|
|
155 |
|
|
|
156 |
@Autowired
|
|
|
157 |
private NotifyOrderRespository notifyOrderRespository;
|
|
|
158 |
|
|
|
159 |
@Autowired
|
| 25851 |
amit.gupta |
160 |
private NotificationService notificationService;
|
|
|
161 |
|
|
|
162 |
@Autowired
|
| 25066 |
tejbeer |
163 |
private NotifyMessageRepository notifyMessageRepository;
|
|
|
164 |
|
|
|
165 |
@Autowired
|
| 24917 |
tejbeer |
166 |
private UserAccountRepository userAccountRepository;
|
|
|
167 |
|
| 21987 |
kshitij.so |
168 |
@Value("${saholic.api.host}")
|
|
|
169 |
private String host;
|
| 23786 |
amit.gupta |
170 |
|
| 21987 |
kshitij.so |
171 |
@Value("${saholic.api.port}")
|
|
|
172 |
private int port;
|
| 23786 |
amit.gupta |
173 |
|
| 21987 |
kshitij.so |
174 |
@Value("${saholic.api.webapp}")
|
|
|
175 |
private String webapp;
|
|
|
176 |
|
| 24917 |
tejbeer |
177 |
@Autowired
|
|
|
178 |
JavaMailSender mailSender;
|
|
|
179 |
|
| 26031 |
tejbeer |
180 |
@Autowired
|
|
|
181 |
private NotifyCancelOrderRepository notifyCancelOrderRepository;
|
|
|
182 |
|
| 23786 |
amit.gupta |
183 |
@RequestMapping(value = "/getCurrentInventorySnapshot")
|
|
|
184 |
public String getCurrentAvailability(HttpServletRequest request,
|
|
|
185 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
186 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
| 24123 |
tejbeer |
187 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
| 23786 |
amit.gupta |
188 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
189 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
190 |
Map<String, Object> map = inventoryService.getCurrentInventorySnapshot(loginDetails.getFofoId(), offset, limit,
|
|
|
191 |
searchTerm);
|
| 22927 |
ashik.ali |
192 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
193 |
return "inventory-snapshot";
|
| 21612 |
ashik.ali |
194 |
}
|
| 21987 |
kshitij.so |
195 |
|
| 23786 |
amit.gupta |
196 |
@RequestMapping(value = "/getBadInventorySnapshot")
|
|
|
197 |
public String getBadAvailability(HttpServletRequest request,
|
|
|
198 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
199 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
200 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
|
|
201 |
throws ProfitMandiBusinessException {
|
| 24123 |
tejbeer |
202 |
if (searchTerm == null) {
|
|
|
203 |
searchTerm = "";
|
| 24052 |
amit.gupta |
204 |
}
|
| 22927 |
ashik.ali |
205 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
206 |
Map<String, Object> map = inventoryService.getBadInventorySnapshot(loginDetails.getFofoId(), offset, limit,
|
|
|
207 |
searchTerm);
|
| 22927 |
ashik.ali |
208 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
209 |
return "bad-inventory-snapshot";
|
|
|
210 |
}
|
|
|
211 |
|
| 23786 |
amit.gupta |
212 |
@RequestMapping(value = "/getPaginatedCurrentInventorySnapshot")
|
|
|
213 |
public String getPaginatedCurrentInventorySnapshot(HttpServletRequest request,
|
|
|
214 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
215 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
216 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
|
|
217 |
throws ProfitMandiBusinessException {
|
| 24123 |
tejbeer |
218 |
if (searchTerm == null) {
|
|
|
219 |
searchTerm = "";
|
| 24052 |
amit.gupta |
220 |
}
|
| 22927 |
ashik.ali |
221 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
222 |
Map<String, Object> map = inventoryService.getPaginatedCurrentInventorySnapshot(loginDetails.getFofoId(),
|
|
|
223 |
offset, limit, searchTerm);
|
| 22927 |
ashik.ali |
224 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
225 |
return "inventory-snapshot-paginated";
|
|
|
226 |
}
|
| 23786 |
amit.gupta |
227 |
|
|
|
228 |
@RequestMapping(value = "/getCatalog")
|
|
|
229 |
public String getCatalog(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
230 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
231 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
|
|
232 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
233 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 24123 |
tejbeer |
234 |
if (searchTerm == null) {
|
|
|
235 |
searchTerm = "";
|
| 24052 |
amit.gupta |
236 |
}
|
| 24739 |
tejbeer |
237 |
|
| 22927 |
ashik.ali |
238 |
Map<String, Object> map = inventoryService.getCatalog(loginDetails.getFofoId(), offset, limit, searchTerm);
|
|
|
239 |
model.addAllAttributes(map);
|
| 24203 |
amit.gupta |
240 |
model.addAttribute("hasGift", hasGift(loginDetails.getFofoId()));
|
| 24658 |
tejbeer |
241 |
|
| 21987 |
kshitij.so |
242 |
return "catalog";
|
|
|
243 |
}
|
| 23786 |
amit.gupta |
244 |
|
| 24465 |
tejbeer |
245 |
// This method is currently hardcoded to faciliate watches sold as gift.
|
| 24203 |
amit.gupta |
246 |
private boolean hasGift(int fofoId) {
|
|
|
247 |
try {
|
| 24465 |
tejbeer |
248 |
return currentInventorySnapshotRepository.selectByItemIdAndFofoId(ProfitMandiConstants.GIFT_ID, fofoId)
|
|
|
249 |
.getAvailability() > 0;
|
| 24203 |
amit.gupta |
250 |
} catch (ProfitMandiBusinessException e) {
|
|
|
251 |
return false;
|
|
|
252 |
}
|
|
|
253 |
}
|
|
|
254 |
|
| 23786 |
amit.gupta |
255 |
@RequestMapping(value = "/getPaginatedCatalog")
|
|
|
256 |
public String getCatalogPaginated(HttpServletRequest request,
|
|
|
257 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
258 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
259 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
|
|
260 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
261 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 24123 |
tejbeer |
262 |
if (searchTerm == null) {
|
|
|
263 |
searchTerm = "";
|
| 24052 |
amit.gupta |
264 |
}
|
| 23786 |
amit.gupta |
265 |
Map<String, Object> map = inventoryService.getPaginatedCatalog(loginDetails.getFofoId(), offset, limit,
|
|
|
266 |
searchTerm);
|
| 22927 |
ashik.ali |
267 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
268 |
return "catalog-paginated";
|
|
|
269 |
}
|
|
|
270 |
|
| 23786 |
amit.gupta |
271 |
@RequestMapping(value = "/checkItemAvailability")
|
|
|
272 |
public String getItemAvailability(HttpServletRequest request,
|
|
|
273 |
@RequestParam(name = ProfitMandiConstants.ITEM_ID) int itemId, Model model)
|
|
|
274 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
275 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
276 |
CustomCurrentInventorySnapshot customCurrentInventorySnapshot = inventoryService.checkItemAvailability(itemId,
|
|
|
277 |
loginDetails.getFofoId());
|
| 25812 |
amit.gupta |
278 |
/*
|
|
|
279 |
* customCurrentInventorySnapshot
|
|
|
280 |
* .setIconUrl(Utils.getIconUrl(customCurrentInventorySnapshot.getCatalogItemId(
|
|
|
281 |
* ), host, port, webapp));
|
|
|
282 |
*/
|
| 22927 |
ashik.ali |
283 |
model.addAttribute("currentInventorySnapshot", new Gson().toJson(customCurrentInventorySnapshot));
|
|
|
284 |
return "current-item-availability";
|
| 23786 |
amit.gupta |
285 |
|
| 21577 |
ashik.ali |
286 |
}
|
| 23786 |
amit.gupta |
287 |
|
| 23192 |
ashik.ali |
288 |
@RequestMapping(value = "/cart", method = RequestMethod.POST)
|
| 23786 |
amit.gupta |
289 |
public String addToCart(HttpServletRequest request, @RequestParam(name = "cartData") String cartData, Model model)
|
|
|
290 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
291 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
292 |
|
| 22927 |
ashik.ali |
293 |
Map<String, Object> map = inventoryService.addToCart(cartData, loginDetails.getFofoId());
|
|
|
294 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
295 |
return "cart";
|
|
|
296 |
}
|
| 23786 |
amit.gupta |
297 |
|
| 23192 |
ashik.ali |
298 |
@RequestMapping(value = "/validate-cart", method = RequestMethod.POST)
|
| 23786 |
amit.gupta |
299 |
public String validateCart(HttpServletRequest request, HttpServletResponse response,
|
|
|
300 |
@RequestParam(name = "cartData") String cartData, Model model) throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
301 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
302 |
|
| 22927 |
ashik.ali |
303 |
Map<String, Object> map = inventoryService.validateCart(cartData, loginDetails.getFofoId());
|
|
|
304 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
305 |
return "validate-cart";
|
|
|
306 |
}
|
|
|
307 |
|
| 23786 |
amit.gupta |
308 |
@RequestMapping(value = "/grnHistory")
|
| 24123 |
tejbeer |
309 |
public String getGrnHistory(HttpServletRequest request, @RequestParam(required = false) LocalDateTime startTime,
|
| 23886 |
amit.gupta |
310 |
@RequestParam(required = false) LocalDateTime endTime,
|
| 23786 |
amit.gupta |
311 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
312 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
313 |
@RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE, defaultValue = "") String purchaseReference,
|
|
|
314 |
@RequestParam(name = "searchType", defaultValue = "") String searchType, Model model)
|
|
|
315 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
316 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 24123 |
tejbeer |
317 |
Map<String, Object> map = inventoryService.getGrnHistory(loginDetails.getFofoId(), startTime, endTime, offset,
|
|
|
318 |
limit, purchaseReference, searchType);
|
| 22927 |
ashik.ali |
319 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
320 |
return "grn-history";
|
| 21636 |
ashik.ali |
321 |
}
|
| 21987 |
kshitij.so |
322 |
|
| 25140 |
amit.gupta |
323 |
@RequestMapping(value = "/downloadPurchaseInvoices")
|
|
|
324 |
public ResponseEntity<?> downloadPurchaseInvoices(HttpServletRequest request,
|
|
|
325 |
@RequestParam(required = false) LocalDateTime startTime,
|
|
|
326 |
@RequestParam(required = false) LocalDateTime endTime,
|
|
|
327 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
328 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
329 |
@RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE, defaultValue = "") String purchaseReference,
|
|
|
330 |
@RequestParam(name = "searchType", defaultValue = "") String searchType, Model model)
|
|
|
331 |
throws ProfitMandiBusinessException {
|
|
|
332 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
333 |
Map<String, Object> map = inventoryService.getGrnHistory(loginDetails.getFofoId(), startTime, endTime, offset,
|
|
|
334 |
limit, purchaseReference, searchType);
|
|
|
335 |
|
|
|
336 |
List<FofoOrder> fofoOrders = (List<FofoOrder>) map.get("saleHistories");
|
|
|
337 |
|
|
|
338 |
if (fofoOrders.size() == 0) {
|
|
|
339 |
throw new ProfitMandiBusinessException("Search criteria", "", "No orders found for criteria");
|
|
|
340 |
}
|
|
|
341 |
|
|
|
342 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
343 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
|
|
344 |
headers.set("Content-disposition", "inline; filename=invoices.pdf");
|
|
|
345 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
346 |
List<PdfModel> pdfModels = new ArrayList<>();
|
| 25371 |
tejbeer |
347 |
/*
|
|
|
348 |
* for (FofoOrder fofoOrder : fofoOrders) { try {
|
|
|
349 |
* pdfModels.add(orderService.getInvoicePdfModel(fofoOrder.getId())); } catch
|
|
|
350 |
* (Exception e) {
|
|
|
351 |
* LOGGER.info("could not create invoice for {}, invoice number {}",
|
|
|
352 |
* fofoOrder.getId(), fofoOrder.getInvoiceNumber()); } }
|
|
|
353 |
*/
|
| 25140 |
amit.gupta |
354 |
PdfUtils.generateAndWrite(pdfModels, byteArrayOutputStream);
|
|
|
355 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
356 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
357 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
358 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
359 |
}
|
|
|
360 |
|
| 23786 |
amit.gupta |
361 |
@RequestMapping(value = "/getPaginatedGrnHistory")
|
|
|
362 |
public String getPaginatedGrnHistory(HttpServletRequest request,
|
| 23886 |
amit.gupta |
363 |
@RequestParam(required = false) LocalDateTime startTime,
|
|
|
364 |
@RequestParam(required = false) LocalDateTime endTime,
|
| 23786 |
amit.gupta |
365 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
366 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
367 |
@RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE, defaultValue = "") String purchaseReference,
|
|
|
368 |
@RequestParam(name = "searchType", defaultValue = "") String searchType, Model model)
|
|
|
369 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
370 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 24123 |
tejbeer |
371 |
Map<String, Object> map = inventoryService.getPaginatedGrnHistory(loginDetails.getFofoId(), startTime, endTime,
|
|
|
372 |
offset, limit);
|
| 22927 |
ashik.ali |
373 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
374 |
return "grn-history-paginated";
|
|
|
375 |
}
|
|
|
376 |
|
| 23786 |
amit.gupta |
377 |
@RequestMapping(value = "/grnHistoryDetailByPurchaseId")
|
|
|
378 |
public String grnHistoryByPurchaseId(HttpServletRequest request,
|
|
|
379 |
@RequestParam(name = ProfitMandiConstants.PURCHASE_ID) int purchaseId, Model model)
|
|
|
380 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
381 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
382 |
Map<String, Object> map = inventoryService.getGrnHistoryDetail(loginDetails.getFofoId(), purchaseId, host, port,
|
|
|
383 |
webapp);
|
| 22927 |
ashik.ali |
384 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
385 |
return "grn-details";
|
| 21636 |
ashik.ali |
386 |
}
|
| 21987 |
kshitij.so |
387 |
|
| 23786 |
amit.gupta |
388 |
@RequestMapping(value = "/grnHistoryDetailByPurchaseReference")
|
|
|
389 |
public String grnHistoryByPurchaseReference(HttpServletRequest request,
|
|
|
390 |
@RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE) String purchaseReference, Model model)
|
|
|
391 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
392 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
393 |
Map<String, Object> map = inventoryService.getGrnHistoryDetail(loginDetails.getFofoId(), purchaseReference,
|
|
|
394 |
host, port, webapp);
|
| 22927 |
ashik.ali |
395 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
396 |
return "grn-details";
|
| 21654 |
ashik.ali |
397 |
}
|
| 23786 |
amit.gupta |
398 |
|
| 26248 |
amit.gupta |
399 |
@RequestMapping(value = "/activatedImeis")
|
|
|
400 |
public String activatedImeis(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
|
|
401 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
402 |
|
|
|
403 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByActivatedNotSold(loginDetails.getFofoId());
|
|
|
404 |
inventoryItems.stream().forEach(x -> {
|
|
|
405 |
try {
|
|
|
406 |
x.setItem(itemRepository.selectById(x.getItemId()));
|
|
|
407 |
} catch (Exception e) {
|
|
|
408 |
e.printStackTrace();
|
|
|
409 |
}
|
|
|
410 |
});
|
|
|
411 |
model.addAttribute("inventoryItems", inventoryItems);
|
|
|
412 |
return "activated-imeis";
|
|
|
413 |
}
|
|
|
414 |
|
| 22472 |
ashik.ali |
415 |
@RequestMapping(value = "/getInventoryItemAgingByInterval", method = RequestMethod.POST)
|
| 23786 |
amit.gupta |
416 |
public String getInventoryItemAgingByInterval(HttpServletRequest request, @RequestBody List<Integer> intervals,
|
|
|
417 |
Model model, @RequestParam(name = "searchContent", defaultValue = "") String searchContent,
|
|
|
418 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
419 |
@RequestParam(name = "limit", defaultValue = "10") int limit) throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
420 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
421 |
Map<String, Object> map = inventoryService.getPaginatedItemAgingByInterval(loginDetails.getFofoId(), intervals,
|
|
|
422 |
searchContent, offset, limit);
|
| 22927 |
ashik.ali |
423 |
model.addAllAttributes(map);
|
| 22523 |
ashik.ali |
424 |
return "item-aging";
|
|
|
425 |
}
|
| 23786 |
amit.gupta |
426 |
|
| 22523 |
ashik.ali |
427 |
@RequestMapping(value = "/downloadInventoryItemAgingByInterval", method = RequestMethod.POST)
|
| 23786 |
amit.gupta |
428 |
public ResponseEntity<?> downloadInventoryItemAgingByInterval(HttpServletRequest request,
|
|
|
429 |
@RequestBody List<Integer> intervals, Model model) throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
430 |
LOGGER.info("Request received at url{} with body {}", request.getRequestURI(), intervals);
|
|
|
431 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
432 |
|
|
|
433 |
List<InventoryItemAgingModel> inventoryItemAgingModels = inventoryService
|
|
|
434 |
.getItemAgingByInterval(fofoDetails.getFofoId(), intervals);
|
|
|
435 |
|
| 22486 |
ashik.ali |
436 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
437 |
ExcelUtils.writeInventoryItemAgingModels(inventoryItemAgingModels, intervals, byteArrayOutputStream);
|
| 23786 |
amit.gupta |
438 |
|
|
|
439 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
440 |
// private static final String CONTENT_TYPE_XLSX =
|
|
|
441 |
// "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
|
442 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
443 |
// headers.set("Content-Type", "application/vnd.ms-excel");
|
| 22486 |
ashik.ali |
444 |
headers.set("Content-disposition", "inline; filename=InventoryItemAging.xlsx");
|
| 23786 |
amit.gupta |
445 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
446 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
447 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
448 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
449 |
|
| 24123 |
tejbeer |
450 |
// return
|
|
|
451 |
// responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
|
| 22472 |
ashik.ali |
452 |
}
|
| 24123 |
tejbeer |
453 |
|
| 24106 |
tejbeer |
454 |
@RequestMapping(value = "/featurePanel", method = RequestMethod.GET)
|
| 25371 |
tejbeer |
455 |
public String FeaturePanel(HttpServletRequest request, Model model) throws Exception {
|
| 21987 |
kshitij.so |
456 |
|
| 24106 |
tejbeer |
457 |
List<TagRanking> tagRanking = null;
|
| 25362 |
tejbeer |
458 |
tagRanking = tagRankingRepository.getAllTagRanking();
|
| 24106 |
tejbeer |
459 |
LOGGER.info("tagRanking" + tagRanking);
|
|
|
460 |
if (!tagRanking.isEmpty()) {
|
| 25371 |
tejbeer |
461 |
Set<Integer> catalogIds = tagRanking.stream().map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
|
| 24798 |
tejbeer |
462 |
List<Item> items = itemRepository.selectAllByCatalogIds(catalogIds);
|
|
|
463 |
Map<Integer, String> catalogDescription = items.stream().collect(Collectors.toMap(x -> x.getCatalogItemId(),
|
|
|
464 |
x -> x.getItemDescription(), (description1, description2) -> description1));
|
|
|
465 |
|
|
|
466 |
LOGGER.info("catalogDescription" + catalogDescription);
|
| 24465 |
tejbeer |
467 |
model.addAttribute("tagRanking", tagRanking);
|
| 24798 |
tejbeer |
468 |
model.addAttribute("catalogDescription", catalogDescription);
|
| 24106 |
tejbeer |
469 |
|
|
|
470 |
} else {
|
|
|
471 |
model.addAttribute("tagRanking", tagRanking);
|
| 25362 |
tejbeer |
472 |
|
| 24106 |
tejbeer |
473 |
}
|
|
|
474 |
|
|
|
475 |
return "feature";
|
|
|
476 |
|
|
|
477 |
}
|
| 24123 |
tejbeer |
478 |
|
| 26279 |
amit.gupta |
479 |
@PostMapping(value = "/imei/upload")
|
| 26294 |
amit.gupta |
480 |
public String uploadContent(HttpServletRequest request, @RequestPart("file") MultipartFile file, Model model)
|
| 26279 |
amit.gupta |
481 |
throws Exception {
|
|
|
482 |
/*if(brand==null) {
|
|
|
483 |
throw new ProfitMandiBusinessException("Please select brand", "Brand empty", "Brand required");
|
|
|
484 |
}*/
|
|
|
485 |
List<CSVRecord> masterDataList = readFile(file);
|
|
|
486 |
|
|
|
487 |
|
|
|
488 |
Map<String, LocalDateTime> imeisActivationMap = masterDataList.stream().collect(Collectors.toMap(x->x.get(0),
|
|
|
489 |
x-> LocalDateTime.parse((String)(x.get(1)), formatter)));
|
|
|
490 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectBySerialNumbers(imeisActivationMap.keySet());
|
|
|
491 |
inventoryItems.stream().forEach(inventoryItem -> {
|
|
|
492 |
if (inventoryItem.getActivationTimestamp() == null) {
|
|
|
493 |
if (inventoryItem.getLastScanType().equals(com.spice.profitmandi.dao.enumuration.fofo.ScanType.SALE)
|
|
|
494 |
|| inventoryItem.getGoodQuantity() + inventoryItem.getBadQuantity() == 1) {
|
|
|
495 |
inventoryItem.setActivationTimestamp(imeisActivationMap.get(inventoryItem.getSerialNumber()));
|
|
|
496 |
}
|
|
|
497 |
}
|
| 26294 |
amit.gupta |
498 |
model.addAttribute("response", true);
|
| 26279 |
amit.gupta |
499 |
});
|
| 26294 |
amit.gupta |
500 |
return "response";
|
| 26279 |
amit.gupta |
501 |
}
|
|
|
502 |
|
|
|
503 |
private List<CSVRecord> readFile(MultipartFile file) throws Exception {
|
|
|
504 |
List<CSVRecord> records = null;
|
|
|
505 |
try (CSVParser parser = new CSVParser(new InputStreamReader(file.getInputStream()), CSVFormat.DEFAULT)) {
|
|
|
506 |
records = parser.getRecords();
|
|
|
507 |
if (records.size() < 2) {
|
|
|
508 |
throw new ProfitMandiBusinessException("Uploaded File", "", "No records Found");
|
|
|
509 |
}
|
|
|
510 |
records.remove(0);
|
|
|
511 |
} catch(Exception e) {
|
|
|
512 |
throw new ProfitMandiBusinessException("Parsing Failed", "parse failed", "file parse failed");
|
|
|
513 |
}
|
|
|
514 |
return records;
|
|
|
515 |
}
|
|
|
516 |
|
| 24106 |
tejbeer |
517 |
@RequestMapping(value = "/itemfeature", method = RequestMethod.POST)
|
| 24123 |
tejbeer |
518 |
public String Itemfeature(HttpServletRequest request, @RequestBody ItemFeatureDataModel itemFeatureDatatModel,
|
|
|
519 |
Model model) throws Exception {
|
| 25371 |
tejbeer |
520 |
TagRanking tagRanking = tagRankingRepository.selectBycatalogItemId(itemFeatureDatatModel.getCatalogItemId());
|
|
|
521 |
LOGGER.info("tagRanking" + tagRanking);
|
|
|
522 |
if (tagRanking == null) {
|
|
|
523 |
tagRanking = new TagRanking();
|
|
|
524 |
tagRanking.setCatalogItemId(itemFeatureDatatModel.getCatalogItemId());
|
| 25363 |
tejbeer |
525 |
}
|
| 24106 |
tejbeer |
526 |
tagRanking.setFeature(itemFeatureDatatModel.getFeature());
|
| 25363 |
tejbeer |
527 |
tagRanking.setRankPoints(itemFeatureDatatModel.getRankPoints());
|
| 25371 |
tejbeer |
528 |
|
| 24123 |
tejbeer |
529 |
tagRankingRepository.persist(tagRanking);
|
| 24106 |
tejbeer |
530 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
531 |
return "response";
|
|
|
532 |
}
|
|
|
533 |
|
| 24798 |
tejbeer |
534 |
@RequestMapping(value = "/removeFeature", method = RequestMethod.DELETE)
|
|
|
535 |
public String removeTagRankingEnteries(HttpServletRequest request,
|
|
|
536 |
@RequestParam(name = "id", defaultValue = "0") int id, Model model) throws Exception {
|
| 24917 |
tejbeer |
537 |
|
| 24798 |
tejbeer |
538 |
tagRankingRepository.deleteById(id);
|
|
|
539 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
540 |
return "response";
|
|
|
541 |
}
|
|
|
542 |
|
| 24465 |
tejbeer |
543 |
@RequestMapping(value = "/getDemolistbyfofoId", method = RequestMethod.GET)
|
|
|
544 |
public String DemoListbyFofoId(HttpServletRequest request,
|
|
|
545 |
@RequestParam(required = false, defaultValue = "0") int fofoId, Model model) throws Exception {
|
|
|
546 |
|
|
|
547 |
List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
|
|
|
548 |
.collect(Collectors.toList());
|
|
|
549 |
Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
|
|
|
550 |
String customRetailers = JSONObject.valueToString(customRetailersMap.values());
|
|
|
551 |
List<String> serailNumberList = liveDemoBillingRespository.selectAllSerialNumber();
|
|
|
552 |
LOGGER.info("serailNumberList" + serailNumberList);
|
|
|
553 |
List<InventoryItem> inventoryItem = null;
|
|
|
554 |
List<InventoryItem> inventoryItem1 = new ArrayList<>();
|
|
|
555 |
if (fofoId > 0) {
|
|
|
556 |
List<Item> items = itemRepository.selectAllByBrand("Live Demo");
|
|
|
557 |
Set<Integer> itemIds = new HashSet<>();
|
|
|
558 |
for (Item Item : items) {
|
|
|
559 |
itemIds.add(Item.getId());
|
|
|
560 |
}
|
|
|
561 |
inventoryItem = inventoryItemRepository.selectByFofoIdItemIds(fofoId, itemIds);
|
|
|
562 |
|
|
|
563 |
Set<String> serial = new HashSet<>();
|
|
|
564 |
for (InventoryItem invItem : inventoryItem) {
|
| 24658 |
tejbeer |
565 |
if (!serailNumberList.contains(invItem.getSerialNumber())) {
|
| 24465 |
tejbeer |
566 |
inventoryItem1.add(invItem);
|
| 25371 |
tejbeer |
567 |
|
| 24465 |
tejbeer |
568 |
}
|
|
|
569 |
|
|
|
570 |
}
|
|
|
571 |
|
|
|
572 |
LOGGER.info("inventoyItem" + inventoryItem1);
|
|
|
573 |
model.addAttribute("customRetailers", customRetailers);
|
| 25371 |
tejbeer |
574 |
|
| 24465 |
tejbeer |
575 |
model.addAttribute("liveDemo", inventoryItem1);
|
|
|
576 |
CustomRetailer fofoIdsAndRetailerName = retailerService.getFofoRetailer(fofoId);
|
|
|
577 |
|
|
|
578 |
model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
|
|
|
579 |
|
|
|
580 |
}
|
|
|
581 |
|
|
|
582 |
else {
|
|
|
583 |
model.addAttribute("customRetailers", customRetailers);
|
|
|
584 |
model.addAttribute("liveDemo", inventoryItem1);
|
|
|
585 |
}
|
|
|
586 |
|
|
|
587 |
return "live_demo_billing";
|
|
|
588 |
|
|
|
589 |
}
|
|
|
590 |
|
|
|
591 |
@RequestMapping(value = "/enableliveDemoSerailNumber", method = RequestMethod.POST)
|
|
|
592 |
public String EnableliveDemoSerailNumber(HttpServletRequest request, @RequestParam String serial_number,
|
|
|
593 |
Model model) throws Exception {
|
|
|
594 |
|
|
|
595 |
LiveDemoSerialNumber liveDemoSerialNumber = new LiveDemoSerialNumber();
|
|
|
596 |
liveDemoSerialNumber.setSerialNumber(serial_number);
|
|
|
597 |
|
|
|
598 |
liveDemoBillingRespository.persist(liveDemoSerialNumber);
|
|
|
599 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
600 |
return "response";
|
|
|
601 |
}
|
|
|
602 |
|
| 24739 |
tejbeer |
603 |
@RequestMapping(value = "/getInProcessOrder", method = RequestMethod.GET)
|
|
|
604 |
public String getInProcessOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
|
|
605 |
|
|
|
606 |
List<com.spice.profitmandi.dao.entity.transaction.Order> inProcessorder = orderRepository
|
| 25067 |
tejbeer |
607 |
.selectAllOrder(OrderStatus.SUBMITTED_FOR_PROCESSING);
|
| 24917 |
tejbeer |
608 |
List<Integer> retailerIds = new ArrayList<>();
|
|
|
609 |
List<Integer> orderIds = new ArrayList<>();
|
|
|
610 |
if (!inProcessorder.isEmpty()) {
|
|
|
611 |
for (com.spice.profitmandi.dao.entity.transaction.Order order : inProcessorder) {
|
|
|
612 |
retailerIds.add(order.getRetailerId());
|
|
|
613 |
orderIds.add(order.getId());
|
| 24739 |
tejbeer |
614 |
|
| 24917 |
tejbeer |
615 |
}
|
| 24739 |
tejbeer |
616 |
|
| 25640 |
tejbeer |
617 |
List<NotifyOrder> notify = notifyOrderRespository.selectByorderIds(orderIds);
|
|
|
618 |
for (NotifyOrder notifyOrder : notify) {
|
| 25449 |
tejbeer |
619 |
|
| 25640 |
tejbeer |
620 |
Order orderdetail = orderRepository.selectById(notifyOrder.getOrderId());
|
| 25449 |
tejbeer |
621 |
if (!orderdetail.getStatus().equals(OrderStatus.SUBMITTED_FOR_PROCESSING)) {
|
| 25640 |
tejbeer |
622 |
notifyOrder.setStatus(NotifyStatus.rejected);
|
| 25449 |
tejbeer |
623 |
}
|
| 25640 |
tejbeer |
624 |
}
|
| 24950 |
tejbeer |
625 |
|
| 24917 |
tejbeer |
626 |
Map<Integer, Optional<NotifyOrder>> notifyOrders = notifyOrderRespository.selectByorderIds(orderIds)
|
|
|
627 |
.stream().collect(Collectors.groupingBy(NotifyOrder::getOrderId,
|
|
|
628 |
Collectors.maxBy((x1, x2) -> x1.getId() - x2.getId())));
|
| 24950 |
tejbeer |
629 |
|
| 26110 |
tejbeer |
630 |
Map<Integer, NotifyCancel> notifyCancelOrders = notifyCancelOrderRepository.selectByOrderIds(orderIds)
|
|
|
631 |
.stream().collect(Collectors.toMap(x -> x.getOrderId(), x -> x));
|
| 24917 |
tejbeer |
632 |
Map<Integer, String> storeIdAndFofoIdMap = fofoStoreRepository.selectByRetailerIds(retailerIds).stream()
|
|
|
633 |
.collect(Collectors.toMap(FofoStore::getId, FofoStore::getCode));
|
|
|
634 |
List<com.spice.profitmandi.dao.entity.transaction.Order> pendingPaymentorder = orderRepository
|
|
|
635 |
.selectAllOrderDatesBetweenByStatus(LocalDateTime.now().minusDays(30), LocalDateTime.now(),
|
|
|
636 |
OrderStatus.PAYMENT_PENDING);
|
|
|
637 |
List<com.spice.profitmandi.dao.entity.transaction.Order> failedPaymentorder = orderRepository
|
|
|
638 |
.selectAllOrderDatesBetweenByStatus(LocalDateTime.now().minusDays(30), LocalDateTime.now(),
|
|
|
639 |
OrderStatus.PAYMENT_FAILED);
|
|
|
640 |
pendingPaymentorder.addAll(failedPaymentorder);
|
|
|
641 |
|
|
|
642 |
model.addAttribute("inProcessorder", inProcessorder);
|
|
|
643 |
model.addAttribute("storeIdAndFofoIdMap", storeIdAndFofoIdMap);
|
|
|
644 |
model.addAttribute("pendingPaymentorder", pendingPaymentorder);
|
|
|
645 |
model.addAttribute("latestNotifyOrders", notifyOrders);
|
| 26110 |
tejbeer |
646 |
model.addAttribute("notifyCancelOrders", notifyCancelOrders);
|
| 24917 |
tejbeer |
647 |
} else {
|
|
|
648 |
model.addAttribute("inProcessorder", inProcessorder);
|
|
|
649 |
}
|
| 24739 |
tejbeer |
650 |
return "review_order";
|
|
|
651 |
}
|
|
|
652 |
|
|
|
653 |
@RequestMapping(value = "/getKeepInTabOrder", method = RequestMethod.GET)
|
|
|
654 |
public String getKeepInTabOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
|
|
655 |
|
|
|
656 |
List<com.spice.profitmandi.dao.entity.transaction.Order> keepatab = orderRepository
|
|
|
657 |
.selectAllOrder(OrderStatus.KEEP_A_TAB);
|
|
|
658 |
|
|
|
659 |
model.addAttribute("keepatab", keepatab);
|
|
|
660 |
|
|
|
661 |
return "keep-a-tab";
|
|
|
662 |
}
|
|
|
663 |
|
|
|
664 |
@RequestMapping(value = "/closeOrder", method = RequestMethod.POST)
|
|
|
665 |
public String closeOrder(HttpServletRequest request, @RequestParam int orderId, Model model) throws Exception {
|
| 24798 |
tejbeer |
666 |
|
| 24739 |
tejbeer |
667 |
Order order = orderRepository.selectById(orderId);
|
| 24798 |
tejbeer |
668 |
if (order != null) {
|
| 24739 |
tejbeer |
669 |
order.setStatus(OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY);
|
| 24798 |
tejbeer |
670 |
|
| 24739 |
tejbeer |
671 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
672 |
|
| 24798 |
tejbeer |
673 |
} else {
|
| 24739 |
tejbeer |
674 |
model.addAttribute("response", mvcResponseSender.createResponseString(false));
|
|
|
675 |
|
|
|
676 |
}
|
|
|
677 |
return "response";
|
| 24658 |
tejbeer |
678 |
}
|
|
|
679 |
|
| 25640 |
tejbeer |
680 |
@RequestMapping(value = "/getcancelOrderItems", method = RequestMethod.GET)
|
|
|
681 |
public String getcancelOrderItems(HttpServletRequest request, @RequestParam int itemId, Model model)
|
|
|
682 |
throws Exception {
|
|
|
683 |
|
|
|
684 |
List<Order> inProcessselectedOrder = orderRepository.selectByItemIdOrderStatus(itemId,
|
|
|
685 |
OrderStatus.SUBMITTED_FOR_PROCESSING);
|
|
|
686 |
|
|
|
687 |
List<Integer> retailerIds = new ArrayList<>();
|
|
|
688 |
for (com.spice.profitmandi.dao.entity.transaction.Order order : inProcessselectedOrder) {
|
|
|
689 |
retailerIds.add(order.getRetailerId());
|
|
|
690 |
|
|
|
691 |
}
|
|
|
692 |
|
|
|
693 |
Map<Integer, String> storeIdAndFofoIdMap = fofoStoreRepository.selectByRetailerIds(retailerIds).stream()
|
|
|
694 |
.collect(Collectors.toMap(FofoStore::getId, FofoStore::getCode));
|
|
|
695 |
|
|
|
696 |
model.addAttribute("inProcessCancelOrder", inProcessselectedOrder);
|
|
|
697 |
model.addAttribute("storeIdAndFofoIdMap", storeIdAndFofoIdMap);
|
|
|
698 |
|
|
|
699 |
return "cancel-order-modal";
|
|
|
700 |
}
|
|
|
701 |
|
| 24739 |
tejbeer |
702 |
@RequestMapping(value = "/cancelOrder", method = RequestMethod.POST)
|
| 25640 |
tejbeer |
703 |
public String cancelOrder(HttpServletRequest request, @RequestBody OrderCancellationModel orderCancellationModel,
|
|
|
704 |
Model model) throws Exception {
|
| 24739 |
tejbeer |
705 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 25640 |
tejbeer |
706 |
LOGGER.info("orderId" + orderCancellationModel.getOrderIds());
|
|
|
707 |
|
| 24739 |
tejbeer |
708 |
try {
|
| 25699 |
tejbeer |
709 |
// List<Order> orders =
|
|
|
710 |
// orderRepository.selectByOrderIds(orderCancellationModel.getOrderIds());
|
| 25640 |
tejbeer |
711 |
|
| 25699 |
tejbeer |
712 |
List<Order> orders = orderRepository.selectByOrderIdsOrdersStatus(orderCancellationModel.getOrderIds(),
|
|
|
713 |
OrderStatus.SUBMITTED_FOR_PROCESSING);
|
|
|
714 |
if (!orders.isEmpty()) {
|
|
|
715 |
for (Order order : orders) {
|
| 25640 |
tejbeer |
716 |
|
| 25699 |
tejbeer |
717 |
orderRepository.refundOrder(order.getId(), loginDetails.getEmailId(),
|
|
|
718 |
orderCancellationModel.getReason(), OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY);
|
|
|
719 |
List<NotifyOrder> notifyOrders = notifyOrderRespository.selectByOrder(order.getId());
|
|
|
720 |
for (NotifyOrder notifyOrder : notifyOrders) {
|
|
|
721 |
if (notifyOrder.getStatus() == NotifyStatus.pending) {
|
|
|
722 |
notifyOrder.setStatus(NotifyStatus.rejected);
|
|
|
723 |
}
|
| 25449 |
tejbeer |
724 |
}
|
| 25699 |
tejbeer |
725 |
sendCancellationNotificationToPartner(order, orderCancellationModel.getReason());
|
|
|
726 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
727 |
|
| 25640 |
tejbeer |
728 |
}
|
|
|
729 |
}
|
| 24739 |
tejbeer |
730 |
} catch (TransactionServiceException | TException e) {
|
|
|
731 |
model.addAttribute("response", mvcResponseSender.createResponseString(false));
|
|
|
732 |
|
|
|
733 |
}
|
| 25640 |
tejbeer |
734 |
|
| 24739 |
tejbeer |
735 |
return "response";
|
|
|
736 |
}
|
|
|
737 |
|
| 25039 |
amit.gupta |
738 |
private void sendCancellationNotificationToPartner(Order order, String reason) throws Exception {
|
|
|
739 |
Item item = itemRepository.selectById(order.getLineItem().getItemId());
|
| 25383 |
tejbeer |
740 |
|
| 25851 |
amit.gupta |
741 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
742 |
sendNotificationModel.setCampaignName("Order Cancellation");
|
|
|
743 |
sendNotificationModel.setTitle(String.format("Order %s %d(Pcs) cancelled", item.getItemDescription(),
|
| 25140 |
amit.gupta |
744 |
order.getLineItem().getQuantity()));
|
| 25851 |
amit.gupta |
745 |
sendNotificationModel.setType("url");
|
|
|
746 |
sendNotificationModel.setMessage(reason);
|
|
|
747 |
sendNotificationModel.setUrl("http://app.smartdukaan.com/pages/home/orderDetails");
|
|
|
748 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
|
|
|
749 |
sendNotificationModel.setMessageType(MessageType.notification);
|
| 25857 |
tejbeer |
750 |
int userId = userAccountRepository.selectUserIdByRetailerId(order.getRetailerId());
|
| 25873 |
tejbeer |
751 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
| 25851 |
amit.gupta |
752 |
notificationService.sendNotification(sendNotificationModel);
|
| 25140 |
amit.gupta |
753 |
|
| 25039 |
amit.gupta |
754 |
}
|
|
|
755 |
|
| 24917 |
tejbeer |
756 |
@RequestMapping(value = "/getNotifyItemColor", method = RequestMethod.GET)
|
|
|
757 |
public String getNotifyItemColor(HttpServletRequest request, @RequestParam int catalogItemId,
|
|
|
758 |
@RequestParam int itemId, Model model) throws ProfitMandiBusinessException {
|
|
|
759 |
|
| 24950 |
tejbeer |
760 |
List<Item> availableColorItems = itemRepository.selectAllByCatalogItemId(catalogItemId);
|
|
|
761 |
Iterator<Item> itemsIterator = availableColorItems.iterator();
|
| 24917 |
tejbeer |
762 |
|
| 24950 |
tejbeer |
763 |
while (itemsIterator.hasNext()) {
|
|
|
764 |
Item item = itemsIterator.next();
|
|
|
765 |
TagListing itemTagListing = tagListingRepository.selectByItemId(item.getId());
|
|
|
766 |
|
|
|
767 |
if (itemTagListing == null) {
|
|
|
768 |
itemsIterator.remove();
|
|
|
769 |
|
|
|
770 |
}
|
|
|
771 |
|
|
|
772 |
else if (!itemTagListing.isActive()) {
|
|
|
773 |
itemsIterator.remove();
|
|
|
774 |
|
|
|
775 |
}
|
|
|
776 |
}
|
|
|
777 |
|
| 24917 |
tejbeer |
778 |
List<Order> inProcessselectedOrder = orderRepository.selectByItemIdOrderStatus(itemId,
|
|
|
779 |
OrderStatus.SUBMITTED_FOR_PROCESSING);
|
|
|
780 |
List<Integer> retailerIds = new ArrayList<>();
|
|
|
781 |
|
|
|
782 |
for (com.spice.profitmandi.dao.entity.transaction.Order order : inProcessselectedOrder) {
|
|
|
783 |
retailerIds.add(order.getRetailerId());
|
|
|
784 |
|
|
|
785 |
}
|
|
|
786 |
|
|
|
787 |
Map<Integer, String> storeIdAndFofoIdMap = fofoStoreRepository.selectByRetailerIds(retailerIds).stream()
|
|
|
788 |
.collect(Collectors.toMap(FofoStore::getId, FofoStore::getCode));
|
| 24950 |
tejbeer |
789 |
LOGGER.info("item" + availableColorItems);
|
|
|
790 |
model.addAttribute("item", availableColorItems);
|
| 24917 |
tejbeer |
791 |
model.addAttribute("inProcessselectedOrder", inProcessselectedOrder);
|
|
|
792 |
model.addAttribute("storeIdAndFofoIdMap", storeIdAndFofoIdMap);
|
|
|
793 |
|
|
|
794 |
return "notify-order-modal";
|
|
|
795 |
}
|
|
|
796 |
|
|
|
797 |
@RequestMapping(value = "/notifyOrder", method = RequestMethod.POST)
|
|
|
798 |
public String NotifyOrder(HttpServletRequest request, @RequestBody NotifyOrderModel notifyOrderModel, Model model)
|
|
|
799 |
throws Exception {
|
|
|
800 |
|
|
|
801 |
com.spice.profitmandi.dao.entity.transaction.NotifyItem notifyItem = null;
|
|
|
802 |
List<Integer> orderIds = new ArrayList<>();
|
|
|
803 |
|
|
|
804 |
NotifyColorChange notifytimestamp = new NotifyColorChange();
|
|
|
805 |
notifytimestamp.setCreated(LocalDateTime.now());
|
|
|
806 |
notifyColorChangeRepository.persist(notifytimestamp);
|
| 25066 |
tejbeer |
807 |
NotifyMessage notifyMessage = new NotifyMessage();
|
|
|
808 |
notifyMessage.setNotifyId(notifytimestamp.getId());
|
|
|
809 |
notifyMessage.setNotifyMessages(notifyOrderModel.getMessage());
|
| 25140 |
amit.gupta |
810 |
notifyMessageRepository.persist(notifyMessage);
|
| 24917 |
tejbeer |
811 |
for (NotifyItemIdModel itemid : notifyOrderModel.getItemIds()) {
|
|
|
812 |
|
|
|
813 |
notifyItem = new com.spice.profitmandi.dao.entity.transaction.NotifyItem();
|
|
|
814 |
notifyItem.setItemId(itemid.getItemId());
|
|
|
815 |
notifyItem.setResponseTime(itemid.getResponseTime());
|
|
|
816 |
notifyItem.setProcuredDate(itemid.getProcuredTime());
|
|
|
817 |
notifyItem.setNotifyColorchangeId(notifytimestamp.getId());
|
|
|
818 |
notifyItemRepository.persist(notifyItem);
|
|
|
819 |
LOGGER.info("notifyItem" + notifyItem);
|
|
|
820 |
}
|
|
|
821 |
for (NotifyOrderIdModel st : notifyOrderModel.getOrderIds()) {
|
|
|
822 |
List<NotifyOrder> existingOrder = notifyOrderRespository.selectByOrder(st.getOrderId());
|
| 24950 |
tejbeer |
823 |
if (!existingOrder.isEmpty()) {
|
| 24917 |
tejbeer |
824 |
LOGGER.info("existingOrder" + existingOrder);
|
| 24950 |
tejbeer |
825 |
for (NotifyOrder notifyOrder : existingOrder) {
|
|
|
826 |
if (NotifyStatus.pending == notifyOrder.getStatus()) {
|
|
|
827 |
notifyOrder.setStatus(NotifyStatus.rejected);
|
| 26105 |
tejbeer |
828 |
notifyOrder.setUpdateTimestamp(LocalDateTime.now());
|
| 24950 |
tejbeer |
829 |
}
|
| 24917 |
tejbeer |
830 |
}
|
|
|
831 |
}
|
|
|
832 |
NotifyOrder orderStatus = new NotifyOrder();
|
|
|
833 |
orderStatus.setOrderId(st.getOrderId());
|
|
|
834 |
orderStatus.setNotifyId(notifytimestamp.getId());
|
|
|
835 |
orderStatus.setItemId(st.getOlditemId());
|
|
|
836 |
Order id = orderRepository.selectById(st.getOrderId());
|
|
|
837 |
orderStatus.setFofoId(id.getRetailerId());
|
|
|
838 |
orderStatus.setStatus(NotifyStatus.pending);
|
|
|
839 |
notifyOrderRespository.persist(orderStatus);
|
|
|
840 |
|
|
|
841 |
LOGGER.info("itemStatus" + orderStatus);
|
|
|
842 |
orderIds.add(st.getOrderId());
|
|
|
843 |
}
|
|
|
844 |
|
|
|
845 |
LOGGER.info("orderIds" + orderIds);
|
|
|
846 |
List<Order> orders = orderRepository.selectByOrderIds(orderIds);
|
|
|
847 |
for (Order order : orders) {
|
|
|
848 |
LOGGER.info("order" + order.getId());
|
|
|
849 |
|
| 25140 |
amit.gupta |
850 |
NotifyMessage message = notifyMessageRepository.selectByNotifyId(notifytimestamp.getId());
|
|
|
851 |
|
| 25851 |
amit.gupta |
852 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
853 |
sendNotificationModel.setCampaignName("Notify Partner");
|
|
|
854 |
sendNotificationModel.setMessage(message.getNotifyMessages());
|
|
|
855 |
sendNotificationModel.setType("url");
|
|
|
856 |
sendNotificationModel.setTitle("Alert");
|
|
|
857 |
sendNotificationModel.setUrl("http://app.smartdukaan.com/pages/home/notifyOrder");
|
|
|
858 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
|
|
|
859 |
sendNotificationModel.setMessageType(MessageType.notification);
|
| 25857 |
tejbeer |
860 |
int userId = userAccountRepository.selectUserIdByRetailerId(order.getRetailerId());
|
| 25873 |
tejbeer |
861 |
|
|
|
862 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
| 25851 |
amit.gupta |
863 |
notificationService.sendNotification(sendNotificationModel);
|
| 25140 |
amit.gupta |
864 |
|
| 24917 |
tejbeer |
865 |
}
|
|
|
866 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
867 |
return "response";
|
|
|
868 |
}
|
|
|
869 |
|
|
|
870 |
@RequestMapping(value = "/getAllNotifyOrder", method = RequestMethod.GET)
|
|
|
871 |
public String getAllNotifyOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| 24950 |
tejbeer |
872 |
List<NotifyOrder> notifyOrders = null;
|
| 24917 |
tejbeer |
873 |
List<com.spice.profitmandi.dao.entity.transaction.Order> inProcessorder = orderRepository
|
| 25067 |
tejbeer |
874 |
.selectAllOrder(OrderStatus.SUBMITTED_FOR_PROCESSING);
|
| 24950 |
tejbeer |
875 |
|
| 24917 |
tejbeer |
876 |
List<Integer> orderIds = new ArrayList<>();
|
| 24950 |
tejbeer |
877 |
if (!inProcessorder.isEmpty()) {
|
| 24917 |
tejbeer |
878 |
for (com.spice.profitmandi.dao.entity.transaction.Order order : inProcessorder) {
|
| 24950 |
tejbeer |
879 |
|
| 24917 |
tejbeer |
880 |
orderIds.add(order.getId());
|
|
|
881 |
|
| 24950 |
tejbeer |
882 |
}
|
|
|
883 |
notifyOrders = notifyOrderRespository.selectByorderIds(orderIds);
|
|
|
884 |
Set<Integer> oldItemIds = new HashSet<>();
|
|
|
885 |
List<Integer> fofoIds = new ArrayList<>();
|
|
|
886 |
List<Integer> notifyIds = new ArrayList<>();
|
|
|
887 |
if (!notifyOrders.isEmpty()) {
|
|
|
888 |
for (NotifyOrder notifyOrder : notifyOrders) {
|
|
|
889 |
oldItemIds.add(notifyOrder.getItemId());
|
|
|
890 |
fofoIds.add(notifyOrder.getFofoId());
|
|
|
891 |
notifyIds.add(notifyOrder.getNotifyId());
|
| 24917 |
tejbeer |
892 |
}
|
|
|
893 |
|
| 24950 |
tejbeer |
894 |
List<NotifyColorChange> notifyColorChanges = notifyColorChangeRepository.selectByNotifyId(notifyIds);
|
|
|
895 |
Map<Integer, NotifyColorChange> notifyIdNotifyColorMap = this
|
|
|
896 |
.notifyOrdersToNotifyId(notifyColorChanges);
|
|
|
897 |
Map<Integer, CustomRetailer> fofoIdsAndRetailerName = retailerService.getFofoRetailers(fofoIds);
|
|
|
898 |
Map<Integer, String> itemdescription = inventoryService.getItemIdDescriptionMap(oldItemIds);
|
| 24917 |
tejbeer |
899 |
|
| 24950 |
tejbeer |
900 |
model.addAttribute("notifyOrders", notifyOrders);
|
|
|
901 |
model.addAttribute("notifyIdNotifyColorMap", notifyIdNotifyColorMap);
|
|
|
902 |
model.addAttribute("itemdescription", itemdescription);
|
|
|
903 |
model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
|
| 24917 |
tejbeer |
904 |
|
| 24950 |
tejbeer |
905 |
} else {
|
|
|
906 |
model.addAttribute("notifyOrders", notifyOrders);
|
|
|
907 |
}
|
| 24917 |
tejbeer |
908 |
} else {
|
|
|
909 |
model.addAttribute("notifyOrders", notifyOrders);
|
| 24950 |
tejbeer |
910 |
}
|
| 24917 |
tejbeer |
911 |
return "notify_order";
|
|
|
912 |
}
|
|
|
913 |
|
|
|
914 |
private Map<Integer, NotifyColorChange> notifyOrdersToNotifyId(List<NotifyColorChange> notifyColorChanges) {
|
|
|
915 |
Map<Integer, NotifyColorChange> notifyIdNotifyColorMap = new HashMap<>();
|
|
|
916 |
for (NotifyColorChange notifyColorChange : notifyColorChanges) {
|
|
|
917 |
notifyIdNotifyColorMap.put(notifyColorChange.getId(), notifyColorChange);
|
|
|
918 |
}
|
|
|
919 |
return notifyIdNotifyColorMap;
|
|
|
920 |
}
|
|
|
921 |
|
| 26031 |
tejbeer |
922 |
@RequestMapping(value = "/getItems", method = RequestMethod.GET)
|
|
|
923 |
public String getItems(HttpServletRequest request, @RequestParam int catalogItemId, Model model) throws Exception {
|
|
|
924 |
|
|
|
925 |
Set<Integer> itemIds = itemRepository.selectAllByCatalogItemId(catalogItemId).stream().map(x -> x.getId())
|
|
|
926 |
.collect(Collectors.toSet());
|
|
|
927 |
|
|
|
928 |
List<Order> notAvailableProcessingOrder = orderRepository.selectByItemIdsOrderStatus(itemIds,
|
|
|
929 |
OrderStatus.SUBMITTED_FOR_PROCESSING);
|
|
|
930 |
LOGGER.info("notAvailableProcessingOrder" + notAvailableProcessingOrder);
|
|
|
931 |
|
|
|
932 |
List<Integer> retailerIds = new ArrayList<>();
|
|
|
933 |
for (com.spice.profitmandi.dao.entity.transaction.Order order : notAvailableProcessingOrder) {
|
|
|
934 |
retailerIds.add(order.getRetailerId());
|
|
|
935 |
|
|
|
936 |
}
|
|
|
937 |
|
|
|
938 |
Map<Integer, String> storeIdAndFofoIdMap = fofoStoreRepository.selectByRetailerIds(retailerIds).stream()
|
|
|
939 |
.collect(Collectors.toMap(FofoStore::getId, FofoStore::getCode));
|
|
|
940 |
|
|
|
941 |
model.addAttribute("notAvailableProcessingOrder", notAvailableProcessingOrder);
|
|
|
942 |
model.addAttribute("storeIdAndFofoIdMap", storeIdAndFofoIdMap);
|
|
|
943 |
|
|
|
944 |
return "partner-cancel-order-modal";
|
|
|
945 |
}
|
|
|
946 |
|
|
|
947 |
@RequestMapping(value = "/notifyCancelOrder", method = RequestMethod.POST)
|
|
|
948 |
public String NotifyCancelOrder(HttpServletRequest request, @RequestBody NotifyOrderModel notifyOrderModel,
|
|
|
949 |
Model model) throws Exception {
|
|
|
950 |
for (NotifyOrderIdModel st : notifyOrderModel.getOrderIds()) {
|
|
|
951 |
LOGGER.info("orderId" + st.getOrderId());
|
|
|
952 |
Order order = orderRepository.selectById(st.getOrderId());
|
| 26110 |
tejbeer |
953 |
NotifyCancel nc = notifyCancelOrderRepository.selectByOrderId(st.getOrderId());
|
|
|
954 |
if (nc == null) {
|
|
|
955 |
nc = new NotifyCancel();
|
|
|
956 |
nc.setOrderId(st.getOrderId());
|
|
|
957 |
nc.setItemId(st.getOlditemId());
|
|
|
958 |
nc.setFofoId(order.getRetailerId());
|
|
|
959 |
nc.setCancellation(false);
|
|
|
960 |
nc.setCreatedTimestamp(LocalDateTime.now());
|
|
|
961 |
nc.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
962 |
notifyCancelOrderRepository.persist(nc);
|
|
|
963 |
} else {
|
|
|
964 |
nc.setOrderId(st.getOrderId());
|
|
|
965 |
nc.setItemId(st.getOlditemId());
|
|
|
966 |
nc.setFofoId(order.getRetailerId());
|
|
|
967 |
nc.setCancellation(false);
|
|
|
968 |
nc.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
969 |
notifyCancelOrderRepository.persist(nc);
|
|
|
970 |
}
|
| 26031 |
tejbeer |
971 |
|
|
|
972 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
973 |
sendNotificationModel.setCampaignName("Notify Partner");
|
|
|
974 |
sendNotificationModel.setMessage(notifyOrderModel.getMessage());
|
|
|
975 |
sendNotificationModel.setType("url");
|
|
|
976 |
sendNotificationModel.setTitle("Alert");
|
|
|
977 |
sendNotificationModel.setUrl("http://app.smartdukaan.com/pages/home/notifyCancelOrder");
|
|
|
978 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
|
|
|
979 |
sendNotificationModel.setMessageType(MessageType.notification);
|
|
|
980 |
int userId = userAccountRepository.selectUserIdByRetailerId(order.getRetailerId());
|
|
|
981 |
|
|
|
982 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
|
|
983 |
notificationService.sendNotification(sendNotificationModel);
|
|
|
984 |
|
|
|
985 |
}
|
|
|
986 |
|
|
|
987 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
988 |
return "response";
|
|
|
989 |
}
|
| 26039 |
tejbeer |
990 |
|
|
|
991 |
@RequestMapping(value = "/getNotifiedCancelOrder", method = RequestMethod.GET)
|
|
|
992 |
public String getNotifiedCancelOrder(HttpServletRequest request, Model model) throws Exception {
|
|
|
993 |
|
|
|
994 |
List<NotifyCancel> notifyCancels = notifyCancelOrderRepository.selectAllNonCancelOrder();
|
|
|
995 |
if (!notifyCancels.isEmpty()) {
|
|
|
996 |
List<Integer> retailerIds = new ArrayList<>();
|
|
|
997 |
Set<Integer> itemIds = new HashSet<>();
|
|
|
998 |
for (NotifyCancel nc : notifyCancels) {
|
|
|
999 |
retailerIds.add(nc.getFofoId());
|
|
|
1000 |
itemIds.add(nc.getItemId());
|
|
|
1001 |
}
|
|
|
1002 |
|
|
|
1003 |
Map<Integer, CustomRetailer> fofoIdsAndRetailerName = retailerService.getFofoRetailers(retailerIds);
|
|
|
1004 |
|
|
|
1005 |
Map<Integer, String> itemdescription = inventoryService.getItemIdDescriptionMap(itemIds);
|
|
|
1006 |
model.addAttribute("notifyCancels", notifyCancels);
|
|
|
1007 |
model.addAttribute("itemdescription", itemdescription);
|
|
|
1008 |
model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
|
|
|
1009 |
} else {
|
|
|
1010 |
|
|
|
1011 |
model.addAttribute("notifyCancels", notifyCancels);
|
|
|
1012 |
|
|
|
1013 |
}
|
|
|
1014 |
return "notify_cancel";
|
|
|
1015 |
}
|
|
|
1016 |
|
|
|
1017 |
@RequestMapping(value = "/getNotifyItems", method = RequestMethod.GET)
|
|
|
1018 |
public String getNotifyItems(HttpServletRequest request, @RequestParam int itemId, Model model) throws Exception {
|
|
|
1019 |
Item item = itemRepository.selectById(itemId);
|
|
|
1020 |
|
|
|
1021 |
List<Integer> itemIds = itemRepository.selectAllByCatalogItemId(item.getCatalogItemId()).stream()
|
|
|
1022 |
.map(x -> x.getId()).collect(Collectors.toList());
|
|
|
1023 |
|
|
|
1024 |
List<NotifyCancel> ncs = notifyCancelOrderRepository.selectByItemIdsAndStatus(itemIds);
|
|
|
1025 |
List<Integer> retailerIds = new ArrayList<>();
|
|
|
1026 |
Map<Integer, Object> orders = new HashMap<>();
|
|
|
1027 |
for (NotifyCancel nc : ncs) {
|
|
|
1028 |
retailerIds.add(nc.getFofoId());
|
|
|
1029 |
Order od = orderRepository.selectById(nc.getOrderId());
|
|
|
1030 |
orders.put(nc.getOrderId(), od);
|
|
|
1031 |
}
|
|
|
1032 |
|
|
|
1033 |
Map<Integer, String> storeIdAndFofoIdMap = fofoStoreRepository.selectByRetailerIds(retailerIds).stream()
|
|
|
1034 |
.collect(Collectors.toMap(FofoStore::getId, FofoStore::getCode));
|
|
|
1035 |
|
|
|
1036 |
model.addAttribute("notifyItems", ncs);
|
|
|
1037 |
model.addAttribute("orders", orders);
|
|
|
1038 |
model.addAttribute("storeIdAndFofoIdMap", storeIdAndFofoIdMap);
|
|
|
1039 |
|
|
|
1040 |
return "notify_cancel_order_modal";
|
|
|
1041 |
}
|
|
|
1042 |
|
|
|
1043 |
@RequestMapping(value = "/changeNotifyCancelRequest", method = RequestMethod.POST)
|
|
|
1044 |
public String changeNotifyCancelRequest(HttpServletRequest request, @RequestBody NotifyOrderModel notifyOrderModel,
|
|
|
1045 |
Model model) throws Exception {
|
|
|
1046 |
List<Integer> orderIds = notifyOrderModel.getOrderIds().stream().map(x -> x.getOrderId())
|
|
|
1047 |
.collect(Collectors.toList());
|
|
|
1048 |
|
|
|
1049 |
List<NotifyCancel> ncs = notifyCancelOrderRepository.selectByOrderIds(orderIds);
|
|
|
1050 |
for (NotifyCancel nc : ncs) {
|
|
|
1051 |
nc.setCancellation(true);
|
|
|
1052 |
}
|
|
|
1053 |
|
|
|
1054 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
1055 |
return "response";
|
|
|
1056 |
}
|
| 24917 |
tejbeer |
1057 |
}
|