Browse Source

fix some bug

storage-in-realtime
zhaohe 12 months ago
parent
commit
21e9cca9ed
  1. 6
      appsrc/baseservice/db/db_service.cpp
  2. 13
      appsrc/baseservice/front_msg_processer/front_msg_processer.cpp
  3. 7
      appsrc/service/audit_mgr_service.cpp
  4. 2
      appsrc/service/audit_mgr_service.hpp
  5. 4
      appsrc/service/hardware/device_io_ctrl_service.cpp
  6. 1
      appsrc/service/hardware/device_io_ctrl_service.hpp
  7. 11
      appsrc/service/user_mgr_service.cpp
  8. 9
      doc/TODO.md

6
appsrc/baseservice/db/db_service.cpp

@ -73,11 +73,13 @@ void DBService::init_usr_db() {
logger->info("init user db");
auto storage = make_storage(USER_DB_STRUCT);
storage.sync_schema();
auto admin = storage.get_all<User>(where(c(&User::uid) == "admin"));
auto allusr = storage.get_all<User>();
auto admin = storage.get_all<User>(where(c(&User::is_admin) == true));
if (admin.size() == 0) {
storage.insert<User>({-1, "管理员", "9973", true}); // 管理员
}
auto user = storage.get_all<User>(where(c(&User::uid) == "user"));
auto user = storage.get_all<User>(where(c(&User::is_admin) == false));
if (user.size() == 0) {
storage.insert<User>({-1, "用户0", "0000", false}); // 普通用户
}

13
appsrc/baseservice/front_msg_processer/front_msg_processer.cpp

@ -90,22 +90,25 @@ void FrontMsgProcesser::processMsg(shared_ptr<MsgProcessContext> cxt) {
}
if (int(cxt->receipt["ackcode"]) != 0) {
cxt->receipt["message"] = fmt::format("[{}],{}", ecode2str(cxt->receipt["ackcode"]), cxt->ackcodeExtMessage);
cxt->receipt["message"] = fmt::format("[{}]", ecode2str(cxt->receipt["ackcode"]));
cxt->receipt["extMessage"] = fmt::format("{}", cxt->ackcodeExtMessage);
}
if (cxt->rely.empty() == false) {
cxt->receipt["rely"] = cxt->rely;
}
} catch (const appexception& e) {
cxt->receipt["ackcode"] = e.ecode();
cxt->receipt["message"] = fmt::format("[{}],{}", ecode2str(cxt->receipt["ackcode"]), e.description);
cxt->receipt["ackcode"] = e.ecode();
cxt->receipt["message"] = fmt::format("[{}]", ecode2str(cxt->receipt["ackcode"]));
cxt->receipt["extMessage"] = fmt::format("{}", e.description);
}
cxt->receipt["fromClass"] = m_msgProcesserMap[key]->className;
cxt->receipt["fromFn"] = m_msgProcesserMap[key]->fnName;
} else {
logger->error("unknown command: {}", key);
cxt->receipt["ackcode"] = err::kappe_cmd_not_support;
cxt->receipt["message"] = fmt::format("[{}],未找到指令 {}", ecode2str(cxt->receipt["ackcode"]), key);
cxt->receipt["ackcode"] = err::kappe_cmd_not_support;
cxt->receipt["message"] = fmt::format("[{}]", ecode2str(cxt->receipt["ackcode"]));
cxt->receipt["extMessage"] = fmt::format("not find cmd: {}", ecode2str(cxt->receipt["ackcode"]), key);
}
}

7
appsrc/service/audit_mgr_service.cpp

@ -24,7 +24,7 @@ void AuditMgrService::initialize() {
GET_TO_SERVICE(m_udiskMgr);
REG_EXTFN_VOID(exportData, void());
REG_EXTFN_VOID(getRecords, void());
REG_EXTFN(getRecords, void(int,int), page, pageSize);
REG_EXTFN_VOID(pushTestData, void());
}
int AuditMgrService::callExportData() {
@ -84,9 +84,10 @@ void AuditMgrService::exportData(shared_ptr<MsgProcessContext> cxt) {
}
}
void AuditMgrService::getRecords(shared_ptr<MsgProcessContext> cxt) {
void AuditMgrService::getRecords(shared_ptr<MsgProcessContext> cxt, int page, int page_size) {
json& params = cxt->params;
cxt->rely = m_db->getUserBehaviorRecordDescJson(jsonGet<int>(params["page"]), jsonGet<int>(params["page_size"]));
// cxt->rely = m_db->getUserBehaviorRecordDescJson(jsonGet<int>(params["page"]), jsonGet<int>(params["page_size"]));
cxt->rely = m_db->getUserBehaviorRecordDescJson(page, page_size);
}
void AuditMgrService::pushTestData(shared_ptr<MsgProcessContext> cxt) {
ADD_USER_BEHAVIOR("123", kbehavior_login, "");

2
appsrc/service/audit_mgr_service.hpp

@ -22,7 +22,7 @@ class AuditMgrService : public enable_shared_from_this<AuditMgrService> {
private:
void exportData(shared_ptr<MsgProcessContext> cxt);
void getRecords(shared_ptr<MsgProcessContext> cxt);
void getRecords(shared_ptr<MsgProcessContext> cxt, int page, int page_size);
void pushTestData(shared_ptr<MsgProcessContext> cxt);
int callExportData();

4
appsrc/service/hardware/device_io_ctrl_service.cpp

@ -472,8 +472,8 @@ int DeviceIoControlService::AddLiquidPumpPostPS_readPa() { //
#define PROCESS_CMD_WITH_RET(fnName, ...) \
if (testFnName == #fnName) { \
auto ret = fnName(__VA_ARGS__); \
cxt->rely = ret; \
auto ret = fnName(__VA_ARGS__); \
cxt->rely = ret; \
return; \
}

1
appsrc/service/hardware/device_io_ctrl_service.hpp

@ -38,6 +38,7 @@ class DeviceIoControlService : public enable_shared_from_this<DeviceIoControlSer
unique_ptr<WorkQueue> m_workQueue;
shared_ptr<H2O2SensorDataMgr> m_h2o2SensorDataMgr = make_shared<H2O2SensorDataMgr>();
unique_ptr<Thread> heartThread;
public:
void initialize();

11
appsrc/service/user_mgr_service.cpp

@ -27,9 +27,9 @@ void UserMgrService::login(shared_ptr<MsgProcessContext> cxt, string uid, string
}
if (!m_db->isUserExist(uid)) //
THROW_APP_EXCEPTION(err::kappe_user_not_exist, fmt::format("user {} not exist", uid));
THROW_APP_EXCEPTION(err::kappe_user_not_exist, "");
if (!m_db->ispasswdCorrect(uid, pwd)) //
THROW_APP_EXCEPTION(err::kappe_passwd_error, fmt::format("user {} passwd error", uid));
THROW_APP_EXCEPTION(err::kappe_passwd_error, "");
m_deviceStateService->setLoginState(uid, m_db->getUser(uid)->is_admin);
logger->info("user {} login success", uid);
@ -44,7 +44,6 @@ void UserMgrService::unlogin(shared_ptr<MsgProcessContext> cxt) {
return;
}
void UserMgrService::chpasswd(shared_ptr<MsgProcessContext> cxt, string uid, string newpasswd, string passwd) {
if (!m_deviceStateService->isLoginAdmin()) {
APPCHECK(!m_db->ispasswdCorrect(uid, passwd), err::kappe_passwd_error, fmt::format("user {} passwd error", uid));
}
@ -52,9 +51,7 @@ void UserMgrService::chpasswd(shared_ptr<MsgProcessContext> cxt, string uid, str
logger->info("changet passwd {} {}", uid, passwd);
auto user = m_db->changePasswd(uid, newpasswd);
}
void UserMgrService::addUser(shared_ptr<MsgProcessContext> cxt, string uid, string passwd) {
m_db->addUser(uid, passwd);
}
void UserMgrService::addUser(shared_ptr<MsgProcessContext> cxt, string uid, string passwd) { m_db->addUser(uid, passwd); }
void UserMgrService::delUser(shared_ptr<MsgProcessContext> cxt, int id) {
auto user = m_db->delUser(id);
APPCHECK(!user, err::kappe_user_not_exist, fmt::format("user {} not exist", id));
@ -66,7 +63,7 @@ void UserMgrService::updateUserUid(shared_ptr<MsgProcessContext> cxt, int id, st
APPCHECK(!user, err::kappe_user_not_exist, fmt::format("user {} not exist", id));
}
void UserMgrService::getAllUser(shared_ptr<MsgProcessContext> cxt) {
auto users = m_db->getAllUserJson();
auto users = m_db->getAllUserJson();
cxt->receipt["rely"] = users;
return;
}

9
doc/TODO.md

@ -0,0 +1,9 @@
```
1. 添加从机心跳检测程序,超时后自动关闭所有硬件
2. 主机添加复位标志位检测程序
3. 从机添加设备启动上报包。监听从机复位事件
4. 添加关机指令
5. 关闭时间自动更新 (OK)
```
Loading…
Cancel
Save