123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- local skynet = require "skynet"
- local s = require "service"
- local mysql = require "skynet.db.mysql"
- local runconfig = require("run_config")
- local cjson = require "cjson"
- local tools = require "tools"
- local db = nil
- local config = {
- config_info = {
- ["1"] = { --片头
- [2]={
- name = "横屏 16:9",
- is_ban = 0,
- classification_id = 2,
- describe = "",
- },
- [1]={
- name = "竖屏 9:16",
- is_ban = 0,
- classification_id = 1,
- describe = "",
- }
- },
- ["2"] = { --正片
- [2]={
- name = "横屏 16:9",
- is_ban = 0,
- classification_id = 2,
- describe = "",
- },
- [1]={
- name = "竖屏 9:16",
- is_ban = 0,
- classification_id = 1,
- describe = "",
- }
- },
- ["3"] = { --片尾
- [2]={
- name = "横屏 16:9",
- is_ban = 0,
- classification_id = 2,
- describe = "",
- },
- [1]={
- name = "竖屏 9:16",
- is_ban = 0,
- classification_id = 1,
- describe = "",
- }
- },
- ["4"] = { --bgm音频
- [1]={
- name = "全部",
- is_ban = 0,
- classification_id = 1,
- describe = "",
- }
- },
- ["5"] = { --片尾音频
- [1]={
- name = "全部",
- is_ban = 0,
- classification_id = 1,
- describe = "",
- }
- },
- ["6"] = { --图片
- [1]={
- name = "全部",
- is_ban = 0,
- classification_id = 1,
- describe = "",
- }
- },
- },
- permissions_info = {
- },
- other_info = {
- },
- group_info = {
- }
- }
- s.resp.update_permissions_info = function(msg_body,fd)
- local permissions_info = {}
- skynet.error("update_permissions_info")
- function action(isOk,list)
- local error_json = '{"code": 10000, "msg": "更新权限失败成功"}'
- if isOk then
- if #list>0 then
- for i = 1, #list, 1 do
- local permissions_id = list[i].id
- permissions_info[permissions_id] = list[i]
- end
- config.permissions_info = permissions_info;
- end
- end
- if fd~=nil then
- s.resp.updateConfigDb()
- return tools.response(fd,200,error_json)
- end
- end
- local sql = string.format("select * from permissions_list_tab")
- local res = db:query(sql)
- if res and #res > 0 then
- local tab = {}
- if #res == 1 then
- tab[1] = tools.getDbResData(res)
- else
- tab = tools.getDbResData(res)
- end
- action(true,tab)
- skynet.error("Found data:")
- else
- action(false,nil)
- skynet.error("No data found.")
- end
- end
- s.resp.update_group_info = function(msg_body,fd)
- local group_info = {}
- function action(isOk,list)
- local error_json = '{"code": 10000, "msg": "更新权限失败成功"}'
- if isOk then
- if #list>0 then
- for i = 1, #list, 1 do
- local group_id = list[i].id
- group_info[group_id] = list[i]
- end
- config.group_info = group_info;
- end
- end
- if fd~=nil then
- s.resp.updateConfigDb()
- return tools.response(fd,200,error_json)
- end
- end
- local sql = string.format("select * from group_list_tab")
- local res = db:query(sql)
- if res and #res > 0 then
- local tab = {}
- if #res == 1 then
- tab[1] = tools.getDbResData(res)
- else
- tab = tools.getDbResData(res)
- end
- action(true,tab)
- skynet.error("Found data:")
- else
- action(false,nil)
- skynet.error("No data found.")
- end
- end
- s.resp.update_other_info = function()
-
- end
- s.resp.update_config_info = function(msg_body,fd)
- local config_info = {}
- skynet.error("update_config_info")
- function action(isOk,info)
- local error_json = '{"code": 10000, "msg": "更新权限失败成功"}'
- if isOk then
- config.config_info = info.info
- else
- config_info = cjson.encode(config.config_info)
- local sql = string.format("INSERT INTO classification_list_tab (info,self_id) VALUES ('%s',%d)",config_info,1)
- local res = db:query(sql)
- skynet.error(sql)
- end
- if fd~=nil then
- s.resp.updateConfigDb()
- return tools.response(fd,200,error_json)
- end
- end
- local sql = string.format("select info from classification_list_tab where self_id = 1")
- local res = db:query(sql)
- if res and #res > 0 then
- local tab = {}
- tab = tools.getDbResData(res)
- action(true,tab)
- skynet.error("Found data:")
- else
- action(false,nil)
- skynet.error("No data found.")
- end
- end
- s.resp.get_config_info = function(msg_body,fd)
- return tools.response(fd,200,cjson.encode({code=10000,msg = "成功!",data=config.config_info}))
- end
- s.resp.get_permissions_info = function(msg_body,fd)
- local permissions_info = {}
- if config.permissions_info~=nil and #config.permissions_info>0 then
- permissions_info = config.permissions_info
- end
- -- tools.dump(permissions_info)
- return tools.response(fd,200,cjson.encode({code=10000,msg = "成功!",data=permissions_info}))
- end
- s.resp.get_group_info = function(msg_body,fd)
- return tools.response(fd,200,cjson.encode({code=10000,msg = "成功!",data=config.group_info}))
- end
- s.resp.get_other_info = function(fd)
- return tools.response(fd,200,cjson.encode({code=10000,msg = "成功!",data=config.other_info}))
- end
- s.resp.on_recv = function (source, fd, msg_id, msg_body,user_data)
- skynet.error("接收一条客户端配置的接口 ",msg_id)
- local func = string.gsub(msg_id, '/config/', '')
- skynet.error("func",func)
- if s.resp[func] ~=nil then
- return s.resp[func](msg_body,fd)
- end
- return tools.response(fd,200,string.format("接口 %s 不存在",func))
- end
- s.init = function()
- db=mysql.connect({
- host=runconfig.db_tost,
- port=runconfig.db_port,
- database=runconfig.db_name,
- user="root",
- password=runconfig.db_pw,
- max_packet_size = 1024 * 1024,
- on_connect = nil
- })
- if not db then
- skynet.error("failed to connect")
- skynet.exit()
- else
- skynet.error(" config success to connect to mysql server")
- s.resp.initConfig()
- end
- end
- s.resp.updateConfigDb = function()
- -- skynet.fork(function()
- -- local config_info ="{}"
- -- if config.config_info~=nil and #config.config_info>0 then
- -- config_info = cjson.encode(config.config_info)
- -- end
- -- local permissions_info ="{}"
- -- if config.permissions_info~=nil and #config.permissions_info>0 then
- -- permissions_info = cjson.encode(config.permissions_info)
- -- end
- -- local other_info ="{}"
- -- if config.other_info~=nil and #config.other_info>0 then
- -- other_info = cjson.encode(config.other_info)
- -- end
- -- local group_info ="{}"
- -- if config.group_info~=nil and #config.group_info>0 then
- -- group_info = cjson.encode(config.group_info)
- -- end
- -- local sql = string.format("UPDATE video_tools_config_tab SET config_info = '%s' , permissions_info = '%s' , other_info = '%s' , group_info = '%s' WHERE id =%d",config_info,permissions_info,other_info,group_info,1)
- -- db:query(sql)
- -- end)
-
- end
- s.resp.initConfig = function()
- -- local sql = string.format("select * from video_tools_config_tab where id = %d ",1)
- -- local res = db:query(sql)
- -- skynet.error('folder_res_list',sql)
- -- 判断是否找到数据
- -- if res and #res > 0 then
- -- local tab = {}
- -- tab = tools.getDbResData(res)
- -- config.config_info = cjson.decode( tab.config_info)
- -- config.group_info = cjson.decode( tab.group_info)
- -- config.permissions_info = cjson.decode( tab.permissions_info)
- -- config.other_info = cjson.decode( tab.other_info)
- -- else
- s.resp.update_config_info()
- s.resp.update_permissions_info()
- s.resp.update_group_info()
- s.resp.update_other_info()
- s.resp.updateConfigDb()
- -- end
- skynet.error("静态配置完成!")
- end
- s.start(...)
|