增加result返回列表,联系人接口增加推送
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
package com.onekeycall.videotablet.config;
|
||||
|
||||
public class PushIdConfig {
|
||||
/*绑定设备*/
|
||||
public static final String BIND_DEVICE = "1";
|
||||
/*卸载应用*/
|
||||
public static final String UNINSTALL_APK = "2";
|
||||
/*添加联系人*/
|
||||
public static final String CONTACT_ADD = "3";
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.onekeycall.videotablet.controller.sn;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.onekeycall.videotablet.config.PushIdConfig;
|
||||
import com.onekeycall.videotablet.entity.DeviceInfo;
|
||||
import com.onekeycall.videotablet.entity.User;
|
||||
import com.onekeycall.videotablet.result.Result;
|
||||
@@ -80,7 +81,7 @@ public class BindSnController {
|
||||
params.addProperty("expire_time", System.currentTimeMillis() + 60 * 1000);
|
||||
|
||||
// PushUtils.aliyunAsyncPush("1", params.toString(), sn);
|
||||
DevicePushUtils.tpnsPush("1", params.toString(), sn);
|
||||
DevicePushUtils.aliyunAsyncPush(PushIdConfig.BIND_DEVICE, sn, params.toString());
|
||||
redisTemplate.opsForValue().set(sn, verifyKey, 1, TimeUnit.MINUTES);
|
||||
return Result.ok().message("send message success");
|
||||
} catch (Exception e) {
|
||||
@@ -184,6 +185,7 @@ public class BindSnController {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("bind_status", 1);
|
||||
map.put("device_alias", deviceInfo.getDeviceAlias());
|
||||
map.put("tablet_avatar", deviceInfo.getTabletAvatar());
|
||||
map.put("bind_phone", deviceInfo.getBindPhone());
|
||||
map.put("user_id", deviceInfo.getUserId());
|
||||
map.put("add_time", deviceInfo.getAddTime());
|
||||
|
||||
@@ -30,7 +30,7 @@ public class DeviceApkInfoController {
|
||||
public Result uploadInstallApks(@RequestBody ApkUploadRequest request) {
|
||||
String sn = request.getSn();
|
||||
List<ApkInfo> apkList = request.getApk_list();
|
||||
if (apkList == null || apkList.size() == 0) {
|
||||
if (apkList == null || apkList.isEmpty()) {
|
||||
return Result.error().message("应用列表为空");
|
||||
}
|
||||
deviceApkInfoService.saveOrUpdateDeviceApkInfo(sn, apkList);
|
||||
|
||||
@@ -29,7 +29,6 @@ public class DevicesController {
|
||||
private ContactService contactService;
|
||||
|
||||
|
||||
|
||||
@PostMapping("/update_location")
|
||||
public Result updateLocation(
|
||||
@RequestHeader("Device-Token") String deviceToken, @RequestHeader("Device-ID") String deviceId,
|
||||
@@ -58,6 +57,7 @@ public class DevicesController {
|
||||
DeviceLocation deviceLocationDB = deviceLocationService.getDeviceLocation(sn);
|
||||
deviceLocation.setId(deviceLocationDB.getId());
|
||||
deviceLocation.setUpdateTime(new Date(System.currentTimeMillis()));
|
||||
deviceLocation.setCreateTime(deviceLocationDB.getCreateTime());
|
||||
deviceLocationService.save(deviceLocation);
|
||||
} else {
|
||||
deviceLocation.setUpdateTime(new Date(System.currentTimeMillis()));
|
||||
@@ -94,7 +94,7 @@ public class DevicesController {
|
||||
if (contacts == null || contacts.isEmpty()) {
|
||||
return Result.notFound().message("contacts not found");
|
||||
}
|
||||
return Result.ok().data("contacts", contacts);
|
||||
return Result.ok().data(contacts);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,13 +2,16 @@ package com.onekeycall.videotablet.controller.user;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.onekeycall.videotablet.config.PushIdConfig;
|
||||
import com.onekeycall.videotablet.entity.Contact;
|
||||
import com.onekeycall.videotablet.entity.DeviceInfo;
|
||||
import com.onekeycall.videotablet.entity.User;
|
||||
import com.onekeycall.videotablet.gson.GsonUtils;
|
||||
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.DevicePushUtils;
|
||||
import com.onekeycall.videotablet.utils.JwtUtil;
|
||||
import com.onekeycall.videotablet.utils.TextUtils;
|
||||
import org.slf4j.Logger;
|
||||
@@ -19,6 +22,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user")
|
||||
@@ -43,7 +47,7 @@ public class ContactController {
|
||||
@RequestParam(value = "sn") String sn,
|
||||
@RequestPart(value = "file", required = false) MultipartFile file,
|
||||
@RequestPart("contact_json") String jsonData
|
||||
) throws JsonProcessingException {
|
||||
) throws Exception {
|
||||
|
||||
User user = userService.getUserByUserId(userId);
|
||||
if (user == null) {
|
||||
@@ -69,6 +73,8 @@ public class ContactController {
|
||||
contact.setSn(sn);
|
||||
contactService.save(contact);
|
||||
|
||||
DevicePushUtils.aliyunAsyncPush(PushIdConfig.CONTACT_ADD, sn, GsonUtils.toJSONString(contactService.findAllBySn(sn)));
|
||||
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@@ -94,6 +100,6 @@ public class ContactController {
|
||||
if (contacts == null || contacts.isEmpty()) {
|
||||
return Result.notFound().message("contacts not found");
|
||||
}
|
||||
return Result.ok().data("contacts", contacts);
|
||||
return Result.ok().data(contacts);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,6 +183,9 @@ public class UserController {
|
||||
public Result getDeviceApkList(@RequestParam String sn) {
|
||||
|
||||
DeviceApkInfo deviceApkInfo = deviceApkInfoService.getDeviceApkInfoBySn(sn);
|
||||
return Result.ok().data("deviceApkInfo", deviceApkInfo);
|
||||
if (deviceApkInfo == null || deviceApkInfo.getApkList() == null) {
|
||||
return Result.notFound().message("未找到设备APK信息");
|
||||
}
|
||||
return Result.ok().data(deviceApkInfo.getApkList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import lombok.Data;
|
||||
public class Contact {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id",unique = true, nullable = false)
|
||||
@Column(name = "id", unique = true, nullable = false)
|
||||
private Long id;
|
||||
|
||||
@Convert(converter = AesAttributeConverter.class)
|
||||
@@ -40,11 +40,16 @@ public class Contact {
|
||||
@Column
|
||||
private String qq;
|
||||
|
||||
int sort;
|
||||
|
||||
boolean show;
|
||||
|
||||
boolean emergency;
|
||||
|
||||
@Column
|
||||
private String sn;
|
||||
|
||||
@Column(name = "user_id")
|
||||
private String userId;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.List;
|
||||
public interface DeviceApkInfoRepository extends MongoRepository<DeviceApkInfo, String> {
|
||||
|
||||
// 根据序列号sn查找设备应用列表
|
||||
DeviceApkInfo findDeviceApkInfoBySn(String sn);
|
||||
DeviceApkInfo getDeviceApkInfoBySn(String sn);
|
||||
|
||||
// 判断某个序列号的记录是否存在
|
||||
boolean existsBySn(String sn);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.onekeycall.videotablet.result;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -9,6 +11,7 @@ import java.util.Map;
|
||||
* @author 爷爷的茶七里香
|
||||
* @date 2022/05/30
|
||||
*/
|
||||
@Data
|
||||
public class Result {
|
||||
|
||||
/**
|
||||
@@ -29,7 +32,12 @@ public class Result {
|
||||
/**
|
||||
* 放置响应的数据
|
||||
*/
|
||||
private Map<String, Object> data = new HashMap<>();
|
||||
// private Map<String, Object> data = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 放置集合类型响应数据
|
||||
*/
|
||||
private Object data;
|
||||
|
||||
public Result() {
|
||||
}
|
||||
@@ -92,46 +100,19 @@ public class Result {
|
||||
}
|
||||
|
||||
public Result data(String key, Object value) {
|
||||
this.data.put(key, value);
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put(key, value);
|
||||
this.setData(data);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Result data(Map<String, Object> map) {
|
||||
this.setData(map);
|
||||
// public Result data(Map<String, Object> map) {
|
||||
// this.setData(map);
|
||||
// return this;
|
||||
// }
|
||||
|
||||
public Result data(Object listData) {
|
||||
this.setData(listData);
|
||||
return this;
|
||||
}
|
||||
|
||||
/** 以下是get/set方法,如果项目有集成lombok可以使用@Data注解代替 */
|
||||
|
||||
public Boolean getSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(Boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Map<String, Object> getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(Map<String, Object> data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,10 @@ public class ContactService {
|
||||
this.contactRepository = deviceSnRepository;
|
||||
}
|
||||
|
||||
public List<Contact> findAllByUserId(String userId) {
|
||||
return contactRepository.findAllByUserId(userId);
|
||||
}
|
||||
|
||||
public boolean isExistByPhoneNumber(String phoneNumber) {
|
||||
return contactRepository.existsByPhoneNumber(phoneNumber);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class DeviceApkInfoService {
|
||||
DeviceApkInfo deviceApkInfo;
|
||||
if (deviceApkInfoRepository.existsBySn(sn)) {
|
||||
// 存在则更新
|
||||
deviceApkInfo = deviceApkInfoRepository.findDeviceApkInfoBySn(sn);
|
||||
deviceApkInfo = deviceApkInfoRepository.getDeviceApkInfoBySn(sn);
|
||||
deviceApkInfo.setApkList(apkList);
|
||||
deviceApkInfo.setUpdateTime(new Date());
|
||||
} else {
|
||||
@@ -42,7 +42,7 @@ public class DeviceApkInfoService {
|
||||
* 根据序列号sn获取设备APK列表
|
||||
*/
|
||||
public DeviceApkInfo getDeviceApkInfoBySn(String sn) {
|
||||
return deviceApkInfoRepository.findDeviceApkInfoBySn(sn);
|
||||
return deviceApkInfoRepository.getDeviceApkInfoBySn(sn);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public class DevicePushUtils {
|
||||
* @throws ExecutionException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public static void aliyunAsyncPush(String title, String jsonString, String targetValue) throws ExecutionException, InterruptedException {
|
||||
public static void aliyunAsyncPush(String title, String targetValue, String jsonString) throws ExecutionException, InterruptedException {
|
||||
// HttpClient Configuration
|
||||
/*HttpClient httpClient = new ApacheAsyncHttpClientBuilder()
|
||||
.connectionTimeout(Duration.ofSeconds(10)) // Set the connection timeout time, the default is 10 seconds
|
||||
|
||||
@@ -56,5 +56,8 @@ logging.pattern.file=%d{yyyy-MM-dd} [%thread] %-5level %logger - %msg%n
|
||||
logging.logback.rollingpolicy.max-file-size=10MB
|
||||
logging.logback.rollingpolicy.max-history=30
|
||||
|
||||
logging.level.com.onekeycall.videotablet.filter=DEBUG
|
||||
logging.level.org.springframework.security=DEBUG
|
||||
|
||||
mybatis.type-aliases-package=com.onekeycall.videotablet.entity
|
||||
mybatis.mapperLocations=classpath:mapper/*.xml
|
||||
@@ -56,5 +56,8 @@ logging.pattern.file=%d{yyyy-MM-dd} [%thread] %-5level %logger - %msg%n
|
||||
logging.logback.rollingpolicy.max-file-size=10MB
|
||||
logging.logback.rollingpolicy.max-history=30
|
||||
|
||||
logging.level.com.onekeycall.videotablet.filter=DEBUG
|
||||
logging.level.org.springframework.security=DEBUG
|
||||
|
||||
mybatis.type-aliases-package=com.onekeycall.videotablet.entity
|
||||
mybatis.mapperLocations=classpath:mapper/*.xml
|
||||
@@ -23,7 +23,7 @@ spring.data.redis.lettuce.pool.max-wait=1ms
|
||||
spring.data.redis.lettuce.shutdown-timeout=100ms
|
||||
|
||||
#MongoDB
|
||||
spring.data.mongodb.uri=mongodb://fht:fanhuitong@139.199.77.221:27027/devices_apk_info?authSource=admin&connectTimeoutMS=5000
|
||||
spring.data.mongodb.uri=mongodb://fht:fanhuitong@139.199.77.221:27027/device_apks?authSource=admin&connectTimeoutMS=5000
|
||||
|
||||
# Hibernate配置
|
||||
#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDBDialect
|
||||
|
||||
Reference in New Issue
Block a user