Browse Source

v2.4.4 | 用户退出登陆时, 会初始化所有硬件状态

master
zhaohe 1 month ago
parent
commit
c05f266dd2
  1. 43
      appsrc/appbase/appevent/app_checkpoint_check_fail_event.hpp
  2. 3
      appsrc/appbase/appevent/app_event_type.hpp
  3. 3
      appsrc/appbase/appevent/app_events.hpp
  4. 21
      appsrc/appbase/appevent/app_login_event.hpp
  5. 19
      appsrc/appbase/appevent/app_login_out_event.hpp
  6. 46
      appsrc/service/app_core.cpp
  7. 5
      appsrc/service/app_core.hpp
  8. 12
      appsrc/service/debug_page_test_service.cpp
  9. 22
      appsrc/service/hardware/device_io_ctrl_service.cpp
  10. 8
      appsrc/service/user_mgr_service.cpp
  11. 3
      appsrc/service/user_mgr_service.hpp

43
appsrc/appbase/appevent/app_checkpoint_check_fail_event.hpp

@ -1,43 +0,0 @@
#pragma once
#include "iapp_event.hpp"
namespace iflytop {
typedef enum {
kCheckPointCode_Unknown = 0,
kCheckPointCode_evaporationBinWSTrigger,
kCheckPointCode_deviceBottomWSTrigger,
} CheckPointCode_t;
class CheckPoint {
public:
CheckPointCode_t index;
string name;
bool passed;
int ecode;
string ecodeInfo;
CheckPoint(CheckPointCode_t index, const string& name, bool passed) : index(index), name(name), passed(passed) {}
NLOHMANN_DEFINE_TYPE_INTRUSIVE(CheckPoint, index, ecode, ecodeInfo, name, passed);
};
class AppCheckPointCheckFailEvent : public IAppEvent {
public:
vector<CheckPoint> errCheckPoints;
public:
AppCheckPointCheckFailEvent(vector<CheckPoint> checkpoint) : IAppEvent(AppEventType::AppCheckPointCheckFailEvent) { errCheckPoints = checkpoint; }
virtual ~AppCheckPointCheckFailEvent() {}
// NLOHMANN_DEFINE_TYPE_INTRUSIVE(AppCheckPointCheckFailEvent, errCheckPoints, uuid, type);
virtual json toJson() {
// return json(*this);
json j;
j["uuid"] = uuid;
j["type"] = type;
j["errCheckPoints"] = errCheckPoints;
return j;
}
};
} // namespace iflytop

3
appsrc/appbase/appevent/app_event_type.hpp

@ -9,6 +9,7 @@
marco(type, AppDisinfectionStartEvent) /**/ \ marco(type, AppDisinfectionStartEvent) /**/ \
marco(type, AppPromoptEvent) /**/ \ marco(type, AppPromoptEvent) /**/ \
marco(type, AppWarningPromoptEvent) /**/ \ marco(type, AppWarningPromoptEvent) /**/ \
marco(type, AppCheckPointCheckFailEvent) /**/
marco(type, AppLoginEvent) /**/\
marco(type, AppLoginOutEvent) /**/
ZENUM_DECLAR(AppEventType, AppEventType_LIST); ZENUM_DECLAR(AppEventType, AppEventType_LIST);

3
appsrc/appbase/appevent/app_events.hpp

@ -6,4 +6,5 @@
#include "app_warning_promopt_event.hpp" #include "app_warning_promopt_event.hpp"
#include "iapp_event.hpp" #include "iapp_event.hpp"
#include "app_event_type.hpp" #include "app_event_type.hpp"
#include "app_checkpoint_check_fail_event.hpp"
#include "app_login_event.hpp"
#include "app_login_out_event.hpp"

21
appsrc/appbase/appevent/app_login_event.hpp

@ -0,0 +1,21 @@
#pragma once
#include "iapp_event.hpp"
namespace iflytop {
class AppLoginEvent : public IAppEvent {
private:
string usr;
string role;
public:
AppLoginEvent(string usr, string role) : IAppEvent(AppEventType::AppLoginEvent), usr(usr), role(role) {}
virtual ~AppLoginEvent() {}
string getUsr() const { return usr; }
string getRole() const { return role; }
NLOHMANN_DEFINE_TYPE_INTRUSIVE(AppLoginEvent, uuid, usr, role);
virtual json toJson() { return json(*this); }
};
} // namespace iflytop

19
appsrc/appbase/appevent/app_login_out_event.hpp

@ -0,0 +1,19 @@
#pragma once
#include "iapp_event.hpp"
namespace iflytop {
class AppLoginOutEvent : public IAppEvent {
private:
string usr;
public:
AppLoginOutEvent(string usr) : IAppEvent(AppEventType::AppLoginOutEvent), usr(usr){}
virtual ~AppLoginOutEvent() {}
string getUsr() const { return usr; }
NLOHMANN_DEFINE_TYPE_INTRUSIVE(AppLoginOutEvent, uuid, usr);
virtual json toJson() { return json(*this); }
};
} // namespace iflytop

46
appsrc/service/app_core.cpp

@ -207,12 +207,14 @@ void AppCore::initialize() {
// shared_ptr<IAppEvent> // shared_ptr<IAppEvent>
AppEventBus::ins()->onEvent.connect([this](shared_ptr<IAppEvent> event) { AppEventBus::ins()->onEvent.connect([this](shared_ptr<IAppEvent> event) {
if (dynamic_pointer_cast<AppPromoptEvent>(event) || //
dynamic_pointer_cast<AppCheckPointCheckFailEvent>(event) || //
if (dynamic_pointer_cast<AppPromoptEvent>(event) || //
dynamic_pointer_cast<AppWarningPromoptEvent>(event)) { dynamic_pointer_cast<AppWarningPromoptEvent>(event)) {
insertAppEvent(event); insertAppEvent(event);
return; return;
} }
if (dynamic_pointer_cast<AppLoginOutEvent>(event)) {
initHardwareState();
}
}); });
REG_EXTFN_VOID(getState, void(void)); REG_EXTFN_VOID(getState, void(void));
@ -233,7 +235,34 @@ void AppCore::initialize() {
ThisThread().sleepForMs(1000); ThisThread().sleepForMs(1000);
} }
})); }));
initHardwareState();
}; };
void AppCore::initHardwareState() {
auto deviceIoControlService = GET_SERVICE(DeviceIoControlService);
try {
if (PORT.isDT600B() || PORT.isDT600N() || PORT.isDT300N() || PORT.isDT300W()) {
// CAN_MASTER->clearResetFlag(kFixBoardId_LiquidCtrl);
// CAN_MASTER->clearResetFlag(kFixBoardId_PowerControl);
deviceIoControlService->AddLiquidPump_stop();
deviceIoControlService->SprayPump_stop();
deviceIoControlService->Blower_close();
deviceIoControlService->AC_close();
deviceIoControlService->Heater_close();
deviceIoControlService->WarningLight_setState(0, 0, 0, 0);
if (PORT.isDT300W()) {
deviceIoControlService->PosiPressureProp_setValve(0);
deviceIoControlService->NegaPressureProp_setValve(0);
deviceIoControlService->AirLeakDetectTestModeCtrl_setMode(AirLeakTestMode::disinfection);
}
}
} catch (const appexception& e) {
logger->error("initialize hardware error:{}", e.what());
AppEventBus::ins()->pushWarningPromptEvent(e);
}
}
int AppCore::demofn(int a, int b) { return 0; } int AppCore::demofn(int a, int b) { return 0; }
void AppCore::getState(shared_ptr<MsgProcessContext> cxt) { void AppCore::getState(shared_ptr<MsgProcessContext> cxt) {
@ -248,12 +277,7 @@ void AppCore::appEventConfirm(shared_ptr<MsgProcessContext> cxt, string evenid)
if (dynamic_pointer_cast<AppWarningPromoptEvent>(*it)) { if (dynamic_pointer_cast<AppWarningPromoptEvent>(*it)) {
ADD_USER_BEHAVIOR(DS->getLoginName(), fmt::format("确认警告-{}", dynamic_pointer_cast<AppWarningPromoptEvent>(*it)->getDescription())); ADD_USER_BEHAVIOR(DS->getLoginName(), fmt::format("确认警告-{}", dynamic_pointer_cast<AppWarningPromoptEvent>(*it)->getDescription()));
} }
if (dynamic_pointer_cast<AppCheckPointCheckFailEvent>(*it)) {
vector<CheckPoint> checkPoints = dynamic_pointer_cast<AppCheckPointCheckFailEvent>(*it)->errCheckPoints;
for (auto& cp : checkPoints) {
ADD_USER_BEHAVIOR(DS->getLoginName(), fmt::format("确认警告-{}", cp.ecodeInfo));
}
}
appEventList.erase(it); appEventList.erase(it);
break; break;
} }
@ -272,12 +296,6 @@ void AppCore::insertAppEvent(shared_ptr<IAppEvent> event) {
GET_SERVICE(WarningLightControler)->setwarningFlag(true); GET_SERVICE(WarningLightControler)->setwarningFlag(true);
// ADD_USER_BEHAVIOR(DS->getLoginName(), kbehavior_warning_prompt, dynamic_pointer_cast<AppWarningPromoptEvent>(event)->getDescription()); // ADD_USER_BEHAVIOR(DS->getLoginName(), kbehavior_warning_prompt, dynamic_pointer_cast<AppWarningPromoptEvent>(event)->getDescription());
ADD_USER_BEHAVIOR(DS->getLoginName(), fmt::format("警告-{}", dynamic_pointer_cast<AppWarningPromoptEvent>(event)->getDescription())); ADD_USER_BEHAVIOR(DS->getLoginName(), fmt::format("警告-{}", dynamic_pointer_cast<AppWarningPromoptEvent>(event)->getDescription()));
} else if (dynamic_pointer_cast<AppCheckPointCheckFailEvent>(event)) {
GET_SERVICE(WarningLightControler)->setwarningFlag(true);
vector<CheckPoint> checkPoints = dynamic_pointer_cast<AppCheckPointCheckFailEvent>(event)->errCheckPoints;
for (auto& cp : checkPoints) {
ADD_USER_BEHAVIOR(DS->getLoginName(), fmt::format("警告-{}", cp.ecodeInfo));
}
} }
} }

5
appsrc/service/app_core.hpp

@ -42,8 +42,8 @@ class AppCore : public enable_shared_from_this<AppCore> {
unique_ptr<WorkQueue> wq; unique_ptr<WorkQueue> wq;
list<shared_ptr<IAppEvent>> appEventList; list<shared_ptr<IAppEvent>> appEventList;
recursive_mutex appEventListMutex; recursive_mutex appEventListMutex;
unique_ptr<Thread> stateUpdateThread;
unique_ptr<Thread> stateUpdateThread2;
unique_ptr<Thread> stateUpdateThread;
unique_ptr<Thread> stateUpdateThread2;
public: public:
AppCore() {}; AppCore() {};
@ -60,6 +60,7 @@ class AppCore : public enable_shared_from_this<AppCore> {
void dosystem(string order, bool dump); void dosystem(string order, bool dump);
void loop(); void loop();
int demofn(int a, int b); int demofn(int a, int b);
void initHardwareState();
private: private:
void onDeviceStateChange(); void onDeviceStateChange();

12
appsrc/service/debug_page_test_service.cpp

@ -11,7 +11,6 @@ void DebugPageTestService::initialize() {
REG_EXTFN_VOID(triggerAppWarningPromoptEvent, void(void)); REG_EXTFN_VOID(triggerAppWarningPromoptEvent, void(void));
REG_EXTFN(triggerPromptEvent, void(string), message); REG_EXTFN(triggerPromptEvent, void(string), message);
REG_EXTFN_VOID(triggerAppCheckPointFailEvent, void(void));
REG_EXTFN(test_int, int(json), param0); REG_EXTFN(test_int, int(json), param0);
REG_EXTFN(test_int, int(SettingId), param0); REG_EXTFN(test_int, int(SettingId), param0);
@ -137,16 +136,5 @@ void DebugPageTestService::triggerPromptEvent(shared_ptr<MsgProcessContext> cxt,
AppEventBus::ins()->pushPromoptEvent(message); AppEventBus::ins()->pushPromoptEvent(message);
} }
void DebugPageTestService::triggerAppCheckPointFailEvent(shared_ptr<MsgProcessContext> cxt) { // void DebugPageTestService::triggerAppCheckPointFailEvent(shared_ptr<MsgProcessContext> cxt) { //
vector<CheckPoint> checkPoints;
auto cp1 = CheckPoint(kCheckPointCode_evaporationBinWSTrigger, "蒸发仓内液位检查", true);
auto cp2 = CheckPoint(kCheckPointCode_deviceBottomWSTrigger, "硬件仓液位检测", true);
cp1.ecode = err::kappe_the_evaporation_bin_has_water;
cp1.ecodeInfo = ecode2str(cp1.ecode);
cp2.ecode = err::kappe_the_bottom_of_the_device_has_water;
cp2.ecodeInfo = ecode2str(cp2.ecode);
checkPoints.push_back(cp1);
AppEventBus::ins()->push(make_shared<AppCheckPointCheckFailEvent>(checkPoints));
} }

22
appsrc/service/hardware/device_io_ctrl_service.cpp

@ -95,27 +95,7 @@ void DeviceIoControlService::initialize() {
/** /**
* @brief * @brief
*/ */
try {
if (PORT.isDT600B() || PORT.isDT600N() || PORT.isDT300N() || PORT.isDT300W()) {
// CAN_MASTER->clearResetFlag(kFixBoardId_LiquidCtrl);
// CAN_MASTER->clearResetFlag(kFixBoardId_PowerControl);
AddLiquidPump_stop();
SprayPump_stop();
Blower_close();
AC_close();
Heater_close();
WarningLight_setState(0, 0, 0, 0);
if (PORT.isDT300W()) {
PosiPressureProp_setValve(0);
NegaPressureProp_setValve(0);
AirLeakDetectTestModeCtrl_setMode(AirLeakTestMode::disinfection);
}
}
} catch (const appexception &e) {
logger->error("initialize hardware error:{}", e.what());
AppEventBus::ins()->pushWarningPromptEvent(e);
}
heartThread.reset(new Thread("heartThread", [this]() { heartThread.reset(new Thread("heartThread", [this]() {
while (true) { while (true) {

8
appsrc/service/user_mgr_service.cpp

@ -31,9 +31,12 @@ void UserMgrService::login(shared_ptr<MsgProcessContext> cxt, string name, strin
if (!UserDao::ins()->ispasswdCorrect(name, pwd)) // if (!UserDao::ins()->ispasswdCorrect(name, pwd)) //
THROW_APP_EXCEPTION(err::kappe_passwd_error, ""); THROW_APP_EXCEPTION(err::kappe_passwd_error, "");
m_deviceStateService->setLoginState(name, UserDao::ins()->getUser(name)->roleType);
string roleType = UserDao::ins()->getUser(name)->roleType;
m_deviceStateService->setLoginState(name, roleType);
logger->info("user {} login success", name); logger->info("user {} login success", name);
ADD_USER_BEHAVIOR(name, "登陆"); ADD_USER_BEHAVIOR(name, "登陆");
AppEventBus::ins()->push(make_shared<AppLoginEvent>(name, roleType));
return; return;
} }
void UserMgrService::unlogin(shared_ptr<MsgProcessContext> cxt) { void UserMgrService::unlogin(shared_ptr<MsgProcessContext> cxt) {
@ -41,6 +44,7 @@ void UserMgrService::unlogin(shared_ptr<MsgProcessContext> cxt) {
m_deviceStateService->unlogin(); m_deviceStateService->unlogin();
logger->info("user unlogin success"); logger->info("user unlogin success");
ADD_USER_BEHAVIOR(name, "登出"); ADD_USER_BEHAVIOR(name, "登出");
AppEventBus::ins()->push(make_shared<AppLoginOutEvent>(name));
return; return;
} }
void UserMgrService::chpasswd(shared_ptr<MsgProcessContext> cxt, int id, string newpasswd, string passwd) { auto user = UserDao::ins()->changePasswd(id, newpasswd); } void UserMgrService::chpasswd(shared_ptr<MsgProcessContext> cxt, int id, string newpasswd, string passwd) { auto user = UserDao::ins()->changePasswd(id, newpasswd); }
@ -53,7 +57,7 @@ void UserMgrService::changeUsrRoleType(shared_ptr<MsgProcessContext> cxt, int id
void UserMgrService::addUser(shared_ptr<MsgProcessContext> cxt, string name, string passwd, UsrRoleType roleType) { // void UserMgrService::addUser(shared_ptr<MsgProcessContext> cxt, string name, string passwd, UsrRoleType roleType) { //
if (UserDao::ins()->isUserExist(name)) { if (UserDao::ins()->isUserExist(name)) {
THROW_APP_EXCEPTION(err::kappe_user_exist,"");
THROW_APP_EXCEPTION(err::kappe_user_exist, "");
} }
UserDao::ins()->addUser(name, passwd, roleType); UserDao::ins()->addUser(name, passwd, roleType);

3
appsrc/service/user_mgr_service.hpp

@ -14,7 +14,8 @@ namespace iflytop {
class UserMgrService : public enable_shared_from_this<UserMgrService> { class UserMgrService : public enable_shared_from_this<UserMgrService> {
THISCLASS(UserMgrService); THISCLASS(UserMgrService);
shared_ptr<DeviceStateService> m_deviceStateService;
SERVICE(DeviceStateService, m_deviceStateService);
SERVICE(AppEventBus, appEventBus);
public: public:
UserMgrService() {} UserMgrService() {}

Loading…
Cancel
Save