Distribution_Service/Server/PortService/R_Order_AB.h
2025-12-09 19:09:12 +08:00

199 lines
7.5 KiB
C++

#ifndef OH_BS_R_ORDER_AB_H
#define OH_BS_R_ORDER_AB_H
#include "DataPacket.h"
#include "ByteTool.h"
#include "../Configuration/BS_Log.h"
#include "Task/TaskInfo.h"
#include "Terminal/Terminal.h"
class R_Order_AB {
public:
static void Function(const DataPacket& packet){
const auto N = packet.FunNumber.get();
const auto hex = APPTool::GetHX(N);
const auto str = CC::format("RoutingAB::Function(%s)", hex.c_str());
BS_Log::Log(str);
}
static void Function_0x02(const DataPacket& packet){
const auto Setting = Config::getConfig();
const auto ID = APPTool::GetInt(packet.Parameter2, packet.Parameter3);
if (packet.Parameter1 == 0x00) {
}
else if (packet.Parameter1 == 0x01) {
Setting->ID = ID;
BS_Log::Log("Function_0x02 ID Change to {}", ID);
}
else if (packet.Parameter1 == 0x03) {
const auto IDS = APPTool::GetBytes(Setting->ID);
const CTL::ByteArray data = {0x66,0xAB,0x02,0x03,IDS[0],IDS[1],0x00,0x00};
if (packet.AimWS && packet.IsTCP) {
packet.AimWS->SendBinary(data);
}
return;
}
const auto IDS = APPTool::GetBytes(Setting->ID);
const CTL::ByteArray data = {0x66,0xAB,0x09,0x00,IDS[0],IDS[1],0x00,0x00};
if (packet.AimWS && packet.IsTCP) {
packet.AimWS->SendBinary(data);
}
}
static void Function_0x03(const DataPacket& packet){
const auto Setting = Config::getConfig();
const auto str = Terminal::toTermInfo();
const auto IDS = APPTool::GetBytes(Setting->ID);
const auto Len = APPTool::GetBytes(str.size());
CTL::ByteArray data = {0x66,0xAB,0x03,0x00,IDS[0],IDS[1],Len[0],Len[1]};
data.append(str);
if (packet.IsTCP && packet.AimWS) {
packet.AimWS->SendBinary(data);
}
}
static void Function_0x04(const DataPacket& packet){
}
static void Function_0x05(const DataPacket& packet){
}
static void Function_0x06(const DataPacket& packet) {
}
static void Function_0x07(const DataPacket& packet) {
try {
const auto ID = APPTool::GetInt(packet.Parameter2, packet.Parameter3);
const int TaskID = packet.Parameter1;
const int Length = APPTool::GetInt(packet.Parameter4, packet.Parameter5);
const auto str = packet.AdditionalData.toString();
CTL::JSONObject Json = CTL::JSONObject::parse(str);
const int Flag = Json.get("Flag");
if (Flag == 1) {
const auto taskInfo = new TaskInfo;
taskInfo->TaskID = TaskID;
taskInfo->TaskType = Json.get("TaskType");
taskInfo->ServerPort = Json.get("ServerPort");
const auto TermList = Json.get("Terms").get<CCVector<int>>();
try {
taskInfo->SendOrder = Json.get("SendOrder");
if (taskInfo->SendOrder == 1) {
taskInfo->TaskOrder = Json.get("TaskOrder").get<std::vector<char>>();
}
}
catch (...){}
for (const auto& TID : TermList) {
taskInfo->Terms.put(TID, TID);
}
taskInfo->pushFlowTask = new PushFlowTask(TaskID);
TaskInfo::Start(taskInfo);
taskInfo->pushFlowTask->start();
}
else if (Flag == 0) {
const auto taskInfo = TaskInfo::getData(TaskID);
if (taskInfo) {
try {
taskInfo->SendOrder = Json.get("SendOrder");
if (taskInfo->SendOrder == 1) {
taskInfo->TaskOrder = Json.get("TaskOrder").get<std::vector<char>>();
}
}
catch (...){}
if (taskInfo->Type == 0 && taskInfo->pushFlowTask) {
taskInfo->pushFlowTask->stop();
}
}
TaskInfo::Stop(TaskID);
}
}
catch (CCException& e) {
BS_Log::Error("Function_0x07 Error: {}",e.what());
}
}
static void Function_0x09(const DataPacket& packet) {
try {
const auto str = packet.AdditionalData.toString();
CTL::JSONObject Json_t = CTL::JSONObject::parse(str);
const auto TaskList = Json_t.get("TaskList").get<CCVector<Dist_Tasks>>();
for (const auto& Task : TaskList) {
const auto taskInfo = new TaskInfo;
taskInfo->TaskID = Task.TaskID;
taskInfo->TaskType = Task.TaskType;
taskInfo->ServerPort = Task.ServerPort;
const auto TermList = Task.Terms;
for (const auto& TID : TermList) {
taskInfo->Terms.put(TID, TID);
}
try {
taskInfo->SendOrder = Task.SendOrder;
if (taskInfo->SendOrder == 1) {
taskInfo->TaskOrder = Task.TaskOrder;
}
}
catch (...){}
taskInfo->pushFlowTask = new PushFlowTask(taskInfo->TaskID);
TaskInfo::Start(taskInfo);
taskInfo->pushFlowTask->start();
}
}
catch (CCException& e) {
BS_Log::Error("Function_0x09 Error: {}",e.what());
}
}
static void Function_0x10(const DataPacket& packet) {
try {
const auto TID = APPTool::GetInt(packet.Parameter2, packet.Parameter3);
const auto task = TaskInfo::getData(packet.Parameter4);
if (task) {
if (task->Type == 0 && task->pushFlowTask) {
if (packet.Parameter1 == 0x01) {
task->pushFlowTask->addTID(TID);
}
else if (packet.Parameter1 == 0x00) {
task->pushFlowTask->removeTID(TID);
}
}
}
}
catch (CCException& e) {
BS_Log::Error("Function_0x10 Error: {}",e.what());
}
}
static void Function_0x11(const DataPacket& packet) {
try {
const auto task = TaskInfo::getData(packet.Parameter2);
const auto str = packet.AdditionalData.toString();
CTL::JSONObject Json = CTL::JSONObject::parse(str);
if (task) {
const auto TermList = Json.get("TermList").get<CCVector<int>>();
if (task->Type == 0 && task->pushFlowTask) {
if (packet.Parameter1 == 0x00) {
for (const auto& TID : TermList) {
task->pushFlowTask->removeTID(TID);
}
}
else if (packet.Parameter1 == 0x01) {
for (const auto& TID : TermList) {
task->pushFlowTask->addTID(TID);
}
}
}
}
}
catch (CCException& e) {
BS_Log::Error("Function_0x11 Error: {}",e.what());
}
}
static void Function_0x13(const DataPacket& packet) {
try {
if (packet.Parameter1 == 0x00) {
Config::CloseService();
CTL::System::Execute("sudo reboot");
}
}
catch (CCException& e) {
BS_Log::Error("Function_0x13 Error: {}",e.what());
}
}
};
#endif