Subversion Repositories SmartDukaan

Rev

Rev 29417 | Rev 29594 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 29417 Rev 29503
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import java.time.LocalDateTime;
3
import java.time.LocalDateTime;
4
import java.util.ArrayList;
4
import java.util.ArrayList;
5
import java.util.Arrays;
5
import java.util.Arrays;
6
import java.util.Collections;
-
 
7
import java.util.HashMap;
6
import java.util.HashMap;
8
import java.util.HashSet;
-
 
9
import java.util.LinkedHashMap;
-
 
10
import java.util.List;
7
import java.util.List;
11
import java.util.Map;
8
import java.util.Map;
12
import java.util.Map.Entry;
-
 
13
import java.util.Set;
9
import java.util.Set;
14
import java.util.stream.Collectors;
10
import java.util.stream.Collectors;
15
 
11
 
16
import javax.servlet.http.HttpServletRequest;
12
import javax.servlet.http.HttpServletRequest;
17
 
13
 
18
import org.apache.logging.log4j.LogManager;
14
import org.apache.logging.log4j.LogManager;
19
import org.apache.logging.log4j.Logger;
15
import org.apache.logging.log4j.Logger;
-
 
16
import org.json.JSONObject;
20
import org.springframework.beans.factory.annotation.Autowired;
17
import org.springframework.beans.factory.annotation.Autowired;
21
import org.springframework.http.MediaType;
18
import org.springframework.http.MediaType;
22
import org.springframework.http.ResponseEntity;
19
import org.springframework.http.ResponseEntity;
23
import org.springframework.stereotype.Controller;
20
import org.springframework.stereotype.Controller;
24
import org.springframework.transaction.annotation.Transactional;
21
import org.springframework.transaction.annotation.Transactional;
Line 27... Line 24...
27
import org.springframework.web.bind.annotation.RequestMapping;
24
import org.springframework.web.bind.annotation.RequestMapping;
28
import org.springframework.web.bind.annotation.RequestMethod;
25
import org.springframework.web.bind.annotation.RequestMethod;
29
import org.springframework.web.bind.annotation.RequestParam;
26
import org.springframework.web.bind.annotation.RequestParam;
30
 
27
 
31
import com.spice.profitmandi.common.enumuration.MessageType;
28
import com.spice.profitmandi.common.enumuration.MessageType;
32
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
-
 
33
import com.spice.profitmandi.common.model.CustomRetailer;
29
import com.spice.profitmandi.common.model.CustomRetailer;
34
import com.spice.profitmandi.common.model.FocusedModelShortageModel;
-
 
35
import com.spice.profitmandi.common.model.ProfitMandiConstants;
30
import com.spice.profitmandi.common.model.ProfitMandiConstants;
36
import com.spice.profitmandi.common.model.SendNotificationModel;
31
import com.spice.profitmandi.common.model.SendNotificationModel;
-
 
32
import com.spice.profitmandi.common.services.mandii.MandiiService;
37
import com.spice.profitmandi.common.web.util.ResponseSender;
33
import com.spice.profitmandi.common.web.util.ResponseSender;
38
import com.spice.profitmandi.dao.cart.CartService;
34
import com.spice.profitmandi.dao.cart.CartService;
39
import com.spice.profitmandi.dao.entity.auth.AuthUser;
35
import com.spice.profitmandi.dao.entity.auth.AuthUser;
40
import com.spice.profitmandi.dao.entity.catalog.FocusedModelByPassRequest;
36
import com.spice.profitmandi.dao.entity.catalog.FocusedModelByPassRequest;
41
import com.spice.profitmandi.dao.entity.catalog.Item;
-
 
42
import com.spice.profitmandi.dao.entity.catalog.TagListing;
-
 
43
import com.spice.profitmandi.dao.entity.cs.PartnerRegion;
-
 
44
import com.spice.profitmandi.dao.entity.cs.Position;
37
import com.spice.profitmandi.dao.entity.cs.Position;
45
import com.spice.profitmandi.dao.entity.dtr.User;
38
import com.spice.profitmandi.dao.entity.dtr.User;
46
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
39
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
47
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
40
import com.spice.profitmandi.dao.entity.fofo.FofoPayment;
48
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
41
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
49
import com.spice.profitmandi.dao.entity.inventory.SaholicCIS;
42
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
50
import com.spice.profitmandi.dao.enumuration.catalog.ByPassRequestStatus;
43
import com.spice.profitmandi.dao.enumuration.catalog.ByPassRequestStatus;
51
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
44
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
52
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
45
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
-
 
46
import com.spice.profitmandi.dao.enumuration.fofo.PaymentStatus;
53
import com.spice.profitmandi.dao.model.AddCartRequest;
47
import com.spice.profitmandi.dao.model.AddCartRequest;
54
import com.spice.profitmandi.dao.model.CartItem;
48
import com.spice.profitmandi.dao.model.CartItem;
55
import com.spice.profitmandi.dao.model.CartItemResponseModel;
-
 
56
import com.spice.profitmandi.dao.model.CartResponse;
49
import com.spice.profitmandi.dao.model.CartResponse;
57
import com.spice.profitmandi.dao.model.ProductPojo;
-
 
58
import com.spice.profitmandi.dao.model.UserCart;
50
import com.spice.profitmandi.dao.model.UserCart;
59
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
51
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
60
import com.spice.profitmandi.dao.repository.catalog.FocusedModelByPassRepository;
52
import com.spice.profitmandi.dao.repository.catalog.FocusedModelByPassRepository;
61
import com.spice.profitmandi.dao.repository.catalog.FocusedModelRepository;
53
import com.spice.profitmandi.dao.repository.catalog.FocusedModelRepository;
62
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
54
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
Line 67... Line 59...
67
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
59
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
68
import com.spice.profitmandi.dao.repository.dtr.RetailerBlockBrandsRepository;
60
import com.spice.profitmandi.dao.repository.dtr.RetailerBlockBrandsRepository;
69
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
61
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
70
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
62
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
71
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
63
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
-
 
64
import com.spice.profitmandi.dao.repository.fofo.FofoPaymentRepository;
72
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
65
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
-
 
66
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
73
import com.spice.profitmandi.dao.util.ContentPojoPopulator;
67
import com.spice.profitmandi.dao.util.ContentPojoPopulator;
74
import com.spice.profitmandi.service.FofoUser;
68
import com.spice.profitmandi.service.FofoUser;
75
import com.spice.profitmandi.service.NotificationService;
69
import com.spice.profitmandi.service.NotificationService;
76
import com.spice.profitmandi.service.PartnerInvestmentService;
70
import com.spice.profitmandi.service.PartnerInvestmentService;
77
import com.spice.profitmandi.service.inventory.ByPassRequestModel;
71
import com.spice.profitmandi.service.inventory.ByPassRequestModel;
78
import com.spice.profitmandi.service.inventory.FocusedShortageModel;
72
import com.spice.profitmandi.service.inventory.FocusedShortageModel;
79
import com.spice.profitmandi.service.inventory.ItemBucketService;
73
import com.spice.profitmandi.service.inventory.ItemBucketService;
80
import com.spice.profitmandi.service.inventory.SaholicInventoryService;
74
import com.spice.profitmandi.service.inventory.SaholicInventoryService;
81
import com.spice.profitmandi.service.transaction.TransactionService;
75
import com.spice.profitmandi.service.transaction.TransactionService;
82
import com.spice.profitmandi.service.user.RetailerService;
76
import com.spice.profitmandi.service.user.RetailerService;
83
import com.spice.profitmandi.web.controller.checkout.OrderController;
77
import com.spice.profitmandi.service.wallet.WalletService;
84
import com.spice.profitmandi.web.res.ValidateCartResponse;
78
import com.spice.profitmandi.web.res.ValidateCartResponse;
85
 
79
 
-
 
80
import in.shop2020.model.v1.order.WalletReferenceType;
86
import io.swagger.annotations.ApiImplicitParam;
81
import io.swagger.annotations.ApiImplicitParam;
87
import io.swagger.annotations.ApiImplicitParams;
82
import io.swagger.annotations.ApiImplicitParams;
88
import io.swagger.annotations.ApiOperation;
83
import io.swagger.annotations.ApiOperation;
89
 
84
 
90
@Controller
85
@Controller
Line 123... Line 118...
123
	@Autowired
118
	@Autowired
124
	private PositionRepository positionRepository;
119
	private PositionRepository positionRepository;
125
 
120
 
126
	@Autowired
121
	@Autowired
127
	private FocusedModelByPassRepository focusedModelByPassRepository;
122
	private FocusedModelByPassRepository focusedModelByPassRepository;
-
 
123
	
-
 
124
	@Autowired
-
 
125
	private FofoPaymentRepository fofoPaymentRepository;
128
 
126
 
129
	@Autowired
127
	@Autowired
130
	private RetailerService retailerService;
128
	private RetailerService retailerService;
131
 
129
 
132
	@Autowired
130
	@Autowired
Line 209... Line 207...
209
 
207
 
210
		int cartId = userAccountRepository.selectByUserIdType(userId, AccountType.cartId).getAccountKey();
208
		int cartId = userAccountRepository.selectByUserIdType(userId, AccountType.cartId).getAccountKey();
211
		List<CartItem> cartItems = cartRequest.getCartItems();
209
		List<CartItem> cartItems = cartRequest.getCartItems();
212
		cartService.addItemsToCart(cartId, cartItems);
210
		cartService.addItemsToCart(cartId, cartItems);
213
		CartResponse cartValidationResponse = cartService.getCartValidation(cartId);
211
		CartResponse cartValidationResponse = cartService.getCartValidation(cartId);
-
 
212
		/*
214
		for (CartItemResponseModel cartItem : cartValidationResponse.getCartItems()) {
213
		 * for (CartItemResponseModel cartItem : cartValidationResponse.getCartItems())
-
 
214
		 * { ProductPojo pp =
215
			ProductPojo pp = contentPojoPopulator.getShortContent(cartItem.getCatalogItemId());
215
		 * contentPojoPopulator.getShortContent(cartItem.getCatalogItemId());
216
 
216
		 * 
217
			log.info("pp {}", pp);
217
		 * log.info("pp {}", pp); if (pp != null) {
218
			if (pp != null) {
-
 
219
				cartItem.setImageUrl(pp.getImageUrl());
218
		 * cartItem.setImageUrl(pp.getImageUrl()); // cartItem.setTitle(pp.getTitle());
220
			//	cartItem.setTitle(pp.getTitle());
-
 
221
			}
219
		 * } }
222
		}
220
		 */
223
		vc = new ValidateCartResponse(cartValidationResponse, "Success", "Items added to cart successfully");
221
		vc = new ValidateCartResponse(cartValidationResponse, "Success", "Items added to cart successfully");
224
		return responseSender.ok(vc);
222
		return responseSender.ok(vc);
225
	}
223
	}
226
 
224
 
227
	@RequestMapping(value = ProfitMandiConstants.URL_CART_CHANGE_ADDRESS, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
225
	@RequestMapping(value = ProfitMandiConstants.URL_CART_CHANGE_ADDRESS, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
Line 359... Line 357...
359
 
357
 
360
		notificationService.sendNotification(sendNotificationModel);
358
		notificationService.sendNotification(sendNotificationModel);
361
 
359
 
362
		return responseSender.ok(true);
360
		return responseSender.ok(true);
363
	}
361
	}
-
 
362
	@Autowired
-
 
363
	WalletService walletService;
-
 
364
	
-
 
365
	@Autowired
-
 
366
	MandiiService mandiiService;
-
 
367
	
-
 
368
	@Autowired UserWalletHistoryRepository userWalletHistoryRepository;
-
 
369
	@RequestMapping(value = "/cart/payment", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
-
 
370
	public ResponseEntity<?> validateCartPayment(HttpServletRequest request,
-
 
371
			@RequestParam(defaultValue = "0") int paymentId, Model model) throws Exception {
-
 
372
		int userId = (int) request.getAttribute("userId");
-
 
373
		UserCart uc = userAccountRepository.getUserCart(userId);
-
 
374
 
-
 
375
		FofoPayment fofoPayment = fofoPaymentRepository.selectById(paymentId);
-
 
376
		if(fofoPayment==null || fofoPayment.getFofoId()!=uc.getUserId()) {
-
 
377
			return responseSender.ok(false);
-
 
378
		}
-
 
379
		String gatewayReference = fofoPayment.getGatewayReference();
-
 
380
		List<UserWalletHistory> historyList = userWalletHistoryRepository.selectAllByreferenceIdandreferenceType(paymentId, WalletReferenceType.PAYMENT_GATEWAY);
-
 
381
		if (fofoPayment.getStatus().equals(PaymentStatus.INIT) && historyList.size() == 0) {
-
 
382
			String jsonString = mandiiService.getOrderStatus(gatewayReference);
-
 
383
			JSONObject jsonOrder = new JSONObject(jsonString);
-
 
384
			double orderAmount = jsonOrder.getDouble("order_amount");
-
 
385
			int merchantOrderId = jsonOrder.getInt("merchant_order_number");
-
 
386
			if(orderAmount != fofoPayment.getAmount() || merchantOrderId != fofoPayment.getId()) {
-
 
387
				responseSender.ok(false);
-
 
388
			}
-
 
389
			fofoPayment.setStatus(PaymentStatus.SUCCESS);
-
 
390
			walletService.addAmountToWallet(uc.getUserId(), paymentId, WalletReferenceType.PAYMENT_GATEWAY, "Amount added to wallet via SD Credit via Mandii", (float)fofoPayment.getAmount(), LocalDateTime.now());
-
 
391
			
-
 
392
			return responseSender.ok(true);
-
 
393
		}
-
 
394
		return responseSender.ok(false);
-
 
395
	}
364
}
396
}
365
397