eis/inc/dao/TeleDAO.h

290 lines
12 KiB
C
Raw Normal View History

/*********************************************************************
*
* : 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