[ref]同步711

This commit is contained in:
shi_jq 2025-03-13 13:51:33 +08:00
parent 772fc63550
commit 71b4a9cf95
5 changed files with 82 additions and 57 deletions

View File

@ -0,0 +1,24 @@
/**********************************************************************************
* @file ApcIfRdbTableDef.h
* @brief
* @author caodingfa
* @versiong 1.0
* @date 2024-8-1
**********************************************************************************/
#pragma once
namespace iot_app
{
typedef struct _SApcCurveYear
{
int year_rule_id; //年规则ID
int type_id; //类型ID
int month_begin; //开始月
int day_begin; //开始日包含该日即从该日0点起
int month_end; //结束月
int day_end; //结束日包含该日即到下一日0点结束
int excption; //是否例外
}SApcCurveYear,*PSApcCurveYear;
} //< namespace iot_app

View File

@ -97,7 +97,18 @@ bool CApcIfSrv::start(int argc, char *argv[], int & /*nStatus*/)
LOGINFO("\n\n%s is now starting ...\n", g_pSzProcName);
//< 判断是否已启动
if (isAlreadyRunning())
std::string strStartArgs;
for (int i = 1; i < argc; ++i)
{
if (i != 1)
{
strStartArgs += " ";
}
strStartArgs += argv[i];
}
if (isAlreadyRunning(strStartArgs))
{
LOGFATAL("%s 已启动,不可重复启动,本实例退出!", g_pSzProcName);
return false;
@ -158,17 +169,6 @@ bool CApcIfSrv::start(int argc, char *argv[], int & /*nStatus*/)
{
//< 进程管理
{
std::string strStartArgs;
for (int i = 1; i < argc; ++i)
{
if (i != 1)
{
strStartArgs += " ";
}
strStartArgs += argv[i];
}
iot_sys::SProcessInfoKey objProcInfo;
objProcInfo.nAppId = m_nAppID;
objProcInfo.nDomainId = m_nDomainID;
@ -351,9 +351,11 @@ bool CApcIfSrv::addAlarm(iot_idl::SAppAddAlm &objAlarm)
}
bool CApcIfSrv::isAlreadyRunning()
bool CApcIfSrv::isAlreadyRunning(const std::string &strStartArgs)
{
return iot_public::CSingleProcInstance::hasInstanceRunning(g_pSzProcName);
std::string strUniqueName = g_pSzProcName;
strUniqueName += strStartArgs;
return iot_public::CSingleProcInstance::hasInstanceRunning( strUniqueName );
}

View File

@ -75,7 +75,7 @@ public:
private:
CApcIfSrv(); //< 单例
bool isAlreadyRunning();
bool isAlreadyRunning(const std::string &strStartArgs);
bool parseCommandLine(int argc, char *argv[]);

View File

@ -44,6 +44,7 @@
#include "CApcIfSrv.h"
#include "CThreadLocalCurve.h"
#include "ApcIfRdbTableDef.h"
namespace iot_app
{
@ -421,7 +422,6 @@ bool CThreadLocalCurve::getCurveByIndex(const int nIndex, SCurve &stCurve)
return true;
}
bool CThreadLocalCurve::getYearWeekRule(const int nTypeId, CThreadLocalCurve::SYearWeekRule &stRule)
{
//< 查找缓存
@ -440,62 +440,60 @@ bool CThreadLocalCurve::getYearWeekRule(const int nTypeId, CThreadLocalCurve::SY
CThreadLocalCurve::SYearWeekRule &stRuleInCache = m_mapYearWeekRuleCache[nTypeId];
stRule = stRuleInCache;
iot_dbms::CVarType rdbVal;
//< 找 apc_curve_year 表
{
iot_dbms::CRdbQueryResult rdbResult;
std::vector<iot_dbms::CONDINFO> vecCondInfo;
{
iot_dbms::CRdbPublic::addCondInfo
(vecCondInfo, "type_id", nTypeId, ATTRCOND_EQU, ATTRCOND_AND);
//< 开始时间 小于等于 当前
iot_dbms::CRdbPublic::addCondInfo
(vecCondInfo, "month_begin", m_stLocalTimeNow.wMonth, ATTRCOND_SMALLEQU, ATTRCOND_AND);
iot_dbms::CRdbPublic::addCondInfo
(vecCondInfo, "day_begin", m_stLocalTimeNow.wDay, ATTRCOND_SMALLEQU, ATTRCOND_AND);
//< 结束时间 大于等于 当前
iot_dbms::CRdbPublic::addCondInfo
(vecCondInfo, "month_end", m_stLocalTimeNow.wMonth, ATTRCOND_LARGEEQU, ATTRCOND_AND);
iot_dbms::CRdbPublic::addCondInfo
(vecCondInfo, "day_end", m_stLocalTimeNow.wDay, ATTRCOND_LARGEEQU, ATTRCOND_AND);
}
static const std::vector<std::string> vecSelectCol({"year_rule_id", "exctption"});
std::vector<PSApcCurveYear> vecApcCurveYear;
int nLocalCurDay = m_stLocalTimeNow.wMonth* 100 + m_stLocalTimeNow.wDay;
//< 锁表
//因为数量量少,直接全部遍历
iot_dbms::CTableLockGuard tableLock(m_objRtdb_apc_curve_year);
if (!m_objRtdb_apc_curve_year.select(vecCondInfo, rdbResult, vecSelectCol))
int nRowCount = m_objRtdb_apc_curve_year.getRecordCount();
for(int nRowIdx = 0; nRowIdx < nRowCount; nRowIdx++)
{
LOGERROR("getYearWeekRule(): 查询实时库 apc_curve_year 表失败!");
return false;
PSApcCurveYear pRecord = (PSApcCurveYear)m_objRtdb_apc_curve_year.getRecordAddrByIndex(nRowIdx);
if(pRecord->type_id != nTypeId)
{
continue;
}
const int nRowCnt = rdbResult.getRecordCount();
if (nRowCnt != 1)
int nBeginDay = pRecord->month_begin * 100 + pRecord->day_begin;
int nEndDay = pRecord->month_end * 100 + pRecord->day_end;
if(nLocalCurDay >= nBeginDay && nLocalCurDay <= nEndDay)
{
vecApcCurveYear.push_back(pRecord);
}
}
const int nRowCnt = static_cast<int>(vecApcCurveYear.size());
if (nRowCnt != 1 && nRowCnt != 2) //最多只有2条1条正常的1条例外的例外的可以覆盖正常的
{
//< 配置错误
//< 此处写LOG会过于频繁外面写
return false;
}
if (!rdbResult.getColumnValue(0, 0, rdbVal))
int nYearRowIdx = 0; //默认第1行
if(nRowCnt == 2)
{
LOGERROR("getYearWeekRule(): 获取 year_rule_id 值失败!");
return false;
}
stRuleInCache.m_nYearRuleId = rdbVal.toInt();
//2行时判断是不是1条正常1条例外否则配置错误
int nRowExctption1 = vecApcCurveYear[0]->excption;
int nRowExctption2 = vecApcCurveYear[1]->excption;
if (!rdbResult.getColumnValue(0, 1, rdbVal))
if(nRowExctption1 == nRowExctption2)
{
LOGERROR("getYearWeekRule(): 获取 exctption 值失败!");
return false;
return false; //2条不能都是正常或者例外必须2条不一样
}
if (0 != rdbVal.toInt())
if(0 != nRowExctption2)
{
nYearRowIdx = 1;//nYearRowIdx默认=0即第1行2条Exctption不相等并且第2条为例外时则认为第2条为准
}
}
stRuleInCache.m_nYearRuleId = vecApcCurveYear[nYearRowIdx]->year_rule_id;
if (0 != vecApcCurveYear[nYearRowIdx]->excption)
{
//< 今天是例外,不用查询周规则
stRuleInCache.m_nWeekRuleId = -1;
@ -529,6 +527,7 @@ bool CThreadLocalCurve::getYearWeekRule(const int nTypeId, CThreadLocalCurve::SY
return false;
}
iot_dbms::CVarType rdbVal;
if (!(m_objRtdb_apc_curve_week.getColumnValueByIndex(nRecIndex, "week_rule_id", rdbVal)))
{
LOGERROR("getYearWeekRule(): 获取 week_rule_id 值失败!");
@ -545,7 +544,6 @@ bool CThreadLocalCurve::getYearWeekRule(const int nTypeId, CThreadLocalCurve::SY
//return false;
}
int CThreadLocalCurve::getDayRuleId(const char *pSzKeyIdTag, const int nYearRuleId, const int nWeekRuleId)
{
struct STableKey

View File

@ -21,7 +21,8 @@ HEADERS += ApcIfSrvCommon.h \
CApcIfSrv.h \
CThreadAnalog.h \
CThreadDigital.h \
CThreadLocalCurve.h
CThreadLocalCurve.h \
ApcIfRdbTableDef.h
SOURCES += Main.cpp \
ApcIfSrvCommon.cpp \