hdw
2018-11-14 b277552000ca51181b2f8ad1031f232bea9aee6f
gx_tieta/src/com/fgkj/dao/impl/ram/Fbs9100s_dfu_stateImpl.java
@@ -10,6 +10,7 @@
import com.fgkj.dao.DAOHelper;
import com.fgkj.dao.UinfDaoFactory;
import com.fgkj.db.DBUtil;
import com.fgkj.dto.BattInf;
import com.fgkj.dto.User_log;
import com.fgkj.dto.ram.Fbs9100s_dfu_state;
import com.fgkj.services.User_logService;
@@ -23,11 +24,138 @@
    //升级插入
   public boolean add(Object obj) {
      Fbs9100s_dfu_state dfu=(Fbs9100s_dfu_state) obj;
      String sql="REPLACE into db_ram_db.tb_fbs9100s_dfu_state (dev_id,dfu_file,dfu_wr_stat,dfu_data_blocknum) values (?,?,?,?)";
      String sql=" REPLACE into db_ram_db.tb_fbs9100s_dfu_state (dev_id,dfu_file,dfu_wr_stat,dfu_data_blocknum) values (?,?,?,?)";
      boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{dfu.getDev_id(),dfu.getDfu_file(),dfu.getDfu_wr_stat(),dfu.getDfu_data_blocknum()});
      return bl;
   }
    //升级确认
   //批量升级插入(所有属性传到stationName中)
   public boolean addPro(Object obj) {
      BattInf binf=(BattInf) obj;
      String sql=" REPLACE into db_ram_db.tb_fbs9100s_dfu_state(dev_id,dfu_file,dfu_wr_stat,dfu_data_blocknum) " +
            " SELECT  DISTINCT fBSDeviceId,'avr_dfu.uc3',1,1 FROM  db_battinf.tb_battinf " +
            " where ";
      //条件
      String sql0=" stationid=? "; //具体机房
      String sql1=" stationname1=? ";//省
      String sql2=" stationname2=? ";//市
      String sql5=" stationname5=? ";//区县
      switch (binf.getNum()) {
      case 0:
         sql+=sql0;
         break;
        case 1:
           sql+=sql1;
         break;
        case 2:
           sql+=sql2;
         break;
        case 5:
           sql+=sql5;
          break;
      default:
         return false;
      }
      //System.out.println(sql);
      boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{binf.getStationName()});
      return bl;
   }
    //表格显示批量插入的机房信息
   public List serchInserStation(Object obj){
      BattInf binf=(BattInf) obj;
      String sql="SELECT  DISTINCT fBSDeviceId,fBSDeviceName,stationId,stationname,stationname1,stationname2,stationname3,stationname5 from db_battinf.tb_battinf " +
            " where ";
      //条件
      String sql0=" stationid=? "; //具体机房
      String sql1=" stationname1=? ";//省
      String sql2=" stationname2=? ";//市
      String sql5=" stationname5=? ";//区县
      switch (binf.getNum()) {
      case 0:
         sql+=sql0;
         break;
        case 1:
           sql+=sql1;
         break;
        case 2:
           sql+=sql2;
         break;
        case 5:
           sql+=sql5;
          break;
      default:
         return null;
      }
      String endSql="  order by fBSDeviceId ";
      sql+=endSql;
      List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{binf.getStationName()}, new CallBack() {
         public List getResults(ResultSet rs) {
            List list=new ArrayList();
            try {
               while(rs.next()){
                  BattInf binf=new BattInf();
                  binf.setFBSDeviceId(rs.getInt("fBSDeviceId"));
                  binf.setStationName(rs.getString("stationName"));
                  binf.setStationName1(rs.getString("stationName1"));
                  binf.setStationName2(rs.getString("stationName2"));
                  binf.setStationName3(rs.getString("stationName3"));
                  binf.setStationName5(rs.getString("stationName5"));
                  binf.setStationId(rs.getString("stationId"));
                  binf.setFBSDeviceName(rs.getString("fBSDeviceName"));
                  list.add(binf);
               }
            } catch (SQLException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
            }
            return list;
         }
      });
      return list;
   }
   //批量升级前验证升级的设备必须处于在线监测状态(9100state的workstate为0)
   public List judgeStation(Object obj){
      List<Integer> list=(List<Integer>) obj;
      String sql=" select distinct dev_id,db_battinf.tb_battinf.stationname,db_battinf.tb_battinf.stationname3 from db_ram_db.tb_fbs9100_state,db_battinf.tb_battinf  " +
            " where db_ram_db.tb_fbs9100_state.dev_id=db_battinf.tb_battinf.fBSDeviceId  and dev_workstate=0 and dev_id in(";
      String devSql="";
      Object[] object=new Object[list.size()];
      //System.out.println(list.size());
      if(list!=null&&list.size()>0){
         for (int i = 0; i <list.size(); i++) {
            if(i==(list.size()-1)){
               devSql+="?)";
            }else{
               devSql+="?,";
            }
            object[i]=list.get(i);
         }
      }
      sql+=devSql;
      String endSql="  order by dev_id";
      sql+=endSql;
      List listAll=DAOHelper.executeQuery(sql, DBUtil.getConn(), object, new CallBack() {
         public List getResults(ResultSet rs) {
            List list=new ArrayList();
            try {
               while(rs.next()){
                  BattInf binf=new BattInf();
                  binf.setFBSDeviceId(rs.getInt("dev_id"));
                  binf.setStationName(rs.getString("stationName"));
                  binf.setStationName3(rs.getString("stationName3"));
                  list.add(binf);
               }
            } catch (SQLException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
            }
            return list;
         }
      });
      return listAll;
   }
   //升级确认
   public boolean update(Object obj) {
      Fbs9100s_dfu_state dfu=(Fbs9100s_dfu_state) obj;
      String sql="update db_ram_db.tb_fbs9100s_dfu_state set dfu_en=true,dfu_wr_stat=1, dfu_data_blocknum=1 where dev_id=?";
@@ -119,15 +247,30 @@
      // TODO Auto-generated method stub
      return null;
   }
   public static void main(String[] args) {
    public static void main(String[] args) {
   Fbs9100s_dfu_stateImpl fimpl=new Fbs9100s_dfu_stateImpl();
   List list=new ArrayList();
   list.add(910000013);
   list.add(910000002);
   list.add(910000577);
   list.add(910000534);
   List<Fbs9100s_dfu_state> listAll=fimpl.serchByCondition(list);
   BattInf binf=new BattInf();
   binf.setNum(1);
   binf.setStationName("湖北省");
   /*List<Fbs9100s_dfu_state> listAll=fimpl.serchByCondition(list);
   for (Fbs9100s_dfu_state dfu : listAll) {
      System.out.println(dfu);
   }*/
   /*List<BattInf> listAll=fimpl.judgeStation(list);
   for (BattInf binf : listAll) {
      System.out.println(binf.getStationName3()+" "+binf.getFBSDeviceId());
   }*/
   /*
   boolean bl=fimpl.addPro(binf);
   System.out.println(bl);*/
   List<BattInf> listAll=fimpl.serchInserStation(binf);
   for (BattInf b : listAll) {
      System.out.println(b.getStationName3()+" "+b.getFBSDeviceId());
   }
}
}