diff --git a/src/main/java/com/onekeycall/videotablet/config/PushIdConfig.java b/src/main/java/com/onekeycall/videotablet/config/PushIdConfig.java new file mode 100644 index 0000000..35315a7 --- /dev/null +++ b/src/main/java/com/onekeycall/videotablet/config/PushIdConfig.java @@ -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"; +} diff --git a/src/main/java/com/onekeycall/videotablet/controller/sn/BindSnController.java b/src/main/java/com/onekeycall/videotablet/controller/sn/BindSnController.java index 7c53007..c00fde5 100644 --- a/src/main/java/com/onekeycall/videotablet/controller/sn/BindSnController.java +++ b/src/main/java/com/onekeycall/videotablet/controller/sn/BindSnController.java @@ -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 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()); diff --git a/src/main/java/com/onekeycall/videotablet/controller/sn/DeviceApkInfoController.java b/src/main/java/com/onekeycall/videotablet/controller/sn/DeviceApkInfoController.java index 80740a4..55b2b44 100644 --- a/src/main/java/com/onekeycall/videotablet/controller/sn/DeviceApkInfoController.java +++ b/src/main/java/com/onekeycall/videotablet/controller/sn/DeviceApkInfoController.java @@ -30,7 +30,7 @@ public class DeviceApkInfoController { public Result uploadInstallApks(@RequestBody ApkUploadRequest request) { String sn = request.getSn(); List apkList = request.getApk_list(); - if (apkList == null || apkList.size() == 0) { + if (apkList == null || apkList.isEmpty()) { return Result.error().message("应用列表为空"); } deviceApkInfoService.saveOrUpdateDeviceApkInfo(sn, apkList); diff --git a/src/main/java/com/onekeycall/videotablet/controller/sn/DevicesController.java b/src/main/java/com/onekeycall/videotablet/controller/sn/DevicesController.java index 2f9d73b..ba28cec 100644 --- a/src/main/java/com/onekeycall/videotablet/controller/sn/DevicesController.java +++ b/src/main/java/com/onekeycall/videotablet/controller/sn/DevicesController.java @@ -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())); @@ -72,7 +72,7 @@ public class DevicesController { 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"); @@ -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); } diff --git a/src/main/java/com/onekeycall/videotablet/controller/user/ContactController.java b/src/main/java/com/onekeycall/videotablet/controller/user/ContactController.java index b54b666..909cb5a 100644 --- a/src/main/java/com/onekeycall/videotablet/controller/user/ContactController.java +++ b/src/main/java/com/onekeycall/videotablet/controller/user/ContactController.java @@ -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); } } diff --git a/src/main/java/com/onekeycall/videotablet/controller/user/UserController.java b/src/main/java/com/onekeycall/videotablet/controller/user/UserController.java index 83dd5b8..5a9982e 100644 --- a/src/main/java/com/onekeycall/videotablet/controller/user/UserController.java +++ b/src/main/java/com/onekeycall/videotablet/controller/user/UserController.java @@ -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()); } } diff --git a/src/main/java/com/onekeycall/videotablet/entity/Contact.java b/src/main/java/com/onekeycall/videotablet/entity/Contact.java index 2020484..d857d6c 100644 --- a/src/main/java/com/onekeycall/videotablet/entity/Contact.java +++ b/src/main/java/com/onekeycall/videotablet/entity/Contact.java @@ -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; - } diff --git a/src/main/java/com/onekeycall/videotablet/repository/DeviceApkInfoRepository.java b/src/main/java/com/onekeycall/videotablet/repository/DeviceApkInfoRepository.java index 2fc52be..0e8435f 100644 --- a/src/main/java/com/onekeycall/videotablet/repository/DeviceApkInfoRepository.java +++ b/src/main/java/com/onekeycall/videotablet/repository/DeviceApkInfoRepository.java @@ -10,7 +10,7 @@ import java.util.List; public interface DeviceApkInfoRepository extends MongoRepository { // 根据序列号sn查找设备应用列表 - DeviceApkInfo findDeviceApkInfoBySn(String sn); + DeviceApkInfo getDeviceApkInfoBySn(String sn); // 判断某个序列号的记录是否存在 boolean existsBySn(String sn); diff --git a/src/main/java/com/onekeycall/videotablet/result/Result.java b/src/main/java/com/onekeycall/videotablet/result/Result.java index 1960568..ce1e176 100644 --- a/src/main/java/com/onekeycall/videotablet/result/Result.java +++ b/src/main/java/com/onekeycall/videotablet/result/Result.java @@ -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 data = new HashMap<>(); +// private Map 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 data = new HashMap<>(); + data.put(key, value); + this.setData(data); return this; } - public Result data(Map map) { - this.setData(map); +// public Result data(Map 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 getData() { - return data; - } - - public void setData(Map data) { - this.data = data; - } } diff --git a/src/main/java/com/onekeycall/videotablet/service/ContactService.java b/src/main/java/com/onekeycall/videotablet/service/ContactService.java index 70fb218..0eff61c 100644 --- a/src/main/java/com/onekeycall/videotablet/service/ContactService.java +++ b/src/main/java/com/onekeycall/videotablet/service/ContactService.java @@ -17,6 +17,10 @@ public class ContactService { this.contactRepository = deviceSnRepository; } + public List findAllByUserId(String userId) { + return contactRepository.findAllByUserId(userId); + } + public boolean isExistByPhoneNumber(String phoneNumber) { return contactRepository.existsByPhoneNumber(phoneNumber); } diff --git a/src/main/java/com/onekeycall/videotablet/service/DeviceApkInfoService.java b/src/main/java/com/onekeycall/videotablet/service/DeviceApkInfoService.java index 737f253..fd947ba 100644 --- a/src/main/java/com/onekeycall/videotablet/service/DeviceApkInfoService.java +++ b/src/main/java/com/onekeycall/videotablet/service/DeviceApkInfoService.java @@ -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); } diff --git a/src/main/java/com/onekeycall/videotablet/utils/DevicePushUtils.java b/src/main/java/com/onekeycall/videotablet/utils/DevicePushUtils.java index 557e640..aaed9d7 100644 --- a/src/main/java/com/onekeycall/videotablet/utils/DevicePushUtils.java +++ b/src/main/java/com/onekeycall/videotablet/utils/DevicePushUtils.java @@ -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 diff --git a/src/main/resources/application-debug.properties b/src/main/resources/application-debug.properties index 62aabe0..9bad4e4 100644 --- a/src/main/resources/application-debug.properties +++ b/src/main/resources/application-debug.properties @@ -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 \ No newline at end of file diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index 94a8f7a..81956e5 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -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 \ No newline at end of file diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties index 653f6ac..81956e5 100644 --- a/src/main/resources/application-test.properties +++ b/src/main/resources/application-test.properties @@ -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