| 26607 |
amit.gupta |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import com.eclipsesource.json.JsonObject;
|
|
|
4 |
import com.google.gson.Gson;
|
|
|
5 |
import com.google.gson.reflect.TypeToken;
|
| 28377 |
tejbeer |
6 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
| 26607 |
amit.gupta |
7 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
|
|
8 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 30123 |
amit.gupta |
9 |
import com.spice.profitmandi.common.model.*;
|
| 34444 |
vikas.jang |
10 |
import com.spice.profitmandi.dao.entity.catalog.LiquidationDetail;
|
| 26607 |
amit.gupta |
11 |
import com.spice.profitmandi.common.solr.SolrService;
|
| 28304 |
amit.gupta |
12 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 28566 |
tejbeer |
13 |
import com.spice.profitmandi.common.util.PdfUtils;
|
| 28405 |
amit.gupta |
14 |
import com.spice.profitmandi.common.util.Utils;
|
| 26607 |
amit.gupta |
15 |
import com.spice.profitmandi.common.web.client.RestClient;
|
|
|
16 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 34242 |
tejus.loha |
17 |
import com.spice.profitmandi.dao.entity.WebEntity.NavBar;
|
| 34444 |
vikas.jang |
18 |
import com.spice.profitmandi.dao.entity.catalog.Bid;
|
| 26607 |
amit.gupta |
19 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 34444 |
vikas.jang |
20 |
import com.spice.profitmandi.dao.entity.catalog.Liquidation;
|
| 26607 |
amit.gupta |
21 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 33436 |
ranu |
22 |
import com.spice.profitmandi.dao.entity.dtr.*;
|
| 30123 |
amit.gupta |
23 |
import com.spice.profitmandi.dao.entity.fofo.*;
|
| 33399 |
ranu |
24 |
import com.spice.profitmandi.dao.entity.inventory.State;
|
| 31203 |
tejbeer |
25 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 26630 |
amit.gupta |
26 |
import com.spice.profitmandi.dao.enumuration.dtr.OtpType;
|
| 31573 |
tejbeer |
27 |
import com.spice.profitmandi.dao.enumuration.dtr.WebListingSource;
|
| 27045 |
tejbeer |
28 |
import com.spice.profitmandi.dao.enumuration.transaction.OrderStatus;
|
| 30123 |
amit.gupta |
29 |
import com.spice.profitmandi.dao.model.*;
|
| 33436 |
ranu |
30 |
import com.spice.profitmandi.dao.model.pendingOrder.PendingOrderDetail;
|
| 34444 |
vikas.jang |
31 |
import com.spice.profitmandi.dao.repository.catalog.BidRepository;
|
| 26607 |
amit.gupta |
32 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 34444 |
vikas.jang |
33 |
import com.spice.profitmandi.dao.repository.catalog.LiquidationRepository;
|
| 26607 |
amit.gupta |
34 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 28290 |
tejbeer |
35 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 30123 |
amit.gupta |
36 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
|
|
37 |
import com.spice.profitmandi.dao.repository.fofo.*;
|
| 26607 |
amit.gupta |
38 |
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
|
| 33399 |
ranu |
39 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
| 28582 |
amit.gupta |
40 |
import com.spice.profitmandi.dao.repository.user.UserRepository;
|
| 34248 |
aman.kumar |
41 |
import com.spice.profitmandi.dao.repository.webRepository.NavBarRepository;
|
| 34494 |
vikas.jang |
42 |
import com.spice.profitmandi.dao.service.BidService;
|
| 34882 |
aman |
43 |
import com.spice.profitmandi.dao.service.OTPResponse;
|
| 26784 |
amit.gupta |
44 |
import com.spice.profitmandi.service.CustomerService;
|
| 28377 |
tejbeer |
45 |
import com.spice.profitmandi.service.EmailService;
|
|
|
46 |
import com.spice.profitmandi.service.NotificationService;
|
| 26607 |
amit.gupta |
47 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 34444 |
vikas.jang |
48 |
import com.spice.profitmandi.service.catalog.BiddingModel;
|
| 33399 |
ranu |
49 |
import com.spice.profitmandi.service.integrations.zest.InsuranceService;
|
|
|
50 |
import com.spice.profitmandi.service.integrations.zest.MobileInsurancePlan;
|
| 30123 |
amit.gupta |
51 |
import com.spice.profitmandi.service.inventory.*;
|
| 28566 |
tejbeer |
52 |
import com.spice.profitmandi.service.order.OrderService;
|
| 26683 |
amit.gupta |
53 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 26651 |
amit.gupta |
54 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 33514 |
tejus.loha |
55 |
import com.spice.profitmandi.dao.service.OtpProcessor;
|
| 34654 |
vikas.jang |
56 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 26607 |
amit.gupta |
57 |
import com.spice.profitmandi.web.res.DealBrands;
|
|
|
58 |
import com.spice.profitmandi.web.res.DealObjectResponse;
|
|
|
59 |
import com.spice.profitmandi.web.res.DealsResponse;
|
|
|
60 |
import com.spice.profitmandi.web.res.ValidateCartResponse;
|
| 28322 |
amit.gupta |
61 |
import com.spice.profitmandi.web.services.PartnerIndexService;
|
| 34654 |
vikas.jang |
62 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
| 26607 |
amit.gupta |
63 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
64 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
65 |
import io.swagger.annotations.ApiOperation;
|
| 30123 |
amit.gupta |
66 |
import org.apache.commons.lang3.StringUtils;
|
|
|
67 |
import org.apache.http.conn.HttpHostConnectException;
|
|
|
68 |
import org.apache.logging.log4j.LogManager;
|
|
|
69 |
import org.apache.logging.log4j.Logger;
|
|
|
70 |
import org.json.JSONArray;
|
|
|
71 |
import org.json.JSONObject;
|
|
|
72 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
73 |
import org.springframework.beans.factory.annotation.Value;
|
|
|
74 |
import org.springframework.core.io.InputStreamResource;
|
|
|
75 |
import org.springframework.http.HttpHeaders;
|
|
|
76 |
import org.springframework.http.HttpStatus;
|
|
|
77 |
import org.springframework.http.MediaType;
|
|
|
78 |
import org.springframework.http.ResponseEntity;
|
|
|
79 |
import org.springframework.stereotype.Controller;
|
|
|
80 |
import org.springframework.transaction.annotation.Transactional;
|
| 33399 |
ranu |
81 |
import org.springframework.ui.Model;
|
| 30123 |
amit.gupta |
82 |
import org.springframework.web.bind.annotation.*;
|
| 26607 |
amit.gupta |
83 |
|
| 30123 |
amit.gupta |
84 |
import javax.servlet.http.HttpServletRequest;
|
|
|
85 |
import javax.servlet.http.HttpServletResponse;
|
|
|
86 |
import java.io.ByteArrayInputStream;
|
|
|
87 |
import java.io.ByteArrayOutputStream;
|
|
|
88 |
import java.io.IOException;
|
|
|
89 |
import java.io.InputStream;
|
| 34446 |
vikas.jang |
90 |
import java.time.LocalDate;
|
| 30123 |
amit.gupta |
91 |
import java.time.LocalDateTime;
|
|
|
92 |
import java.time.LocalTime;
|
|
|
93 |
import java.time.format.DateTimeFormatter;
|
|
|
94 |
import java.util.*;
|
|
|
95 |
import java.util.stream.Collectors;
|
|
|
96 |
|
| 26607 |
amit.gupta |
97 |
@Controller
|
|
|
98 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
99 |
public class StoreController {
|
|
|
100 |
|
| 32018 |
tejbeer |
101 |
private static final Logger logger = LogManager.getLogger(StoreController.class);
|
| 26630 |
amit.gupta |
102 |
|
| 32018 |
tejbeer |
103 |
private static final LocalTime CUTOFF_TIME = LocalTime.of(15, 0);
|
| 26745 |
amit.gupta |
104 |
|
| 32018 |
tejbeer |
105 |
private static final List<Integer> TAG_IDS = Arrays.asList(4);
|
| 26745 |
amit.gupta |
106 |
|
| 32018 |
tejbeer |
107 |
@Autowired
|
|
|
108 |
CustomerAddressRepository customerAddressRepository;
|
| 28392 |
tejbeer |
109 |
|
| 32018 |
tejbeer |
110 |
@Autowired
|
|
|
111 |
WebOfferRepository webOfferRepository;
|
| 26607 |
amit.gupta |
112 |
|
| 32018 |
tejbeer |
113 |
@Value("${new.solr.url}")
|
|
|
114 |
private String solrUrl;
|
| 28345 |
tejbeer |
115 |
|
| 32018 |
tejbeer |
116 |
@Autowired
|
|
|
117 |
private PartnerIndexService partnerIndexService;
|
| 28345 |
tejbeer |
118 |
|
| 32018 |
tejbeer |
119 |
@Autowired
|
|
|
120 |
InventoryService inventoryService;
|
| 27045 |
tejbeer |
121 |
|
| 32018 |
tejbeer |
122 |
@Autowired
|
|
|
123 |
UserAccountRepository userAccountRepository;
|
| 26923 |
amit.gupta |
124 |
|
| 32018 |
tejbeer |
125 |
@Value("${python.api.host}")
|
|
|
126 |
private String host;
|
| 26833 |
amit.gupta |
127 |
|
| 32018 |
tejbeer |
128 |
@Autowired
|
|
|
129 |
CustomerService customerService;
|
| 26607 |
amit.gupta |
130 |
|
| 32018 |
tejbeer |
131 |
@Value("${python.api.port}")
|
|
|
132 |
private int port;
|
| 26923 |
amit.gupta |
133 |
|
| 32018 |
tejbeer |
134 |
@Autowired
|
|
|
135 |
private SaholicInventoryService saholicInventoryService;
|
| 26607 |
amit.gupta |
136 |
|
| 32018 |
tejbeer |
137 |
@Autowired
|
|
|
138 |
private PincodePartnerRepository pincodePartnerRepository;
|
| 26715 |
amit.gupta |
139 |
|
| 32018 |
tejbeer |
140 |
@Autowired
|
|
|
141 |
private FofoStoreRepository fofoStoreRepository;
|
| 26745 |
amit.gupta |
142 |
|
| 32018 |
tejbeer |
143 |
@Autowired
|
|
|
144 |
private RetailerService retailerService;
|
| 26861 |
tejbeer |
145 |
|
| 32018 |
tejbeer |
146 |
@Autowired
|
|
|
147 |
private PendingOrderRepository pendingOrderRepository;
|
| 26861 |
tejbeer |
148 |
|
| 32018 |
tejbeer |
149 |
@Autowired
|
|
|
150 |
private PendingOrderItemRepository pendingOrderItemRepository;
|
| 26652 |
amit.gupta |
151 |
|
| 32018 |
tejbeer |
152 |
@Autowired
|
|
|
153 |
private PendingOrderService pendingOrderService;
|
| 26648 |
amit.gupta |
154 |
|
| 32018 |
tejbeer |
155 |
@Autowired
|
|
|
156 |
private CustomerRepository customerRepository;
|
| 26774 |
amit.gupta |
157 |
|
| 32018 |
tejbeer |
158 |
@Autowired
|
|
|
159 |
private SolrService commonSolrService;
|
| 26607 |
amit.gupta |
160 |
|
| 32018 |
tejbeer |
161 |
@Autowired
|
|
|
162 |
private OtpProcessor otpProcessor;
|
| 26630 |
amit.gupta |
163 |
|
| 32018 |
tejbeer |
164 |
@Autowired
|
|
|
165 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
| 26607 |
amit.gupta |
166 |
|
| 32018 |
tejbeer |
167 |
@Autowired
|
|
|
168 |
private ResponseSender<?> responseSender;
|
| 26607 |
amit.gupta |
169 |
|
| 32018 |
tejbeer |
170 |
@Autowired
|
|
|
171 |
private TagListingRepository tagListingRepository;
|
| 26607 |
amit.gupta |
172 |
|
| 32018 |
tejbeer |
173 |
@Autowired
|
|
|
174 |
private ItemRepository itemRepository;
|
| 26701 |
amit.gupta |
175 |
|
| 32018 |
tejbeer |
176 |
@Autowired
|
|
|
177 |
private SchemeService schemeService;
|
| 26607 |
amit.gupta |
178 |
|
| 32018 |
tejbeer |
179 |
@Autowired
|
|
|
180 |
private UserRepository userRepository;
|
| 28566 |
tejbeer |
181 |
|
| 32018 |
tejbeer |
182 |
@Autowired
|
|
|
183 |
private ItemAvailabilityCacheRepository itemAvailabilityCacheRepository;
|
| 26607 |
amit.gupta |
184 |
|
| 32018 |
tejbeer |
185 |
@Autowired
|
|
|
186 |
private WebListingRepository webListingRepository;
|
| 26745 |
amit.gupta |
187 |
|
| 32018 |
tejbeer |
188 |
@Autowired
|
|
|
189 |
private WebProductListingRepository webProductListingRepository;
|
| 26745 |
amit.gupta |
190 |
|
| 32018 |
tejbeer |
191 |
@Autowired
|
|
|
192 |
private RoleManager roleManagerService;
|
| 26607 |
amit.gupta |
193 |
|
| 32018 |
tejbeer |
194 |
@Autowired
|
|
|
195 |
EmailService emailService;
|
| 27028 |
tejbeer |
196 |
|
| 32018 |
tejbeer |
197 |
@Autowired
|
|
|
198 |
CsService csService;
|
| 28339 |
tejbeer |
199 |
|
| 32018 |
tejbeer |
200 |
@Autowired
|
|
|
201 |
private NotificationService notificationService;
|
| 28377 |
tejbeer |
202 |
|
| 32018 |
tejbeer |
203 |
@Autowired
|
|
|
204 |
private com.spice.profitmandi.dao.repository.dtr.UserRepository dtrUserRepository;
|
| 28377 |
tejbeer |
205 |
|
| 32018 |
tejbeer |
206 |
@Autowired
|
|
|
207 |
private FofoOrderRepository fofoOrderRepository;
|
| 28566 |
tejbeer |
208 |
|
| 32018 |
tejbeer |
209 |
@Autowired
|
|
|
210 |
private FofoOrderItemRepository fofoOrderItemRepository;
|
| 28566 |
tejbeer |
211 |
|
| 32018 |
tejbeer |
212 |
@Autowired
|
|
|
213 |
private OrderService orderService;
|
| 29515 |
tejbeer |
214 |
|
| 32018 |
tejbeer |
215 |
@Autowired
|
| 33436 |
ranu |
216 |
InsurancePolicyRepository insurancePolicyRepository;
|
|
|
217 |
|
|
|
218 |
@Autowired
|
| 34444 |
vikas.jang |
219 |
LiquidationRepository liquidationRepository;
|
|
|
220 |
|
|
|
221 |
@Autowired
|
| 33436 |
ranu |
222 |
PendingOrderPlanRepository pendingOrderPlanRepository;
|
|
|
223 |
|
|
|
224 |
@Autowired
|
| 32018 |
tejbeer |
225 |
private ScratchOfferRepository scratchOfferRepository;
|
|
|
226 |
private static final List<String> offlineOrders = Arrays.asList("EMIOD", "POD");
|
| 28339 |
tejbeer |
227 |
|
| 34242 |
tejus.loha |
228 |
@Autowired
|
|
|
229 |
NavBarRepository navBarRepository;
|
|
|
230 |
|
| 34444 |
vikas.jang |
231 |
@Autowired
|
|
|
232 |
BidRepository bidRepository;
|
|
|
233 |
|
| 34494 |
vikas.jang |
234 |
@Autowired
|
|
|
235 |
BidService bidService;
|
|
|
236 |
|
| 34654 |
vikas.jang |
237 |
@Autowired
|
|
|
238 |
WalletService walletService;
|
|
|
239 |
|
| 32018 |
tejbeer |
240 |
List<String> filterableParams = Arrays.asList("brand");
|
| 26607 |
amit.gupta |
241 |
|
| 32018 |
tejbeer |
242 |
@RequestMapping(value = "/store/entity/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
243 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
244 |
@ApiOperation(value = "Get unit deal object")
|
|
|
245 |
public ResponseEntity<?> getUnitFocoDeal(HttpServletRequest request, @PathVariable(value = "id") long id) throws ProfitMandiBusinessException {
|
|
|
246 |
List<FofoCatalogResponse> dealResponses = new ArrayList<>();
|
|
|
247 |
List<Integer> tagIds = Arrays.asList(4);
|
|
|
248 |
FofoCatalogResponse fofoCatalogResponse = null;
|
|
|
249 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
250 |
if (roleManagerService.isPartner(userInfo.getRoleIds())) {
|
|
|
251 |
String categoryId = "(3 OR 6)";
|
| 26745 |
amit.gupta |
252 |
|
| 32018 |
tejbeer |
253 |
RestClient rc = new RestClient();
|
|
|
254 |
Map<String, String> params = new HashMap<>();
|
|
|
255 |
List<String> mandatoryQ = new ArrayList<>();
|
|
|
256 |
String catalogString = "catalog" + id;
|
| 26607 |
amit.gupta |
257 |
|
| 32018 |
tejbeer |
258 |
mandatoryQ.add(String.format("+(categoryId_i:%s) +(id:%s) +{!parent which=\"id:%s\"} tagId_i:(%s)", categoryId, catalogString, catalogString, StringUtils.join(tagIds, " ")));
|
| 26668 |
amit.gupta |
259 |
|
| 32018 |
tejbeer |
260 |
params.put("q", StringUtils.join(mandatoryQ, " "));
|
|
|
261 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
|
|
262 |
params.put("sort", "rank_i asc, create_s desc");
|
|
|
263 |
params.put("wt", "json");
|
|
|
264 |
String response = null;
|
|
|
265 |
try {
|
|
|
266 |
response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
|
|
267 |
} catch (HttpHostConnectException e) {
|
|
|
268 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
269 |
}
|
|
|
270 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
|
|
271 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
|
|
272 |
dealResponses = getCatalogResponse(docs, false, userInfo.getRetailerId());
|
|
|
273 |
fofoCatalogResponse = dealResponses.get(0);
|
|
|
274 |
fofoCatalogResponse.setWebOffers(webOfferRepository.selectAllActiveOffers().get(fofoCatalogResponse.getCatalogId()));
|
| 28467 |
tejbeer |
275 |
|
| 32018 |
tejbeer |
276 |
} else {
|
|
|
277 |
return responseSender.badRequest(
|
|
|
278 |
new ProfitMandiBusinessException("Retailer id", userInfo.getUserId(), "NOT_FOFO_RETAILER"));
|
|
|
279 |
}
|
|
|
280 |
return responseSender.ok(dealResponses.get(0));
|
|
|
281 |
}
|
| 26668 |
amit.gupta |
282 |
|
| 32018 |
tejbeer |
283 |
private Object toDealObject(JsonObject jsonObject) {
|
|
|
284 |
if (jsonObject.get("dealObject") != null && jsonObject.get("dealObject").asInt() == 1) {
|
|
|
285 |
return new Gson().fromJson(jsonObject.toString(), DealObjectResponse.class);
|
|
|
286 |
}
|
|
|
287 |
return new Gson().fromJson(jsonObject.toString(), DealsResponse.class);
|
|
|
288 |
}
|
| 26607 |
amit.gupta |
289 |
|
| 32018 |
tejbeer |
290 |
@RequestMapping(value = "/store/brands", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
291 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
292 |
@ApiOperation(value = "Get brand list and count for category")
|
|
|
293 |
public ResponseEntity<?> getBrands(HttpServletRequest request, @RequestParam(value = "category_id") String category_id) throws ProfitMandiBusinessException {
|
|
|
294 |
logger.info("Request " + request.getParameterMap());
|
|
|
295 |
String response = null;
|
|
|
296 |
// TODO: move to properties
|
|
|
297 |
String uri = ProfitMandiConstants.URL_BRANDS;
|
|
|
298 |
RestClient rc = new RestClient();
|
|
|
299 |
Map<String, String> params = new HashMap<>();
|
|
|
300 |
params.put("category_id", category_id);
|
|
|
301 |
List<DealBrands> dealBrandsResponse = null;
|
|
|
302 |
try {
|
|
|
303 |
response = rc.get(SchemeType.HTTP, host, port, uri, params);
|
|
|
304 |
} catch (HttpHostConnectException e) {
|
|
|
305 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
306 |
}
|
| 26607 |
amit.gupta |
307 |
|
| 32018 |
tejbeer |
308 |
dealBrandsResponse = new Gson().fromJson(response, new TypeToken<List<DealBrands>>() {
|
|
|
309 |
}.getType());
|
| 26607 |
amit.gupta |
310 |
|
| 32018 |
tejbeer |
311 |
return responseSender.ok(dealBrandsResponse);
|
|
|
312 |
}
|
| 26607 |
amit.gupta |
313 |
|
| 32018 |
tejbeer |
314 |
@RequestMapping(value = "/store/listing/{listingUrl}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
315 |
public ResponseEntity<?> bestSellers(HttpServletRequest request, @PathVariable String listingUrl) throws Exception {
|
|
|
316 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
317 |
WebListing webListing = webListingRepository.selectByUrl(listingUrl);
|
|
|
318 |
webListing.setFofoCatalogResponses(getDealResponses(userInfo, webListing));
|
|
|
319 |
return responseSender.ok(webListing);
|
|
|
320 |
}
|
| 26654 |
amit.gupta |
321 |
|
| 32018 |
tejbeer |
322 |
@RequestMapping(value = "/store/otp/generateOTP", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
323 |
public ResponseEntity<?> generateOtp(HttpServletRequest request, @RequestParam String mobile) throws Exception {
|
| 26630 |
amit.gupta |
324 |
|
| 32018 |
tejbeer |
325 |
return responseSender.ok(otpProcessor.generateOtp(mobile, OtpType.REGISTRATION));
|
| 26630 |
amit.gupta |
326 |
|
| 32018 |
tejbeer |
327 |
}
|
| 26652 |
amit.gupta |
328 |
|
| 32018 |
tejbeer |
329 |
@RequestMapping(value = "/store/checkmobile/{mobile}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 34882 |
aman |
330 |
public ResponseEntity<?> checkRegistrationUsingMobile(HttpServletRequest request, @PathVariable String mobile ,@RequestParam(required = false, defaultValue = "false") boolean isSmartSeller) throws Exception {
|
| 32018 |
tejbeer |
331 |
try {
|
|
|
332 |
Customer customer = customerRepository.selectByMobileNumber(mobile);
|
|
|
333 |
customer.setPasswordExist(StringUtils.isNotEmpty(customer.getPassword()));
|
| 34882 |
aman |
334 |
if(isSmartSeller){
|
|
|
335 |
customer.setSmartSeller(isSmartSeller);
|
|
|
336 |
}
|
| 32018 |
tejbeer |
337 |
return responseSender.ok(new CustomerModel(true, customer));
|
|
|
338 |
} catch (Exception e) {
|
|
|
339 |
return responseSender.ok(new CustomerModel(false, null));
|
|
|
340 |
}
|
|
|
341 |
}
|
| 26833 |
amit.gupta |
342 |
|
| 34477 |
aman.kumar |
343 |
|
| 32019 |
tejbeer |
344 |
@RequestMapping(value = "/store/getCustomerById/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 32018 |
tejbeer |
345 |
public ResponseEntity<?> getCustomerById(HttpServletRequest request, @PathVariable int id) throws Exception {
|
| 26774 |
amit.gupta |
346 |
|
| 32018 |
tejbeer |
347 |
Customer customer = customerRepository.selectById(id);
|
|
|
348 |
customer.setPasswordExist(StringUtils.isNotEmpty(customer.getPassword()));
|
| 32218 |
tejbeer |
349 |
|
| 32018 |
tejbeer |
350 |
return responseSender.ok(customer);
|
| 26857 |
amit.gupta |
351 |
|
| 32018 |
tejbeer |
352 |
}
|
| 26652 |
amit.gupta |
353 |
|
| 32018 |
tejbeer |
354 |
@RequestMapping(value = "/store/signin", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
355 |
public ResponseEntity<?> signIn(HttpServletRequest request, @RequestBody UserModel userModel) throws Exception {
|
|
|
356 |
if (customerService.authenticate(userModel.getMobile(), userModel.getPassword())) {
|
|
|
357 |
return responseSender.ok(true);
|
|
|
358 |
} else {
|
| 34899 |
aman |
359 |
return responseSender.badRequest("Invalid Credentials");
|
| 32018 |
tejbeer |
360 |
}
|
|
|
361 |
}
|
| 27028 |
tejbeer |
362 |
|
| 32018 |
tejbeer |
363 |
@RequestMapping(value = "/store/resetPassword", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 34190 |
aman.kumar |
364 |
public ResponseEntity<?> resetPassword(@RequestBody UserModel userModel) throws Exception {
|
| 34247 |
aman.kumar |
365 |
if ((userModel.getMobile() == null || userModel.getMobile().isEmpty()) && (userModel.getPassword() == null || userModel.getPassword().isEmpty())) {
|
|
|
366 |
throw new ProfitMandiBusinessException("error", "", "all field are required");
|
|
|
367 |
}
|
| 34259 |
aman.kumar |
368 |
try {
|
|
|
369 |
customerService.resetPassword(userModel.getMobile(), userModel.getPassword());
|
|
|
370 |
} catch (ProfitMandiBusinessException p) {
|
|
|
371 |
throw new ProfitMandiBusinessException("error", "", "An error occurred while resetting password");
|
|
|
372 |
}
|
| 34247 |
aman.kumar |
373 |
|
| 32018 |
tejbeer |
374 |
return responseSender.ok(true);
|
|
|
375 |
}
|
| 34242 |
tejus.loha |
376 |
|
| 34190 |
aman.kumar |
377 |
@RequestMapping(value = "/store/changePassword", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
378 |
public ResponseEntity<?> changePassword(@RequestBody UserModel userModel) throws Exception {
|
| 34259 |
aman.kumar |
379 |
logger.info("UserModel - " + userModel);
|
|
|
380 |
if ((userModel.getOldPassword() == null || userModel.getOldPassword().isEmpty()) && (userModel.getMobile() == null || userModel.getMobile().isEmpty()) && (userModel.getPassword() == null || userModel.getPassword().isEmpty())) {
|
| 34247 |
aman.kumar |
381 |
throw new ProfitMandiBusinessException("error", "", "all fields are required");
|
| 34190 |
aman.kumar |
382 |
}
|
| 34259 |
aman.kumar |
383 |
try {
|
|
|
384 |
customerService.changePassword(userModel.getMobile(), userModel.getOldPassword(), userModel.getPassword());
|
|
|
385 |
} catch (ProfitMandiBusinessException p) {
|
| 34247 |
aman.kumar |
386 |
throw new ProfitMandiBusinessException("error", "", "An error occurred while changing password");
|
|
|
387 |
}
|
|
|
388 |
return responseSender.ok(true);
|
| 34190 |
aman.kumar |
389 |
}
|
| 28339 |
tejbeer |
390 |
|
| 32018 |
tejbeer |
391 |
@RequestMapping(value = "/store/register", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
392 |
public ResponseEntity<?> register(HttpServletRequest request, @RequestBody UserModel userModel) throws Exception {
|
|
|
393 |
Customer customer = new Customer();
|
|
|
394 |
customer.setPassword(userModel.getPassword());
|
|
|
395 |
customer.setEmailId(userModel.getEmail());
|
|
|
396 |
customer.setFirstName(userModel.getFirstName());
|
|
|
397 |
customer.setLastName(userModel.getLastName());
|
|
|
398 |
customer.setMobileNumber(userModel.getMobile());
|
| 34882 |
aman |
399 |
customer.setSmartSeller(userModel.getIsSmartSeller());
|
| 32018 |
tejbeer |
400 |
return responseSender.ok(customerService.addCustomer(customer));
|
|
|
401 |
}
|
| 34882 |
aman |
402 |
@RequestMapping(value = "/store/signinWithOtp", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
403 |
public ResponseEntity<?> signInWithOtp(HttpServletRequest request,
|
|
|
404 |
@RequestBody OtpLoginRequest otpLoginRequest) throws Exception {
|
|
|
405 |
OTPResponse otpResponse = otpProcessor.validateOtp(
|
|
|
406 |
otpLoginRequest.getReferenceId(),
|
|
|
407 |
otpLoginRequest.getMobile(),
|
|
|
408 |
otpLoginRequest.getOtp()
|
|
|
409 |
);
|
|
|
410 |
if (otpResponse.isResult()) {
|
|
|
411 |
return responseSender.ok(true);
|
|
|
412 |
} else {
|
|
|
413 |
return responseSender.badRequest("Invalid otp please check again");
|
|
|
414 |
}
|
|
|
415 |
}
|
| 28339 |
tejbeer |
416 |
|
| 33573 |
amit.gupta |
417 |
@RequestMapping(value = "/store/checkplans", method = RequestMethod.GET)
|
| 33436 |
ranu |
418 |
public ResponseEntity<?> getInsurancePrices(HttpServletRequest request, @RequestParam float price, Model model,
|
| 33573 |
amit.gupta |
419 |
@RequestParam int itemId) throws ProfitMandiBusinessException {
|
| 33399 |
ranu |
420 |
logger.info("Request received at url : {}", request.getRequestURI());
|
|
|
421 |
|
|
|
422 |
try {
|
| 33436 |
ranu |
423 |
Map<String, List<MobileInsurancePlan>> response = this.getPlans(price, itemId);
|
|
|
424 |
List<MobileInsurancePlan> combinedPlans = new ArrayList<>();
|
|
|
425 |
for (List<MobileInsurancePlan> plans : response.values()) {
|
|
|
426 |
combinedPlans.addAll(plans);
|
|
|
427 |
}
|
|
|
428 |
return responseSender.ok(combinedPlans);
|
| 33399 |
ranu |
429 |
} catch (Exception e) {
|
|
|
430 |
logger.info(e.getMessage(), e);
|
|
|
431 |
throw new ProfitMandiBusinessException("Plans", "Plans API", "Error formatting insurance plans");
|
|
|
432 |
}
|
|
|
433 |
|
|
|
434 |
}
|
|
|
435 |
|
|
|
436 |
@Autowired
|
|
|
437 |
InsuranceService insuranceService;
|
|
|
438 |
|
|
|
439 |
private Map<String, List<MobileInsurancePlan>> getPlans(float sellingPrice, int itemId)
|
|
|
440 |
throws ProfitMandiBusinessException {
|
|
|
441 |
try {
|
| 33573 |
amit.gupta |
442 |
Map<String, List<MobileInsurancePlan>> productDurationPlans = insuranceService.getAllPlans(itemId, sellingPrice, true);
|
| 34822 |
ranu |
443 |
Map<String, List<MobileInsurancePlan>> filteredPlans = productDurationPlans.entrySet()
|
|
|
444 |
.stream()
|
|
|
445 |
.collect(Collectors.toMap(
|
|
|
446 |
Map.Entry::getKey,
|
|
|
447 |
e -> e.getValue().stream()
|
| 34823 |
ranu |
448 |
.filter(plan -> "5".equals(plan.getProviderId()))
|
| 34822 |
ranu |
449 |
.collect(Collectors.toList())
|
|
|
450 |
));
|
|
|
451 |
return filteredPlans;
|
| 33399 |
ranu |
452 |
} catch (Exception e) {
|
|
|
453 |
logger.info(e, e);
|
| 34247 |
aman.kumar |
454 |
throw new ProfitMandiBusinessException("Fetch Insurance Plans", "Insurance", "Could not fetch insurance Plans");
|
| 33399 |
ranu |
455 |
}
|
|
|
456 |
|
|
|
457 |
}
|
|
|
458 |
|
| 32018 |
tejbeer |
459 |
@RequestMapping(value = "/store/confirmOrder", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
460 |
public ResponseEntity<?> confirmOrder(HttpServletRequest request, @RequestBody CreatePendingOrderRequest createPendingOrderRequest) throws Exception {
|
|
|
461 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
462 |
Integer storeId = userInfo.getRetailerId();
|
|
|
463 |
createPendingOrderRequest.setFofoId(storeId);
|
|
|
464 |
List<CreatePendingOrderItem> pendingOrderItems = createPendingOrderRequest.getCreatePendingOrderItem();
|
|
|
465 |
List<CartItem> cartItems = new ArrayList<>();
|
|
|
466 |
pendingOrderItems.stream().forEach(x -> {
|
|
|
467 |
CartItem ci = new CartItem();
|
|
|
468 |
ci.setItemId(x.getItemId());
|
|
|
469 |
ci.setQuantity(x.getQuantity());
|
|
|
470 |
ci.setSellingPrice(x.getSellingPrice());
|
| 33436 |
ranu |
471 |
ci.setPendingOrderItemPolicyPlan(x.getPendingOrderItemPolicyPlan());
|
| 32018 |
tejbeer |
472 |
cartItems.add(ci);
|
|
|
473 |
});
|
| 33573 |
amit.gupta |
474 |
logger.info("cartItems {}", cartItems);
|
| 32018 |
tejbeer |
475 |
CartResponse cr = this.validateCart(storeId, cartItems);
|
| 34239 |
vikas.jang |
476 |
logger.info("CartResponse cr {}", cr);
|
| 32018 |
tejbeer |
477 |
if (cr.getCartMessageChanged() > 0 || cr.getTotalAmount() != createPendingOrderRequest.getTotalAmount()) {
|
| 34186 |
vikas.jang |
478 |
return responseSender.badRequest(cr.getCartMessages());
|
| 32018 |
tejbeer |
479 |
}
|
| 28377 |
tejbeer |
480 |
|
| 32018 |
tejbeer |
481 |
Map<String, String> returnMap = this.pendingOrderService.createPendingOrder(createPendingOrderRequest, cr);
|
| 28377 |
tejbeer |
482 |
|
| 32018 |
tejbeer |
483 |
PendingOrder pendingOrder = pendingOrderRepository.selectById(Integer.parseInt(returnMap.get("poId")));
|
|
|
484 |
if (offlineOrders.contains(pendingOrder.getPayMethod())) {
|
| 28391 |
tejbeer |
485 |
|
| 32018 |
tejbeer |
486 |
Map<String, Object> emailModel = pendingOrderService.sendCreateOrderMail(pendingOrder);
|
| 28400 |
tejbeer |
487 |
|
| 32018 |
tejbeer |
488 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(pendingOrder.getFofoId());
|
|
|
489 |
Customer customer = customerRepository.selectById(pendingOrder.getCustomerId());
|
|
|
490 |
String[] customerEmail = null;
|
|
|
491 |
if (Utils.validateEmail(customer.getEmailId())) {
|
|
|
492 |
customerEmail = new String[]{customer.getEmailId()};
|
|
|
493 |
}
|
| 31203 |
tejbeer |
494 |
|
| 32616 |
amit.gupta |
495 |
List<String> bccTo = Arrays.asList("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com", "niranjan.kala@smartdukaan.com", "sm@smartdukaan.com", "ranu.rajput@smartdukaan.com", "devkinandan.lal@smartdukaan.com", customRetailer.getEmail());
|
| 28394 |
tejbeer |
496 |
|
| 32018 |
tejbeer |
497 |
List<String> authUserEmails = csService.getAuthUserByPartnerId(customRetailer.getPartnerId());
|
|
|
498 |
if (authUserEmails != null) {
|
|
|
499 |
authUserEmails = new ArrayList<>();
|
|
|
500 |
}
|
|
|
501 |
logger.info("authUserEmails {}", authUserEmails);
|
|
|
502 |
authUserEmails.addAll(bccTo);
|
|
|
503 |
StringBuffer itemBuffer = new StringBuffer();
|
|
|
504 |
List<PendingOrderItem> orderItems = pendingOrderItemRepository.selectByOrderId(pendingOrder.getId());
|
|
|
505 |
int totalItems = 0;
|
|
|
506 |
String itemNoColor = null;
|
|
|
507 |
float maxValue = 0;
|
|
|
508 |
for (PendingOrderItem orderItem : orderItems) {
|
|
|
509 |
if (maxValue < orderItem.getSellingPrice()) {
|
|
|
510 |
maxValue = orderItem.getSellingPrice();
|
|
|
511 |
itemNoColor = itemRepository.selectById(orderItem.getItemId()).getItemDescriptionNoColor();
|
|
|
512 |
}
|
|
|
513 |
totalItems += orderItem.getQuantity();
|
|
|
514 |
}
|
|
|
515 |
if (totalItems > 1) {
|
|
|
516 |
itemBuffer.append(StringUtils.abbreviate(itemNoColor, 22));
|
|
|
517 |
itemBuffer.append(" +").append(totalItems - 1).append(" items");
|
|
|
518 |
} else {
|
|
|
519 |
itemBuffer.append(StringUtils.abbreviate(itemNoColor, 30));
|
|
|
520 |
}
|
|
|
521 |
String message = String.format(OtpProcessor.TEMPLATE_ORDER_CREATED, pendingOrder.getId(), itemBuffer.toString(), pendingOrder.getTotalAmount());
|
|
|
522 |
otpProcessor.sendSms(OtpProcessor.TEMPLATE_ORDER_CREATED_ID, message, customer.getMobileNumber());
|
| 28377 |
tejbeer |
523 |
|
| 32018 |
tejbeer |
524 |
emailService.sendMailWithAttachments("Order Created with SmartDukaan", "order-confirm.vm", emailModel, customerEmail, null, bccTo.toArray(new String[0]));
|
| 28377 |
tejbeer |
525 |
|
| 32018 |
tejbeer |
526 |
List<String> emailIds = csService.getAuthUserIdByPartnerId(customRetailer.getPartnerId()).stream().map(x -> x.getEmailId()).collect(Collectors.toList());
|
| 27028 |
tejbeer |
527 |
|
| 32018 |
tejbeer |
528 |
emailIds.addAll(
|
|
|
529 |
csService.getAuthUserIds(ProfitMandiConstants.TICKET_CATEGORY_MARKETING, Arrays.asList(EscalationType.L1, EscalationType.L2, EscalationType.L3, EscalationType.L4)).stream().map(x -> x.getEmailId()).collect(Collectors.toList()));
|
|
|
530 |
emailIds.add("tarun.verma@smartdukaan.com");
|
|
|
531 |
emailIds.add("devkinandan.lal@smartdukaan.com");
|
| 34186 |
vikas.jang |
532 |
emailIds.add("vikas.jangra@smartdukaan.com");
|
| 32018 |
tejbeer |
533 |
List<User> user = dtrUserRepository.selectAllByEmailIds(emailIds);
|
|
|
534 |
List<Integer> userIds = user.stream().map(x -> x.getId()).collect(Collectors.toList());
|
| 26630 |
amit.gupta |
535 |
|
| 32018 |
tejbeer |
536 |
logger.info("userIds" + userIds);
|
|
|
537 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
538 |
sendNotificationModel.setCampaignName("Online Order Alert");
|
|
|
539 |
sendNotificationModel.setTitle("Online Order Update");
|
|
|
540 |
sendNotificationModel.setMessage(String.format(
|
|
|
541 |
"You have new Online Order. Please check your Dashboard. In case of an activation scheme pls ensure the handset is activated, payout will be processed as per brand's activation report."));
|
|
|
542 |
sendNotificationModel.setType("url");
|
|
|
543 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
|
|
544 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
|
|
545 |
sendNotificationModel.setMessageType(MessageType.notification);
|
|
|
546 |
int userId = userAccountRepository.selectUserIdByRetailerId(pendingOrder.getFofoId());
|
|
|
547 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
|
|
548 |
notificationService.sendNotification(sendNotificationModel);
|
| 26857 |
amit.gupta |
549 |
|
| 32018 |
tejbeer |
550 |
SendNotificationModel snm = new SendNotificationModel();
|
|
|
551 |
snm.setCampaignName("Online Order Alert");
|
|
|
552 |
snm.setTitle("Online Order Update");
|
|
|
553 |
snm.setMessage(String.format("Your Partner " + customRetailer.getBusinessName() + " have new Online Order. Please inform your partner. In case of an activation scheme pls ensure the handset is activated, payout will be processed as per brand's activation report."));
|
|
|
554 |
snm.setType("url");
|
|
|
555 |
snm.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
|
|
556 |
snm.setExpiresat(LocalDateTime.now().plusDays(1));
|
|
|
557 |
snm.setMessageType(MessageType.notification);
|
|
|
558 |
snm.setUserIds(userIds);
|
|
|
559 |
notificationService.sendNotification(snm);
|
| 26857 |
amit.gupta |
560 |
|
| 32018 |
tejbeer |
561 |
}
|
|
|
562 |
return responseSender.ok(returnMap);
|
| 26857 |
amit.gupta |
563 |
|
| 32018 |
tejbeer |
564 |
}
|
|
|
565 |
@RequestMapping(value = "/store/address", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
566 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
567 |
@ApiOperation(value = "Get brand list and count for category")
|
|
|
568 |
public ResponseEntity<?> getAddress(HttpServletRequest request) throws Exception {
|
|
|
569 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
570 |
Integer storeId = userInfo.getRetailerId();
|
|
|
571 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(storeId);
|
| 26923 |
amit.gupta |
572 |
|
| 32018 |
tejbeer |
573 |
return responseSender.ok(customRetailer.getAddress());
|
| 28566 |
tejbeer |
574 |
|
| 32018 |
tejbeer |
575 |
}
|
| 34190 |
aman.kumar |
576 |
@RequestMapping(value = "/store/address/defaultAddress/{addressId}/{customerId}", method = RequestMethod.POST)
|
|
|
577 |
@ApiImplicitParams({
|
|
|
578 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")
|
|
|
579 |
})
|
|
|
580 |
@ApiOperation(value = "Set default address for a store")
|
| 34259 |
aman.kumar |
581 |
public ResponseEntity<?> setDefaultAddress(HttpServletRequest request, @PathVariable int addressId, @PathVariable int customerId) throws Exception {
|
| 34190 |
aman.kumar |
582 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
583 |
CustomerAddress defaultAddress;
|
|
|
584 |
try {
|
|
|
585 |
defaultAddress = customerAddressRepository.selectById(addressId);
|
|
|
586 |
} catch (ProfitMandiBusinessException e) {
|
|
|
587 |
return responseSender.badRequest("Address not found.");
|
|
|
588 |
}
|
|
|
589 |
logger.info("CustomerID: {}", customerId);
|
|
|
590 |
List<CustomerAddress> customerAddresses = customerAddressRepository.selectByActiveCustomerId(customerId);
|
|
|
591 |
logger.info("customerAddresses: {}", customerAddresses);
|
|
|
592 |
for (CustomerAddress addr : customerAddresses) {
|
| 34259 |
aman.kumar |
593 |
if (addr.getDefault() ) {
|
| 34190 |
aman.kumar |
594 |
addr.setDefault(false);
|
|
|
595 |
}
|
|
|
596 |
}
|
|
|
597 |
defaultAddress.setDefault(true);
|
|
|
598 |
return responseSender.ok("Default address updated successfully.");
|
|
|
599 |
}
|
| 28566 |
tejbeer |
600 |
|
| 32018 |
tejbeer |
601 |
@RequestMapping(value = "/store/address/{pincode}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
602 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
603 |
@ApiOperation(value = "Get brand list and count for category")
|
|
|
604 |
public ResponseEntity<?> getStoresByPincode(HttpServletRequest request, @PathVariable String pincode) throws Exception {
|
|
|
605 |
List<PincodePartner> pincodePartners = pincodePartnerRepository.selectPartnersByPincode(pincode);
|
|
|
606 |
int fofoId = ProfitMandiConstants.DEFAULT_STORE;
|
|
|
607 |
if (pincodePartners.size() > 0) {
|
|
|
608 |
List<Integer> fofoIds = pincodePartners.stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
|
|
609 |
List<FofoStore> fofoStores = fofoStoreRepository.selectActivePartnersByRetailerIds(fofoIds);
|
|
|
610 |
if (fofoStores.size() > 0) {
|
|
|
611 |
fofoId = fofoStores.get(0).getId();
|
|
|
612 |
}
|
| 28566 |
tejbeer |
613 |
|
| 32018 |
tejbeer |
614 |
}
|
|
|
615 |
return responseSender.ok(fofoStoreRepository.selectByRetailerId(fofoId).getCode());
|
|
|
616 |
}
|
| 28566 |
tejbeer |
617 |
|
| 32018 |
tejbeer |
618 |
@RequestMapping(value = "/store/addresses", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
619 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
620 |
@ApiOperation(value = "Get brand list and count for category")
|
|
|
621 |
public ResponseEntity<?> getStoresByPincod(HttpServletRequest request, @RequestParam String pincode, @RequestParam(name = "fofoCode", defaultValue = "", required = false) String fofoCode) throws Exception {
|
| 28566 |
tejbeer |
622 |
|
| 32018 |
tejbeer |
623 |
List<CustomRetailer> customerRetailers = new ArrayList<>();
|
| 28566 |
tejbeer |
624 |
|
| 32018 |
tejbeer |
625 |
logger.info("fofoCode" + fofoCode);
|
| 30426 |
tejbeer |
626 |
|
| 32018 |
tejbeer |
627 |
if (fofoCode != null) {
|
|
|
628 |
FofoStore fs = fofoStoreRepository.selectByStoreCode(fofoCode.toUpperCase());
|
|
|
629 |
PincodePartner pp = pincodePartnerRepository.selectPartnerByPincode(pincode, fs.getId());
|
|
|
630 |
if (pp != null) {
|
|
|
631 |
return responseSender.ok(customerRetailers.add(retailerService.getFofoRetailer(pp.getFofoId())));
|
|
|
632 |
} else {
|
| 30426 |
tejbeer |
633 |
|
| 32018 |
tejbeer |
634 |
List<PincodePartner> pincodePartners = pincodePartnerRepository.selectPartnersByPincode(pincode);
|
|
|
635 |
if (pincodePartners.size() > 0) {
|
| 28566 |
tejbeer |
636 |
|
| 32018 |
tejbeer |
637 |
List<Integer> fofoIds = pincodePartners.stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
|
|
638 |
List<Integer> activefofoIds = fofoStoreRepository.selectByRetailerIds(fofoIds).stream().filter(x -> x.isActive()).map(x -> x.getId()).collect(Collectors.toList());
|
| 28566 |
tejbeer |
639 |
|
| 32018 |
tejbeer |
640 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
| 28566 |
tejbeer |
641 |
|
| 32018 |
tejbeer |
642 |
Map<Integer, CustomRetailer> customerRetailerMap = activefofoIds.stream().map(x -> customRetailerMap.get(x)).filter(x -> x != null).collect(Collectors.toList()).stream().collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
| 28566 |
tejbeer |
643 |
|
| 32018 |
tejbeer |
644 |
customerRetailers.addAll(customerRetailerMap.values());
|
| 30426 |
tejbeer |
645 |
|
| 32018 |
tejbeer |
646 |
}
|
|
|
647 |
return responseSender.ok(customerRetailers);
|
| 30426 |
tejbeer |
648 |
|
| 32018 |
tejbeer |
649 |
}
|
|
|
650 |
} else {
|
| 28566 |
tejbeer |
651 |
|
| 32018 |
tejbeer |
652 |
List<PincodePartner> pincodePartners = pincodePartnerRepository.selectPartnersByPincode(pincode);
|
|
|
653 |
if (pincodePartners.size() > 0) {
|
|
|
654 |
List<Integer> fofoIds = pincodePartners.stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
|
|
655 |
List<Integer> activefofoIds = fofoStoreRepository.selectByRetailerIds(fofoIds).stream().filter(x -> x.isActive()).map(x -> x.getId()).collect(Collectors.toList());
|
| 28566 |
tejbeer |
656 |
|
| 32018 |
tejbeer |
657 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
| 28566 |
tejbeer |
658 |
|
| 32018 |
tejbeer |
659 |
Map<Integer, CustomRetailer> customerRetailerMap = activefofoIds.stream().map(x -> customRetailerMap.get(x)).filter(x -> x != null).collect(Collectors.toList()).stream().collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
| 28566 |
tejbeer |
660 |
|
| 32018 |
tejbeer |
661 |
customerRetailers.addAll(customerRetailerMap.values());
|
|
|
662 |
}
|
| 28298 |
tejbeer |
663 |
|
| 32018 |
tejbeer |
664 |
return responseSender.ok(customerRetailers);
|
| 30426 |
tejbeer |
665 |
|
| 32018 |
tejbeer |
666 |
}
|
| 30426 |
tejbeer |
667 |
|
| 32018 |
tejbeer |
668 |
}
|
| 30426 |
tejbeer |
669 |
|
| 32018 |
tejbeer |
670 |
@RequestMapping(value = "/store/address/detail/{pincode}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
671 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
672 |
@ApiOperation(value = "Get brand list and count for category")
|
|
|
673 |
public ResponseEntity<?> getStoresDetailsByPincode(HttpServletRequest request, @PathVariable String pincode) throws Exception {
|
|
|
674 |
List<CustomRetailer> customerRetailers = new ArrayList<>();
|
|
|
675 |
List<PincodePartner> pincodePartners = pincodePartnerRepository.selectPartnersByPincode(pincode);
|
| 28298 |
tejbeer |
676 |
|
| 32018 |
tejbeer |
677 |
if (!pincodePartners.isEmpty()) {
|
|
|
678 |
List<Integer> fofoIds = pincodePartners.stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
|
|
679 |
List<Integer> activefofoIds = fofoStoreRepository.selectByRetailerIds(fofoIds).stream().filter(x -> x.isActive()).map(x -> x.getId()).collect(Collectors.toList());
|
| 28298 |
tejbeer |
680 |
|
| 32018 |
tejbeer |
681 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
| 28566 |
tejbeer |
682 |
|
| 32018 |
tejbeer |
683 |
Map<Integer, CustomRetailer> customerRetailerMap = activefofoIds.stream().map(x -> customRetailerMap.get(x)).filter(x -> x != null).collect(Collectors.toList()).stream().collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
| 27049 |
tejbeer |
684 |
|
| 32018 |
tejbeer |
685 |
customerRetailers.addAll(customerRetailerMap.values());
|
|
|
686 |
}
|
| 27049 |
tejbeer |
687 |
|
| 32018 |
tejbeer |
688 |
logger.info("customerRetailers" + customerRetailers);
|
|
|
689 |
return responseSender.ok(customerRetailers);
|
|
|
690 |
}
|
| 26855 |
tejbeer |
691 |
|
| 32018 |
tejbeer |
692 |
@RequestMapping(value = "/store/order", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
693 |
public ResponseEntity<?> getOrderDetail(HttpServletRequest request, @RequestParam(value = "id") int id, @RequestParam(name = "offset") int offset, @RequestParam(name = "limit") int limit) throws Exception {
|
| 33436 |
ranu |
694 |
|
|
|
695 |
List<PendingOrderDetail> pendingOrderDetails = new ArrayList<>();
|
| 32018 |
tejbeer |
696 |
List<Integer> catalogIds = new ArrayList<>();
|
|
|
697 |
List<PendingOrder> pendingOrders = pendingOrderRepository.selectByCustomerId(id, offset, limit);
|
| 26855 |
tejbeer |
698 |
|
| 32018 |
tejbeer |
699 |
if (!pendingOrders.isEmpty()) {
|
|
|
700 |
for (PendingOrder po : pendingOrders) {
|
|
|
701 |
List<PendingOrderItem> pois = pendingOrderItemRepository.selectByOrderId(po.getId());
|
|
|
702 |
for (PendingOrderItem pendingOrderItem : pois) {
|
|
|
703 |
Item item = itemRepository.selectById(pendingOrderItem.getItemId());
|
|
|
704 |
pendingOrderItem.setItemName(item.getItemDescription());
|
| 34287 |
vikas.jang |
705 |
FofoOrderItem fofoItem = fofoOrderItemRepository.selectByPendingOrderItemId(pendingOrderItem.getId());
|
|
|
706 |
if (fofoItem != null) pendingOrderItem.setFofoOrderItem(fofoItem);
|
| 32018 |
tejbeer |
707 |
catalogIds.add(item.getCatalogItemId());
|
|
|
708 |
}
|
| 26855 |
tejbeer |
709 |
|
| 32018 |
tejbeer |
710 |
Map<Integer, JSONObject> contentMap = commonSolrService.getContentByCatalogIds(catalogIds);
|
| 26855 |
tejbeer |
711 |
|
| 32018 |
tejbeer |
712 |
for (PendingOrderItem poi : pois) {
|
| 33436 |
ranu |
713 |
PendingOrderDetail pendingOrderDetail = new PendingOrderDetail();
|
| 32018 |
tejbeer |
714 |
Item item = itemRepository.selectById(poi.getItemId());
|
| 34287 |
vikas.jang |
715 |
if(contentMap.containsKey(item.getCatalogItemId())) {
|
|
|
716 |
JSONObject jsonObj = contentMap.get(item.getCatalogItemId());
|
|
|
717 |
pendingOrderDetail.setImageUrl(jsonObj.getString("imageUrl_s"));
|
|
|
718 |
} else {
|
|
|
719 |
pendingOrderDetail.setImageUrl(ProfitMandiConstants.NO_IMAGE);
|
|
|
720 |
}
|
| 33436 |
ranu |
721 |
pendingOrderDetail.setBrand(item.getBrand());
|
|
|
722 |
pendingOrderDetail.setColor(item.getColor());
|
|
|
723 |
pendingOrderDetail.setPendingOrderItemId(poi.getId());
|
|
|
724 |
pendingOrderDetail.setId(poi.getOrderId());
|
| 34287 |
vikas.jang |
725 |
if(poi.getFofoOrderItem() != null && poi.getFofoOrderItem().getOrderId() > 0) pendingOrderDetail.setFofoOrderId(poi.getFofoOrderItem().getOrderId());
|
| 33436 |
ranu |
726 |
pendingOrderDetail.setItemId(poi.getItemId());
|
|
|
727 |
pendingOrderDetail.setModelName(item.getModelName());
|
|
|
728 |
pendingOrderDetail.setModelNumber(item.getModelNumber());
|
|
|
729 |
pendingOrderDetail.setQuantity(poi.getQuantity());
|
|
|
730 |
pendingOrderDetail.setBilledTimestamp(poi.getBilledTimestamp());
|
|
|
731 |
pendingOrderDetail.setStatus(poi.getStatus());
|
|
|
732 |
pendingOrderDetail.setTotalPrice(poi.getSellingPrice());
|
|
|
733 |
pendingOrderDetail.setPayMethod(po.getPayMethod());
|
|
|
734 |
pendingOrderDetail.setCreatedTimeStamp(po.getCreateTimestamp());
|
|
|
735 |
pendingOrderDetail.setPendingOrderPlan(pendingOrderPlanRepository.selectByPoid(poi.getId()));
|
|
|
736 |
pendingOrderDetails.add(pendingOrderDetail);
|
| 32018 |
tejbeer |
737 |
}
|
|
|
738 |
}
|
|
|
739 |
}
|
| 28566 |
tejbeer |
740 |
|
| 33436 |
ranu |
741 |
return responseSender.ok(pendingOrderDetails);
|
| 32018 |
tejbeer |
742 |
}
|
| 28566 |
tejbeer |
743 |
|
| 32018 |
tejbeer |
744 |
@RequestMapping(value = "/store/invoiceOrder", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
745 |
public ResponseEntity<?> getOrderInvoiceDetail(HttpServletRequest request, @RequestParam(value = "id") int id, @RequestParam(name = "offset") int offset, @RequestParam(name = "limit") int limit) throws Exception {
|
| 33436 |
ranu |
746 |
List<CustomerOrderAndInsuranceDetails> customerOrderAndInsuranceDetails = new ArrayList<>();
|
| 32018 |
tejbeer |
747 |
List<Integer> catalogIds = new ArrayList<>();
|
|
|
748 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectOrderByCustomerId(id, offset, limit);
|
| 28566 |
tejbeer |
749 |
|
| 32018 |
tejbeer |
750 |
if (!fofoOrders.isEmpty()) {
|
|
|
751 |
for (FofoOrder fo : fofoOrders) {
|
|
|
752 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fo.getId());
|
|
|
753 |
for (FofoOrderItem fofoOrderItem : fofoOrderItems) {
|
|
|
754 |
Item item = itemRepository.selectById(fofoOrderItem.getItemId());
|
|
|
755 |
fofoOrderItem.setItemName(item.getItemDescription());
|
|
|
756 |
catalogIds.add(item.getCatalogItemId());
|
|
|
757 |
}
|
| 28566 |
tejbeer |
758 |
|
| 32018 |
tejbeer |
759 |
Map<Integer, JSONObject> contentMap = commonSolrService.getContentByCatalogIds(catalogIds);
|
|
|
760 |
for (FofoOrderItem foi : fofoOrderItems) {
|
| 33436 |
ranu |
761 |
CustomerOrderAndInsuranceDetails customerOrderDetail = new CustomerOrderAndInsuranceDetails();
|
| 32018 |
tejbeer |
762 |
Item item = itemRepository.selectById(foi.getItemId());
|
|
|
763 |
JSONObject jsonObj = contentMap.get(item.getCatalogItemId());
|
|
|
764 |
customerOrderDetail.setImageUrl(jsonObj.getString("imageUrl_s"));
|
|
|
765 |
customerOrderDetail.setBrand(item.getBrand());
|
|
|
766 |
customerOrderDetail.setColor(item.getColor());
|
|
|
767 |
customerOrderDetail.setFofoOrderItemId(foi.getId());
|
|
|
768 |
customerOrderDetail.setFofoOrderId(foi.getOrderId());
|
|
|
769 |
customerOrderDetail.setItemId(foi.getItemId());
|
|
|
770 |
customerOrderDetail.setModelName(item.getModelName());
|
|
|
771 |
customerOrderDetail.setModelNumber(item.getModelNumber());
|
|
|
772 |
customerOrderDetail.setQuantity(foi.getQuantity());
|
|
|
773 |
customerOrderDetail.setTotalPrice(foi.getSellingPrice());
|
|
|
774 |
customerOrderDetail.setCreatedTimeStamp(foi.getCreateTimestamp());
|
|
|
775 |
customerOrderDetail.setInvoiceNumber(fo.getInvoiceNumber());
|
|
|
776 |
customerOrderDetail.setCancelledTimestamp(fo.getCancelledTimestamp());
|
| 33436 |
ranu |
777 |
customerOrderDetail.setInsurancePolicies(insurancePolicyRepository.selectByRetailerIdInvoiceNumber(fo.getInvoiceNumber()));
|
|
|
778 |
customerOrderAndInsuranceDetails.add(customerOrderDetail);
|
| 32018 |
tejbeer |
779 |
}
|
| 33436 |
ranu |
780 |
|
| 32018 |
tejbeer |
781 |
}
|
| 28566 |
tejbeer |
782 |
|
| 32018 |
tejbeer |
783 |
}
|
| 33436 |
ranu |
784 |
return responseSender.ok(customerOrderAndInsuranceDetails);
|
| 32018 |
tejbeer |
785 |
}
|
| 28566 |
tejbeer |
786 |
|
| 32018 |
tejbeer |
787 |
@RequestMapping(value = "/store/generateInvoice", method = RequestMethod.GET)
|
|
|
788 |
public ResponseEntity<?> generateInvoice(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId) throws ProfitMandiBusinessException {
|
|
|
789 |
InvoicePdfModel pdfModel = null;
|
|
|
790 |
FofoOrder fo = fofoOrderRepository.selectByOrderId(orderId);
|
|
|
791 |
pdfModel = orderService.getInvoicePdfModel(fo.getFofoId(), orderId);
|
|
|
792 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
793 |
PdfUtils.generateAndWrite(Arrays.asList(pdfModel), byteArrayOutputStream);
|
|
|
794 |
try {
|
|
|
795 |
byteArrayOutputStream.close();
|
|
|
796 |
} catch (IOException e) {
|
|
|
797 |
// TODO Auto-generated catch block
|
|
|
798 |
e.printStackTrace();
|
|
|
799 |
}
|
|
|
800 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
801 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
|
|
802 |
// headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
|
| 26745 |
amit.gupta |
803 |
|
| 32018 |
tejbeer |
804 |
headers.setContentType(MediaType.parseMediaType("application/pdf"));
|
|
|
805 |
headers.set("Content-disposition", "inline; filename=invoice-" + pdfModel.getInvoiceNumber() + ".pdf");
|
|
|
806 |
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
|
|
|
807 |
headers.add("Pragma", "no-cache");
|
|
|
808 |
headers.add("Expires", "0");
|
| 28287 |
amit.gupta |
809 |
|
| 32018 |
tejbeer |
810 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
811 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
812 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
813 |
return new ResponseEntity<>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
814 |
// return responseSender.ok(new
|
|
|
815 |
// ResponseEntity<byte[]>(byteArrayOutputStream.toByteArray(),
|
|
|
816 |
// headers,HttpStatus.OK));
|
|
|
817 |
/*
|
|
|
818 |
* ResponseEntity<byte[]> response = new
|
|
|
819 |
* ResponseEntity<byte[]>(byteArrayOutputStream.toByteArray(), headers,
|
| 34878 |
vikas |
820 |
* HttpStatus.OK); return response;{
|
| 32018 |
tejbeer |
821 |
*/
|
| 26923 |
amit.gupta |
822 |
|
| 32018 |
tejbeer |
823 |
}
|
| 26607 |
amit.gupta |
824 |
|
| 32018 |
tejbeer |
825 |
@RequestMapping(value = "/store/listing", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
826 |
public ResponseEntity<?> getStoresListing(HttpServletRequest request) throws Exception {
|
|
|
827 |
List<WebListing> webListings = webListingRepository.selectAllWebListingByType(Optional.of(true), WebListingSource.store);
|
|
|
828 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 32546 |
amit.gupta |
829 |
for (WebListing webListing : webListings) {
|
|
|
830 |
webListing.setFofoCatalogResponses(getDealResponses(userInfo, webListing));
|
|
|
831 |
}
|
|
|
832 |
return responseSender.ok(webListings);
|
|
|
833 |
}
|
| 33399 |
ranu |
834 |
|
|
|
835 |
@Autowired
|
|
|
836 |
StateRepository stateRepository;
|
|
|
837 |
|
|
|
838 |
@RequestMapping(value = "/store/stateList", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
839 |
public ResponseEntity<?> getStateList(HttpServletRequest request) throws Exception {
|
|
|
840 |
List<State> states = stateRepository.selectAll();
|
|
|
841 |
return responseSender.ok(states);
|
|
|
842 |
}
|
| 32546 |
amit.gupta |
843 |
/*@RequestMapping(value = "/store/listing", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
844 |
public ResponseEntity<?> getStoresListing(HttpServletRequest request) throws Exception {
|
|
|
845 |
List<WebListing> webListings = webListingRepository.selectAllWebListingByType(Optional.of(true), WebListingSource.store);
|
|
|
846 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
| 32544 |
amit.gupta |
847 |
Iterator<WebListing> webListingIterator = webListings.iterator();
|
|
|
848 |
while (webListingIterator.hasNext()) {
|
|
|
849 |
WebListing webListing = webListingIterator.next();
|
|
|
850 |
List<FofoCatalogResponse> catalogResponses = getDealResponses(userInfo, webListing);
|
|
|
851 |
boolean isAvailable = catalogResponses.stream().anyMatch(x->x.getItems().stream().anyMatch(y->y.getAvailability()>0));
|
| 32545 |
amit.gupta |
852 |
webListing.setFofoCatalogResponses(catalogResponses);
|
| 32544 |
amit.gupta |
853 |
if(!isAvailable) {
|
|
|
854 |
webListings.remove(webListing);
|
|
|
855 |
}
|
| 32018 |
tejbeer |
856 |
}
|
| 32544 |
amit.gupta |
857 |
|
| 32018 |
tejbeer |
858 |
return responseSender.ok(webListings);
|
| 32546 |
amit.gupta |
859 |
}*/
|
| 26607 |
amit.gupta |
860 |
|
| 32018 |
tejbeer |
861 |
private List<FofoCatalogResponse> getDealResponses(UserInfo userInfo, WebListing webListing) throws ProfitMandiBusinessException {
|
|
|
862 |
List<Integer> webProducts = webProductListingRepository.selectAllByWebListingId(webListing.getId()).stream().filter(x -> x.getRank() > 0).map(x -> x.getEntityId()).collect(Collectors.toList());
|
|
|
863 |
if (webProducts.size() == 0) {
|
|
|
864 |
return new ArrayList<>();
|
|
|
865 |
}
|
|
|
866 |
RestClient rc = new RestClient();
|
|
|
867 |
Map<String, String> params = new HashMap<>();
|
|
|
868 |
List<String> mandatoryQ = new ArrayList<>();
|
|
|
869 |
mandatoryQ.add(String.format(
|
| 33599 |
amit.gupta |
870 |
"+{!parent which=\"catalogId_i:(" + StringUtils.join(webProducts, " ") + ")\"} tagId_i:(%s)", StringUtils.join(TAG_IDS, " ")));
|
| 32018 |
tejbeer |
871 |
params.put("q", StringUtils.join(mandatoryQ, " "));
|
|
|
872 |
params.put("fl", "*, [child parentFilter=id:catalog*]");
|
|
|
873 |
// params.put("sort", "create_s desc");
|
|
|
874 |
params.put("start", String.valueOf(0));
|
|
|
875 |
params.put("rows", String.valueOf(100));
|
|
|
876 |
params.put("wt", "json");
|
|
|
877 |
String response = null;
|
|
|
878 |
try {
|
| 33487 |
amit.gupta |
879 |
response = rc.get(SchemeType.HTTP, solrUrl, 8984, "solr/demo/select", params);
|
| 32018 |
tejbeer |
880 |
} catch (HttpHostConnectException e) {
|
|
|
881 |
throw new ProfitMandiBusinessException("", "", "Could not connect to host");
|
|
|
882 |
}
|
|
|
883 |
JSONObject solrResponseJSONObj = new JSONObject(response).getJSONObject("response");
|
|
|
884 |
JSONArray docs = solrResponseJSONObj.getJSONArray("docs");
|
|
|
885 |
List<FofoCatalogResponse> dealResponse = getCatalogResponse(docs, false, userInfo.getRetailerId());
|
|
|
886 |
return dealResponse;
|
|
|
887 |
}
|
| 26607 |
amit.gupta |
888 |
|
| 32018 |
tejbeer |
889 |
@RequestMapping(value = "/store/cart", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
890 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
891 |
@ApiOperation(value = "Get brand list and count for category")
|
|
|
892 |
public ResponseEntity<?> cart(HttpServletRequest request, @RequestBody AddCartRequest cartRequest) throws Exception {
|
|
|
893 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
894 |
Integer storeId = userInfo.getRetailerId();
|
|
|
895 |
ValidateCartResponse vc = new ValidateCartResponse(this.validateCart(storeId, cartRequest.getCartItems()), "Success", "Items added to cart successfully");
|
|
|
896 |
return responseSender.ok(vc);
|
|
|
897 |
}
|
| 26607 |
amit.gupta |
898 |
|
| 32018 |
tejbeer |
899 |
// Validate Cart for B2C Customers
|
|
|
900 |
private CartResponse validateCart(int storeId, List<CartItem> cartItems) throws Exception {
|
| 33436 |
ranu |
901 |
|
| 33573 |
amit.gupta |
902 |
logger.info("cartItems {}", cartItems);
|
| 32018 |
tejbeer |
903 |
cartItems = cartItems.stream().filter(x -> x.getQuantity() > 0).collect(Collectors.toList());
|
|
|
904 |
List<Integer> itemIds = cartItems.stream().map(x -> x.getItemId()).collect(Collectors.toList());
|
|
|
905 |
Map<Integer, AvailabilityModel> inventoryItemAvailabilityMap = inventoryService.getStoreAndOurStock(storeId, itemIds);
|
|
|
906 |
CartResponse cartResponse = new CartResponse();
|
|
|
907 |
List<CartItemResponseModel> cartItemResponseModels = new ArrayList<>();
|
|
|
908 |
cartResponse.setCartItems(cartItemResponseModels);
|
|
|
909 |
Set<Integer> itemsIdsSet = new HashSet<>(itemIds);
|
|
|
910 |
logger.info("Store Id {}, Item Ids {}", storeId, itemsIdsSet);
|
| 26607 |
amit.gupta |
911 |
|
| 32018 |
tejbeer |
912 |
Map<Integer, Item> itemsMap = itemRepository.selectByIds(itemsIdsSet).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 26652 |
amit.gupta |
913 |
|
| 32018 |
tejbeer |
914 |
Map<Integer, TagListing> tagListingMap = tagListingRepository.selectByItemIdsAndTagIds(new HashSet<>(itemIds), new HashSet<>(Arrays.asList(4))).stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
| 26923 |
amit.gupta |
915 |
|
| 32018 |
tejbeer |
916 |
List<Integer> catalogIds = itemsMap.values().stream().map(x -> x.getCatalogItemId()).collect(Collectors.toList());
|
| 26607 |
amit.gupta |
917 |
|
| 32018 |
tejbeer |
918 |
Map<Integer, JSONObject> contentMap = commonSolrService.getContentByCatalogIds(catalogIds);
|
| 27030 |
amit.gupta |
919 |
|
| 32018 |
tejbeer |
920 |
// cartResponse.getCartItems()
|
|
|
921 |
int cartMessageChanged = 0;
|
|
|
922 |
int cartMessageOOS = 0;
|
|
|
923 |
int totalAmount = 0;
|
|
|
924 |
int totalQty = 0;
|
| 34186 |
vikas.jang |
925 |
List<CartMessage> itemMessages = new ArrayList<>();
|
| 32018 |
tejbeer |
926 |
for (CartItem cartItem : cartItems) {
|
|
|
927 |
Item item = itemsMap.get(cartItem.getItemId());
|
| 34186 |
vikas.jang |
928 |
CartMessage itemMsg = new CartMessage();
|
| 32018 |
tejbeer |
929 |
TagListing tagListing = tagListingMap.get(cartItem.getItemId());
|
| 32977 |
amit.gupta |
930 |
int catalogId = itemsMap.get(cartItem.getItemId()).getCatalogItemId();
|
|
|
931 |
Float cashback = schemeService.getCatalogSchemeCashBack(storeId, Arrays.asList(catalogId))
|
|
|
932 |
.get(itemsMap.get(cartItem.getItemId()).getCatalogItemId());
|
| 32018 |
tejbeer |
933 |
cashback = cashback == null ? 0 : cashback;
|
|
|
934 |
float itemSellingPrice = tagListing.getMop() - cashback;
|
|
|
935 |
CartItemResponseModel cartItemResponseModel = new CartItemResponseModel();
|
|
|
936 |
cartItemResponseModel.setSellingPrice(cartItem.getSellingPrice());
|
| 33436 |
ranu |
937 |
cartItemResponseModel.setPendingOrderItemPolicyPlan(cartItem.getPendingOrderItemPolicyPlan());
|
| 34259 |
aman.kumar |
938 |
logger.info("itemSellingPrice: {}", itemSellingPrice);
|
|
|
939 |
logger.info("cartItem: {}", cartItem.getSellingPrice());
|
|
|
940 |
logger.info("cashback: {}", cashback);
|
| 32018 |
tejbeer |
941 |
if (itemSellingPrice != cartItem.getSellingPrice()) {
|
| 34186 |
vikas.jang |
942 |
itemMsg.setType("price");
|
| 34259 |
aman.kumar |
943 |
itemMsg.setMessageText("Price has changed to " + itemSellingPrice);
|
| 32018 |
tejbeer |
944 |
cartItemResponseModel.setSellingPrice(itemSellingPrice);
|
|
|
945 |
cartMessageChanged++;
|
|
|
946 |
}
|
|
|
947 |
int estimate = -2;
|
|
|
948 |
LocalDateTime promiseDeliveryTime = LocalDateTime.now();
|
|
|
949 |
int qtyRequired = (int) cartItem.getQuantity();
|
|
|
950 |
AvailabilityModel availabilityModel = inventoryItemAvailabilityMap.get(cartItem.getItemId());
|
|
|
951 |
cartItemResponseModel.setMaxQuantity(availabilityModel.getMaxAvailability());
|
|
|
952 |
if (availabilityModel.getStoreAvailability() >= qtyRequired) {
|
| 34239 |
vikas.jang |
953 |
itemMsg.setType("estimate0");
|
| 34259 |
aman.kumar |
954 |
itemMsg.setMessageText("Store availability is " + availabilityModel.getStoreAvailability());
|
| 32018 |
tejbeer |
955 |
estimate = 0;
|
|
|
956 |
} else if (availabilityModel.getWarehouseAvailability() >= qtyRequired) {
|
| 34239 |
vikas.jang |
957 |
itemMsg.setType("estimate2");
|
| 34259 |
aman.kumar |
958 |
itemMsg.setMessageText("Store availability is " + availabilityModel.getWarehouseAvailability());
|
| 32018 |
tejbeer |
959 |
estimate = 2;
|
|
|
960 |
} else if (availabilityModel.getStoreAvailability() > 0) {
|
|
|
961 |
estimate = 0;
|
|
|
962 |
qtyRequired = availabilityModel.getStoreAvailability();
|
|
|
963 |
cartMessageChanged++;
|
| 34186 |
vikas.jang |
964 |
itemMsg.setType("quantity0");
|
| 34259 |
aman.kumar |
965 |
itemMsg.setMessageText("quantity is updated " + qtyRequired);
|
| 32018 |
tejbeer |
966 |
} else if (availabilityModel.getWarehouseAvailability() > 0) {
|
|
|
967 |
qtyRequired = availabilityModel.getWarehouseAvailability();
|
|
|
968 |
estimate = 2;
|
|
|
969 |
cartMessageChanged++;
|
| 34186 |
vikas.jang |
970 |
itemMsg.setType("quantity2");
|
| 34259 |
aman.kumar |
971 |
itemMsg.setMessageText("quantity is updated " + qtyRequired);
|
| 32018 |
tejbeer |
972 |
} else {
|
|
|
973 |
qtyRequired = 0;
|
|
|
974 |
cartMessageChanged++;
|
| 34186 |
vikas.jang |
975 |
itemMsg.setType("item");
|
|
|
976 |
itemMsg.setMessageText(item.getItemDescriptionNoColor() + " is out of stock");
|
| 32018 |
tejbeer |
977 |
}
|
|
|
978 |
cartItemResponseModel.setQuantity(qtyRequired);
|
|
|
979 |
if (estimate >= 0 && LocalTime.now().isAfter(CUTOFF_TIME)) {
|
|
|
980 |
estimate = estimate + 1;
|
|
|
981 |
promiseDeliveryTime = promiseDeliveryTime.plusDays(3);
|
|
|
982 |
}
|
|
|
983 |
totalQty += qtyRequired;
|
| 33573 |
amit.gupta |
984 |
if (cartItem.getPendingOrderItemPolicyPlan() != null) {
|
|
|
985 |
totalAmount += qtyRequired * itemSellingPrice + qtyRequired * cartItem.getPendingOrderItemPolicyPlan().getPrice();
|
|
|
986 |
} else {
|
| 33436 |
ranu |
987 |
totalAmount += qtyRequired * itemSellingPrice;
|
|
|
988 |
}
|
|
|
989 |
|
| 32018 |
tejbeer |
990 |
cartItemResponseModel.setEstimate(estimate);
|
|
|
991 |
cartItemResponseModel.setTitle(item.getItemDescriptionNoColor());
|
|
|
992 |
cartItemResponseModel.setItemId(cartItem.getItemId());
|
|
|
993 |
cartItemResponseModel.setMinBuyQuantity(1);
|
|
|
994 |
cartItemResponseModel.setQuantity(qtyRequired);
|
| 34884 |
vikas |
995 |
cartItemResponseModel.setCategoryId(item.getCategoryId());
|
|
|
996 |
cartItemResponseModel.setSmartSellerId(cartItem.getSmartSellerId());
|
| 32018 |
tejbeer |
997 |
cartItemResponseModel.setQuantityStep(1);
|
|
|
998 |
cartItemResponseModel.setPromiseDelivery(promiseDeliveryTime);
|
|
|
999 |
cartItemResponseModel.setMaxQuantity(availabilityModel.getMaxAvailability());
|
|
|
1000 |
cartItemResponseModel.setCatalogItemId(item.getCatalogItemId());
|
|
|
1001 |
cartItemResponseModel.setImageUrl(contentMap.get(item.getCatalogItemId()).getString("imageUrl_s"));
|
|
|
1002 |
cartItemResponseModel.setColor(item.getColor());
|
|
|
1003 |
cartItemResponseModels.add(cartItemResponseModel);
|
| 34186 |
vikas.jang |
1004 |
itemMessages.add(itemMsg);
|
| 32018 |
tejbeer |
1005 |
}
|
|
|
1006 |
cartResponse.setCartItems(cartItemResponseModels);
|
| 34186 |
vikas.jang |
1007 |
cartResponse.setCartMessages(itemMessages);
|
| 32018 |
tejbeer |
1008 |
cartResponse.setCartMessageChanged(cartMessageChanged);
|
|
|
1009 |
cartResponse.setCartMessageOOS(cartMessageOOS);
|
|
|
1010 |
int maxEstimate = cartItemResponseModels.stream().mapToInt(x -> x.getEstimate()).max().getAsInt();
|
|
|
1011 |
cartResponse.setMaxEstimate(maxEstimate);
|
|
|
1012 |
cartResponse.setTotalAmount(totalAmount);
|
|
|
1013 |
cartResponse.setTotalQty(totalQty);
|
| 26607 |
amit.gupta |
1014 |
|
| 32018 |
tejbeer |
1015 |
return cartResponse;
|
| 26923 |
amit.gupta |
1016 |
|
| 32018 |
tejbeer |
1017 |
}
|
| 27069 |
tejbeer |
1018 |
|
| 32018 |
tejbeer |
1019 |
@RequestMapping(value = "/store/partnerStock", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 33573 |
amit.gupta |
1020 |
public ResponseEntity<?> partnerStock(HttpServletRequest request, @RequestParam(required = false, defaultValue = "3") String categoryId, @RequestParam int offset,
|
| 34444 |
vikas.jang |
1021 |
@RequestParam int limit, @RequestParam(required = false) String sort, @RequestParam(required = false) String brand,
|
|
|
1022 |
@RequestParam(value = "subCategoryId", required = false) int subCategoryId, @RequestParam(required = false) String queryTerm,
|
|
|
1023 |
@RequestParam(required = false) String listing, @RequestParam(required = false, defaultValue = "true") boolean partnerStockOnly) throws Throwable {
|
| 32018 |
tejbeer |
1024 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
|
|
1025 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
1026 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(userInfo.getRetailerId());
|
|
|
1027 |
sort = "w" + fs.getWarehouseId() + "_i desc";
|
|
|
1028 |
dealResponse = this.getCatalogResponse(
|
| 34024 |
vikas.jang |
1029 |
commonSolrService.getSolrDocs(queryTerm, categoryId, offset, limit, sort, brand, subCategoryId, false, false), false, userInfo.getRetailerId());
|
| 32018 |
tejbeer |
1030 |
return responseSender.ok(dealResponse);
|
|
|
1031 |
}
|
| 26923 |
amit.gupta |
1032 |
|
| 32018 |
tejbeer |
1033 |
private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal, int fofoId) throws ProfitMandiBusinessException {
|
|
|
1034 |
Map<Integer, Integer> ourItemAvailabilityMap = null;
|
|
|
1035 |
Map<Integer, Integer> partnerStockAvailabilityMap = null;
|
|
|
1036 |
List<FofoCatalogResponse> dealResponse = new ArrayList<>();
|
|
|
1037 |
List<Integer> tagIds = Arrays.asList(4);
|
|
|
1038 |
if (docs.length() > 0) {
|
|
|
1039 |
HashSet<Integer> itemsSet = new HashSet<>();
|
|
|
1040 |
for (int i = 0; i < docs.length(); i++) {
|
|
|
1041 |
JSONObject doc = docs.getJSONObject(i);
|
|
|
1042 |
if (doc.has("_childDocuments_")) {
|
|
|
1043 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
|
|
1044 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
|
|
1045 |
int itemId = childItem.getInt("itemId_i");
|
|
|
1046 |
itemsSet.add(itemId);
|
|
|
1047 |
}
|
|
|
1048 |
}
|
|
|
1049 |
}
|
|
|
1050 |
if (itemsSet.size() == 0) {
|
|
|
1051 |
return dealResponse;
|
|
|
1052 |
}
|
|
|
1053 |
if (fofoId > 0) {
|
|
|
1054 |
partnerStockAvailabilityMap = currentInventorySnapshotRepository.selectItemsStock(fofoId).stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getAvailability()));
|
|
|
1055 |
}
|
|
|
1056 |
ourItemAvailabilityMap = saholicInventoryService.getTotalAvailabilityByItemIds(new ArrayList<>(itemsSet));
|
|
|
1057 |
}
|
| 26833 |
amit.gupta |
1058 |
|
| 32018 |
tejbeer |
1059 |
for (int i = 0; i < docs.length(); i++) {
|
|
|
1060 |
Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
|
|
|
1061 |
JSONObject doc = docs.getJSONObject(i);
|
|
|
1062 |
FofoCatalogResponse ffdr = new FofoCatalogResponse();
|
|
|
1063 |
ffdr.setCatalogId(doc.getInt("catalogId_i"));
|
|
|
1064 |
ffdr.setImageUrl(doc.getString("imageUrl_s"));
|
|
|
1065 |
ffdr.setTitle(doc.getString("title_s"));
|
| 34239 |
vikas.jang |
1066 |
ffdr.setSuperCatalogTitle(doc.getString("superCatalog_s"));
|
|
|
1067 |
ffdr.setSuperCatalogId(doc.getInt("superCatalog_i"));
|
|
|
1068 |
ffdr.setSuperCatalogVariants(doc.getString("superCatalogVariants_s"));
|
| 32018 |
tejbeer |
1069 |
List<WebOffer> webOffers = webOfferRepository.selectAllActiveOffers().get(ffdr.getCatalogId());
|
|
|
1070 |
if (webOffers != null && webOffers.size() > 0) {
|
|
|
1071 |
ffdr.setOffers(webOffers.stream().map(x -> x.getTitle()).collect(Collectors.toList()));
|
|
|
1072 |
}
|
|
|
1073 |
try {
|
|
|
1074 |
ffdr.setFeature(doc.getString("feature_s"));
|
|
|
1075 |
} catch (Exception e) {
|
|
|
1076 |
ffdr.setFeature(null);
|
|
|
1077 |
}
|
|
|
1078 |
ffdr.setBrand(doc.getJSONArray("brand_ss").getString(0));
|
| 33314 |
ranu |
1079 |
|
| 32018 |
tejbeer |
1080 |
if (doc.has("_childDocuments_")) {
|
|
|
1081 |
for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
|
|
|
1082 |
JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
|
|
|
1083 |
int itemId = childItem.getInt("itemId_i");
|
| 33314 |
ranu |
1084 |
ffdr.setIsSmartPhone(itemRepository.selectById(itemId).isSmartPhone());
|
| 32018 |
tejbeer |
1085 |
float sellingPrice = (float) childItem.getDouble("sellingPrice_f");
|
|
|
1086 |
if (fofoAvailabilityInfoMap.containsKey(itemId)) {
|
|
|
1087 |
if (fofoAvailabilityInfoMap.get(itemId).getSellingPrice() > sellingPrice) {
|
|
|
1088 |
fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
|
|
|
1089 |
fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
|
|
|
1090 |
}
|
|
|
1091 |
} else {
|
|
|
1092 |
FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
|
|
|
1093 |
fdi.setSellingPrice(sellingPrice);
|
|
|
1094 |
fdi.setMrp(childItem.getDouble("mrp_f"));
|
|
|
1095 |
fdi.setMop((float) childItem.getDouble("mop_f"));
|
|
|
1096 |
fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
|
|
|
1097 |
fdi.setTagId(childItem.getInt("tagId_i"));
|
|
|
1098 |
fdi.setItem_id(itemId);
|
| 34196 |
ranu |
1099 |
fdi.setCatalog_id(doc.getInt("catalogId_i"));
|
| 32977 |
amit.gupta |
1100 |
Float cashBack = schemeService.getCatalogSchemeCashBack(fofoId, Arrays.asList(ffdr.getCatalogId())).get(ffdr.getCatalogId());
|
| 32018 |
tejbeer |
1101 |
cashBack = cashBack == null ? 0 : cashBack;
|
|
|
1102 |
// TODO:Dont commit
|
|
|
1103 |
// fdi.setCashback(Math.min(100, fdi.getMop()));
|
|
|
1104 |
fdi.setCashback(cashBack);
|
|
|
1105 |
fdi.setMinBuyQuantity(1);
|
|
|
1106 |
int partnerAvailability = partnerStockAvailabilityMap.get(itemId) == null ? 0 : partnerStockAvailabilityMap.get(itemId);
|
|
|
1107 |
int ourStockAvailability = ourItemAvailabilityMap.get(itemId) == null ? 0 : Math.max(0, ourItemAvailabilityMap.get(itemId));
|
|
|
1108 |
fdi.setActive(partnerAvailability > 0);
|
|
|
1109 |
// fdi.setActive(true);
|
| 34239 |
vikas.jang |
1110 |
fdi.setPartnerAvailability(partnerAvailability);
|
| 32018 |
tejbeer |
1111 |
fdi.setAvailability(Math.min(5, ourStockAvailability + partnerAvailability));
|
|
|
1112 |
fdi.setQuantityStep(1);
|
|
|
1113 |
fdi.setMaxQuantity(fdi.getAvailability());
|
|
|
1114 |
fofoAvailabilityInfoMap.put(itemId, fdi);
|
|
|
1115 |
}
|
|
|
1116 |
}
|
|
|
1117 |
}
|
|
|
1118 |
if (fofoAvailabilityInfoMap.values().size() > 0) {
|
|
|
1119 |
ffdr.setItems(fofoAvailabilityInfoMap.values().stream().sorted(Comparator.comparing(FofoAvailabilityInfo::isActive, Comparator.reverseOrder()).thenComparingInt(y -> -y.getAvailability())).collect(Collectors.toList()));
|
|
|
1120 |
dealResponse.add(ffdr);
|
|
|
1121 |
}
|
|
|
1122 |
}
|
|
|
1123 |
return dealResponse.stream().sorted(Comparator.comparing(FofoCatalogResponse::getItems, (s1, s2) -> (s2.get(0).isActive() ? 1 : 0) - (s1.get(0).isActive() ? 1 : 0)).thenComparing(FofoCatalogResponse::getItems, (x, y) -> y.get(0).getAvailability() - x.get(0).getAvailability())).collect(Collectors.toList());
|
|
|
1124 |
}
|
| 26857 |
amit.gupta |
1125 |
|
| 32018 |
tejbeer |
1126 |
@GetMapping(value = "store/order-status/{pendingOrderId}")
|
|
|
1127 |
public ResponseEntity<?> orderStatus(HttpServletRequest request, @PathVariable int pendingOrderId) throws Exception {
|
|
|
1128 |
PendingOrder pendingOrder = pendingOrderRepository.selectById(pendingOrderId);
|
|
|
1129 |
List<PendingOrderItem> pendingOrderItems = pendingOrderItemRepository.selectByOrderId(pendingOrder.getId());
|
|
|
1130 |
List<Integer> catalogIds = new ArrayList<>();
|
|
|
1131 |
for (PendingOrderItem pendingOrderItem : pendingOrderItems) {
|
| 34477 |
aman.kumar |
1132 |
//TODO : Amit feedback use poItemId instead of poId change Param name
|
|
|
1133 |
// when list is supposed then use method names as selectAllBy instead selectBy of
|
|
|
1134 |
//check for unique constraint
|
|
|
1135 |
List<PendingOrderPlan> policyPlans = pendingOrderPlanRepository.selectByPoId(pendingOrderItem.getId());
|
|
|
1136 |
pendingOrderItem.setPendingOrderItemPolicyPlan(policyPlans);
|
| 32018 |
tejbeer |
1137 |
Item item = itemRepository.selectById(pendingOrderItem.getItemId());
|
|
|
1138 |
pendingOrderItem.setItemName(item.getItemDescription());
|
| 34186 |
vikas.jang |
1139 |
pendingOrderItem.setCatalogId(item.getCatalogItemId());
|
| 32018 |
tejbeer |
1140 |
catalogIds.add(item.getCatalogItemId());
|
|
|
1141 |
}
|
|
|
1142 |
Map<Integer, JSONObject> contentMap = commonSolrService.getContentByCatalogIds(catalogIds);
|
|
|
1143 |
for (PendingOrderItem pendingOrderItem : pendingOrderItems) {
|
|
|
1144 |
Item item = itemRepository.selectById(pendingOrderItem.getItemId());
|
|
|
1145 |
JSONObject jsonObj = contentMap.get(item.getCatalogItemId());
|
|
|
1146 |
pendingOrderItem.setImgUrl(jsonObj.getString("imageUrl_s"));
|
|
|
1147 |
}
|
|
|
1148 |
pendingOrder.setPendingOrderItems(pendingOrderItems);
|
| 27045 |
tejbeer |
1149 |
|
| 32018 |
tejbeer |
1150 |
return responseSender.ok(pendingOrder);
|
|
|
1151 |
}
|
| 28345 |
tejbeer |
1152 |
|
| 32018 |
tejbeer |
1153 |
@RequestMapping(value = "/store/addresses/{customerId}", method = RequestMethod.GET)
|
|
|
1154 |
public ResponseEntity<?> getAll(HttpServletRequest request, @PathVariable int customerId) throws Throwable {
|
|
|
1155 |
return responseSender.ok(customerAddressRepository.selectByActiveCustomerId(customerId));
|
|
|
1156 |
}
|
| 26861 |
tejbeer |
1157 |
|
| 32018 |
tejbeer |
1158 |
@RequestMapping(value = "/store/address", method = RequestMethod.POST)
|
|
|
1159 |
public ResponseEntity<?> addAddress(HttpServletRequest request, @RequestBody CustomerAddress customerAddress) throws Throwable {
|
| 34259 |
aman.kumar |
1160 |
List<CustomerAddress> customerAddresses = customerAddressRepository.selectByActiveCustomerId(customerAddress.getCustomerId());
|
|
|
1161 |
if (customerAddresses.isEmpty()) {
|
|
|
1162 |
customerAddress.setDefault(true);
|
|
|
1163 |
} else {
|
|
|
1164 |
customerAddress.setDefault(false);
|
|
|
1165 |
}
|
| 32018 |
tejbeer |
1166 |
customerAddressRepository.persist(customerAddress);
|
|
|
1167 |
return responseSender.ok(customerAddress);
|
|
|
1168 |
}
|
| 27045 |
tejbeer |
1169 |
|
| 32018 |
tejbeer |
1170 |
@RequestMapping(value = "/store/deactivateCustomerAddress", method = RequestMethod.POST)
|
|
|
1171 |
public ResponseEntity<?> deactivateAddresss(HttpServletRequest request, @RequestParam int id) throws Throwable {
|
|
|
1172 |
CustomerAddress cust = customerAddressRepository.selectById(id);
|
| 34259 |
aman.kumar |
1173 |
List<CustomerAddress> customerAddresses = customerAddressRepository.selectByCustomerId(cust.getCustomerId());
|
| 32018 |
tejbeer |
1174 |
cust.setActive(false);
|
| 34259 |
aman.kumar |
1175 |
if(cust.getDefault()){
|
|
|
1176 |
List<CustomerAddress> activeAddresses = customerAddresses.stream()
|
|
|
1177 |
.filter(a -> a.getActive() && a.getId() != id)
|
|
|
1178 |
.sorted(Comparator.comparing(CustomerAddress::getUpdateTimestamp).reversed())
|
|
|
1179 |
.collect(Collectors.toList());
|
|
|
1180 |
|
|
|
1181 |
if (!activeAddresses.isEmpty()) {
|
|
|
1182 |
CustomerAddress newDefault = activeAddresses.get(0);
|
|
|
1183 |
newDefault.setDefault(true);
|
|
|
1184 |
}
|
|
|
1185 |
}
|
| 32018 |
tejbeer |
1186 |
return responseSender.ok(cust);
|
|
|
1187 |
}
|
| 27048 |
tejbeer |
1188 |
|
| 32018 |
tejbeer |
1189 |
@RequestMapping(value = "/store/updateCustomer", method = RequestMethod.POST)
|
|
|
1190 |
public ResponseEntity<?> updateCustomerProfile(HttpServletRequest request, @RequestBody Customer customer) throws Throwable {
|
|
|
1191 |
Customer cust = customerRepository.selectById(customer.getId());
|
|
|
1192 |
cust.setGender(customer.getGender());
|
|
|
1193 |
cust.setProfileImageId(customer.getProfileImageId());
|
| 34186 |
vikas.jang |
1194 |
cust.setEmailId(customer.getEmailId());
|
| 32018 |
tejbeer |
1195 |
cust.setDob(customer.getDob());
|
|
|
1196 |
return responseSender.ok(cust);
|
|
|
1197 |
}
|
| 27048 |
tejbeer |
1198 |
|
| 32018 |
tejbeer |
1199 |
@RequestMapping(value = "/stores/{state}/{city}/{storeCode}", method = RequestMethod.GET)
|
|
|
1200 |
public void getStoreIndex(HttpServletResponse response, HttpServletRequest request, @PathVariable String state, @PathVariable String city, @PathVariable String storeCode) throws Throwable {
|
|
|
1201 |
logger.info("Store code {}", storeCode);
|
|
|
1202 |
Map<String, Integer> map = retailerService.getStoreCodeRetailerMap();
|
|
|
1203 |
logger.info("retailer id {}", map.get(storeCode));
|
|
|
1204 |
String retailerName = retailerService.getAllFofoRetailers().get(map.get(storeCode)).getBusinessName();
|
|
|
1205 |
String html = partnerIndexService.getPartnerIndexHtml();
|
|
|
1206 |
logger.info("html {}", html);
|
|
|
1207 |
html = html.replace("Buy Mobiles and Accessories at exciting prices - SmartDukaan", String.format("%s is now ONLINE. Buy Mobiles, Accessories & more | SmartDukaan", retailerName));
|
|
|
1208 |
response.getWriter().write(html);
|
|
|
1209 |
}
|
| 27048 |
tejbeer |
1210 |
|
| 32018 |
tejbeer |
1211 |
@RequestMapping(value = "/cancelPendingOrderItem", method = RequestMethod.POST)
|
| 34186 |
vikas.jang |
1212 |
public ResponseEntity<?> cancelPendingOrderItem(HttpServletRequest request, @RequestParam int id, @RequestParam String statusDescription, @RequestParam String reason) throws Exception {
|
| 28339 |
tejbeer |
1213 |
|
| 32018 |
tejbeer |
1214 |
PendingOrderItem pendingOrderItem = pendingOrderItemRepository.selectById(id);
|
|
|
1215 |
PendingOrder pendingOrder = pendingOrderRepository.selectById(pendingOrderItem.getOrderId());
|
|
|
1216 |
Customer customer = customerRepository.selectById(pendingOrder.getCustomerId());
|
|
|
1217 |
if (pendingOrderItem.getBilledTimestamp() == null) {
|
|
|
1218 |
pendingOrderItem.setStatus(OrderStatus.CANCELLED);
|
|
|
1219 |
pendingOrderItem.setRemark(reason);
|
|
|
1220 |
pendingOrderItem.setStatusDescription("cancel by self");
|
|
|
1221 |
pendingOrderItem.setCancelledTimestamp(LocalDateTime.now());
|
|
|
1222 |
List<OrderStatus> status = pendingOrderItemRepository.selectByOrderId(pendingOrderItem.getOrderId()).stream().map(x -> x.getStatus()).collect(Collectors.toList());
|
| 28339 |
tejbeer |
1223 |
|
| 32018 |
tejbeer |
1224 |
if (!status.contains(OrderStatus.PENDING) && !status.contains(OrderStatus.PROCESSING) && !status.contains(OrderStatus.BILLED) && !status.contains(OrderStatus.UNSETTLED) && !status.contains(OrderStatus.CLAIMED)) {
|
|
|
1225 |
pendingOrder.setStatus(OrderStatus.CLOSED);
|
|
|
1226 |
}
|
| 28339 |
tejbeer |
1227 |
|
| 32018 |
tejbeer |
1228 |
pendingOrderItemRepository.persist(pendingOrderItem);
|
|
|
1229 |
String itemDescription = itemRepository.selectById(pendingOrderItem.getItemId()).getItemDescription();
|
|
|
1230 |
otpProcessor.sendSms(OtpProcessor.SELF_CANCELLED_TEMPLATE_ID, String.format(OtpProcessor.SELF_CANCELLED_TEMPLATE, pendingOrder.getId(), StringUtils.abbreviate(itemDescription, 30), FormattingUtils.format(pendingOrderItem.getCancelledTimestamp())), customer.getMobileNumber());
|
| 28339 |
tejbeer |
1231 |
|
| 32018 |
tejbeer |
1232 |
List<Integer> catalogIds = new ArrayList<>();
|
| 28339 |
tejbeer |
1233 |
|
| 32018 |
tejbeer |
1234 |
Item item = itemRepository.selectById(pendingOrderItem.getItemId());
|
|
|
1235 |
pendingOrderItem.setItemName(item.getItemDescription());
|
|
|
1236 |
catalogIds.add(item.getCatalogItemId());
|
| 28339 |
tejbeer |
1237 |
|
| 32018 |
tejbeer |
1238 |
Map<Integer, JSONObject> contentMap = commonSolrService.getContentByCatalogIds(catalogIds);
|
|
|
1239 |
JSONObject jsonObj = contentMap.get(item.getCatalogItemId());
|
|
|
1240 |
pendingOrderItem.setImgUrl(jsonObj.getString("imageUrl_s"));
|
|
|
1241 |
pendingOrder.setPendingOrderItems(Arrays.asList(pendingOrderItem));
|
|
|
1242 |
CustomerAddress customerAddress = customerAddressRepository.selectById(pendingOrder.getCustomerAddressId());
|
| 28355 |
tejbeer |
1243 |
|
| 32018 |
tejbeer |
1244 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy h:mm a");
|
| 28339 |
tejbeer |
1245 |
|
| 32018 |
tejbeer |
1246 |
Map<String, Object> emailModel = new HashMap<>();
|
|
|
1247 |
emailModel.put("customer", customerAddress);
|
|
|
1248 |
emailModel.put("pendingOrder", pendingOrder);
|
|
|
1249 |
emailModel.put("date", dateTimeFormatter);
|
| 27048 |
tejbeer |
1250 |
|
| 32018 |
tejbeer |
1251 |
String[] customerEmail = null;
|
|
|
1252 |
if (customer.getEmailId() != null) {
|
|
|
1253 |
customerEmail = new String[]{customer.getEmailId()};
|
| 27048 |
tejbeer |
1254 |
|
| 34186 |
vikas.jang |
1255 |
List<String> bccTo = Arrays.asList("vikas.jangra@smartdukaan.com");
|
| 29515 |
tejbeer |
1256 |
|
| 32018 |
tejbeer |
1257 |
emailService.sendMailWithAttachments("Order Cancellation", "order-cancellation.vm", emailModel, customerEmail, null, bccTo.toArray(new String[0]));
|
| 29515 |
tejbeer |
1258 |
|
| 32018 |
tejbeer |
1259 |
}
|
|
|
1260 |
}
|
| 29515 |
tejbeer |
1261 |
|
| 32018 |
tejbeer |
1262 |
return responseSender.ok(true);
|
| 29515 |
tejbeer |
1263 |
|
| 32018 |
tejbeer |
1264 |
}
|
| 31444 |
tejbeer |
1265 |
|
| 32018 |
tejbeer |
1266 |
@RequestMapping(value = "/store/checkEligibilityStoreOffers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1267 |
public ResponseEntity<?> checkEligibilityStoreOffers(HttpServletRequest request, @RequestParam(value = "id") int id) throws Exception {
|
| 29515 |
tejbeer |
1268 |
|
| 32018 |
tejbeer |
1269 |
boolean eligibility = false;
|
| 29515 |
tejbeer |
1270 |
|
| 34186 |
vikas.jang |
1271 |
List<ScratchOffer> scratchOffers = scratchOfferRepository.selectBycCustomerIdAndDate(id, ProfitMandiConstants.SCRATCH_OFFER_START_DATE, ProfitMandiConstants.SCRATCH_OFFER_END_DATE);
|
| 29515 |
tejbeer |
1272 |
|
| 32018 |
tejbeer |
1273 |
if (!scratchOffers.isEmpty()) {
|
|
|
1274 |
eligibility = true;
|
| 31457 |
tejbeer |
1275 |
|
| 32018 |
tejbeer |
1276 |
}
|
|
|
1277 |
return responseSender.ok(eligibility);
|
|
|
1278 |
}
|
| 29515 |
tejbeer |
1279 |
|
| 32018 |
tejbeer |
1280 |
@RequestMapping(value = "/store/ScratchOffers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1281 |
public ResponseEntity<?> scratchOffers(HttpServletRequest request, @RequestParam(value = "id") int id) throws Exception {
|
| 29515 |
tejbeer |
1282 |
|
| 34186 |
vikas.jang |
1283 |
List<ScratchOffer> scratchOffers = scratchOfferRepository.selectBycCustomerIdAndDate(id, ProfitMandiConstants.SCRATCH_OFFER_START_DATE, ProfitMandiConstants.SCRATCH_OFFER_END_DATE);
|
| 29515 |
tejbeer |
1284 |
|
| 32218 |
tejbeer |
1285 |
logger.info("scratchOffers {}", scratchOffers);
|
| 32018 |
tejbeer |
1286 |
// List<ScratchOffer> scratchOffers =
|
|
|
1287 |
// scratchOfferRepository.selectBycCustomerId(id);
|
|
|
1288 |
for (ScratchOffer so : scratchOffers) {
|
|
|
1289 |
if (LocalDateTime.now().isAfter(so.getUnlockedAt())) {
|
|
|
1290 |
so.setUnlocked(true);
|
|
|
1291 |
} else {
|
|
|
1292 |
so.setUnlocked(false);
|
|
|
1293 |
}
|
| 34371 |
ranu |
1294 |
LocalDateTime expiredTimestamp = ProfitMandiConstants.SCRATCH_OFFER_END_DATE.plusDays(0).atTime(LocalTime.MAX);
|
| 32671 |
ranu |
1295 |
so.setExpiredTimestamp(expiredTimestamp);
|
| 33573 |
amit.gupta |
1296 |
if (LocalDateTime.now().isAfter(expiredTimestamp)) {
|
| 32671 |
ranu |
1297 |
so.setExpired(true);
|
|
|
1298 |
}
|
| 32018 |
tejbeer |
1299 |
}
|
| 29515 |
tejbeer |
1300 |
|
| 32018 |
tejbeer |
1301 |
return responseSender.ok(scratchOffers);
|
|
|
1302 |
}
|
|
|
1303 |
|
|
|
1304 |
@RequestMapping(value = "/store/ScratchedOffer", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1305 |
public ResponseEntity<?> scratchedOffer(HttpServletRequest request, @RequestParam(value = "id") int id) throws Exception {
|
|
|
1306 |
|
|
|
1307 |
ScratchOffer scratchOffer = scratchOfferRepository.selectById(id);
|
|
|
1308 |
scratchOffer.setScratched(true);
|
|
|
1309 |
scratchOffer.setScracthedAt(LocalDateTime.now());
|
|
|
1310 |
|
|
|
1311 |
return responseSender.ok(true);
|
|
|
1312 |
}
|
|
|
1313 |
|
| 34242 |
tejus.loha |
1314 |
@RequestMapping(value = "/store/navbar", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1315 |
public ResponseEntity<?> navBars() throws Exception {
|
|
|
1316 |
List<NavBar> navBars = navBarRepository.selectAllActive();
|
|
|
1317 |
return responseSender.ok(navBars);
|
|
|
1318 |
}
|
|
|
1319 |
|
| 34444 |
vikas.jang |
1320 |
@RequestMapping(value = "/store/clearance", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1321 |
public ResponseEntity<?> getLiquidations() throws Exception {
|
|
|
1322 |
List<Integer> catalogIds = new ArrayList<>();
|
|
|
1323 |
Map<Integer, JSONObject> contentMap = null;
|
| 34545 |
vikas.jang |
1324 |
List<Liquidation> liquidations = liquidationRepository.selectAllByStatus(ProfitMandiConstants.LIQUIDATION_ENUM.PUBLISHED);
|
| 34242 |
tejus.loha |
1325 |
|
| 34444 |
vikas.jang |
1326 |
if (!liquidations.isEmpty()) {
|
|
|
1327 |
for (Liquidation liquidation : liquidations) catalogIds.add(liquidation.getCatalogId());
|
|
|
1328 |
contentMap = commonSolrService.getContentByCatalogIds(catalogIds);
|
|
|
1329 |
}
|
|
|
1330 |
|
|
|
1331 |
List<LiquidationDetail> resultList = new ArrayList<>();
|
|
|
1332 |
|
|
|
1333 |
if (contentMap != null) {
|
|
|
1334 |
for (Liquidation liquidation : liquidations) {
|
|
|
1335 |
List<Bid> bidList = bidRepository.selectBidByLiquidationId(liquidation.getId());
|
|
|
1336 |
LiquidationDetail liquidationDetail = new LiquidationDetail();
|
|
|
1337 |
if(contentMap.containsKey(liquidation.getCatalogId())) {
|
|
|
1338 |
JSONObject jsonObj = contentMap.get(liquidation.getCatalogId());
|
|
|
1339 |
liquidationDetail.setLiquidationId(liquidation.getId());
|
|
|
1340 |
liquidationDetail.setImageURL(jsonObj.getString("imageUrl_s"));
|
|
|
1341 |
liquidationDetail.setItemName(jsonObj.getString("title_s"));
|
|
|
1342 |
liquidationDetail.setBrand(jsonObj.getString("title_s"));
|
|
|
1343 |
liquidationDetail.setCatalogId(jsonObj.getInt("catalogId_i"));
|
|
|
1344 |
liquidationDetail.setMrp(jsonObj.getFloat("mop_f"));
|
|
|
1345 |
liquidationDetail.setMop(jsonObj.getFloat("mop_f"));
|
|
|
1346 |
liquidationDetail.setDp(jsonObj.getFloat("dp_f"));
|
|
|
1347 |
liquidationDetail.setSuperCatalogs(jsonObj.getString("superCatalogVariants_s"));
|
|
|
1348 |
liquidationDetail.setStartDate(liquidation.getStartDate());
|
|
|
1349 |
liquidationDetail.setEndDate(liquidation.getEndDate());
|
|
|
1350 |
liquidationDetail.setSellingPrice(liquidation.getPrice());
|
|
|
1351 |
liquidationDetail.setAvailableQuantity(liquidation.getQuantity());
|
| 34494 |
vikas.jang |
1352 |
liquidationDetail.setIncrementStep(liquidation.getIncrementStep());
|
| 34444 |
vikas.jang |
1353 |
liquidationDetail.setBidList(bidList);
|
|
|
1354 |
resultList.add(liquidationDetail);
|
|
|
1355 |
}
|
|
|
1356 |
}
|
|
|
1357 |
}
|
|
|
1358 |
|
|
|
1359 |
return responseSender.ok(resultList);
|
|
|
1360 |
}
|
|
|
1361 |
|
|
|
1362 |
@RequestMapping(value = "/store/clearance/bid", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
1363 |
@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
|
|
|
1364 |
public ResponseEntity<?> saveBidding(HttpServletRequest request, @RequestBody BiddingModel biddingModel) throws Exception {
|
| 34446 |
vikas.jang |
1365 |
LocalDateTime now = LocalDateTime.now();
|
| 34476 |
vikas.jang |
1366 |
Liquidation liquidation = liquidationRepository.selectLiquidationById(biddingModel.getLiquidationId());
|
|
|
1367 |
LocalDateTime endDateTime = LocalDateTime.of(liquidation.getEndDate().toLocalDate(), LocalTime.of(ProfitMandiConstants.BID_END_HOUR, ProfitMandiConstants.BID_END_MIN));
|
| 34494 |
vikas.jang |
1368 |
List<Bid> biddings = bidRepository.selectBidByLiquidationId(biddingModel.getLiquidationId());
|
| 34476 |
vikas.jang |
1369 |
if (now.isAfter(endDateTime)) {
|
| 34494 |
vikas.jang |
1370 |
return responseSender.badRequest("Bid on this product has been closed");
|
| 34446 |
vikas.jang |
1371 |
}
|
| 34444 |
vikas.jang |
1372 |
Bid bid = null;
|
|
|
1373 |
UserInfo userInfo = (UserInfo) request.getAttribute("userInfo");
|
|
|
1374 |
if (biddingModel.getId() != null && biddingModel.getId() > 0) {
|
|
|
1375 |
bid = bidRepository.selectById(biddingModel.getId());
|
|
|
1376 |
if (bid == null) {
|
| 34494 |
vikas.jang |
1377 |
return responseSender.badRequest("Bidding record not found with ID: " + biddingModel.getId());
|
| 34444 |
vikas.jang |
1378 |
}
|
|
|
1379 |
} else {
|
|
|
1380 |
bid = new Bid();
|
|
|
1381 |
}
|
| 34476 |
vikas.jang |
1382 |
logger.info("biddingModel {}: ",biddingModel);
|
| 34444 |
vikas.jang |
1383 |
bid.setLiquidationId(biddingModel.getLiquidationId());
|
|
|
1384 |
bid.setBiddingAmount(biddingModel.getBiddingAmount());
|
|
|
1385 |
bid.setFofoId(userInfo.getRetailerId());
|
|
|
1386 |
bid.setItemName(biddingModel.getItemName());
|
|
|
1387 |
bid.setQuantity(biddingModel.getBidQty());
|
|
|
1388 |
bid.setStatus(ProfitMandiConstants.BID_ENUM.PENDING);
|
|
|
1389 |
bid.setCreatedAt(LocalDateTime.now());
|
| 34562 |
ranu |
1390 |
if (biddingModel.getId() == null) {
|
|
|
1391 |
bidRepository.persist(bid);
|
| 34654 |
vikas.jang |
1392 |
//debit 500 from wallet
|
| 34878 |
vikas |
1393 |
try {
|
|
|
1394 |
String reason = "Advance security for "+bid.getItemName()+" bid";
|
|
|
1395 |
String message = "Dear Partner - We have Debited Rs "+ProfitMandiConstants.BID_CHARGES+" as Booking amount against your Bidding of Model No. "+bid.getItemName()+". We will refund this amount if the Bid gets approved.";
|
|
|
1396 |
walletService.consumeAmountFromWallet(bid.getFofoId(),
|
|
|
1397 |
bid.getId(),
|
|
|
1398 |
WalletReferenceType.ADVANCE_SECURITY,
|
|
|
1399 |
reason, ProfitMandiConstants.BID_CHARGES,
|
|
|
1400 |
bid.getCreatedAt(),false);
|
|
|
1401 |
bidService.sendPushNotification(message,"Bidding Update!",Arrays.asList(bid.getFofoId()));
|
|
|
1402 |
} catch (Exception e) {
|
|
|
1403 |
logger.info("WalletDebit: {}",e.getMessage());
|
|
|
1404 |
}
|
| 34562 |
ranu |
1405 |
}
|
| 34494 |
vikas.jang |
1406 |
if (biddings.size() > 1) {
|
|
|
1407 |
for (Bid bidding : biddings) {
|
| 34562 |
ranu |
1408 |
if (!(bid.getFofoId().equals(bidding.getFofoId()))) bidService.notifyPartner(bidding.getFofoId(), bid, ProfitMandiConstants.BID_ENUM.UPDATE);
|
| 34494 |
vikas.jang |
1409 |
}
|
|
|
1410 |
}
|
|
|
1411 |
return responseSender.ok("Bid placed successfully!");
|
| 34444 |
vikas.jang |
1412 |
}
|
|
|
1413 |
|
|
|
1414 |
|
| 26607 |
amit.gupta |
1415 |
}
|