#pragma once 

#include "db_api/CDBSingletonDefine.h"
#include"module_service/module_mgr.h"

void test_find_path(const point&p1,const point&p2)
{
	printf("\nfind-path:  from=(%.3lf,%.3lf),to=(%.3lf,%.3lf)\n",p1.x,p1.y,p2.x,p2.y);
	std::vector<point> rc=card_path::inst().find_path(p1,p2);
	for(uint32_t i=0;i<rc.size();i++)
		printf("x=%.3lf,y=%.3lf\n",rc[i].x,rc[i].y);
}

struct test_Sa{
    static void test_savedata2db(void * p)
    {
        while(true)
        {
            std::string sql = "CALL add_att_staff(0010000002323, 2323, '2018-12-14 14:00:14', '2018-12-14 14:00:14', 0, 0, 0.000);";
            sDBConnPool.PushAsync(sql.c_str());
            //boost::this_thread::sleep( boost::posix_time::microseconds( 10000 ) );
            usleep(1000*1000);
        }
    }

    static void test_query(void *p)
    {
        std::string sql = "SELECT ve.vehicle_id, ve.card_id, c.card_type_id, \
                            ve.dept_id, ve.group_id, v.vehicle_type_id, vt.vehicle_level_id, \
                            vt.is_railroad AS vt_is_railroad,ve.need_display ,ve.power_alarm,\
                            vt.vehicle_category_id,v.bigger_car_flag,vc.over_speed \
                            FROM dat_vehicle_extend ve \
                            LEFT JOIN dat_vehicle v ON ve.vehicle_id = v.vehicle_id \
                            LEFT JOIN dat_card c ON ve.card_id = c.card_id \
                            LEFT JOIN dat_dept d ON ve.dept_id = d.dept_id \
                            LEFT JOIN dat_group g ON ve.group_id = g.group_id \
                            LEFT JOIN dat_vehicle_type vt ON v.vehicle_type_id = vt.vehicle_type_id \
                            LEFT JOIN dat_vehicle_category vc ON vc.vehicle_category_id = vt.vehicle_category_id \
                            WHERE c.state_id = 0";

        std::string Error;
        YADB::CDBResultSet DBRes;
        while(true)
        {
            if (!sDBConnPool.Query(sql.c_str(),DBRes,Error))
            {
                printf(" Error = %s \n",Error.c_str());
            }
            usleep(10);
        }
    }

    static void Test_JsonDataSend(void * p)
    {
        std::string text = "";
        FILE * pfile = fopen("message_error.json","r");
        if ( NULL != pfile)
        {
            
            char p[10240] = {0};
            while(!feof(pfile))
            {
                memset(p,0,sizeof(p));
                fread(p,1,sizeof(p) - 1,pfile);
                text += std::string(p);
            }
            fclose(pfile); 
        }
        int count = 0;
        while(true)
        {
            swsClientMgr.send(JSON_CMD_VALUE_PUSH,text);
            usleep(1000*1000*2);
            printf("WSClient Send DataLen=%d count=%d \n",(int)text.length(),count++);
        }
    }
};


void test_createthread()
{
    for (int i = 1 ; i < 1 ; i++)
    {
        new  std::thread( std::bind( &test_Sa::Test_JsonDataSend, &i ) );
    }
}