whyclxw
2025-03-29 b2304cfc3342211dfd161de427879fa813a22a44
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Response;
import com.whyc.mapper.*;
import com.whyc.pojo.PowerInf;
import com.whyc.pojo.PwrdevAcdata;
import com.whyc.pojo.PwrdevAcdcdata;
import com.whyc.pojo.PwrdevDcdata;
import com.whyc.util.ActionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Service
public class PwrdevAcdcdataService {
    @Resource
    private PwrdevAcdcdataMapper mapper;
 
    @Resource
    private PwrdevAcdataMapper acdataMapper;
 
    @Resource
    private PwrdevDcdataMapper dcdataMapper;
 
    @Resource
    private PowerInfMapper powerInfMapper;
 
    @Autowired
    private SubTablePageInfoService subService;
 
    //查询电源的ACDC信息
    @Transactional
    public Response getDataByDevId(int powerDeviceId) {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("PowerDeviceId",powerDeviceId);
        List list=mapper.selectList(wrapper);
        PageInfo pageInfo=new PageInfo(list);
        return new Response().setII(1,list.size()>0?true:false,pageInfo,"");
    }
 
    //获取配电柜的实时数据
    @Transactional
    public Response getPowerInfoById(int powerDeviceId) {
        Map<String, Object> resultMap = new HashMap<>();
        PwrdevAcdata ac=acdataMapper.getInfo(powerDeviceId);
        PwrdevDcdata dc=dcdataMapper.getInfo(powerDeviceId);
        PwrdevAcdcdata acdc=mapper.getInfo(powerDeviceId);
        //时间30秒为超时基准
        int timeoutMilliSecond = 30*1000;
        if(ac==null){
            ac = new PwrdevAcdata();
            ac.setCommStatus(0);
        }
        else{
            if(System.currentTimeMillis()-ac.getRecordDatetime().getTime()>timeoutMilliSecond) {
                ac.setCommStatus(0);
            }else{
                ac.setCommStatus(1);
            }
        }
        if(dc==null){
            dc = new PwrdevDcdata();
            dc.setCommStatus(0);
        }else{
            if(System.currentTimeMillis()-dc.getRecordDatetime().getTime()>timeoutMilliSecond){
                dc.setCommStatus(0);
            }else{
                dc.setCommStatus(1);
            }
        }
        if(acdc==null){
            acdc = new PwrdevAcdcdata();
            acdc.setCommStatus(0);
        }else{
            if(System.currentTimeMillis()-acdc.getRecordDatetime().getTime()>timeoutMilliSecond){
                acdc.setCommStatus(0);
            }else{
                acdc.setCommStatus(1);
            }
        }
        int flag=0;
        //有一个模块通讯状态正常,则整体通讯状态为正常
        if(ac.getCommStatus()==0 && dc.getCommStatus()==0 && acdc.getCommStatus()==0){
            flag = 0;
        }else{
            flag = 1;
        }
        resultMap.put("ac", ac);
        resultMap.put("dc", dc);
        resultMap.put("acdc", acdc);
 
        return new Response().setII(1,flag>0?true:false,resultMap,flag>0?"通讯正常":"通讯不正常");
    }
 
    //获取配电柜的实时数据-ws接口专用
    public Response getPowerInfoById2(int powerDeviceId) {
        Map<String, Object> resultMap = new HashMap<>();
        PwrdevAcdata ac=acdataMapper.getInfo(powerDeviceId);
        PwrdevDcdata dc=dcdataMapper.getInfo(powerDeviceId);
        PwrdevAcdcdata acdc=mapper.getInfo(powerDeviceId);
        //时间30秒为超时基准
        int timeoutMilliSecond = 30*1000;
        if(ac==null){
            ac = new PwrdevAcdata();
            ac.setCommStatus(0);
        }
        else{
            if(System.currentTimeMillis()-ac.getRecordDatetime().getTime()>timeoutMilliSecond) {
                ac.setCommStatus(0);
            }else{
                ac.setCommStatus(1);
            }
        }
        if(dc==null){
            dc = new PwrdevDcdata();
            dc.setCommStatus(0);
        }else{
            if(System.currentTimeMillis()-dc.getRecordDatetime().getTime()>timeoutMilliSecond){
                dc.setCommStatus(0);
            }else{
                dc.setCommStatus(1);
            }
        }
        if(acdc==null){
            acdc = new PwrdevAcdcdata();
            acdc.setCommStatus(0);
        }else{
            if(System.currentTimeMillis()-acdc.getRecordDatetime().getTime()>timeoutMilliSecond){
                acdc.setCommStatus(0);
            }else{
                acdc.setCommStatus(1);
            }
        }
        int flag=0;
        //有一个模块通讯状态正常,则整体通讯状态为正常
        if(ac.getCommStatus()==0 && dc.getCommStatus()==0 && acdc.getCommStatus()==0){
            flag = 0;
        }else{
            flag = 1;
        }
        resultMap.put("ac", ac);
        resultMap.put("dc", dc);
        resultMap.put("acdc", acdc);
 
        Response response = new Response();
        response.set(1,flag);
        response.setData2(resultMap);
        return response;
    }
    /*重庆bts4810(61850)
    目前客户的负载电流比较小,充放电参数设置时,小于0.1C10的,电流值要求能自动识别,
    采用一天内电流平均值来放电。负载电流大于0.1C10.用0.1C10放电客户要求自动填充,不要人为的录入.
    (100AH电池 负载电流小于10A 就用负载电流的平均值 大于10A 就用10A)
    */
    public float getBts4810LoadCurr(String stationId,float monCapStd) {
        float loadCurr=0f;
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("stationid",stationId);
        wrapper.last("limit 1");
        PowerInf powerInf=powerInfMapper.selectOne(wrapper);
        if(powerInf!=null){
            int powerId=powerInf.getPowerDeviceId();
            QueryWrapper wrapper1=new QueryWrapper();
            wrapper1.eq("PowerDeviceId",powerId);
            wrapper1.last("limit 1");
            PwrdevAcdcdata acdcdata=mapper.selectOne(wrapper1);
            if(acdcdata!=null){
                loadCurr=acdcdata.getLoaderCurr();
                if (loadCurr<(0.1*monCapStd)) {
                    String tableName="db_pwrdev_data_history_gw"+"."+"tb_pwrdev_historydata_gw_"+powerId;
                    tableName=tableName+"_"+ ActionUtil.sdfwithOutday.format(new Date());
                    Float avgCurr=subService.getAvgLoadCurr(powerId,tableName);
                    loadCurr=avgCurr;
                }else{
                    loadCurr=0.1f*monCapStd;
                }
            }
        }
        return loadCurr;
    }
}