unknown
2025-09-10 a4fc45393e242f15517f9347f95e55c77887b332
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include "stdafx.h"
#include "Respond.h"
#include "MySQLDB.h"
 
#include <iostream>
#include <time.h>
 
using namespace std;
 
Respond::Respond()
{
}
 
 
Respond::~Respond()
{
}
 
//¸¨Öúº¯Êý
bool Respond::business_login(LoginReq * req, SOCKET client)
{
    cout << "µÇ¼ÇëÇóÒµÎñµÄ´¦Àí..." << endl;
    // µÇ¼ÏìÓ¦
 
    // Ç°ÖõĴ¦Àí£ºÏÈÑéÖ¤Ò»ÏÂÊý¾ÝµÄ׼ȷÐÔ£¬Ñé֤ͨ¹ý£¬ÔÙÍùÏÂÒ»²½
 
    // µÚÒ»²½£ºÏȰÑÇëÇóµÄÊý¾ÝÄóöÀ´£¬×é×°Ò»ÏÂSQLÓï¾ä¡¾±ê×¼¸ñʽ¡¿
    char sql[512] = { 0 };
 
    //½«¸ñʽ»¯Êý¾ÝдÈëÒ»¸ö×Ö·û´®»º³åÇø
    sprintf_s(sql, "select id,user_name,status,admin,history,log_search,map_change,attend_manage,device_manage,version_manage,notify_manage,image_input,monitor_back from user_info a,role_info b where a.user_name ='%s' and a.password = '%s' and a.role_id = b.id;", req->user_name,req->password);
 
    //ʵÀý»¯Ò»¸ö¶ÔÏó
    MySQLDB my_DB;
 
    //·µ»Ø½á¹ûµÄ¡°Êý¾Ý½áºÏÌ塱
    vector<vector<string>> result;
    size_t rows = my_DB.execSQL(sql, result);
    cout << "rows:" << rows << endl;
    //Ò»¸öµÇ¼ÏìÓ¦½á¹¹Ì壬¸ù¾Ýresult,Ìî³ä½á¹¹Ì壬·¢ËÍ
    LoginRes res;
 
    //³õÖµ
    res.per = { 0 };
 
    
    if (rows > 0)//´ú±íÓÐÊý¾Ý¼¯
    {
        //È¡µÃÓû§ID
        res.emp_id               = stoi(result[0][0]);
        strcpy_s(res.user_name, result[0][1].c_str());
        //½«resultÊý×éÖеÚ0ÐеÚ2ÁÐλÖõÄ×Ö·û´®ÄÚÈÝת»»ÎªÕûÊý
        res.status               = stoi(result[0][2]);
        //ȨÏÞ¸³Öµ
        res.per.admin            = stoi(result[0][3]);
        res.per.admin          = stoi(result[0][4]);
        res.per.log_search     = stoi(result[0][5]);
        res.per.map_change     = stoi(result[0][6]);
        res.per.attend_manage  = stoi(result[0][7]);
        res.per.device_manage  = stoi(result[0][8]);
        res.per.version_manage = stoi(result[0][9]);
        res.per.notify_manage  = stoi(result[0][10]);
        res.per.image_input    = stoi(result[0][11]);
        res.per.monitor_back   = stoi(result[0][12]);
    }
    else 
    {
        //ûÓÐÊý¾Ý¼¯
        strcpy_s(res.user_name, "");
 
        res.status = 0;
        res.emp_id = 0;
    }
 
    int send_len = 0;
    //·¢Ë͵ǼÏìÓ¦°ü
    send_len = send(client, (char *)&res, res.head.len, 0);
    
    cout << "send len :" << send_len << endl;
    cout << "·¢Ë͵ǼÏìÓ¦°ü£¬µÇ¼ҵÎñ´¦ÀíÍê³É£¡" << endl;
 
//test
    cout << "user_status :" << res.status << endl;
    cout << "some part user_power :" << res.per.admin << res.per.admin << res.per.image_input << endl;
 
    return false;
}
 
bool Respond::business_register(RegisterReq * req, SOCKET client)
{
    //ÏÈÓÃÒ»¸öcharÊý×飬°Ñ·ÃÎÊÊý¾Ý¿âµÄÓï¾ä×¼±¸ºÃ
    char sql[512] = { 0 };
 
    /*
        ¾­¹ýЭÉÌ£¬¿Í»§¶ËQt½çÃæ¡¤Óû§ÐÅÏ¢µÄ½á¹¹Ìå
        
        struct User {
            QString username;        //ok
            QString password;        //ok
            QString email;            //ok
            QString phone;            //ok
            QString department;        //ok
            QString permission;        //default¡¾×¢²áĬÈÏÖ»ÓÐ×î»ù±¾µÄȨÏÞ¡¿
            QString status;            //default¡¾×¢²áĬÈÏ״̬1¡¿
            QDate registerDate;        //default¡¾×¢²áĬÈϵ±Ç°Ê±¼ä¡¿
        };
    */
 
    // »ñÈ¡µ±Ç°Ê±¼ä²¢¸ñʽ»¯Îª×Ö·û´®
    char current_time[20];
    time_t now = time(NULL);
    struct tm tm_info;  // ¸ÄΪջ±äÁ¿¶ø²»ÊÇÖ¸Õë
 
    // Ê¹Óð²È«µÄ localtime_s Ìæ´ú localtime
    errno_t err = localtime_s(&tm_info, &now);
    if (err == 0) {
        strftime(current_time, sizeof(current_time), "%Y-%m-%d %H:%M:%S", &tm_info);
    }
    else {
        // ´íÎó´¦Àí
        strcpy_s(current_time, sizeof(current_time), "1970-01-01 00:00:00");
    }
    cout << "µ±Ç°²Ù×÷ʱ¼ä£º" << current_time;
 
    //¸ñʽ»¯ÊäÈëµ½×Ö·û´®¡¾Äѵ㣬дÈëÊý¾Ý¿âµÄÁ÷³Ì¡¿
    sprintf_s(sql, "INSERT INTO user_info (user_name, password, tel, email, department, status, register_time, role_id) VALUES('%s', '%s', '%s', '%s', '%s', 1, '%s', 2);", req->user_name, req->password, req->telephone, req->email, req->department,current_time);
 
    //ʵÀý»¯Ò»¸ö¶ÔÏó
    MySQLDB my_DB;
 
    //·¢ËÍ×¢²áÏìÓ¦°ü
    RegisterRes res;
 
    //Êý¾Ý¿â·â×°µÄ²åÈ뺯Êý
    uint64_t user_id = 0;
    user_id = my_DB.exec_insSQL(sql, res.res_info);
 
    //Ìî³äÏìÓ¦½á¹¹Ìå
    strcpy_s(res.user_name, req->user_name);
    res.per = { 0 };
    res.emp_id = user_id;//¿ÉÒÔͨ¹ý¼ì²éid£¬ÅжÏÊÇ·ñ³É¹¦×¢²á
    res.status = 1;
 
 
    /*
        ÐèÒª¼ÓÃÜ
    */
 
 
    int send_len = 0;
    //·¢ËÍ×¢²áÏìÓ¦°ü
    send_len = send(client, (char *)&res, res.head.len, 0);
 
    cout << "send len :" << send_len << endl;
    cout << "·¢ËÍ×¢²áÏìÓ¦°ü£¬×¢²áÒµÎñ´¦ÀíÍê³É£¡" << endl;
 
    //test
    cout << "user_status :" << res.status << endl;
    cout << "some part user_power :" << res.per.admin << res.per.admin << res.per.image_input << endl;
    cout << "user_info :" << res.status << endl;
    cout << "Óû§Ãû£º" << res.user_name << " ¹¤ºÅ£º" << res.emp_id << " ×´Ì¬£º" << res.status << endl;
    cout << "´íÎóÐÅÏ¢£º[" << res.res_info << "/]" << endl;
 
    return false;
}