/**
* @file:    $RCSfile: db_interface.h,v $
* @brief:   $IEC 61850 Protocol  
*
* @version: $Revision: 1.12 $
* @date:    $Date: 2019/01/12 08:44:26 $
* @author:  $Author: lizhongming $
* @state:   $State: Exp $
*
* @latest:  $Id: db_interface.h,v 1.12 2019/01/12 08:44:26 lizhongming Exp $
*
*/

#ifndef DB_INTERFACE_7ew2327hyhy0923r_H
#define DB_INTERFACE_7ew2327hyhy0923r_H
 
#include "apr_time.h"

#include <stdbool.h>//lnk20241022

#define  LOG_IDX  (0)
#define  RPT_IDX  (1)

///////////////////////////////////////////////////////////////////////////////
#define INVALID_DEV_IDX					-1

#define STAT_DATA_BASE_NODE_ID			100
#define THREE_SECS_DATA_BASE_NODE_ID	200
#define SOE_COMTRADE_BASE_NODE_ID		300
#define HIS_DATA_BASE_NODE_ID			400
#define NEW_HIS_DATA_BASE_NODE_ID		500
#define RECALL_HIS_DATA_BASE_NODE_ID	600
#define RECALL_ALL_DATA_BASE_NODE_ID	700
#define PQDIF_DATA_BASE_NODE_ID			800

#define REPORT_TYPE_STAT				1
#define REPORT_TYPE_REAL				2
#define REPORT_TYPE_SOE					4
#define REPORT_TYPE_EVENT				8

#define SHOULD_DO_NOTHING				0
#define SHOULD_REGISTER					1
#define SHOULD_UNREGISTER				2
///////////////////////////////////////////////////////////////////////////////

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
//extern	char* OSS_ENDPOINT;
//extern	char* ACCESS_KEY_ID;
//extern	char* ACCESS_KEY_SECRET;
//extern	char* BUCKET_NAME;

extern char* POSTGRES_SCHEMA;
extern char* POSTGRES_TABLEPREFIX;

void GetSM4Code(unsigned char* pSerise,char* pKey,char* output);
void MyGetSM4Code(char* input,unsigned char* szKey,char* output);

int sm4_ecb_decrypt_zeropad_base64(const char* base64_cipher, const char* key_str, char* plaintext_out);//lnk20250728

void try_start_kafka_thread();

void try_start_mqconsumer_thread();//lnk20241216

//0.	json生成开始函数
int json_block_create_start( char voltage_level[],char monid_char[],int flicker_flag, char temcode[],int line_id);
//1.	json生成设置时标函数
int json_block_create_time(char monid_char[], long long Time, int flicker_flag);
//1.5	json生成设置flag函数
int json_block_create_flag(char monid_char[], int flag, int flicker_flag);
//2.	json生成数据回调函数
int json_block_create_data(char monid_char[], char* mms_str , double v, int flicker_flag);
//3.	json生成结束函数
//lnk2024-8-16添加参数
int json_block_create_end(char v_wiring_type[], char monid_char[], int flicker_flag); //CZY 2023-08-17 测试

int json_trace_block_create_start(char voltage_level[], char monid_char[], int flicker_flag, char temcode[], int line_id, char v_wiring_type[], char rpt_id[], int rpt_no);
int json_trace_block_create_time(char monid_char[], long long Time, int flicker_flag, char rpt_id[], int rpt_no);
int json_trace_block_create_flag(char monid_char[], int flag, int flicker_flag, char rpt_id[], int rpt_no);
int json_trace_block_create_data(char monid_char[], char* mms_str, double v, int flicker_flag, char rpt_id[], int rpt_no);
int json_trace_block_create_end(char v_wiring_type[], char monid_char[], int flicker_flag, char rpt_id[], int rpt_no);

//zw 2024-01-31 补招模式优化
void add_mvl_type_ctrl(char doname[], int ctrl);
int sel_mvl_type_ctrl_flag(char doname[]);
void del_mvl_type_ctrl();
//补招模式优化 end

#ifndef DB_INTERFACE_H
#define DB_INTERFACE_H
// 前向声明 LD_info_t
typedef struct LD_info_t LD_info_t;
int	urcbRealDataHasReceived(int dev_index,int rptNo, LD_info_t* LD_info, long long Time); //lnk20241223 20250624
#endif
 
apr_status_t app_get_private_config(const char *myfilename);

void parse_log_switch_ini(unsigned int* error,unsigned int* warn,unsigned int* info);
void init_config();
int GetServerIndexFromDB();
int parse_device_cfg();
int parse_line_cfg();
int parse_rpt_log_ini();
void clear_all_LD_real_soe_report_shoud_register();
void add_comm_log(char* log_str);
void clear_old_comtrade_files();
int process_login_verify();

//////////////////////////////WW 20230819增加数据库操作函数
void TestToken();
void TestBodyPost();//WW 测试qt post
void TestSMSPost();//WW 测试qt post
void TestJson(char* szJson);
//void TestOSS();//WW 测试
//void PutOSS(char* File_Name, char* data); //zw修改 2023-9-7 上送oss文件
//void GetOSS(char* File_Name, char* savepath); //zw修改 2023-9-7 获取oss文件
//void DelOSS(char* File_Name);
void delete_object_new(char* File_Name);
void coutTest();//CZY 2023-09-11 test
//void TestOBS();//WW 20230921 测试华为云服务器
//void OBSFile(char* localpath, char* cloudpath,const char* code);
//void OBSFile_del(char* cloudpath, const char* code);
//void DataHub_Send_Datahub(char* topic, char* data);//datahub通讯
void Nacos_GetParam(char* postgres_uid, char* postgres_pwd, char* web_clientid, char* web_clientsecret);//nacos
void Nacos_GetParam_Ptr(const char* code, char** ptr);
void Read_Nacos_Param_Postgres(char** database_ip, char** database_port, char** postgres_database, char** postgres_username, char** postgres_password, char** postgres_schema, char** postgres_dnsname, char** postgres_tableprefix);
void Read_Nacos_Param_Kafka(char** broker_list, char** topic_stat, char** topic_pst, char** topic_plt, char** topic_event, char** topic_alarm, char** topic_sng, char** protocol, char** mechanisms, char** service_name, char** principal, char** domain_name);
void Read_Nacos_Param_Web(char** client_id, char** client_secret, char** token_url, char** device_url, char** grant_type);
void Read_Nacos_Param_Flag(int*  file_flag, int* send_flag, int* front_inst, char** front_ip);
void Read_Nacos_Param_Recall(int* recall_len, int* recall_sta, int* recall_daily);
void Read_Nacos_Param_Uds(char** uds_upload_url, char** uds_download_url, char** uds_delete_url);//nacos获取uds参数
int  WebAPI_Uds_Upload(char* strUrl, char* loacl_path, char* uuid,char* filename);
void WebAPI_Uds_Download(char* strUrl, char* uuid, char* local_path,char* filename);
int  base64_decode(const char* indata, int inlen, char* outdata, long* outlen);
int  testbase64();
/////////////////////////////WW end

//////////////////////////////WW 20230822增加数据库和WebSocket线程
void try_start_socket_thread(); //启动Web Socket线程
void try_start_ontimer_thread();//启动定时线程s
/////////////////////////////WW end

//lnk20241029增加http线程////////////////////////////////////////
void try_start_web_http_thread(); //启动Webhttp线程
void try_start_http_thread(); //启动http线程
int try_start_mqtest_thread(int argc, char *argv[]); //20241202
void CreateRecallXml();
void DeletcRecallXml();

/*lnk10-11*////////////////////////////////////////////////////////////////////////
void rocketmq_test();
void rocketmq_test_300(int mpnum,int front_index,int type);
void SOEFileWeb_test();
void qvvr_test();
void comflag_test();
int parse_device_cfg_web();
int parse_model_cfg_web();
void SOEFileWeb(char* localpath,char* cloudpath,char* wavepath);
const char* get_front_msg_from_subdir();

char* find_mp_name_from_mp_id(const char* mp_id);


//////////////////////////////////////////////////////////////////////////////////////
typedef struct {
    char WavePhasicFlag[64];
    char WavePhasicA[64];
    char WavePhasicB[64];
    char WavePhasicC[64];
    char UnitOfTimeUnit[64];
    char TypeOfData[64];
    char ValueOfTimeUnit[64];
    char WaveTimeFlag[64];
    char IEDControl[64];
    char IEDname[64];
    char LDevicePrefix[64];
} XmlConfigC;

bool get_xml_config_by_dev_type(const char* dev_type, XmlConfigC* out_cfg);

//////////////////////////////////////////////////////////////////////////////////////文件控制请求参数
typedef struct file_dir_req_t
{
    struct file_dir_req_t *next;
    struct file_dir_req_t *prev;

    char guid[128];
    char frontid[128];
    int  processNo;
    char devid[128];
    int  type;
    char path[256];
    char remote_path[256];

    time_t create_time;
} file_dir_req_t;

#ifdef __cplusplus
}
#endif


#endif //DB_INTERFACE_7ew2327hyhy0923r_H
