1
81041
2019-10-18 cc4059f9f5a2cd6766f4d888bd35d19f3827a053
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
package com.fgkj.dao.impl;
 
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
 
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.Batt_maint_inf;
import com.fgkj.dto.Batt_maint_process;
 
public class Batt_maint_processImpl implements BaseDAO,CallBack{
 
    public List getResults(ResultSet rs) {
        List list=new ArrayList();
        try {
            while(rs.next()){
                Batt_maint_process bprocess=new Batt_maint_process();
                bprocess.setNum(rs.getInt("num"));
                bprocess.setUname(rs.getString("uname"));
                bprocess.setBatt_maint_rec_id(rs.getInt("batt_maint_rec_id"));
                bprocess.setUsr_id(rs.getInt("usr_id"));
                bprocess.setWork_caption(rs.getString("work_caption"));
                bprocess.setWork_caption_time(rs.getTimestamp("work_caption_time"));
                
                list.add(bprocess);
                
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
        return list;
    }
 
    public boolean add(Object obj) {
        Batt_maint_process bprocess=(Batt_maint_process) obj;
        String sql="insert into db_battinf.tb_batt_maint_process(batt_maint_rec_id,usr_id,work_caption,work_caption_time) values(?,?,?,?) ";
        Boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{bprocess.getBatt_maint_rec_id(),
            bprocess.getUsr_id(),bprocess.getWork_caption(),bprocess.getWork_caption_time()});
        return bl;
    }
    //2.1电池维护记录查询(编辑记录)的同时向batt_maint_process表插入数据提交的方式插入数据库
    public String addPro(Object obj) {
        Batt_maint_process bprocess=(Batt_maint_process) obj;
        String sql="insert into db_battinf.tb_batt_maint_process(batt_maint_rec_id,usr_id,work_caption,work_caption_time) values("+bprocess.getBatt_maint_rec_id()+","+bprocess.getUsr_id()+
                ",'"+bprocess.getWork_caption()+"','"+DAOHelper.sdf.format(bprocess.getWork_caption_time())+"')";
        return sql;
    }
    public boolean update(Object obj) {
        Batt_maint_process bprocess=(Batt_maint_process) obj;
        String sql="update db_battinf.tb_batt_maint_process set batt_maint_rec_id=?,usr_id=?,work_caption=?,work_caption_time=? where num=?";
        Boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{bprocess.getBatt_maint_rec_id(),
            bprocess.getUsr_id(),bprocess.getWork_caption(),bprocess.getWork_caption_time(),bprocess.getNum()});
        return bl;
    }
 
    //2.1 电池维护记录查询(删除记录)时,将所有的编辑记录全删除
    public boolean del(Object obj) {
        Batt_maint_process bprocess=(Batt_maint_process) obj;
        String sql="delete from db_battinf.tb_batt_maint_process where batt_maint_rec_id=?";
        Boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{bprocess.getBatt_maint_rec_id()});
        return bl;
    }
 
    public List searchAll() {
        String sql="select * from db_battinf.tb_batt_maint_process";
        List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), null, new Batt_maint_processImpl());
        return list;
    }
    
    //3.1根据id查所有编辑信息
    public List serchByCondition(Object obj) {
        Batt_maint_process bprocess=(Batt_maint_process) obj;
        //System.out.println(bprocess);
        String sql="select num,batt_maint_rec_id,usr_id,work_caption,work_caption_time,uname from db_battinf.tb_batt_maint_process,db_user.tb_user_inf where batt_maint_rec_id=? and db_user.tb_user_inf.uid=usr_id ORDER BY work_caption_time desc";
        List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{bprocess.getBatt_maint_rec_id()}, new Batt_maint_processImpl());
        return list;
    }
 
    public List serchByInfo(Object obj) {
        // TODO Auto-generated method stub
        return null;
    }
    public static void main(String[] args) {
        
        Batt_maint_processImpl bp=new Batt_maint_processImpl();
        /*List<Batt_maint_process> list=bp.searchAll();
        for(Batt_maint_process u:list){
            System.out.println(u);
        }*/
        Batt_maint_process b=new Batt_maint_process();
        b.setUsr_id(1001);
        List<Batt_maint_process> list=bp.serchByCondition(b);
        for(Batt_maint_process u:list){
            System.out.println(u);
        }
        System.out.println(list.size());
    }
}