1
81041
2019-06-20 ab3c4acf83f54f8449ca8664c4a2bb79bd30f297
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
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 com.fgkj.dao.BaseDAO;
import com.fgkj.dao.CallBack;
import com.fgkj.dao.DAOHelper;
import com.fgkj.dao.FBS9100_ComBase;
import com.fgkj.dao.UinfDaoFactory;
import com.fgkj.db.DBUtil;
import com.fgkj.dto.User_log;
import com.fgkj.dto.ram.Fbs9100_battparam;
import com.fgkj.dto.ram.Fbs9100_setparam;
import com.fgkj.dto.ram.Fbs9100_sysparam;
import com.fgkj.services.User_logService;
 
public class Fbs9100_sysparamImpl 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) {
        Fbs9100_sysparam sys=(Fbs9100_sysparam) obj;
        String sql=" update db_ram_db.tb_fbs9100_sysparam set IPADDR=?,SubIPADDR=?,NetGateADDR=?,GroupVolRange=?,GroupVolSorce=?,CurrentRange=?,CurrentTyte=?,MonomerOrder=?,BackLightTime=?" +
                ",MACADDR=?,LoaderCount=?,DtCardCount=?,PowerBreakChargeCurr=?,MajorBattGroupNum=?,POF_BG_Boost_Cnt=?,POF_BG_Boost_VolStop=?,POF_BG_Boost_VolStart=? " +
                "where dev_id=? ";
        boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{sys.getIPADDR(),sys.getSubIPADDR(),sys.getNetGateADDR(),sys.getGroupVolRange(),sys.getGroupVolSorce(),sys.getCurrentRange(),sys.getCurrentTyte(),sys.getMonomerOrder(),sys.getBackLightTime()
            ,sys.getMACADDR(),sys.getLoaderCount(),sys.getDtCardCount(),sys.getPowerBreakChargeCurr(),sys.getMajorBattGroupNum(),sys.getPOF_BG_Boost_Cnt(),sys.getPOF_BG_Boost_VolStop(),sys.getPOF_BG_Boost_VolStart(),sys.getDev_id()});
        return bl;
    }
    //批量设置系统参数
    public boolean updatePro(Object obj) {
        List<Fbs9100_sysparam> list=(List<Fbs9100_sysparam>) obj;
        ArrayList sql_str=new ArrayList();
        List<User_log> listU=new ArrayList<User_log>();//存放user_log
        if(list!=null&&list.size()>0){
            for (int i = 0; i < list.size(); i++) {
                Fbs9100_sysparam fs=list.get(i);
                String sql="REPLACE  into db_ram_db.tb_fbs9100_sysparam(dev_id,op_cmd,IPADDR,SubIPADDR,NetGateADDR,GroupVolRange,GroupVolSorce,CurrentRange,CurrentTyte,MonomerOrder,BackLightTime"
                        + ",MACADDR,LoaderCount,DtCardCount,PowerBreakChargeCurr,MajorBattGroupNum,POF_BG_Boost_Cnt,POF_BG_Boost_VolStop,POF_BG_Boost_VolStart) "
                        + " values("+fs.getDev_id()+","+fs.getOp_cmd()+",'"+fs.getIPADDR()+"','"+fs.getSubIPADDR()+"','"+fs.getNetGateADDR()+"',"+fs.getGroupVolRange()+","+fs.getGroupVolSorce()+","+fs.getCurrentRange()+","+fs.getCurrentTyte()+","+fs.getMonomerOrder()+","+fs.getBackLightTime()
                        +",'"+fs.getMACADDR()+"',"+fs.getLoaderCount()+","+fs.getDtCardCount()+","+fs.getPowerBreakChargeCurr()+","+fs.getMajorBattGroupNum()+","+fs.getPOF_BG_Boost_Cnt()+","+fs.getPOF_BG_Boost_VolStop()+","+fs.getPOF_BG_Boost_VolStart()+")";
                sql_str.add(sql);
                {
                    String msg="修改"+fs.getDev_id()+"机房系统参数";
                    User_log ulog=UinfDaoFactory.CreateULog(UinfDaoFactory.Alter, msg);
                    listU.add(ulog);
                 }
            }
        }
        
        Boolean bl=DAOHelper.makeManualCommit(DBUtil.getConn(), sql_str);
        (new User_logService()).addPro(listU);//将用户的操作记录下来
        return bl;
    }
    //查询系统参数前(如果没有默认数据要用REPLACE 添加一笔数据)
    public boolean replace (Object obj){
        Fbs9100_sysparam sys=(Fbs9100_sysparam) obj;
        String sql=" REPLACE  into db_ram_db.tb_fbs9100_sysparam(dev_id) values(?)";
        boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{sys.getDev_id()});
        return bl;
    }
    //查询系统参数前(如果没有默认数据要用REPLACE 添加一笔数据)同时发送命令
    public boolean replacePL(Object obj){
        Fbs9100_sysparam sys=(Fbs9100_sysparam) obj;
        String sql=" REPLACE  into db_ram_db.tb_fbs9100_sysparam(dev_id,op_cmd) values(?,?)";
        boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{sys.getDev_id(),sys.getOp_cmd()});
        return bl;
    }
    //批量读取电池参数
    public boolean readPL(Object obj) {
        List<Fbs9100_sysparam> list=(List<Fbs9100_sysparam>) obj;
        ArrayList sql_str=new ArrayList();
        List<User_log> listU=new ArrayList<User_log>();//存放user_log
        if(list!=null&&list.size()>0){
            for (int i = 0; i < list.size(); i++) {
                Fbs9100_sysparam fs=list.get(i);
                String sql="replace into db_ram_db.tb_fbs9100_sysparam(dev_id,op_cmd) "
                        + " values("+fs.getDev_id()+","+fs.getOp_cmd()+")";
                sql_str.add(sql);
                {
                    String msg="获取"+fs.getDev_id()+"系统参数";
                    User_log ulog=UinfDaoFactory.CreateULog(UinfDaoFactory.Alter, msg);
                    listU.add(ulog);
                 }
            }
        }
        
        Boolean bl=DAOHelper.makeManualCommit(DBUtil.getConn(), sql_str);
        (new User_logService()).addPro(listU);//将用户的操作记录下来
        return bl;
    }
    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) {
        Fbs9100_sysparam sys=(Fbs9100_sysparam) obj;
        String sql=" select distinct dev_ip,dev_id,op_cmd,IPADDR,SubIPADDR,NetGateADDR,GroupVolRange,GroupVolSorce,CurrentRange,CurrentTyte,MonomerOrder,BackLightTime" +
                " ,MACADDR,LoaderCount,DtCardCount,PowerBreakChargeCurr,MajorBattGroupNum,POF_BG_Boost_Cnt,POF_BG_Boost_VolStop,POF_BG_Boost_VolStart" +
                " ,db_battinf.tb_battinf.FBSDeviceName,db_battinf.tb_battinf.StationName " +
                " from db_ram_db.tb_fbs9100_sysparam,db_battinf.tb_battinf " +
                " where db_ram_db.tb_fbs9100_sysparam.dev_id=db_battinf.tb_battinf.FBSDeviceId " +
                " and db_ram_db.tb_fbs9100_sysparam.dev_id=?  " ;
        List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{sys.getDev_id()}, new CallBack() {
            
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while(rs.next()){
                        Fbs9100_sysparam fbs_sys=new Fbs9100_sysparam();
                        fbs_sys.setDev_ip(rs.getString("dev_ip"));
                        fbs_sys.setDev_id(rs.getInt("dev_id"));
                        fbs_sys.setOp_cmd(rs.getInt("op_cmd"));
                        fbs_sys.setIPADDR(rs.getString("iPADDR"));
                        fbs_sys.setSubIPADDR(rs.getString("subIPADDR"));
                        fbs_sys.setNetGateADDR(rs.getString("netGateADDR"));
                        fbs_sys.setGroupVolRange(rs.getInt("groupVolRange"));
                        fbs_sys.setGroupVolSorce(rs.getInt("groupVolSorce"));
                        fbs_sys.setCurrentRange(rs.getInt("currentRange"));
                        fbs_sys.setCurrentTyte(rs.getInt("currentTyte"));
                        fbs_sys.setMonomerOrder(rs.getInt("monomerOrder"));
                        fbs_sys.setBackLightTime(rs.getInt("backLightTime"));
                        fbs_sys.setMACADDR(rs.getString("mACADDR"));
                        fbs_sys.setLoaderCount(rs.getInt("loaderCount"));
                        fbs_sys.setDtCardCount(rs.getInt("dtCardCount"));
                        fbs_sys.setPowerBreakChargeCurr(rs.getFloat("powerBreakChargeCurr"));
                        fbs_sys.setMajorBattGroupNum(rs.getInt("majorBattGroupNum"));
                        fbs_sys.setPOF_BG_Boost_Cnt(rs.getInt("pOF_BG_Boost_Cnt"));
                        fbs_sys.setPOF_BG_Boost_VolStop(rs.getFloat("pOF_BG_Boost_VolStop"));
                        fbs_sys.setPOF_BG_Boost_VolStart(rs.getFloat("pOF_BG_Boost_VolStart"));
                        fbs_sys.setFBSDeviceName(rs.getString("FBSDeviceName"));
                        fbs_sys.setStationName(rs.getString("stationName"));
                        list.add(fbs_sys);
                    }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                        
                return list;
            }
        });
        return list;
    }
    //系统参数命令操作设备时的cmd和ack校验    
    public boolean sendCmdToFBS9100Dev(int cmd,int dev_id)
    { 
        int m_cmd = cmd;
        int m_cmd_ack = cmd;
        switch(m_cmd) {
            case FBS9100_ComBase.CMD_GetSYSSetParam: m_cmd_ack = FBS9100_ComBase.CMD_GetSYSSetParamAck; break;
            case FBS9100_ComBase.CMD_SetSYSSetParam: m_cmd_ack = FBS9100_ComBase.CMD_SetSYSSetParamAck; break;
            default: return false;
        }
        boolean res_exe = false;
        String sql = "UPDATE db_ram_db.tb_fbs9100_sysparam  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_fbs9100_sysparam "+
                        " 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;
    }
    
    //批量设置系统参数成功后读取命令的ACK
    public boolean getCmdAck(int cmd,int dev_id) {
        int m_cmd = cmd;
        int m_cmd_ack = cmd;
        switch(m_cmd) {
        case FBS9100_ComBase.CMD_GetSYSSetParam: m_cmd_ack = FBS9100_ComBase.CMD_GetSYSSetParamAck; break;
        case FBS9100_ComBase.CMD_SetSYSSetParam: m_cmd_ack = FBS9100_ComBase.CMD_SetSYSSetParamAck; break;
        default: return false;
        }
        String sql = "SELECT op_cmd FROM db_ram_db.tb_fbs9100_sysparam "+
                " WHERE dev_id="+dev_id;
        Connection conn=DBUtil.getConn();
        PreparedStatement ps = null;
        ResultSet rs = null;
        boolean res_exe=false;
        try {
            ps = conn.prepareStatement(sql);
            rs=ps.executeQuery();
            if(rs.next())
            {
                if(rs.getInt("op_cmd") == m_cmd_ack)
                {
                    res_exe = true;
                }
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        DBUtil.close(rs, ps, conn);
        return res_exe;
    }
    
    public List serchByInfo(Object obj) {
        // TODO Auto-generated method stub
        return null;
    }
    
    public static void main(String[] args) {
        Fbs9100_sysparamImpl fimpl=new Fbs9100_sysparamImpl();
        Fbs9100_sysparam sys=new Fbs9100_sysparam();
        sys.setDev_id(910000011);
        List list=fimpl.serchByCondition(sys);
        System.out.println(list.size());
    }
 
}