| 27366 |
amit.gupta |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 27402 |
tejbeer |
3 |
import java.time.LocalDateTime;
|
|
|
4 |
import java.util.ArrayList;
|
|
|
5 |
import java.util.HashMap;
|
| 27366 |
amit.gupta |
6 |
import java.util.List;
|
| 27402 |
tejbeer |
7 |
import java.util.Map;
|
| 27366 |
amit.gupta |
8 |
|
|
|
9 |
import javax.servlet.http.HttpServletRequest;
|
|
|
10 |
|
|
|
11 |
import org.apache.logging.log4j.LogManager;
|
|
|
12 |
import org.apache.logging.log4j.Logger;
|
|
|
13 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
14 |
import org.springframework.stereotype.Controller;
|
|
|
15 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
16 |
import org.springframework.ui.Model;
|
|
|
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.google.gson.Gson;
|
| 27402 |
tejbeer |
22 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 27366 |
amit.gupta |
23 |
import com.spice.profitmandi.dao.entity.dtr.GpsLocation;
|
|
|
24 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
|
|
25 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
|
|
26 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
|
|
27 |
import com.spice.profitmandi.dao.repository.user.GpsLocationRepository;
|
|
|
28 |
|
|
|
29 |
@Controller
|
| 35458 |
amit |
30 |
@Transactional(rollbackFor = Throwable.class)
|
| 27366 |
amit.gupta |
31 |
public class MapTrackController {
|
|
|
32 |
|
|
|
33 |
private static final Logger LOGGER = LogManager.getLogger(PostOfficeController.class);
|
|
|
34 |
|
|
|
35 |
@Autowired
|
|
|
36 |
GpsLocationRepository gpsLocationRepository;
|
| 27402 |
tejbeer |
37 |
|
| 27366 |
amit.gupta |
38 |
@Autowired
|
|
|
39 |
UserRepository userRepository;
|
| 27402 |
tejbeer |
40 |
|
| 27366 |
amit.gupta |
41 |
@Autowired
|
|
|
42 |
AuthRepository authRepository;
|
| 27402 |
tejbeer |
43 |
|
| 27366 |
amit.gupta |
44 |
@Autowired
|
|
|
45 |
Gson gson;
|
| 27402 |
tejbeer |
46 |
|
|
|
47 |
@RequestMapping(value = "/authUserMapInfo", method = RequestMethod.GET)
|
|
|
48 |
public String AuthUserMapInfo(HttpServletRequest request, Model model) throws Exception {
|
|
|
49 |
|
|
|
50 |
List<AuthUser> authUsers = authRepository.selectAllActiveUser();
|
|
|
51 |
|
|
|
52 |
model.addAttribute("authUsers", authUsers);
|
|
|
53 |
return "map-info";
|
|
|
54 |
}
|
|
|
55 |
|
| 27366 |
amit.gupta |
56 |
@RequestMapping(value = "/map", method = RequestMethod.GET)
|
| 27402 |
tejbeer |
57 |
public String getByPin(HttpServletRequest request, @RequestParam List<String> emails,
|
|
|
58 |
@RequestParam LocalDateTime date, Model model) throws Exception {
|
|
|
59 |
Map<Integer, List<GpsLocation>> userIdAndLocationMap = new HashMap<>();
|
|
|
60 |
List<User> users = new ArrayList<>();
|
|
|
61 |
for (String email : emails) {
|
|
|
62 |
User dtrUser = userRepository.selectByEmailId(email);
|
|
|
63 |
|
|
|
64 |
List<GpsLocation> locations = gpsLocationRepository.selectAllByUserIdAndDate(dtrUser.getId(),
|
|
|
65 |
date.toLocalDate());
|
|
|
66 |
if (!locations.isEmpty()) {
|
|
|
67 |
userIdAndLocationMap.put(dtrUser.getId(), locations);
|
|
|
68 |
users.add(dtrUser);
|
|
|
69 |
}
|
|
|
70 |
}
|
|
|
71 |
LOGGER.info("locations {}", gson.toJson(userIdAndLocationMap));
|
|
|
72 |
model.addAttribute("userLocationMap", gson.toJson(userIdAndLocationMap));
|
|
|
73 |
model.addAttribute("users", gson.toJson(users));
|
| 27366 |
amit.gupta |
74 |
return "map-index";
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
}
|