Subversion Repositories SmartDukaan

Rev

Rev 27417 | Rev 27419 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.spice.profitmandi.web.controller;

import java.io.IOException;
import java.io.StringWriter;
import java.time.LocalDateTime;
import java.util.Base64;

import javax.mail.MessagingException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.http.HttpServletRequest;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.google.gson.Gson;
import com.mongodb.util.JSON;
import com.spice.profitmandi.common.model.CustomRetailer;
import com.spice.profitmandi.common.web.util.ResponseSender;
import com.spice.profitmandi.dao.entity.dtr.EmployeeAttendance;
import com.spice.profitmandi.dao.entity.dtr.HyperTrackKeyModel;
import com.spice.profitmandi.dao.entity.dtr.HypertrackKey;
import com.spice.profitmandi.dao.entity.fofo.Customer;
import com.spice.profitmandi.dao.entity.user.Device;
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
import com.spice.profitmandi.dao.enumuration.dtr.PunchType;
import com.spice.profitmandi.dao.repository.dtr.EmployeeAttendanceRepository;
import com.spice.profitmandi.dao.repository.user.HypertrackKeyRepository;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

@Controller
@Transactional(rollbackFor = Throwable.class)
public class HyperTrackController {

        private static final Logger LOGGER = LogManager.getLogger(HyperTrackController.class);

        @Autowired
        ResponseSender<?> responseSender;

        @Autowired
        Gson gson;

        @Autowired
        private HypertrackKeyRepository hypertrackKeyRepository;

        private static final String ACCOUNT_ID = "aZ6flHhrgPIEl18buHdPBdueEN4";
        private static final String SECRET_KEY = "a7rsX5B4UNNfTTx1-IJ19qdH48BT4YvBKlQJg3n3_KKNe7WWych55g";

        @RequestMapping(value = "/devices/hypertrackId", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
        @ApiImplicitParams({
                        @ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
        @ApiOperation(value = "")
        public ResponseEntity<?> deviceHypertrackId(HttpServletRequest request,
                        @RequestBody HyperTrackKeyModel hyperTrackKeyModel) {
                HypertrackKey hyperTrackKey = hypertrackKeyRepository.selectByUserIdAndDeviceId(hyperTrackKeyModel.getUserId(),
                                hyperTrackKeyModel.getDeviceId());
                if (hyperTrackKey == null) {
                        hyperTrackKey = new HypertrackKey();
                        hyperTrackKey.setDeviceId(hyperTrackKeyModel.getDeviceId());
                        hyperTrackKey.setUserId(hyperTrackKeyModel.getUserId());
                }
                hyperTrackKey.setHypertrackKeyId(hyperTrackKeyModel.getHyperTrackId());
                hyperTrackKey.setCreatedTimestamp(LocalDateTime.now());
                hyperTrackKey.setUpdatedTimestamp(LocalDateTime.now());
                hypertrackKeyRepository.persist(hyperTrackKey);
                return responseSender.ok(true);
        }

}