Subversion Repositories SmartDukaan

Rev

Rev 27417 | Rev 27419 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
27417 tejbeer 1
package com.spice.profitmandi.web.controller;
2
 
3
import java.io.IOException;
4
import java.io.StringWriter;
5
import java.time.LocalDateTime;
6
import java.util.Base64;
7
 
8
import javax.mail.MessagingException;
9
import javax.mail.internet.InternetAddress;
10
import javax.mail.internet.MimeMessage;
11
import javax.servlet.http.HttpServletRequest;
12
 
13
import org.apache.logging.log4j.LogManager;
14
import org.apache.logging.log4j.Logger;
15
import org.apache.velocity.Template;
16
import org.apache.velocity.VelocityContext;
17
import org.apache.velocity.app.VelocityEngine;
18
import org.json.JSONArray;
19
import org.json.JSONObject;
20
import org.springframework.beans.factory.annotation.Autowired;
21
import org.springframework.format.annotation.DateTimeFormat;
22
import org.springframework.http.MediaType;
23
import org.springframework.http.ResponseEntity;
24
import org.springframework.mail.javamail.JavaMailSender;
25
import org.springframework.mail.javamail.MimeMessageHelper;
26
import org.springframework.stereotype.Controller;
27
import org.springframework.transaction.annotation.Transactional;
28
import org.springframework.web.bind.annotation.RequestBody;
29
import org.springframework.web.bind.annotation.RequestMapping;
30
import org.springframework.web.bind.annotation.RequestMethod;
31
import org.springframework.web.bind.annotation.RequestParam;
32
 
33
import com.google.gson.Gson;
34
import com.mongodb.util.JSON;
35
import com.spice.profitmandi.common.model.CustomRetailer;
36
import com.spice.profitmandi.common.web.util.ResponseSender;
37
import com.spice.profitmandi.dao.entity.dtr.EmployeeAttendance;
38
import com.spice.profitmandi.dao.entity.dtr.HyperTrackKeyModel;
39
import com.spice.profitmandi.dao.entity.dtr.HypertrackKey;
40
import com.spice.profitmandi.dao.entity.fofo.Customer;
41
import com.spice.profitmandi.dao.entity.user.Device;
42
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
43
import com.spice.profitmandi.dao.enumuration.dtr.PunchType;
44
import com.spice.profitmandi.dao.repository.dtr.EmployeeAttendanceRepository;
45
import com.spice.profitmandi.dao.repository.user.HypertrackKeyRepository;
46
 
47
import io.swagger.annotations.ApiImplicitParam;
48
import io.swagger.annotations.ApiImplicitParams;
49
import io.swagger.annotations.ApiOperation;
50
import okhttp3.OkHttpClient;
51
import okhttp3.Request;
52
import okhttp3.Response;
53
 
54
@Controller
55
@Transactional(rollbackFor = Throwable.class)
56
public class HyperTrackController {
57
 
58
	private static final Logger LOGGER = LogManager.getLogger(HyperTrackController.class);
59
 
60
	@Autowired
61
	ResponseSender<?> responseSender;
62
 
63
	@Autowired
64
	Gson gson;
65
 
66
	@Autowired
67
	private HypertrackKeyRepository hypertrackKeyRepository;
68
 
69
	private static final String ACCOUNT_ID = "aZ6flHhrgPIEl18buHdPBdueEN4";
70
	private static final String SECRET_KEY = "a7rsX5B4UNNfTTx1-IJ19qdH48BT4YvBKlQJg3n3_KKNe7WWych55g";
71
 
72
	@RequestMapping(value = "/devices/hypertrackId", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
73
	@ApiImplicitParams({
74
			@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
75
	@ApiOperation(value = "")
76
	public ResponseEntity<?> deviceHypertrackId(HttpServletRequest request,
77
			@RequestBody HyperTrackKeyModel hyperTrackKeyModel) {
78
		HypertrackKey hyperTrackKey = hypertrackKeyRepository.selectByUserIdAndDeviceId(hyperTrackKeyModel.getUserId(),
79
				hyperTrackKeyModel.getDeviceId());
80
		if (hyperTrackKey == null) {
81
			hyperTrackKey = new HypertrackKey();
82
			hyperTrackKey.setDeviceId(hyperTrackKeyModel.getDeviceId());
83
			hyperTrackKey.setUserId(hyperTrackKeyModel.getUserId());
84
		}
85
		hyperTrackKey.setHypertrackKeyId(hyperTrackKeyModel.getHyperTrackId());
86
		hyperTrackKey.setCreatedTimestamp(LocalDateTime.now());
87
		hyperTrackKey.setUpdatedTimestamp(LocalDateTime.now());
88
		hypertrackKeyRepository.persist(hyperTrackKey);
89
		return responseSender.ok(true);
90
	}
91
 
92
}