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
package com.fgkj.dao.impl.ram;
 
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
 
import org.omg.CORBA.OBJ_ADAPTER;
 
import com.fgkj.dao.BaseDAO;
import com.fgkj.dao.CallBack;
import com.fgkj.dao.DAOHelper;
import com.fgkj.dao.FBS9100_ComBase;
import com.fgkj.db.DBUtil;
import com.fgkj.dto.ram.Fbs9100s_fod_param;
 
public class Fbs9100s_fod_paramImpl implements BaseDAO,CallBack{
 
    public List getResults(ResultSet rs) {
        // TODO Auto-generated method stub
        return null; 
    }
 
    public boolean add(Object obj) {
        // TODO Auto-generated method stub
        return false;
    }
    //发送命令修改参数
    public boolean update(Object obj) {
        Fbs9100s_fod_param fod=(Fbs9100s_fod_param) obj;
        String sql=" replace into db_ram_db.tb_fbs9100s_fod_param(dev_id,GroupNum,STDCap_one,FloatVol_one,Strength_one,YHStrength_one,TimeLong_one,STDCap_two,FloatVol_two,Strength_two,YHStrength_two,TimeLong_two"
                + ",STDCap_three,FloatVol_three,Strength_three,YHStrength_three,TimeLong_three,STDCap_four,FloatVol_four,Strength_four,YHStrength_four,TimeLong_four) "
                + "  values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{fod.getDev_id(),fod.getGroupNum()
            ,fod.getSTDCap_one(),fod.getFloatVol_one(),fod.getStrength_one(),fod.getYHStrength_one(),fod.getTimeLong_one()
            ,fod.getSTDCap_two(),fod.getFloatVol_two(),fod.getStrength_two(),fod.getYHStrength_two(),fod.getTimeLong_two()
            ,fod.getSTDCap_three(),fod.getFloatVol_three(),fod.getStrength_three(),fod.getYHStrength_three(),fod.getTimeLong_three()
            ,fod.getSTDCap_four(),fod.getFloatVol_four(),fod.getStrength_four(),fod.getYHStrength_four(),fod.getTimeLong_four()});
        return bl;
    }
    //启动和停止命令
    public boolean startOrStopTest(Object obj) {
        Fbs9100s_fod_param fod=(Fbs9100s_fod_param) obj;
        String sql=" replace into db_ram_db.tb_fbs9100s_fod_param(dev_id,GroupNum) "
                + "  values(?,?)";
        boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{fod.getDev_id(),fod.getGroupNum()});
        return bl;
    }
    //机房命令操作设备时的cmd和ack校验  
    public boolean sendCmdToFBS9100FOD(int cmd,int dev_id)
    { 
        int m_cmd = cmd;
        int m_cmd_ack = cmd;
        switch(m_cmd) {
            case FBS9100_ComBase.CMD_ReadFodParam: m_cmd_ack = FBS9100_ComBase.CMD_ReadFodParamAck; break;
            case FBS9100_ComBase.CMD_WriteFodParam: m_cmd_ack = FBS9100_ComBase.CMD_WriteFodParamAck; break;
            case FBS9100_ComBase.CMD_Start_FODCL_test: m_cmd_ack = FBS9100_ComBase.CMD_Start_FODCL_testAck; break;
            case FBS9100_ComBase.CMD_Start_FODYH_test: m_cmd_ack = FBS9100_ComBase.CMD_Start_FODYH_testAck; break;
            case FBS9100_ComBase.CMD_Stop_FOD_test: m_cmd_ack = FBS9100_ComBase.CMD_Stop_FOD_testAck; break;
            default: return false;
        }
        boolean res_exe = false;
        String sql = "UPDATE db_ram_db.tb_fbs9100s_fod_param  SET "
                        + " op_cmd=? "
                        + " WHERE dev_id=? ";
        Boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{m_cmd,dev_id});
        if(true == bl)
        {
            sql = "SELECT op_cmd FROM db_ram_db.tb_fbs9100s_fod_param "+
                        " WHERE dev_id="+dev_id;
            Connection conn=DBUtil.getConn();
            PreparedStatement ps = null;
            ResultSet rs = null;
            for(int n=0; n<20; n++)
            {
              try {
                    ps = conn.prepareStatement(sql);
                    rs=ps.executeQuery();
                        if(rs.next())
                        {
                            if(rs.getInt("op_cmd") == m_cmd_ack)
                            {
                                res_exe = true;
                                break;
                            }
                        }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
              
                try {
                    Thread.sleep(250);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            DBUtil.close(rs, ps, conn);
        }
        return res_exe;
    }
    public boolean del(Object obj) {
        // TODO Auto-generated method stub
        return false;
    }
 
    public List searchAll() {
        // TODO Auto-generated method stub
        return null;
    }
    //根据设备id查询参数
    public List serchByCondition(Object obj) {
        Fbs9100s_fod_param fod=(Fbs9100s_fod_param) obj;
        String sql=" select distinct num,dev_id,GroupNum"
                + ",STDCap_one,FloatVol_one,Strength_one,YHStrength_one,TimeLong_one "
                + ",STDCap_two,FloatVol_two,Strength_two,YHStrength_two,TimeLong_two "
                + ",STDCap_three,FloatVol_three,Strength_three,YHStrength_three,TimeLong_three "
                + ",STDCap_four,FloatVol_four,Strength_four,YHStrength_four,TimeLong_four  "
                + "  from db_ram_db.tb_fbs9100s_fod_param where dev_id=? limit 1";
        //System.out.println(sql);
        List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{fod.getDev_id()}, new CallBack() {
            
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while(rs.next()){
                        Fbs9100s_fod_param f=new Fbs9100s_fod_param();
                        f.setNum(rs.getInt("num"));
                        f.setDev_id(rs.getInt("dev_id"));
                        f.setGroupNum(rs.getInt("groupNum"));
                        f.setSTDCap_one(rs.getInt("sTDCap_one"));
                        f.setFloatVol_one(rs.getFloat("floatVol_one"));
                        f.setStrength_one(rs.getFloat("strength_one"));
                        f.setYHStrength_one(rs.getFloat("yHStrength_one"));
                        f.setTimeLong_one(rs.getInt("timeLong_one"));
                        
                        f.setSTDCap_two(rs.getInt("sTDCap_two"));
                        f.setFloatVol_two(rs.getFloat("floatVol_two"));
                        f.setStrength_two(rs.getFloat("strength_two"));
                        f.setYHStrength_two(rs.getFloat("yHStrength_two"));
                        f.setTimeLong_two(rs.getInt("timeLong_two"));
                        
                        f.setSTDCap_three(rs.getInt("sTDCap_three"));
                        f.setFloatVol_three(rs.getFloat("floatVol_three"));
                        f.setStrength_three(rs.getFloat("strength_three"));
                        f.setYHStrength_three(rs.getFloat("yHStrength_three"));
                        f.setTimeLong_three(rs.getInt("timeLong_three"));
                        
                        f.setSTDCap_four(rs.getInt("sTDCap_four"));
                        f.setFloatVol_four(rs.getFloat("floatVol_four"));
                        f.setStrength_four(rs.getFloat("strength_four"));
                        f.setYHStrength_four(rs.getFloat("yHStrength_four"));
                        f.setTimeLong_four(rs.getInt("timeLong_four"));
                        list.add(f);
                    }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return list;
            }
        });
        return list;
    }
 
    public List serchByInfo(Object obj) {
        // TODO Auto-generated method stub
        return null;
    }
 
}