4 |
#include <tntdb/result.h> |
#include <tntdb/result.h> |
5 |
#include <tntdb/row.h> |
#include <tntdb/row.h> |
6 |
|
|
|
#include <vector> |
|
|
|
|
|
|
|
|
|
|
|
class CriticalInstallation |
|
|
{ |
|
|
public: |
|
|
CriticalInstallation() {} |
|
|
CriticalInstallation(int i, std::string m) : id(i), message(m) {} |
|
|
int id; |
|
|
std::string message; |
|
|
}; |
|
|
|
|
7 |
</%pre> |
</%pre> |
8 |
|
|
9 |
<%config> |
<%config> |
16 |
|
|
17 |
<{ |
<{ |
18 |
|
|
19 |
|
tntdb::Connection conn = tntdb::connect(dburl); |
20 |
|
|
21 |
|
|
22 |
std::vector<CriticalInstallation> criticals; |
std::string query1; |
23 |
|
query1 += "SELECT c.name, i.description, i.id "; |
24 |
|
query1 += "FROM installation i INNER JOIN customer c "; |
25 |
|
query1 += "ON i.customerid = c.id"; |
26 |
|
|
|
tntdb::Connection conn = tntdb::connect(dburl); |
|
27 |
|
|
28 |
tntdb::Result res = conn.select("SELECT id FROM installation WHERE commerror = true"); |
tntdb::Result inst_res = conn.select(query1); |
29 |
for (int i=0; i<res.size(); ++i) |
|
30 |
|
|
31 |
|
std::string query2; |
32 |
|
query2 += "SELECT commerror,temperature,flamedetector,conveyorerror,powerfailure "; |
33 |
|
query2 += "FROM logtable "; |
34 |
|
query2 += "INNER JOIN installation "; |
35 |
|
query2 += "ON logtable.installationnr = installation.id "; |
36 |
|
query2 += "WHERE installationnr = :v1 "; |
37 |
|
query2 += "ORDER BY messagenr DESC "; |
38 |
|
query2 += "LIMIT 1"; |
39 |
|
|
40 |
|
tntdb::Statement st = conn.prepare(query2); |
41 |
|
|
42 |
|
std::ostream& out = reply.out(); |
43 |
|
|
44 |
|
for (int i=0; i<inst_res.size(); i++) |
45 |
{ |
{ |
46 |
criticals.push_back(CriticalInstallation(res[i].getInt(0), std::string("Communication Error"))); |
int id = inst_res[i].getInt(2); |
47 |
} |
st.clear(); |
48 |
|
|
49 |
|
st.setInt("v1", id); |
50 |
|
tntdb::Result res = st.select(); |
51 |
|
|
52 |
|
if (res.size() > 0) |
53 |
|
{ |
54 |
|
bool commerror = res[0].getBool(0); |
55 |
|
int temperature = res[0].getInt(1); |
56 |
|
bool flameDetector = res[0].getBool(2); |
57 |
|
bool conveyorError = res[0].getBool(3); |
58 |
|
bool powerFailure = res[0].getBool(4); |
59 |
|
|
60 |
|
if (commerror || temperature > 90 || flameDetector == false || conveyorError || powerFailure) |
61 |
|
{ |
62 |
|
out << "<a href='installationdetails?id=" << id << "'><b>" << inst_res[i].getString(0) << "</b> : " << inst_res[i].getString(1) << "<br></a>\n"; |
63 |
|
out << "<ul>"; |
64 |
|
|
65 |
|
if (temperature > 90) |
66 |
|
out << "<li>High temperature</li>\n"; |
67 |
|
|
68 |
|
if (commerror) |
69 |
|
out << "<li>Communication error</li>\n"; |
70 |
|
|
71 |
|
if (flameDetector == false) |
72 |
|
out << "<li>No flames</li>\n"; |
73 |
|
|
74 |
|
if (conveyorError) |
75 |
|
out << "<li>Conveyor error</li>\n"; |
76 |
|
|
77 |
|
if (powerFailure) |
78 |
|
out << "<li>Power failure</li>\n"; |
79 |
|
|
80 |
|
out << "</ul>\n"; |
81 |
|
|
82 |
|
|
83 |
|
} |
84 |
|
} |
85 |
|
} |
86 |
|
|
87 |
}> |
}> |
88 |
|
|