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