| 27176 |
tejbeer |
1 |
package com.spice.profitmandi.service;
|
|
|
2 |
|
|
|
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 |
|
|
|
9 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
10 |
import org.springframework.stereotype.Component;
|
|
|
11 |
|
|
|
12 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
13 |
import com.spice.profitmandi.dao.entity.logistics.PostOffice;
|
|
|
14 |
import com.spice.profitmandi.dao.repository.logistics.PostOfficeRepository;
|
|
|
15 |
|
|
|
16 |
@Component
|
|
|
17 |
public class PostOfficeServiceImpl implements PostOfficeService {
|
|
|
18 |
|
|
|
19 |
@Autowired
|
|
|
20 |
private PostOfficeRepository postOfficeRepository;
|
| 27365 |
amit.gupta |
21 |
private static final Map<Integer, String> pincodeCitiesMap = new HashMap<Integer, String>();
|
|
|
22 |
|
|
|
23 |
static {
|
|
|
24 |
pincodeCitiesMap.put(160104, "Ludhiana");
|
|
|
25 |
}
|
| 27176 |
tejbeer |
26 |
@Override
|
|
|
27 |
public Map<String, Object> getPOPincode(int pincode) {
|
|
|
28 |
List<PostOffice> postOffices = postOfficeRepository.selectByPinCode(pincode);
|
|
|
29 |
Set<String> cities = new HashSet<>();
|
| 27365 |
amit.gupta |
30 |
//Add custom pincodes to support the major cities;
|
|
|
31 |
if(pincodeCitiesMap.containsKey(pincode)) {
|
|
|
32 |
cities.add(pincodeCitiesMap.get(pincode));
|
|
|
33 |
}
|
| 27176 |
tejbeer |
34 |
Map<String, Object> map = new HashMap<>(3);
|
|
|
35 |
|
|
|
36 |
map.put(ProfitMandiConstants.PIN_CODE, pincode);
|
|
|
37 |
for (PostOffice postOffice : postOffices) {
|
|
|
38 |
String city = postOffice.getCity();
|
|
|
39 |
if (city.equals("NA")) {
|
|
|
40 |
cities.add(postOffice.getDistrict());
|
|
|
41 |
|
|
|
42 |
} else {
|
|
|
43 |
cities.add(postOffice.getCity());
|
|
|
44 |
}
|
|
|
45 |
map.put(ProfitMandiConstants.STATE, postOffice.getState());
|
|
|
46 |
}
|
|
|
47 |
map.put(ProfitMandiConstants.CITIES, cities);
|
|
|
48 |
return map;
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
}
|