whycxzp
2025-04-02 506168ae540c5aabb34f97a46a6248cd73b77f8b
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);
    }