Merge branch 'xxy' into dev

dev
Aaaaaaaa 2024-10-10 22:14:37 +08:00
commit ea7bbfd906
6 changed files with 202 additions and 1 deletions

View File

@ -97,5 +97,11 @@
<groupId>com.muyu</groupId> <groupId>com.muyu</groupId>
<artifactId>cloud-common-rabbit</artifactId> <artifactId>cloud-common-rabbit</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-modules-enterprise-common</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -0,0 +1,47 @@
package com.muyu.carData.listener;
import com.alibaba.fastjson.JSONObject;
import com.muyu.carData.event.EsSaveEvent;
import com.muyu.carData.event.EventListener;
import com.muyu.carData.util.CacheUtil;
import com.muyu.domain.WarnRule;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.HashMap;
/**
*
*/
@Component
@Log4j2
public class FaultWarningListener implements EventListener {
@Autowired
private CacheUtil cacheUtil;
@Override
public void onEvent(EsSaveEvent event) {
try {
log.info("事件开始");
JSONObject data = event.getData();
String vin = (String) data.get("VIN");
HashMap<String, Object> map = (HashMap<String, Object>) cacheUtil.get(vin);
if (map != null) {
WarnRule warnRule = (WarnRule) map.get("warnRule");
Long maxValue = warnRule.getMaxValue();
Long minValue = warnRule.getMinValue();
}
} catch (Exception e) {
log.error("事件发送错误",e);
throw new RuntimeException(e);
}
}
@Override
public void onApplicationEvent(EsSaveEvent event) {
onEvent(event);
}
}

View File

@ -0,0 +1,76 @@
package com.muyu.carData.listener;
import com.alibaba.fastjson.JSONObject;
import com.muyu.carData.event.EsSaveEvent;
import com.muyu.carData.event.EventListener;
import com.muyu.carData.util.CacheUtil;
import com.muyu.carData.util.FenceGroup;
import com.muyu.domain.req.FenceGroupReq;
import io.swagger.v3.oas.models.security.SecurityScheme;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.muyu.domain.resp.CarFenceGroupsResp;
import java.util.List;
import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
/**
*
*/
@Log4j2
@Component
public class FenceListener implements EventListener {
@Autowired
private CacheUtil cacheUtil;
/**
*
* @param event
*/
@Override
public void onEvent(EsSaveEvent event) {
try {
log.info("开始事件运行监听");
JSONObject data = event.getData();
String vin = (String) data.get("VIN");
Integer longitude = (Integer) data.get("longitude");
Integer latitude = (Integer) data.get("latitude");
HashMap<String, Object> map = (HashMap<String, Object>) cacheUtil.get(vin);
if (map != null) {
CarFenceGroupsResp fence = (CarFenceGroupsResp) map.get("fence");
String status = fence.getStatus(); //启动状态(1.驶入 2.驶出)
String fenceText = fence.getFenceText();
String[] split = fenceText.split(";");
ArrayList<Point> points = new ArrayList<>();
for (int i = 0; i < split.length; i++) {
String[] latitudeAndLongitude = split[i].split(",");
Integer longi = Integer.valueOf(latitudeAndLongitude[0]);
Integer lati = Integer.valueOf(latitudeAndLongitude[1]);
Point point = new Point(longi, lati);
points.add(point);
}
List<List<Point>> fences = List.of(
points
);
FenceGroup fenceGroup = new FenceGroup(fences);
Point testPoint = new Point(longitude, latitude); // 应该在第一个围栏内
System.out.println(fenceGroup.isPointInFenceGroup(testPoint)); // 应该输出true
}
}catch(NumberFormatException e){
log.error("数据格式异常,数据发送错误",e);
throw new RuntimeException(e);
}
}
@Override
public void onApplicationEvent(EsSaveEvent event) {
onEvent(event);
}
}

View File

@ -0,0 +1,59 @@
package com.muyu.carData.util;
import java.awt.*;
import java.util.List;
public class FenceGroup {
private List<List<Point>> fences;
public FenceGroup(List<List<Point>> fences){
this.fences = fences;
}
/**
*
* @param point
* @return truefalse
*/
public boolean isPointInFenceGroup(Point point) {
for (List<Point> fence : fences) {
if (isPointInsidePolygon(point, fence)) {
return true;
}
}
return false;
}
/**
*
* @param point
* @param polygon
* @return truefalse
*/
private boolean isPointInsidePolygon(Point point, List<Point> polygon) {
int n = polygon.size();
boolean inside = false;
Point p1 = polygon.get(0);
for (int i = 1; i <= n; i++) {
Point p2 = polygon.get(i % n);
if (point.getY() > Math.min(p1.getY(), p2.getY())) {
if (point.getY() <= Math.max(p1.getY(), p2.getY())) {
if (point.getX() <= Math.max(p1.getX(), p2.getX())) {
if (p1.getY() != p2.getY()) {
double xinters = (point.getY() - p1.getY()) * (p2.getX() - p1.getX()) / (p2.getY() - p1.getY()) + p1.getX();
if (p1.getX() == p2.getX() || point.getX() <= xinters) {
inside = !inside;
}
}
}
}
}
p1 = p2;
}
return inside;
}
}

View File

@ -31,7 +31,7 @@ public class CarFenceGroupsResp {
*/ */
private Integer priority; private Integer priority;
/** /**
* * (1. 2.)
*/ */
private String status; private String status;
/** /**

View File

@ -53,4 +53,17 @@ public interface CarMessageService extends IService<CarMessage> {
* *
*/ */
JSONObject inciseCarMessage(String testString); JSONObject inciseCarMessage(String testString);
} }