| @@ -225,6 +225,21 @@ public class Base64TeaUitls { | |||
| return 0; | |||
| } | |||
| } | |||
| /** | |||
| * 获取byte指定的bit的值 | |||
| * @param b | |||
| * @param start | |||
| * @param end | |||
| * @return | |||
| */ | |||
| public static Integer getLowConactHighEndForByte(byte b,int start,int end){ | |||
| String bitStr = ""; | |||
| for(int i=start;i<=end;i++){ | |||
| bitStr += String.valueOf((b >> (7-i)) & 0x1); | |||
| } | |||
| return Integer.parseInt(bitStr,2); | |||
| } | |||
| public static void main(String args[]) throws UnsupportedEncodingException | |||
| { | |||
| @@ -892,4 +892,45 @@ public class BytesUtils { | |||
| return bString; | |||
| } | |||
| public static long toIntSmall(byte[] byteParams){ | |||
| return toIntSmall(0,byteParams.length-1,byteParams); | |||
| } | |||
| /** | |||
| * 转换小端序byte数组 | |||
| * @param start 数组开始下标 | |||
| * @param end 数组结束下标 | |||
| * @param byteParams 数组 | |||
| * @return | |||
| */ | |||
| public static long toIntSmall(int start,int end,byte[] byteParams){ | |||
| byte[] bs = new byte[end-start+1]; | |||
| System.arraycopy(byteParams,start,bs,0,bs.length); | |||
| int bytes = bs.length; | |||
| switch(bytes) { | |||
| case 0: | |||
| return 0; | |||
| case 1: | |||
| return (long)((bs[0] & 0xff)); | |||
| case 2: | |||
| return (long)((bs[0] & 0xff) | (bs[1] & 0xff)<<8); | |||
| case 3: | |||
| return (long)((bs[0] & 0xff) | (bs[1] & 0xff) <<8 | (bs[2] & 0xff) <<16); | |||
| case 4: | |||
| return (long)((bs[0] & 0xffL) | (bs[1] & 0xffL) <<8 | (bs[2] & 0xffL) << 16 | (bs[3] & 0xffL) <<24 ); | |||
| case 5: | |||
| return (long)((bs[0] & 0xffL) | (bs[1] & 0xffL) <<8 | (bs[2] & 0xffL) << 16 | (bs[3] & 0xffL) <<24 | (bs[4] & 0xffL) << 32); | |||
| case 6: | |||
| return (long)((bs[0] & 0xffL) | (bs[1] & 0xffL) <<8 | (bs[2] & 0xffL) <<16 | (bs[3] & 0xffL) << 24 | (bs[4] & 0xffL) <<32 | (bs[5] & 0xffL) << 40); | |||
| case 7: | |||
| return (long)((bs[0] & 0xffL) | (bs[1] & 0xffL) <<8 | (bs[2] & 0xffL) <<16 | (bs[3] & 0xffL) <<24 | (bs[4] & 0xffL) << 32 | (bs[5] & 0xffL) <<40 | (bs[6] & 0xffL) << 48); | |||
| case 8: | |||
| return (long)((bs[0] & 0xffL) | (bs[1] & 0xffL) << 8 | (bs[2] & 0xffL) <<16 | (bs[3] & 0xffL)<<24 | | |||
| (bs[4] & 0xffL) <<32 | (bs[5] & 0xffL) << 40 | (bs[6] & 0xffL) <<48 | (bs[7] & 0xffL) << 56); | |||
| default: | |||
| return 0; | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,32 @@ | |||
| package com.inet.ailink.receiver.common.utils; | |||
| import com.inet.ailink.receiver.entity.Tlv; | |||
| import java.util.ArrayList; | |||
| import java.util.Arrays; | |||
| import java.util.List; | |||
| public abstract class TlvUtils { | |||
| /** | |||
| * 将16进制字符串转换为TLV对象列表 | |||
| * @param paramsByte | |||
| * @param position 开始下标 | |||
| * @return | |||
| */ | |||
| public static List<Tlv> builderTlvList(byte[] paramsByte,int position) { | |||
| List<Tlv> tlvs = new ArrayList<Tlv>(); | |||
| while (position != paramsByte.length) { | |||
| Integer _tag = Integer.parseInt(Base64TeaUitls.getLowConactHighEndForInt(position, position, paramsByte)); | |||
| if(_tag == 0){ | |||
| break; | |||
| } | |||
| Integer _length = Integer.parseInt(Base64TeaUitls.getLowConactHighEndForInt(position+1, position+1, paramsByte)); | |||
| byte[] _value = Arrays.copyOfRange(paramsByte,position+2,position+2+_length); | |||
| position = position + 2 +_length; | |||
| tlvs.add(new Tlv(_tag, _length, _value)); | |||
| } | |||
| return tlvs; | |||
| } | |||
| } | |||
| @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; | |||
| public class Response<T>{ | |||
| private String status; | |||
| public T data; | |||
| private String config; | |||
| public Response(){} | |||
| @@ -26,5 +27,11 @@ public class Response<T>{ | |||
| } | |||
| public String getConfig() { | |||
| return config; | |||
| } | |||
| public void setConfig(String config) { | |||
| this.config = config; | |||
| } | |||
| } | |||
| @@ -4,6 +4,7 @@ import com.inet.ailink.receiver.common.enums.StatusCode; | |||
| import com.inet.ailink.receiver.common.exception.BizException; | |||
| import com.inet.ailink.receiver.common.utils.Base64TeaUitls; | |||
| import com.inet.ailink.receiver.common.utils.JsonUtils; | |||
| import com.inet.ailink.receiver.common.utils.StringSelfUtil; | |||
| import com.inet.ailink.receiver.common.vo.Response; | |||
| import com.inet.ailink.receiver.service.impl.SysAccoountServiceImpl; | |||
| import org.slf4j.Logger; | |||
| @@ -199,5 +200,28 @@ public abstract class BaseController extends java.beans.PropertyEditorSupport | |||
| } | |||
| return paramsByte; | |||
| } | |||
| /** | |||
| * 写回加密数据 | |||
| * @param response | |||
| * @param result | |||
| * @throws IOException | |||
| */ | |||
| public void writeOutResponse(HttpServletRequest request,byte[] paramsByte,HttpServletResponse response,Response<Object> result) throws IOException{ | |||
| if(result == null){ | |||
| result = new Response<Object>(); | |||
| result.setStatus(StatusCode.SUCCESS.getCode()); | |||
| //设备id | |||
| Integer deviceId = Integer.parseInt(Base64TeaUitls.getLowConactHighEndForLong(0, 3, paramsByte)+""); | |||
| if(deviceId != null){ | |||
| //查询APP设置的设备配置信息 | |||
| String deviceConfig = ""; | |||
| if(!StringSelfUtil.isEmpty(deviceConfig)){ | |||
| result.setConfig(deviceConfig); | |||
| } | |||
| } | |||
| } | |||
| writeOutResponse(response,result); | |||
| } | |||
| } | |||
| @@ -4,6 +4,7 @@ | |||
| import com.inet.ailink.receiver.common.vo.Response; | |||
| import com.inet.ailink.receiver.service.impl.BloodPressureServiceImpl; | |||
| import com.inet.ailink.receiver.service.impl.BodyFatServiceImpl; | |||
| import com.inet.ailink.receiver.service.impl.TrackPositionerLogsServiceImpl; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.*; | |||
| @@ -21,6 +22,9 @@ public class DeDataBaseController extends BaseController { | |||
| @Autowired | |||
| private BloodPressureServiceImpl bloodPressureServiceImpl; | |||
| @Autowired | |||
| private TrackPositionerLogsServiceImpl trackPositionerLogsServiceImpl; | |||
| /** | |||
| * 4G/WIFI+BLE设备测量结果数据 | |||
| * @param params | |||
| @@ -34,14 +38,14 @@ public class DeDataBaseController extends BaseController { | |||
| checkParams(response, params,cid,vid,pid); | |||
| byte[] paramsByte = decryptParams(response,params); | |||
| if(paramsByte.length >1){ | |||
| //WIFI_BLE体脂秤 cid = 17 ,WIFI体脂秤 cid = 25 ,4G体脂秤 cid = 57 | |||
| if(cid == 17 || cid == 25 || cid == 57){ | |||
| if(cid == 17 || cid == 25 || cid == 57){//WIFI_BLE体脂秤 cid = 17 ,WIFI体脂秤 cid = 25 ,4G体脂秤 cid = 57 | |||
| writeOutResponse(response, bodyFatServiceImpl.saveWeighDataByAdc(paramsByte, request)); | |||
| } | |||
| //4G血压仪 cid = 48,WIFI+BLE血压仪 cid = 56 | |||
| else if(cid == 48 || cid == 56){ | |||
| }else if(cid == 48 || cid == 56){//4G血压仪 cid = 48,WIFI+BLE血压仪 cid = 56 | |||
| writeOutResponse(response, bloodPressureServiceImpl.saveOrUpdateBloodPressure(paramsByte, request)); | |||
| }else{ | |||
| }else if(cid == 121 || cid == 144){//一次性温湿度计CID=144[0x0090] | |||
| writeOutResponse(request,paramsByte,response, trackPositionerLogsServiceImpl.saveTrackPositionerLogsBatch(paramsByte, request)); | |||
| } | |||
| else{ | |||
| Response<Object> result = new Response<Object>(); | |||
| result.setStatus(StatusCode.DEVICE_UN_SUPPORT.getCode()); | |||
| writeOutResponse(response, result); | |||
| @@ -50,6 +54,5 @@ public class DeDataBaseController extends BaseController { | |||
| writeOutResponse(response,paramsByte); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -14,7 +14,6 @@ | |||
| import java.io.IOException; | |||
| @RestController | |||
| //@RequestMapping(value="devivce",produces={"application/json;charset=UTF-8"}) | |||
| @RequestMapping(value="devivce") | |||
| public class DeviceController extends BaseController { | |||
| @@ -26,6 +26,11 @@ | |||
| private String deviceUnit; | |||
| private Integer appUserId; | |||
| private String imei; | |||
| private String iccid; | |||
| private String deviceAutoSn; | |||
| private Integer SleepTime; | |||
| public Device(){} | |||
| @@ -171,5 +176,36 @@ | |||
| this.appUserId = appUserId; | |||
| } | |||
| public String getImei() { | |||
| return imei; | |||
| } | |||
| public void setImei(String imei) { | |||
| this.imei = imei; | |||
| } | |||
| public String getIccid() { | |||
| return iccid; | |||
| } | |||
| public void setIccid(String iccid) { | |||
| this.iccid = iccid; | |||
| } | |||
| public String getDeviceAutoSn() { | |||
| return deviceAutoSn; | |||
| } | |||
| public void setDeviceAutoSn(String deviceAutoSn) { | |||
| this.deviceAutoSn = deviceAutoSn; | |||
| } | |||
| public Integer getSleepTime() { | |||
| return SleepTime; | |||
| } | |||
| public void setSleepTime(Integer sleepTime) { | |||
| SleepTime = sleepTime; | |||
| } | |||
| } | |||
| @@ -0,0 +1,48 @@ | |||
| package com.inet.ailink.receiver.entity; | |||
| public class Tlv { | |||
| /** 子域Tag标签 */ | |||
| private Integer tag; | |||
| /** 子域取值的长度 */ | |||
| private Integer length; | |||
| /** 子域取值 */ | |||
| private byte[] value; | |||
| public Tlv(Integer tag, Integer length, byte[] value) { | |||
| this.length = length; | |||
| this.tag = tag; | |||
| this.value = value; | |||
| } | |||
| public Integer getTag() { | |||
| return tag; | |||
| } | |||
| public void setTag(Integer tag) { | |||
| this.tag = tag; | |||
| } | |||
| public Integer getLength() { | |||
| return length; | |||
| } | |||
| public void setLength(Integer length) { | |||
| this.length = length; | |||
| } | |||
| public byte[] getValue() { | |||
| return value; | |||
| } | |||
| public void setValue(byte[] value) { | |||
| this.value = value; | |||
| } | |||
| @Override | |||
| public String toString() { | |||
| return "tag=[" + this.tag + "]," + "length=[" + this.length + "]," + "value=[" + this.value + "]"; | |||
| } | |||
| } | |||
| @@ -0,0 +1,613 @@ | |||
| /** | |||
| * Copyright (c) 2020-2020 yann | |||
| * Licensed under the Apache License, Version 1.0 (the "License"); | |||
| */ | |||
| package com.inet.ailink.receiver.entity; | |||
| @SuppressWarnings("serial") | |||
| public class TrackPositionerLogs extends BaseEntity { | |||
| //alias | |||
| public static final String TABLE_ALIAS = "TrackPositionerLogs"; | |||
| public static final String ALIAS_APP_USER_ID = "用户id"; | |||
| public static final String ALIAS_SUB_USER_ID = "子用户id"; | |||
| public static final String ALIAS_DEVICE_ID = "设备id"; | |||
| public static final String ALIAS_DATA_FROM = "数据来源(0:手动;其他值:设备CID)"; | |||
| public static final String ALIAS_UPLOAD_TIME = "实际数据产生时间戳"; | |||
| public static final String ALIAS_LOCATE_MODE = "定位方式:0:经纬度;1:基站;2:WIFI"; | |||
| public static final String ALIAS_LON = "经度"; | |||
| public static final String ALIAS_LAT = "纬度"; | |||
| public static final String ALIAS_SITUATION = "前进方向;"; | |||
| public static final String ALIAS_SPEED = "速度,单位;千米每小时"; | |||
| public static final String ALIAS_LBS_SERVER_TYPE = "定位服务商类型"; | |||
| public static final String ALIAS_LBS_SERVER_ID = "定位服务商ID"; | |||
| public static final String ALIAS_ACCESSTYPE = "移动端接入网络方式:可选值:"; | |||
| public static final String ALIAS_CDMA = "手机卡是否为 CDMA 卡"; | |||
| public static final String ALIAS_NETWORK = "无线网络类型 "; | |||
| public static final String ALIAS_BTS = "接入基站信息"; | |||
| public static final String ALIAS_MMAC = "已连接 WiFi 信息"; | |||
| public static final String ALIAS_MACS = "WiFi 列表中的 WiFi 信息"; | |||
| public static final String ALIAS_SHOW_FIELDS = "逆地理编码结果开关,打开则放回地理位置信息"; | |||
| public static final String ALIAS_LBS_SERVER_STATUS = "定位服务商请求状态码"; | |||
| public static final String ALIAS_LBS_SERVER_MSG = "定位服务商请求提示信息"; | |||
| public static final String ALIAS_POSITION_LON = "定位结果-经度"; | |||
| public static final String ALIAS_POSITION_LAT = "定位结果-纬度"; | |||
| public static final String ALIAS_ADDRESS_COUNTRY = "国家 (非必返回)"; | |||
| public static final String ALIAS_ADDRESS_PROVINCE = "省份 (非必返回)"; | |||
| public static final String ALIAS_ADDRESS_CITY = "城市 (非必返回)"; | |||
| public static final String ALIAS_ADDRESS_DISTRICT = "区 (非必返回)"; | |||
| public static final String ALIAS_ADDRESS_CITYCODE = "城市编码 (非必返回)"; | |||
| public static final String ALIAS_ADDRESS_ADCODE = "区域编码 (非必返回)"; | |||
| public static final String ALIAS_ADDRESS_STREET = "附近街道名称 (非必返回)"; | |||
| public static final String ALIAS_ADDRESS_ROAD = "周边道路名称 (非必返回)"; | |||
| //columns START | |||
| private Integer appUserId; | |||
| private Integer subUserId; | |||
| private Integer deviceId; | |||
| private Integer dataFrom; | |||
| private String uploadTime; | |||
| private String locateMode; | |||
| private String lon; | |||
| private String lat; | |||
| private String situation; | |||
| private String speed; | |||
| private Integer lbsServerRequest; | |||
| private Integer lbsServerType; | |||
| private Long lbsServerId; | |||
| private Integer accesstype; | |||
| private Integer cdma; | |||
| private Integer network; | |||
| private String bts; | |||
| private String mmac; | |||
| private String macs; | |||
| private Integer showFields; | |||
| private String lbsServerStatus; | |||
| private String lbsServerMsg; | |||
| private String positionLon; | |||
| private String positionLat; | |||
| private String addressCountry; | |||
| private String addressProvince; | |||
| private String addressCity; | |||
| private String addressDistrict; | |||
| private String addressCitycode; | |||
| private String addressAdcode; | |||
| private String addressStreet; | |||
| private String addressRoad; | |||
| private Integer power; | |||
| private String addressAll; | |||
| private String imei; | |||
| private String imsi; | |||
| private String mobile; | |||
| private String stationIp; | |||
| private String tel; | |||
| private String nearbts; | |||
| private String temperature; | |||
| private String humidity; | |||
| private String pa; | |||
| private String altitude; | |||
| private int warnStatus; | |||
| private int warnDetachmentStatus; | |||
| private int warnSosStatus; | |||
| private int warnFallStatus; | |||
| private int warnPowerStatus; | |||
| private int warnTemperatureStatus; | |||
| private int warnHumidityStatus; | |||
| private int warnPaStatus; | |||
| private int warnAltitudeStatus; | |||
| private int warnSpeedStatus; | |||
| private Integer warnBreakStatus; | |||
| private String oldParams; | |||
| private String light; | |||
| private String deviceConf; | |||
| private Integer outLine; | |||
| //columns END | |||
| public TrackPositionerLogs(){ | |||
| } | |||
| public Integer getOutLine() { | |||
| return outLine; | |||
| } | |||
| public void setOutLine(Integer outLine) { | |||
| this.outLine = outLine; | |||
| } | |||
| public String getDeviceConf() { | |||
| return deviceConf; | |||
| } | |||
| public void setDeviceConf(String deviceConf) { | |||
| this.deviceConf = deviceConf; | |||
| } | |||
| public String getLight() { | |||
| return light; | |||
| } | |||
| public void setLight(String light) { | |||
| this.light = light; | |||
| } | |||
| public int getWarnSpeedStatus() { | |||
| return warnSpeedStatus; | |||
| } | |||
| public void setWarnSpeedStatus(int warnSpeedStatus) { | |||
| this.warnSpeedStatus = warnSpeedStatus; | |||
| } | |||
| public int getWarnTemperatureStatus() { | |||
| return warnTemperatureStatus; | |||
| } | |||
| public void setWarnTemperatureStatus(int warnTemperatureStatus) { | |||
| this.warnTemperatureStatus = warnTemperatureStatus; | |||
| } | |||
| public int getWarnHumidityStatus() { | |||
| return warnHumidityStatus; | |||
| } | |||
| public void setWarnHumidityStatus(int warnHumidityStatus) { | |||
| this.warnHumidityStatus = warnHumidityStatus; | |||
| } | |||
| public int getWarnPaStatus() { | |||
| return warnPaStatus; | |||
| } | |||
| public void setWarnPaStatus(int warnPaStatus) { | |||
| this.warnPaStatus = warnPaStatus; | |||
| } | |||
| public int getWarnAltitudeStatus() { | |||
| return warnAltitudeStatus; | |||
| } | |||
| public void setWarnAltitudeStatus(int warnAltitudeStatus) { | |||
| this.warnAltitudeStatus = warnAltitudeStatus; | |||
| } | |||
| public int getWarnStatus() { | |||
| return warnStatus; | |||
| } | |||
| public void setWarnStatus(int warnStatus) { | |||
| this.warnStatus = warnStatus; | |||
| } | |||
| public String getTemperature() { | |||
| return temperature; | |||
| } | |||
| public void setTemperature(String temperature) { | |||
| this.temperature = temperature; | |||
| } | |||
| public String getHumidity() { | |||
| return humidity; | |||
| } | |||
| public void setHumidity(String humidity) { | |||
| this.humidity = humidity; | |||
| } | |||
| public String getPa() { | |||
| return pa; | |||
| } | |||
| public void setPa(String pa) { | |||
| this.pa = pa; | |||
| } | |||
| public String getAltitude() { | |||
| return altitude; | |||
| } | |||
| public void setAltitude(String altitude) { | |||
| this.altitude = altitude; | |||
| } | |||
| public String getAddressAll() { | |||
| return addressAll; | |||
| } | |||
| public void setAddressAll(String addressAll) { | |||
| this.addressAll = addressAll; | |||
| } | |||
| public int getWarnDetachmentStatus() { | |||
| return warnDetachmentStatus; | |||
| } | |||
| public void setWarnDetachmentStatus(int warnDetachmentStatus) { | |||
| this.warnDetachmentStatus = warnDetachmentStatus; | |||
| } | |||
| public int getWarnSosStatus() { | |||
| return warnSosStatus; | |||
| } | |||
| public void setWarnSosStatus(int warnSosStatus) { | |||
| this.warnSosStatus = warnSosStatus; | |||
| } | |||
| public int getWarnFallStatus() { | |||
| return warnFallStatus; | |||
| } | |||
| public void setWarnFallStatus(int warnFallStatus) { | |||
| this.warnFallStatus = warnFallStatus; | |||
| } | |||
| public int getWarnPowerStatus() { | |||
| return warnPowerStatus; | |||
| } | |||
| public void setWarnPowerStatus(int warnPowerStatus) { | |||
| this.warnPowerStatus = warnPowerStatus; | |||
| } | |||
| public Integer getPower() { | |||
| return power; | |||
| } | |||
| public void setPower(Integer power) { | |||
| this.power = power; | |||
| } | |||
| public Integer getLbsServerRequest() { | |||
| return lbsServerRequest; | |||
| } | |||
| public void setLbsServerRequest(Integer lbsServerRequest) { | |||
| this.lbsServerRequest = lbsServerRequest; | |||
| } | |||
| public Integer getAppUserId() { | |||
| return appUserId; | |||
| } | |||
| public void setAppUserId(Integer appUserId) { | |||
| this.appUserId = appUserId; | |||
| } | |||
| public Integer getSubUserId() { | |||
| return subUserId; | |||
| } | |||
| public void setSubUserId(Integer subUserId) { | |||
| this.subUserId = subUserId; | |||
| } | |||
| public Integer getDeviceId() { | |||
| return deviceId; | |||
| } | |||
| public void setDeviceId(Integer deviceId) { | |||
| this.deviceId = deviceId; | |||
| } | |||
| public void setDataFrom(Integer value) { | |||
| this.dataFrom = value; | |||
| } | |||
| public Integer getDataFrom() { | |||
| return this.dataFrom; | |||
| } | |||
| public void setUploadTime(String value) { | |||
| this.uploadTime = value; | |||
| } | |||
| public String getUploadTime() { | |||
| return this.uploadTime; | |||
| } | |||
| public void setLocateMode(String value) { | |||
| this.locateMode = value; | |||
| } | |||
| public String getLocateMode() { | |||
| return this.locateMode; | |||
| } | |||
| public void setLon(String value) { | |||
| this.lon = value; | |||
| } | |||
| public String getLon() { | |||
| return this.lon; | |||
| } | |||
| public void setLat(String value) { | |||
| this.lat = value; | |||
| } | |||
| public String getLat() { | |||
| return this.lat; | |||
| } | |||
| public void setSituation(String value) { | |||
| this.situation = value; | |||
| } | |||
| public String getSituation() { | |||
| return this.situation; | |||
| } | |||
| public void setSpeed(String value) { | |||
| this.speed = value; | |||
| } | |||
| public String getSpeed() { | |||
| return this.speed; | |||
| } | |||
| public void setLbsServerType(Integer value) { | |||
| this.lbsServerType = value; | |||
| } | |||
| public Integer getLbsServerType() { | |||
| return this.lbsServerType; | |||
| } | |||
| public void setLbsServerId(Long value) { | |||
| this.lbsServerId = value; | |||
| } | |||
| public Long getLbsServerId() { | |||
| return this.lbsServerId; | |||
| } | |||
| public void setAccesstype(Integer value) { | |||
| this.accesstype = value; | |||
| } | |||
| public Integer getAccesstype() { | |||
| return this.accesstype; | |||
| } | |||
| public void setCdma(Integer value) { | |||
| this.cdma = value; | |||
| } | |||
| public Integer getCdma() { | |||
| return this.cdma; | |||
| } | |||
| public void setNetwork(Integer value) { | |||
| this.network = value; | |||
| } | |||
| public Integer getNetwork() { | |||
| return this.network; | |||
| } | |||
| public void setBts(String value) { | |||
| this.bts = value; | |||
| } | |||
| public String getBts() { | |||
| return this.bts; | |||
| } | |||
| public void setMmac(String value) { | |||
| this.mmac = value; | |||
| } | |||
| public String getMmac() { | |||
| return this.mmac; | |||
| } | |||
| public void setMacs(String value) { | |||
| this.macs = value; | |||
| } | |||
| public String getMacs() { | |||
| return this.macs; | |||
| } | |||
| public void setShowFields(Integer value) { | |||
| this.showFields = value; | |||
| } | |||
| public Integer getShowFields() { | |||
| return this.showFields; | |||
| } | |||
| public void setLbsServerStatus(String value) { | |||
| this.lbsServerStatus = value; | |||
| } | |||
| public String getLbsServerStatus() { | |||
| return this.lbsServerStatus; | |||
| } | |||
| public void setLbsServerMsg(String value) { | |||
| this.lbsServerMsg = value; | |||
| } | |||
| public String getLbsServerMsg() { | |||
| return this.lbsServerMsg; | |||
| } | |||
| public void setPositionLon(String value) { | |||
| this.positionLon = value; | |||
| } | |||
| public String getPositionLon() { | |||
| return this.positionLon; | |||
| } | |||
| public void setPositionLat(String value) { | |||
| this.positionLat = value; | |||
| } | |||
| public String getPositionLat() { | |||
| return this.positionLat; | |||
| } | |||
| public void setAddressCountry(String value) { | |||
| this.addressCountry = value; | |||
| } | |||
| public String getAddressCountry() { | |||
| return this.addressCountry; | |||
| } | |||
| public void setAddressProvince(String value) { | |||
| this.addressProvince = value; | |||
| } | |||
| public String getAddressProvince() { | |||
| return this.addressProvince; | |||
| } | |||
| public void setAddressCity(String value) { | |||
| this.addressCity = value; | |||
| } | |||
| public String getAddressCity() { | |||
| return this.addressCity; | |||
| } | |||
| public void setAddressDistrict(String value) { | |||
| this.addressDistrict = value; | |||
| } | |||
| public String getAddressDistrict() { | |||
| return this.addressDistrict; | |||
| } | |||
| public void setAddressCitycode(String value) { | |||
| this.addressCitycode = value; | |||
| } | |||
| public String getAddressCitycode() { | |||
| return this.addressCitycode; | |||
| } | |||
| public void setAddressAdcode(String value) { | |||
| this.addressAdcode = value; | |||
| } | |||
| public String getAddressAdcode() { | |||
| return this.addressAdcode; | |||
| } | |||
| public void setAddressStreet(String value) { | |||
| this.addressStreet = value; | |||
| } | |||
| public String getAddressStreet() { | |||
| return this.addressStreet; | |||
| } | |||
| public void setAddressRoad(String value) { | |||
| this.addressRoad = value; | |||
| } | |||
| public String getAddressRoad() { | |||
| return this.addressRoad; | |||
| } | |||
| public String getImei() { | |||
| return imei; | |||
| } | |||
| public void setImei(String imei) { | |||
| this.imei = imei; | |||
| } | |||
| public String getImsi() { | |||
| return imsi; | |||
| } | |||
| public void setImsi(String imsi) { | |||
| this.imsi = imsi; | |||
| } | |||
| public String getMobile() { | |||
| return mobile; | |||
| } | |||
| public void setMobile(String mobile) { | |||
| this.mobile = mobile; | |||
| } | |||
| public String getStationIp() { | |||
| return stationIp; | |||
| } | |||
| public void setStationIp(String stationIp) { | |||
| this.stationIp = stationIp; | |||
| } | |||
| public String getTel() { | |||
| return tel; | |||
| } | |||
| public void setTel(String tel) { | |||
| this.tel = tel; | |||
| } | |||
| public String getNearbts() { | |||
| return nearbts; | |||
| } | |||
| public void setNearbts(String nearbts) { | |||
| this.nearbts = nearbts; | |||
| } | |||
| public Integer getWarnBreakStatus() { | |||
| return warnBreakStatus; | |||
| } | |||
| public void setWarnBreakStatus(Integer warnBreakStatus) { | |||
| this.warnBreakStatus = warnBreakStatus; | |||
| } | |||
| public String getOldParams() { | |||
| return oldParams; | |||
| } | |||
| public void setOldParams(String oldParams) { | |||
| this.oldParams = oldParams; | |||
| } | |||
| } | |||
| @@ -0,0 +1,12 @@ | |||
| /** | |||
| * Copyright (c) 2020-2020 yann | |||
| * Licensed under the Apache License, Version 1.0 (the "License"); | |||
| */ | |||
| package com.inet.ailink.receiver.mapper; | |||
| import com.inet.ailink.receiver.entity.TrackPositionerLogs; | |||
| public interface ITrackPositionerLogsDao extends BaseDao<TrackPositionerLogs>{ | |||
| } | |||
| @@ -43,7 +43,6 @@ | |||
| //解析数据 | |||
| //设备ID【0-3】 | |||
| Integer deviceId = Integer.parseInt(Base64TeaUitls.getLowConactHighEndForLong(0, 3, paramsByte)+""); | |||
| String deviceId2 = Base64TeaUitls.getStartToEndForHex(0, 3, paramsByte); | |||
| //舒张压【4-5】 | |||
| String dia = Base64TeaUitls.getLowConactHighEndForInt(4, 5, paramsByte); | |||
| //收缩压【6-7】 | |||
| @@ -93,7 +92,6 @@ | |||
| result.setStatus(StatusCode.SUCCESS.getCode()); | |||
| } | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| result.setStatus(StatusCode.PARAMS_dECRYPT_ERROR.getCode()); | |||
| } | |||
| return result; | |||
| @@ -4,9 +4,11 @@ | |||
| import com.inet.ailink.receiver.common.utils.Base64TeaUitls; | |||
| import com.inet.ailink.receiver.common.utils.JsonUtils; | |||
| import com.inet.ailink.receiver.common.utils.StringSelfUtil; | |||
| import com.inet.ailink.receiver.common.utils.TlvUtils; | |||
| import com.inet.ailink.receiver.common.vo.Response; | |||
| import com.inet.ailink.receiver.entity.Device; | |||
| import com.inet.ailink.receiver.entity.DeviceType; | |||
| import com.inet.ailink.receiver.entity.Tlv; | |||
| import com.inet.ailink.receiver.mapper.ISysDeviceInfoDao; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| @@ -15,6 +17,7 @@ | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import java.nio.charset.StandardCharsets; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| @Service | |||
| @Transactional(rollbackFor=Exception.class) | |||
| @@ -48,21 +51,10 @@ | |||
| } | |||
| return sb.toString(); | |||
| } | |||
| // public static byte[] hexStr2ByteArr(String strIn) { | |||
| // byte[] arrB = strIn.getBytes(); | |||
| // int iLen = arrB.length; | |||
| // | |||
| // // 两个字符表示一个字节,所以字节数组长度是字符串长度除以2 | |||
| // byte[] arrOut = new byte[iLen / 2]; | |||
| // for (int i = 0; i < iLen; i = i + 2) { | |||
| // String strTmp = new String(arrB, i, 2); | |||
| // arrOut[i / 2] = (byte) Integer.parseInt(strTmp, 16); | |||
| // } | |||
| // return arrOut; | |||
| // } | |||
| public Response<Object> register(byte[] paramsByte, HttpServletRequest request){ | |||
| // System.out.println("register(): " + byteArr2HexStr(paramsByte)); | |||
| public Response<Object> register(byte[] paramsByte,HttpServletRequest request){ | |||
| // System.out.println("register(): " + byteArr2HexStr(paramsByte)); | |||
| Response<Object> result = new Response<Object>(); | |||
| //解析数据 | |||
| //设备地址 | |||
| @@ -75,15 +67,9 @@ | |||
| String deviceName = Base64TeaUitls.getStartToEndForHex(12, 13, paramsByte); | |||
| //产品型号 | |||
| String deviceType = Base64TeaUitls.getStartToEndForHex(14, 14, paramsByte); | |||
| // //硬件版本 | |||
| // String deviceHardwareVersion = Base64TeaUitls.getStartToEndForInt(15, 15, paramsByte); | |||
| // //软件版本 | |||
| // String deviceSoftwareVersion = Base64TeaUitls.getStartToEndForInt(16, 16, paramsByte); | |||
| // //用户版本 | |||
| // String deviceUserAutoVersion = Base64TeaUitls.getStartToEndForInt(17, 17, paramsByte); | |||
| // //年月日 | |||
| // //年月日 | |||
| String deviceDate = Base64TeaUitls.getStartToEndForInt(18, 20, paramsByte); | |||
| // System.out.println("deviceDate: " + deviceDate); | |||
| // System.out.println("deviceDate: " + deviceDate); | |||
| //芯片id | |||
| String chipId = Base64TeaUitls.getStartToEndForHex(21, 26, paramsByte); | |||
| //设备SN [12-14]WM05+[0-5]设备地址+[21-26]芯片id | |||
| @@ -93,50 +79,94 @@ | |||
| String deviceUnit = Base64TeaUitls.getStartToEndForInt(27, 27, paramsByte); | |||
| //如果IMEI不为空,则使用IMEI当作设备的唯一标识 | |||
| String imei = null; | |||
| int imeiLength=0; | |||
| String iccid = ""; | |||
| String deviceAutoSn = ""; | |||
| String deviceTypeNew = ""; | |||
| String sleepTime = "0"; | |||
| if(paramsByte.length > 28){ | |||
| //设备IMEI长度 | |||
| int imeiLength = Integer.parseInt(Base64TeaUitls.getStartToEndForInt(28, 28, paramsByte)); | |||
| imeiLength = Integer.parseInt(Base64TeaUitls.getStartToEndForInt(28, 28, paramsByte)); | |||
| if(imeiLength > 0){ | |||
| //获取imei | |||
| imei = Base64TeaUitls.getStartToEndForASIII(28+1, 28+imeiLength, paramsByte); | |||
| } | |||
| } | |||
| int imeiEnd = 28+imeiLength+1;//28+5+1=34 | |||
| //从IMEI结束,为TLV格式数据 | |||
| //根据数据类型,截分数据 | |||
| List<Tlv> tlvs = TlvUtils.builderTlvList(paramsByte, imeiEnd); | |||
| if (tlvs != null || tlvs.size() > 0) { | |||
| for (Tlv tlv : tlvs) { | |||
| if (tlv.getValue() != null && tlv.getValue().length > 0) { | |||
| try { | |||
| //设备SIM卡ICCID的ASCII对应的HEX值 : T=0x01 L=value的长度; | |||
| if (tlv.getTag() == 1) { | |||
| iccid = Base64TeaUitls.getStartToEndForASIII(0,tlv.getLength()-1,tlv.getValue()); | |||
| iccid = iccid.replaceAll(":",""); | |||
| continue; | |||
| } | |||
| //设备自定义SN对应的HEX值 : T=0x02 L=value的长度; | |||
| if (tlv.getTag() == 2) { | |||
| deviceAutoSn = Base64TeaUitls.getStartToEndForASIII(0,tlv.getLength()-1,tlv.getValue()); | |||
| deviceAutoSn = deviceAutoSn.replaceAll(":",""); | |||
| continue; | |||
| } | |||
| //产品型号对应的HEX值 : T=0x03 L=value的长度; | |||
| if (tlv.getTag() == 3) { | |||
| deviceTypeNew = Base64TeaUitls.getStartToEndForASIII(0,tlv.getLength()-1,tlv.getValue()); | |||
| deviceTypeNew = deviceTypeNew.replaceAll(":",""); | |||
| continue; | |||
| } | |||
| //延时对应的HEX值,整型,单位:分钟 : T=0x04 L=value的长度; | |||
| if (tlv.getTag() == 4) { | |||
| sleepTime = Base64TeaUitls.getStartToEndForASIII(0,tlv.getLength()-1,tlv.getValue()); | |||
| sleepTime = sleepTime.replaceAll(":",""); | |||
| continue; | |||
| } | |||
| } catch (Exception e) { | |||
| continue; | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| //将解析出的数据,赋值 | |||
| // Device device = new Device(deviceName, deviceMac, new Date(), cid, pid, vid, "", | |||
| // deviceType,deviceSoftwareVersion, deviceHardwareVersion, deviceUserAutoVersion, deviceDate,chipId,deviceSN,deviceUnit); | |||
| byte[] name = new byte[2]; | |||
| name[0] = paramsByte[12]; | |||
| name[1] = paramsByte[13]; | |||
| String moduleName = new String(name, StandardCharsets.UTF_8); | |||
| // System.out.println("moduleName: " + moduleName); | |||
| int type = paramsByte[14] & 0xFF; | |||
| String moduleType = (type<10?("0"):"") + type; | |||
| // System.out.println("moduleType: " + moduleType); | |||
| int hardware = paramsByte[15] & 0xFF; | |||
| String hardwareVer = "H" + hardware; | |||
| // System.out.println("hardwareVer: " + hardwareVer); | |||
| int software = paramsByte[16] & 0xFF; | |||
| String softwareVer = "S" + String.valueOf(software / 10) + "." + String.valueOf(software % 10); | |||
| // System.out.println("softwareVer: " + softwareVer); | |||
| int custom = paramsByte[17] & 0xFF; | |||
| String customVer = "." + String.valueOf(custom); | |||
| // System.out.println("customVer: " + customVer); | |||
| int year = paramsByte[18] & 0xFF; | |||
| int month = paramsByte[19] & 0xFF; | |||
| int day = paramsByte[20] & 0xFF; | |||
| String dateStr = "_20" + (year<10?("0"+year):year) + (month<10?("0"+month):month) + (day<10?("0"+day):day); | |||
| // System.out.println("dateStr: " + dateStr); | |||
| String version = moduleName + moduleType + hardwareVer + softwareVer + customVer + dateStr; | |||
| // System.out.println("version: " + version); | |||
| if(!StringSelfUtil.isEmpty(deviceTypeNew)){ | |||
| version = deviceTypeNew; | |||
| } | |||
| Device device = new Device(null, deviceMac, new Date(), cid, pid, vid, "", | |||
| null, version, null, null, null, chipId, deviceSN, deviceUnit); | |||
| //如果IMEI不为空,则使用IMEI当作设备的唯一标识 | |||
| if(imei != null && !StringSelfUtil.isEmpty(imei)){ | |||
| device.setMac(imei.replaceAll(":", "")); | |||
| device.setDeviceSN(imei.replaceAll(":", "")); | |||
| device.setImei(imei.replaceAll(":", "")); | |||
| } | |||
| if(!StringSelfUtil.isEmpty(iccid)){ | |||
| device.setIccid(iccid); | |||
| } | |||
| if(!StringSelfUtil.isEmpty(deviceAutoSn)){ | |||
| device.setDeviceAutoSn(deviceAutoSn); | |||
| } | |||
| System.out.println(JsonUtils.toJson(device)); | |||
| device.setSleepTime(Integer.parseInt(sleepTime)); | |||
| //注册设备 | |||
| result = saveDevice(device); | |||
| return result; | |||
| @@ -155,6 +185,9 @@ | |||
| params.setMac(device.getMac()); | |||
| Device deviceResult = sysDeviceInfoDao.getLastObjByAttribute(params); | |||
| if(deviceResult != null){ | |||
| //更新设备 | |||
| device.setDeviceId(deviceResult.getDeviceId()); | |||
| sysDeviceInfoDao.update(device); | |||
| result.setStatus(StatusCode.SUCCESS.getCode()); | |||
| result.setData(deviceResult.getDeviceId()); | |||
| return result; | |||
| @@ -0,0 +1,337 @@ | |||
| /** | |||
| * Copyright (c) 2020-2020 yann | |||
| * Licensed under the Apache License, Version 1.0 (the "License"); | |||
| */ | |||
| package com.inet.ailink.receiver.service.impl; | |||
| import com.inet.ailink.receiver.common.enums.StatusCode; | |||
| import com.inet.ailink.receiver.common.utils.*; | |||
| import com.inet.ailink.receiver.common.vo.Response; | |||
| import com.inet.ailink.receiver.entity.Device; | |||
| import com.inet.ailink.receiver.entity.Tlv; | |||
| import com.inet.ailink.receiver.entity.TrackPositionerLogs; | |||
| import com.inet.ailink.receiver.mapper.ISysDeviceInfoDao; | |||
| import com.inet.ailink.receiver.mapper.ITrackPositionerLogsDao; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.scheduling.annotation.Async; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import java.util.*; | |||
| @Service | |||
| @Transactional(rollbackFor=Exception.class) | |||
| public class TrackPositionerLogsServiceImpl extends BaseServiceImpl<ITrackPositionerLogsDao, TrackPositionerLogs> | |||
| { | |||
| @Autowired | |||
| ITrackPositionerLogsDao trackPositionerLogsDao; | |||
| @Autowired | |||
| ISysDeviceInfoDao deviceInfoDao; | |||
| @Override | |||
| protected ITrackPositionerLogsDao getEntityDao() { | |||
| // TODO Auto-generated method stub | |||
| return trackPositionerLogsDao; | |||
| } | |||
| @Async | |||
| public Response<Object> saveTrackPositionerLogsBatch(byte[] paramsByte, HttpServletRequest request) { | |||
| Response<Object> result = new Response<Object>(); | |||
| try { | |||
| //解析数据 | |||
| //设备id | |||
| Integer deviceId = Integer.parseInt(Base64TeaUitls.getLowConactHighEndForLong(0, 3, paramsByte)+""); | |||
| //查询设备 | |||
| Device device = null; | |||
| if (deviceId != null && deviceId != 0) { | |||
| device = deviceInfoDao.getById(Long.valueOf(deviceId)); | |||
| } | |||
| if (device == null) { | |||
| result.setStatus(StatusCode.DEVICE_NOT_EXIT.getCode()); | |||
| return result; | |||
| } | |||
| //根据数据类型,截分TLV数据 | |||
| List<Tlv> tlvs = TlvUtils.builderTlvList(paramsByte, 4); | |||
| if (tlvs == null || tlvs.size() <= 0) { | |||
| result.setStatus(StatusCode.PARAMS_EMPTY.getCode()); | |||
| return result; | |||
| } | |||
| //判断是否多组记录 | |||
| if(tlvs.get(0).getTag() == 0x15){ | |||
| int tlvStartIndex = 0; | |||
| for(int i=1;i<tlvs.size();i++){ | |||
| Tlv tlv = tlvs.get(i); | |||
| if(tlv.getTag() == 0x15 ){ | |||
| //截取tlvs从下标 tlvStartIndex 到 i的元素 | |||
| result = saveTrackPositionerLogs(paramsByte, request, tlvs.subList(tlvStartIndex, i),device,0,1); | |||
| tlvStartIndex = i; | |||
| } | |||
| } | |||
| //全部循环完后,取最后一组数据,从 tlvStartIndex 到 tlvs.size() | |||
| result = saveTrackPositionerLogs(paramsByte, request, tlvs.subList(tlvStartIndex, tlvs.size()),device,1,0); | |||
| }else{ | |||
| result = saveTrackPositionerLogs(paramsByte, request, null,device,1,0); | |||
| } | |||
| //通过设备ID查询APP设置的设备配置信息 | |||
| String deviceConfig = ""; | |||
| if(!StringSelfUtil.isEmpty(deviceConfig)){ | |||
| result.setConfig(deviceConfig); | |||
| } | |||
| }catch (Exception e){ | |||
| e.printStackTrace(); | |||
| } | |||
| return result; | |||
| } | |||
| public Response<Object> saveTrackPositionerLogs(byte[] paramsByte, HttpServletRequest request,List<Tlv> tlvsParams,Device device,int pushAlarmStatus,Integer outLine) { | |||
| Response<Object> result = new Response<Object>(); | |||
| TrackPositionerLogs trackPositioner = new TrackPositionerLogs(); | |||
| trackPositioner.setCreateTime(new Date()); | |||
| trackPositioner.setDeviceId(device.getDeviceId()); | |||
| trackPositioner.setLbsServerRequest(0);//默认不需要请求定位服务 | |||
| trackPositioner.setOutLine(outLine); | |||
| try { | |||
| //根据数据类型,截分数据 | |||
| List<Tlv> tlvs = new ArrayList<>(); | |||
| if(tlvsParams != null){ | |||
| tlvs = tlvsParams; | |||
| }else{ | |||
| tlvs = TlvUtils.builderTlvList(paramsByte, 4); | |||
| } | |||
| if (tlvs == null || tlvs.size() <= 0) { | |||
| result.setStatus(StatusCode.PARAMS_EMPTY.getCode()); | |||
| return result; | |||
| } | |||
| List<String> macList = new ArrayList<>(); | |||
| List<String> btsList = new ArrayList<>(); | |||
| for (Tlv tlv : tlvs) { | |||
| if (tlv.getValue() != null && tlv.getValue().length > 0) { | |||
| try { | |||
| //时间戳: T=0x01 L=4 | |||
| if (tlv.getTag() == 1) { | |||
| //时间戳,为空时,传值为0x00000000,即:0 | |||
| Long timeUnix = BytesUtils.toIntSmall(tlv.getValue()); | |||
| if (timeUnix != null && timeUnix.equals(0L)) { | |||
| timeUnix = trackPositioner.getCreateTime().getTime() / 1000; | |||
| } | |||
| trackPositioner.setUploadTime(timeUnix+""); | |||
| continue; | |||
| } | |||
| //电量: T=0x02 L=1 | |||
| if (tlv.getTag() == 2) { | |||
| //电量 | |||
| Long power = BytesUtils.toIntSmall(tlv.getValue()); | |||
| trackPositioner.setPower(Integer.parseInt(power+"")); | |||
| continue; | |||
| } | |||
| //报警类型: T=0x03 L=1 | |||
| if (tlv.getTag() == 3) { | |||
| Integer warnDetachmentStatus = Base64TeaUitls.getLowConactHighEndForByte(tlv.getValue()[0], 7, 7);//bit0:拆卸报警【0:否;1:是】; | |||
| Integer warnSosStatus = Base64TeaUitls.getLowConactHighEndForByte(tlv.getValue()[0], 6, 6);//bit1:SOS报警【0:否;1:是】; | |||
| Integer warnFallStatus = Base64TeaUitls.getLowConactHighEndForByte(tlv.getValue()[0], 5, 5);//bit2:跌倒报警【0:否;1:是】; | |||
| Integer warnPowerStatus = Base64TeaUitls.getLowConactHighEndForByte(tlv.getValue()[0], 4, 4);//bit3:低电警【0:否;1:是】; | |||
| Integer warnBreakStatus = Base64TeaUitls.getLowConactHighEndForByte(tlv.getValue()[0], 3, 3);//bit4:拆箱报警【0:否;1:是】; | |||
| trackPositioner.setWarnDetachmentStatus(warnDetachmentStatus); | |||
| trackPositioner.setWarnSosStatus(warnSosStatus); | |||
| trackPositioner.setWarnFallStatus(warnFallStatus); | |||
| trackPositioner.setWarnPowerStatus(warnPowerStatus); | |||
| trackPositioner.setWarnBreakStatus(warnBreakStatus); | |||
| continue; | |||
| } | |||
| //定位方式: T=0x04 L=1 | |||
| if (tlv.getTag() == 4) { | |||
| Integer locateModeOfLatLon = Base64TeaUitls.getLowConactHighEndForByte(tlv.getValue()[0], 7, 7);//bit0:经纬度【经纬度(T=0x03、T=0x04)不允许为空】 | |||
| Integer locateModeOfLbs = Base64TeaUitls.getLowConactHighEndForByte(tlv.getValue()[0], 6, 6);//bit1:LBS定位(基站、WIFI)【0:否;1:是(0x07至0x0F必传)】; | |||
| trackPositioner.setLocateMode(locateModeOfLatLon+","+locateModeOfLbs); | |||
| trackPositioner.setLbsServerRequest(locateModeOfLbs); | |||
| continue; | |||
| } | |||
| //经度: T=0x05 L=6; | |||
| if (tlv.getTag() == 5) { | |||
| Integer lonSign = Base64TeaUitls.getLowConactHighEndForByte(tlv.getValue()[0], 7, 7);//byte0-bit0:正负号【0:正;1:负】; | |||
| Integer lonPoint = Base64TeaUitls.getLowConactHighEndForByte(tlv.getValue()[0], 4, 6);//byte0-bit1-3:小数位个数 | |||
| Long lon=BytesUtils.toIntSmall(new byte[]{tlv.getValue()[5], tlv.getValue()[4],tlv.getValue()[3],tlv.getValue()[2],tlv.getValue()[1]}); | |||
| trackPositioner.setLon((lonSign==0?"":"-")+convertPoint(lon+"", lonPoint)); | |||
| continue; | |||
| } | |||
| //纬度: T=0x06 L=6; | |||
| if (tlv.getTag() == 6) { | |||
| Integer latSign = Base64TeaUitls.getLowConactHighEndForByte(tlv.getValue()[0], 7, 7);//byte0-bit0:正负号【0:正;1:负】; | |||
| Integer latPoint = Base64TeaUitls.getLowConactHighEndForByte(tlv.getValue()[0], 4, 6);//byte0-bit1-3:小数位个数 | |||
| Long lat=BytesUtils.toIntSmall(new byte[]{tlv.getValue()[5], tlv.getValue()[4],tlv.getValue()[3],tlv.getValue()[2],tlv.getValue()[1]}); | |||
| trackPositioner.setLat((latSign==0?"":"-")+convertPoint(lat+"", latPoint)); | |||
| continue; | |||
| } | |||
| //基础网络信息: T=0x07 L=3; | |||
| if (tlv.getTag() == 7) { | |||
| Long accesstype = Base64TeaUitls.getLowConactHighEndForLong(0,0,tlv.getValue());//移动端接入网络方式accesstype,移动接入网络:0 ;wifi 接入网络:1 | |||
| Long cdma = Base64TeaUitls.getLowConactHighEndForLong(1,1,tlv.getValue());//是否为 cdma,非 cdma:0 ;是 cdma:1 | |||
| Long networkType = Base64TeaUitls.getLowConactHighEndForLong(2,2,tlv.getValue());//无线网络类型:0:GSM;1:GPRS;2:EDGE;3:HSUPA;4:HSDPA;5:WCDMA | |||
| trackPositioner.setAccesstype(Integer.parseInt(accesstype+"")); | |||
| trackPositioner.setCdma(Integer.parseInt(cdma+"")); | |||
| trackPositioner.setNetwork(Integer.parseInt(networkType+"")); | |||
| continue; | |||
| } | |||
| //IMEI的ASCII对应的HEX值 : T=0x08 L=value的长度; | |||
| if (tlv.getTag() == 8) { | |||
| String IMEI = Base64TeaUitls.getStartToEndForASIII(0,tlv.getLength()-1,tlv.getValue()); | |||
| trackPositioner.setImei(IMEI.replaceAll(":","")); | |||
| continue; | |||
| } | |||
| //移动用户识别码IMSI的ASCII对应的HEX值 : T=0x09 L=value的长度; | |||
| if (tlv.getTag() == 9) { | |||
| String IMSI = Base64TeaUitls.getStartToEndForASIII(0,tlv.getLength()-1,tlv.getValue()); | |||
| trackPositioner.setImsi(IMSI.replaceAll(":","")); | |||
| continue; | |||
| } | |||
| //手机号的ASCII对应的HEX值: T=0x0A L=value的长度; | |||
| if (tlv.getTag() == 10) { | |||
| String tel = Base64TeaUitls.getStartToEndForASIII(0,tlv.getLength()-1,tlv.getValue()); | |||
| trackPositioner.setTel(tel.replaceAll(":","")); | |||
| continue; | |||
| } | |||
| //设备接入基站时对应的网关IP的ASCII对应的HEX值: T=0x0B L=value的长度; | |||
| if (tlv.getTag() == 11) { | |||
| String stationIp = Base64TeaUitls.getStartToEndForASIII(0,tlv.getLength()-1,tlv.getValue()); | |||
| trackPositioner.setStationIp(stationIp.replaceAll(":","")); | |||
| continue; | |||
| } | |||
| //T=0x0C L=value的长度; | |||
| //接入的基站信息的ASCII对应的HEX值,接入基站信息,详见:“接入基站信息表”说明; | |||
| //非 CDMA 格式为:mcc,mnc,lac,cellid,signal ; | |||
| //CDMA 格式为:sid,nid,bid,lon,lat,signal,其中 lon,lat 可为空,格式为:sid,nid,bid,,,signal: T=0x0B L=value的长度; | |||
| if (tlv.getTag() == 12) { | |||
| String bts = Base64TeaUitls.getStartToEndForASIII(0,tlv.getLength()-1,tlv.getValue()); | |||
| trackPositioner.setBts(bts.replaceAll(":","")); | |||
| continue; | |||
| } | |||
| //T=0x0D L=value的长度; | |||
| //周边搜索到的基站信息【不含接入的基站信息】的ASCII对应的HEX值,单基站信息如接入的基站信息,多个基站信息之间使用竖划线 分隔 | |||
| if (tlv.getTag() == 13) { | |||
| String bts = Base64TeaUitls.getStartToEndForASIII(0,tlv.getLength()-1,tlv.getValue()); | |||
| btsList.add(bts.replaceAll(":","")); | |||
| continue; | |||
| } | |||
| //T=0x0E L=value的长度; | |||
| //连接的WIFI信息的ASCII对应的HEX值,mac,signal,ssid | |||
| //如:f0:7d:68:9e:7d:18,-41,TPLink | |||
| if (tlv.getTag() == 14) { | |||
| String mmac = Base64TeaUitls.getStartToEndForASIII(0,tlv.getLength()-1,tlv.getValue()); | |||
| trackPositioner.setMmac(mmac.replaceAll(":","")); | |||
| continue; | |||
| } | |||
| //T=0x0F L=value的长度; | |||
| //搜索到的WIFI信息的ASCII对应的HEX值,单WIFI信息同“连接的WIFI信息”,WIFI信息之间使用竖划线分隔。必须填写 2 个及 2 个以上,30 个以内的方可正常定位。请不要包含移动 wifi 信息 | |||
| if (tlv.getTag() == 15) { | |||
| String mac = Base64TeaUitls.getStartToEndForASIII(0,tlv.getLength()-1,tlv.getValue()); | |||
| macList.add(mac.replaceAll(":","")); | |||
| continue; | |||
| } | |||
| //T=0x10 L=value的长度; | |||
| //当前速度ASCII对应的HEX值,单位:km/h | |||
| if (tlv.getTag() == 16) { | |||
| String speed = Base64TeaUitls.getStartToEndForASIII(0,tlv.getLength()-1,tlv.getValue()); | |||
| trackPositioner.setSpeed(speed.replace(":","")); | |||
| continue; | |||
| } | |||
| //T=0x11 L=value的长度; | |||
| //当前温度ASCII对应的HEX值,单位:℃ | |||
| if (tlv.getTag() == 17) { | |||
| String temp = Base64TeaUitls.getStartToEndForASIII(0,tlv.getLength()-1,tlv.getValue()); | |||
| trackPositioner.setTemperature(temp.replace(":","")); | |||
| continue; | |||
| } | |||
| //T=0x12 L=value的长度; | |||
| //当前湿度ASCII对应的HEX值,单位:百分比 | |||
| if (tlv.getTag() == 18) { | |||
| String humidity = Base64TeaUitls.getStartToEndForASIII(0,tlv.getLength()-1,tlv.getValue()); | |||
| trackPositioner.setHumidity(humidity.replace(":","")); | |||
| continue; | |||
| } | |||
| //T=0x13 L=value的长度; | |||
| //当前气压ASCII对应的HEX值,单位:pa | |||
| if (tlv.getTag() == 19) { | |||
| String pa = Base64TeaUitls.getStartToEndForASIII(0,tlv.getLength()-1,tlv.getValue()); | |||
| trackPositioner.setPa( pa.replace(":","")); | |||
| continue; | |||
| } | |||
| //T=0x14 L=value的长度; | |||
| //当前海拔ASCII对应的HEX值,单位:米 | |||
| if (tlv.getTag() == 20) { | |||
| String altitude = Base64TeaUitls.getStartToEndForASIII(0,tlv.getLength()-1,tlv.getValue()); | |||
| trackPositioner.setAltitude( altitude.replace(":","")); | |||
| continue; | |||
| } | |||
| //T=0x16 L=value的长度; | |||
| //当前光感值的ASCII对应的HEX值,整数,单位:无 | |||
| if (tlv.getTag() == 22) { | |||
| String light = Base64TeaUitls.getStartToEndForASIII(0,tlv.getLength()-1,tlv.getValue()); | |||
| trackPositioner.setLight(light.replace(":","")); | |||
| continue; | |||
| } | |||
| } catch (Exception e) { | |||
| trackPositioner.setRemark("设备上传数据错误"); | |||
| continue; | |||
| } | |||
| } | |||
| } | |||
| if(macList!=null && macList.size()>0){ | |||
| String macs = ""; | |||
| for(String mac:macList){ | |||
| macs+=mac+"|"; | |||
| } | |||
| trackPositioner.setMacs(macs.substring(0, macs.length()-1)); | |||
| } | |||
| if(btsList!=null && btsList.size()>0){ | |||
| String nearbts = ""; | |||
| for(String bts:btsList){ | |||
| nearbts+=bts+"|"; | |||
| } | |||
| trackPositioner.setNearbts(nearbts.substring(0, nearbts.length()-1)); | |||
| } | |||
| //通过基站/WIFI信息,请求地图服务商提供的位置服务,补充经纬度 | |||
| if(trackPositioner.getLbsServerRequest()==1 && (!StringSelfUtil.isEmpty(trackPositioner.getBts()) || !StringSelfUtil.isEmpty(trackPositioner.getMmac()))){ | |||
| Map postionResultMap = new HashMap<String, String>(); | |||
| if(postionResultMap!=null && postionResultMap.size()>0){ | |||
| trackPositioner.setLon((String)postionResultMap.get("lon")); | |||
| trackPositioner.setLat((String)postionResultMap.get("lat")); | |||
| trackPositioner.setAddressAll((String)postionResultMap.get("address")); | |||
| }else{ | |||
| trackPositioner.setRemark("LBS定位失败"); | |||
| } | |||
| } | |||
| //已有经纬度信息,直接赋值给定位后的经纬度 | |||
| trackPositioner.setPositionLon(trackPositioner.getLon()); | |||
| trackPositioner.setPositionLat(trackPositioner.getLat()); | |||
| trackPositioner.setAppUserId(device.getAppUserId() == null ? 0 : device.getAppUserId()); | |||
| //如果经纬度不为空,则获取地理位置 | |||
| if(trackPositioner.getPositionLat()!=null && trackPositioner.getPositionLon()!=null && StringSelfUtil.isEmpty(trackPositioner.getAddressAll())){ | |||
| trackPositioner.setAddressAll(""); | |||
| } | |||
| if (trackPositionerLogsDao.insert(trackPositioner) > 0) { | |||
| result.setData(trackPositioner.getId()); | |||
| result.setStatus(StatusCode.SUCCESS.getCode()); | |||
| } else { | |||
| result.setStatus(StatusCode.FAIL.getCode()); | |||
| } | |||
| } catch (Exception e) { | |||
| result.setStatus(StatusCode.PARAMS_dECRYPT_ERROR.getCode()); | |||
| } | |||
| return result; | |||
| } | |||
| //插入小数点位 | |||
| public String convertPoint(String value,int position) { | |||
| if(position==0){ | |||
| return value; | |||
| } | |||
| StringBuilder sb = new StringBuilder(value); | |||
| sb.insert(value.length()-position, '.'); | |||
| return sb.toString(); | |||
| } | |||
| } | |||