whycxzp
2025-04-02 af63b02bfaca4d55065d423f52a9a667f1c188c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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.util.HikTempUtil;
import com.whyc.util.PointUtil;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.List;
 
@Service
public class BattStationTempAlarmService {
 
    @Resource
    private BattStationTempAlarmMapper mapper;
 
    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);
    }
 
    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);
    }
}