133 lines
4.5 KiB
C++
133 lines
4.5 KiB
C++
|
|
#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 {
|
|||
|
|
std::unordered_map<std::string, bool> eqp_status; ///<设备id,运行状态
|
|||
|
|
std::unordered_map<std::string, std::string> eqpid2item; ///<设备id,item
|
|||
|
|
// std::unordered_map<std::string, std::vector<std::string> >
|
|||
|
|
// eqpid2items_or; ///<设备id,items 或
|
|||
|
|
std::vector<std::string> eqp_ids; ///<设备编号
|
|||
|
|
} // namespace
|
|||
|
|
|
|||
|
|
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;
|
|||
|
|
// logger_->Debug() << "item:" << binary_tele[j].item
|
|||
|
|
// << ",flag:" << binary_tele[j].flag << endl;
|
|||
|
|
if (flag[1] == 'E') {
|
|||
|
|
string eqp_id = binary_tele[j].tables[0];
|
|||
|
|
// string epq_id2 = binary_tele[j].tables[1];
|
|||
|
|
std::string name_without_plant_code = binary_tele[j].item;
|
|||
|
|
eqpid2item[eqp_id] = prefix + name_without_plant_code;
|
|||
|
|
// if (!epq_id2.empty()) {
|
|||
|
|
// logger_->Debug() << "epq_id:" << eqp_id << ",eqp_id2:" << eqp_id2
|
|||
|
|
// << ",item:" << name_without_plant_code << endl;
|
|||
|
|
// eqpid2items_or[eqp_id2].push_back(prefix +
|
|||
|
|
// name_without_plant_code);
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// logger_->Debug() << "eqp_id:" << eqp_id
|
|||
|
|
// << ",item:" << name_without_plant_code << endl;
|
|||
|
|
}
|
|||
|
|
// else if (flag[1] == 'D') {
|
|||
|
|
// string eqp_id = binary_tele[j].tables[0];
|
|||
|
|
// std::string name_without_plant_code = binary_tele[j].item;
|
|||
|
|
// eqpid2items_or[eqp_id].push_back(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]]];
|
|||
|
|
// logger_->Debug()
|
|||
|
|
// << "epqid:" << eqp_ids[i] << ",item:" << eqpid2item[eqp_ids[i]]
|
|||
|
|
// << ",data:"
|
|||
|
|
// << SingletonTemplate<
|
|||
|
|
// GlobaltemSharedMemory>::GetInstance()[eqpid2item[eqp_ids[i]]]
|
|||
|
|
// << endl;
|
|||
|
|
}
|
|||
|
|
// else if (eqpid2items_or.find(eqp_ids[i]) != eqpid2items_or.end()) {
|
|||
|
|
// if (!eqpid2items_or[eqp_ids[i]].empty()) {
|
|||
|
|
// eqp_status[eqp_ids[i]] = false;
|
|||
|
|
// for (auto items : eqpid2items_or[eqp_ids[i]]) {
|
|||
|
|
// eqp_status[eqp_ids[i]] =
|
|||
|
|
// eqp_status[eqp_ids[i]] ||
|
|||
|
|
// SingletonTemplate<GlobaltemSharedMemory>::GetInstance()[items];
|
|||
|
|
// }
|
|||
|
|
// } else {
|
|||
|
|
// eqp_status[eqp_ids[i]] = true;
|
|||
|
|
// }
|
|||
|
|
|
|||
|
|
// }
|
|||
|
|
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";
|
|||
|
|
}
|
|||
|
|
}
|