2026-05-09 11:23:45 +08:00
|
|
|
#include <eqpalg/table_struct/t_eqp_data.h>
|
|
|
|
|
#include <eqpalg/utility/eqp_status.h>
|
|
|
|
|
#include <mix_cc/sql.h>
|
|
|
|
|
#include <mix_cc/sql/database/db2_t.h>
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
#include <vector>
|
|
|
|
|
namespace {
|
2026-05-09 13:30:09 +08:00
|
|
|
std::unordered_map<std::string, bool> eqp_status;
|
|
|
|
|
std::unordered_map<std::string, std::string> eqpid2item;
|
|
|
|
|
std::vector<std::string> eqp_ids;
|
|
|
|
|
}
|
2026-05-09 11:23:45 +08:00
|
|
|
|
|
|
|
|
EqpStatus::EqpStatus() {
|
|
|
|
|
logger_ = std::make_unique<LOG>("EqpStatus");
|
|
|
|
|
const auto prefix = string(CMemVar::Const()->UnitNo) + "_";
|
|
|
|
|
for (int i = CMemVar::Const()->event_eis_start;
|
|
|
|
|
i <= CMemVar::Const()->event_eis_end; i++) {
|
|
|
|
|
if (i != 2012) {
|
|
|
|
|
binary_tele.ReBuild(i);
|
|
|
|
|
const auto size = binary_tele.size();
|
|
|
|
|
for (int j = 0; j < size; j++) {
|
|
|
|
|
string flag = binary_tele[j].flag;
|
|
|
|
|
if (flag[1] == 'E') {
|
|
|
|
|
string eqp_id = binary_tele[j].tables[0];
|
|
|
|
|
std::string name_without_plant_code = binary_tele[j].item;
|
|
|
|
|
eqpid2item[eqp_id] = prefix + name_without_plant_code;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
logger_->Debug() << "eqpid2item size:" << eqpid2item.size() << endl;
|
|
|
|
|
select_eqp_data();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EqpStatus::~EqpStatus() {
|
|
|
|
|
logger_->Debug() << "EqpStatus::~EqpStatus()" << endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int EqpStatus::update_status() {
|
|
|
|
|
int res = 0;
|
|
|
|
|
try {
|
|
|
|
|
for (int i = 0; i < eqp_ids.size(); i++) {
|
|
|
|
|
if (eqpid2item.find(eqp_ids[i]) != eqpid2item.end()) {
|
|
|
|
|
eqp_status[eqp_ids[i]] = SingletonTemplate<
|
|
|
|
|
GlobaltemSharedMemory>::GetInstance()[eqpid2item[eqp_ids[i]]];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
eqp_status[eqp_ids[i]] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (const std::exception& e) {
|
|
|
|
|
logger_->Error() << "EqpStatus::update_status()," << e.what() << endl;
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int EqpStatus::select_eqp_data() {
|
|
|
|
|
T_EQP_DATA ted;
|
|
|
|
|
auto sql_statement = select(ted.eqpId()).from(ted);
|
|
|
|
|
auto sample_list_maybe = exec<db2_t, T_EQP_DATA>(sql_statement);
|
|
|
|
|
if (sample_list_maybe.is_just()) {
|
|
|
|
|
auto sample_list = sample_list_maybe.unsafe_get_just();
|
|
|
|
|
if (sample_list.empty()) {
|
|
|
|
|
logger_->Debug() << "T_EQP_DATA 无数据!" << std::endl;
|
|
|
|
|
return -2;
|
|
|
|
|
} else {
|
|
|
|
|
size_t eqp_size = sample_list.size();
|
|
|
|
|
eqp_ids.clear();
|
|
|
|
|
for (int i = 0; i < eqp_size; i++) {
|
|
|
|
|
eqp_ids.push_back(sample_list[i].eqpId);
|
|
|
|
|
}
|
|
|
|
|
logger_->Debug() << "T_EQP_DATA,eqp_size:" << eqp_size << endl;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
logger_->Error() << "EqpStatus::select_eqp_data()查询失败!" << std::endl;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string EqpStatus::get_data_json() {
|
|
|
|
|
update_status();
|
|
|
|
|
mix_cc::json js1;
|
|
|
|
|
try {
|
|
|
|
|
if (!eqp_status.empty()) {
|
|
|
|
|
js1 = eqp_status;
|
|
|
|
|
return js1.dump();
|
|
|
|
|
} else {
|
|
|
|
|
return "empty";
|
|
|
|
|
}
|
|
|
|
|
} catch (std::exception& e) {
|
|
|
|
|
return "ERROR";
|
|
|
|
|
}
|
|
|
|
|
}
|