lxw
2023-03-07 bbf192dc5440606432cf311ac27f92dae3ae2dbe
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package com.whyc.service;
 
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.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Response;
import com.whyc.mapper.*;
import com.whyc.pojo.BattRtdata;
import com.whyc.pojo.StationInf;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Service
public class StationInfService {
    @Autowired(required = false)
    private StationInfMapper mapper;
 
    @Autowired(required = false)
    private BattRtdataMapper rtdataMapper;
 
    @Autowired(required = false)
    private BattalarmDataMapper battAlmMapper;
 
    @Autowired(required = false)
    private DevalarmDataMapper devAlmMapper;
 
    @Autowired(required = false)
    private PwrdevAlarmMapper pwrAlmMapper;
 
    //插入站点
    public Response insertStation(StationInf stationInf) {
        int flag = mapper.insert(stationInf);
        return new Response().set(1, flag > 0, "插入站点");
    }
 
    //查询所有的站点
    public Response searchStationAll(int pageCurr, int pageSize) {
        PageHelper.startPage(pageCurr, pageSize);
        List<StationInf> list = mapper.selectList(null);
        PageInfo pageInfo = new PageInfo(list);
        return new Response().setII(1, list.size() > 0, pageInfo, "查询站点");
    }
 
    //删除总站点
    public Response deleteStation(int num) {
        UpdateWrapper wrapper = new UpdateWrapper();
        wrapper.eq("num", num);
        int flag = mapper.delete(wrapper);
        return new Response().set(1, flag > 0, "插入站点");
    }
 
    //管理员首页:站点实时数据推送
    public Response getSystemAll(int userId) {
        List<StationInf> list = mapper.getSystemAll(userId);
        for (StationInf inf : list) {
            String stationId = inf.getStationId();
            //查询机房下最大的单体电压和单体
            BattRtdata maxData = rtdataMapper.maxData(stationId);
            inf.setMaxVol(maxData.getMonVol());
            inf.setMaxNum(maxData.getMonNum());
            //查询机房下最低的单体电压和单体
            BattRtdata minData = rtdataMapper.minData(stationId);
            inf.setMinVol(maxData.getMonVol());
            inf.setMinNum(maxData.getMonNum());
            //查询实时告警总数
            int battAlm = battAlmMapper.getbattAlm(stationId);
            int devAlm = devAlmMapper.getdevAlm(stationId);
            int pwrAlm = pwrAlmMapper.getpwrAlm(stationId);
            inf.setAlarmNum(battAlm + devAlm + pwrAlm);
        }
        return new Response().setII(1, list.size() > 0, list, "站点实时数据推送");
    }
 
    public String getMaxStationId() {
        QueryWrapper<StationInf> query = Wrappers.query();
        query.select("stationId").orderByDesc("num").last(" limit 1");
        StationInf stationInf = mapper.selectOne(query);
        if (stationInf == null) {
            return "42000000";
        } else {
            return stationInf.getStationId();
        }
    }
 
    public Response getStationStatistic(int userId) {
        return null;
    }
 
    //运维层首页:站点实时数据推送
    public Object getDevOpAll(int userId) {
        Map<String, Object> map = null;
        try {
            map = new HashMap();
 
            List<StationInf> list = mapper.getSystemAll(userId);
            map.put("data", list);
        } catch (Exception e) {
            return new Response().set(1, false, "发生异常:" + e.getCause());
        }
        return new Response().setII(1, true, map, "站点实时数据推送");
    }
 
    //总机房
    public int geStation(int userId) {
        return mapper.geStation(userId);
    }
}