| 21277 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 23332 |
ashik.ali |
3 |
import java.util.HashMap;
|
|
|
4 |
import java.util.HashSet;
|
|
|
5 |
import java.util.List;
|
|
|
6 |
import java.util.Map;
|
|
|
7 |
import java.util.Set;
|
|
|
8 |
|
| 21277 |
ashik.ali |
9 |
import javax.servlet.http.HttpServletRequest;
|
|
|
10 |
|
| 23568 |
govind |
11 |
import org.apache.logging.log4j.Logger;
|
|
|
12 |
import org.apache.logging.log4j.LogManager;
|
| 21278 |
ashik.ali |
13 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21277 |
ashik.ali |
14 |
import org.springframework.http.ResponseEntity;
|
|
|
15 |
import org.springframework.stereotype.Controller;
|
| 21702 |
ashik.ali |
16 |
import org.springframework.transaction.annotation.Transactional;
|
| 21277 |
ashik.ali |
17 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
18 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
19 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
20 |
|
|
|
21 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 21740 |
ashik.ali |
22 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 23332 |
ashik.ali |
23 |
import com.spice.profitmandi.dao.entity.logistics.PostOffice;
|
| 21735 |
ashik.ali |
24 |
import com.spice.profitmandi.dao.repository.logistics.PostOfficeRepository;
|
| 21277 |
ashik.ali |
25 |
|
|
|
26 |
@Controller
|
| 35434 |
amit |
27 |
@Transactional(readOnly = true, rollbackFor = Throwable.class)
|
| 21277 |
ashik.ali |
28 |
public class PostOfficeController {
|
| 27113 |
tejbeer |
29 |
|
| 21448 |
ashik.ali |
30 |
@Autowired
|
| 22931 |
ashik.ali |
31 |
private ResponseSender<?> responseSender;
|
| 27113 |
tejbeer |
32 |
|
|
|
33 |
private static final Logger LOGGER = LogManager.getLogger(PostOfficeController.class);
|
|
|
34 |
|
| 21278 |
ashik.ali |
35 |
@Autowired
|
| 22931 |
ashik.ali |
36 |
private PostOfficeRepository postOfficeRepository;
|
| 27113 |
tejbeer |
37 |
|
|
|
38 |
@RequestMapping(value = ProfitMandiConstants.URL_POST_OFFICE, method = RequestMethod.GET)
|
|
|
39 |
public ResponseEntity<?> getByPin(HttpServletRequest request, @RequestParam(name = "pinCode") int pinCode) {
|
|
|
40 |
LOGGER.info("requested url : " + request.getRequestURL().toString());
|
| 23332 |
ashik.ali |
41 |
List<PostOffice> postOffices = postOfficeRepository.selectByPinCode(pinCode);
|
|
|
42 |
Set<String> cities = new HashSet<>();
|
|
|
43 |
Map<String, Object> map = new HashMap<>(3);
|
| 27113 |
tejbeer |
44 |
|
| 23332 |
ashik.ali |
45 |
map.put(ProfitMandiConstants.PIN_CODE, pinCode);
|
| 27113 |
tejbeer |
46 |
for (PostOffice postOffice : postOffices) {
|
| 23332 |
ashik.ali |
47 |
String city = postOffice.getCity();
|
| 27113 |
tejbeer |
48 |
if (city.equals("NA")) {
|
| 23332 |
ashik.ali |
49 |
cities.add(postOffice.getDistrict());
|
| 27113 |
tejbeer |
50 |
|
|
|
51 |
} else {
|
| 23332 |
ashik.ali |
52 |
cities.add(postOffice.getCity());
|
|
|
53 |
}
|
|
|
54 |
map.put(ProfitMandiConstants.STATE, postOffice.getState());
|
| 31599 |
amit.gupta |
55 |
String[] nameArr = postOffice.getCodeName().split( " ");
|
|
|
56 |
if(nameArr.length > 2)
|
|
|
57 |
cities.add(postOffice.getCodeName().split( " ")[0]);
|
| 23332 |
ashik.ali |
58 |
}
|
|
|
59 |
map.put(ProfitMandiConstants.CITIES, cities);
|
| 27113 |
tejbeer |
60 |
return responseSender.ok(map);
|
|
|
61 |
|
| 21277 |
ashik.ali |
62 |
}
|
|
|
63 |
}
|