whyclj
2019-10-29 1c0469e45346d464e0c5672ee68f9ecd4fb6be7c
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
package com.fgkj.dao.impl;
 
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.actions.ActionUtil;
import com.fgkj.dao.BaseDAO;
import com.fgkj.dao.CallBack;
import com.fgkj.dao.DAOHelper;
import com.fgkj.db.DBUtil;
import com.fgkj.db.IDatabaseName;
import com.fgkj.dto.BattInf;
import com.fgkj.dto.Batt_User_Permit;
import com.fgkj.dto.Batt_maint_inf;
import com.fgkj.dto.Page;
import com.fgkj.dto.User_inf;
 
public class Batt_maint_infAgainImpl implements BaseDAO, CallBack {
 
    public List getResults(ResultSet rs) {
        return null;
    }
 
    public boolean add(Object obj) {
        return false;
    }
 
    public boolean update(Object obj) {
        return false;
    }
 
    public boolean del(Object obj) {
        return false;
    }
 
    public List searchAll() {
        return null;
    }
 
    //2.2电池故障处理统计查询
        /*
     * 维护区:stationname1
     * 包机人:stationname
     * 电池品牌:battproducer
     * 统计方式:devicename
     * 统计开始时间:battproductdate
     * 统计结束时间:battproductdata1
     * */
    public List serchByCondition(Object obj) {
            final BattInf binf=(BattInf) obj;
            
            // System.out.println(binf);
            String sql = "select distinct(db_battinf.tb_batt_maint_inf.usr_id),fault_time,maint_done_time,maint_time_limit,maint_done "
                    + "from db_battinf.tb_batt_maint_inf,db_battinf.tb_battinf ,db_user.tb_user_inf  "
                    + "where db_battinf.tb_batt_maint_inf.battgroupid=db_battinf.tb_battinf .battgroupid "
                    + "and fault_time>=? and fault_time<=?   "
                    + "and db_battinf.tb_batt_maint_inf.usr_id=db_user.tb_user_inf.uid  ";
            //责任人(包机人)
            String unameSqlF=" and db_user.tb_user_inf.uname!=? ";
            String unameSqlT=" and db_user.tb_user_inf.uname=? "; 
            if(binf.getStationName().equals("")){
                sql+=unameSqlF;
            }else{
                sql+=unameSqlT;
            }
             //用于维护区
            String station1SqlT=" and stationname1!=? ";//全部
            String station1SqlF=" and stationname1=? ";
            if(binf.getStationName1().equals("")){
                sql+=station1SqlT;
            }else{
                sql+=station1SqlF;
            }
            //用于电池类型
            String producerSqlT=" and battproducer!=? ";//全部
            String producerSqlF=" and battproducer=? ";
            if(binf.getBattProducer().equals("")){
                sql+=producerSqlT;
            }else{
                sql+=producerSqlF;
            }
            List list = DAOHelper.executeQuery(
                            sql,
                            DBUtil.getConn(),
                            new Object[] { 
                                    binf.getBattProductDate(),
                                    binf.getBattProductDate1(),
                                    binf.getStationName(),
                                    binf.getStationName1(),
                                    binf.getBattProducer(),}, new CallBack() {
                                public List getResults(ResultSet rs) {
                                    List list = new ArrayList();
                                    try {
                                        // System.out.println(rs.next());
                                        while (rs.next()) {
                                            Batt_maint_inf mainf = new Batt_maint_inf();
                                            mainf.setUsr_id(rs.getInt("usr_id"));
                                            mainf.setFault_time(rs.getTimestamp("fault_time"));
                                            mainf.setMaint_done_time(rs.getTimestamp("maint_done_time"));
                                            mainf.setMaint_time_limit(rs.getTimestamp("maint_time_limit"));
                                            mainf.setMaint_done(rs.getInt("maint_done"));
 
                                            // maint_result存放统计方式
 
                                            mainf.setMaint_result(binf.getDeviceName());
 
                                            // fault_caption存放维护区
                                            if (binf.getStationName1().equals("")) {
                                                mainf.setFault_caption("全部");
                                            } else {
                                                mainf.setFault_caption(binf.getStationName1());
                                            }
                                            // master_check存放包机人
                                            if (binf.getStationName().equals("")) {
                                                mainf.setMaster_check("全部");
                                            } else {
                                                mainf.setMaster_check(binf.getStationName());
                                            }
                                            // remark存放品牌
                                            if (binf.getBattProducer().equals("")) {
                                                mainf.setRemark("全部");
                                            } else {
                                                mainf.setRemark(binf.getBattProducer());
                                            }
                                            //System.out.println(mainf);
                                            list.add(mainf);
                                        }
                                    } catch (SQLException e) {
                                        e.printStackTrace();
                                    }
                                    return list;
                                }
                            });
            
//            List<Batt_maint_inf> listd=new ArrayList();
//            int index=0;
//            for(int i=(bup.getPage().getPageCurr()-1)*bup.getPage().getPageSize();i<bup.getPage().getPageSize()*bup.getPage().getPageCurr()&&i<list.size();i++){
//                ((Batt_maint_inf)list.get(i)).setMaster_id(list.size());
//                listd.add((Batt_maint_inf) list.get(i));
//                //System.out.println(list.get(i));
//            }
            //System.out.println(listd.size());
            return list;
        }
 
    public List serchByInfo(Object obj) {
        return null;
    }
 
    public static void main(String[] args) throws ParseException {
        BattInf binf = new BattInf();
        binf.setStationName1("");
        binf.setStationName("");
        binf.setBattProducer("");
        binf.setDeviceName("1");
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date1 = sdf.parse("2000-01-01");
        Date date2 = sdf.parse("2016-12-30");
        binf.setBattProductDate(ActionUtil.getSimpDate(date1));
        binf.setBattProductDate1(ActionUtil.getSimpDate(date2));
 
        User_inf uinf = new User_inf();
        uinf.setUName("0");
 
        Page p = new Page();
        p.setPageCurr(1);
        p.setPageSize(10);
 
        Batt_User_Permit bup = new Batt_User_Permit();
        bup.setBinf(binf);
        bup.setPage(p);
        bup.setUinf(uinf);
        Batt_maint_infAgainImpl bimpl = new Batt_maint_infAgainImpl();
        List<Batt_maint_inf> list = bimpl.serchByCondition(bup);
 
        for (Batt_maint_inf batt_maint_inf : list) {
            System.out.println(batt_maint_inf);
        }
        System.out.println(list.size());
    }
 
}