Skip to content

Commit

Permalink
同步代码
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaobangyu committed Oct 7, 2023
1 parent 6d34e40 commit 3b5d5e3
Showing 1 changed file with 38 additions and 79 deletions.
117 changes: 38 additions & 79 deletions server/robot/accord_mgr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
local log_warn = logger.warn
local log_debug = logger.debug
local jdecode = json.decode
local jencode = json.encode
local json_pretty = json.pretty
local tinsert = table.insert

Expand All @@ -19,11 +20,10 @@ local SECOND_3_MS = quanta.enum("PeriodTime", "SECOND_3_MS")
local AccordMgr = singleton()
local prop = property(AccordMgr)
prop:reader("http_server", nil)
prop:reader("accord_html", "") -- html
prop:reader("server_list", {}) -- 服务列表
prop:reader("accord_list", {}) -- 协议列表(添加的数据)
prop:reader("case_group", {}) -- 用例分组
prop:reader("load_db_status", false)
prop:reader("srvlist_api", environ.get("QUANTA_SRVLIST_API")) -- 服务器列表api

function AccordMgr:__init()
-- 创建HTTP服务器
Expand All @@ -33,11 +33,7 @@ function AccordMgr:__init()
server:register_post("/create", "on_create", self)
server:register_post("/destory", "on_destory", self)
server:register_post("/run", "on_run", self)

-- 服务器操作
server:register_post("/server_list", "on_server_list", self)
server:register_post("/server_edit", "on_server_edit", self)
server:register_post("/server_del", "on_server_del", self)
server:register_post("/get_config", "on_get_config", self)

-- 协议操作
server:register_post("/case_group", "on_case_group", self)
Expand Down Expand Up @@ -71,17 +67,7 @@ function AccordMgr:load_db_data()
self.case_group[group.id] = group
end
else
log_warn("[AccordMgr][load_db_data] case_group fail ok(%s)", cgp_ok)
end

-- 服务器列表
local svr_ok, srv_dbdata = accord_dao:load_data("accord_server")
if svr_ok then
for _, server in pairs(srv_dbdata) do
self.server_list[tonumber(server.id)] = server
end
else
log_warn("[AccordMgr][load_db_data] accord_server fail ok(%s)", svr_ok)
log_warn("[AccordMgr][load_db_data] case_group fail ok:{}", cgp_ok)
end

-- 协议配置
Expand All @@ -105,13 +91,13 @@ function AccordMgr:load_db_data()
end
end
else
log_warn("[AccordMgr][load_db_data] accord_conf fail ok(%s)", cf_ok)
log_warn("[AccordMgr][load_db_data] accord_conf fail ok:{}", cf_ok)
end

if cgp_ok and svr_ok and cf_ok then
if cgp_ok and cf_ok then
self.load_db_status = true
end
return cgp_ok and svr_ok and cf_ok
return cgp_ok and cf_ok
end)
end

Expand Down Expand Up @@ -162,53 +148,19 @@ end

-- monitor拉取
function AccordMgr:on_create(url, body, params)
log_debug("[AccordMgr][on_create] params: %s", params)
log_debug("[AccordMgr][on_create] params:{}", params)
return robot_mgr:create_robot(body.ip, body.port, body.open_id, body.passwd)
end

-- 后台GM调用,字符串格式
function AccordMgr:on_destory(url, body, params)
log_debug("[AccordMgr][on_destory] body: %s", body)
log_debug("[AccordMgr][on_destory] body:{}", body)
return robot_mgr:destory_robot(body.open_id)
end

-- 服务器列表
function AccordMgr:on_server_list(url, body)
log_debug("[AccordMgr][on_server_list] body: %s", body)
return { code = 0, server_list = self.server_list }
end

-- 编辑服务器
function AccordMgr:on_server_edit(url, body)
log_debug("[AccordMgr][on_server_edit] body: %s", body)
if body.data then
local data = body.data
if self.server_list[data.id] then
accord_dao:update("accord_server", data)
else
accord_dao:insert("accord_server", data)
end
self.server_list[data.id] = data
return { code = 0 }
end
return { code = -1, msg = "数据格式不正确!" }
end

-- 删除服务器
function AccordMgr:on_server_del(url, body)
log_debug("[AccordMgr][on_server_del] body: %s", body)
if body.data then
local data = body.data
self.server_list[data.id] = nil
accord_dao:delete("accord_server", data.id)
return { code = 0 }
end
return { code = -1, msg = "数据格式不正确!" }
end

-- 协议分组
function AccordMgr:on_accord_group(url, body)
log_debug("[AccordMgr][on_accord_group] body: %s", body)
log_debug("[AccordMgr][on_accord_group] body:{}", body)
return {
code = 0,
accord_group = msg_mgr.accord_group
Expand All @@ -219,32 +171,34 @@ end

-- 分组列表
function AccordMgr:on_case_group(url, body)
log_debug("[AccordMgr][on_case_group] body: %s", body)
log_debug("[AccordMgr][on_case_group] body:{}", body)
return { code = 0, case_group = self.case_group }
end

-- 编辑用例分组
function AccordMgr:on_case_group_edit(url, body)
log_debug("[AccordMgr][on_case_group_edit] body: %s", body)
log_debug("[AccordMgr][on_case_group_edit] body:{}", body)
if body.data then
local data = body.data.case_group
if self.case_group[data.id] then
local id = tonumber(data.id)
if self.case_group[id] then
accord_dao:update("case_group", data)
else
accord_dao:insert("case_group", data)
end
self.case_group[data.id] = data
self.case_group[id] = data
return { code = 0 }
end
return { code = -1, msg = "数据格式不正确!" }
end

-- 删除用例分组
function AccordMgr:on_case_group_del(url, body)
log_debug("[AccordMgr][on_case_group_del] body: %s", body)
log_debug("[AccordMgr][on_case_group_del] body:{}", body)
if body.data then
local data = body.data
local group = self.case_group[data.id]
local id = tonumber(data.id)
local group = self.case_group[id]
if not group then
return { code = 0 }
end
Expand All @@ -253,25 +207,25 @@ function AccordMgr:on_case_group_del(url, body)
accord_dao:delete("accord_conf", id)
end
end
self.case_group[data.id] = nil
accord_dao:delete("case_group", data.id)
self.case_group[id] = nil
accord_dao:delete("case_group", id)
return { code = 0 }
end
return { code = -1, msg = "数据格式不正确!" }
end

-- 协议列表
function AccordMgr:on_accord_list(url, body)
log_debug("[AccordMgr][on_accord_list] body: %s", body)
log_debug("[AccordMgr][on_accord_list] body:{}", body)
return { code = 0, accord_list = self.accord_list }
end

-- 编辑协议
function AccordMgr:on_accord_edit(url, body)
log_debug("[AccordMgr][on_accord_edit] body: %s", body)
log_debug("[AccordMgr][on_accord_edit] body:{}", body)
if body.data then
local data = body.data
local id = data.id
local id = tonumber(data.id)
local new = false
local accord = self.accord_list[id]
if not accord then
Expand Down Expand Up @@ -304,22 +258,22 @@ end

-- 删除协议
function AccordMgr:on_accord_del(url, body)
log_debug("[AccordMgr][on_accord_del] body: %s", body)
log_debug("[AccordMgr][on_accord_del] body:{}", body)
if body.data then
local data = body.data
self.accord_list[data.id] = nil
accord_dao:delete("accord_conf", data.id)
self.accord_list[tonumber(data.id)] = nil
accord_dao:delete("accord_conf", tonumber(data.id))
return { code = 0 }
end
return { code = -1, msg = "数据格式不正确!" }
end

-- 编辑协议选项
function AccordMgr:on_proto_edit(url, body)
log_debug("[AccordMgr][on_proto_edit] body: %s", body)
log_debug("[AccordMgr][on_proto_edit] body:{}", body)
if body and body.data then
local data = body.data
local accord = self.accord_list[data.id]
local accord = self.accord_list[tonumber(data.id)]
if not accord then
return { code = -1, msg = "不存在的协议配置,请重新创建!" }
end
Expand All @@ -328,22 +282,22 @@ if body and body.data then
proto.args = jdecode(proto.args);
-- 格式json字符串
proto.args = json_pretty(proto.args)
accord.protocols[proto.id] = proto
accord.protocols[tonumber(proto.id)] = proto
accord_dao:update("accord_conf", accord)
end
return { code = 0}
end

-- 删除协议选项
function AccordMgr:on_proto_del(url, body)
log_debug("[AccordMgr][on_proto_del] body: %s", body)
log_debug("[AccordMgr][on_proto_del] body:{}", body)
if body.data then
local data = body.data
local accord = self.accord_list[data.id]
local accord = self.accord_list[tonumber(data.id)]
if not accord then
return { code = -1, msg = "不存在的协议配置!" }
end
accord.protocols[data.proto_id] = nil
accord.protocols[tonumber(data.proto_id)] = nil
accord_dao:update("accord_conf", accord)
end
return { code = 0}
Expand All @@ -354,11 +308,16 @@ function AccordMgr:on_run(url, body)
local data = body.data
if body.cmd_id ~= 1001 then
data = jdecode(body.data)
log_debug("[AccordMgr][on_run] body: %s", body)
log_debug("[AccordMgr][on_run] body:{}", body)
end
return robot_mgr:run_accord_message(body.open_id, body.cmd_id, data)
end

-- 获取配置
function AccordMgr:on_get_config(url, body)
return { code = 0, srvlist_api=self.srvlist_api}
end

quanta.accord_mgr = AccordMgr()

return AccordMgr

0 comments on commit 3b5d5e3

Please sign in to comment.