23 changed files with 414 additions and 146 deletions
-
2stm32basic
-
26uappbase/bean/appevent.hpp
-
14uappbase/bean/appevent_type.hpp
-
1uappbase/bean/dbtype/acid_use_record.hpp
-
9uappbase/service/app_event_bus.cpp
-
2uappbase/service/app_event_bus.hpp
-
33uappbase/service/gstate_mgr.cpp
-
39uappbase/service/gstate_mgr.hpp
-
17usrc/db/dao/acid_ch_cfg_dao.cpp
-
18usrc/db/dao/acid_distrubt_record_dao.cpp
-
2usrc/db/dao/acid_distrubt_record_dao.hpp
-
6usrc/db/dao/acid_name_dao.cpp
-
130usrc/db/dao/acid_use_record_dao.cpp
-
7usrc/db/dao/acid_use_record_dao.hpp
-
16usrc/db/dao/device_acid_volume_dao.cpp
-
8usrc/db/dao/device_acid_volume_dao.hpp
-
5usrc/db/dao/device_setting_dao.cpp
-
26usrc/db/dao/user_dao.cpp
-
148usrc/service/statistics_sync_service.cpp
-
16usrc/service/statistics_sync_service.hpp
-
4usrc/uicontroler/page/mupage/MuAcidDistMgrPage.cpp
-
3usrc/uicontroler/page/mupage/muAcidUseMgr_page.cpp
-
28usrc/uicontroler/tjc/tjc_base_type.h
@ -1 +1 @@ |
|||||
Subproject commit d830dc9ba6bbcae328723d94f6b8a0c1829fe850 |
|
||||
|
Subproject commit cba5845768a21a847d3e2b528107f65516399c90 |
@ -0,0 +1,148 @@ |
|||||
|
#include "statistics_sync_service.hpp"
|
||||
|
|
||||
|
#include "db\dao\acid_ch_cfg_dao.hpp"
|
||||
|
#include "db\dao\acid_distrubt_record_dao.hpp"
|
||||
|
#include "db\dao\acid_name_dao.hpp"
|
||||
|
#include "db\dao\acid_use_record_dao.hpp"
|
||||
|
#include "db\dao\device_acid_volume_dao.hpp"
|
||||
|
#include "db\dao\device_setting_dao.hpp"
|
||||
|
#include "db\dao\user_dao.hpp"
|
||||
|
|
||||
|
#define TAG "StatisticsSyncService"
|
||||
|
using namespace iflytop; |
||||
|
static ZThread m_thread; |
||||
|
static osTimerId statiUpdateTimerId; //
|
||||
|
|
||||
|
static bool m_dataIsDirty = false; |
||||
|
static void syncTimer(const void* tid); |
||||
|
|
||||
|
void StatisticsSyncService::initialize() { |
||||
|
m_thread.init("StatiSync"); |
||||
|
AppEventBus::ins()->regOnEvent([](AppEvent* event) { |
||||
|
if (event->type == kAE_LoginEvent) { |
||||
|
onLogin(); |
||||
|
} |
||||
|
|
||||
|
else if (event->type == kAE_AcidStatChangeEvent) { |
||||
|
auto* acidStateChangeEvent = event->getAcidStateChangeEvent(); |
||||
|
if (acidStateChangeEvent->subtype == kACID_STORAGE) { |
||||
|
onAddAcidStorage(acidStateChangeEvent->addCh, acidStateChangeEvent->addChVal); |
||||
|
} else if (acidStateChangeEvent->subtype == kACID_USE) { |
||||
|
onUseAcid(acidStateChangeEvent->useVal[0], acidStateChangeEvent->useVal[1], acidStateChangeEvent->useVal[2], acidStateChangeEvent->useVal[3]); |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
osTimerDef(statiUpdateTimer, syncTimer); |
||||
|
osTimerStart(statiUpdateTimerId, 30 * 1000); |
||||
|
} |
||||
|
|
||||
|
void StatisticsSyncService::onLogin() { |
||||
|
/**
|
||||
|
* @brief |
||||
|
* 1.同步数据库中当前剩余酸液到全局 |
||||
|
* 2.清空全局用户酸液使用量 |
||||
|
*/ |
||||
|
|
||||
|
GStateMgr::ins()->setAcidRemain(0, DeviceAcidVolume::getAcidVolume(0)); |
||||
|
GStateMgr::ins()->setAcidRemain(1, DeviceAcidVolume::getAcidVolume(1)); |
||||
|
GStateMgr::ins()->setAcidRemain(2, DeviceAcidVolume::getAcidVolume(2)); |
||||
|
GStateMgr::ins()->setAcidRemain(3, DeviceAcidVolume::getAcidVolume(3)); |
||||
|
|
||||
|
GStateMgr::ins()->setAcidUsed(0, 0); |
||||
|
GStateMgr::ins()->setAcidUsed(1, 0); |
||||
|
GStateMgr::ins()->setAcidUsed(2, 0); |
||||
|
GStateMgr::ins()->setAcidUsed(3, 0); |
||||
|
|
||||
|
acid_use_record_t record = {0}; |
||||
|
AppHal::rtc_set(&record.date); |
||||
|
record.usrid = GStateMgr::ins()->getUserId(); |
||||
|
record.dirty = 1; |
||||
|
|
||||
|
AcidUseRecordDao::addRecord(record); |
||||
|
AcidUseRecordDao::syncTheLastRecord(); |
||||
|
} |
||||
|
void StatisticsSyncService::doSyncOnUnLoginOrPowerOff() { |
||||
|
/**
|
||||
|
* @brief 切换到事件上下文 |
||||
|
*/ |
||||
|
if (!AppEventBus::ins()->isInAppEventThread()) { |
||||
|
bool callfinished = false; |
||||
|
AppEventBus::ins()->callFnInEventBus([&]() { |
||||
|
doSyncOnUnLoginOrPowerOff(); |
||||
|
callfinished = true; |
||||
|
}); |
||||
|
|
||||
|
while (!callfinished) { |
||||
|
osDelay(30); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
float used0 = GStateMgr::ins()->getAcidUsed(0); |
||||
|
float used1 = GStateMgr::ins()->getAcidUsed(1); |
||||
|
float used2 = GStateMgr::ins()->getAcidUsed(2); |
||||
|
float used3 = GStateMgr::ins()->getAcidUsed(3); |
||||
|
|
||||
|
/**
|
||||
|
* @brief 同步数据库中当前剩余酸液到全局 |
||||
|
*/ |
||||
|
DeviceAcidVolume::updateAcidVolume(0, GStateMgr::ins()->getAcidRemain(0)); |
||||
|
DeviceAcidVolume::updateAcidVolume(1, GStateMgr::ins()->getAcidRemain(1)); |
||||
|
DeviceAcidVolume::updateAcidVolume(2, GStateMgr::ins()->getAcidRemain(2)); |
||||
|
DeviceAcidVolume::updateAcidVolume(3, GStateMgr::ins()->getAcidRemain(3)); |
||||
|
DeviceAcidVolume::sync(); |
||||
|
|
||||
|
// 如果酸液使用量小于0.01,则删除最后一条记录
|
||||
|
if (used0 < 0.01 && used1 < 0.01 && used2 < 0.01 && used3 < 0.01) { |
||||
|
AcidUseRecordDao::removeTheLastDirtyRecordSync(); |
||||
|
} else { |
||||
|
ZLOGI(TAG, "updateLastRecordSync : %f %f %f %f", used0, used1, used2, used3); |
||||
|
AcidUseRecordDao::updateLastRecord(used0, used1, used2, used3); |
||||
|
AcidUseRecordDao::syncTheLastRecord(); |
||||
|
} |
||||
|
|
||||
|
/**
|
||||
|
* @brief 清空全局用户酸液使用量 |
||||
|
*/ |
||||
|
|
||||
|
GStateMgr::ins()->setAcidUsed(0, 0); |
||||
|
GStateMgr::ins()->setAcidUsed(1, 0); |
||||
|
GStateMgr::ins()->setAcidUsed(2, 0); |
||||
|
GStateMgr::ins()->setAcidUsed(3, 0); |
||||
|
m_dataIsDirty = false; |
||||
|
} |
||||
|
|
||||
|
void StatisticsSyncService::onAddAcidStorage(int ch, float addChVal) { |
||||
|
/**
|
||||
|
* @brief 添加酸液 |
||||
|
* |
||||
|
* 1. 修正酸液总量 |
||||
|
* 2. 修正酸液剩余量 |
||||
|
* |
||||
|
*/ |
||||
|
GStateMgr::ins()->setAcidRemain(ch, addChVal); |
||||
|
DeviceAcidVolume::updateAcidVolumeSync(ch, addChVal); |
||||
|
} |
||||
|
void StatisticsSyncService::onUseAcid(float useVal0, float useVal1, float useVal2, float useVal3) { |
||||
|
float now0 = GStateMgr::ins()->getAcidUsed(0); |
||||
|
float now1 = GStateMgr::ins()->getAcidUsed(1); |
||||
|
float now2 = GStateMgr::ins()->getAcidUsed(2); |
||||
|
float now3 = GStateMgr::ins()->getAcidUsed(3); |
||||
|
|
||||
|
GStateMgr::ins()->setAcidUsed(0, now0 + useVal0); |
||||
|
GStateMgr::ins()->setAcidUsed(1, now1 + useVal1); |
||||
|
GStateMgr::ins()->setAcidUsed(2, now2 + useVal2); |
||||
|
GStateMgr::ins()->setAcidUsed(3, now3 + useVal3); |
||||
|
|
||||
|
AcidUseRecordDao::updateLastRecord(now0 + useVal0, now1 + useVal1, now2 + useVal2, now3 + useVal3); |
||||
|
m_dataIsDirty = true; |
||||
|
} |
||||
|
|
||||
|
static void syncTimer(const void* tid) { |
||||
|
AppEventBus::ins()->callFnInEventBus([]() { |
||||
|
if (m_dataIsDirty) { |
||||
|
AcidUseRecordDao::syncTheLastRecord(); |
||||
|
m_dataIsDirty = false; |
||||
|
} |
||||
|
}); |
||||
|
} |
@ -0,0 +1,16 @@ |
|||||
|
#pragma once
|
||||
|
#include "uappbase/base.hpp"
|
||||
|
namespace iflytop { |
||||
|
using namespace std; |
||||
|
class StatisticsSyncService { |
||||
|
public: |
||||
|
static void initialize(); |
||||
|
static void doSyncOnUnLoginOrPowerOff(); |
||||
|
|
||||
|
private: |
||||
|
static void onLogin(); |
||||
|
static void onAddAcidStorage(int ch, float addChVal); |
||||
|
static void onUseAcid(float useVal0, float useVal1, float useVal2, float useVal3); |
||||
|
}; |
||||
|
|
||||
|
} // namespace iflytop
|
@ -1,33 +1,5 @@ |
|||||
#pragma once |
#pragma once |
||||
#include <stdint.h> |
#include <stdint.h> |
||||
|
|
||||
/** |
|
||||
* @brief |
|
||||
* |
|
||||
* 约定 |
|
||||
* 1.用户名最大长度为15 |
|
||||
* 2.组件名称最大长度为14 |
|
||||
* 3.页面名称最大长度为14 |
|
||||
* 4.密码为纯数字6位数密码 |
|
||||
* |
|
||||
* |
|
||||
* 1. 键盘最终不修改页面内容,页面内容由单片机进行修改 |
|
||||
* 2. 每进入一个页面均要发送sendme指令 |
|
||||
* 2. 可用组件 |
|
||||
* 按键 |
|
||||
* 双态按键 |
|
||||
* 键盘 |
|
||||
* 文本输入框(页面一律使用文本输入框) |
|
||||
* 图片 |
|
||||
* 返回按键 |
|
||||
* 下拉框组件 |
|
||||
* |
|
||||
*/ |
|
||||
|
|
||||
|
|
||||
|
|
||||
/*********************************************************************************************************************** |
|
||||
* event * |
|
||||
***********************************************************************************************************************/ |
|
||||
#include "ui_event.h" |
#include "ui_event.h" |
||||
|
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue