Subversion Repositories SmartDukaan

Rev

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

Rev 28653 Rev 28742
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.util.ArrayList;
4
import java.util.ArrayList;
-
 
5
import java.util.Arrays;
4
import java.util.HashMap;
6
import java.util.HashMap;
5
import java.util.List;
7
import java.util.List;
6
import java.util.Map;
8
import java.util.Map;
-
 
9
import java.util.Set;
7
 
10
 
8
import javax.servlet.http.HttpServletRequest;
11
import javax.servlet.http.HttpServletRequest;
9
 
12
 
10
import org.apache.logging.log4j.LogManager;
13
import org.apache.logging.log4j.LogManager;
11
import org.apache.logging.log4j.Logger;
14
import org.apache.logging.log4j.Logger;
12
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.http.MediaType;
16
import org.springframework.http.MediaType;
14
import org.springframework.http.ResponseEntity;
17
import org.springframework.http.ResponseEntity;
15
import org.springframework.stereotype.Controller;
18
import org.springframework.stereotype.Controller;
16
import org.springframework.transaction.annotation.Transactional;
19
import org.springframework.transaction.annotation.Transactional;
-
 
20
import org.springframework.ui.Model;
17
import org.springframework.web.bind.annotation.RequestBody;
21
import org.springframework.web.bind.annotation.RequestBody;
18
import org.springframework.web.bind.annotation.RequestMapping;
22
import org.springframework.web.bind.annotation.RequestMapping;
19
import org.springframework.web.bind.annotation.RequestMethod;
23
import org.springframework.web.bind.annotation.RequestMethod;
20
import org.springframework.web.bind.annotation.RequestParam;
24
import org.springframework.web.bind.annotation.RequestParam;
21
 
25
 
-
 
26
import com.spice.profitmandi.common.enumuration.MessageType;
-
 
27
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
-
 
28
import com.spice.profitmandi.common.model.CustomRetailer;
22
import com.spice.profitmandi.common.model.ProfitMandiConstants;
29
import com.spice.profitmandi.common.model.ProfitMandiConstants;
-
 
30
import com.spice.profitmandi.common.model.SendNotificationModel;
23
import com.spice.profitmandi.common.web.util.ResponseSender;
31
import com.spice.profitmandi.common.web.util.ResponseSender;
24
import com.spice.profitmandi.dao.cart.CartService;
32
import com.spice.profitmandi.dao.cart.CartService;
-
 
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;
25
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
37
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
-
 
38
import com.spice.profitmandi.dao.enumuration.catalog.ByPassRequestStatus;
-
 
39
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
26
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
40
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
27
import com.spice.profitmandi.dao.model.AddCartRequest;
41
import com.spice.profitmandi.dao.model.AddCartRequest;
28
import com.spice.profitmandi.dao.model.CartItem;
42
import com.spice.profitmandi.dao.model.CartItem;
29
import com.spice.profitmandi.dao.model.CartItemResponseModel;
43
import com.spice.profitmandi.dao.model.CartItemResponseModel;
30
import com.spice.profitmandi.dao.model.CartResponse;
44
import com.spice.profitmandi.dao.model.CartResponse;
31
import com.spice.profitmandi.dao.model.ProductPojo;
45
import com.spice.profitmandi.dao.model.ProductPojo;
32
import com.spice.profitmandi.dao.model.UserCart;
46
import com.spice.profitmandi.dao.model.UserCart;
-
 
47
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
-
 
48
import com.spice.profitmandi.dao.repository.catalog.FocusedModelByPassRepository;
33
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
49
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
-
 
50
import com.spice.profitmandi.dao.repository.cs.CsService;
-
 
51
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
34
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
52
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
-
 
53
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
35
import com.spice.profitmandi.dao.util.ContentPojoPopulator;
54
import com.spice.profitmandi.dao.util.ContentPojoPopulator;
-
 
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;
36
import com.spice.profitmandi.service.inventory.ItemBucketService;
59
import com.spice.profitmandi.service.inventory.ItemBucketService;
-
 
60
import com.spice.profitmandi.service.user.RetailerService;
37
import com.spice.profitmandi.thrift.clients.UserClient;
61
import com.spice.profitmandi.thrift.clients.UserClient;
38
import com.spice.profitmandi.web.res.ValidateCartResponse;
62
import com.spice.profitmandi.web.res.ValidateCartResponse;
39
 
63
 
40
import in.shop2020.model.v1.user.ItemQuantity;
64
import in.shop2020.model.v1.user.ItemQuantity;
41
import in.shop2020.model.v1.user.UserContextService;
65
import in.shop2020.model.v1.user.UserContextService;
Line 65... Line 89...
65
	private ContentPojoPopulator contentPojoPopulator;
89
	private ContentPojoPopulator contentPojoPopulator;
66
 
90
 
67
	@Autowired
91
	@Autowired
68
	private ItemRepository itemRepository;
92
	private ItemRepository itemRepository;
69
 
93
 
-
 
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;
-
 
117
	
-
 
118
	@Autowired
-
 
119
	private NotificationService notificationService;
-
 
120
 
70
	public static final Map<String, Integer> MIN_BRAND_QTY_LIMIT = new HashMap<>();
121
	public static final Map<String, Integer> MIN_BRAND_QTY_LIMIT = new HashMap<>();
71
 
122
 
-
 
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
 
72
	static {
127
	static {
73
		// MIN_BRAND_QTY_LIMIT.put("Realme", 10);
128
		// MIN_BRAND_QTY_LIMIT.put("Realme", 10);
74
		MIN_BRAND_QTY_LIMIT.put("Reliance", 5);
129
		MIN_BRAND_QTY_LIMIT.put("Reliance", 5);
75
	}
130
	}
76
 
131
 
Line 106... Line 161...
106
		List<CartItem> cartItems = cartRequest.getCartItems();
161
		List<CartItem> cartItems = cartRequest.getCartItems();
107
		cartService.addItemsToCart(cartId, cartItems);
162
		cartService.addItemsToCart(cartId, cartItems);
108
		CartResponse cartValidationResponse = cartService.getCartValidation(cartId);
163
		CartResponse cartValidationResponse = cartService.getCartValidation(cartId);
109
		for (CartItemResponseModel cartItem : cartValidationResponse.getCartItems()) {
164
		for (CartItemResponseModel cartItem : cartValidationResponse.getCartItems()) {
110
			ProductPojo pp = contentPojoPopulator.getShortContent(cartItem.getCatalogItemId());
165
			ProductPojo pp = contentPojoPopulator.getShortContent(cartItem.getCatalogItemId());
111
			if(pp!=null) {
166
			if (pp != null) {
112
				cartItem.setImageUrl(pp.getImageUrl());
167
				cartItem.setImageUrl(pp.getImageUrl());
113
				cartItem.setTitle(pp.getTitle());
168
				cartItem.setTitle(pp.getTitle());
114
			}
169
			}
115
		}
170
		}
116
		vc = new ValidateCartResponse(cartValidationResponse, "Success", "Items added to cart successfully");
171
		vc = new ValidateCartResponse(cartValidationResponse, "Success", "Items added to cart successfully");
Line 126... Line 181...
126
			@RequestParam(value = "addressId") long addressId) throws Throwable {
181
			@RequestParam(value = "addressId") long addressId) throws Throwable {
127
		UserCart uc = userAccountRepository.getUserCart((int) request.getAttribute("userId"));
182
		UserCart uc = userAccountRepository.getUserCart((int) request.getAttribute("userId"));
128
		cartService.addAddressToCart(uc.getCartId(), addressId);
183
		cartService.addAddressToCart(uc.getCartId(), addressId);
129
		return responseSender.ok("Address Changed successfully");
184
		return responseSender.ok("Address Changed successfully");
130
	}
185
	}
-
 
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
 
-
 
197
		User user = userRepository.selectById(39411);
-
 
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
-
 
277
				+ "Please ensure to order the missing focus models as soon as possible"));
-
 
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
	}
131
}
289
}
132
290