| 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;
|
| 21378 |
kshitij.so |
10 |
|
|
|
11 |
import javax.servlet.http.HttpServletRequest;
|
|
|
12 |
|
| 23959 |
amit.gupta |
13 |
import org.apache.logging.log4j.LogManager;
|
|
|
14 |
import org.apache.logging.log4j.Logger;
|
| 21378 |
kshitij.so |
15 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
16 |
import org.springframework.http.MediaType;
|
|
|
17 |
import org.springframework.http.ResponseEntity;
|
|
|
18 |
import org.springframework.stereotype.Controller;
|
| 21707 |
amit.gupta |
19 |
import org.springframework.transaction.annotation.Transactional;
|
| 28742 |
tejbeer |
20 |
import org.springframework.ui.Model;
|
| 21378 |
kshitij.so |
21 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
22 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
23 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 21393 |
amit.gupta |
24 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 21378 |
kshitij.so |
25 |
|
| 28742 |
tejbeer |
26 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
|
|
27 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
28 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 21378 |
kshitij.so |
29 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 28742 |
tejbeer |
30 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
| 21741 |
ashik.ali |
31 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 28653 |
amit.gupta |
32 |
import com.spice.profitmandi.dao.cart.CartService;
|
| 28742 |
tejbeer |
33 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
|
|
34 |
import com.spice.profitmandi.dao.entity.catalog.FocusedModelByPassRequest;
|
|
|
35 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
|
|
36 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
| 23273 |
ashik.ali |
37 |
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
|
| 28742 |
tejbeer |
38 |
import com.spice.profitmandi.dao.enumuration.catalog.ByPassRequestStatus;
|
|
|
39 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 21735 |
ashik.ali |
40 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
| 26607 |
amit.gupta |
41 |
import com.spice.profitmandi.dao.model.AddCartRequest;
|
|
|
42 |
import com.spice.profitmandi.dao.model.CartItem;
|
| 28653 |
amit.gupta |
43 |
import com.spice.profitmandi.dao.model.CartItemResponseModel;
|
| 26607 |
amit.gupta |
44 |
import com.spice.profitmandi.dao.model.CartResponse;
|
| 21378 |
kshitij.so |
45 |
import com.spice.profitmandi.dao.model.ProductPojo;
|
| 21738 |
amit.gupta |
46 |
import com.spice.profitmandi.dao.model.UserCart;
|
| 28742 |
tejbeer |
47 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
|
|
48 |
import com.spice.profitmandi.dao.repository.catalog.FocusedModelByPassRepository;
|
| 23360 |
amit.gupta |
49 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 28742 |
tejbeer |
50 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
|
|
51 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
| 21735 |
ashik.ali |
52 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 28742 |
tejbeer |
53 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 21643 |
ashik.ali |
54 |
import com.spice.profitmandi.dao.util.ContentPojoPopulator;
|
| 28742 |
tejbeer |
55 |
import com.spice.profitmandi.service.FofoUser;
|
|
|
56 |
import com.spice.profitmandi.service.NotificationService;
|
|
|
57 |
import com.spice.profitmandi.service.PartnerInvestmentService;
|
|
|
58 |
import com.spice.profitmandi.service.inventory.ByPassRequestModel;
|
| 25962 |
amit.gupta |
59 |
import com.spice.profitmandi.service.inventory.ItemBucketService;
|
| 28742 |
tejbeer |
60 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 21378 |
kshitij.so |
61 |
import com.spice.profitmandi.thrift.clients.UserClient;
|
|
|
62 |
import com.spice.profitmandi.web.res.ValidateCartResponse;
|
|
|
63 |
|
|
|
64 |
import in.shop2020.model.v1.user.ItemQuantity;
|
| 21393 |
amit.gupta |
65 |
import in.shop2020.model.v1.user.UserContextService;
|
| 21378 |
kshitij.so |
66 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
67 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
68 |
import io.swagger.annotations.ApiOperation;
|
|
|
69 |
|
|
|
70 |
@Controller
|
| 24199 |
amit.gupta |
71 |
@Transactional(rollbackFor = Throwable.class)
|
| 21378 |
kshitij.so |
72 |
public class CartController {
|
|
|
73 |
|
| 24199 |
amit.gupta |
74 |
private static final Logger logger = LogManager.getLogger(CartController.class);
|
|
|
75 |
|
| 21440 |
ashik.ali |
76 |
@Autowired
|
| 22931 |
ashik.ali |
77 |
private ResponseSender<?> responseSender;
|
| 21378 |
kshitij.so |
78 |
|
|
|
79 |
@Autowired
|
| 22931 |
ashik.ali |
80 |
private UserAccountRepository userAccountRepository;
|
| 24199 |
amit.gupta |
81 |
|
| 22173 |
amit.gupta |
82 |
@Autowired
|
| 25962 |
amit.gupta |
83 |
private ItemBucketService itemBucketService;
|
|
|
84 |
|
|
|
85 |
@Autowired
|
| 28653 |
amit.gupta |
86 |
CartService cartService;
|
|
|
87 |
|
|
|
88 |
@Autowired
|
| 22931 |
ashik.ali |
89 |
private ContentPojoPopulator contentPojoPopulator;
|
| 24199 |
amit.gupta |
90 |
|
| 23360 |
amit.gupta |
91 |
@Autowired
|
|
|
92 |
private ItemRepository itemRepository;
|
| 21378 |
kshitij.so |
93 |
|
| 28742 |
tejbeer |
94 |
@Autowired
|
|
|
95 |
private UserRepository userRepository;
|
|
|
96 |
|
|
|
97 |
@Autowired
|
|
|
98 |
private AuthRepository authRepository;
|
|
|
99 |
|
|
|
100 |
@Autowired
|
|
|
101 |
private CsService csService;
|
|
|
102 |
|
|
|
103 |
@Autowired
|
|
|
104 |
private PositionRepository positionRepository;
|
|
|
105 |
|
|
|
106 |
@Autowired
|
|
|
107 |
private FocusedModelByPassRepository focusedModelByPassRepository;
|
|
|
108 |
|
|
|
109 |
@Autowired
|
|
|
110 |
private RetailerService retailerService;
|
|
|
111 |
|
|
|
112 |
@Autowired
|
|
|
113 |
private PartnerInvestmentService partnerInvestmentService;
|
|
|
114 |
|
|
|
115 |
@Autowired
|
|
|
116 |
private FofoUser fofoUser;
|
| 28743 |
tejbeer |
117 |
|
| 28742 |
tejbeer |
118 |
@Autowired
|
|
|
119 |
private NotificationService notificationService;
|
|
|
120 |
|
| 24422 |
amit.gupta |
121 |
public static final Map<String, Integer> MIN_BRAND_QTY_LIMIT = new HashMap<>();
|
|
|
122 |
|
| 28742 |
tejbeer |
123 |
List<EscalationType> esclationType = Arrays.asList(EscalationType.L3, EscalationType.L4);
|
|
|
124 |
|
|
|
125 |
List<String> emails = Arrays.asList("kamini.sharma@smartdukaan.com", "tarun.verma@smartdukaan.com");
|
|
|
126 |
|
| 24422 |
amit.gupta |
127 |
static {
|
| 25962 |
amit.gupta |
128 |
// MIN_BRAND_QTY_LIMIT.put("Realme", 10);
|
| 24464 |
amit.gupta |
129 |
MIN_BRAND_QTY_LIMIT.put("Reliance", 5);
|
| 24422 |
amit.gupta |
130 |
}
|
|
|
131 |
|
| 25962 |
amit.gupta |
132 |
@RequestMapping(value = ProfitMandiConstants.URL_CART, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
133 |
@ApiImplicitParams({
|
|
|
134 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
135 |
@ApiOperation(value = "Add items to cart")
|
|
|
136 |
public ResponseEntity<?> validateCart(HttpServletRequest request,
|
|
|
137 |
@RequestParam(value = "pincode", defaultValue = "110001") String pincode, @RequestParam int bucketId)
|
|
|
138 |
throws Throwable {
|
|
|
139 |
|
|
|
140 |
AddCartRequest cartRequest = new AddCartRequest();
|
| 26607 |
amit.gupta |
141 |
List<CartItem> ci = new ArrayList<>();
|
| 25962 |
amit.gupta |
142 |
itemBucketService.getBucketDetails(bucketId).stream().forEach(x -> {
|
| 28653 |
amit.gupta |
143 |
ci.add(new CartItem(x.getQuantity(), x.getItemId()));
|
| 25962 |
amit.gupta |
144 |
});
|
| 26607 |
amit.gupta |
145 |
cartRequest.setCartItems(ci);
|
| 25962 |
amit.gupta |
146 |
return this.validateCart(request, cartRequest, "110001");
|
|
|
147 |
|
|
|
148 |
}
|
|
|
149 |
|
| 24199 |
amit.gupta |
150 |
@RequestMapping(value = ProfitMandiConstants.URL_CART, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 21378 |
kshitij.so |
151 |
@ApiImplicitParams({
|
| 24199 |
amit.gupta |
152 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 21378 |
kshitij.so |
153 |
@ApiOperation(value = "Add items to cart")
|
| 24199 |
amit.gupta |
154 |
public ResponseEntity<?> validateCart(HttpServletRequest request, @RequestBody AddCartRequest cartRequest,
|
|
|
155 |
@RequestParam(value = "pincode", defaultValue = "110001") String pincode) throws Throwable {
|
| 23273 |
ashik.ali |
156 |
UserAccount userAccount = null;
|
| 21378 |
kshitij.so |
157 |
ValidateCartResponse vc = null;
|
| 24199 |
amit.gupta |
158 |
int userId = (int) request.getAttribute("userId");
|
|
|
159 |
|
| 28653 |
amit.gupta |
160 |
int cartId = userAccountRepository.selectByUserIdType(userId, AccountType.cartId).getAccountKey();
|
| 26607 |
amit.gupta |
161 |
List<CartItem> cartItems = cartRequest.getCartItems();
|
| 28653 |
amit.gupta |
162 |
cartService.addItemsToCart(cartId, cartItems);
|
|
|
163 |
CartResponse cartValidationResponse = cartService.getCartValidation(cartId);
|
|
|
164 |
for (CartItemResponseModel cartItem : cartValidationResponse.getCartItems()) {
|
|
|
165 |
ProductPojo pp = contentPojoPopulator.getShortContent(cartItem.getCatalogItemId());
|
| 28742 |
tejbeer |
166 |
if (pp != null) {
|
| 28653 |
amit.gupta |
167 |
cartItem.setImageUrl(pp.getImageUrl());
|
|
|
168 |
cartItem.setTitle(pp.getTitle());
|
| 24153 |
amit.gupta |
169 |
}
|
|
|
170 |
}
|
| 28653 |
amit.gupta |
171 |
vc = new ValidateCartResponse(cartValidationResponse, "Success", "Items added to cart successfully");
|
| 23021 |
ashik.ali |
172 |
return responseSender.ok(vc);
|
| 21378 |
kshitij.so |
173 |
}
|
| 21393 |
amit.gupta |
174 |
|
| 24199 |
amit.gupta |
175 |
@RequestMapping(value = ProfitMandiConstants.URL_CART_CHANGE_ADDRESS, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 21393 |
amit.gupta |
176 |
@ApiImplicitParams({
|
| 24199 |
amit.gupta |
177 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
178 |
|
| 21393 |
amit.gupta |
179 |
@ApiOperation(value = "Change address")
|
| 24199 |
amit.gupta |
180 |
public ResponseEntity<?> changeAddress(HttpServletRequest request,
|
|
|
181 |
@RequestParam(value = "addressId") long addressId) throws Throwable {
|
|
|
182 |
UserCart uc = userAccountRepository.getUserCart((int) request.getAttribute("userId"));
|
| 28653 |
amit.gupta |
183 |
cartService.addAddressToCart(uc.getCartId(), addressId);
|
| 24199 |
amit.gupta |
184 |
return responseSender.ok("Address Changed successfully");
|
|
|
185 |
}
|
| 28742 |
tejbeer |
186 |
|
|
|
187 |
@RequestMapping(value = "/planogram", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
188 |
@ApiImplicitParams({
|
|
|
189 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
190 |
|
|
|
191 |
@ApiOperation(value = "planogram")
|
|
|
192 |
public ResponseEntity<?> Planogram(HttpServletRequest request, Model model) throws Exception {
|
|
|
193 |
|
|
|
194 |
int userId = (int) request.getAttribute("userId");
|
|
|
195 |
logger.info(" userId" + userId);
|
|
|
196 |
|
| 28743 |
tejbeer |
197 |
User user = userRepository.selectById(userId);
|
| 28742 |
tejbeer |
198 |
logger.info(" user" + user);
|
|
|
199 |
AuthUser authUser = authRepository.selectByEmailOrMobile(user.getEmailId());
|
|
|
200 |
logger.info("authUser" + authUser);
|
|
|
201 |
List<FocusedModelByPassRequest> byPassRequests = null;
|
|
|
202 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
|
|
203 |
|
|
|
204 |
Set<Integer> authfofoIds = null;
|
|
|
205 |
|
|
|
206 |
List<Position> positions = positionRepository.selectPositionByAuthId(authUser.getId());
|
|
|
207 |
|
|
|
208 |
if (emails.contains(authUser.getEmailId())) {
|
|
|
209 |
authfofoIds = storeGuyMap.get("tarun.verma@smartdukaan.com");
|
|
|
210 |
logger.info("authfofoeIds" + authfofoIds);
|
|
|
211 |
|
|
|
212 |
} else {
|
|
|
213 |
|
|
|
214 |
for (Position ps : positions) {
|
|
|
215 |
if (esclationType.contains(ps.getEscalationType())) {
|
|
|
216 |
authfofoIds = storeGuyMap.get(user.getEmailId());
|
|
|
217 |
logger.info("authfofoIdsw" + authfofoIds);
|
|
|
218 |
|
|
|
219 |
break;
|
|
|
220 |
}
|
|
|
221 |
|
|
|
222 |
}
|
|
|
223 |
}
|
|
|
224 |
logger.info("authfofoIds" + authfofoIds);
|
|
|
225 |
if (authfofoIds != null) {
|
|
|
226 |
byPassRequests = focusedModelByPassRepository.selectByStatusAndFofoIds(new ArrayList<>(authfofoIds),
|
|
|
227 |
ByPassRequestStatus.PENDING);
|
|
|
228 |
}
|
|
|
229 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
|
|
230 |
List<ByPassRequestModel> byPassList = new ArrayList<>();
|
|
|
231 |
|
|
|
232 |
for (FocusedModelByPassRequest byPassRequest : byPassRequests) {
|
|
|
233 |
Map<String, Object> investments = fofoUser.getInvestments(byPassRequest.getFofoId());
|
|
|
234 |
ByPassRequestModel bp = new ByPassRequestModel();
|
|
|
235 |
bp.setPartnerName(customRetailerMap.get(byPassRequest.getFofoId()).getBusinessName());
|
|
|
236 |
bp.setCity(customRetailerMap.get(byPassRequest.getFofoId()).getAddress().getCity());
|
|
|
237 |
bp.setState(customRetailerMap.get(byPassRequest.getFofoId()).getAddress().getState());
|
|
|
238 |
bp.setCode(customRetailerMap.get(byPassRequest.getFofoId()).getCode());
|
|
|
239 |
bp.setStatus(byPassRequest.getStatus());
|
|
|
240 |
bp.setFofoId(byPassRequest.getFofoId());
|
|
|
241 |
bp.setByPassRequestId(byPassRequest.getId());
|
|
|
242 |
bp.setInvestmentOkDays((Long) investments.get("okDays"));
|
|
|
243 |
bp.setInvestmentShort((int) investments.get("short"));
|
|
|
244 |
bp.setMobileNumber(customRetailerMap.get(byPassRequest.getFofoId()).getMobileNumber());
|
|
|
245 |
bp.setCreateTimestamp(byPassRequest.getCreatedTimeStamp());
|
|
|
246 |
bp.setUpdateTimestamp(byPassRequest.getUpdatedTimestamp());
|
|
|
247 |
byPassList.add(bp);
|
|
|
248 |
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
return responseSender.ok(byPassList);
|
|
|
252 |
}
|
|
|
253 |
|
|
|
254 |
@RequestMapping(value = "/byPassRequestAction", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
255 |
@ApiImplicitParams({
|
|
|
256 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
257 |
@ApiOperation(value = "Add items to cart")
|
|
|
258 |
public ResponseEntity<?> addAmountToWalletRequestRejected(HttpServletRequest request,
|
|
|
259 |
@RequestParam(name = "id", defaultValue = "0") int id, @RequestParam ByPassRequestStatus status,
|
|
|
260 |
Model model) throws Exception {
|
|
|
261 |
|
|
|
262 |
FocusedModelByPassRequest byPassRequest = focusedModelByPassRepository.selectById(id);
|
|
|
263 |
if (status.equals(ByPassRequestStatus.APPROVED)) {
|
|
|
264 |
byPassRequest.setByPass(true);
|
|
|
265 |
byPassRequest.setStatus(ByPassRequestStatus.APPROVED);
|
|
|
266 |
byPassRequest.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
267 |
} else if (status.equals(ByPassRequestStatus.REJECTED)) {
|
|
|
268 |
byPassRequest.setByPass(false);
|
|
|
269 |
byPassRequest.setStatus(ByPassRequestStatus.REJECTED);
|
|
|
270 |
byPassRequest.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
271 |
}
|
|
|
272 |
|
|
|
273 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
274 |
sendNotificationModel.setCampaignName("Billing Request");
|
|
|
275 |
sendNotificationModel.setTitle("Billing Request");
|
|
|
276 |
sendNotificationModel.setMessage(String.format("Your Billing Request is " + " " + status
|
| 28745 |
tejbeer |
277 |
+ ". Please ensure to order the missing focus models as soon as possible"));
|
| 28742 |
tejbeer |
278 |
sendNotificationModel.setType("url");
|
|
|
279 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
|
|
280 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
|
|
281 |
sendNotificationModel.setMessageType(MessageType.notification);
|
|
|
282 |
sendNotificationModel
|
|
|
283 |
.setUserIds(Arrays.asList(userAccountRepository.selectUserIdByRetailerId(byPassRequest.getFofoId())));
|
|
|
284 |
|
|
|
285 |
notificationService.sendNotification(sendNotificationModel);
|
|
|
286 |
|
|
|
287 |
return responseSender.ok(true);
|
|
|
288 |
}
|
| 21378 |
kshitij.so |
289 |
}
|