290 lines
12 KiB
C++
290 lines
12 KiB
C++
/*********************************************************************
|
||
*
|
||
* 文 件: TeleDAO.h 声明AutoTele数据访问接口
|
||
*
|
||
* 版权所有: Shanghai Baosight Software Co., Ltd.
|
||
*
|
||
* 概述:
|
||
* :
|
||
* :
|
||
*
|
||
* 版本历史
|
||
* 1.0 2010-09-02 echo_li 增加注释
|
||
*
|
||
*********************************************************************/
|
||
#ifndef TELEDAO_H_
|
||
#define TELEDAO_H_
|
||
#include <iostream>
|
||
#include <string.h>
|
||
#include <string>
|
||
#include <vector>
|
||
#include <math.h>
|
||
#include <log4cplus/LOG.h>
|
||
#include <iDA/iDA.h>
|
||
#ifdef _MSC_VER
|
||
#pragma warning(disable:4250) // disable warning saying "... via dominance ..."
|
||
#pragma warning(disable:4996)
|
||
#pragma warning(disable:4244)
|
||
#endif
|
||
|
||
using namespace std;
|
||
using namespace iPlature;
|
||
using namespace log4cplus;
|
||
|
||
#define MAX_ITEM_COUNT 700 //MAX COUNT OF TELE'S ITEMS
|
||
#define MAX_VALUE_LENGTH 256 //电文项值最大长度
|
||
#define ITEM_LENGTH 40
|
||
#define MAX_TAB_NUMS 5
|
||
#define DEFAULT_COIL "00000000"
|
||
#define NO_TEL_ATT "noITEM"
|
||
|
||
#define PTR_FLAG_1 0
|
||
#define PTR_FLAG_INSERT 1
|
||
#define PTR_FLAG_UPDATE 2
|
||
#define PTR_FLAG_CUS 3
|
||
#define PTR_FLAG_LIMIT 4
|
||
#define PTR_FLAG_NULL_END 5
|
||
#define PTR_FLAG_LEAD_ZEROS 6
|
||
#define PTR_FLAG_TAKE_OVER 7
|
||
#define PTR_FLAG_COL_EMPTY 10
|
||
|
||
|
||
typedef char name_type[ITEM_LENGTH];
|
||
const float FLOAT_FIXED = 0.000001f;
|
||
|
||
//该结构体对应电文的某一项
|
||
class TeleItem{
|
||
friend ostream& operator<<(ostream&out,TeleItem&item)
|
||
{
|
||
out<<item.value;
|
||
return out;
|
||
}
|
||
friend LOG& operator<<(LOG&log,TeleItem&item)
|
||
{
|
||
log<<item.value;
|
||
return log;
|
||
}
|
||
|
||
public:
|
||
|
||
inline TeleItem& operator=(bool value) {this->value[0]=(short)value+'0';return *this;}
|
||
inline TeleItem& operator=(char value) {this->value[0] = value; return *this;}
|
||
inline TeleItem& operator=(const char* value){strcpy(this->value,value); return *this;}
|
||
inline TeleItem& operator=(int value) {sprintf(this->value,"%d",value);return *this;}
|
||
inline TeleItem& operator=(long value) {sprintf(this->value,"%ld",value);return *this;}
|
||
inline TeleItem& operator=(float value) {sprintf(this->value,"%f",value);return *this;}
|
||
|
||
inline bool operator==(bool value) {return (bool)(this->value[0]) == value ? true : false;}
|
||
inline bool operator==(char value) {return this->value[0] == value ? true : false;}
|
||
inline bool operator!=(bool value) {return (bool)(this->value[0]) != value ? true : false;}
|
||
inline bool operator!=(char value) {return this->value[0] != value ? true : false;}
|
||
|
||
inline bool operator==(const char* value){return strncmp(this->value,value,strlen(value)) == 0 ? true : false;}
|
||
inline bool operator==(int value) {return atoi(this->value) == value ? true : false;}
|
||
inline bool operator==(long value) {return atoi(this->value) == value ? true : false;}
|
||
inline bool operator==(float value) {return fabs(atof(this->value) -value) < FLOAT_FIXED ? true : false;}
|
||
|
||
inline bool operator<=(int value) {return atoi(this->value) <= value ? true : false;}
|
||
inline bool operator<=(long value) {return atoi(this->value) <= value ? true : false;}
|
||
inline bool operator<=(float value) {return fabs(atof(this->value) -value) < FLOAT_FIXED || atof(this->value) < value ? true : false;}
|
||
|
||
inline bool operator<(int value) {return atoi(this->value) < value ? true : false;}
|
||
inline bool operator<(long value) {return atoi(this->value) < value ? true : false;}
|
||
inline bool operator<(float value) {return fabs(atof(this->value) -value) > FLOAT_FIXED && atof(this->value) < value ? true : false;}
|
||
|
||
inline bool operator>(int value) {return atoi(this->value) > value ? true : false;}
|
||
inline bool operator>(long value) {return atoi(this->value) > value ? true : false;}
|
||
inline bool operator>(float value) {return fabs(atof(this->value) -value) > FLOAT_FIXED && atof(this->value) < value ? true : false;}
|
||
|
||
inline bool operator>=(int value) {return atoi(this->value) >= value ? true : false;}
|
||
inline bool operator>=(long value) {return atoi(this->value) >= value ? true : false;}
|
||
inline bool operator>=(float value) {return fabs(atof(this->value) -value) < FLOAT_FIXED || atof(this->value) > value ? true : false;}
|
||
|
||
inline operator bool (void) const {return this->value[0];}
|
||
inline operator char (void) const {return this->value[0];}
|
||
inline operator short (void) const {return atoi(this->value);}
|
||
inline operator int (void) const {return atol(this->value);}
|
||
inline operator long (void) const {return atol(this->value);}
|
||
inline operator float (void) const {return atof(this->value);}
|
||
inline operator string(void) const {return string( this->value);}
|
||
inline operator const char* (void) const {return this->value;} //no use
|
||
|
||
|
||
int eventNo; //事件号
|
||
char teleId[10]; // 电文号
|
||
char chinese[100]; //中文名字
|
||
int majNo; // Major Number for sorting
|
||
int minNo; // Minor Number for sorting
|
||
char item[100]; // 电文项
|
||
int length; // 电文项长度
|
||
int offset; // offet within the zone
|
||
char flag[16]; // 处理标记
|
||
int repeat; // max. no of repeating groups
|
||
int logCount;
|
||
int ordCount;
|
||
char type[4]; // 电文项类型,c,d,n
|
||
char defaultValue[10]; // 电文项默认值
|
||
float factor; // 电文项单位系数
|
||
name_type tables[MAX_TAB_NUMS]; // 目标表名
|
||
name_type columns[MAX_TAB_NUMS]; // 目标字段名
|
||
char limitDB[30]; // 极限值检查名字,来自 PlantLimits ( for messages L3 -> L2)
|
||
char limitMin[20]; // 极限值下限( for messages L3 -> L2)
|
||
char limitMax[20]; // 极限值上限( for messages L3 -> L2)
|
||
char value[MAX_VALUE_LENGTH]; // 电文项的值,比如length的内容是12345,
|
||
char check[6]; //检查标记是否通过 0 ok, 1 NG
|
||
char addr[50];
|
||
char fdaaItem[100]; //fdaa数据项名称
|
||
char unit[10]; //单位
|
||
|
||
};
|
||
|
||
//该结构体对应电文的常量参数
|
||
struct TeleConf{
|
||
int eventNo;
|
||
string teleId;
|
||
string description ; //电文描述
|
||
int lineNo;
|
||
int header;
|
||
int headerLength;//电文头部长度
|
||
int totalLength;//电文全部长度
|
||
};
|
||
namespace baosight
|
||
{
|
||
//接口函数
|
||
|
||
/*********************************************************************
|
||
* 类 名: //TODO请补充类名称
|
||
* 版权所有: Shanghai Baosight Software Co., Ltd.
|
||
* 类 职 责:
|
||
* :
|
||
* :
|
||
* 版本历史
|
||
* 1.0 2010-09-02 echo_li 增加注释
|
||
*
|
||
*********************************************************************/
|
||
class TeleDAO
|
||
{
|
||
public:
|
||
/**********************************************************************
|
||
* 概述: 获取数据库原始电文结构
|
||
* 函数名: GetDefine
|
||
* 返回值: int
|
||
* 参数列表: 参数类型 取值范围 描述
|
||
* eventNo: int
|
||
* itemvect: vector<TeleItem*>&
|
||
*
|
||
* 版本历史
|
||
* 1.0 2010-09-02 echo_li 增加注释
|
||
*
|
||
**********************************************************************/
|
||
virtual int GetDefineGroup(int eventNo,vector<TeleItem*>& itemvect,const string& table = "T_LOV_TELEITEM");
|
||
|
||
/**********************************************************************
|
||
* 概述: 获取展开电文结构
|
||
* 函数名: GetDefineUnGroup
|
||
* 返回值: int
|
||
* 参数列表: 参数类型 取值范围 描述
|
||
* eventNo: int
|
||
* vector<TeleItem*>: itemvect
|
||
*
|
||
* 版本历史
|
||
* 1.0 2010-09-02 echo_li 增加注释
|
||
*
|
||
**********************************************************************/
|
||
virtual int GetDefineUnGroup( int eventNo, vector<TeleItem*>& itemvect,const string& table = "T_LOV_TELEITEM");
|
||
|
||
|
||
/**********************************************************************
|
||
* 概述: 读表方式获取电文数据
|
||
* 函数名: ReadDB
|
||
* 返回值: int
|
||
* 参数列表: 参数类型 取值范围 描述
|
||
* eventNo: int
|
||
* teleItem: TeleItem *
|
||
*
|
||
* 版本历史
|
||
* 1.0 2010-09-02 echo_li 增加注释
|
||
*
|
||
**********************************************************************/
|
||
virtual int ReadDB(const string& sql,vector<int>& readindex,vector<TeleItem*>& itemvect);
|
||
|
||
/**********************************************************************
|
||
* 概述: 获取电文定义
|
||
* 函数名: GetTeleInfo
|
||
* 返回值: short
|
||
* 参数列表: 参数类型 取值范围 描述
|
||
* eventNo: int
|
||
* info: TeleConf &
|
||
*
|
||
* 版本历史
|
||
* 1.0 2010-09-02 echo_li 增加注释
|
||
*
|
||
**********************************************************************/
|
||
short GetTeleConf(int eventNo,TeleConf& info);
|
||
/**********************************************************************
|
||
* 概述: 写接收的电文
|
||
* 函数名: PutRcvTeleToDB
|
||
* 返回值: short
|
||
* 参数列表: 参数类型 取值范围 描述
|
||
* eventNo: int
|
||
* teleId: const char *
|
||
* coilId: const char *
|
||
* seq: const char *
|
||
* length: int
|
||
* sender: string
|
||
*
|
||
* 版本历史
|
||
* 1.0 2010-09-02 echo_li 增加注释
|
||
*
|
||
**********************************************************************/
|
||
virtual short PutRcvTeleToDB(int eventNo,const char* teleId,const char* coilId,const char* seq,int length,string sender);
|
||
/**********************************************************************
|
||
* 概述: 写发送的电文
|
||
* 函数名: PutSndTeleToDB
|
||
* 返回值: short
|
||
* 参数列表: 参数类型 取值范围 描述
|
||
* eventNo: int
|
||
* teleId: const char *
|
||
* coilId: const char *
|
||
* seq: const char *
|
||
* length: int
|
||
*
|
||
* 版本历史
|
||
* 1.0 2010-09-02 echo_li 增加注释
|
||
*
|
||
**********************************************************************/
|
||
virtual short PutSndTeleToDB(int eventNo,const char* teleId,const char* coilId,const char* seq,int length);
|
||
|
||
//rmbai 2012-03-26 check enum item by destColumn of the destTable
|
||
virtual short CheckEnumValue( const string &value,const string &destTable, const string &destColumnName);
|
||
|
||
protected:
|
||
|
||
/**********************************************************************
|
||
* 概述: 展开原始电文结构中的重复项
|
||
* 函数名: BuildInRepGroups
|
||
* 返回值: int
|
||
* 参数列表: 参数类型 取值范围 描述
|
||
* eventNo: int
|
||
* vector<TeleItem*>: ingroupvect 输入未展开的电文结构
|
||
* vector<TeleItem*>: outgroupvect 输出展开后的电文结构
|
||
*
|
||
* 版本历史
|
||
* 1.0 2010-09-02 echo_li 增加注释
|
||
*
|
||
**********************************************************************/
|
||
int BuildInRepGroups(int maxItem, vector<TeleItem*>& groupvect, vector<TeleItem*>& ungroupvect);
|
||
|
||
void InitMember();
|
||
|
||
private:
|
||
iDA::Command cmd;
|
||
char* mp_dbMessage;
|
||
char m_dbWhere[200];
|
||
char m_dbOrder[100];
|
||
};
|
||
|
||
};
|
||
#endif
|
||
|