Browse Source

义乌公路 初始化项目

master-new
PoffyZhang 2 months ago
parent
commit
01292b9146
9 changed files with 251 additions and 81 deletions
  1. +75
    -74
      ningda-yw-api/src/main/java/com/ningdatech/carapi/car/position/manage/PositionMonitorManage.java
  2. +0
    -1
      ningda-yw-api/src/main/java/com/ningdatech/carapi/driver/manage/DriverManageDataViewManage.java
  3. +15
    -0
      ningda-yw-api/src/main/java/com/ningdatech/carapi/user/security/auth/WebSecurityConfig.java
  4. +6
    -6
      ningda-yw-api/src/main/resources/application-prod.yml
  5. +27
    -0
      ningda-yw-api/src/test/java/com/ningdatech/carapi/client/ObjectData.java
  6. +32
    -0
      ningda-yw-api/src/test/java/com/ningdatech/carapi/client/RadarClient.java
  7. +46
    -0
      ningda-yw-api/src/test/java/com/ningdatech/carapi/client/RadarDataProcessor.java
  8. +29
    -0
      ningda-yw-api/src/test/java/com/ningdatech/carapi/client/RadarPacket.java
  9. +21
    -0
      ningda-yw-api/src/test/java/com/ningdatech/carapi/client/TrafficData.java

+ 75
- 74
ningda-yw-api/src/main/java/com/ningdatech/carapi/car/position/manage/PositionMonitorManage.java View File

@@ -310,80 +310,81 @@ public class PositionMonitorManage {
}

public List<ResRealTimeMonitorVehicleGisListVO> realTimeMonitorVehicleGisList(ReqRealTimeMonitorPO po) {
if (CollUtil.isEmpty(po.getCompanyIdList())) {
return Collections.emptyList();
}
// 按照登录用户,如果是运营商账号登录,删选出该运营商关联的车辆信息
UserInfoDetails userDetail = LoginUserUtil.loginUserDetail();
Long roleId = userDetail.getRoleId();
List<VehicleCompanyPO> carPlates = Lists.newArrayList();
// 如果登录用户是运营商,只过滤出运营商下的车辆
if (UserRoleTypeEnum.OPERATOR_ROLE_ID.getId().equals(roleId)) {
carPlates = vehicleBaseInfoService.getCarPlatesByCompanyIds(po.getCompanyIdList());
String companyName = userDetail.getCompanyName();
// 暂时控制运营商名称和运营商所在企业名称相同
OperatorQueryDTO operatorQueryDTO = operatorsCacheHelper.getByName(companyName);
// 获取运营商id
Long operatorId = operatorQueryDTO.getId();
carPlates = carPlates.stream()
.filter(v -> operatorId.equals(v.getOperatorId()))
.collect(Collectors.toList());
}
// 如果登录用户是企业信息员,过滤出使用企业和所属企业为该企业的车辆
else if (UserRoleTypeEnum.COMPANY_INFO_OFFICER_ROLE_ID.getId().equals(roleId)) {
Long companyId = userDetail.getCompanyId();
carPlates = vehicleBaseInfoService.getCarPlatesByUseCompanyId(companyId);
}else{
carPlates = vehicleBaseInfoService.getCarPlatesByCompanyIds(po.getCompanyIdList());
}
log.info("request real carPlates 【{}】:", JSON.toJSONString(carPlates));
if (CollUtil.isEmpty(carPlates)) {
return Collections.emptyList();
}
Map<String, Object> map = Maps.newConcurrentMap();
map.put(PositionContant.FIELD_CAR_PLATE, carPlates.stream().map(VehicleCompanyPO::getCarPlate).collect(Collectors.joining(",")));
map.put(PositionContant.HOST_FEILD, HOST);
JSONObject response = restTemplate.getForObject(PositionContant.REAL_GPS_URL, JSONObject.class, map);
log.info("request real gps 【{}】:", JSON.toJSONString(response));
if (Objects.isNull(response)) {
throw new BizException(ExceptionCode.BAD_REQUEST.getCode(), "实时数据请求失败 网络异常");
}
Integer statusCode = response.getInteger("status_code");
if (0 != statusCode) {
throw new BizException(ExceptionCode.BAD_REQUEST.getCode(), response.getString("message"));
}
JSONArray resultJsonArray = response.getJSONArray("result");
if (Objects.isNull(resultJsonArray) || resultJsonArray.size() == 0) {
return Collections.emptyList();
}

Map<String, VehicleCompanyPO> carMap = carPlates.stream()
.filter(w -> Objects.nonNull(w) && Objects.nonNull(w.getCarPlate()))
.filter(CodeUtil.distinctByKey(VehicleCompanyPO::getCarPlate)).collect(Collectors.toMap(VehicleCompanyPO::getCarPlate, v -> v));
List<ResRealTimeMonitorVehicleGisListVO> res = resultJsonArray.stream().map(o -> {
JSONObject j = JSON.parseObject(JSON.toJSONString(o));
String carPlate = j.getString(PositionContant.FIELD_CAR_PLATE);
VehicleCompanyPO vehicleCompany = carMap.get(carPlate);
ResRealTimeMonitorVehicleGisListVO vo = new ResRealTimeMonitorVehicleGisListVO();
vo.setCarLongitude(new BigDecimal(String.valueOf(j.getOrDefault(PositionContant.LONGITUDE,BigDecimal.valueOf(0L)))));
vo.setCarLatitude(new BigDecimal(String.valueOf(j.getOrDefault(PositionContant.LATITUDE,BigDecimal.valueOf(0L)))));
vo.setCarAltitude(new BigDecimal(String.valueOf(j.getOrDefault(PositionContant.ALTITUDE,BigDecimal.valueOf(0L)))));
vo.setCarDirection(new BigDecimal(String.valueOf(j.getOrDefault(PositionContant.DIRECTION,BigDecimal.valueOf(0L)))));
vo.setCarPlate(carPlate);
vo.setPlateColor(j.getString(PositionContant.PLATE_COLOR));
vo.setCompanyId(vehicleCompany.getCompanyId());
vo.setCompanyName(vehicleCompany.getCompanyName());
vo.setCarVelocity(BigDecimal.valueOf(Double.valueOf(String.valueOf(j.getOrDefault(PositionContant.CAR_VELOCITY,BigDecimal.valueOf(0L))))));
vo.setUpdateTime((j.getString(PositionContant.UPDATE_TIME)));
vo.setSelfNo(vehicleCompany.getSelfNo());
vo.setStatus(j.getInteger(PositionContant.ONLINE_STATUS));
vo.setMoving(vehicleCompany.getMoving());
vo.setVehicleType(vehicleCompany.getVehicleType());
vo.setVehicleTypeName(vehicleCompany.getVechileTypeName());
vo.setLimitSpeed(VehicleLimitSpeedEnum.getLimitSpeedByCode(vehicleCompany.getVehicleType()));
return vo;
}).collect(Collectors.toList());
return res;
return Collections.emptyList();
// if (CollUtil.isEmpty(po.getCompanyIdList())) {
// return Collections.emptyList();
// }
// // 按照登录用户,如果是运营商账号登录,删选出该运营商关联的车辆信息
// UserInfoDetails userDetail = LoginUserUtil.loginUserDetail();
// Long roleId = userDetail.getRoleId();
// List<VehicleCompanyPO> carPlates = Lists.newArrayList();
// // 如果登录用户是运营商,只过滤出运营商下的车辆
// if (UserRoleTypeEnum.OPERATOR_ROLE_ID.getId().equals(roleId)) {
// carPlates = vehicleBaseInfoService.getCarPlatesByCompanyIds(po.getCompanyIdList());
// String companyName = userDetail.getCompanyName();
// // 暂时控制运营商名称和运营商所在企业名称相同
// OperatorQueryDTO operatorQueryDTO = operatorsCacheHelper.getByName(companyName);
// // 获取运营商id
// Long operatorId = operatorQueryDTO.getId();
// carPlates = carPlates.stream()
// .filter(v -> operatorId.equals(v.getOperatorId()))
// .collect(Collectors.toList());
// }
// // 如果登录用户是企业信息员,过滤出使用企业和所属企业为该企业的车辆
// else if (UserRoleTypeEnum.COMPANY_INFO_OFFICER_ROLE_ID.getId().equals(roleId)) {
// Long companyId = userDetail.getCompanyId();
// carPlates = vehicleBaseInfoService.getCarPlatesByUseCompanyId(companyId);
// }else{
// carPlates = vehicleBaseInfoService.getCarPlatesByCompanyIds(po.getCompanyIdList());
// }
// log.info("request real carPlates 【{}】:", JSON.toJSONString(carPlates));
// if (CollUtil.isEmpty(carPlates)) {
// return Collections.emptyList();
// }
// Map<String, Object> map = Maps.newConcurrentMap();
// map.put(PositionContant.FIELD_CAR_PLATE, carPlates.stream().map(VehicleCompanyPO::getCarPlate).collect(Collectors.joining(",")));
// map.put(PositionContant.HOST_FEILD, HOST);
// JSONObject response = restTemplate.getForObject(PositionContant.REAL_GPS_URL, JSONObject.class, map);
// log.info("request real gps 【{}】:", JSON.toJSONString(response));
// if (Objects.isNull(response)) {
// throw new BizException(ExceptionCode.BAD_REQUEST.getCode(), "实时数据请求失败 网络异常");
// }
// Integer statusCode = response.getInteger("status_code");
// if (0 != statusCode) {
// throw new BizException(ExceptionCode.BAD_REQUEST.getCode(), response.getString("message"));
// }
// JSONArray resultJsonArray = response.getJSONArray("result");
// if (Objects.isNull(resultJsonArray) || resultJsonArray.size() == 0) {
// return Collections.emptyList();
// }
//
// Map<String, VehicleCompanyPO> carMap = carPlates.stream()
// .filter(w -> Objects.nonNull(w) && Objects.nonNull(w.getCarPlate()))
// .filter(CodeUtil.distinctByKey(VehicleCompanyPO::getCarPlate)).collect(Collectors.toMap(VehicleCompanyPO::getCarPlate, v -> v));
// List<ResRealTimeMonitorVehicleGisListVO> res = resultJsonArray.stream().map(o -> {
// JSONObject j = JSON.parseObject(JSON.toJSONString(o));
// String carPlate = j.getString(PositionContant.FIELD_CAR_PLATE);
// VehicleCompanyPO vehicleCompany = carMap.get(carPlate);
// ResRealTimeMonitorVehicleGisListVO vo = new ResRealTimeMonitorVehicleGisListVO();
// vo.setCarLongitude(new BigDecimal(String.valueOf(j.getOrDefault(PositionContant.LONGITUDE,BigDecimal.valueOf(0L)))));
// vo.setCarLatitude(new BigDecimal(String.valueOf(j.getOrDefault(PositionContant.LATITUDE,BigDecimal.valueOf(0L)))));
// vo.setCarAltitude(new BigDecimal(String.valueOf(j.getOrDefault(PositionContant.ALTITUDE,BigDecimal.valueOf(0L)))));
// vo.setCarDirection(new BigDecimal(String.valueOf(j.getOrDefault(PositionContant.DIRECTION,BigDecimal.valueOf(0L)))));
// vo.setCarPlate(carPlate);
// vo.setPlateColor(j.getString(PositionContant.PLATE_COLOR));
// vo.setCompanyId(vehicleCompany.getCompanyId());
// vo.setCompanyName(vehicleCompany.getCompanyName());
// vo.setCarVelocity(BigDecimal.valueOf(Double.valueOf(String.valueOf(j.getOrDefault(PositionContant.CAR_VELOCITY,BigDecimal.valueOf(0L))))));
// vo.setUpdateTime((j.getString(PositionContant.UPDATE_TIME)));
// vo.setSelfNo(vehicleCompany.getSelfNo());
// vo.setStatus(j.getInteger(PositionContant.ONLINE_STATUS));
// vo.setMoving(vehicleCompany.getMoving());
// vo.setVehicleType(vehicleCompany.getVehicleType());
// vo.setVehicleTypeName(vehicleCompany.getVechileTypeName());
// vo.setLimitSpeed(VehicleLimitSpeedEnum.getLimitSpeedByCode(vehicleCompany.getVehicleType()));
// return vo;
// }).collect(Collectors.toList());
// return res;
}

public List<ResRealTimeMonitorVehicleGisListVO> realTimeMonitorVehicleGisList(DataScreenParam param) {


+ 0
- 1
ningda-yw-api/src/main/java/com/ningdatech/carapi/driver/manage/DriverManageDataViewManage.java View File

@@ -117,7 +117,6 @@ public class DriverManageDataViewManage {
MapDataVO mapData = MapDataVO.builder()
.regionCode(MapUtil.getStr(v.get(0), "nativePlaceRegionCode"))
.regionName(k)
.value(CollUtils.sum(v, w -> MapUtil.getInt(w, "count")))
.build();
result.add(mapData);
});


+ 15
- 0
ningda-yw-api/src/main/java/com/ningdatech/carapi/user/security/auth/WebSecurityConfig.java View File

@@ -10,6 +10,10 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

import java.util.Collections;

/**
* @Author LiuXinXin
@@ -61,6 +65,17 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.csrf().csrfTokenRepository(new CookieCsrfTokenRepository())
.ignoringAntMatchers(authProperties.getIgnoreCsrfUrlsArray());
// http.anonymous().authenticationFilter(availableUserAuthenticationFilter);

UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setAllowedHeaders(Collections.singletonList("*"));
corsConfiguration.setAllowedMethods(Collections.singletonList("*"));
// corsConfiguration.setAllowedOrigins(Collections.singletonList("*"));
corsConfiguration.setAllowedOriginPatterns(Collections.singletonList("*"));
corsConfiguration.setMaxAge(3600L);
corsConfiguration.setAllowCredentials(true);
source.registerCorsConfiguration("/**", corsConfiguration);
http.cors().configurationSource(source);
}

}

+ 6
- 6
ningda-yw-api/src/main/resources/application-prod.yml View File

@@ -21,10 +21,10 @@ spring:
namespace: "spring:session"
redis:
timeout: 15000
host: r-i5c0beef0e0c5114.redis.rds.internet.cloud-inner.zj.gov.cn
host: localhost
port: 6379
database: 0
password: Sswt_8705
password: Ndkj1234
jedis:
pool:
max-active: 200
@@ -40,9 +40,9 @@ spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://rm-i5c1i506lf32hy1ox.mysql.rds.internet.cloud-inner.zj.gov.cn/szsnc2?serverTimezone=Asia/Shanghai&characterEncoding=utf8&allowPublicKeyRetrieval=true&useSSL=false
username: u_snc2
password: Sswt_8705
url: jdbc:mysql://localhost:3306/nd-yw-road?serverTimezone=Asia/Shanghai&characterEncoding=utf8&allowPublicKeyRetrieval=true&useSSL=false
username: root
password: NingdaKeji123!
hikari:
minimum-idle: 5
maximum-pool-size: 1000
@@ -157,7 +157,7 @@ log:
# url: http://shuiniche.ningdatech.com/cm/open/api/log/backup/download

login:
sms-check: true
sms-check: false
public-key: MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCAPhUV8sdOC5MB0m6qHAIJfI0vhkO+wZpO8srcmiMjbzCoaCSznlxZKLVv8MXMB5fgEHqTlrXThZlmCXHJRdZvIpBLNCYu5dd8T0NlmxuioiOVH3dU7Cd1a78B901oZ0NJ5TdcmtQQQQNIq/eKdeOpb+x9NGCLBy7vaOJtYYPTKQIDAQAB
private-key: MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAIA+FRXyx04LkwHSbqocAgl8jS+GQ77Bmk7yytyaIyNvMKhoJLOeXFkotW/wxcwHl+AQepOWtdOFmWYJcclF1m8ikEs0Ji7l13xPQ2WbG6KiI5Ufd1TsJ3VrvwH3TWhnQ0nlN1ya1BBBA0ir94p146lv7H00YIsHLu9o4m1hg9MpAgMBAAECgYBdgueFNZ62/iGX9oXTbNDfcf7RZKoJcsq+PrRF3+83a2CjrCz2/MaCDPkgQwU4HWFVdS6sZ/z13Dla+hAKn+4X2v2pL3ryrcjlY35yreB6NlCjbsRbEACZEvhaps/taLu4IkZ/CQ6msCz8XHkBOMlWDF36kIxS3BFRmu3mWjHCcQJBAMAfZfKZxWX6lJBWLSy3QhV8jIo9+e+kk4VQRZUXgLJf1IwkxcHMmp4OSgcJp5do1YcoBlPQNdaWta0bt7TQL0cCQQCq4X+jc8Ikn/fxeeIpE75CqveHiF86KU7HKVfpjqiZATIeIbBe8eeC1pXlgX6TmMTWFQSRHWVzmVSwRaRhuYIPAkBd5jquksdu60T3MpdLtpm+5KvP2TCyFq7fRndrwhvtknbQtBxPdw/O1k8KF4bosp1CPKazCh12LxzGabikz+d7AkA0iKbo5UmmYNelEUeKQVuYu17l9/LuuoxRhlBUqVsDzu5NfSXvyobWHopuyGTVk33QIx4ITvVFmLoEhySGNrXZAkBktQR+kMStI0SlcMKYFKmQXu78W97p8soVvhP1AndvPiI9keO3UxO7cUjcPRROmcGUU39yGHYlJvu1Krj6+GI1
qyytz:


+ 27
- 0
ningda-yw-api/src/test/java/com/ningdatech/carapi/client/ObjectData.java View File

@@ -0,0 +1,27 @@
package com.ningdatech.carapi.client;

import lombok.Data;

@Data
public class ObjectData {
private short targetId;
private byte laneNumber;
private byte targetType;
private float length;
private float width;
private float height;
private float yawAngle;
private float xCoordinate;
private float yCoordinate;
private float xVelocity;
private float yVelocity;
private float speed;
private float acceleration;
private float xAcceleration;
private float yAcceleration;
private double longitude;
private double latitude;

// 构造函数、getter和setter方法
// ...
}

+ 32
- 0
ningda-yw-api/src/test/java/com/ningdatech/carapi/client/RadarClient.java View File

@@ -0,0 +1,32 @@
package com.ningdatech.carapi.client;

import java.io.*;
import java.net.*;

public class RadarClient {
private Socket socket;
private DataInputStream input;
private DataOutputStream output;

public RadarClient(String host, int port) throws IOException {
socket = new Socket(host, port);
input = new DataInputStream(new BufferedInputStream(socket.getInputStream()));
output = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
}

public void sendData(byte[] data) throws IOException {
output.write(data);
output.flush();
}

public byte[] receiveData() throws IOException {
// 实现接收数据的逻辑
return null;
}

public void close() throws IOException {
input.close();
output.close();
socket.close();
}
}

+ 46
- 0
ningda-yw-api/src/test/java/com/ningdatech/carapi/client/RadarDataProcessor.java View File

@@ -0,0 +1,46 @@
package com.ningdatech.carapi.client;

import java.io.IOException;

public class RadarDataProcessor {
public static void main(String[] args) {
try {
RadarClient client = new RadarClient("localhost", 8080);

while (true) {
byte[] receivedData = client.receiveData();
RadarPacket packet = RadarPacket.fromByteArray(receivedData);

if (packet.getDataType() == 0x01) {
ObjectData objectData = parseObjectData(packet.getData());
processObjectData(objectData);
} else if (packet.getDataType() == 0x03) {
TrafficData trafficData = parseTrafficData(packet.getData());
processTrafficData(trafficData);
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private static ObjectData parseObjectData(byte[] data) {
// 实现解析目标轨迹数据的逻辑
return new ObjectData();
}

private static TrafficData parseTrafficData(byte[] data) {
// 实现解析交通流量统计数据的逻辑
return new TrafficData();
}

private static void processObjectData(ObjectData data) {
// 处理目标轨迹数据
return;
}

private static void processTrafficData(TrafficData data) {
// 处理交通流量统计数据
return;
}
}

+ 29
- 0
ningda-yw-api/src/test/java/com/ningdatech/carapi/client/RadarPacket.java View File

@@ -0,0 +1,29 @@
package com.ningdatech.carapi.client;

import lombok.Data;

@Data
public class RadarPacket {
private static final byte[] HEADER = {0x55, (byte) 0xAA, 0x55, (byte) 0xBB};
private static final byte[] FOOTER = {0x55, (byte) 0xCC, 0x55, (byte) 0xDD};

private short dataLength;
private byte dataType;
private byte checksum;
private String deviceId;
private long timestamp;
private byte[] data;

// 构造函数、getter和setter方法
// ...

public byte[] toByteArray() {
// 实现将数据包转换为字节数组的逻辑
return new byte[0];
}

public static RadarPacket fromByteArray(byte[] bytes) {
// 实现从字节数组解析数据包的逻辑
return new RadarPacket();
}
}

+ 21
- 0
ningda-yw-api/src/test/java/com/ningdatech/carapi/client/TrafficData.java View File

@@ -0,0 +1,21 @@
package com.ningdatech.carapi.client;

import lombok.Data;

@Data
public class TrafficData {
private short statisticalPeriod;
private short laneNumber;
private float monitoringPosition;
private short smallCarFlow;
private short largeCarFlow;
private short extraLargeCarFlow;
private short totalFlow;
private float averageSpeed;
private float headwayTime;
private float occupancyRate;
private float maxQueueLength;

// 构造函数、getter和setter方法
// ...
}

Loading…
Cancel
Save