|
@@ -34,6 +34,9 @@
|
|
|
#else
|
|
|
#include "sp_dbg_export.h"
|
|
|
#endif //_WIN32
|
|
|
+#include "sp_httpDefine.h"
|
|
|
+#include <iostream>
|
|
|
+#include <sstream>
|
|
|
|
|
|
static void var_callback(sp_var_listener_t *listener,
|
|
|
const char *key,
|
|
@@ -2041,6 +2044,130 @@ ErrorCodeEnum SpEntity::GetRunningVersion(CSimpleString& ver)
|
|
|
return (ErrorCodeEnum)ret;
|
|
|
}
|
|
|
|
|
|
+struct ErrMsgStruct {
|
|
|
+ std::string VTMCode;
|
|
|
+ std::string errMsg;
|
|
|
+
|
|
|
+ // 带参数的构造函数,参数有默认值
|
|
|
+ ErrMsgStruct(const std::string& tmp_VTMCode = "", const std::string& tmp_errMsg = "") : VTMCode(tmp_VTMCode), errMsg(tmp_errMsg) {}
|
|
|
+};
|
|
|
+
|
|
|
+ErrorCodeEnum SpEntity::GetVTMErrMsg(DWORD dwUserCode, CSimpleStringA& strDescription, CSimpleStringA& strVTMCode)
|
|
|
+{
|
|
|
+ sp_env_t* env = sp_get_env();
|
|
|
+ if (env->cfg->root_ini->vtm_err_msg_config == NULL || strlen(env->cfg->root_ini->vtm_err_msg_config) == 0)
|
|
|
+ {
|
|
|
+ strVTMCode = "RTA42F0";
|
|
|
+ strDescription = "微服务异常";
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode(strVTMCode)("GetVTMErrMsg vtm_err_msg_config is null, may have not sync from server or sync failed");
|
|
|
+ return ErrorCodeEnum::Error_NotConfig;
|
|
|
+ }
|
|
|
+
|
|
|
+ std::string userCodeStr = CSimpleString::Format("0x%X", dwUserCode).GetData();
|
|
|
+ std::transform(userCodeStr.begin(), userCodeStr.end(), userCodeStr.begin(), [](unsigned char c) { return std::tolower(c); });
|
|
|
+
|
|
|
+ static std::map<std::string, ErrMsgStruct> m_UserCodeToMsgTip;
|
|
|
+ static bool isInit = false;
|
|
|
+ if (!isInit)//Some entities may have no UserCode
|
|
|
+ {
|
|
|
+ CAutoArray<CSimpleStringA> strErrorCodeArr;
|
|
|
+ CAutoArray<CSimpleStringA> strDescriptionArr;
|
|
|
+ CAutoArray<CSimpleStringA> strRemarkArr;
|
|
|
+ ConvertStrToVTMErrMsg(env->cfg->root_ini->vtm_err_msg_config, strErrorCodeArr, strDescriptionArr, strRemarkArr);
|
|
|
+
|
|
|
+ auto intToHex = [](int num) -> std::string {
|
|
|
+ const char hexChars[] = "0123456789ABCDEF";
|
|
|
+ std::string hexStr;
|
|
|
+
|
|
|
+ // 将整数的每个字节转换为对应的16进制字符
|
|
|
+ for (int i = sizeof(num) - 1; i >= 0; --i) {
|
|
|
+ unsigned char byte = (num >> (8 * i)) & 0xFF;
|
|
|
+ if (byte == 0 && hexStr.empty()) {
|
|
|
+ continue; // 跳过前导零
|
|
|
+ }
|
|
|
+ hexStr += hexChars[byte >> 4];
|
|
|
+ hexStr += hexChars[byte & 0x0F];
|
|
|
+ }
|
|
|
+
|
|
|
+ return hexStr;
|
|
|
+ };
|
|
|
+
|
|
|
+ auto hexToInt = [](const std::string& hexStr)-> int {
|
|
|
+ std::stringstream ss;
|
|
|
+ ss << std::hex << hexStr;
|
|
|
+ int num;
|
|
|
+ ss >> num;
|
|
|
+ return num;
|
|
|
+ };
|
|
|
+
|
|
|
+ auto intTo36 = [](int num) -> std::string {
|
|
|
+ std::string base36Chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
|
+ std::string base36Str;
|
|
|
+
|
|
|
+ while (num > 0) {
|
|
|
+ base36Str = base36Chars[num % 36] + base36Str;
|
|
|
+ num /= 36;
|
|
|
+ }
|
|
|
+
|
|
|
+ return base36Str;
|
|
|
+ };
|
|
|
+
|
|
|
+ int id = GetDevID();
|
|
|
+ auto idHexStr = intToHex(id);
|
|
|
+ if (idHexStr.length() != 4 || idHexStr[0] != '0')
|
|
|
+ {
|
|
|
+ strVTMCode = "RTA42F2";
|
|
|
+ strDescription = "实体Id异常";
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode(strVTMCode)("GetVTMErrMsg get error entity id %d, convert to %s", id, idHexStr.c_str());
|
|
|
+ return ErrorCodeEnum::Error_Unregisted;
|
|
|
+ }
|
|
|
+
|
|
|
+ std::string dstRTA = "RTA";
|
|
|
+ dstRTA.push_back(idHexStr[1]); //first
|
|
|
+
|
|
|
+ std::string lastTwoDigits = idHexStr.substr(idHexStr.length() - 2); // last two digits
|
|
|
+
|
|
|
+ int num = hexToInt(lastTwoDigits);
|
|
|
+ if (num < 0 || num >= 36) {
|
|
|
+ strVTMCode = "RTA42F2";
|
|
|
+ strDescription = "无法转换实体Id";
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode(strVTMCode)("GetVTMErrMsg cannot convert entity id %d ", id);
|
|
|
+ return ErrorCodeEnum::Error_DataCheck;
|
|
|
+ }
|
|
|
+
|
|
|
+ std::string base36Str = intTo36(num);
|
|
|
+ dstRTA.append(base36Str);
|
|
|
+
|
|
|
+ for (int i = 0; i < strErrorCodeArr.GetCount(); i++)
|
|
|
+ {
|
|
|
+ if (strErrorCodeArr[i].IsStartWith(dstRTA.c_str(), true))
|
|
|
+ {
|
|
|
+ std::string curRemark = strRemarkArr[i].GetData();
|
|
|
+ std::transform(curRemark.begin(), curRemark.end(), curRemark.begin(), [](unsigned char c) { return std::tolower(c); });
|
|
|
+ m_UserCodeToMsgTip.insert(std::make_pair(curRemark, ErrMsgStruct(strErrorCodeArr[i].GetData(), strDescriptionArr[i].GetData())));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ isInit = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (m_UserCodeToMsgTip.find(userCodeStr) != m_UserCodeToMsgTip.end())
|
|
|
+ {
|
|
|
+ strVTMCode = m_UserCodeToMsgTip[userCodeStr].VTMCode.c_str();
|
|
|
+ strDescription = m_UserCodeToMsgTip[userCodeStr].errMsg.c_str();
|
|
|
+ return ErrorCodeEnum::Error_Succeed;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ strVTMCode = "RTA42F1";
|
|
|
+ strDescription = "错误映射异常";
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode(strVTMCode)("GetVTMErrMsg entity did not contain the usercode %s ", userCodeStr.c_str());
|
|
|
+ return ErrorCodeEnum::Error_NotExist;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
ErrorCodeEnum SpEntity::SetSelfPriority(EntityPriorityEnum nPriority)
|
|
|
{
|
|
|
ErrorCodeEnum result(Error_Succeed);
|