增加添加和获取联系人接口,AesAttributeConverter中autoApply = false取消全局加密
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
package com.onekeycall.videotablet.controller;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.onekeycall.videotablet.entity.Contact;
|
||||
import com.onekeycall.videotablet.entity.DeviceInfo;
|
||||
import com.onekeycall.videotablet.entity.User;
|
||||
import com.onekeycall.videotablet.result.Result;
|
||||
import com.onekeycall.videotablet.service.ContactService;
|
||||
import com.onekeycall.videotablet.service.DeviceSnService;
|
||||
import com.onekeycall.videotablet.service.UserService;
|
||||
import com.onekeycall.videotablet.utils.JwtUtil;
|
||||
@@ -13,6 +16,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/contact")
|
||||
@@ -23,6 +27,8 @@ public class ContactController {
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private DeviceSnService deviceSnService;
|
||||
@Autowired
|
||||
private ContactService contactService;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
@@ -33,7 +39,9 @@ public class ContactController {
|
||||
public Result userAddContact(
|
||||
@RequestHeader("Authorization") String authHeader, @RequestHeader("Device-ID") String deviceId,
|
||||
@RequestParam(value = "user_id") String userId, @RequestParam(value = "sn") String sn,
|
||||
@Valid @RequestBody Contact contact) {
|
||||
@RequestPart(value = "file", required = false) MultipartFile file,
|
||||
@RequestPart("contact_json") String jsonData
|
||||
) throws JsonProcessingException {
|
||||
|
||||
if (!authHeader.startsWith("Bearer ")) {
|
||||
return Result.error().message("Invalid Authorization header");
|
||||
@@ -57,6 +65,17 @@ public class ContactController {
|
||||
return Result.error().message("device not belong to user");
|
||||
}
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Contact contact = mapper.readValue(jsonData, Contact.class);
|
||||
|
||||
if (contactService.isExistByPhoneNumberAndSn(contact.getPhoneNumber(), sn)) {
|
||||
return Result.error().message("contact already exist");
|
||||
}
|
||||
|
||||
contact.setUserId(userId);
|
||||
contact.setSn(sn);
|
||||
contactService.save(contact);
|
||||
|
||||
return Result.ok();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.onekeycall.videotablet.entity.Contact;
|
||||
import com.onekeycall.videotablet.entity.DeviceInfo;
|
||||
import com.onekeycall.videotablet.entity.DeviceLocation;
|
||||
import com.onekeycall.videotablet.result.Result;
|
||||
import com.onekeycall.videotablet.service.ContactService;
|
||||
import com.onekeycall.videotablet.service.DeviceLocationService;
|
||||
import com.onekeycall.videotablet.service.DeviceSnService;
|
||||
import com.onekeycall.videotablet.utils.JwtUtil;
|
||||
@@ -26,10 +27,13 @@ public class DevicesController {
|
||||
private DeviceSnService deviceSnService;
|
||||
@Autowired
|
||||
private DeviceLocationService deviceLocationService;
|
||||
@Autowired
|
||||
private ContactService contactService;
|
||||
|
||||
@GetMapping("/get_sn_list")
|
||||
public Result register(@RequestHeader("Authorization") String authHeader, @RequestHeader("Device-ID") String deviceId,
|
||||
@RequestParam(value = "user_id") String userId, @RequestParam(value = "sn", required = false) String sn) {
|
||||
public Result register(
|
||||
@RequestHeader("Authorization") String authHeader, @RequestHeader("Device-ID") String deviceId,
|
||||
@RequestParam(value = "user_id") String userId, @RequestParam(value = "sn", required = false) String sn) {
|
||||
// 1. 校验 Authorization 头
|
||||
if (!authHeader.startsWith("Bearer ")) {
|
||||
return Result.error().message("Invalid Authorization header");
|
||||
@@ -87,7 +91,7 @@ public class DevicesController {
|
||||
return Result.error().message("sn not bind");
|
||||
}
|
||||
if (deviceLocationService.isExist(sn)) {
|
||||
DeviceLocation deviceLocationDB=deviceLocationService.getDeviceLocation(sn);
|
||||
DeviceLocation deviceLocationDB = deviceLocationService.getDeviceLocation(sn);
|
||||
deviceLocation.setId(deviceLocationDB.getId());
|
||||
deviceLocation.setUpdateTime(new Date(System.currentTimeMillis()));
|
||||
deviceLocationService.save(deviceLocation);
|
||||
@@ -98,4 +102,35 @@ public class DevicesController {
|
||||
}
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/get_contacts")
|
||||
public Result getContacts(
|
||||
@RequestHeader("Device-Token") String deviceToken, @RequestHeader("Device-ID") String deviceId,
|
||||
@RequestHeader("Device-Sig") String deviceSig, @RequestParam(value = "sn") String sn
|
||||
) {
|
||||
|
||||
if (!jwtUtil.validateDeviceToken(deviceToken, deviceId, sn)) {
|
||||
return Result.error().message("Invalid token");
|
||||
}
|
||||
|
||||
DeviceInfo deviceInfo = deviceSnService.findBySn(sn);
|
||||
if (deviceInfo == null) {
|
||||
return Result.notFound().message("sn not found");
|
||||
}
|
||||
|
||||
if (!deviceInfo.getBindSig().equals(deviceSig)) {
|
||||
return Result.error().message("device sig not match");
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(deviceInfo.getBindPhone())) {
|
||||
return Result.error().message("sn not bind");
|
||||
}
|
||||
List<Contact> contacts = contactService.findAllBySn(sn);
|
||||
if (contacts == null || contacts.isEmpty()) {
|
||||
return Result.notFound().message("contacts not found");
|
||||
}
|
||||
return Result.ok().data("contacts", contacts);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user