whycxzp
2025-04-02 506168ae540c5aabb34f97a46a6248cd73b77f8b
更新计算
5个文件已修改
112 ■■■■■ 已修改文件
src/main/java/com/whyc/pojo/db_alarm/BattStationTempAlarm.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/db_batt/BattCamera.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/BattStationTempAlarmService.java 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/BattStationTempHisService.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/util/PointUtil.java 59 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/db_alarm/BattStationTempAlarm.java
@@ -44,6 +44,8 @@
    private Date endTime;
    private String maxTempPoint;
    @TableField(exist = false)
    private String battGroupName;
@@ -53,5 +55,12 @@
    @TableField(exist = false)
    private String powerName;
    @TableField(exist = false)
    @ApiModelProperty("最高温度点在磁条的方位")
    private String position;
    @TableField(exist = false)
    private double pointPercentage;
}
src/main/java/com/whyc/pojo/db_batt/BattCamera.java
@@ -17,5 +17,7 @@
    private String cameraIp;
    private Integer battGroupId;
    private Integer stationId;
    /**磁条起点,终点,格式为x1*y1,x2*y2*/
    private String mstPoints;
}
src/main/java/com/whyc/service/BattStationTempAlarmService.java
@@ -4,9 +4,12 @@
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.util.HikTempUtil;
import com.whyc.util.PointUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -21,6 +24,37 @@
    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);
        });
        PageInfo<BattStationTempAlarm> pageInfo = new PageInfo<>(list);
        return new Response<PageInfo<BattStationTempAlarm>>().set(1,pageInfo);
    }
@@ -35,6 +69,7 @@
    public BattStationTempAlarm getByBattGroupId(int battGroupId) {
        QueryWrapper<BattStationTempAlarm> query = Wrappers.query();
        query.eq("batt_group_id",battGroupId);
        query.isNull("end_time");
        return mapper.selectOne(query);
    }
src/main/java/com/whyc/service/BattStationTempHisService.java
@@ -80,12 +80,13 @@
    }
    public boolean existTempHisTableByMonth(Integer battGroupId, String yearMonth) {
        return commonMapper.existTable("db_power_history","db_batt_station_temp_history_"+battGroupId+"_"+yearMonth);
        return commonMapper.existTable("db_power_history","tb_batt_station_temp_history_"+battGroupId+"_"+yearMonth);
    }
    public void add(Integer battGroupId, String yearMonth, BattStationTempHistory tempHistory) {
        jdbcSqlExecuteService.execute("INSERT INTO `db_power_history`.`db_batt_station_temp_history_"+battGroupId+"_"+yearMonth+"` (`batt_group_id`, `station_id`, `pixel_x`, `pixel_y`, `max_temp`, `min_temp`, `min_temp_point`, `max_temp_point`, `camera_id`, `record_time`)" +
                "\n values("+tempHistory.getBattGroupId()+","+tempHistory.getStationId()+","+tempHistory.getPixelX()+","+tempHistory.getPixelY()+","+tempHistory.getMaxTemp()+","+tempHistory.getMinTemp()+",'"+tempHistory.getMinTempPoint()+"','"+tempHistory.getMaxTempPoint()+"','"+tempHistory.getCameraId()+"','"+tempHistory.getRecordTime());
        String sql = "INSERT INTO `db_power_history`.`tb_batt_station_temp_history_"+battGroupId+"_"+yearMonth+"` (`batt_group_id`, `station_id`, `pixel_x`, `pixel_y`, `max_temp`, `min_temp`, `min_temp_point`, `max_temp_point`, `camera_id`, `record_time`)" +
                "\n values("+tempHistory.getBattGroupId()+","+tempHistory.getStationId()+","+tempHistory.getPixelX()+","+tempHistory.getPixelY()+","+tempHistory.getMaxTemp()+","+tempHistory.getMinTemp()+",'"+tempHistory.getMinTempPoint()+"','"+tempHistory.getMaxTempPoint()+"','"+tempHistory.getCameraId()+"','"+tempHistory.getRecordTime()+"')";
        jdbcSqlExecuteService.execute(sql);
    }
    public Response getPageByCameraId(int pageNum, int pageSize, String cameraId, String startTime, String endTime) throws ParseException, InterruptedException {
src/main/java/com/whyc/util/PointUtil.java
@@ -4,7 +4,7 @@
public class PointUtil {
    public static void main(String[] args) {
        double a1 = 1, b1 = 2;
        /*double a1 = 1, b1 = 2;
        double a2 = 3, b2 = 4;
        double x0 = 9, y0 = 9;
        Point p1 = new Point(1, 2);
@@ -18,7 +18,17 @@
        System.out.println("Intersection Point P3: (" + p3[0] + ", " + p3[1] + ")");
        String position = determinePosition(a1, b1, a2, b2, x0, y0);
        System.out.println("Point P is on the " + position + " of the line P1P2.");
        System.out.println("Point P is on the " + position + " of the line P1P2.");*/
        double x0 = 5, y0 = 5;
        double x1 = 0, y1 = 0;
        double x2 = 2, y2 = 2;
        double proportion = calculateProportion(x0, y0, x1, y1, x2, y2);
        if (proportion >= 0) {
            System.out.println("垂足到mstPointStart的距离占整条线段长度的比例是: " + proportion);
        } else {
            System.out.println("垂足不在线段上");
        }
    }
    public static double[] findIntersection(double a1, double b1, double a2, double b2, double x0, double y0) {
@@ -77,5 +87,50 @@
            return "line";
        }
    }
    /**
     * 计算点到线段的距离占线段长度的比例
     * @param x0 垂足x点
     * @param y0 垂足y点
     * @param x1 起点x点
     * @param y1 起点y点
     * @param x2 终点x点
     * @param y2 终点y点
     * @return
     */
    public static double calculateProportion(double x0, double y0, double x1, double y1, double x2, double y2) {
        // 向量 AB
        double ABx = x2 - x1;
        double ABy = y2 - y1;
        // 向量 AP
        double APx = x0 - x1;
        double APy = y0 - y1;
        // 向量积 AB × AP
        double crossProduct = ABx * APy - APx * ABy;
        if (crossProduct == 0) {
            // 点在直线上,判断是否在线段上
            double dotProduct = APx * ABx + APy * ABy;
            double squaredLengthAB = ABx * ABx + ABy * ABy;
            double t = dotProduct / squaredLengthAB;
            if (t >= 0 && t <= 1) {
                return t; // 垂足到mstPointStart的距离占整条线段长度的比例
            }  else if (t < 0) {
                //点在mstPointStart的延长线上
                return 0;
            } else {
                //点在mstPointEnd的延长线上
                return 1;
            }
        } else {
            return -1; // 点不在直线上
        }
    }
}