package com.whyc.service;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageInfo;
|
import com.whyc.dto.Point;
|
import com.whyc.dto.Response;
|
import com.whyc.mapper.BattStationTempAlarmMapper;
|
import com.whyc.pojo.db_alarm.BattStationTempAlarm;
|
import com.whyc.pojo.db_batt.BattMonsLocation;
|
import com.whyc.util.HikTempUtil;
|
import com.whyc.util.PointUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
@Service
|
public class BattStationTempAlarmService {
|
|
@Resource
|
private BattStationTempAlarmMapper mapper;
|
|
@Autowired
|
private BattMonsLocationService battMonsLocationService;
|
|
|
public Response<PageInfo<BattStationTempAlarm>> getPage(int pageNum, int pageSize, Integer level) {
|
PageHelper.startPage(pageNum,pageSize);
|
List<BattStationTempAlarm> list = mapper.getList(level);
|
/*//对这些告警进行计算在磁条哪边,并计算与磁条的垂直线的百分比
|
list.forEach(alarm->{
|
Integer battGroupId = alarm.getBattGroupId();
|
//将maxTempPoint进行解析,得到x,y坐标,并放入Point对象中 TODO 这里暂定最大温度对应的点为1个坐标
|
String maxTempPoint = alarm.getMaxTempPoint();
|
String[] split = maxTempPoint.split("\\*");
|
Point tempPoint = new Point(Integer.valueOf(split[0]),Integer.valueOf(split[1]));
|
//磁条的坐标,格式为 x1*y1,x2*y2
|
String mstPoints = HikTempUtil.cameraInfoList.stream().filter(c -> c.getBattGroupId().equals(battGroupId)).findFirst().get().getMstPoints();
|
String[] mstPointsSplit = mstPoints.split(",");
|
Point mstPointStart = null;
|
Point mstPointEnd = null;
|
for (int i = 0; i < mstPointsSplit.length; i++) {
|
String mstPointsStr = mstPointsSplit[i];
|
if (i == 0) {
|
mstPointStart = new Point(Integer.valueOf(mstPointsStr.split("\\*")[0]),Integer.valueOf(mstPointsStr.split("\\*")[1]));
|
}else{
|
mstPointEnd = new Point(Integer.valueOf(mstPointsStr.split("\\*")[0]),Integer.valueOf(mstPointsStr.split("\\*")[1]));
|
}
|
}
|
//计算tempPoint坐标点在 mstPointStart和mstPointEnd组成的线的哪边
|
String position = PointUtil.determinePosition(mstPointStart.getX(), mstPointEnd.getX(), mstPointStart.getY(), mstPointEnd.getY(), tempPoint.getX(), tempPoint.getY());
|
//计算tempPoint与线的垂足
|
Point footPoint = PointUtil.findIntersection2(mstPointStart, mstPointEnd, tempPoint);
|
//判断垂足footPoint与mstPointStart和mstPointEnd组成的线段,在线上还是在延长线上
|
double pointPercentage = PointUtil.calculateProportion(footPoint.getX(), footPoint.getY(), mstPointStart.getX(), mstPointStart.getY(), mstPointEnd.getX(), mstPointEnd.getY());
|
|
alarm.setPosition(position);
|
alarm.setPointPercentage(pointPercentage);
|
|
});*/
|
/**判断 最高温度点 在 四个点形成的框 内部*/
|
List<BattMonsLocation> batteryLocations = battMonsLocationService.getList();
|
list.forEach(alarm->{
|
String maxTempPointStr = alarm.getMaxTempPoint();
|
if(maxTempPointStr.contains(",")){ // 万一有多个点,取第一个点
|
maxTempPointStr = maxTempPointStr.split(",")[0];
|
}
|
String[] split = maxTempPointStr.split("\\*");
|
Point tempPoint = new Point(Integer.valueOf(split[0]),Integer.valueOf(split[1]));
|
List<BattMonsLocation> battGroupLocations = batteryLocations.stream().filter(location -> location.getBattGroupId().intValue() == alarm.getBattGroupId()).collect(Collectors.toList());
|
for (int i = 0; i < battGroupLocations.size(); i++) {
|
BattMonsLocation battMonsLocation = battGroupLocations.get(i);
|
String battMonsPoints = battMonsLocation.getBattMonsPoints();
|
//battMonsPoints为四边形的四个坐标点,示例: x1*y1,x2*y2,x3*y3,x4*y4
|
|
// 解析四边形的四个顶点坐标
|
String[] points = battMonsPoints.split(",");
|
int[] pointsX = new int[4];
|
int[] pointsY = new int[4];
|
for (int j = 0; j < points.length; j++) {
|
String[] xy = points[j].split("\\*");
|
pointsX[j] = Integer.parseInt(xy[0]);
|
pointsY[j] = Integer.parseInt(xy[1]);
|
}
|
|
// 判断点是否在四边形内
|
boolean isInside = PointUtil.isPointInQuadrilateral(tempPoint.getX(), tempPoint.getY(),pointsX, pointsY);
|
//System.out.println("点是否在四边形内: " + isInside);
|
if(isInside){
|
alarm.setBattMonsLocation(battMonsLocation);
|
break;
|
}
|
}
|
|
});
|
PageInfo<BattStationTempAlarm> pageInfo = new PageInfo<>(list);
|
return new Response<PageInfo<BattStationTempAlarm>>().set(1,pageInfo);
|
}
|
|
public static void main(String[] args) {
|
String battMonsPoints = "105*81,112*24,146*52,138*100";
|
String tempPointStr = "117*47";
|
|
// 解析四边形的四个顶点坐标
|
String[] points = battMonsPoints.split(",");
|
int[] pointsX = new int[4];
|
int[] pointsY = new int[4];
|
for (int i = 0; i < points.length; i++) {
|
String[] xy = points[i].split("\\*");
|
pointsX[i] = Integer.parseInt(xy[0]);
|
pointsY[i] = Integer.parseInt(xy[1]);
|
}
|
|
// 解析待判断的点坐标
|
String[] tempPointArray = tempPointStr.split("\\*");
|
int tx = Integer.parseInt(tempPointArray[0]);
|
int ty = Integer.parseInt(tempPointArray[1]);
|
|
// 判断点是否在四边形内
|
boolean isInside = PointUtil.isPointInQuadrilateral(tx, ty,pointsX, pointsY);
|
System.out.println("点是否在四边形内: " + isInside);
|
}
|
|
public Response<PageInfo<BattStationTempAlarm>> getHisPage(int pageNum, int pageSize, Integer level) {
|
PageHelper.startPage(pageNum,pageSize);
|
List<BattStationTempAlarm> list = mapper.getHisList(level);
|
PageInfo<BattStationTempAlarm> pageInfo = new PageInfo<>(list);
|
return new Response<PageInfo<BattStationTempAlarm>>().set(1,pageInfo);
|
}
|
|
public BattStationTempAlarm getByBattGroupId(int battGroupId) {
|
QueryWrapper<BattStationTempAlarm> query = Wrappers.query();
|
query.eq("batt_group_id",battGroupId);
|
query.isNull("end_time");
|
return mapper.selectOne(query);
|
}
|
|
public void updateById(BattStationTempAlarm alarm) {
|
mapper.updateById(alarm);
|
}
|
|
public void add(BattStationTempAlarm alarm) {
|
mapper.insert(alarm);
|
}
|
}
|