⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 huadong.java

📁 通讯采集软件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    catch (InterruptedException ie) {
      processDebug.writeDebug(debugNo + 100, "sleepmidi in huadong #1");
    }
  }

  public static void huaD() {
    int ret, i;
    boolean runTag = true;
    Collection allRows = null;
    Collection ftpRows = null;
    Iterator it = null, it_me = null, it_dvt = null, it_fr;
    Iterator it_pl = null;
    DataValue dv = null;
    DataValueDetail dvt = null;
    commonFunc cf = null;
    meter me;
    pulse pl = null;
    int count = 0;
    long min_last_send_time = Constant.MAX_TIME_TAG;

    init();
    while (runTag) {
      CommBuffer.IsRunning = true;
      count = 0;
      pbs.service.util.Calendar cal1 = pbs.service.util.Calendar.getInstance();
      long end_time = pbs.service.function.timeFunc.truncTime(cal1.
          getTimeInMillis() / 1000);
      long start_time = HUADONG_TIME;
      if (end_time - start_time > 86400 * 366) {
        start_time = end_time - 86400 * 366;
      }
      System.out.println("huaD -- " + start_time);

      processDebug.writeDebug(debugNo + 100, "I am ready to work");
      System.out.println("I am ready to work");
      if (!wBean1.getStatusOK()) {
        ret = wBean1.init(Constant.SERVER_NO_SERVER1);
        if (ret < 0) {
          processDebug.writeDebug(debugNo + 100, "Error in huadong #2");
          pbs.service.util.Calendar cal4 = pbs.service.util.Calendar.
              getInstance();
          long now_time4 = cal4.getTimeInMillis() / 1000;
          String time_str = cF.getTimeStringLine(now_time4);
          CommBuffer.m_CommGui.appendString("时间: " + time_str + " 初始化wBean1" +
                                            " 失败");
          System.out.println("Error in huadong #2");
        }
      }
      if (!wBean2.getStatusOK()) {
        ret = wBean2.init(Constant.SERVER_NO_SERVER2);
        if (ret < 0) {
          processDebug.writeDebug(debugNo + 100, "Error in huadong #3");
          pbs.service.util.Calendar cal4 = pbs.service.util.Calendar.
              getInstance();
          long now_time4 = cal4.getTimeInMillis() / 1000;
          String time_str = cF.getTimeStringLine(now_time4);
          CommBuffer.m_CommGui.appendString("时间: " + time_str + " 初始化wBean2" +
                                            " 失败");
          System.out.println("Error in huadong #3");
        }
      }
      if (!wBean1.getStatusOK() && !wBean2.getStatusOK()) {
        processDebug.writeDebug(debugNo + 100, "Error in huadong #4");
        pbs.service.util.Calendar cal4 = pbs.service.util.Calendar.getInstance();
        long now_time4 = cal4.getTimeInMillis() / 1000;
        String time_str = cF.getTimeStringLine(now_time4);
        CommBuffer.m_CommGui.appendString("时间: " + time_str +
                                          " wBean1和wBean2状态异常");
        System.out.println("Error in huadong #4");
        sleep(5);
        continue;
      }

      if (paramChange) {
        mes = null;
        if (wBean1.getStatusOK()) {
          pbs.service.util.Calendar cal4 = pbs.service.util.Calendar.
              getInstance();
          long now_time4 = cal4.getTimeInMillis() / 1000;
          String time_str = cF.getTimeStringLine(now_time4);
          CommBuffer.m_CommGui.appendString("时间: " + time_str + " 准备下装华东转发表参数");

          mes = wBean1.getMeters();
          if (mes == null) {
            if (wBean2.getStatusOK()) {
              mes = wBean2.getMeters();
              if (mes == null) {
                processDebug.writeDebug(debugNo + 100, "Error in huadong #2.5");
                cal4 = pbs.service.util.Calendar.getInstance();
                now_time4 = cal4.getTimeInMillis() / 1000;
                time_str = cF.getTimeStringLine(now_time4);
                CommBuffer.m_CommGui.appendString("时间: " + time_str +
                                                  " 下装参数失败,等待下一次任务");
                sleep(5);
                continue;
              }
            }
            else {
              processDebug.writeDebug(debugNo + 100, "Error in huadong #2.6");
              cal4 = pbs.service.util.Calendar.getInstance();
              now_time4 = cal4.getTimeInMillis() / 1000;
              time_str = cF.getTimeStringLine(now_time4);
              CommBuffer.m_CommGui.appendString("时间: " + time_str +
                                                " 下装参数失败,等待下一次任务");
              sleep(5);
              continue;
            }
          }
        }
        else {
          mes = wBean2.getMeters();
          if (mes == null) {
            processDebug.writeDebug(debugNo + 100, "Error in huadong #2.8");

            pbs.service.util.Calendar cal4 = pbs.service.util.Calendar.
                getInstance();
            long now_time4 = cal4.getTimeInMillis() / 1000;
            String time_str = cF.getTimeStringLine(now_time4);
            CommBuffer.m_CommGui.appendString("时间: " + time_str +
                                              " 下装参数失败,等待下一次任务");
            sleep(5);
            continue;
          }
        }
        paramChange = false;
        processDebug.writeDebug(debugNo + 100, "begin to down param");
      }
      if (mes == null) {
        processDebug.writeDebug(debugNo + 100, "Error in huadong #2.9");
        System.out.println("Error in huadong #2.9");

        pbs.service.util.Calendar cal4 = pbs.service.util.Calendar.getInstance();
        long now_time4 = cal4.getTimeInMillis() / 1000;
        String time_str = cF.getTimeStringLine(now_time4);
        CommBuffer.m_CommGui.appendString("时间: " + time_str +
                                          " 下装参数失败,等待下一次任务");

        paramChange = true;
        sleep(5);
        continue;
      }
      if (mes.size() == 0) {
        processDebug.writeDebug(debugNo + 100, "Error in huadong #2.10");
        System.out.println("Error in huadong #2.10");
        paramChange = true;
        sleep(5);
        continue;
      }

      pbs.service.util.Calendar cal4 = pbs.service.util.Calendar.getInstance();
      long now_time4 = cal4.getTimeInMillis() / 1000;
      String time_str = cF.getTimeStringLine(now_time4);
      CommBuffer.m_CommGui.appendString("时间: " + time_str +
                                        " 下装参数成功,准备开始任务");

      try {
        ftpRows = getFtpInfo(debugNo);
        if (ftpRows != null) {
          while (start_time < end_time) {
            long modify_time = checkFile(HUADONG_DIR_NAME, debugNo, start_time,
                                         ftpRows);
            if (modify_time > 1) {
              if (task_type == Constant.TASK_TYPE_BY_HAND) {
                if (NeedModiTimeOrNot(HUADONG_DIR_NAME, start_time)) {
                  task_type = Constant.TASK_TYPE_ON_TIME; //定时任务,修改时间
                }
              }
              count = 1;
              pbs.service.util.Calendar cal2 = pbs.service.util.Calendar.
                  getInstance();
              long now_time1 = cal2.getTimeInMillis();
              processDebug.writeDebug(debugNo + 100,
                                      "Download file Start!Time:" + now_time1);
              ret = downFile(HUADONG_DIR_NAME, debugNo, start_time, modify_time);
              pbs.service.util.Calendar cal3 = pbs.service.util.Calendar.
                  getInstance();
              long now_time2 = cal3.getTimeInMillis();
              processDebug.writeDebug(debugNo + 100,
                                      "Download file End!Time:" + now_time2);
              long now_time3 = now_time2 / 1000;
              time_str = cF.getTimeStringLine(now_time3);
              CommBuffer.m_CommGui.appendString("时间: " + time_str + "  文件 " +
                                                getFileName(start_time) +
                                                " 下载完毕!");
              System.out.println("时间: " + time_str + "  文件 " +
                                 getFileName(start_time) + " 下载完毕!");

              allRows = getData(HUADONG_DIR_NAME, debugNo, start_time);
              if (allRows != null) {
                if (mes != null && mes.size() != 0) {
                  it_me = mes.iterator();
                  while (it_me.hasNext()) {
                    count++;
                    me = (meter) it_me.next();
                    if (me.getOtherKey1() == "") {
                      continue;
                    }
                    System.out.println("meter count = " + count +
                                       " meter.other_key1 =  " +
                                       me.getOtherKey1());
                    System.out.println("此电表开始组装数据");
                    ret = impData(debugNo, me, allRows, task_type, count);
                    if (ret < 0) {
                      processDebug.writeDebug(debugNo + 100,
                                              "Error in HUADONG #000");
                    }
                    sleep(1);
                  }
                }
              }
              cal4 = pbs.service.util.Calendar.
                  getInstance();
              now_time4 = cal4.getTimeInMillis() / 1000;
              String time_str1 = cF.getTimeStringLine(now_time4);
              CommBuffer.m_CommGui.appendString("时间: " + time_str1 + "  数据文件 " +
                                                getFileName(start_time) +
                                                " 导入成功");
              System.out.println("时间: " + time_str1 + "  数据文件 " +
                                 getFileName(start_time) + " 导入成功");
              processDebug.writeDebug(debugNo + 100,
                                      "import HUADONG data OK!Day_time===" +
                                      start_time);
            }
            start_time += 86400;
            sleep(2);
          }
        }
        else if (ftpRows == null) {
          System.out.println(
              "something is wrong, wait 15 minutes and try again");
          try {
            Thread.sleep(1000 * 60 * 15);
          }
          catch (InterruptedException ie) {
            processDebug.writeDebug(debugNo + 100, "Error in HUADONG 777");
            System.out.println("Error in HUADONG 777");
          }
          continue;
        }
      }
      catch (Exception ex) {
        processDebug.writeDebug(debugNo + 100, "Error in HUADONG 666");
        System.out.println("Error in HUADONG 666");
        DataOutputStream ds = processDebug.getDebugStream(debugNo);
        ex.printStackTrace(new PrintStream(ds));
        processDebug.closeDebugStream(ds);
        System.out.println(
            "something is wrong in ftp, wait 15 minutes and try again");
        try {
          Thread.sleep(1000 * 60 * 15);
        }
        catch (InterruptedException ie) {
          processDebug.writeDebug(debugNo + 100, "Error in HUADONG 777");
          System.out.println("Error in HUADONG 777");
        }
        continue;
      }
      processDebug.writeDebug(debugNo + 100, "go to sleep 2 hours!");
      CommBuffer.IsRunning = false;
      if (! (CommBuffer.m_CommGui.getPursueStatus())) {
        CommBuffer.m_CommGui.setPursueEnable();
      }
      try {
        Thread.sleep(1000 * 3600 * 2); //一次读到当前时间,两小时以后再读
      }
      catch (InterruptedException ie) {
        processDebug.writeDebug(debugNo + 100, "Sleep Error in HUADONG #000");
        System.out.println("Sleep Error in HUADONG #000");
      }
    }
  }

  static long getTimeStr(String str1, String str2) {
    String yearStr = null;
    String monthStr = null;
    String dayStr = null;
    String hourStr = null;
    String minStr = null;
    String am_pm = null;
    int hourTime;

    String timeStr = null;

    monthStr = str1.substring(0, 2);
    dayStr = str1.substring(3, 5);
    yearStr = str1.substring(6, 8);
    hourStr = str2.substring(0, 2);
    minStr = str2.substring(3, 5);
    am_pm = str2.substring(5, 7);
    if (am_pm.equalsIgnoreCase("PM")) {
      hourTime = Integer.parseInt(hourStr);
      hourTime += 12;
      hourStr = (new Integer(hourTime)).toString();
    }
    timeStr = "20" + yearStr + monthStr + dayStr + hourStr + minStr + "00";
    long Ctime = getTimeFromString(timeStr);

    return Ctime;
  }

  static long getTimeFromString(String str) {
    String yearStr = null;
    String monthStr = null;
    String dayStr = null;
    String hourStr = null;
    String minStr = null;
    String secStr = null;
    if (str == null) {
      return -1;
    }
    if (str.length() == 0) {
      return -1;
    }
    yearStr = str.substring(0, 4);
    monthStr = str.substring(4, 6);
    dayStr = str.substring(6, 8);
    hourStr = str.substring(8, 10);
    minStr = str.substring(10, 12);
    secStr = str.substring(12, 14);
    Date date = new Date();
    pbs.service.util.Calendar cal = pbs.service.util.Calendar.getInstance();
    cal.setTime(date);
    cal.set(Calendar.YEAR, Integer.parseInt(yearStr));
    cal.set(Calendar.MONTH, Integer.parseInt(monthStr) - 1);
    cal.set(Calendar.DATE, Integer.parseInt(dayStr));
    cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hourStr));
    cal.set(Calendar.MINUTE, Integer.parseInt(minStr));
    cal.set(Calendar.SECOND, Integer.parseInt(secStr));
    long Ctime = cal.getTimeInMillis();
    return Ctime;
  }

  static String getDayString(long now_time) {
    pbs.service.util.Calendar cal = pbs.service.util.Calendar.getInstance();
    String timeStr, yearStr, monthStr, dayStr;

    cal.setTimeInMillis(now_time * 1000);
    yearStr = (new Integer(cal.get(pbs.service.util.Calendar.YEAR))).toString();
    if (cal.get(pbs.service.util.Calendar.MONTH) + 1 < 10) {
      monthStr = "0" +
          (new Integer(cal.get(pbs.service.util.Calendar.MONTH) + 1)).toString();
    }
    else {
      monthStr = (new Integer(cal.get(pbs.service.util.Calendar.MONTH) + 1)).
          toString();
    }
    if (cal.get(pbs.service.util.Calendar.DAY_OF_MONTH) < 10) {
      dayStr = "0" +
          (new Integer(cal.get(pbs.service.util.Calendar.DAY_OF_MONTH))).
          toString();
    }
    else {
      dayStr = (new Integer(cal.get(pbs.service.util.Calendar.DAY_OF_MONTH))).
          toString();
    }

    timeStr = yearStr + monthStr + dayStr;

    return timeStr;
  }

  public static boolean NeedModiTimeOrNot(String dirName, long start_time) {
    boolean modifytime = true;
    pbs.service.util.Calendar cal1 = pbs.service.util.Calendar.getInstance();
    long start_time_check = start_time + 86400;
    String dayStr_check = null;
    String filename_check = null;
    long end_time_check = pbs.service.function.timeFunc.truncTime(cal1.
        getTimeInMillis() / 1000);
    while (start_time_check < end_time_check) {
      dayStr_check = getDayString(start_time_check);
      dayStr_check = dayStr_check.substring(2, 8);
      filename_check = "DL" + dayStr_check + ".dat";
      File fe_check = new File(dirName + filename_check);
      if (fe_check.exists() == true) { //比这个文件后面的文件存在,就不改最后采样时间
        modifytime = false;
        break;
      }
      start_time_check += 86400;
    }
    if (modifytime) {
      task_type = Constant.TASK_TYPE_ON_TIME;
      System.out.println("重新下载文件,并且修改最后采样时间");
    }
    else {
      task_type = Constant.TASK_TYPE_BY_HAND;
      System.out.println("重新下载文件,但是不修改最后采样时间");
    }
    return modifytime;
  }

  public static meter getMeterByOtherKey1(Collection meter_col, String name) {
    meter m_meter = null;
    meter ret_meter = null;
    if(meter_col!=null && name!=null){
      Iterator it_me = meter_col.iterator();
      while (it_me.hasNext()) {
        m_meter = (meter) it_me.next();
        if (m_meter.getOtherKey1().equalsIgnoreCase(name)) {
          ret_meter = m_meter;
          break;
        }
      }
    }
    return ret_meter;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -