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