| 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;
|
|
|
20 |
import com.spice.profitmandi.dao.entity.user.Device;
|
|
|
21 |
import com.spice.profitmandi.dao.repository.catalog.DeviceRepository;
|
|
|
22 |
import com.spice.profitmandi.web.req.AddDevicesRequest;
|
|
|
23 |
|
|
|
24 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
25 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
26 |
import io.swagger.annotations.ApiOperation;
|
|
|
27 |
|
|
|
28 |
@Controller
|
|
|
29 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
30 |
public class DevicesController {
|
|
|
31 |
|
|
|
32 |
@Autowired
|
|
|
33 |
ResponseSender<?> responseSender;
|
|
|
34 |
|
|
|
35 |
@Autowired
|
|
|
36 |
private DeviceRepository deviceRepository;
|
|
|
37 |
|
|
|
38 |
private static final Logger LOGGER = LogManager.getLogger(RetailerController.class);
|
|
|
39 |
|
|
|
40 |
@RequestMapping(value = "/devices/add", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
41 |
@ApiImplicitParams({
|
|
|
42 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
|
|
43 |
@ApiOperation(value = "")
|
|
|
44 |
public ResponseEntity<?> devicesInfo(HttpServletRequest request, @RequestBody AddDevicesRequest addDevicesRequest)
|
|
|
45 |
throws ProfitMandiBusinessException {
|
|
|
46 |
Device device = deviceRepository.selectByImeiNumber(addDevicesRequest.getImeinumber());
|
|
|
47 |
LOGGER.info("divices" + device);
|
|
|
48 |
if (device == null) {
|
|
|
49 |
device = new Device();
|
|
|
50 |
device.setImeiNumber(addDevicesRequest.getImeinumber());
|
|
|
51 |
}
|
|
|
52 |
device.setUser_id(addDevicesRequest.getUser_id());
|
|
|
53 |
device.setBrand(addDevicesRequest.getBrand());
|
|
|
54 |
device.setManufacturer(addDevicesRequest.getManufacturer());
|
|
|
55 |
device.setModel(addDevicesRequest.getModel());
|
|
|
56 |
device.setOsVersion(addDevicesRequest.getOsversion());
|
|
|
57 |
device.setVersionCode(addDevicesRequest.getVersioncode());
|
|
|
58 |
device.setVersionName(addDevicesRequest.getVersionname());
|
|
|
59 |
device.setAndroidId(addDevicesRequest.getAndroidid());
|
| 25309 |
tejbeer |
60 |
if(addDevicesRequest.getGcm_regid() == null)
|
|
|
61 |
LOGGER.info("gcm" + addDevicesRequest.getGcm_regid());
|
|
|
62 |
else {
|
|
|
63 |
device.setFcmId(addDevicesRequest.getGcm_regid());
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
|
| 25300 |
tejbeer |
67 |
device.setModified(LocalDateTime.now());
|
|
|
68 |
deviceRepository.persist(device);
|
|
|
69 |
return responseSender.ok(true);
|
|
|
70 |
}
|
|
|
71 |
}
|