whyclxw
2024-09-21 02056b86fcf3fae5f06c43dde29e489973508e1f
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
package com.whyc.service;
 
import com.whyc.dto.DalmDto;
import com.whyc.mapper.CallBack;
import com.whyc.pojo.db_alarm.DevalarmData;
import com.whyc.pojo.db_alarm.DevalarmDataYear;
import com.whyc.pojo.db_batt_testdata.BatttestdataId;
import com.whyc.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
 
@Service
public class SubTablePageInfoService {
    @Autowired
    private MybatisSqlExecuteService sqlExecuteService;
    //获取设备某次记录详细的单体放电过程
    public List<BatttestdataId> getTdataById(Integer devId, Integer testRecordCount) {
        String sql="select  * from db_batt_testdata.tb_batttestdata_" +devId
                +" where need_test=1 and test_record_count="+testRecordCount+" ";
        sql+="  ORDER BY test_starttime asc ";
        System.out.println(sql);
        List list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
            @Override
            public List getResults(ResultSet rs) throws SQLException {
                List<BatttestdataId> list=new ArrayList<>();
                while (rs.next()){
                    BatttestdataId tdata=new BatttestdataId();
                    tdata.setNum(rs.getInt("num"));
                    tdata.setDevId(rs.getInt("dev_id"));
                    tdata.setBattIdx(rs.getInt("batt_idx"));
                    tdata.setTestRecordCount(rs.getInt("test_record_count"));
                    tdata.setTestType(rs.getInt("test_type"));
                    tdata.setRecordNum(rs.getInt("record_num"));
                    tdata.setTestStarttime(rs.getTimestamp("test_starttime"));
                    tdata.setRecordTime(rs.getTimestamp("record_time"));
                    tdata.setTestTimelong(rs.getInt("test_timelong"));
                    tdata.setGroupVol(rs.getDouble("group_vol"));
                    tdata.setTestCurr(rs.getDouble("test_curr"));
                    tdata.setTestCap(rs.getDouble("test_cap"));
                    tdata.setMonNum(rs.getInt("mon_num"));
                    tdata.setMonVol(rs.getDouble("mon_vol"));
                    tdata.setMonTmp(rs.getDouble("mon_tmp"));
                    tdata.setMonCurr(rs.getDouble("mon_curr"));
                    tdata.setMonCap(rs.getDouble("mon_cap"));
                    tdata.setMonWh(rs.getDouble("mon_wh"));
                    tdata.setMonState(rs.getString("mon_state"));
                    tdata.setMonFault(rs.getString("mon_fault"));
                    tdata.setNeedTest(rs.getInt("need_test"));
                    list.add(tdata);
                }
                return list;
            }
        });
        return list;
    }
 
 
    //查询DevAlm历史告警数量
    public int getCountForDevAlm(DalmDto dto) {
        String sql="select  count(distinct num) as number from db_alarm." +dto.getTableName()
                +" where 1=1 ";
 
        if(dto.getStartTime()!=null){
            sql+=" and alm_starttime  >='"+ ThreadLocalUtil.format(dto.getStartTime(),1)+"' ";
        }
        if(dto.getEndTime()!=null){
            sql+=" and alm_endtime  <='"+ThreadLocalUtil.format(dto.getEndTime(),1)+"' ";
        }
        if(dto.getDevType()!=null){
           sql+=" and  FLOOR(dev_id/100000000)="+dto.getDevType();
        }
        if(dto.getDevId()!=null){
            sql+=" and  dev_id="+dto.getDevId();
        }
        if(dto.getAlmId()!=null){
            sql+=" and alm_id="+dto.getAlmId();
        }
        sql+=" and dev_id in (" +
                "            SELECT distinct dev_id from db_user.tb_battgroup_baojigroup,db_user.tb_battgroup_usr" +
                "            where tb_battgroup_baojigroup.baoji_group_id=tb_battgroup_usr.baoji_group_id" +
                "           and uid="+dto.getUid()+
                ")";
        sql+="  order by alm_starttime desc ";
        List list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
            @Override
            public List getResults(ResultSet rs) throws SQLException {
                LinkedList<Object> temp = new LinkedList<>();
                try {
                    while (rs.next())
                        temp.add(rs.getInt("number"));
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                return temp;
            }
        });
        int num =0;
        if(list!=null){
            num= (int) list.get(0);
        }
        return num;
    }
    //查询devalm历史告警
    public List getListDevAlm(DalmDto dto){
        String sql="select  * from db_alarm." +dto.getTableName()
                +" where 1=1 ";
 
        if(dto.getStartTime()!=null){
            sql+=" and alm_starttime  >='"+ ThreadLocalUtil.format(dto.getStartTime(),1)+"' ";
        }
        if(dto.getEndTime()!=null){
            sql+=" and alm_endtime  <='"+ThreadLocalUtil.format(dto.getEndTime(),1)+"' ";
        }
        if(dto.getDevType()!=null){
            sql+=" and  FLOOR(dev_id/100000000)="+dto.getDevType();
        }
        if(dto.getDevId()!=null){
            sql+=" and  dev_id="+dto.getDevId();
        }
        if(dto.getAlmId()!=null){
            sql+=" and alm_id="+dto.getAlmId();
        }
        sql+=" and dev_id in (" +
                "            SELECT distinct dev_id from db_user.tb_battgroup_baojigroup,db_user.tb_battgroup_usr" +
                "           where tb_battgroup_baojigroup.baoji_group_id=tb_battgroup_usr.baoji_group_id" +
                "           and uid="+dto.getUid()+
                ")";
        sql+="  ORDER BY alm_starttime desc  limit "+dto.getLimitStart()+","+dto.getLimitEnd()+" ";
        List list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
            @Override
            public List getResults(ResultSet rs) throws SQLException {
                List<DevalarmDataYear> list=new ArrayList<>();
                while (rs.next()){
                    DevalarmDataYear dataYear=new DevalarmDataYear();
                    dataYear.setNum(rs.getInt("num"));
                    dataYear.setDevId(rs.getInt("dev_id"));
                    dataYear.setAlmId(rs.getInt("alm_id"));
                    dataYear.setAlmSignalId(rs.getInt("alm_signal_id"));
                    dataYear.setAlmStarttime(rs.getTimestamp("alm_starttime"));
                    dataYear.setAlmValue(rs.getFloat("alm_value"));
                    dataYear.setAlmIsConfirmed(rs.getInt("alm_is_confirmed"));
                    dataYear.setConfirmedUid(rs.getInt("confirmed_uid"));
                    dataYear.setConfirmedTime(rs.getTimestamp("confirmed_time"));
                    dataYear.setAlmEndtime(rs.getTimestamp("alm_endtime"));
                    dataYear.setAlmClearedType(rs.getInt("alm_cleared_type"));
                    list.add(dataYear);
                }
                return list;
            }
        });
        return list;
    }
 
 
}