Subversion Repositories SmartDukaan

Rev

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

Rev 28123 Rev 30487
Line 3... Line 3...
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;
6
import java.time.LocalTime;
7
import java.time.temporal.ChronoUnit;
7
import java.time.temporal.ChronoUnit;
8
import java.util.ArrayList;
-
 
9
import java.util.Base64;
8
import java.util.Base64;
10
import java.util.List;
9
import java.util.List;
11
 
10
 
12
import javax.mail.MessagingException;
11
import javax.mail.MessagingException;
13
import javax.servlet.http.HttpServletRequest;
12
import javax.servlet.http.HttpServletRequest;
Line 15... Line 14...
15
import org.apache.logging.log4j.LogManager;
14
import org.apache.logging.log4j.LogManager;
16
import org.apache.logging.log4j.Logger;
15
import org.apache.logging.log4j.Logger;
17
import org.json.JSONArray;
16
import org.json.JSONArray;
18
import org.json.JSONObject;
17
import org.json.JSONObject;
19
import org.springframework.beans.factory.annotation.Autowired;
18
import org.springframework.beans.factory.annotation.Autowired;
20
import org.springframework.format.annotation.DateTimeFormat;
-
 
21
import org.springframework.http.MediaType;
19
import org.springframework.http.MediaType;
22
import org.springframework.http.ResponseEntity;
20
import org.springframework.http.ResponseEntity;
23
import org.springframework.stereotype.Controller;
21
import org.springframework.stereotype.Controller;
24
import org.springframework.transaction.annotation.Transactional;
22
import org.springframework.transaction.annotation.Transactional;
25
import org.springframework.web.bind.annotation.RequestBody;
23
import org.springframework.web.bind.annotation.RequestBody;
Line 31... Line 29...
31
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
29
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
32
import com.spice.profitmandi.common.web.util.ResponseSender;
30
import com.spice.profitmandi.common.web.util.ResponseSender;
33
import com.spice.profitmandi.dao.entity.dtr.EmployeeAttendance;
31
import com.spice.profitmandi.dao.entity.dtr.EmployeeAttendance;
34
import com.spice.profitmandi.dao.entity.dtr.HyperTrackKeyModel;
32
import com.spice.profitmandi.dao.entity.dtr.HyperTrackKeyModel;
35
import com.spice.profitmandi.dao.entity.dtr.HypertrackKey;
33
import com.spice.profitmandi.dao.entity.dtr.HypertrackKey;
-
 
34
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
36
import com.spice.profitmandi.dao.enumuration.dtr.PunchType;
35
import com.spice.profitmandi.dao.enumuration.dtr.PunchType;
37
import com.spice.profitmandi.dao.model.EmployeeAttendanceModel;
36
import com.spice.profitmandi.dao.model.EmployeeAttendanceModel;
38
import com.spice.profitmandi.dao.repository.dtr.EmployeeAttendanceRepository;
37
import com.spice.profitmandi.dao.repository.dtr.EmployeeAttendanceRepository;
39
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
38
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
40
import com.spice.profitmandi.dao.repository.user.HypertrackKeyRepository;
39
import com.spice.profitmandi.dao.repository.user.HypertrackKeyRepository;
Line 103... Line 102...
103
		LOGGER.info("UserId -> {}, Device Id -> {}", userId, deviceId);
102
		LOGGER.info("UserId -> {}, Device Id -> {}", userId, deviceId);
104
		double lat1 = 28.516045882182738;
103
		double lat1 = 28.516045882182738;
105
		double lng1 = 77.3771954997187;
104
		double lng1 = 77.3771954997187;
106
 
105
 
107
		HypertrackKey hyperTrackKey = hypertrackKeyRepository.selectByUserIdAndDeviceId(userId, deviceId);
106
		HypertrackKey hyperTrackKey = hypertrackKeyRepository.selectByUserIdAndDeviceId(userId, deviceId);
108
		// EmployeeAttendance employeeAttendance =
-
 
109
		// employeeAttendanceRepository.selectLatestPunchTimeStamp();
-
 
110
 
107
 
111
		List<EmployeeAttendance> employeeAttendances = employeeAttendanceRepository.selectByUserIdKey(userId, deviceId,
108
		List<EmployeeAttendance> employeeAttendances = employeeAttendanceRepository.selectByUserIdKey(userId, deviceId,
112
				LocalDate.now());
109
				LocalDate.now());
113
		EmployeeAttendanceModel em = null;
110
		EmployeeAttendanceModel em = null;
114
		LOGGER.info("hyperTrackKey" + hyperTrackKey);
111
		LOGGER.info("hyperTrackKey" + hyperTrackKey);
Line 373... Line 370...
373
		Response response = client.newCall(request1).execute();
370
		Response response = client.newCall(request1).execute();
374
		return responseSender.ok(response.body().string());
371
		return responseSender.ok(response.body().string());
375
 
372
 
376
	}
373
	}
377
 
374
 
-
 
375
	@RequestMapping(value = "/devices/partner/location", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
-
 
376
	public ResponseEntity<?> getPartnerLocationByKeyId(HttpServletRequest request, @RequestParam int userId,
-
 
377
			@RequestParam int deviceId, @RequestParam int fofoId)
-
 
378
			throws IOException, MessagingException, ProfitMandiBusinessException {
-
 
379
 
-
 
380
		LOGGER.info("UserId -> {}, Device Id -> {}", userId, deviceId);
-
 
381
		FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
-
 
382
		double dist = 0;
-
 
383
		HypertrackKey hyperTrackKey = hypertrackKeyRepository.selectByUserIdAndDeviceId(userId, deviceId);
-
 
384
 
-
 
385
		OkHttpClient client = new OkHttpClient();
-
 
386
 
-
 
387
		String authString = "Basic "
-
 
388
				+ Base64.getEncoder().encodeToString(String.format("%s:%s", ACCOUNT_ID, SECRET_KEY).getBytes());
-
 
389
 
-
 
390
		Request request1 = new Request.Builder()
-
 
391
				.url("https://v3.api.hypertrack.com/devices/" + hyperTrackKey.getHypertrackKeyId()).get()
-
 
392
				.addHeader("Authorization", authString).build();
-
 
393
 
-
 
394
		Response response = client.newCall(request1).execute();
-
 
395
 
-
 
396
		JSONObject jsonObj = new JSONObject(response.body().string());
-
 
397
 
-
 
398
		JSONObject deviceStatus = jsonObj.getJSONObject("device_status");
-
 
399
		String status = deviceStatus.getString("value");
-
 
400
 
-
 
401
		if (status.equals("inactive") || status.equals("disconnected")) {
-
 
402
 
-
 
403
			LOGGER.info("status" + status);
-
 
404
			okhttp3.RequestBody reqbody = okhttp3.RequestBody.create(null, new byte[0]);
-
 
405
 
-
 
406
			Request request2 = new Request.Builder()
-
 
407
					.url("https://v3.api.hypertrack.com/devices/" + hyperTrackKey.getHypertrackKeyId() + "/start")
-
 
408
					.post(reqbody).addHeader("Authorization", authString).build();
-
 
409
 
-
 
410
			Response resp = client.newCall(request2).execute();
-
 
411
			LOGGER.info("resp" + resp);
-
 
412
 
-
 
413
		} else if (status.equals("active")) {
-
 
414
			JSONObject c = jsonObj.getJSONObject("location");
-
 
415
			JSONObject d = c.getJSONObject("geometry");
-
 
416
			JSONArray coords = d.getJSONArray("coordinates");
-
 
417
			double lat1 = 28.516045882182738;
-
 
418
			double lng1 = 77.3771954997187;
-
 
419
 
-
 
420
			double lat2 = coords.getDouble(1);
-
 
421
			double lng2 = coords.getDouble(0);
-
 
422
			// dist = distance(Float.valueOf(fs.getLatitude()),
-
 
423
			// Float.valueOf(fs.getLongitude()), lat2, lng2, "m");
-
 
424
 
-
 
425
			dist = distance(lat1, lng1, lat2, lng2, "m");
-
 
426
			LOGGER.info("jsonObj" + jsonObj);
-
 
427
			JSONObject deviceData = deviceStatus.getJSONObject("data");
-
 
428
			LOGGER.info("status1" + status);
-
 
429
 
-
 
430
		}
-
 
431
		return responseSender.ok(dist);
-
 
432
	}
-
 
433
 
378
}
434
}