81041
2019-11-12 107623064b162aef3e5d1d734d0763d068a7c4f9
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
190
191
192
193
194
195
196
197
198
package com.fgkj.impl;
 
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import com.fgkj.dao.BaseDAO;
import com.fgkj.dao.BattTestData;
import com.fgkj.dto.Batttestdata_inf;
import com.sqlite_DaoHelper.CallBack;
import com.sqlite_DaoHelper.DAOHelper;
import com.sqlite_DaoHelper.DBUtil;
 
 
public class Batttestdata_infDAOImpl implements BaseDAO, CallBack {
    private SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    
    //向batttestdata_inf表中添加数据
    public boolean add(Object obj) {
        Batttestdata_inf b=(Batttestdata_inf)obj;
        String sql="insert into tb_batttestdata_inf(BattGroupId,test_record_count,test_record_count_ex,test_type,record_time_interval,data_new,data_available,record_num,test_starttime,test_starttime_ex,test_starttype,record_time,test_timelong,test_stoptype,group_vol,test_curr,test_cap,max_monnum,max_monvol,min_monnum,min_monvol,mon_num,mon_vol,upload_usr_id) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        return DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{
            b.getBattGroupId(),
            b.getTest_record_count(),
            b.getTest_record_count_ex(),
            b.getTest_type(),
            b.getRecord_time_interval(),
            b.getData_new(),
            b.getData_available(),
            b.getRecord_num(),
            b.getTest_starttime(),
            b.getTest_starttime_ex(),
            b.getTest_starttype(),
            b.getRecord_time(),
            b.getTest_timelong(),
            b.getTest_stoptype(),
            b.getGroup_vol(),
            b.getTest_curr(),
            b.getTest_cap(),
            b.getMax_monnum(),
            b.getMax_monvol(),
            b.getMin_monnum(),
            b.getMin_monvol(),
            b.getMon_num(),
            b.getMon_vol(),
            b.getUpload_usr_id()
        });
        
    }
    
    public boolean update(Object obj) {
        
        return false;
    }
 
    //6.1电池充放电删除操作
    public boolean del(Object obj) {
        Batttestdata_inf tdata=(Batttestdata_inf)obj;
        String sql="delete from tb_batttestdata_inf where num=?";
        return DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{tdata.getNum()});
    }
     //电池充/放电数据管理删除
    public String delPro(Object obj) {
        Batttestdata_inf tdata=(Batttestdata_inf)obj;
        String sql="delete from tb_batttestdata_inf where num="+tdata.getNum();
        return sql;
    }
    //查询所有的充放电信息
    public List searchAll() {
        String sql="select num,BattGroupId,test_record_count,test_record_count_ex,test_type,record_time_interval,data_new,data_available,record_num,test_starttime,test_starttime_ex,test_starttype,record_time,test_timelong,test_stoptype,group_vol,test_curr,test_cap,max_monnum,max_monvol,min_monnum,min_monvol,mon_num,mon_vol,upload_usr_id " +
                " from tb_batttestdata_inf " +
                " where tb_batttestdata_inf.data_available=1 ";
        return DAOHelper.executeQuery(sql, DBUtil.getConn(), null, new CallBack() {
            
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while(rs.next()){
                        Batttestdata_inf b=new Batttestdata_inf();
                        b.setNum(rs.getInt("num"));
                        b.setBattGroupId(rs.getInt("BattGroupId"));
                        b.setTest_record_count(rs.getInt("test_record_count"));
                        b.setTest_record_count_ex(rs.getInt("test_record_count_ex"));
                        b.setTest_type(rs.getInt("test_type"));
                        b.setRecord_time_interval(rs.getInt("record_time_interval"));
                        b.setData_new(rs.getInt("data_new"));
                        b.setData_available(rs.getInt("data_available"));                        
                        b.setRecord_num(rs.getInt("record_num"));
                        b.setTest_starttime(rs.getTimestamp("test_starttime"));
                        b.setTest_starttime_ex(rs.getTimestamp("test_starttime_ex"));
                        b.setTest_starttype(rs.getInt("test_starttype"));
                        b.setRecord_time(rs.getTimestamp("record_time"));
                        b.setTest_timelong(rs.getInt("test_timelong"));
                        b.setTest_stoptype(rs.getInt("test_stoptype"));
                        b.setGroup_vol(rs.getFloat("group_vol"));
                        b.setTest_curr(rs.getFloat("test_curr"));
                        b.setTest_cap(rs.getFloat("test_cap"));
                        b.setMax_monnum(rs.getInt("max_monnum"));
                        b.setMax_monvol(rs.getFloat("max_monvol"));
                        b.setMin_monnum(rs.getInt("min_monnum"));
                        b.setMin_monvol(rs.getFloat("min_monvol"));
                        b.setMon_num(rs.getInt("mon_num"));
                        b.setMon_vol(rs.getFloat("mon_vol"));
                        b.setUpload_usr_id(rs.getInt("upload_usr_id"));
                        list.add(b);
                        //System.out.println(b);
                    }
                } catch (SQLException e) {
                    e.printStackTrace();
                } 
                return list;
            }
        });
    }
 
    //历史数据查询
    public List serchByCondition(Object obj) {
        final Batttestdata_inf bti=(Batttestdata_inf)obj;
        String sql="select tb_batttestdata_inf.num,tb_batttestdata_inf.BattGroupId,test_record_count,test_record_count_ex,test_type,record_time_interval,data_new,data_available,record_num,test_starttime,test_starttime_ex,test_starttype,record_time,test_timelong,test_stoptype,group_vol,test_curr,test_cap,max_monnum,max_monvol,min_monnum,min_monvol,mon_num,mon_vol,upload_usr_id"
                +" from tb_batttestdata_inf where "
                +" tb_batttestdata_inf.data_available=1 " +
                " order by test_type asc,test_starttime desc ";
        return DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{bti.getBattGroupId()}, new CallBack() {
            
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while(rs.next()){
                        Batttestdata_inf b=new Batttestdata_inf();
                        b.setNum(rs.getInt("num"));
                        b.setBattGroupId(rs.getInt("BattGroupId"));
                        b.setTest_record_count(rs.getInt("test_record_count"));
                        b.setTest_record_count_ex(rs.getInt("test_record_count_ex"));
                        b.setTest_type(rs.getInt("test_type"));
                        b.setRecord_time_interval(rs.getInt("record_time_interval"));
                        b.setData_new(rs.getInt("data_new"));
                        b.setData_available(rs.getInt("data_available"));                        
                        b.setRecord_num(rs.getInt("record_num"));
                        b.setTest_starttime(rs.getTimestamp("test_starttime"));
                        b.setTest_starttime_ex(rs.getTimestamp("test_starttime_ex"));
                        b.setTest_starttype(rs.getInt("test_starttype"));
                        b.setRecord_time(rs.getTimestamp("record_time"));
                        b.setTest_timelong(rs.getInt("test_timelong"));
                        b.setTest_stoptype(rs.getInt("test_stoptype"));
                        //放电终止原因
                        
                        if(bti.getNum()/100000==6185){
                            b.setTest_stoptype_reason(BattTestData.getStopType_6185(b.getTest_stoptype()));
                        }else if(bti.getNum()/100000==4016){
                            b.setTest_stoptype_reason(BattTestData.getStopType_4016(b.getTest_stoptype()));
                        }else{
                            b.setTest_stoptype_reason(BattTestData.getStopType(b.getTest_starttype(), b.getTest_stoptype()));
                        }
                        b.setGroup_vol(rs.getFloat("group_vol"));
                        b.setTest_curr(rs.getFloat("test_curr"));
                        b.setTest_cap(rs.getFloat("test_cap"));
                        b.setMax_monnum(rs.getInt("max_monnum"));
                        b.setMax_monvol(rs.getFloat("max_monvol"));
                        b.setMin_monnum(rs.getInt("min_monnum"));
                        b.setMin_monvol(rs.getFloat("min_monvol"));
                        b.setMon_num(rs.getInt("mon_num"));
                        b.setMon_vol(rs.getFloat("mon_vol"));
                        b.setUpload_usr_id(rs.getInt("upload_usr_id"));
                        b.setMoncapstd(rs.getFloat("MonCapStd"));
                        b.setMonvolstd(rs.getFloat("monvolstd"));
                        list.add(b);
                    }
                } catch (SQLException e) {
                    e.printStackTrace();
                } 
                return list;
            }
        });
    }
    
    public List serchByInfo(Object obj) {
        return null;
    }
 
 
    public List getResults(ResultSet rs) {
        // TODO Auto-generated method stub
        return null;
    }
 
    public static void main(String[] args) {
        Batttestdata_infDAOImpl bimpl=new Batttestdata_infDAOImpl();
        List<Batttestdata_inf> list=bimpl.searchAll();
        for (Batttestdata_inf b:list) {
            System.out.println(b);
        }
    }
}