📄 huadong.java.svn-base
字号:
package pbs.application.iiop.GUI.huadong;
import java.util.*;
import java.io.*;
import java.net.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import pbs.sessionbean.ejb.*;
import pbs.service.function.*;
import pbs.service.vo.*;
import pbs.service.struct.*;
import pbs.com.enterprisedt.net.ftp.*;
import pbs.application.iiop.GUI.*;
public class huaDong {
static Runtime rt = null;
static workBean wBean1 = null;
static workBean wBean2 = null;
static int primaryAppServer;
static int debugNo = 121;
static int huadongTime;
static huadongData hd = null;
static String HUADONG_DIR_NAME = null;
static String HUADONG_PURSUE_DIR_NAME = null;
static String HUADONG_IP_ADDR = null;
static String HUADONG_DIR_PATH = null;
static String HUADONG_USER_NAME = null;
static String HUADONG_USER_PASSWD = null;
static long HUADONG_TIME = 0;
static CommBuffer CBF = new CommBuffer();
static commonFunc cF = new commonFunc();
static boolean paramChange = true;
static Collection mes = null;
static int task_type = 0;
static CommGui m_CommGui = null;
static final int REPLACED = 1;
public void setParamChange(boolean paramC) {
paramChange = paramC;
}
public huaDong() {
}
public huaDong(CommGui m_commGui) {
m_CommGui = m_commGui;
}
static public int init() {
String noStr = null;
Properties config = new Properties();
commonFunc cf = new commonFunc(debugNo);
int m_debug_no = 121;
rt = Runtime.getRuntime();
try {
config.load(new FileInputStream(Config.CONFIG_FILE_NAME));
HUADONG_DIR_NAME = config.getProperty(Config.HUADONG_DIR_NAME);
HUADONG_PURSUE_DIR_NAME = config.getProperty("HUADONG_PURSUE_DIR_NAME");
HUADONG_IP_ADDR = config.getProperty(Config.HUADONG_IP_ADDR);
HUADONG_DIR_PATH = config.getProperty(Config.HUADONG_DIR_PATH);
HUADONG_USER_NAME = config.getProperty(Config.HUADONG_USER_NAME);
HUADONG_USER_PASSWD = config.getProperty(Config.HUADONG_USER_PASSWD);
if (HUADONG_DIR_NAME == null) {
HUADONG_DIR_NAME = "D:\\opt\\pbs\\huadong\\";
}
if (HUADONG_PURSUE_DIR_NAME == null) {
HUADONG_PURSUE_DIR_NAME = "D:\\opt\\pbs\\huadong\\pursue";
}
if (HUADONG_IP_ADDR == null) {
HUADONG_IP_ADDR = "10.30.21.20";
}
if (HUADONG_DIR_PATH == null) {
HUADONG_DIR_PATH = "/dljf/js/dl";
}
if (HUADONG_USER_NAME == null) {
HUADONG_USER_NAME = "anonymous";
}
if (HUADONG_USER_PASSWD == null) {
HUADONG_USER_PASSWD = "";
}
noStr = config.getProperty(Config.HUADONG_TIME);
if (noStr == null) {
HUADONG_TIME = 1131292800; //2005年11月7号
}
else {
try {
HUADONG_TIME = (Integer.parseInt(noStr));
}
catch (NumberFormatException ex) {
HUADONG_TIME = 1131292800;
}
}
noStr = config.getProperty(Config.DEBUG_NO_OF_HUADONG);
if (noStr == null) {
debugNo = 121;
}
else {
try {
debugNo = (Integer.parseInt(noStr));
}
catch (NumberFormatException ex) {
debugNo = 0;
}
}
noStr = config.getProperty(Config.PRIMARY_APP_SERVER);
if (noStr == null) {
primaryAppServer = 0;
}
else {
try {
primaryAppServer = (Integer.parseInt(noStr));
}
catch (NumberFormatException ex) {
primaryAppServer = 0;
}
}
noStr = config.getProperty(Config.HUADONG_TIME);
if (noStr == null) {
huadongTime = 2;
}
else {
try {
huadongTime = (Integer.parseInt(noStr));
}
catch (NumberFormatException ex) {
huadongTime = 2;
}
}
}
catch (Exception ex) {
debugNo = 121;
huadongTime = 2;
primaryAppServer = 0;
}
wBean1 = new workBean(Constant.SERVER_NO_SERVER1);
wBean2 = new workBean(Constant.SERVER_NO_SERVER2);
return 1;
}
public static void deleteFile(String dirName, long start_time, int debug_no) {
String dayStr = null;
dayStr = getDayString(start_time);
dayStr = dayStr.substring(2, 8);
String filename = "DL" + dayStr + ".dat";
File fe = new File(dirName + filename);
if (!fe.exists()) {
return;
}
else if (fe.exists()) {
fe.delete();
}
}
public static int downFile(String dirName, int debug_no, long start_time,
long last_modified_time) {
String dayStr = null;
dayStr = getDayString(start_time);
dayStr = dayStr.substring(2, 8);
String filename = "DL" + dayStr + ".dat";
processDebug.writeDebug(debug_no, "file = " + filename);
pbs.service.util.Calendar cal2 = pbs.service.util.Calendar.getInstance();
long now_time2 = cal2.getTimeInMillis() / 1000;
String time_str = cF.getTimeStringLine(now_time2);
CommBuffer.m_CommGui.appendString("时间: " + time_str + " 正在下载文件:" + filename +
" ……");
try {
FTPClient fc = new FTPClient(HUADONG_IP_ADDR);
fc.login(HUADONG_USER_NAME, HUADONG_USER_PASSWD);
fc.chdir(HUADONG_DIR_PATH);
fc.get(dirName + filename, filename);
fc.quit();
File fe = new File(dirName + filename);
if (!fe.setLastModified(last_modified_time * 1000)) {
processDebug.writeDebug(debug_no, "setLastModified Error in HUADONG");
return -1;
}
}
catch (IOException ioe) {
CommBuffer.m_CommGui.appendString("时间: " + time_str + " 下载文件:" + filename +
" 失败");
ioe.printStackTrace();
}
catch (FTPException ftpe) {
CommBuffer.m_CommGui.appendString("时间: " + time_str + " 下载文件:" + filename +
" 失败");
ftpe.printStackTrace();
}
return 1;
}
public static Collection getFtpInfo(int m_debug_no) {
Collection allRows = null;
allRows = new ArrayList();
try {
FTPClient fc = new FTPClient(HUADONG_IP_ADDR);
fc.login(HUADONG_USER_NAME, HUADONG_USER_PASSWD);
fc.chdir(HUADONG_DIR_PATH);
String[] files = fc.dir(".", true);
if (files.length == 0) {
processDebug.writeDebug(m_debug_no, "Get ftp info Error in HUADONG");
return null;
}
for (int i = 0; i < files.length; i++) {
allRows.add(files[i]);
}
fc.quit();
}
catch (IOException ioe) {
ioe.printStackTrace();
processDebug.writeDebug(debugNo + 100,
"Error in HUADONG--getFtpInfo,IOException");
System.out.println("Error in HUADONG--getFtpInfo,IOException");
return null;
}
catch (FTPException ftpe) {
ftpe.printStackTrace();
processDebug.writeDebug(debugNo + 100,
"Error in HUADONG--getFtpInfo,FTPException");
System.out.println("Error in HUADONG--getFtpInfo,FTPException");
return null;
}
return allRows;
}
public static String getFileName(long start_time) {
String dayStr = null;
dayStr = getDayString(start_time);
dayStr = dayStr.substring(2, 8);
String filename = "DL" + dayStr + ".dat";
return filename;
}
public static long checkFile(String dirName, int m_debug_no, long start_time,
Collection allRows) {
long modify_time;
long sub_time;
long last_modified_time;
String dayStr = null;
String tmpString = null;
String timeStr1 = null;
String timeStr2 = null;
String ftpStr = null;
Iterator it = null;
long localSize, ftpSize;
dayStr = getDayString(start_time);
dayStr = dayStr.substring(2, 8);
String filename = "DL" + dayStr + ".dat";
File fe = new File(dirName + filename);
if (fe.exists() == false) {
task_type = Constant.TASK_TYPE_ON_TIME; //如果还没有这个文件,算是定时任务
modify_time = 0;
localSize = 0;
}
else {
task_type = Constant.TASK_TYPE_BY_HAND; //已经有这个文件,算是追补
modify_time = ( (fe.lastModified() / 1000) / 60) * 60;
localSize = fe.length();
}
if (allRows == null) {
processDebug.writeDebug(m_debug_no, "check File Error in HUADONG");
return -1;
}
it = allRows.iterator();
while (it.hasNext()) {
String tmpStr = (String) it.next();
StringTokenizer st = new StringTokenizer(tmpStr, " ");
while (st.hasMoreTokens()) {
timeStr1 = st.nextToken();
timeStr2 = st.nextToken();
tmpString = st.nextToken();
ftpStr = tmpString;
tmpString = st.nextToken();
if (tmpString.equalsIgnoreCase(filename)) {
last_modified_time = getTimeStr(timeStr1, timeStr2) / 1000;
ftpSize = Long.parseLong(ftpStr);
if (ftpSize != localSize) {
return last_modified_time;
}
if (modify_time != last_modified_time) {
return last_modified_time;
}
else {
return 0;
}
}
}
}
return 0;
}
//pzy 060719 modi
/*
public static Collection readFile(String dirName, int m_debug_no,
long start_time) {
int ret, voNum, count = 0;
String fileName = null;
BufferedReader br = null;
String readStr = null;
String meName = null;
StringTokenizer st = null;
double values = 0;
int status = 0, type = 0;
int count1 = 0, count2 = 0;
long real_start_time = start_time + Constant.TIME_INTERVAL_QUARTER;
DataValue dv;
String dayStr = null;
dayStr = getDayString(start_time);
dayStr = dayStr.substring(2, 8);
String dataName = "DL" + dayStr + ".dat";
DataValueDetail dvt = null;
pbs.service.util.Calendar cal2 = pbs.service.util.Calendar.getInstance();
long now_time2 = cal2.getTimeInMillis() / 1000;
String time_str = cF.getTimeStringLine(now_time2);
CommBuffer.m_CommGui.appendString("时间: " + time_str + " 正在从: " + dataName +
" 读取数据……");
Collection allRows = new ArrayList();
try {
fileName = dirName + dataName;
FileReader fr = new FileReader(fileName);
br = new BufferedReader(fr);
readStr = br.readLine();
dv = new DataValue();
dv.m_data_type = 0;
while ( (readStr = br.readLine()) != null) {
st = new StringTokenizer(readStr);
while (st.hasMoreTokens()) {
meName = st.nextToken();
}
if (!meName.equalsIgnoreCase("0") && !meName.equalsIgnoreCase("1") &&
!meName.equalsIgnoreCase("2") && !meName.equalsIgnoreCase("3") &&
!meName.equalsIgnoreCase("4") && !meName.equalsIgnoreCase("5")) {
dv = new DataValue();
dv.m_data_type = 0;
dv.m_display_name = meName;
dv.m_values = new ArrayList();
//pzy add 060718
count1 = 0;
//pzy add 060718
}
else {
ret = readString(readStr);
if (ret > 0) {
values += hd.m_data_value;
type = hd.m_data_type;
status |= hd.m_data_status;
count1++;
if (count1 == 15) {
count1 = 0;
count2++;
dvt = new DataValueDetail();
dvt.m_value_type = type;
dvt.m_value = values;
if (status == REPLACED) {
status = Constant.PULSE_STATUS_REPLACE;
}
dvt.m_status = status;
dvt.m_raw_value = values;
dvt.m_occur_time = real_start_time;
if (dvt.m_value_type > dv.m_data_type) {
dv.m_data_type = dvt.m_value_type;
}
dv.m_values.add(dvt);
real_start_time += Constant.TIME_INTERVAL_QUARTER;
values = 0;
status = 0;
if (count2 == 96) { //一天一种类型(15分钟一个点)共96个点
allRows.add(dv);
real_start_time = start_time + Constant.TIME_INTERVAL_QUARTER;
count2 = 0;
}
}
}
}
}
fr.close();
}
catch (Exception ex) {
processDebug.writeDebug(m_debug_no, "impDumpFile in area Error #1");
DataOutputStream dsex = processDebug.getDebugStream(m_debug_no);
ex.printStackTrace(new PrintStream(dsex));
processDebug.closeDebugStream(dsex);
}
return allRows;
}
*/
//pzy 060719 modi
//pzy 060719 modi
public static Collection readFile(String dirName, int m_debug_no,
long start_time) {
int ret, voNum, count = 0;
String fileName = null;
BufferedReader br = null;
String readStr = null;
String meName = null;
StringTokenizer st = null;
double values = 0;
int status = 0, type = 0;
int count1 = 0, count2 = 0;
long real_start_time = start_time + Constant.TIME_INTERVAL_QUARTER;
DataValue dv;
String dayStr = null;
dayStr = getDayString(start_time);
dayStr = dayStr.substring(2, 8);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -