新wifi厂家集成

dev
zef 1 month ago
parent d36ddd8ec5
commit d1435c3fa0

@ -2,5 +2,5 @@
wifi.manufacturers=WT
wifi.path=/home/bcp/v4/
wifi.configFilePath1=/home/project/wifi/wifiConfig.xlsx
wifi.configFilePath2=D:\\yunshuhuafei\\project\\WiFI\\config\\wifiConfig.xlsx
wifi.configFilePath2=D:\\yunshuhuafei\\wifi\\config\\wifiConfig.xlsx
# wifi.path=D:\\home\\v4\\

Binary file not shown.

@ -48,5 +48,39 @@ public class WifiController {
return "true";
}
@PostMapping("/Wificd/mac_agent/index/apmac.do")
public ResObject jsonapmac(@RequestParam("apmac") String date,String gwid){
log.info("调用接口入参:"+date);
executor.submit(()->{
wifiExcelBluetoothService.jsonParsingApmac(date,gwid);
});
return new ResObject();
}
@PostMapping("/apmac.do")
public ResObject jsonapmac2(@RequestBody String date,String gwid){
log.info("调用接口入参:"+date +"gwid:"+gwid);
executor.submit(()->{
wifiExcelBluetoothService.jsonParsingApmac(date,gwid);
});
return new ResObject();
}
@PostMapping("/Wificd/mac_agent/index/mac.do")
public ResObject jsonmac(@RequestParam("apmac") String date,String gwid){
log.info("调用接口入参:"+date);
executor.submit(()->{
wifiExcelBluetoothService.jsonParsingMac(date,gwid);
});
return new ResObject();
}
@PostMapping("/mac.do")
public ResObject jsonmac2(@RequestBody String date,String gwid){
log.info("调用接口入参:"+date +"gwid:"+gwid);
executor.submit(()->{
wifiExcelBluetoothService.jsonParsingMac(date,gwid);
});
return new ResObject();
}
}

@ -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);

@ -3,4 +3,6 @@ package com.watu.wifi.service;
public interface wifiExcelBluetoothService {
String jsonParsing(String json);
String jsonParsingApmac(String json,String gwid);
String jsonParsingMac(String json,String gwid);
}

@ -7,7 +7,7 @@ import org.springframework.context.annotation.PropertySource;
@Configuration
@PropertySource(value = {
"file:/home/project/wifi/comparison.setting", // 默认配置文件
"file:D:\\yunshuhuafei\\project\\WiFI\\config\\comparison.setting" // 第二个配置文件
"file:D:\\yunshuhuafei\\wifi\\config\\comparison.setting" // 第二个配置文件
}, encoding = "UTF-8",ignoreResourceNotFound = true)
public class ConstantUtil {

Loading…
Cancel
Save