Subversion Repositories SmartDukaan

Rev

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

Rev 27444 Rev 27445
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import java.io.IOException;
3
import java.io.IOException;
4
import java.time.LocalDate;
4
import java.time.LocalDate;
5
import java.time.LocalDateTime;
5
import java.time.LocalDateTime;
-
 
6
import java.time.LocalTime;
-
 
7
import java.time.temporal.ChronoUnit;
-
 
8
import java.util.ArrayList;
6
import java.util.Base64;
9
import java.util.Base64;
7
import java.util.List;
10
import java.util.List;
8
 
11
 
9
import javax.mail.MessagingException;
12
import javax.mail.MessagingException;
10
import javax.servlet.http.HttpServletRequest;
13
import javax.servlet.http.HttpServletRequest;
Line 23... Line 26...
23
import org.springframework.web.bind.annotation.RequestMapping;
26
import org.springframework.web.bind.annotation.RequestMapping;
24
import org.springframework.web.bind.annotation.RequestMethod;
27
import org.springframework.web.bind.annotation.RequestMethod;
25
import org.springframework.web.bind.annotation.RequestParam;
28
import org.springframework.web.bind.annotation.RequestParam;
26
 
29
 
27
import com.google.gson.Gson;
30
import com.google.gson.Gson;
-
 
31
import com.ibm.icu.impl.duration.Period;
28
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
32
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
29
import com.spice.profitmandi.common.model.CustomRetailer;
33
import com.spice.profitmandi.common.model.CustomRetailer;
30
import com.spice.profitmandi.common.web.util.ResponseSender;
34
import com.spice.profitmandi.common.web.util.ResponseSender;
31
import com.spice.profitmandi.dao.entity.dtr.EmployeeAttendance;
35
import com.spice.profitmandi.dao.entity.dtr.EmployeeAttendance;
32
import com.spice.profitmandi.dao.entity.dtr.HyperTrackKeyModel;
36
import com.spice.profitmandi.dao.entity.dtr.HyperTrackKeyModel;
Line 183... Line 187...
183
		employeeAttendance.setDeviceId(deviceId);
187
		employeeAttendance.setDeviceId(deviceId);
184
		employeeAttendance.setPunch(punch);
188
		employeeAttendance.setPunch(punch);
185
		employeeAttendance.setPunchType(punchType);
189
		employeeAttendance.setPunchType(punchType);
186
		employeeAttendance.setCreateTimestamp(LocalDateTime.now());
190
		employeeAttendance.setCreateTimestamp(LocalDateTime.now());
187
		employeeAttendanceRepository.persist(employeeAttendance);
191
		employeeAttendanceRepository.persist(employeeAttendance);
-
 
192
		if (punch.equals("punchOut")) {
-
 
193
			List<EmployeeAttendance> employeeAttendances = employeeAttendanceRepository.selectByUserIdKeyASC(userId,
-
 
194
					deviceId, LocalDate.now());
-
 
195
			long hours = 0;
-
 
196
			long minutes = 0;
-
 
197
			long seconds = 0;
-
 
198
			LocalDateTime startTime = null;
-
 
199
			LocalDateTime endTime = null;
-
 
200
 
-
 
201
			for (EmployeeAttendance em : employeeAttendances) {
-
 
202
				if (em.getPunch().equals("punchIn")) {
-
 
203
					startTime = em.getCreateTimestamp();
-
 
204
				} else if (em.getPunch().equals("punchOut")) {
-
 
205
					endTime = em.getCreateTimestamp();
-
 
206
				}
-
 
207
				if (startTime != null && endTime != null) {
-
 
208
					long mites = ChronoUnit.MINUTES.between(startTime, endTime);
-
 
209
					long hour = ChronoUnit.HOURS.between(startTime, endTime);
-
 
210
					long secds = ChronoUnit.SECONDS.between(startTime, endTime);
-
 
211
					hours = hours + hour;
-
 
212
					minutes = minutes + mites;
-
 
213
					if (minutes >= 60) {
-
 
214
						minutes = minutes - 60;
-
 
215
					}
-
 
216
					seconds = seconds + secds;
-
 
217
					if (seconds >= 60) {
-
 
218
						seconds = seconds - 60;
-
 
219
					}
-
 
220
 
-
 
221
					startTime = null;
-
 
222
					endTime = null;
-
 
223
				}
-
 
224
 
-
 
225
			}
-
 
226
			LOGGER.info("employeeAttendance" + employeeAttendances);
-
 
227
 
-
 
228
			EmployeeAttendanceModel emm = new EmployeeAttendanceModel();
-
 
229
			emm.setHours(hours);
-
 
230
			emm.setMinutes(minutes);
-
 
231
			emm.setSeconds(seconds);
-
 
232
			return responseSender.ok(emm);
-
 
233
 
-
 
234
		}
188
		return responseSender.ok(true);
235
		return responseSender.ok(true);
189
	}
236
	}
190
 
237
 
191
	@RequestMapping(value = "/create/geofence", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
238
	@RequestMapping(value = "/create/geofence", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
192
	public ResponseEntity<?> createGreofence(HttpServletRequest request)
239
	public ResponseEntity<?> createGeofence(HttpServletRequest request)
193
			throws IOException, ProfitMandiBusinessException {
240
			throws IOException, ProfitMandiBusinessException {
194
 
241
 
195
		List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
242
		List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
196
		for (FofoStore fofoStore : fofoStores) {
243
		for (FofoStore fofoStore : fofoStores) {
197
			CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoStore.getId());
244
			CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoStore.getId());
Line 228... Line 275...
228
		}
275
		}
229
		return responseSender.ok(true);
276
		return responseSender.ok(true);
230
 
277
 
231
	}
278
	}
232
 
279
 
233
	@RequestMapping(value = "/device/status", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
280
	@RequestMapping(value = "/employee/hourcacl", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
234
	@ApiImplicitParams({
281
	public ResponseEntity<?> workingHourCalculation(HttpServletRequest request,
235
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
282
			@RequestParam(name = "userId") int userId, @RequestParam(name = "deviceId") int deviceId,
236
	@ApiOperation(value = "")
-
 
237
	public ResponseEntity<?> deviceStatus(HttpServletRequest request, @RequestParam String hyperTrackKey)
283
			@RequestParam(name = "punchType") PunchType punchType, @RequestParam(name = "punch") String punch) {
238
			throws IOException {
-
 
239
		OkHttpClient client = new OkHttpClient();
-
 
240
 
284
 
-
 
285
		EmployeeAttendance employeeAttendance = new EmployeeAttendance();
-
 
286
		employeeAttendance.setUserId(userId);
-
 
287
		employeeAttendance.setDeviceId(deviceId);
241
		String authString = "Basic "
288
		employeeAttendance.setPunch(punch);
-
 
289
		employeeAttendance.setPunchType(punchType);
242
				+ Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
290
		employeeAttendance.setCreateTimestamp(LocalDateTime.now());
-
 
291
		employeeAttendanceRepository.persist(employeeAttendance);
243
 
292
 
244
		Request request1 = new Request.Builder().url("https://v3.api.hypertrack.com/devices/" + hyperTrackKey).get()
293
		List<EmployeeAttendance> employeeAttendances = employeeAttendanceRepository.selectByUserIdKeyASC(userId,
-
 
294
				deviceId, LocalDate.now());
-
 
295
		long hours = 0;
-
 
296
		long minutes = 0;
-
 
297
		long seconds = 0;
-
 
298
		LocalDateTime startTime = null;
-
 
299
		LocalDateTime endTime = null;
-
 
300
		List<Long> hghg = new ArrayList<>();
-
 
301
 
-
 
302
		for (EmployeeAttendance em : employeeAttendances) {
-
 
303
			if (em.getPunch().equals("punchIn")) {
-
 
304
				startTime = em.getCreateTimestamp();
-
 
305
			} else if (em.getPunch().equals("punchOut")) {
245
				.addHeader("Authorization", authString).build();
306
				endTime = em.getCreateTimestamp();
-
 
307
			}
-
 
308
			if (startTime != null && endTime != null) {
-
 
309
				long mites = ChronoUnit.MINUTES.between(startTime, endTime);
-
 
310
				long hour = ChronoUnit.HOURS.between(startTime, endTime);
-
 
311
				long secds = ChronoUnit.SECONDS.between(startTime, endTime);
-
 
312
				hours = hours + hour;
-
 
313
				minutes = minutes + mites;
-
 
314
				if (minutes >= 60) {
-
 
315
					minutes = minutes - 60;
-
 
316
				}
-
 
317
				seconds = seconds + secds;
-
 
318
				if (seconds >= 60) {
-
 
319
					seconds = seconds - 60;
-
 
320
				}
246
 
321
 
247
		Response response = client.newCall(request1).execute();
322
				startTime = null;
248
		return responseSender.ok(response.body().string());
323
				endTime = null;
-
 
324
			}
249
 
325
 
250
	}
326
		}
-
 
327
		LOGGER.info("employeeAttendance" + employeeAttendances);
251
 
328
 
-
 
329
		EmployeeAttendanceModel emm = new EmployeeAttendanceModel();
-
 
330
		emm.setHours(hours);
-
 
331
		emm.setMinutes(minutes);
-
 
332
		emm.setSeconds(seconds);
-
 
333
		return responseSender.ok(emm);
-
 
334
 
-
 
335
	}
252
}
336
}