package com.fgkj.dao.impl; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import com.fgkj.dao.AlarmDaoFactory; 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.Alarm_param; public class Alarm_paramImpl implements BaseDAO,CallBack{ public List getResults(ResultSet rs) { List list=new ArrayList(); try { while(rs.next()){ Alarm_param ap=new Alarm_param(); ap.setNum(rs.getInt("num")); ap.setAlm_id(rs.getInt("alm_id")); ap.setAlm_name(rs.getString("alm_name")); ap.setAlm_high_coe(rs.getFloat("alm_high_coe")); ap.setAlm_low_coe(rs.getFloat("alm_low_coe")); ap.setAlm_high_level(rs.getInt("alm_high_level")); ap.setAlm_low_level(rs.getInt("alm_low_level")); ap.setAlm_high_en(rs.getInt("alm_high_en")); ap.setAlm_low_en(rs.getInt("alm_low_en")); list.add(ap); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return list; } public boolean add(Object obj) { Alarm_param ap=(Alarm_param) obj; String sql="insert into db_param.tb_alarm_param(alm_id,alm_name,alm_high_coe,alm_low_coe,alm_high_level,alm_low_level,alm_high_en,alm_low_en) values(?,?,?,?,?,?,?,?)"; Boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{ap.getAlm_id(),ap.getAlm_name(),ap.getAlm_high_coe(),ap.getAlm_low_coe(), ap.getAlm_high_level(),ap.getAlm_low_level(),ap.getAlm_high_en(),ap.getAlm_low_en()}); return bl; } //编辑参数 public boolean update(Object obj) { Alarm_param ap=(Alarm_param) obj; String sql="update db_param.tb_alarm_param set alm_high_coe=?,alm_low_coe=?,alm_high_level=?,alm_low_level=?,alm_high_en=?,alm_low_en=? where alm_id=? "; Boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{ap.getAlm_high_coe(),ap.getAlm_low_coe(), ap.getAlm_high_level(),ap.getAlm_low_level(),ap.getAlm_high_en(),ap.getAlm_low_en(),ap.getAlm_id()}); return bl; } public boolean del(Object obj) { Alarm_param ap=(Alarm_param) obj; String sql="delete from db_param.tb_alarm_param where num=?"; Boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{ap.getNum()}); return bl; } public List searchAll() { String sql="select num,alm_id,alm_name,alm_high_coe,alm_low_coe,alm_high_level,alm_low_level,alm_high_en,alm_low_en from db_param.tb_alarm_param " ; List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), null, new App_ParamImpl()); return list; } //7.1根据告警类型查告警参数 public List serchByCondition(Object obj) { Alarm_param ap=(Alarm_param) obj; String sql=""; String baseSql=" select num,alm_id,alm_name,alm_high_coe,alm_low_coe,alm_high_level,alm_low_level,alm_high_en,alm_low_en from db_param.tb_alarm_param " + " where "; //alm_id=1电池告警参数 String idSqlT=" alm_id in ("+AlarmDaoFactory.Alarm_vol_Online+","+AlarmDaoFactory.Alarm_vol_Group+","+AlarmDaoFactory.Alarm_curr_Charge+","+AlarmDaoFactory.Alarm_curr_Discharge +","+AlarmDaoFactory.Alarm_vol_Monomer+","+AlarmDaoFactory.Alarm_tmp_Monomer+","+AlarmDaoFactory.Alarm_res_Monomer+","+AlarmDaoFactory.Alarm_res_Conn +","+AlarmDaoFactory.ALM_TYPE_DisChargeMonVol_ID+") "; //alm_id=2容量/更换告警参数 String idSqlF=" alm_id in ("+AlarmDaoFactory.Alarm_CapAlarm+","+AlarmDaoFactory.Alarm_CapChange+") "; if(ap.getAlm_id()==1){ baseSql+=idSqlT; }else{ baseSql+=idSqlF; } String endSql=" order by alm_id "; sql=baseSql+endSql; //System.out.println(sql);; List list=DAOHelper.executeQuery(sql, DBUtil.getConn(),null, new Alarm_paramImpl()); return list; } public List serchByInfo(Object obj) { // TODO Auto-generated method stub return null; } public static void main(String[] args) { Alarm_paramImpl aimpl=new Alarm_paramImpl(); Alarm_param ap=new Alarm_param(); ap.setAlm_id(2); List list=aimpl.serchByCondition(ap); for (Alarm_param a : list) { System.out.println(a); } } }