whycxzp
2025-06-10 7895624ee546875e48767850e1e190ebca05294e
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
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.whyc.dto.Point;
import com.whyc.dto.Response;
import com.whyc.mapper.BattStationTempMapper;
import com.whyc.pojo.db_power_rt.BattStationTemp;
import com.whyc.util.ActionUtil;
import com.whyc.util.PointUtil;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;
 
@Service
public class BattStationTempService {
 
    @Resource
    private BattStationTempMapper mapper;
 
    public Response<List<BattStationTemp>> getList() {
        QueryWrapper<BattStationTemp> query = Wrappers.query();
        query.orderByAsc("camera_id");
        List<BattStationTemp> list = mapper.selectList(query);
        //对温度坐标进行解析,minTempPoint格式为"1*2,2*3",把里面所有的x*y点 拆解到Point(x,y)列表中
        list.stream().forEach(battStationTemp -> {
            String minTempPointStr = battStationTemp.getMinTempPoint();
 
            List<Point> minTempPointList = battStationTemp.getMinTempPointList();
            minTempPointList = new LinkedList<>();
 
            List<Point> maxTempPointList = battStationTemp.getMaxTempPointList();
            maxTempPointList =new LinkedList<>();
            if(minTempPointStr!=null&&!minTempPointStr.equals("")){
                String[] split = minTempPointStr.split(",");
                for (String s : split) {
                    String[] split1 = s.split("\\*");
                    minTempPointList.add(new Point(Integer.parseInt(split1[0]),Integer.parseInt(split1[1])));
                }
            }
            String maxTempPointStr = battStationTemp.getMaxTempPoint();
            if(maxTempPointStr!=null&&!maxTempPointStr.equals("")){
                String[] split = maxTempPointStr.split(",");
                for (String s : split) {
                    String[] split1 = s.split("\\*");
                    Point p = new Point(Integer.parseInt(split1[0]), Integer.parseInt(split1[1]));
                    //对于最高温度点 p(a,b)
                    //TODO 已知坐标点两点为p1(a1,b1)和p2(a2,b2), 求 maxTempPoint点与p1p2组成的线垂直相交的点p3的坐标计算方式
 
                    maxTempPointList.add(p);
                }
            }
 
        });
        return new Response<List<BattStationTemp>>().set(1,list);
    }
 
    public void addOrUpdate(BattStationTemp battStationTemp) {
        QueryWrapper<BattStationTemp> query = Wrappers.query();
        query.eq("camera_id",battStationTemp.getCameraId());
        BattStationTemp tempInDB = mapper.selectOne(query);
        if (tempInDB ==null) {
            mapper.insert(battStationTemp);
        }else{
            battStationTemp.setId(tempInDB.getId());
            mapper.updateById(battStationTemp);
        }
    }
}