From 3b5d5e3283a21bf30188d21f04ae494881bd8f9a Mon Sep 17 00:00:00 2001 From: zhaobangyu <763098346@QQ.com> Date: Sat, 7 Oct 2023 18:55:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/robot/accord_mgr.lua | 117 ++++++++++++------------------------ 1 file changed, 38 insertions(+), 79 deletions(-) diff --git a/server/robot/accord_mgr.lua b/server/robot/accord_mgr.lua index 9c158c30..13132c7a 100644 --- a/server/robot/accord_mgr.lua +++ b/server/robot/accord_mgr.lua @@ -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 @@ -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服务器 @@ -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) @@ -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 -- 协议配置 @@ -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 @@ -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 @@ -219,21 +171,22 @@ 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 = "数据格式不正确!" } @@ -241,10 +194,11 @@ 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 @@ -253,8 +207,8 @@ 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 = "数据格式不正确!" } @@ -262,16 +216,16 @@ 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 @@ -304,11 +258,11 @@ 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 = "数据格式不正确!" } @@ -316,10 +270,10 @@ 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 @@ -328,7 +282,7 @@ 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} @@ -336,14 +290,14 @@ 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} @@ -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