| 25300 |
tejbeer |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.time.LocalDateTime;
|
|
|
4 |
|
|
|
5 |
import javax.servlet.http.HttpServletRequest;
|
|
|
6 |
|
|
|
7 |
import org.apache.logging.log4j.LogManager;
|
|
|
8 |
import org.apache.logging.log4j.Logger;
|
|
|
9 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
10 |
import org.springframework.http.MediaType;
|
|
|
11 |
import org.springframework.http.ResponseEntity;
|
|
|
12 |
import org.springframework.stereotype.Controller;
|
|
|
13 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
14 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
15 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
16 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
17 |
|
|
|
18 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
19 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 27350 |
amit.gupta |
20 |
import com.spice.profitmandi.dao.entity.dtr.GpsLocation;
|
|
|
21 |
import com.spice.profitmandi.dao.entity.dtr.GpsLocationModel;
|
| 25300 |
tejbeer |
22 |
import com.spice.profitmandi.dao.entity.user.Device;
|
|
|
23 |
import com.spice.profitmandi.dao.repository.catalog.DeviceRepository;
|
| 27350 |
amit.gupta |
24 |
import com.spice.profitmandi.dao.repository.user.GpsLocationRepository;
|
| 25300 |
tejbeer |
25 |
import com.spice.profitmandi.web.req.AddDevicesRequest;
|
|
|
26 |
|
|
|
27 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
28 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
29 |
import io.swagger.annotations.ApiOperation;
|
|
|
30 |
|
|
|
31 |
@Controller
|
|
|
32 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
33 |
public class DevicesController {
|
|
|
34 |
|
|
|
35 |
@Autowired
|
|
|
36 |
ResponseSender<?> responseSender;
|
|
|
37 |
|
|
|
38 |
@Autowired
|
|
|
39 |
private DeviceRepository deviceRepository;
|
| 28449 |
tejbeer |
40 |
|
| 27350 |
amit.gupta |
41 |
@Autowired
|
|
|
42 |
private GpsLocationRepository gpsLocationRepository;
|
| 25300 |
tejbeer |
43 |
|
| 28303 |
amit.gupta |
44 |
private static final Logger LOGGER = LogManager.getLogger(DevicesController.class);
|
| 25300 |
tejbeer |
45 |
|
| 27350 |
amit.gupta |
46 |
@RequestMapping(value = "/devices/add-new", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
47 |
@ApiImplicitParams({
|
| 28449 |
tejbeer |
48 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 27350 |
amit.gupta |
49 |
@ApiOperation(value = "")
|
| 28449 |
tejbeer |
50 |
public ResponseEntity<?> devicesInfo1(HttpServletRequest request,
|
|
|
51 |
@RequestBody AddDevicesRequest addDevicesRequest) {
|
| 27350 |
amit.gupta |
52 |
Device device = this.deviceInfo(request, addDevicesRequest);
|
| 28449 |
tejbeer |
53 |
LOGGER.info("devices1" + device.getId());
|
| 27350 |
amit.gupta |
54 |
return responseSender.ok(device.getId());
|
|
|
55 |
}
|
| 28449 |
tejbeer |
56 |
|
| 25300 |
tejbeer |
57 |
@RequestMapping(value = "/devices/add", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
58 |
@ApiImplicitParams({
|
|
|
59 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
60 |
@ApiOperation(value = "")
|
|
|
61 |
public ResponseEntity<?> devicesInfo(HttpServletRequest request, @RequestBody AddDevicesRequest addDevicesRequest)
|
|
|
62 |
throws ProfitMandiBusinessException {
|
| 28449 |
tejbeer |
63 |
Device device = this.deviceInfo(request, addDevicesRequest);
|
|
|
64 |
LOGGER.info("devices2" + device.getId());
|
| 27350 |
amit.gupta |
65 |
return responseSender.ok(true);
|
|
|
66 |
}
|
| 28449 |
tejbeer |
67 |
|
| 27350 |
amit.gupta |
68 |
private Device deviceInfo(HttpServletRequest request, AddDevicesRequest addDevicesRequest) {
|
| 25300 |
tejbeer |
69 |
Device device = deviceRepository.selectByImeiNumber(addDevicesRequest.getImeinumber());
|
| 27350 |
amit.gupta |
70 |
LOGGER.info("devices" + device);
|
| 25300 |
tejbeer |
71 |
if (device == null) {
|
|
|
72 |
device = new Device();
|
|
|
73 |
device.setImeiNumber(addDevicesRequest.getImeinumber());
|
| 28450 |
tejbeer |
74 |
|
| 25300 |
tejbeer |
75 |
}
|
|
|
76 |
device.setUser_id(addDevicesRequest.getUser_id());
|
|
|
77 |
device.setBrand(addDevicesRequest.getBrand());
|
|
|
78 |
device.setManufacturer(addDevicesRequest.getManufacturer());
|
|
|
79 |
device.setModel(addDevicesRequest.getModel());
|
|
|
80 |
device.setOsVersion(addDevicesRequest.getOsversion());
|
|
|
81 |
device.setVersionCode(addDevicesRequest.getVersioncode());
|
|
|
82 |
device.setVersionName(addDevicesRequest.getVersionname());
|
|
|
83 |
device.setAndroidId(addDevicesRequest.getAndroidid());
|
| 28449 |
tejbeer |
84 |
if (addDevicesRequest.getGcm_regid() == null)
|
|
|
85 |
LOGGER.info("gcm" + addDevicesRequest.getGcm_regid());
|
|
|
86 |
else {
|
|
|
87 |
device.setFcmId(addDevicesRequest.getGcm_regid());
|
|
|
88 |
}
|
| 25300 |
tejbeer |
89 |
device.setModified(LocalDateTime.now());
|
| 28450 |
tejbeer |
90 |
deviceRepository.persist(device);
|
| 27350 |
amit.gupta |
91 |
return device;
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
@RequestMapping(value = "/devices/location", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
95 |
public ResponseEntity<?> deviceLocation(HttpServletRequest request, @RequestBody GpsLocationModel locationModel) {
|
|
|
96 |
GpsLocation gpsLocation = new GpsLocation();
|
|
|
97 |
gpsLocation.setGps(locationModel.isGps());
|
|
|
98 |
gpsLocation.setDeviceId(locationModel.getDeviceId());
|
|
|
99 |
gpsLocation.setLat(locationModel.getLat());
|
|
|
100 |
gpsLocation.setLng(locationModel.getLng());
|
|
|
101 |
gpsLocation.setUserId(locationModel.getUserId());
|
|
|
102 |
gpsLocation.setCreateTime(LocalDateTime.now());
|
|
|
103 |
gpsLocationRepository.persist(gpsLocation);
|
| 25300 |
tejbeer |
104 |
return responseSender.ok(true);
|
|
|
105 |
}
|
| 28303 |
amit.gupta |
106 |
}
|