瀏覽代碼

增加通讯录、SOS、修改开机命令

master
bin 3 年之前
父節點
當前提交
f1f0537b1c
共有 9 個文件被更改,包括 110 次插入55 次删除
  1. +13
    -4
      src/main/java/com/ssjl/zhaobiao/guizhou/controller/IotController.java
  2. +7
    -11
      src/main/java/com/ssjl/zhaobiao/guizhou/handle/GZResponseHandle.java
  3. +1
    -1
      src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZHeartJob.java
  4. +1
    -1
      src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZSyncSetting.java
  5. +1
    -1
      src/main/java/com/ssjl/zhaobiao/guizhou/service/IGZPlatformService.java
  6. +7
    -7
      src/main/java/com/ssjl/zhaobiao/guizhou/service/impl/GZPlatformCmdService.java
  7. +71
    -26
      src/main/java/com/ssjl/zhaobiao/guizhou/service/impl/GZPlatformSettingService.java
  8. +7
    -3
      src/main/java/com/ssjl/zhaobiao/guizhou/utils/GZUtil.java
  9. +2
    -1
      src/main/resources/application.properties

+ 13
- 4
src/main/java/com/ssjl/zhaobiao/guizhou/controller/IotController.java 查看文件

@@ -98,13 +98,22 @@ public class IotController {
byte[] nid = { 0x36, 0x14};
cdma.setNID(nid);

int power = 50;
GpsDeviceStatus gpsDeviceStatus = gpsDeviceStatusMapper.selectByImei(imei);
if(gpsDeviceStatus != null){
String statusStr = gpsDeviceStatus.getDeviceStatus();
IOTDeviceStatus status = IOTDeviceStatus.build(statusStr);
power = status.getBattery();
}

GZDeviceStatus deviceStatus = new GZDeviceStatus();
deviceStatus.setOpenFirst(true);
GZDevicePower devicePower = new GZDevicePower();
devicePower.setCharge(false);
devicePower.setPower(10);
GZAskLocation askLocation = new GZAskLocation(imei, 0,0,0,1,0,0,
0,0,0,0, deviceStatus, devicePower, 0, 0, true, extend);
devicePower.setPower(power);
LocalDateTime time = LocalDateTime.now();
GZAskLocation askLocation = new GZAskLocation(imei, time.getHour(),time.getMinute(),time.getSecond(),time.getDayOfMonth(),15976140,0,
63968668,0,0,0, deviceStatus, devicePower, 0, 0, true, extend);

GZRequest req = new GZRequest();
req.setImei(imei);
@@ -123,7 +132,7 @@ public class IotController {
System.out.println(JSON.toJSONString(rs));
log.info(imei + "激活返回:" + JSON.toJSONString(rs));
// 处理电信返回数据
res = (byte[]) responseHandle.process(res);
res = (byte[]) responseHandle.process(imei, res);
System.out.println(ByteUtil.bytesToHexString(res));
log.info(imei + "电信返回:" + ByteUtil.bytesToHexString(res));
return "success";


+ 7
- 11
src/main/java/com/ssjl/zhaobiao/guizhou/handle/GZResponseHandle.java 查看文件

@@ -20,7 +20,7 @@ public class GZResponseHandle {
@Autowired
GZHttpUtil gzHttpUtil;

public Object process(byte[] res) throws IOException {
public Object process(String sourceImei, byte[] res) throws IOException {
if(res[1] == 0xFF){
// 常规应答

@@ -39,9 +39,10 @@ public class GZResponseHandle {
String deviceFlag = GZUtil.byteToDeviceFlag(imeiBytes);
GZDeviceFlagType flagType = GZDeviceFlagType.IMEI;
String[] flags = deviceFlag.split(",");
if(flags.length > 1){
String phone = "";
if(flags.length > 1 && flags[1].equals("phone")){
deviceFlag = flags[0];
flagType = flags[1].equals("phone") ? GZDeviceFlagType.PHONE : GZDeviceFlagType.IMEI;
phone = flags[0];
}

// 消息序列号
@@ -57,18 +58,13 @@ public class GZResponseHandle {
IGZPlatformService service = serviceFactory.getService(msgType);
Object serviceRs = new byte[0];
if(service != null){
serviceRs = service.process(content, deviceFlag, flagType, msgIndex, status);
serviceRs = service.process(content, sourceImei, phone, msgIndex, status);
}
// 应答
GZResponse gzRs = new GZResponse();
gzRs.setIndex(msgIndex);
if(flagType == GZDeviceFlagType.PHONE){
gzRs.setPhone(deviceFlag);
gzRs.setImei("");
}else{
gzRs.setImei(deviceFlag);
gzRs.setPhone("");
}
gzRs.setPhone(phone);
gzRs.setImei(sourceImei);
gzRs.setErrorCode(GZResponseStatus.RECEIVE_SUCCESS);
log.info("应答报文:" + ByteUtil.bytesToHexString(gzRs.toBytes()));
byte[] responseRs = gzHttpUtil.send(gzRs.getImei(), gzRs.getPhone(), gzRs);


+ 1
- 1
src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZHeartJob.java 查看文件

@@ -53,7 +53,7 @@ public class GZHeartJob extends QuartzJobBean {
heart.setPower(power);
GZDeviceStatus gzStatus = new GZDeviceStatus();
heart.setStatus(gzStatus);
heart.setSignalIntensity(50);
heart.setSignalIntensity(70);
try {
byte[] res = httpUtil.send(imei, phone, heart);
// System.out.println(ByteUtil.bytesToHexString(res));


+ 1
- 1
src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZSyncSetting.java 查看文件

@@ -39,7 +39,7 @@ public class GZSyncSetting extends QuartzJobBean {
try {
byte[] res = httpUtil.send(device.getImei(), device.getPhone(), askSetting);
// System.out.println(ByteUtil.bytesToHexString(res));
res = (byte[]) responseHandle.process(res);
res = (byte[]) responseHandle.process(device.getImei(), res);
// System.out.println(ByteUtil.bytesToHexString(res));
} catch (IOException e) {
e.printStackTrace();


+ 1
- 1
src/main/java/com/ssjl/zhaobiao/guizhou/service/IGZPlatformService.java 查看文件

@@ -8,5 +8,5 @@ import java.io.IOException;

public interface IGZPlatformService {

Object process(IMessageContent msg, String deviceFlag, GZDeviceFlagType flagType, byte msgIndex, GZRequestStatus requestStatus) throws IOException;
Object process(IMessageContent msg, String imei, String phone, byte msgIndex, GZRequestStatus requestStatus) throws IOException;
}

+ 7
- 7
src/main/java/com/ssjl/zhaobiao/guizhou/service/impl/GZPlatformCmdService.java 查看文件

@@ -1,5 +1,6 @@
package com.ssjl.zhaobiao.guizhou.service.impl;

import com.google.common.base.Strings;
import com.ssjl.zhaobiao.guizhou.entity.*;
import com.ssjl.zhaobiao.guizhou.entity.GZMessage.GZPlatformCmd;
import com.ssjl.zhaobiao.guizhou.entity.GZMessage.GZUpDeviceConfig;
@@ -35,7 +36,7 @@ public class GZPlatformCmdService implements IGZPlatformCmdService {
private GZHttpUtil httpUtil;

@Override
public Object process(IMessageContent msg, String deviceFlag, GZDeviceFlagType flagType, byte msgIndex, GZRequestStatus requestStatus) throws IOException {
public Object process(IMessageContent msg, String imei, String phone, byte msgIndex, GZRequestStatus requestStatus) throws IOException {
GZPlatformCmd cmd = (GZPlatformCmd) msg;
if(cmd.getUpLocation() != null){
// 上报位置信息
@@ -44,17 +45,16 @@ public class GZPlatformCmdService implements IGZPlatformCmdService {
if(cmd.getUpSetting() != null){
// 上报设置参数
// 先查询参数

DianxinGzDeviceConfig gzConfig = null;
if(flagType == GZDeviceFlagType.IMEI){
gzConfig = gzDeviceConfigMapper.selectByImei(deviceFlag);
if(Strings.isNullOrEmpty(phone)){
gzConfig = gzDeviceConfigMapper.selectByImei(imei);
}else{
gzConfig = gzDeviceConfigMapper.selectByPhone(deviceFlag);
gzConfig = gzDeviceConfigMapper.selectByPhone(phone);
}
if(gzConfig == null){
gzConfig = new DianxinGzDeviceConfig();
gzConfig.setDeviceImei(flagType == GZDeviceFlagType.IMEI ? deviceFlag : "");
gzConfig.setPhone(flagType == GZDeviceFlagType.PHONE ? deviceFlag : "");
gzConfig.setDeviceImei(imei);
gzConfig.setPhone(phone);
}
GpsDeviceConfig dbConfig = configMapper.selectByPrimaryKey(gzConfig.getDeviceImei());



+ 71
- 26
src/main/java/com/ssjl/zhaobiao/guizhou/service/impl/GZPlatformSettingService.java 查看文件

@@ -1,6 +1,7 @@
package com.ssjl.zhaobiao.guizhou.service.impl;

import com.alibaba.fastjson.JSON;
import com.google.common.base.Strings;
import com.ssjl.zhaobiao.guizhou.entity.DianxinGzDeviceConfig;
import com.ssjl.zhaobiao.guizhou.entity.GZDeviceFlagType;
import com.ssjl.zhaobiao.guizhou.entity.GZMessage.GZLocationInterval;
@@ -27,24 +28,21 @@ public class GZPlatformSettingService implements IGZPlatformSettingService {
IOTApiUtil iotApiUtil;

@Override
public Object process(IMessageContent msg, String deviceFlag, GZDeviceFlagType flagType, byte msgIndex, GZRequestStatus requestStatus) throws IOException {
public Object process(IMessageContent msg, String imei, String phone, byte msgIndex, GZRequestStatus requestStatus) throws IOException {
GZPlatformDeviceConfig config = (GZPlatformDeviceConfig)msg;
DianxinGzDeviceConfig dbConfig = null;
String imei = "";
boolean isUpdate = true;
if(flagType == GZDeviceFlagType.PHONE){
dbConfig = configMapper.selectByPhone(deviceFlag);

}else{
dbConfig = configMapper.selectByImei(deviceFlag);
imei = deviceFlag;
}
dbConfig = configMapper.selectByImei(imei);
// if(!Strings.isNullOrEmpty(phone)){
// dbConfig = configMapper.selectByPhone(phone);
// }else{
// dbConfig = configMapper.selectByImei(imei);
// }
if(dbConfig == null){
dbConfig = new DianxinGzDeviceConfig();
dbConfig.setDeviceImei(imei);
dbConfig.setPhone(phone);
isUpdate = false;
}else{
imei = dbConfig.getDeviceImei();
}
boolean allSuccess = true;
// 下发给iot接口
@@ -114,30 +112,76 @@ public class GZPlatformSettingService implements IGZPlatformSettingService {
}
}
// 亲情号码
if(dbConfig.getAffectionPhone() == null || !dbConfig.getAffectionPhone().equals(config.getAffectionPhone())){
IotApiWhiteList whiteList = new IotApiWhiteList();
whiteList.setSerialNo(imei);
if(dbConfig.getAffectionPhone() == null || !dbConfig.getAffectionPhone().equals(config.getAffectionPhone()) ||
dbConfig.getAddressBook() == null || !dbConfig.getAddressBook().equals(config.getAddressBook())){
// if(true){
// SOS
String sos = config.getSosPhone();
if(!Strings.isNullOrEmpty(sos)){
if(sos.indexOf("/") > -1){
sos = sos.substring(0, sos.indexOf("/"));
}
for (int i = 0; i < whiteList.getWhiteList().size(); i++) {
IotApiWhiteList.IotApiWhiteListItem item = whiteList.getWhiteList().get(i);
if(item.getPhone().equals(sos)){
item.setSos(1);
}
}
}
boolean hadSos = false;
boolean isSos = false;

String[] phones = config.getAffectionPhone().split(",");
IotApiWhiteList whiteList = new IotApiWhiteList();
whiteList.setSerialNo(imei);

for (int i = 0; i < phones.length; i++) {
String phone = phones[i];
String aphone = phones[i];
String relationship = "";
if(phone.indexOf("/") > -1){
String[] pstrs = phone.split("/");
phone = pstrs[0];
if(aphone.indexOf("/") > -1){
String[] pstrs = aphone.split("/");
aphone = pstrs[0];
relationship = UnicodeUtil.unicodeToCn(pstrs[1]);
}
whiteList.addPhone(phone, relationship, String.valueOf(i + 1), i == 0 ? 1 : 0);
isSos = aphone.equals(sos);
hadSos = hadSos ? hadSos : isSos;
whiteList.addPhone(aphone, relationship , String.valueOf(i + 1), (isSos? 1 : 0));
}
IotApiResponse phoneRs = iotApiUtil.setWhiteList(whiteList);
System.out.println(JSON.toJSONString(phoneRs));
if(checkOffline(phoneRs.getMessage())){
allSuccess = false;
// 通讯录
phones = config.getAddressBook().split(",");
for (int i = 0; i < phones.length; i++) {
String aphone = phones[i];
String relationship = "";
if(aphone.indexOf("/") > -1){
String[] pstrs = aphone.split("/");
aphone = pstrs[0];
relationship = UnicodeUtil.unicodeToCn(pstrs[1]);
}
isSos = aphone.equals(sos);
hadSos = hadSos ? hadSos : isSos;
whiteList.addPhone(aphone, relationship, "", (isSos? 1 : 0));
}
}
// sos不在通讯录或亲情号码中,则另外加入白名单
if(!hadSos){
whiteList.addPhone(sos, "", "", 1);
}
if(whiteList.getWhiteList().size() > 0){
IotApiResponse phoneRs = iotApiUtil.setWhiteList(whiteList);
System.out.println(JSON.toJSONString(phoneRs));
if(checkOffline(phoneRs.getMessage())){
allSuccess = false;
}
}
}






if(allSuccess){
// 存入数据库
dbConfig.setDeviceImei(imei);
dbConfig.setPhone(config.getDevicePhone());
dbConfig.setHttpIp(config.getHttpIp());
dbConfig.setHttpUrl(config.getHttpUrl());
@@ -161,9 +205,10 @@ public class GZPlatformSettingService implements IGZPlatformSettingService {
dbConfig.setRfid(config.getRfid());
if(isUpdate){
configMapper.updateByPrimaryKey(dbConfig);
}else{
configMapper.insert(dbConfig);
}
// else{
// configMapper.insert(dbConfig);
// }
}

return new byte[0];


+ 7
- 3
src/main/java/com/ssjl/zhaobiao/guizhou/utils/GZUtil.java 查看文件

@@ -172,14 +172,18 @@ public class GZUtil {
String hex;
if(phone.length() <= 15){
hex = phone + "F";
while (hex .length() < 16){
hex = hex + "F";
}
}else{
BigInteger num = new BigInteger(phone);
hex = num.toString(16);
hex += "E";
while (hex .length() < 16){
hex = "0" + hex;
}
}
while (hex .length() < 16){
hex = "0" + hex;
}

return ByteUtil.hexToByteArray(hex);
}



+ 2
- 1
src/main/resources/application.properties 查看文件

@@ -50,7 +50,8 @@ guizhou.device.version=ACB_1001
#guizhou.device.version=TPE_0056
guizhou.http.url=http://202.105.147.30:24183
#\u5929\u6CE2
guizhou.device.testList= [{ "imei": "862622050253671","phone": "18664272743" },{ "imei": "862622050253358","phone": "18038740596" },{ "imei": "800115470000678","phone": "13500259054" }]
#guizhou.device.testList= [{ "imei": "862622050253671","phone": "18664272743" },{ "imei": "862622050253358","phone": "18038740596" },{ "imei": "800115470000678","phone": "13500259054" }]
guizhou.device.testList= [{ "imei": "862622050253671","phone": "" }]
#\u667A\u4E2D
#guizhou.device.testList= [{ "imei": "862622050654340","phone": "18985521203" },{ "imei": "862622050317740","phone": "18985521202" }]
#\u5C55\u80FD


Loading…
取消
儲存