| Line 108... |
Line 108... |
| 108 |
// EmployeeAttendance employeeAttendance =
|
108 |
// EmployeeAttendance employeeAttendance =
|
| 109 |
// employeeAttendanceRepository.selectLatestPunchTimeStamp();
|
109 |
// employeeAttendanceRepository.selectLatestPunchTimeStamp();
|
| 110 |
|
110 |
|
| 111 |
List<EmployeeAttendance> employeeAttendances = employeeAttendanceRepository.selectByUserIdKey(userId, deviceId,
|
111 |
List<EmployeeAttendance> employeeAttendances = employeeAttendanceRepository.selectByUserIdKey(userId, deviceId,
|
| 112 |
LocalDate.now());
|
112 |
LocalDate.now());
|
| 113 |
|
- |
|
| - |
|
113 |
EmployeeAttendanceModel em = null;
|
| 114 |
LOGGER.info("hyperTrackKey" + hyperTrackKey);
|
114 |
LOGGER.info("hyperTrackKey" + hyperTrackKey);
|
| 115 |
LOGGER.info("employeeAttendance" + employeeAttendances);
|
115 |
LOGGER.info("employeeAttendance" + employeeAttendances);
|
| 116 |
OkHttpClient client = new OkHttpClient();
|
116 |
OkHttpClient client = new OkHttpClient();
|
| 117 |
|
117 |
|
| 118 |
String authString = "Basic "
|
118 |
String authString = "Basic "
|
| Line 121... |
Line 121... |
| 121 |
Request request1 = new Request.Builder()
|
121 |
Request request1 = new Request.Builder()
|
| 122 |
.url("https://v3.api.hypertrack.com/devices/" + hyperTrackKey.getHypertrackKeyId()).get()
|
122 |
.url("https://v3.api.hypertrack.com/devices/" + hyperTrackKey.getHypertrackKeyId()).get()
|
| 123 |
.addHeader("Authorization", authString).build();
|
123 |
.addHeader("Authorization", authString).build();
|
| 124 |
|
124 |
|
| 125 |
Response response = client.newCall(request1).execute();
|
125 |
Response response = client.newCall(request1).execute();
|
| - |
|
126 |
|
| 126 |
JSONObject jsonObj = new JSONObject(response.body().string());
|
127 |
JSONObject jsonObj = new JSONObject(response.body().string());
|
| 127 |
JSONObject c = jsonObj.getJSONObject("location");
|
- |
|
| 128 |
JSONObject d = c.getJSONObject("geometry");
|
- |
|
| 129 |
JSONArray coords = d.getJSONArray("coordinates");
|
- |
|
| 130 |
|
128 |
|
| 131 |
double lat2 = coords.getDouble(1);
|
- |
|
| 132 |
double lng2 = coords.getDouble(0);
|
- |
|
| 133 |
double dist = distance(lat1, lng1, lat2, lng2, "m");
|
- |
|
| 134 |
LOGGER.info("jsonObj" + jsonObj);
|
- |
|
| 135 |
JSONObject deviceStatus = jsonObj.getJSONObject("device_status");
|
129 |
JSONObject deviceStatus = jsonObj.getJSONObject("device_status");
|
| 136 |
JSONObject deviceData = deviceStatus.getJSONObject("data");
|
- |
|
| 137 |
String status = deviceStatus.getString("value");
|
130 |
String status = deviceStatus.getString("value");
|
| 138 |
|
131 |
|
| - |
|
132 |
if (deviceStatus.equals("inactive") || deviceStatus.equals("disconnected")) {
|
| - |
|
133 |
|
| - |
|
134 |
Request request2 = new Request.Builder()
|
| - |
|
135 |
.url("https://v3.api.hypertrack.com/devices/" + hyperTrackKey.getHypertrackKeyId() + "/start")
|
| - |
|
136 |
.post(null).addHeader("Authorization", authString).build();
|
| - |
|
137 |
|
| - |
|
138 |
Response resp = client.newCall(request2).execute();
|
| - |
|
139 |
em.setPunchIn(false);
|
| - |
|
140 |
} else {
|
| - |
|
141 |
JSONObject c = jsonObj.getJSONObject("location");
|
| - |
|
142 |
JSONObject d = c.getJSONObject("geometry");
|
| - |
|
143 |
JSONArray coords = d.getJSONArray("coordinates");
|
| - |
|
144 |
|
| - |
|
145 |
double lat2 = coords.getDouble(1);
|
| - |
|
146 |
double lng2 = coords.getDouble(0);
|
| - |
|
147 |
double dist = distance(lat1, lng1, lat2, lng2, "m");
|
| - |
|
148 |
LOGGER.info("jsonObj" + jsonObj);
|
| - |
|
149 |
JSONObject deviceData = deviceStatus.getJSONObject("data");
|
| - |
|
150 |
|
| 139 |
EmployeeAttendanceModel em = new EmployeeAttendanceModel();
|
151 |
em = new EmployeeAttendanceModel();
|
| 140 |
em.setDistance(dist);
|
152 |
em.setDistance(dist);
|
| 141 |
em.setLatitude(lat2);
|
153 |
em.setLatitude(lat2);
|
| 142 |
em.setLongitude(lng2);
|
154 |
em.setLongitude(lng2);
|
| 143 |
em.setDeviceStatus(status);
|
155 |
em.setDeviceStatus(status);
|
| 144 |
|
156 |
|
| 145 |
if (!employeeAttendances.isEmpty()) {
|
157 |
if (!employeeAttendances.isEmpty()) {
|
| 146 |
if (employeeAttendances.get(0).getCreateTimestamp().toLocalDate().equals(LocalDate.now())) {
|
158 |
if (employeeAttendances.get(0).getCreateTimestamp().toLocalDate().equals(LocalDate.now())) {
|
| 147 |
if (employeeAttendances.get(0).getPunch().equals("punchIn")) {
|
159 |
if (employeeAttendances.get(0).getPunch().equals("punchIn")) {
|
| 148 |
em.setPunchIn(true);
|
160 |
em.setPunchIn(true);
|
| - |
|
161 |
} else {
|
| - |
|
162 |
em.setPunchIn(false);
|
| - |
|
163 |
}
|
| 149 |
} else {
|
164 |
} else {
|
| 150 |
em.setPunchIn(false);
|
165 |
em.setPunchIn(false);
|
| 151 |
}
|
166 |
}
|
| - |
|
167 |
|
| - |
|
168 |
if (employeeAttendances.get(0).getPunch().equals("punchOut")) {
|
| - |
|
169 |
LocalTime startTime = employeeAttendances.get(employeeAttendances.size() - 1).getCreateTimestamp()
|
| - |
|
170 |
.toLocalTime();
|
| - |
|
171 |
Long secondsBetween = ChronoUnit.SECONDS.between(startTime,
|
| - |
|
172 |
employeeAttendances.get(0).getCreateTimestamp().toLocalTime());
|
| - |
|
173 |
long hours = secondsBetween / 3600;
|
| - |
|
174 |
long minutes = (secondsBetween % 3600) / 60;
|
| - |
|
175 |
long seconds = secondsBetween % 60;
|
| - |
|
176 |
em.setPunchHours(hours);
|
| - |
|
177 |
em.setPunchMinutes(minutes);
|
| - |
|
178 |
em.setPunchSeconds(seconds);
|
| - |
|
179 |
|
| - |
|
180 |
} else if (employeeAttendances.get(employeeAttendances.size() - 1).getPunch().equals("punchIn")) {
|
| - |
|
181 |
LocalTime startTime = employeeAttendances.get(employeeAttendances.size() - 1).getCreateTimestamp()
|
| - |
|
182 |
.toLocalTime();
|
| - |
|
183 |
Long secondsBetween = ChronoUnit.SECONDS.between(startTime, LocalDateTime.now().toLocalTime());
|
| - |
|
184 |
long hours = secondsBetween / 3600;
|
| - |
|
185 |
long minutes = (secondsBetween % 3600) / 60;
|
| - |
|
186 |
long seconds = secondsBetween % 60;
|
| - |
|
187 |
em.setPunchHours(hours);
|
| - |
|
188 |
em.setPunchMinutes(minutes);
|
| - |
|
189 |
em.setPunchSeconds(seconds);
|
| - |
|
190 |
}
|
| - |
|
191 |
|
| 152 |
} else {
|
192 |
} else {
|
| 153 |
em.setPunchIn(false);
|
193 |
em.setPunchIn(false);
|
| 154 |
}
|
194 |
}
|
| 155 |
|
- |
|
| 156 |
if (employeeAttendances.get(0).getPunch().equals("punchOut")) {
|
- |
|
| 157 |
LocalTime startTime = employeeAttendances.get(employeeAttendances.size() - 1).getCreateTimestamp()
|
- |
|
| 158 |
.toLocalTime();
|
- |
|
| 159 |
Long secondsBetween = ChronoUnit.SECONDS.between(startTime,
|
- |
|
| 160 |
employeeAttendances.get(0).getCreateTimestamp().toLocalTime());
|
- |
|
| 161 |
long hours = secondsBetween / 3600;
|
- |
|
| 162 |
long minutes = (secondsBetween % 3600) / 60;
|
- |
|
| 163 |
long seconds = secondsBetween % 60;
|
- |
|
| 164 |
em.setPunchHours(hours);
|
- |
|
| 165 |
em.setPunchMinutes(minutes);
|
- |
|
| 166 |
em.setPunchSeconds(seconds);
|
- |
|
| 167 |
|
- |
|
| 168 |
} else if (employeeAttendances.get(employeeAttendances.size() - 1).getPunch().equals("punchIn")) {
|
- |
|
| 169 |
LocalTime startTime = employeeAttendances.get(employeeAttendances.size() - 1).getCreateTimestamp()
|
- |
|
| 170 |
.toLocalTime();
|
- |
|
| 171 |
Long secondsBetween = ChronoUnit.SECONDS.between(startTime, LocalDateTime.now().toLocalTime());
|
- |
|
| 172 |
long hours = secondsBetween / 3600;
|
- |
|
| 173 |
long minutes = (secondsBetween % 3600) / 60;
|
- |
|
| 174 |
long seconds = secondsBetween % 60;
|
- |
|
| 175 |
em.setPunchHours(hours);
|
- |
|
| 176 |
em.setPunchMinutes(minutes);
|
- |
|
| 177 |
em.setPunchSeconds(seconds);
|
- |
|
| 178 |
}
|
- |
|
| 179 |
|
- |
|
| 180 |
} else {
|
- |
|
| 181 |
em.setPunchIn(false);
|
- |
|
| 182 |
}
|
195 |
}
|
| 183 |
return responseSender.ok(em);
|
196 |
return responseSender.ok(em);
|
| 184 |
}
|
197 |
}
|
| 185 |
|
198 |
|
| 186 |
private static double distance(double lat1, double lon1, double lat2, double lon2, String unit) {
|
199 |
private static double distance(double lat1, double lon1, double lat2, double lon2, String unit) {
|