|
|
|
@ -16,6 +16,8 @@ import org.springframework.util.StringUtils;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
|
import java.net.URLDecoder;
|
|
|
|
|
import java.time.Instant;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.time.ZoneOffset;
|
|
|
|
@ -169,6 +171,185 @@ public class wifiExcelBluetoothServiceImpl implements wifiExcelBluetoothService
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String jsonParsingApmac(String json,String gwid) {
|
|
|
|
|
|
|
|
|
|
String timestamp="null";
|
|
|
|
|
String hourMinuteSecond="null";
|
|
|
|
|
//wifi总输出对象
|
|
|
|
|
StringBuilder results = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
//解析json
|
|
|
|
|
JSONArray jsonObject = new JSONArray(json);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < jsonObject.length(); i++) {
|
|
|
|
|
StringBuilder result = new StringBuilder();
|
|
|
|
|
JSONObject dataObject = jsonObject.getJSONObject(i);
|
|
|
|
|
System.out.println("id = " + gwid);
|
|
|
|
|
//采集地点
|
|
|
|
|
String place = ExcelReader.getmap("place", gwid);
|
|
|
|
|
result.append(place).append(",");
|
|
|
|
|
System.out.println("采集地点 = " + place);
|
|
|
|
|
|
|
|
|
|
//设备id号替换为国标编码
|
|
|
|
|
String nationalStandard = ExcelReader.getmap("nationalStandard", gwid);
|
|
|
|
|
result.append(nationalStandard).append(",");
|
|
|
|
|
//采集时间
|
|
|
|
|
|
|
|
|
|
LocalDateTime dateTime = LocalDateTime.now();
|
|
|
|
|
Instant instant = dateTime.toInstant(ZoneOffset.ofHours(8));
|
|
|
|
|
long epochSeconds =instant.toEpochMilli();
|
|
|
|
|
System.out.println("dateTime ="+dateTime);
|
|
|
|
|
int hours = dateTime.getHour();
|
|
|
|
|
int minutes = dateTime.getMinute();
|
|
|
|
|
int seconds = dateTime.getSecond();
|
|
|
|
|
timestamp =epochSeconds+"";
|
|
|
|
|
hourMinuteSecond=hours+""+minutes+""+seconds+"";
|
|
|
|
|
// 打印结果
|
|
|
|
|
System.out.println("时间戳:"+timestamp +"时分秒:"+hourMinuteSecond);
|
|
|
|
|
result.append(timestamp).append(",");
|
|
|
|
|
|
|
|
|
|
//手机MAC
|
|
|
|
|
|
|
|
|
|
result.append("null").append(",");
|
|
|
|
|
//信号强度
|
|
|
|
|
result.append(getSafeString(dataObject, "power")).append(",");
|
|
|
|
|
//手机与采集设备之间的预估距离
|
|
|
|
|
result.append("null").append(",");
|
|
|
|
|
//手机连的热点名称
|
|
|
|
|
String essid = getSafeString(dataObject, "essid");
|
|
|
|
|
String s = decodeUrl(essid);
|
|
|
|
|
result.append(s).append(",");
|
|
|
|
|
|
|
|
|
|
//经纬度
|
|
|
|
|
String lat1 = ExcelReader.getmap("lat", gwid);
|
|
|
|
|
result.append(lat1).append(",");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String lon1 = ExcelReader.getmap("lon", gwid);
|
|
|
|
|
result.append(lon1).append(",");
|
|
|
|
|
//采集设备ip
|
|
|
|
|
String collectDeviceIp = ExcelReader.getmap("collectDeviceIp", gwid);
|
|
|
|
|
result.append(collectDeviceIp).append(",");
|
|
|
|
|
//路由器mac
|
|
|
|
|
result.append(getSafeString(dataObject, "apmac")).append("\n");
|
|
|
|
|
|
|
|
|
|
results.append(result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String path = databaseConfig.getPath();
|
|
|
|
|
String manufacturers = databaseConfig.getManufacturers();
|
|
|
|
|
String wifi = writeToBCPFile2(results.toString(), getFileName(timestamp, hourMinuteSecond, manufacturers), path);
|
|
|
|
|
return "Wifi: "+wifi;
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
System.out.println("捕获异常= "+e+"json:"+json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public String jsonParsingMac(String json,String gwid) {
|
|
|
|
|
|
|
|
|
|
String timestamp="null";
|
|
|
|
|
String hourMinuteSecond="null";
|
|
|
|
|
//wifi总输出对象
|
|
|
|
|
StringBuilder results = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
//解析json
|
|
|
|
|
JSONArray jsonObject = new JSONArray(json);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < jsonObject.length(); i++) {
|
|
|
|
|
StringBuilder result = new StringBuilder();
|
|
|
|
|
JSONObject dataObject = jsonObject.getJSONObject(i);
|
|
|
|
|
System.out.println("id = " + gwid);
|
|
|
|
|
//采集地点
|
|
|
|
|
String place = ExcelReader.getmap("place", gwid);
|
|
|
|
|
result.append(place).append(",");
|
|
|
|
|
System.out.println("采集地点 = " + place);
|
|
|
|
|
|
|
|
|
|
//设备id号替换为国标编码
|
|
|
|
|
String nationalStandard = ExcelReader.getmap("nationalStandard", gwid);
|
|
|
|
|
result.append(nationalStandard).append(",");
|
|
|
|
|
//采集时间
|
|
|
|
|
|
|
|
|
|
LocalDateTime dateTime = LocalDateTime.now();
|
|
|
|
|
Instant instant = dateTime.toInstant(ZoneOffset.ofHours(8));
|
|
|
|
|
long epochSeconds =instant.toEpochMilli();
|
|
|
|
|
System.out.println("dateTime ="+dateTime);
|
|
|
|
|
int hours = dateTime.getHour();
|
|
|
|
|
int minutes = dateTime.getMinute();
|
|
|
|
|
int seconds = dateTime.getSecond();
|
|
|
|
|
timestamp =epochSeconds+"";
|
|
|
|
|
hourMinuteSecond=hours+""+minutes+""+seconds+"";
|
|
|
|
|
// 打印结果
|
|
|
|
|
System.out.println("时间戳:"+timestamp +"时分秒:"+hourMinuteSecond);
|
|
|
|
|
result.append(timestamp).append(",");
|
|
|
|
|
|
|
|
|
|
//手机MAC
|
|
|
|
|
|
|
|
|
|
result.append(getSafeString(dataObject, "s")).append(",");
|
|
|
|
|
//信号强度
|
|
|
|
|
result.append(getSafeString(dataObject, "p")).append(",");
|
|
|
|
|
//手机与采集设备之间的预估距离
|
|
|
|
|
result.append("null").append(",");
|
|
|
|
|
//手机连的热点名称
|
|
|
|
|
String essid = getSafeString(dataObject, "e");
|
|
|
|
|
String s = decodeUrl(essid);
|
|
|
|
|
result.append(s).append(",");
|
|
|
|
|
|
|
|
|
|
//经纬度
|
|
|
|
|
String lat1 = ExcelReader.getmap("lat", gwid);
|
|
|
|
|
result.append(lat1).append(",");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String lon1 = ExcelReader.getmap("lon", gwid);
|
|
|
|
|
result.append(lon1).append(",");
|
|
|
|
|
//采集设备ip
|
|
|
|
|
String collectDeviceIp = ExcelReader.getmap("collectDeviceIp", gwid);
|
|
|
|
|
result.append(collectDeviceIp).append(",");
|
|
|
|
|
//路由器mac
|
|
|
|
|
result.append(getSafeString(dataObject, "a")).append("\n");
|
|
|
|
|
|
|
|
|
|
results.append(result);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String path = databaseConfig.getPath();
|
|
|
|
|
String manufacturers = databaseConfig.getManufacturers();
|
|
|
|
|
String wifi = writeToBCPFile2(results.toString(), getFileName(timestamp, hourMinuteSecond, manufacturers), path);
|
|
|
|
|
return "Wifi: "+wifi;
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
System.out.println("捕获异常= "+e+"json:"+json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String decodeUrl(String encodedString) throws UnsupportedEncodingException {
|
|
|
|
|
if(StringUtils.isEmpty(encodedString)){
|
|
|
|
|
return "null";
|
|
|
|
|
}
|
|
|
|
|
String decoded = encodedString;
|
|
|
|
|
// 循环解码,直到不再有编码字符为止
|
|
|
|
|
while (decoded.contains("%")) {
|
|
|
|
|
decoded = URLDecoder.decode(decoded, "UTF-8");
|
|
|
|
|
}
|
|
|
|
|
return decoded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getFileName(String timestamp,String hourMinuteSecond,String manufacturers){
|
|
|
|
|
|
|
|
|
|
IdGeneratorOptions options = new IdGeneratorOptions((short) 6);
|
|
|
|
|