Subversion Repositories SmartDukaan

Rev

Rev 35458 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21378 kshitij.so 1
package com.spice.profitmandi.web.controller;
2
 
28742 tejbeer 3
import java.time.LocalDateTime;
21378 kshitij.so 4
import java.util.ArrayList;
28742 tejbeer 5
import java.util.Arrays;
24422 amit.gupta 6
import java.util.HashMap;
21378 kshitij.so 7
import java.util.List;
24422 amit.gupta 8
import java.util.Map;
28742 tejbeer 9
import java.util.Set;
29325 tejbeer 10
import java.util.stream.Collectors;
21378 kshitij.so 11
 
12
import javax.servlet.http.HttpServletRequest;
13
 
34196 ranu 14
import com.spice.profitmandi.common.enumuration.SchemeType;
15
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
16
import com.spice.profitmandi.common.model.UserInfo;
17
import com.spice.profitmandi.common.web.client.RestClient;
18
import com.spice.profitmandi.dao.model.*;
19
import com.spice.profitmandi.dao.repository.fofo.FofoOpeningStockRepository;
20
import com.spice.profitmandi.service.inventory.*;
21
import org.apache.commons.lang3.StringUtils;
22
import org.apache.http.conn.HttpHostConnectException;
23959 amit.gupta 23
import org.apache.logging.log4j.LogManager;
24
import org.apache.logging.log4j.Logger;
34196 ranu 25
import org.json.JSONArray;
29503 amit.gupta 26
import org.json.JSONObject;
21378 kshitij.so 27
import org.springframework.beans.factory.annotation.Autowired;
28
import org.springframework.http.MediaType;
29
import org.springframework.http.ResponseEntity;
30
import org.springframework.stereotype.Controller;
21707 amit.gupta 31
import org.springframework.transaction.annotation.Transactional;
28742 tejbeer 32
import org.springframework.ui.Model;
34196 ranu 33
import org.springframework.web.bind.annotation.*;
21378 kshitij.so 34
 
28742 tejbeer 35
import com.spice.profitmandi.common.enumuration.MessageType;
36
import com.spice.profitmandi.common.model.CustomRetailer;
21378 kshitij.so 37
import com.spice.profitmandi.common.model.ProfitMandiConstants;
28742 tejbeer 38
import com.spice.profitmandi.common.model.SendNotificationModel;
29503 amit.gupta 39
import com.spice.profitmandi.common.services.mandii.MandiiService;
21741 ashik.ali 40
import com.spice.profitmandi.common.web.util.ResponseSender;
28653 amit.gupta 41
import com.spice.profitmandi.dao.cart.CartService;
28742 tejbeer 42
import com.spice.profitmandi.dao.entity.auth.AuthUser;
43
import com.spice.profitmandi.dao.entity.catalog.FocusedModelByPassRequest;
44
import com.spice.profitmandi.dao.entity.cs.Position;
45
import com.spice.profitmandi.dao.entity.dtr.User;
23273 ashik.ali 46
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
29503 amit.gupta 47
import com.spice.profitmandi.dao.entity.fofo.FofoPayment;
29327 tejbeer 48
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
29503 amit.gupta 49
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
28742 tejbeer 50
import com.spice.profitmandi.dao.enumuration.catalog.ByPassRequestStatus;
51
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
21735 ashik.ali 52
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
29503 amit.gupta 53
import com.spice.profitmandi.dao.enumuration.fofo.PaymentStatus;
28742 tejbeer 54
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
55
import com.spice.profitmandi.dao.repository.catalog.FocusedModelByPassRepository;
29327 tejbeer 56
import com.spice.profitmandi.dao.repository.catalog.FocusedModelRepository;
23360 amit.gupta 57
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
29327 tejbeer 58
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
28742 tejbeer 59
import com.spice.profitmandi.dao.repository.cs.CsService;
29327 tejbeer 60
import com.spice.profitmandi.dao.repository.cs.PartnerRegionRepository;
28742 tejbeer 61
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
29327 tejbeer 62
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
63
import com.spice.profitmandi.dao.repository.dtr.RetailerBlockBrandsRepository;
21735 ashik.ali 64
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
28742 tejbeer 65
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
29327 tejbeer 66
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
29503 amit.gupta 67
import com.spice.profitmandi.dao.repository.fofo.FofoPaymentRepository;
29327 tejbeer 68
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
29503 amit.gupta 69
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
21643 ashik.ali 70
import com.spice.profitmandi.dao.util.ContentPojoPopulator;
28742 tejbeer 71
import com.spice.profitmandi.service.FofoUser;
72
import com.spice.profitmandi.service.NotificationService;
73
import com.spice.profitmandi.service.PartnerInvestmentService;
29327 tejbeer 74
import com.spice.profitmandi.service.transaction.TransactionService;
28742 tejbeer 75
import com.spice.profitmandi.service.user.RetailerService;
29503 amit.gupta 76
import com.spice.profitmandi.service.wallet.WalletService;
21378 kshitij.so 77
import com.spice.profitmandi.web.res.ValidateCartResponse;
78
 
29503 amit.gupta 79
import in.shop2020.model.v1.order.WalletReferenceType;
21378 kshitij.so 80
import io.swagger.annotations.ApiImplicitParam;
81
import io.swagger.annotations.ApiImplicitParams;
82
import io.swagger.annotations.ApiOperation;
83
 
84
@Controller
24199 amit.gupta 85
@Transactional(rollbackFor = Throwable.class)
21378 kshitij.so 86
public class CartController {
87
 
24199 amit.gupta 88
	private static final Logger logger = LogManager.getLogger(CartController.class);
89
 
21440 ashik.ali 90
	@Autowired
22931 ashik.ali 91
	private ResponseSender<?> responseSender;
21378 kshitij.so 92
 
93
	@Autowired
22931 ashik.ali 94
	private UserAccountRepository userAccountRepository;
24199 amit.gupta 95
 
22173 amit.gupta 96
	@Autowired
25962 amit.gupta 97
	private ItemBucketService itemBucketService;
98
 
99
	@Autowired
28653 amit.gupta 100
	CartService cartService;
101
 
102
	@Autowired
22931 ashik.ali 103
	private ContentPojoPopulator contentPojoPopulator;
24199 amit.gupta 104
 
23360 amit.gupta 105
	@Autowired
106
	private ItemRepository itemRepository;
21378 kshitij.so 107
 
28742 tejbeer 108
	@Autowired
109
	private UserRepository userRepository;
110
 
111
	@Autowired
112
	private AuthRepository authRepository;
113
 
114
	@Autowired
115
	private CsService csService;
116
 
117
	@Autowired
118
	private PositionRepository positionRepository;
119
 
120
	@Autowired
121
	private FocusedModelByPassRepository focusedModelByPassRepository;
30989 tejbeer 122
 
29503 amit.gupta 123
	@Autowired
124
	private FofoPaymentRepository fofoPaymentRepository;
28742 tejbeer 125
 
126
	@Autowired
127
	private RetailerService retailerService;
128
 
129
	@Autowired
130
	private PartnerInvestmentService partnerInvestmentService;
131
 
132
	@Autowired
133
	private FofoUser fofoUser;
28743 tejbeer 134
 
28742 tejbeer 135
	@Autowired
29327 tejbeer 136
	private FocusedModelRepository focusedModelRepository;
137
 
138
	@Autowired
139
	private PartnerRegionRepository partnerRegionRepository;
140
 
141
	@Autowired
142
	private SaholicInventoryService saholicInventoryService;
143
 
144
	@Autowired
145
	private TransactionService transactionService;
146
 
147
	@Autowired
148
	private FofoStoreRepository fofoStoreRepository;
149
 
150
	@Autowired
151
	private RetailerBlockBrandsRepository retailerBlockBrandRepository;
152
 
153
	@Autowired
154
	private OrderRepository orderRepository;
155
 
156
	@Autowired
157
	private TagListingRepository tagListingRepository;
158
 
159
	@Autowired
28742 tejbeer 160
	private NotificationService notificationService;
161
 
29327 tejbeer 162
	@Autowired
34196 ranu 163
	private FofoOpeningStockRepository fofoOpeningStockRepository;
164
 
165
	@Autowired
29327 tejbeer 166
	private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
167
 
24422 amit.gupta 168
	public static final Map<String, Integer> MIN_BRAND_QTY_LIMIT = new HashMap<>();
169
 
29327 tejbeer 170
	private static final Logger log = LogManager.getLogger(CartController.class);
171
 
28746 tejbeer 172
	List<EscalationType> esclationType = Arrays.asList(EscalationType.L3, EscalationType.L4, EscalationType.L2);
28742 tejbeer 173
 
29325 tejbeer 174
	List<String> emails = Arrays.asList("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com",
175
			"niranjan.kala@smartdukaan.com", "sm@smartdukaan.com");
28742 tejbeer 176
 
24422 amit.gupta 177
	static {
25962 amit.gupta 178
		// MIN_BRAND_QTY_LIMIT.put("Realme", 10);
24464 amit.gupta 179
		MIN_BRAND_QTY_LIMIT.put("Reliance", 5);
24422 amit.gupta 180
	}
181
 
25962 amit.gupta 182
	@RequestMapping(value = ProfitMandiConstants.URL_CART, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
183
	@ApiImplicitParams({
184
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
185
	@ApiOperation(value = "Add items to cart")
186
	public ResponseEntity<?> validateCart(HttpServletRequest request,
187
			@RequestParam(value = "pincode", defaultValue = "110001") String pincode, @RequestParam int bucketId)
188
			throws Throwable {
189
 
190
		AddCartRequest cartRequest = new AddCartRequest();
26607 amit.gupta 191
		List<CartItem> ci = new ArrayList<>();
25962 amit.gupta 192
		itemBucketService.getBucketDetails(bucketId).stream().forEach(x -> {
28653 amit.gupta 193
			ci.add(new CartItem(x.getQuantity(), x.getItemId()));
25962 amit.gupta 194
		});
26607 amit.gupta 195
		cartRequest.setCartItems(ci);
25962 amit.gupta 196
		return this.validateCart(request, cartRequest, "110001");
197
 
198
	}
199
 
24199 amit.gupta 200
	@RequestMapping(value = ProfitMandiConstants.URL_CART, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
21378 kshitij.so 201
	@ApiImplicitParams({
24199 amit.gupta 202
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
21378 kshitij.so 203
	@ApiOperation(value = "Add items to cart")
24199 amit.gupta 204
	public ResponseEntity<?> validateCart(HttpServletRequest request, @RequestBody AddCartRequest cartRequest,
205
			@RequestParam(value = "pincode", defaultValue = "110001") String pincode) throws Throwable {
23273 ashik.ali 206
		UserAccount userAccount = null;
21378 kshitij.so 207
		ValidateCartResponse vc = null;
24199 amit.gupta 208
		int userId = (int) request.getAttribute("userId");
209
 
28653 amit.gupta 210
		int cartId = userAccountRepository.selectByUserIdType(userId, AccountType.cartId).getAccountKey();
26607 amit.gupta 211
		List<CartItem> cartItems = cartRequest.getCartItems();
28653 amit.gupta 212
		cartService.addItemsToCart(cartId, cartItems);
213
		CartResponse cartValidationResponse = cartService.getCartValidation(cartId);
31715 tejbeer 214
 
33474 amit.gupta 215
		for (CartItemResponseModel cartItem : cartValidationResponse.getCartItems()) {
31715 tejbeer 216
			ProductPojo pp = contentPojoPopulator.getShortContent(cartItem.getCatalogItemId());
217
 
218
			log.info("pp {}", pp);
219
			if (pp != null) {
220
				cartItem.setImageUrl(pp.getImageUrl()); // cartItem.setTitle(pp.getTitle());
221
			}
33474 amit.gupta 222
		}
31715 tejbeer 223
 
28653 amit.gupta 224
		vc = new ValidateCartResponse(cartValidationResponse, "Success", "Items added to cart successfully");
23021 ashik.ali 225
		return responseSender.ok(vc);
21378 kshitij.so 226
	}
21393 amit.gupta 227
 
35958 amit 228
	@RequestMapping(value = "/cart/item", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
229
	@ApiImplicitParams({
230
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
231
	@ApiOperation(value = "Add or update a single cart item")
232
	public ResponseEntity<?> updateCartItem(HttpServletRequest request,
233
			@RequestParam int itemId, @RequestParam int quantity,
234
			@RequestParam(defaultValue = "0") float sellingPrice) throws Throwable {
235
		int userId = (int) request.getAttribute("userId");
236
		int cartId = userAccountRepository.selectByUserIdType(userId, AccountType.cartId).getAccountKey();
237
		cartService.updateCartItem(cartId, itemId, quantity, sellingPrice);
238
		return responseSender.ok(cartService.getCartItems(cartId));
239
	}
240
 
241
	@RequestMapping(value = "/cart/item", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
242
	@ApiImplicitParams({
243
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
244
	@ApiOperation(value = "Remove an item from cart")
245
	public ResponseEntity<?> removeCartItem(HttpServletRequest request,
246
			@RequestParam int itemId) throws Throwable {
247
		int userId = (int) request.getAttribute("userId");
248
		int cartId = userAccountRepository.selectByUserIdType(userId, AccountType.cartId).getAccountKey();
249
		cartService.removeCartItem(cartId, itemId);
250
		return responseSender.ok(cartService.getCartItems(cartId));
251
	}
252
 
253
	@RequestMapping(value = "/cart/items", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
254
	@ApiImplicitParams({
255
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
256
	@ApiOperation(value = "Get current cart items")
257
	public ResponseEntity<?> getCartItems(HttpServletRequest request) throws Throwable {
258
		int userId = (int) request.getAttribute("userId");
259
		int cartId = userAccountRepository.selectByUserIdType(userId, AccountType.cartId).getAccountKey();
260
		return responseSender.ok(cartService.getCartItems(cartId));
261
	}
262
 
24199 amit.gupta 263
	@RequestMapping(value = ProfitMandiConstants.URL_CART_CHANGE_ADDRESS, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
21393 amit.gupta 264
	@ApiImplicitParams({
24199 amit.gupta 265
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
266
 
21393 amit.gupta 267
	@ApiOperation(value = "Change address")
24199 amit.gupta 268
	public ResponseEntity<?> changeAddress(HttpServletRequest request,
269
			@RequestParam(value = "addressId") long addressId) throws Throwable {
270
		UserCart uc = userAccountRepository.getUserCart((int) request.getAttribute("userId"));
28653 amit.gupta 271
		cartService.addAddressToCart(uc.getCartId(), addressId);
24199 amit.gupta 272
		return responseSender.ok("Address Changed successfully");
273
	}
28742 tejbeer 274
 
29325 tejbeer 275
	@RequestMapping(value = "/byPassRequests", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
28742 tejbeer 276
	@ApiImplicitParams({
277
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
278
 
29325 tejbeer 279
	@ApiOperation(value = "byPassRequests")
280
	public ResponseEntity<?> byPassRequests(HttpServletRequest request, Model model) throws Exception {
28742 tejbeer 281
 
282
		int userId = (int) request.getAttribute("userId");
283
 
28743 tejbeer 284
		User user = userRepository.selectById(userId);
29328 tejbeer 285
		AuthUser authUser = authRepository.selectByEmailOrMobile(user.getEmailId());
29325 tejbeer 286
 
28742 tejbeer 287
		List<FocusedModelByPassRequest> byPassRequests = null;
288
 
289
		Set<Integer> authfofoIds = null;
29325 tejbeer 290
		boolean actionAccess = false;
291
		logger.info("authUser" + authUser);
28742 tejbeer 292
 
29325 tejbeer 293
		List<Position> positions = positionRepository.selectPositionByAuthId(authUser.getId()).stream()
294
				.filter(x -> (x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_SALES
295
						|| x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_RBM))
296
				.collect(Collectors.toList());
28742 tejbeer 297
 
29325 tejbeer 298
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
299
 
28742 tejbeer 300
		if (emails.contains(authUser.getEmailId())) {
29325 tejbeer 301
			byPassRequests = focusedModelByPassRepository.selectByStatus(ByPassRequestStatus.PENDING);
302
			actionAccess = true;
28742 tejbeer 303
		} else {
29325 tejbeer 304
			if (!positions.isEmpty()) {
305
				for (Position ps : positions) {
306
					if (ProfitMandiConstants.TICKET_CATEGORY_RBM == ps.getCategoryId()) {
307
						authfofoIds = storeGuyMap.get(user.getEmailId());
308
						logger.info("authfofoIdsw" + authfofoIds);
309
						actionAccess = true;
310
						break;
311
					} else if (ProfitMandiConstants.TICKET_CATEGORY_SALES == ps.getCategoryId()) {
312
						authfofoIds = storeGuyMap.get(user.getEmailId());
313
						logger.info("authfofoIdsw" + authfofoIds);
314
						actionAccess = false;
315
						break;
316
					}
28742 tejbeer 317
 
318
				}
319
			}
320
		}
321
		logger.info("authfofoIds" + authfofoIds);
322
		if (authfofoIds != null) {
323
			byPassRequests = focusedModelByPassRepository.selectByStatusAndFofoIds(new ArrayList<>(authfofoIds),
324
					ByPassRequestStatus.PENDING);
325
		}
29327 tejbeer 326
 
28742 tejbeer 327
		Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
328
		List<ByPassRequestModel> byPassList = new ArrayList<>();
329
 
330
		for (FocusedModelByPassRequest byPassRequest : byPassRequests) {
29327 tejbeer 331
 
332
			List<FocusedShortageModel> fsms = cartService.focusedModelShortageValidation(byPassRequest.getFofoId(),
333
					new HashMap<>());
28742 tejbeer 334
			Map<String, Object> investments = fofoUser.getInvestments(byPassRequest.getFofoId());
335
			ByPassRequestModel bp = new ByPassRequestModel();
336
			bp.setPartnerName(customRetailerMap.get(byPassRequest.getFofoId()).getBusinessName());
337
			bp.setCity(customRetailerMap.get(byPassRequest.getFofoId()).getAddress().getCity());
338
			bp.setState(customRetailerMap.get(byPassRequest.getFofoId()).getAddress().getState());
339
			bp.setCode(customRetailerMap.get(byPassRequest.getFofoId()).getCode());
340
			bp.setStatus(byPassRequest.getStatus());
341
			bp.setFofoId(byPassRequest.getFofoId());
342
			bp.setByPassRequestId(byPassRequest.getId());
343
			bp.setInvestmentOkDays((Long) investments.get("okDays"));
29327 tejbeer 344
			bp.setInvestmentShort((PartnerDailyInvestment) investments.get("investment"));
28742 tejbeer 345
			bp.setMobileNumber(customRetailerMap.get(byPassRequest.getFofoId()).getMobileNumber());
29325 tejbeer 346
			bp.setActionAccess(actionAccess);
28742 tejbeer 347
			bp.setCreateTimestamp(byPassRequest.getCreatedTimeStamp());
348
			bp.setUpdateTimestamp(byPassRequest.getUpdatedTimestamp());
29327 tejbeer 349
			bp.setFsms(fsms);
28742 tejbeer 350
			byPassList.add(bp);
351
 
352
		}
353
 
354
		return responseSender.ok(byPassList);
355
	}
356
 
357
	@RequestMapping(value = "/byPassRequestAction", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
358
	@ApiImplicitParams({
359
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
360
	@ApiOperation(value = "Add items to cart")
361
	public ResponseEntity<?> addAmountToWalletRequestRejected(HttpServletRequest request,
362
			@RequestParam(name = "id", defaultValue = "0") int id, @RequestParam ByPassRequestStatus status,
29333 tejbeer 363
			@RequestParam String reason, Model model) throws Exception {
29325 tejbeer 364
		int userId = (int) request.getAttribute("userId");
28742 tejbeer 365
 
29325 tejbeer 366
		User user = userRepository.selectById(userId);
367
		AuthUser authUser = authRepository.selectByEmailOrMobile(user.getEmailId());
368
 
28742 tejbeer 369
		FocusedModelByPassRequest byPassRequest = focusedModelByPassRepository.selectById(id);
370
		if (status.equals(ByPassRequestStatus.APPROVED)) {
371
			byPassRequest.setByPass(true);
29325 tejbeer 372
			byPassRequest.setAuthId(authUser.getId());
28742 tejbeer 373
			byPassRequest.setStatus(ByPassRequestStatus.APPROVED);
374
			byPassRequest.setUpdatedTimestamp(LocalDateTime.now());
29333 tejbeer 375
			byPassRequest.setReason(reason);
28742 tejbeer 376
		} else if (status.equals(ByPassRequestStatus.REJECTED)) {
377
			byPassRequest.setByPass(false);
29325 tejbeer 378
			byPassRequest.setAuthId(authUser.getId());
28742 tejbeer 379
			byPassRequest.setStatus(ByPassRequestStatus.REJECTED);
380
			byPassRequest.setUpdatedTimestamp(LocalDateTime.now());
29333 tejbeer 381
			byPassRequest.setReason(reason);
28742 tejbeer 382
		}
383
 
30989 tejbeer 384
		String title = "Billing Request";
385
 
386
		String message = String.format("Your Billing  Request is " + status
387
				+ ". Please ensure to order the missing focus models as soon as possible.");
388
 
28742 tejbeer 389
		SendNotificationModel sendNotificationModel = new SendNotificationModel();
390
		sendNotificationModel.setCampaignName("Billing Request");
30989 tejbeer 391
		sendNotificationModel.setTitle(title);
392
		sendNotificationModel.setMessage(message);
28742 tejbeer 393
		sendNotificationModel.setType("url");
34902 vikas 394
		sendNotificationModel.setUrl("https://smartdukaan.com/pages/home/notifications");
28742 tejbeer 395
		sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
396
		sendNotificationModel.setMessageType(MessageType.notification);
397
		sendNotificationModel
398
				.setUserIds(Arrays.asList(userAccountRepository.selectUserIdByRetailerId(byPassRequest.getFofoId())));
399
 
400
		notificationService.sendNotification(sendNotificationModel);
401
 
402
		return responseSender.ok(true);
403
	}
30989 tejbeer 404
 
29503 amit.gupta 405
	@Autowired
406
	WalletService walletService;
30989 tejbeer 407
 
29503 amit.gupta 408
	@Autowired
409
	MandiiService mandiiService;
30989 tejbeer 410
 
411
	@Autowired
412
	UserWalletHistoryRepository userWalletHistoryRepository;
413
 
29503 amit.gupta 414
	@RequestMapping(value = "/cart/payment", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
415
	public ResponseEntity<?> validateCartPayment(HttpServletRequest request,
416
			@RequestParam(defaultValue = "0") int paymentId, Model model) throws Exception {
417
		int userId = (int) request.getAttribute("userId");
418
		UserCart uc = userAccountRepository.getUserCart(userId);
419
 
420
		FofoPayment fofoPayment = fofoPaymentRepository.selectById(paymentId);
30989 tejbeer 421
		if (fofoPayment == null || fofoPayment.getFofoId() != uc.getUserId()) {
29503 amit.gupta 422
			return responseSender.ok(false);
423
		}
424
		String gatewayReference = fofoPayment.getGatewayReference();
30989 tejbeer 425
		List<UserWalletHistory> historyList = userWalletHistoryRepository
426
				.selectAllByreferenceIdandreferenceType(paymentId, WalletReferenceType.PAYMENT_GATEWAY);
29503 amit.gupta 427
		if (fofoPayment.getStatus().equals(PaymentStatus.INIT) && historyList.size() == 0) {
428
			String jsonString = mandiiService.getOrderStatus(gatewayReference);
429
			JSONObject jsonOrder = new JSONObject(jsonString);
430
			double orderAmount = jsonOrder.getDouble("order_amount");
29611 amit.gupta 431
			double capturedAmount = jsonOrder.getDouble("captured_amount");
29503 amit.gupta 432
			int merchantOrderId = jsonOrder.getInt("merchant_order_number");
29594 amit.gupta 433
			String status = jsonOrder.getString("status");
30989 tejbeer 434
			if (merchantOrderId == paymentId && status.equals("SUCCESS") || status.equals("CAPTURED")) {
435
				if (orderAmount == fofoPayment.getAmount()) {
29611 amit.gupta 436
					fofoPayment.setStatus(PaymentStatus.SUCCESS);
29625 amit.gupta 437
					fofoPayment.setAmount(capturedAmount);
30989 tejbeer 438
					walletService.addAmountToWallet(uc.getUserId(), paymentId, WalletReferenceType.PAYMENT_GATEWAY,
439
							"Amount added to wallet via SD Credit via Mandii", (float) fofoPayment.getAmount(),
440
							LocalDateTime.now());
441
					if (orderAmount == capturedAmount) {
29611 amit.gupta 442
						return responseSender.ok(true);
30989 tejbeer 443
					}
29611 amit.gupta 444
				}
29503 amit.gupta 445
			}
446
		}
447
		return responseSender.ok(false);
448
	}
34196 ranu 449
 
450
	@RequestMapping(value = "/partner/hidAllocation", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
451
	@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
452
	public ResponseEntity<?> getItemHidAllocation(HttpServletRequest request) throws
453
			Exception {
454
		List<HidAllocationModel> hidAllocationModels = new ArrayList<>();
455
 
456
		int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
457
		int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
458
 
459
		hidAllocationModels = fofoOpeningStockRepository.getPartnerHidAllocation(retailerId);
460
 
461
		return responseSender.ok(hidAllocationModels);
462
	}
463
 
464
 
21378 kshitij.so 465
}