| 21577 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 22486 |
ashik.ali |
3 |
import java.io.ByteArrayInputStream;
|
|
|
4 |
import java.io.ByteArrayOutputStream;
|
| 24917 |
tejbeer |
5 |
import java.io.IOException;
|
| 22486 |
ashik.ali |
6 |
import java.io.InputStream;
|
| 23886 |
amit.gupta |
7 |
import java.time.LocalDateTime;
|
| 24917 |
tejbeer |
8 |
import java.time.ZoneOffset;
|
| 24465 |
tejbeer |
9 |
import java.util.ArrayList;
|
| 24917 |
tejbeer |
10 |
import java.util.HashMap;
|
| 24465 |
tejbeer |
11 |
import java.util.HashSet;
|
| 24917 |
tejbeer |
12 |
import java.util.Iterator;
|
| 21577 |
ashik.ali |
13 |
import java.util.List;
|
| 21654 |
ashik.ali |
14 |
import java.util.Map;
|
| 24917 |
tejbeer |
15 |
import java.util.Optional;
|
| 24465 |
tejbeer |
16 |
import java.util.Set;
|
|
|
17 |
import java.util.stream.Collectors;
|
| 21577 |
ashik.ali |
18 |
|
| 24917 |
tejbeer |
19 |
import javax.mail.MessagingException;
|
|
|
20 |
import javax.mail.internet.InternetAddress;
|
|
|
21 |
import javax.mail.internet.MimeMessage;
|
| 21577 |
ashik.ali |
22 |
import javax.servlet.http.HttpServletRequest;
|
| 21987 |
kshitij.so |
23 |
import javax.servlet.http.HttpServletResponse;
|
| 21577 |
ashik.ali |
24 |
|
| 23886 |
amit.gupta |
25 |
import org.apache.logging.log4j.LogManager;
|
| 23568 |
govind |
26 |
import org.apache.logging.log4j.Logger;
|
| 24739 |
tejbeer |
27 |
import org.apache.thrift.TException;
|
| 24465 |
tejbeer |
28 |
import org.json.JSONObject;
|
| 21577 |
ashik.ali |
29 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23784 |
ashik.ali |
30 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 21987 |
kshitij.so |
31 |
import org.springframework.beans.factory.annotation.Value;
|
| 22486 |
ashik.ali |
32 |
import org.springframework.core.io.InputStreamResource;
|
|
|
33 |
import org.springframework.http.HttpHeaders;
|
|
|
34 |
import org.springframework.http.HttpStatus;
|
| 22472 |
ashik.ali |
35 |
import org.springframework.http.ResponseEntity;
|
| 24917 |
tejbeer |
36 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
37 |
import org.springframework.mail.javamail.MimeMessageHelper;
|
| 21577 |
ashik.ali |
38 |
import org.springframework.stereotype.Controller;
|
| 21654 |
ashik.ali |
39 |
import org.springframework.transaction.annotation.Transactional;
|
| 21577 |
ashik.ali |
40 |
import org.springframework.ui.Model;
|
| 22472 |
ashik.ali |
41 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 21577 |
ashik.ali |
42 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 22472 |
ashik.ali |
43 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 21577 |
ashik.ali |
44 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
45 |
|
| 21987 |
kshitij.so |
46 |
import com.google.gson.Gson;
|
| 21577 |
ashik.ali |
47 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 21612 |
ashik.ali |
48 |
import com.spice.profitmandi.common.model.CustomCurrentInventorySnapshot;
|
| 24106 |
tejbeer |
49 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 22472 |
ashik.ali |
50 |
import com.spice.profitmandi.common.model.InventoryItemAgingModel;
|
| 24106 |
tejbeer |
51 |
import com.spice.profitmandi.common.model.ItemFeatureDataModel;
|
| 24917 |
tejbeer |
52 |
import com.spice.profitmandi.common.model.NotifyItemIdModel;
|
|
|
53 |
import com.spice.profitmandi.common.model.NotifyOrderIdModel;
|
|
|
54 |
import com.spice.profitmandi.common.model.NotifyOrderModel;
|
| 21577 |
ashik.ali |
55 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 22472 |
ashik.ali |
56 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
| 21987 |
kshitij.so |
57 |
import com.spice.profitmandi.common.util.Utils;
|
| 24123 |
tejbeer |
58 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 24106 |
tejbeer |
59 |
import com.spice.profitmandi.dao.entity.catalog.TagRanking;
|
| 24917 |
tejbeer |
60 |
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaigns;
|
|
|
61 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 24465 |
tejbeer |
62 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
|
|
63 |
import com.spice.profitmandi.dao.entity.fofo.LiveDemoSerialNumber;
|
| 24917 |
tejbeer |
64 |
import com.spice.profitmandi.dao.entity.transaction.NotifyColorChange;
|
|
|
65 |
import com.spice.profitmandi.dao.entity.transaction.NotifyItem;
|
|
|
66 |
import com.spice.profitmandi.dao.entity.transaction.NotifyOrder;
|
| 24739 |
tejbeer |
67 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
|
|
68 |
import com.spice.profitmandi.dao.entity.user.User;
|
| 24123 |
tejbeer |
69 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 24106 |
tejbeer |
70 |
import com.spice.profitmandi.dao.repository.catalog.TagRankingRepository;
|
| 24465 |
tejbeer |
71 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 24917 |
tejbeer |
72 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
|
|
73 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 24203 |
amit.gupta |
74 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
| 24465 |
tejbeer |
75 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
|
|
76 |
import com.spice.profitmandi.dao.repository.fofo.LiveDemoBillingRespository;
|
| 24917 |
tejbeer |
77 |
import com.spice.profitmandi.dao.repository.inventory.NotifyStatus;
|
|
|
78 |
import com.spice.profitmandi.dao.repository.transaction.NotifyColorChangeRepository;
|
|
|
79 |
import com.spice.profitmandi.dao.repository.transaction.NotifyItemRepository;
|
|
|
80 |
import com.spice.profitmandi.dao.repository.transaction.NotifyOrderRespository;
|
| 24658 |
tejbeer |
81 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 24739 |
tejbeer |
82 |
import com.spice.profitmandi.dao.repository.user.UserRepository;
|
| 22927 |
ashik.ali |
83 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 24465 |
tejbeer |
84 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 22139 |
amit.gupta |
85 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 22069 |
ashik.ali |
86 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 24106 |
tejbeer |
87 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 21577 |
ashik.ali |
88 |
|
| 24658 |
tejbeer |
89 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 24739 |
tejbeer |
90 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 24658 |
tejbeer |
91 |
|
| 21577 |
ashik.ali |
92 |
@Controller
|
| 24123 |
tejbeer |
93 |
@Transactional(rollbackFor = Throwable.class)
|
| 21577 |
ashik.ali |
94 |
public class InventoryController {
|
| 21987 |
kshitij.so |
95 |
|
| 23568 |
govind |
96 |
private static final Logger LOGGER = LogManager.getLogger(InventoryController.class);
|
| 21987 |
kshitij.so |
97 |
|
| 21577 |
ashik.ali |
98 |
@Autowired
|
| 22927 |
ashik.ali |
99 |
private CookiesProcessor cookiesProcessor;
|
| 24123 |
tejbeer |
100 |
|
| 22354 |
ashik.ali |
101 |
@Autowired
|
| 23784 |
ashik.ali |
102 |
@Qualifier("fofoInventoryService")
|
| 22927 |
ashik.ali |
103 |
private InventoryService inventoryService;
|
| 24465 |
tejbeer |
104 |
|
| 24203 |
amit.gupta |
105 |
@Autowired
|
|
|
106 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
| 24123 |
tejbeer |
107 |
|
| 24106 |
tejbeer |
108 |
@Autowired
|
|
|
109 |
private TagRankingRepository tagRankingRepository;
|
| 24123 |
tejbeer |
110 |
|
| 24106 |
tejbeer |
111 |
@Autowired
|
| 24465 |
tejbeer |
112 |
private InventoryItemRepository inventoryItemRepository;
|
|
|
113 |
|
|
|
114 |
@Autowired
|
|
|
115 |
private LiveDemoBillingRespository liveDemoBillingRespository;
|
|
|
116 |
|
|
|
117 |
@Autowired
|
| 24123 |
tejbeer |
118 |
private ItemRepository itemRepository;
|
|
|
119 |
|
|
|
120 |
@Autowired
|
| 24917 |
tejbeer |
121 |
private NotifyItemRepository notifyItemRespository;
|
|
|
122 |
|
|
|
123 |
@Autowired
|
| 24465 |
tejbeer |
124 |
private RetailerService retailerService;
|
|
|
125 |
|
|
|
126 |
@Autowired
|
| 24106 |
tejbeer |
127 |
private MVCResponseSender mvcResponseSender;
|
| 24123 |
tejbeer |
128 |
|
| 24465 |
tejbeer |
129 |
@Autowired
|
|
|
130 |
FofoStoreRepository fofoStoreRepository;
|
|
|
131 |
|
| 24658 |
tejbeer |
132 |
@Autowired
|
|
|
133 |
private OrderRepository orderRepository;
|
|
|
134 |
|
| 24739 |
tejbeer |
135 |
@Autowired
|
|
|
136 |
private UserRepository userRepository;
|
| 24917 |
tejbeer |
137 |
@Autowired
|
|
|
138 |
private NotifyItemRepository notifyItemRepository;
|
| 24739 |
tejbeer |
139 |
|
| 24917 |
tejbeer |
140 |
@Autowired
|
|
|
141 |
private NotifyColorChangeRepository notifyColorChangeRepository;
|
|
|
142 |
|
|
|
143 |
@Autowired
|
|
|
144 |
private NotifyOrderRespository notifyOrderRespository;
|
|
|
145 |
|
|
|
146 |
@Autowired
|
|
|
147 |
private UserAccountRepository userAccountRepository;
|
|
|
148 |
|
| 21987 |
kshitij.so |
149 |
@Value("${saholic.api.host}")
|
|
|
150 |
private String host;
|
| 23786 |
amit.gupta |
151 |
|
| 21987 |
kshitij.so |
152 |
@Value("${saholic.api.port}")
|
|
|
153 |
private int port;
|
| 23786 |
amit.gupta |
154 |
|
| 21987 |
kshitij.so |
155 |
@Value("${saholic.api.webapp}")
|
|
|
156 |
private String webapp;
|
|
|
157 |
|
| 24917 |
tejbeer |
158 |
@Autowired
|
|
|
159 |
JavaMailSender mailSender;
|
|
|
160 |
|
|
|
161 |
@Autowired
|
|
|
162 |
private Mongo mongoClient;
|
|
|
163 |
|
| 23786 |
amit.gupta |
164 |
@RequestMapping(value = "/getCurrentInventorySnapshot")
|
|
|
165 |
public String getCurrentAvailability(HttpServletRequest request,
|
|
|
166 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
167 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
| 24123 |
tejbeer |
168 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
| 23786 |
amit.gupta |
169 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
170 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
171 |
Map<String, Object> map = inventoryService.getCurrentInventorySnapshot(loginDetails.getFofoId(), offset, limit,
|
|
|
172 |
searchTerm);
|
| 22927 |
ashik.ali |
173 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
174 |
return "inventory-snapshot";
|
| 21612 |
ashik.ali |
175 |
}
|
| 21987 |
kshitij.so |
176 |
|
| 23786 |
amit.gupta |
177 |
@RequestMapping(value = "/getBadInventorySnapshot")
|
|
|
178 |
public String getBadAvailability(HttpServletRequest request,
|
|
|
179 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
180 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
181 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
|
|
182 |
throws ProfitMandiBusinessException {
|
| 24123 |
tejbeer |
183 |
if (searchTerm == null) {
|
|
|
184 |
searchTerm = "";
|
| 24052 |
amit.gupta |
185 |
}
|
| 22927 |
ashik.ali |
186 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
187 |
Map<String, Object> map = inventoryService.getBadInventorySnapshot(loginDetails.getFofoId(), offset, limit,
|
|
|
188 |
searchTerm);
|
| 22927 |
ashik.ali |
189 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
190 |
return "bad-inventory-snapshot";
|
|
|
191 |
}
|
|
|
192 |
|
| 23786 |
amit.gupta |
193 |
@RequestMapping(value = "/getPaginatedCurrentInventorySnapshot")
|
|
|
194 |
public String getPaginatedCurrentInventorySnapshot(HttpServletRequest request,
|
|
|
195 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
196 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
197 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
|
|
198 |
throws ProfitMandiBusinessException {
|
| 24123 |
tejbeer |
199 |
if (searchTerm == null) {
|
|
|
200 |
searchTerm = "";
|
| 24052 |
amit.gupta |
201 |
}
|
| 22927 |
ashik.ali |
202 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
203 |
Map<String, Object> map = inventoryService.getPaginatedCurrentInventorySnapshot(loginDetails.getFofoId(),
|
|
|
204 |
offset, limit, searchTerm);
|
| 22927 |
ashik.ali |
205 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
206 |
return "inventory-snapshot-paginated";
|
|
|
207 |
}
|
| 23786 |
amit.gupta |
208 |
|
|
|
209 |
@RequestMapping(value = "/getCatalog")
|
|
|
210 |
public String getCatalog(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
211 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
212 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
|
|
213 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
214 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 24123 |
tejbeer |
215 |
if (searchTerm == null) {
|
|
|
216 |
searchTerm = "";
|
| 24052 |
amit.gupta |
217 |
}
|
| 24739 |
tejbeer |
218 |
|
| 22927 |
ashik.ali |
219 |
Map<String, Object> map = inventoryService.getCatalog(loginDetails.getFofoId(), offset, limit, searchTerm);
|
|
|
220 |
model.addAllAttributes(map);
|
| 24203 |
amit.gupta |
221 |
model.addAttribute("hasGift", hasGift(loginDetails.getFofoId()));
|
| 24658 |
tejbeer |
222 |
|
| 21987 |
kshitij.so |
223 |
return "catalog";
|
|
|
224 |
}
|
| 23786 |
amit.gupta |
225 |
|
| 24465 |
tejbeer |
226 |
// This method is currently hardcoded to faciliate watches sold as gift.
|
| 24203 |
amit.gupta |
227 |
private boolean hasGift(int fofoId) {
|
|
|
228 |
try {
|
| 24465 |
tejbeer |
229 |
return currentInventorySnapshotRepository.selectByItemIdAndFofoId(ProfitMandiConstants.GIFT_ID, fofoId)
|
|
|
230 |
.getAvailability() > 0;
|
| 24203 |
amit.gupta |
231 |
} catch (ProfitMandiBusinessException e) {
|
|
|
232 |
return false;
|
|
|
233 |
}
|
|
|
234 |
}
|
|
|
235 |
|
| 23786 |
amit.gupta |
236 |
@RequestMapping(value = "/getPaginatedCatalog")
|
|
|
237 |
public String getCatalogPaginated(HttpServletRequest request,
|
|
|
238 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
239 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
240 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
|
|
241 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
242 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 24123 |
tejbeer |
243 |
if (searchTerm == null) {
|
|
|
244 |
searchTerm = "";
|
| 24052 |
amit.gupta |
245 |
}
|
| 23786 |
amit.gupta |
246 |
Map<String, Object> map = inventoryService.getPaginatedCatalog(loginDetails.getFofoId(), offset, limit,
|
|
|
247 |
searchTerm);
|
| 22927 |
ashik.ali |
248 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
249 |
return "catalog-paginated";
|
|
|
250 |
}
|
|
|
251 |
|
| 23786 |
amit.gupta |
252 |
@RequestMapping(value = "/checkItemAvailability")
|
|
|
253 |
public String getItemAvailability(HttpServletRequest request,
|
|
|
254 |
@RequestParam(name = ProfitMandiConstants.ITEM_ID) int itemId, Model model)
|
|
|
255 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
256 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
257 |
CustomCurrentInventorySnapshot customCurrentInventorySnapshot = inventoryService.checkItemAvailability(itemId,
|
|
|
258 |
loginDetails.getFofoId());
|
|
|
259 |
customCurrentInventorySnapshot
|
|
|
260 |
.setIconUrl(Utils.getIconUrl(customCurrentInventorySnapshot.getCatalogItemId(), host, port, webapp));
|
| 22927 |
ashik.ali |
261 |
model.addAttribute("currentInventorySnapshot", new Gson().toJson(customCurrentInventorySnapshot));
|
|
|
262 |
return "current-item-availability";
|
| 23786 |
amit.gupta |
263 |
|
| 21577 |
ashik.ali |
264 |
}
|
| 23786 |
amit.gupta |
265 |
|
| 23192 |
ashik.ali |
266 |
@RequestMapping(value = "/cart", method = RequestMethod.POST)
|
| 23786 |
amit.gupta |
267 |
public String addToCart(HttpServletRequest request, @RequestParam(name = "cartData") String cartData, Model model)
|
|
|
268 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
269 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
270 |
|
| 22927 |
ashik.ali |
271 |
Map<String, Object> map = inventoryService.addToCart(cartData, loginDetails.getFofoId());
|
|
|
272 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
273 |
return "cart";
|
|
|
274 |
}
|
| 23786 |
amit.gupta |
275 |
|
| 23192 |
ashik.ali |
276 |
@RequestMapping(value = "/validate-cart", method = RequestMethod.POST)
|
| 23786 |
amit.gupta |
277 |
public String validateCart(HttpServletRequest request, HttpServletResponse response,
|
|
|
278 |
@RequestParam(name = "cartData") String cartData, Model model) throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
279 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
280 |
|
| 22927 |
ashik.ali |
281 |
Map<String, Object> map = inventoryService.validateCart(cartData, loginDetails.getFofoId());
|
|
|
282 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
283 |
return "validate-cart";
|
|
|
284 |
}
|
|
|
285 |
|
| 23786 |
amit.gupta |
286 |
@RequestMapping(value = "/grnHistory")
|
| 24123 |
tejbeer |
287 |
public String getGrnHistory(HttpServletRequest request, @RequestParam(required = false) LocalDateTime startTime,
|
| 23886 |
amit.gupta |
288 |
@RequestParam(required = false) LocalDateTime endTime,
|
| 23786 |
amit.gupta |
289 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
290 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
291 |
@RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE, defaultValue = "") String purchaseReference,
|
|
|
292 |
@RequestParam(name = "searchType", defaultValue = "") String searchType, Model model)
|
|
|
293 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
294 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 24123 |
tejbeer |
295 |
Map<String, Object> map = inventoryService.getGrnHistory(loginDetails.getFofoId(), startTime, endTime, offset,
|
|
|
296 |
limit, purchaseReference, searchType);
|
| 22927 |
ashik.ali |
297 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
298 |
return "grn-history";
|
| 21636 |
ashik.ali |
299 |
}
|
| 21987 |
kshitij.so |
300 |
|
| 23786 |
amit.gupta |
301 |
@RequestMapping(value = "/getPaginatedGrnHistory")
|
|
|
302 |
public String getPaginatedGrnHistory(HttpServletRequest request,
|
| 23886 |
amit.gupta |
303 |
@RequestParam(required = false) LocalDateTime startTime,
|
|
|
304 |
@RequestParam(required = false) LocalDateTime endTime,
|
| 23786 |
amit.gupta |
305 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
306 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
307 |
@RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE, defaultValue = "") String purchaseReference,
|
|
|
308 |
@RequestParam(name = "searchType", defaultValue = "") String searchType, Model model)
|
|
|
309 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
310 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 24123 |
tejbeer |
311 |
Map<String, Object> map = inventoryService.getPaginatedGrnHistory(loginDetails.getFofoId(), startTime, endTime,
|
|
|
312 |
offset, limit);
|
| 22927 |
ashik.ali |
313 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
314 |
return "grn-history-paginated";
|
|
|
315 |
}
|
|
|
316 |
|
| 23786 |
amit.gupta |
317 |
@RequestMapping(value = "/grnHistoryDetailByPurchaseId")
|
|
|
318 |
public String grnHistoryByPurchaseId(HttpServletRequest request,
|
|
|
319 |
@RequestParam(name = ProfitMandiConstants.PURCHASE_ID) int purchaseId, Model model)
|
|
|
320 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
321 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
322 |
Map<String, Object> map = inventoryService.getGrnHistoryDetail(loginDetails.getFofoId(), purchaseId, host, port,
|
|
|
323 |
webapp);
|
| 22927 |
ashik.ali |
324 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
325 |
return "grn-details";
|
| 21636 |
ashik.ali |
326 |
}
|
| 21987 |
kshitij.so |
327 |
|
| 23786 |
amit.gupta |
328 |
@RequestMapping(value = "/grnHistoryDetailByPurchaseReference")
|
|
|
329 |
public String grnHistoryByPurchaseReference(HttpServletRequest request,
|
|
|
330 |
@RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE) String purchaseReference, Model model)
|
|
|
331 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
332 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
333 |
Map<String, Object> map = inventoryService.getGrnHistoryDetail(loginDetails.getFofoId(), purchaseReference,
|
|
|
334 |
host, port, webapp);
|
| 22927 |
ashik.ali |
335 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
336 |
return "grn-details";
|
| 21654 |
ashik.ali |
337 |
}
|
| 23786 |
amit.gupta |
338 |
|
| 22472 |
ashik.ali |
339 |
@RequestMapping(value = "/getInventoryItemAgingByInterval", method = RequestMethod.POST)
|
| 23786 |
amit.gupta |
340 |
public String getInventoryItemAgingByInterval(HttpServletRequest request, @RequestBody List<Integer> intervals,
|
|
|
341 |
Model model, @RequestParam(name = "searchContent", defaultValue = "") String searchContent,
|
|
|
342 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
343 |
@RequestParam(name = "limit", defaultValue = "10") int limit) throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
344 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
345 |
Map<String, Object> map = inventoryService.getPaginatedItemAgingByInterval(loginDetails.getFofoId(), intervals,
|
|
|
346 |
searchContent, offset, limit);
|
| 22927 |
ashik.ali |
347 |
model.addAllAttributes(map);
|
| 22523 |
ashik.ali |
348 |
return "item-aging";
|
|
|
349 |
}
|
| 23786 |
amit.gupta |
350 |
|
| 22523 |
ashik.ali |
351 |
@RequestMapping(value = "/downloadInventoryItemAgingByInterval", method = RequestMethod.POST)
|
| 23786 |
amit.gupta |
352 |
public ResponseEntity<?> downloadInventoryItemAgingByInterval(HttpServletRequest request,
|
|
|
353 |
@RequestBody List<Integer> intervals, Model model) throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
354 |
LOGGER.info("Request received at url{} with body {}", request.getRequestURI(), intervals);
|
|
|
355 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
356 |
|
|
|
357 |
List<InventoryItemAgingModel> inventoryItemAgingModels = inventoryService
|
|
|
358 |
.getItemAgingByInterval(fofoDetails.getFofoId(), intervals);
|
|
|
359 |
|
| 22486 |
ashik.ali |
360 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
361 |
ExcelUtils.writeInventoryItemAgingModels(inventoryItemAgingModels, intervals, byteArrayOutputStream);
|
| 23786 |
amit.gupta |
362 |
|
|
|
363 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
364 |
// private static final String CONTENT_TYPE_XLSX =
|
|
|
365 |
// "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
|
366 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
367 |
// headers.set("Content-Type", "application/vnd.ms-excel");
|
| 22486 |
ashik.ali |
368 |
headers.set("Content-disposition", "inline; filename=InventoryItemAging.xlsx");
|
| 23786 |
amit.gupta |
369 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
370 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
371 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
372 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
373 |
|
| 24123 |
tejbeer |
374 |
// return
|
|
|
375 |
// responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
|
| 22472 |
ashik.ali |
376 |
}
|
| 24123 |
tejbeer |
377 |
|
| 24106 |
tejbeer |
378 |
@RequestMapping(value = "/featurePanel", method = RequestMethod.GET)
|
| 24123 |
tejbeer |
379 |
public String FeaturePanel(HttpServletRequest request,
|
|
|
380 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 24106 |
tejbeer |
381 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Exception {
|
| 21987 |
kshitij.so |
382 |
|
| 24106 |
tejbeer |
383 |
List<TagRanking> tagRanking = null;
|
|
|
384 |
|
|
|
385 |
long size = 0;
|
| 24123 |
tejbeer |
386 |
tagRanking = tagRankingRepository.selectAllTagRanking(offset, limit);
|
|
|
387 |
size = tagRankingRepository.selectAllCount();
|
| 24106 |
tejbeer |
388 |
LOGGER.info("tagRanking" + tagRanking);
|
|
|
389 |
if (!tagRanking.isEmpty()) {
|
| 24798 |
tejbeer |
390 |
|
|
|
391 |
Set<Integer> catalogIds = tagRanking.stream().map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
|
|
|
392 |
List<Item> items = itemRepository.selectAllByCatalogIds(catalogIds);
|
|
|
393 |
Map<Integer, String> catalogDescription = items.stream().collect(Collectors.toMap(x -> x.getCatalogItemId(),
|
|
|
394 |
x -> x.getItemDescription(), (description1, description2) -> description1));
|
|
|
395 |
|
|
|
396 |
LOGGER.info("catalogDescription" + catalogDescription);
|
| 24465 |
tejbeer |
397 |
model.addAttribute("tagRanking", tagRanking);
|
| 24798 |
tejbeer |
398 |
model.addAttribute("catalogDescription", catalogDescription);
|
| 24106 |
tejbeer |
399 |
model.addAttribute("start", offset + 1);
|
|
|
400 |
model.addAttribute("size", size);
|
|
|
401 |
model.addAttribute("url", "/getPaginatedfeature");
|
|
|
402 |
|
|
|
403 |
} else {
|
|
|
404 |
model.addAttribute("tagRanking", tagRanking);
|
|
|
405 |
model.addAttribute("size", size);
|
|
|
406 |
}
|
|
|
407 |
|
|
|
408 |
return "feature";
|
|
|
409 |
|
|
|
410 |
}
|
| 24123 |
tejbeer |
411 |
|
| 24798 |
tejbeer |
412 |
/*
|
| 24917 |
tejbeer |
413 |
* @RequestMapping(value = "/getPaginatedfeature", method = RequestMethod.GET)
|
|
|
414 |
* public String getPaginatedFeaturePanel(HttpServletRequest request,
|
| 24798 |
tejbeer |
415 |
*
|
|
|
416 |
* @RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
417 |
*
|
| 24917 |
tejbeer |
418 |
* @RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
419 |
* throws ProfitMandiBusinessException {
|
| 24798 |
tejbeer |
420 |
* LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
|
|
|
421 |
* List<TagRanking> tagRanking = null;
|
|
|
422 |
*
|
|
|
423 |
*
|
| 24917 |
tejbeer |
424 |
* long size = 0; tagRanking = tagRankingRepository.selectAllTagRanking(offset,
|
|
|
425 |
* limit); if (!tagRanking.isEmpty()) {
|
| 24798 |
tejbeer |
426 |
*
|
|
|
427 |
* model.addAttribute("tagRanking", tagRanking); model.addAttribute("start",
|
|
|
428 |
* offset + 1); model.addAttribute("size", size); model.addAttribute("url",
|
|
|
429 |
* "/getPaginatedfeature");
|
|
|
430 |
*
|
|
|
431 |
* } else { model.addAttribute("tagRanking", tagRanking); } return
|
|
|
432 |
* "feature-paginated"; }
|
|
|
433 |
*/
|
| 24106 |
tejbeer |
434 |
@RequestMapping(value = "/itemfeature", method = RequestMethod.POST)
|
| 24123 |
tejbeer |
435 |
public String Itemfeature(HttpServletRequest request, @RequestBody ItemFeatureDataModel itemFeatureDatatModel,
|
|
|
436 |
Model model) throws Exception {
|
| 24106 |
tejbeer |
437 |
|
|
|
438 |
TagRanking tagRanking = new TagRanking();
|
|
|
439 |
tagRanking.setRankPoints(itemFeatureDatatModel.getRankPoints());
|
|
|
440 |
tagRanking.setCatalogItemId(itemFeatureDatatModel.getCatalogItemId());
|
|
|
441 |
tagRanking.setFeature(itemFeatureDatatModel.getFeature());
|
| 24123 |
tejbeer |
442 |
|
|
|
443 |
LOGGER.info("tagRanking" + tagRanking);
|
|
|
444 |
tagRankingRepository.persist(tagRanking);
|
| 24106 |
tejbeer |
445 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
446 |
return "response";
|
|
|
447 |
}
|
|
|
448 |
|
| 24798 |
tejbeer |
449 |
@RequestMapping(value = "/removeFeature", method = RequestMethod.DELETE)
|
|
|
450 |
public String removeTagRankingEnteries(HttpServletRequest request,
|
|
|
451 |
@RequestParam(name = "id", defaultValue = "0") int id, Model model) throws Exception {
|
| 24917 |
tejbeer |
452 |
|
| 24798 |
tejbeer |
453 |
tagRankingRepository.deleteById(id);
|
|
|
454 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
455 |
return "response";
|
|
|
456 |
}
|
|
|
457 |
|
| 24465 |
tejbeer |
458 |
@RequestMapping(value = "/getDemolistbyfofoId", method = RequestMethod.GET)
|
|
|
459 |
public String DemoListbyFofoId(HttpServletRequest request,
|
|
|
460 |
@RequestParam(required = false, defaultValue = "0") int fofoId, Model model) throws Exception {
|
|
|
461 |
|
|
|
462 |
List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
|
|
|
463 |
.collect(Collectors.toList());
|
|
|
464 |
Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
|
|
|
465 |
String customRetailers = JSONObject.valueToString(customRetailersMap.values());
|
|
|
466 |
List<String> serailNumberList = liveDemoBillingRespository.selectAllSerialNumber();
|
|
|
467 |
LOGGER.info("serailNumberList" + serailNumberList);
|
|
|
468 |
List<InventoryItem> inventoryItem = null;
|
|
|
469 |
List<InventoryItem> inventoryItem1 = new ArrayList<>();
|
|
|
470 |
if (fofoId > 0) {
|
|
|
471 |
List<Item> items = itemRepository.selectAllByBrand("Live Demo");
|
|
|
472 |
Set<Integer> itemIds = new HashSet<>();
|
|
|
473 |
for (Item Item : items) {
|
|
|
474 |
itemIds.add(Item.getId());
|
|
|
475 |
}
|
|
|
476 |
inventoryItem = inventoryItemRepository.selectByFofoIdItemIds(fofoId, itemIds);
|
|
|
477 |
|
|
|
478 |
Set<String> serial = new HashSet<>();
|
|
|
479 |
for (InventoryItem invItem : inventoryItem) {
|
| 24658 |
tejbeer |
480 |
if (!serailNumberList.contains(invItem.getSerialNumber())) {
|
| 24465 |
tejbeer |
481 |
inventoryItem1.add(invItem);
|
|
|
482 |
}
|
|
|
483 |
|
|
|
484 |
}
|
|
|
485 |
|
|
|
486 |
LOGGER.info("inventoyItem" + inventoryItem1);
|
|
|
487 |
model.addAttribute("customRetailers", customRetailers);
|
|
|
488 |
model.addAttribute("liveDemo", inventoryItem1);
|
|
|
489 |
|
|
|
490 |
CustomRetailer fofoIdsAndRetailerName = retailerService.getFofoRetailer(fofoId);
|
|
|
491 |
|
|
|
492 |
model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
|
|
|
493 |
|
|
|
494 |
}
|
|
|
495 |
|
|
|
496 |
else {
|
|
|
497 |
model.addAttribute("customRetailers", customRetailers);
|
|
|
498 |
model.addAttribute("liveDemo", inventoryItem1);
|
|
|
499 |
}
|
|
|
500 |
|
|
|
501 |
return "live_demo_billing";
|
|
|
502 |
|
|
|
503 |
}
|
|
|
504 |
|
|
|
505 |
@RequestMapping(value = "/enableliveDemoSerailNumber", method = RequestMethod.POST)
|
|
|
506 |
public String EnableliveDemoSerailNumber(HttpServletRequest request, @RequestParam String serial_number,
|
|
|
507 |
Model model) throws Exception {
|
|
|
508 |
|
|
|
509 |
LiveDemoSerialNumber liveDemoSerialNumber = new LiveDemoSerialNumber();
|
|
|
510 |
liveDemoSerialNumber.setSerialNumber(serial_number);
|
|
|
511 |
|
|
|
512 |
liveDemoBillingRespository.persist(liveDemoSerialNumber);
|
|
|
513 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
514 |
return "response";
|
|
|
515 |
}
|
|
|
516 |
|
| 24739 |
tejbeer |
517 |
@RequestMapping(value = "/getInProcessOrder", method = RequestMethod.GET)
|
|
|
518 |
public String getInProcessOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
|
|
519 |
|
|
|
520 |
List<com.spice.profitmandi.dao.entity.transaction.Order> inProcessorder = orderRepository
|
|
|
521 |
.selectAllOrderBeforeTwoDaysByStatus(OrderStatus.SUBMITTED_FOR_PROCESSING);
|
| 24917 |
tejbeer |
522 |
List<Integer> retailerIds = new ArrayList<>();
|
|
|
523 |
List<Integer> orderIds = new ArrayList<>();
|
|
|
524 |
if (!inProcessorder.isEmpty()) {
|
|
|
525 |
for (com.spice.profitmandi.dao.entity.transaction.Order order : inProcessorder) {
|
|
|
526 |
retailerIds.add(order.getRetailerId());
|
|
|
527 |
orderIds.add(order.getId());
|
| 24739 |
tejbeer |
528 |
|
| 24917 |
tejbeer |
529 |
}
|
| 24739 |
tejbeer |
530 |
|
| 24917 |
tejbeer |
531 |
List<NotifyOrder> notify = notifyOrderRespository.selectByorderIds(orderIds);
|
|
|
532 |
for (NotifyOrder notifyOrder : notify) {
|
|
|
533 |
List<NotifyItem> notifyItems = notifyItemRepository.selectByNotifyId(notifyOrder.getNotifyId());
|
|
|
534 |
Iterator<NotifyItem> notifyItemsIterator = notifyItems.iterator();
|
|
|
535 |
|
|
|
536 |
while(notifyItemsIterator.hasNext()) {
|
|
|
537 |
NotifyItem notifyItem = notifyItemsIterator.next();
|
|
|
538 |
if (LocalDateTime.now().isAfter(notifyItem.getResponseTime())) {
|
|
|
539 |
notifyItemsIterator.remove();
|
|
|
540 |
}
|
|
|
541 |
}
|
|
|
542 |
if(notifyItems.size() == 0) {
|
|
|
543 |
if(NotifyStatus.pending== notifyOrder.getStatus() ) {
|
|
|
544 |
notifyOrder.setStatus(NotifyStatus.rejected);
|
|
|
545 |
}
|
|
|
546 |
}
|
|
|
547 |
|
|
|
548 |
}
|
|
|
549 |
|
|
|
550 |
Map<Integer, Optional<NotifyOrder>> notifyOrders = notifyOrderRespository.selectByorderIds(orderIds)
|
|
|
551 |
.stream().collect(Collectors.groupingBy(NotifyOrder::getOrderId,
|
|
|
552 |
Collectors.maxBy((x1, x2) -> x1.getId() - x2.getId())));
|
|
|
553 |
|
|
|
554 |
Map<Integer, String> storeIdAndFofoIdMap = fofoStoreRepository.selectByRetailerIds(retailerIds).stream()
|
|
|
555 |
.collect(Collectors.toMap(FofoStore::getId, FofoStore::getCode));
|
|
|
556 |
List<com.spice.profitmandi.dao.entity.transaction.Order> pendingPaymentorder = orderRepository
|
|
|
557 |
.selectAllOrderDatesBetweenByStatus(LocalDateTime.now().minusDays(30), LocalDateTime.now(),
|
|
|
558 |
OrderStatus.PAYMENT_PENDING);
|
|
|
559 |
List<com.spice.profitmandi.dao.entity.transaction.Order> failedPaymentorder = orderRepository
|
|
|
560 |
.selectAllOrderDatesBetweenByStatus(LocalDateTime.now().minusDays(30), LocalDateTime.now(),
|
|
|
561 |
OrderStatus.PAYMENT_FAILED);
|
|
|
562 |
pendingPaymentorder.addAll(failedPaymentorder);
|
|
|
563 |
|
|
|
564 |
model.addAttribute("inProcessorder", inProcessorder);
|
|
|
565 |
model.addAttribute("storeIdAndFofoIdMap", storeIdAndFofoIdMap);
|
|
|
566 |
model.addAttribute("pendingPaymentorder", pendingPaymentorder);
|
|
|
567 |
model.addAttribute("latestNotifyOrders", notifyOrders);
|
|
|
568 |
} else {
|
|
|
569 |
model.addAttribute("inProcessorder", inProcessorder);
|
|
|
570 |
}
|
| 24739 |
tejbeer |
571 |
return "review_order";
|
|
|
572 |
}
|
|
|
573 |
|
|
|
574 |
@RequestMapping(value = "/getKeepInTabOrder", method = RequestMethod.GET)
|
|
|
575 |
public String getKeepInTabOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
|
|
576 |
|
|
|
577 |
List<com.spice.profitmandi.dao.entity.transaction.Order> keepatab = orderRepository
|
|
|
578 |
.selectAllOrder(OrderStatus.KEEP_A_TAB);
|
|
|
579 |
|
|
|
580 |
model.addAttribute("keepatab", keepatab);
|
|
|
581 |
|
|
|
582 |
return "keep-a-tab";
|
|
|
583 |
}
|
|
|
584 |
|
|
|
585 |
@RequestMapping(value = "/closeOrder", method = RequestMethod.POST)
|
|
|
586 |
public String closeOrder(HttpServletRequest request, @RequestParam int orderId, Model model) throws Exception {
|
| 24798 |
tejbeer |
587 |
|
| 24739 |
tejbeer |
588 |
Order order = orderRepository.selectById(orderId);
|
| 24798 |
tejbeer |
589 |
if (order != null) {
|
| 24739 |
tejbeer |
590 |
order.setStatus(OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY);
|
| 24798 |
tejbeer |
591 |
|
| 24739 |
tejbeer |
592 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
593 |
|
| 24798 |
tejbeer |
594 |
} else {
|
| 24739 |
tejbeer |
595 |
model.addAttribute("response", mvcResponseSender.createResponseString(false));
|
|
|
596 |
|
|
|
597 |
}
|
|
|
598 |
return "response";
|
| 24658 |
tejbeer |
599 |
}
|
|
|
600 |
|
| 24739 |
tejbeer |
601 |
@RequestMapping(value = "/cancelOrder", method = RequestMethod.POST)
|
|
|
602 |
public String cancelOrder(HttpServletRequest request, @RequestParam int orderId, @RequestParam String reason,
|
|
|
603 |
@RequestParam OrderStatus orderStatus, Model model) throws Exception {
|
|
|
604 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
605 |
User userInfo = userRepository.selectById(loginDetails.getFofoId());
|
|
|
606 |
LOGGER.info("status" + orderStatus);
|
|
|
607 |
try {
|
|
|
608 |
orderRepository.refundOrder(orderId, userInfo.getName(), reason, orderStatus);
|
|
|
609 |
|
|
|
610 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
611 |
|
|
|
612 |
} catch (TransactionServiceException | TException e) {
|
|
|
613 |
model.addAttribute("response", mvcResponseSender.createResponseString(false));
|
|
|
614 |
|
|
|
615 |
}
|
|
|
616 |
return "response";
|
|
|
617 |
}
|
|
|
618 |
|
| 24917 |
tejbeer |
619 |
@RequestMapping(value = "/getNotifyItemColor", method = RequestMethod.GET)
|
|
|
620 |
public String getNotifyItemColor(HttpServletRequest request, @RequestParam int catalogItemId,
|
|
|
621 |
@RequestParam int itemId, Model model) throws ProfitMandiBusinessException {
|
|
|
622 |
|
|
|
623 |
List<Item> availableColorItem = itemRepository.selectAllByCatalogItemId(catalogItemId);
|
|
|
624 |
|
|
|
625 |
List<Order> inProcessselectedOrder = orderRepository.selectByItemIdOrderStatus(itemId,
|
|
|
626 |
OrderStatus.SUBMITTED_FOR_PROCESSING);
|
|
|
627 |
List<Integer> retailerIds = new ArrayList<>();
|
|
|
628 |
|
|
|
629 |
for (com.spice.profitmandi.dao.entity.transaction.Order order : inProcessselectedOrder) {
|
|
|
630 |
retailerIds.add(order.getRetailerId());
|
|
|
631 |
|
|
|
632 |
}
|
|
|
633 |
|
|
|
634 |
Map<Integer, String> storeIdAndFofoIdMap = fofoStoreRepository.selectByRetailerIds(retailerIds).stream()
|
|
|
635 |
.collect(Collectors.toMap(FofoStore::getId, FofoStore::getCode));
|
|
|
636 |
LOGGER.info("item" + availableColorItem);
|
|
|
637 |
LOGGER.info("inProcessselectedOrder" + inProcessselectedOrder);
|
|
|
638 |
model.addAttribute("item", availableColorItem);
|
|
|
639 |
model.addAttribute("inProcessselectedOrder", inProcessselectedOrder);
|
|
|
640 |
model.addAttribute("storeIdAndFofoIdMap", storeIdAndFofoIdMap);
|
|
|
641 |
|
|
|
642 |
return "notify-order-modal";
|
|
|
643 |
}
|
|
|
644 |
|
|
|
645 |
@RequestMapping(value = "/notifyOrder", method = RequestMethod.POST)
|
|
|
646 |
public String NotifyOrder(HttpServletRequest request, @RequestBody NotifyOrderModel notifyOrderModel, Model model)
|
|
|
647 |
throws Exception {
|
|
|
648 |
|
|
|
649 |
com.spice.profitmandi.dao.entity.transaction.NotifyItem notifyItem = null;
|
|
|
650 |
List<Integer> orderIds = new ArrayList<>();
|
|
|
651 |
|
|
|
652 |
NotifyColorChange notifytimestamp = new NotifyColorChange();
|
|
|
653 |
notifytimestamp.setCreated(LocalDateTime.now());
|
|
|
654 |
notifyColorChangeRepository.persist(notifytimestamp);
|
|
|
655 |
for (NotifyItemIdModel itemid : notifyOrderModel.getItemIds()) {
|
|
|
656 |
|
|
|
657 |
notifyItem = new com.spice.profitmandi.dao.entity.transaction.NotifyItem();
|
|
|
658 |
notifyItem.setItemId(itemid.getItemId());
|
|
|
659 |
notifyItem.setResponseTime(itemid.getResponseTime());
|
|
|
660 |
notifyItem.setProcuredDate(itemid.getProcuredTime());
|
|
|
661 |
notifyItem.setNotifyColorchangeId(notifytimestamp.getId());
|
|
|
662 |
notifyItemRepository.persist(notifyItem);
|
|
|
663 |
LOGGER.info("notifyItem" + notifyItem);
|
|
|
664 |
}
|
|
|
665 |
for (NotifyOrderIdModel st : notifyOrderModel.getOrderIds()) {
|
|
|
666 |
List<NotifyOrder> existingOrder = notifyOrderRespository.selectByOrder(st.getOrderId());
|
|
|
667 |
if(!existingOrder.isEmpty()) {
|
|
|
668 |
LOGGER.info("existingOrder" + existingOrder);
|
|
|
669 |
for(NotifyOrder notifyOrder: existingOrder) {
|
|
|
670 |
if(NotifyStatus.pending == notifyOrder.getStatus()) {
|
|
|
671 |
notifyOrder.setStatus(NotifyStatus.rejected);
|
|
|
672 |
}
|
|
|
673 |
}
|
|
|
674 |
}
|
|
|
675 |
NotifyOrder orderStatus = new NotifyOrder();
|
|
|
676 |
orderStatus.setOrderId(st.getOrderId());
|
|
|
677 |
orderStatus.setNotifyId(notifytimestamp.getId());
|
|
|
678 |
orderStatus.setItemId(st.getOlditemId());
|
|
|
679 |
Order id = orderRepository.selectById(st.getOrderId());
|
|
|
680 |
orderStatus.setFofoId(id.getRetailerId());
|
|
|
681 |
orderStatus.setStatus(NotifyStatus.pending);
|
|
|
682 |
notifyOrderRespository.persist(orderStatus);
|
|
|
683 |
|
|
|
684 |
LOGGER.info("itemStatus" + orderStatus);
|
|
|
685 |
orderIds.add(st.getOrderId());
|
|
|
686 |
}
|
|
|
687 |
|
|
|
688 |
LOGGER.info("orderIds" + orderIds);
|
|
|
689 |
List<Order> orders = orderRepository.selectByOrderIds(orderIds);
|
|
|
690 |
for (Order order : orders) {
|
|
|
691 |
LOGGER.info("order" + order.getId());
|
|
|
692 |
Item item = itemRepository.selectById(order.getLineItem().getItemId());
|
|
|
693 |
List<String> color = new ArrayList<>();
|
|
|
694 |
for (NotifyItemIdModel itemid : notifyOrderModel.getItemIds()) {
|
|
|
695 |
Item newItem = itemRepository.selectById(itemid.getItemId());
|
|
|
696 |
color.add(newItem.getColor());
|
|
|
697 |
}
|
|
|
698 |
|
|
|
699 |
LOGGER.info("message" + item.getItemDescriptionNoColor() + "/" + item.getColor()
|
|
|
700 |
+ "is currently not in stock with Brand/ND. The current availability is in" + color);
|
|
|
701 |
|
|
|
702 |
NotificationCampaigns notification = new NotificationCampaigns();
|
|
|
703 |
notification.setName("Notify Partner");
|
|
|
704 |
|
|
|
705 |
notification.setTitle("Notify Partner");
|
|
|
706 |
|
|
|
707 |
notification.setMessage(item.getItemDescriptionNoColor() +"/"+
|
|
|
708 |
item.getColor() +
|
|
|
709 |
"is currently not in stock with Brand/ND. The current availability is in" +
|
|
|
710 |
color); notification.setType("Url");
|
|
|
711 |
notification.setUrl("http://app.profitmandi.com/pages/home/notifyOrder");
|
|
|
712 |
|
|
|
713 |
notification.
|
|
|
714 |
setSql("SELECT distinct d1.user_id from devices d1 left join devices d2 on" +
|
|
|
715 |
"(d1.imeinumber = d2.imeinumber and d1.created < d2.created) " +
|
|
|
716 |
" where d2.id is null and d1.user_id = " +
|
|
|
717 |
userAccountRepository.selectUserIdByRetailerId(order. getRetailerId()));
|
|
|
718 |
notification.setExpiresat(LocalDateTime.now().plusDays(2).
|
|
|
719 |
toEpochSecond(ZoneOffset.UTC) * 1000);
|
|
|
720 |
notification.setStatus("active");
|
|
|
721 |
notification.setSmsprocessed(0); notification.setNotification_processed(0);
|
|
|
722 |
notification.setNotification_type("GENERAL_NOTIFICATION");
|
|
|
723 |
mongoClient.persistNotificationCmpInfo(notification);
|
|
|
724 |
|
|
|
725 |
}
|
|
|
726 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
727 |
return "response";
|
|
|
728 |
}
|
|
|
729 |
|
|
|
730 |
private void sendMailOfHtmlFomat(String email, String messageText, String subject)
|
|
|
731 |
throws MessagingException, ProfitMandiBusinessException, IOException {
|
|
|
732 |
MimeMessage message = mailSender.createMimeMessage();
|
|
|
733 |
MimeMessageHelper helper = new MimeMessageHelper(message);
|
|
|
734 |
helper.setSubject(subject);
|
|
|
735 |
helper.setText(messageText, true);
|
|
|
736 |
helper.setTo(email);
|
|
|
737 |
|
|
|
738 |
InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "Smart Dukaan");
|
|
|
739 |
helper.setFrom(senderAddress);
|
|
|
740 |
mailSender.send(message);
|
|
|
741 |
}
|
|
|
742 |
|
|
|
743 |
/*
|
|
|
744 |
* private String getMessage(List<NotifyOrderModel> notifyOrderModels, Order
|
|
|
745 |
* order) throws ProfitMandiBusinessException {
|
|
|
746 |
*
|
|
|
747 |
* StringBuilder sb = new StringBuilder(); sb.
|
|
|
748 |
* append("<html><body><p>Notify Partner</p><p>Which have order out stock following model:-</p>"
|
|
|
749 |
* + "<div>" + order.getLineItem().getItem().getItemDescription() +
|
|
|
750 |
* "</div> <div>choose the model from following:- </div><br/><table style='border:1px solid black ;padding: 5px';>"
|
|
|
751 |
* ); sb.append("<tbody>\n" + " <tr>\n" +
|
|
|
752 |
* " <th style='border:1px solid black;padding: 5px'>Color</th>\n"
|
|
|
753 |
* +
|
|
|
754 |
* " <th style='border:1px solid black;padding: 5px'>Procured Time</th>\n"
|
|
|
755 |
* +
|
|
|
756 |
* " <th style='border:1px solid black;padding: 5px'>Response Time</th>\n"
|
|
|
757 |
* + " </tr>"); for (NotifyOrderModel notifyOrderModel :
|
|
|
758 |
* notifyOrderModels) { Item item =
|
|
|
759 |
* itemRepository.selectById(notifyOrderModel.getItemId()); sb.append("<tr>");
|
|
|
760 |
* sb.append("<td style='border:1px solid black;padding: 5px'>" +
|
|
|
761 |
* item.getColor() + "</td>");
|
|
|
762 |
*
|
|
|
763 |
* sb.append("<td style='border:1px solid black;padding: 5px'>" +
|
|
|
764 |
* notifyOrderModel.getFormattedProcuredTime() + "</td>");
|
|
|
765 |
*
|
|
|
766 |
* sb.append("<td style='border:1px solid black;padding: 5px'>" +
|
|
|
767 |
* notifyOrderModel.getFormattedResponseTime() + "</td>");
|
|
|
768 |
*
|
|
|
769 |
* sb.append("</tr>"); }
|
|
|
770 |
*
|
|
|
771 |
* sb.append("</tbody></table></body></html>"); return sb.toString(); }
|
|
|
772 |
*/
|
|
|
773 |
|
|
|
774 |
@RequestMapping(value = "/getAllNotifyOrder", method = RequestMethod.GET)
|
|
|
775 |
public String getAllNotifyOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
|
|
776 |
List<NotifyOrder> notifyOrders= null;
|
|
|
777 |
List<com.spice.profitmandi.dao.entity.transaction.Order> inProcessorder = orderRepository
|
|
|
778 |
.selectAllOrderBeforeTwoDaysByStatus(OrderStatus.SUBMITTED_FOR_PROCESSING);
|
|
|
779 |
|
|
|
780 |
List<Integer> orderIds = new ArrayList<>();
|
|
|
781 |
if(!inProcessorder.isEmpty()) {
|
|
|
782 |
for (com.spice.profitmandi.dao.entity.transaction.Order order : inProcessorder) {
|
|
|
783 |
|
|
|
784 |
orderIds.add(order.getId());
|
|
|
785 |
|
|
|
786 |
}
|
|
|
787 |
notifyOrders = notifyOrderRespository.selectByorderIds(orderIds);
|
|
|
788 |
Set<Integer> oldItemIds = new HashSet<>();
|
|
|
789 |
List<Integer> fofoIds = new ArrayList<>();
|
|
|
790 |
List<Integer> notifyIds = new ArrayList<>();
|
|
|
791 |
if (!notifyOrders.isEmpty()) {
|
|
|
792 |
for (NotifyOrder notifyOrder : notifyOrders) {
|
|
|
793 |
List<NotifyItem> notifyItems = notifyItemRepository.selectByNotifyId(notifyOrder.getNotifyId());
|
|
|
794 |
Iterator<NotifyItem> notifyItemsIterator = notifyItems.iterator();
|
|
|
795 |
|
|
|
796 |
while(notifyItemsIterator.hasNext()) {
|
|
|
797 |
NotifyItem notifyItem = notifyItemsIterator.next();
|
|
|
798 |
if (LocalDateTime.now().isAfter(notifyItem.getResponseTime())) {
|
|
|
799 |
notifyItemsIterator.remove();
|
|
|
800 |
}
|
|
|
801 |
}
|
|
|
802 |
if(notifyItems.size() == 0) {
|
|
|
803 |
if(NotifyStatus.pending == notifyOrder.getStatus()) {
|
|
|
804 |
notifyOrder.setStatus(NotifyStatus.rejected);
|
|
|
805 |
LOGGER.info("existingOrder" + notifyOrder);
|
|
|
806 |
}
|
|
|
807 |
}
|
|
|
808 |
oldItemIds.add(notifyOrder.getItemId());
|
|
|
809 |
fofoIds.add(notifyOrder.getFofoId());
|
|
|
810 |
notifyIds.add(notifyOrder.getNotifyId());
|
|
|
811 |
}
|
|
|
812 |
|
|
|
813 |
List<NotifyColorChange> notifyColorChanges = notifyColorChangeRepository.selectByNotifyId(notifyIds);
|
|
|
814 |
Map<Integer, NotifyColorChange> notifyIdNotifyColorMap = this.notifyOrdersToNotifyId(notifyColorChanges);
|
|
|
815 |
Map<Integer, CustomRetailer> fofoIdsAndRetailerName = retailerService.getFofoRetailers(fofoIds);
|
|
|
816 |
Map<Integer, String> itemdescription = inventoryService.getItemIdDescriptionMap(oldItemIds);
|
|
|
817 |
|
|
|
818 |
model.addAttribute("notifyOrders", notifyOrders);
|
|
|
819 |
model.addAttribute("notifyIdNotifyColorMap", notifyIdNotifyColorMap);
|
|
|
820 |
model.addAttribute("itemdescription", itemdescription);
|
|
|
821 |
model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
|
|
|
822 |
|
|
|
823 |
} else {
|
|
|
824 |
model.addAttribute("notifyOrders", notifyOrders);
|
|
|
825 |
}}
|
|
|
826 |
else {
|
|
|
827 |
model.addAttribute("notifyOrders", notifyOrders);
|
|
|
828 |
}
|
|
|
829 |
return "notify_order";
|
|
|
830 |
}
|
|
|
831 |
|
|
|
832 |
private Map<Integer, NotifyColorChange> notifyOrdersToNotifyId(List<NotifyColorChange> notifyColorChanges) {
|
|
|
833 |
Map<Integer, NotifyColorChange> notifyIdNotifyColorMap = new HashMap<>();
|
|
|
834 |
for (NotifyColorChange notifyColorChange : notifyColorChanges) {
|
|
|
835 |
notifyIdNotifyColorMap.put(notifyColorChange.getId(), notifyColorChange);
|
|
|
836 |
}
|
|
|
837 |
return notifyIdNotifyColorMap;
|
|
|
838 |
}
|
|
|
839 |
|
|
|
840 |
}
|