904118851 před 1 rokem
rodič
revize
58990b9e56

+ 3 - 0
bin/kill.sh

@@ -0,0 +1,3 @@
+lsof -i :9910 | grep LISTEN | awk '{print $2}' | xargs sudo kill -9
+lsof -i :9902 | grep LISTEN | awk '{print $2}' | xargs sudo kill -9
+lsof -i :9904 | grep LISTEN | awk '{print $2}' | xargs sudo kill -9

+ 3 - 0
bin/run.sh

@@ -0,0 +1,3 @@
+bash /home/video-tools-server/bin/kill.sh
+# bash ./start_nginx.sh
+/home/skynet/skynet /home/video-tools-server/etc/config_node$1

+ 10 - 4
etc/run_config.lua

@@ -1,20 +1,20 @@
 return {
     --集群
     cluster = {
-		  node1 = "127.0.0.1:7771", 
+		  node1 = "127.0.0.1:9901", 
 		  -- node2 = "127.0.0.1:7772",
     },
     --agentmgr
     agentmgr = { node = "node1" },
     --scene
     scene = {
-      node1 = {1001, 1002},  
+      node1 = {9902, 9903},  
       --node2 = {1003},
     },
     --节点1
     node1 = {
         gateway = {
-          [1] = {port=8001},
+          [1] = {port=9904},
           -- [2] = {port=8002},
         },
         login = {
@@ -26,7 +26,7 @@ return {
     --节点2
     node2 = {
         gateway = {
-          [1] = {port=8011},
+          [1] = {port=9905},
           -- [2] = {port=8022},
         },
         login = {
@@ -34,4 +34,10 @@ return {
             -- [2] = {},
         },
     },
+    db_tost = "127.0.0.1",
+    db_port = 3306,
+    db_pw = "p0LTZh&CjMl2023",
+    db_name = "video_tools_user_db",
+    testHttpProt = 9910;
+    tools_api = "http://clipvideoup.hainanmlwl.com"
 }

+ 87 - 0
lualib/service.lua

@@ -0,0 +1,87 @@
+local skynet = require "skynet"
+local cluster = require "skynet.cluster"
+
+local M = {
+	--类型和id
+	name = "",
+	id = 0,
+	--回调函数
+	exit = nil,
+	init = nil,
+	--分发方法
+	resp = {},
+}
+
+--[[
+function exit_dispatch()
+	if M.exit then
+		M.exit()
+	end
+	skynet.ret()
+	skynet.exit()
+end
+--]]
+
+function traceback(err)
+	skynet.error(tostring(err))
+	skynet.error(debug.traceback())
+end
+
+local dispatch = function(session, address, cmd, ...)
+	local fun = M.resp[cmd]
+	if not fun then
+		skynet.ret()
+		return
+	end
+	
+	local ret = table.pack(xpcall(fun, traceback, address, ...))
+	local isok = ret[1]
+	
+	if not isok then
+		skynet.ret()
+		return
+	end
+
+	skynet.retpack(table.unpack(ret,2))
+end
+
+function init()
+	skynet.dispatch("lua", dispatch)
+	if M.init then
+		M.init()
+	end
+end
+
+function M.call(node, srv, ...)
+	local mynode = skynet.getenv("node")
+	if node == mynode then
+		return skynet.call(srv, "lua", ...)
+	else
+		return cluster.call(node, srv, ...)
+	end
+end
+
+function M.send(node, srv, ...)
+	local mynode = skynet.getenv("node")
+	if node == mynode then
+		return skynet.send(srv, "lua", ...)
+	else
+		return cluster.send(node, srv, ...)
+	end
+end
+
+function M.start(name, id, ...)
+	M.name = name
+	M.id = tonumber(id)
+	skynet.start(init)
+end
+
+M.resp.exit = function()
+    if M.exit then
+        M.exit()
+    end
+    skynet.ret()
+    skynet.exit()
+end
+
+return M

+ 419 - 0
lualib/tools.lua

@@ -0,0 +1,419 @@
+local httpd = require "http.httpd"
+local sockethelper = require "http.sockethelper"
+local skynet = require "skynet"
+local httpd = require "http.httpd"
+local cjson = require "cjson"
+local crypt = require "client.crypt"
+local M = {
+
+}
+M.read_request = function(id)
+     -- limit request body size to 8192 (you can pass nil to unlimit)
+        -- 一般的业务不需要处理大量上行数据,为了防止攻击,做了一个 8K 限制。这个限制可以去掉。
+    -- local code, url, method, header, body = httpd.read_request(sockethelper.readfunc(id), 8192)
+    local code, url, method, header, body = httpd.read_request(sockethelper.readfunc(id))
+    return {code=code,url=url,method=method,header=header,body=body}
+end
+
+M.response = function(id, ...)
+    local ok, err = httpd.write_response(sockethelper.writefunc(id), ...)
+    if not ok then
+        -- if err == sockethelper.socket_error , that means socket closed.
+        skynet.error(string.format("fd = %d, %s", id, err))
+    end
+end
+
+--检查工具返回的字段是否缺失
+M.checkToolsSyncVideo= function(table)
+    local requiredFields = {"classification_id","stype","folder_id", "height", "width","duration", "user_id", "ratio", "category_name","file_name","size","surl","path"} -- Define the required fields here
+    for _, field in pairs(requiredFields) do
+        if not table[field] then
+            return false,field
+        end
+    end
+
+    return true
+end
+
+--检查工具返回的字段是否缺失
+M.checkData= function(origin,table)
+    for _, field in pairs(origin) do
+        if not table[field] then
+            return false,field
+        end
+    end
+    return true
+end
+
+M.dump = function(res, tab)
+    tab = tab or 0
+    if(tab == 0) then
+        skynet.error("............dump...........")
+    end
+    
+    if type(res) == "table" then
+        skynet.error(string.rep("\t", tab).."{")
+        for k,v in pairs(res) do
+            if type(v) == "table" then
+                skynet.error(k.."=")
+                M.dump(v, tab + 1)
+             else
+                skynet.error(string.rep("\t", tab), k, "=", v, ",")
+            end
+        end
+        skynet.error(string.rep("\t", tab).."}")
+    else
+        skynet.error(string.rep("\t", tab) , res)
+    end
+end
+
+M.getDbResData = function(res)
+    local tab = {}
+    if #res >1 then
+        local i = 1;
+        for k, v in pairs(res) do
+            -- skynet.error("Row " .. k)
+            local tab_1 = {}
+            for field, value in pairs(v) do
+                tab_1[field] = value
+                -- skynet.error(field .. ": " .. value)
+            end
+            tab[i] = tab_1;
+            i=i+1;
+        end
+    else
+        for k, v in pairs(res) do
+            for field, value in pairs(v) do
+                tab[field] = value
+            end
+        end
+    end
+    return tab
+end
+
+M.tokenEncode = function(user_data)
+    return crypt.base64encode(user_data)
+end
+
+M.tokenDecode = function(base_str)
+    return crypt.base64decode(base_str)
+end
+
+M.base64decode = function(base_str)
+    return crypt.base64decode(base_str)
+end
+
+M.base64encode = function(base_str)
+    return crypt.base64encode(base_str)
+end
+
+M.getPageData = function(page, count,list)
+    local _start = (page-1)*count+1
+    local _end =page*count
+    -- skynet.error("_start",_start)
+    -- skynet.error("_end",_end)
+    -- skynet.error("list",#list)
+    local _temp_list = {}
+    if _start <1 or _end <1 then
+        return _temp_list
+    end
+    if #list <=0 then
+        return _temp_list
+    end
+    if #list < _start then
+        return _temp_list
+    end
+
+    -- local total_page = math.floor(#list/count) +1
+    -- if (#list%count)>0 then
+    --     total_page = total_page+1
+    -- end
+
+    if _end > #list then
+        local index = 1
+        for i = _start, #list do
+            _temp_list[index] = list[i]
+            index= index+1
+        end
+    else
+        local index = 1
+        for i = _start, _end do
+            _temp_list[index] = list[i]
+            index= index+1
+        end
+    end
+    return _temp_list,#list
+
+end
+
+--回应db新建文件夹
+M.response_db_new_folder = function(fd,is_ok)
+    if not is_ok then
+        return M.response(fd,200,cjson.encode({code=10001,msg = "新建文件夹失败!"}))
+    end
+    return M.response(fd,200,cjson.encode({code=10000,msg = "新建文件夹成功!"}))
+end
+
+--回应db获取资源文件夹列表
+M.response_db_folder_list = function(fd,msg_body,isok,tab)
+    if not isok then
+        return M.response(fd,200, '{"code": 10000,   "msg": "获取资源文件夹列表失败!",  "data": [] }')
+    end
+    local total_count = 0 
+    local list = tab
+    list,total_count = M.getPageData(msg_body.page,msg_body.count,list) 
+    if #list <= 0 or list == nil then
+        return M.response(fd,200,'{"code": 10000,   "msg": "获取资源文件夹列表失败!",  "data": [] }')
+        -- return M.response(fd,200,cjson.encode({code=10000,msg = "获取资源文件夹列表成功!",data=folder_list,total_count=total_count}))
+    end
+    skynet.call("dbmgr","lua","on_recv","folder_res_list_nums",list,fd,total_count)
+end
+
+M.response_db_folder_list_nums  = function(fd,list,count_list,total_count)
+    local folder_list = {}
+    for i = 1, #list, 1 do
+        folder_list[i] = {file_nums=count_list[list[i].id],folder_name=list[i].folder_name,folder_id=list[i].id}
+    end
+    return M.response(fd,200,cjson.encode({code=10000,msg = "获取资源文件夹列表成功!",data=folder_list,total_count=total_count}))
+end
+
+--回应db获取指定文件夹内的资源列表
+M.response_db_folder_res_list = function(fd,msg_body,isok,tab)
+    if not isok then
+        return M.response(fd,200,'{"code": 10000,   "msg": "获取文件夹资源失败",  "data": [] }')
+    end
+    local list = tab
+    local folder_list = {}
+    local total_count = 0 
+    -- M.dump(list)
+    -- skynet.error("list",list)
+    -- skynet.error("msg_body",msg_body)
+    -- M.dump(msg_body)
+    list,total_count = M.getPageData(msg_body.page,msg_body.count,list)
+    for i = 1, #list, 1 do
+        -- skynet.error("create_time")
+        -- M.dump(list[i])
+        table.insert(folder_list,i,{create_time=list[i].create_time,file_id=list[i].id,info=list[i].file_info,file_name=list[i].file_name})
+    end
+    if #list<=0  then
+        return M.response(fd,200,'{"code": 10000,   "msg": "获取文件夹资源失败",  "data": [] }')
+    end
+    return M.response(fd,200,cjson.encode({code=10000,msg = "获取文件夹资源成功!",data=folder_list,total_count=total_count}))
+end
+
+M.response_db_search_res = function(fd,msg_body,isok,tab)
+    local error_json = '{"code": 10000,   "msg": "搜索失败",  "data": [] }'
+    if not isok then
+        return M.response(fd,200,error_json)
+    end
+    local list = tab
+    local file_list = {}
+    local total_count = 0 
+    -- M.dump(list)
+    -- skynet.error("list",list)
+    -- skynet.error("msg_body",msg_body)
+    -- tools.dump(msg_body)
+    list ,total_count = M.getPageData(msg_body.page,msg_body.count,list)
+    for i = 1, #list, 1 do
+        table.insert(file_list,i,{create_time=list[i].create_time,file_id=list[i].id,info=list[i].file_info,file_name=list[i].file_name})
+    end
+    if #list<=0  then
+        return M.response(fd,200,error_json)
+    end
+    return M.response(fd,200,cjson.encode({code=10000,msg = "搜索成功",data=file_list,total_count=total_count}))
+end
+
+M.response_db_get_file_list_by_type = function(fd,msg_body,isok,tab)
+    local error_json = '{"code": 10000,   "msg": "获取指定类型所有文件失败!",  "data": [] }'
+    if not isok then
+        return M.response(fd,200,error_json)
+    end
+    local list = tab
+    local file_list = {}
+    local total_count = 0
+
+    list ,total_count = M.getPageData(msg_body.page,msg_body.count,list)
+    for i = 1, #list, 1 do
+        table.insert(file_list,i,{create_time=list[i].create_time,file_id=list[i].id,info=list[i].file_info,file_name=list[i].file_name})
+    end
+    if #list<=0  then
+        return M.response(fd,200,error_json)
+    end
+    return M.response(fd,200,cjson.encode({code=10000,msg = "获取指定类型所有文件成功",data=file_list,total_count=total_count}))
+end
+
+M.response_db_get_template_list = function(fd,msg_body,isok,tab)
+    local error_json = '{"code": 10000,   "msg": "获取模板列表失败",  "data": [] }'
+    if not isok then
+        return M.response(fd,200,error_json)
+    end
+    local list = tab
+    local template_list = {}
+    local total_count = 0
+
+    list ,total_count = M.getPageData(msg_body.page,msg_body.count,list)
+    for i = 1, #list, 1 do
+        table.insert(template_list,i,{create_time=list[i].create_time,
+        template_id=list[i].id,
+        project_name=list[i].project_name,
+        book_name=list[i].book_name,
+        ratio=list[i].ratio,
+        video_stype=list[i].video_stype,
+        subtitles=list[i].subtitles,
+        subtitles_audio=list[i].subtitles_audio,
+        video_nums=list[i].video_nums,
+        video_crop_time=list[i].video_crop_time,
+        info=list[i].template_info})
+    end
+    if #list<=0  then
+        return M.response(fd,200,error_json)
+    end
+    return M.response(fd,200,cjson.encode({code=10000,msg = "获取模板列表成功",data=template_list,total_count=total_count}))
+end
+
+M.response_db_search_template = function(fd,msg_body,isok,tab)
+    local error_json = '{"code": 10000,   "msg": "搜索模板失败",  "data": [] }'
+    if not isok then
+        return M.response(fd,200,error_json)
+    end
+    local list = tab
+    local template_list = {}
+    local total_count = 0
+
+    list ,total_count = M.getPageData(msg_body.page,msg_body.count,list)
+    for i = 1, #list, 1 do
+        table.insert(template_list,i,{create_time=list[i].create_time,
+        template_id=list[i].id,
+        project_name=list[i].project_name,
+        book_name=list[i].book_name,
+        ratio=list[i].ratio,
+        video_stype=list[i].video_stype,
+        subtitles=list[i].subtitles,
+        subtitles_audio=list[i].subtitles_audio,
+        video_nums=list[i].video_nums,
+        video_crop_time=list[i].video_crop_time,
+        info=list[i].template_info})
+    end
+    if #list<=0  then
+        return M.response(fd,200,error_json)
+    end
+    return M.response(fd,200,cjson.encode({code=10000,msg = "搜索模板成功",data=template_list,total_count=total_count}))
+end
+
+M.response_db_get_template_info_by_id = function(fd,msg_body,isok,tab)
+    local error_json = '{"code": 10000,   "msg": "获取模板信息失败!",  "data": [] }'
+    if not isok then
+        return M.response(fd,200,error_json)
+    end
+    local info = {create_time=tab.create_time,
+    template_id=tab.id,
+    project_name=tab.project_name,
+    book_name=tab.book_name,
+    ratio=tab.ratio,
+    video_stype=tab.video_stype,
+    subtitles=tab.subtitles,
+    subtitles_audio=tab.subtitles_audio,
+    video_nums=tab.video_nums,
+    video_crop_time=tab.video_crop_time,
+    info=tab.template_info}
+    return M.response(fd,200,cjson.encode({code=10000,msg = "获取模板信息成功!",data=info}))
+end
+
+M.response_db_generate_video_folder_list = function(fd,msg_body,isok,tab)
+    local err_code = '{"code": 10000,   "msg": "获取生成视频文件夹列表失败!",  "data": [] }'
+    if not isok then
+        return M.response(fd,200, err_code)
+    end
+    local total_count = 0 
+    local list = tab
+    list,total_count = M.getPageData(msg_body.page,msg_body.count,list) 
+    if #list <= 0 or list == nil then
+        return M.response(fd,200,err_code)
+        -- return M.response(fd,200,cjson.encode({code=10000,msg = "获取资源文件夹列表成功!",data=folder_list,total_count=total_count}))
+    end
+    skynet.call("dbmgr","lua","on_recv","folder_gen_video_list_nums",list,fd,total_count)
+end
+M.response_db_folder_generate_video_list_nums  = function(fd,list,count_list,total_count)
+    local folder_list = {}
+    for i = 1, #list, 1 do
+        folder_list[i] = {file_nums=count_list[list[i].id],folder_name=list[i].book_name,folder_id=list[i].id,create_time=list[i].create_time,info=list[i].generate_video_info}
+    end
+    return M.response(fd,200,cjson.encode({code=10000,msg = "获取生成视频文件夹列表成功!",data=folder_list,total_count=total_count}))
+end
+
+--回应db获取文件夹内的生成视频
+M.response_db_get_video_list_by_folder_id = function(fd,msg_body,isok,tab)
+    if not isok then
+        return M.response(fd,200,'{"code": 10000,   "msg": "获取文件夹内的生成视频失败",  "data": [] }')
+    end
+    local list = tab
+    local folder_list = {}
+    local total_count = 0 
+    -- M.dump(list)
+    -- skynet.error("list",list)
+    -- skynet.error("msg_body",msg_body)
+    -- M.dump(msg_body)
+    list,total_count = M.getPageData(msg_body.page,msg_body.count,list)
+    for i = 1, #list, 1 do
+        -- skynet.error("create_time")
+        -- M.dump(list[i])
+        table.insert(folder_list,i,{template_id=list[i].template_id,video_state=list[i].video_state,video_url=list[i].video_url,create_time=list[i].create_time,file_id=list[i].id,info=list[i].generate_video_info,file_name=list[i].video_name,custom=list[i].custom})
+    end
+    if #list<=0  then
+        return M.response(fd,200,'{"code": 10000,   "msg": "获取文件夹内的生成视频失败",  "data": [] }')
+    end
+    return M.response(fd,200,cjson.encode({code=10000,msg = "获取文件夹内的生成视频成功!",data=folder_list,total_count=total_count}))
+end
+
+M.response_db_search_generate_video_file = function(fd,msg_body,isok,tab)
+    local error_json = '{"code": 10000,   "msg": "搜索失败",  "data": [] }'
+    if not isok then
+        return M.response(fd,200,error_json)
+    end
+    local list = tab
+    local file_list = {}
+    local total_count = 0 
+    list ,total_count = M.getPageData(msg_body.page,msg_body.count,list)
+    for i = 1, #list, 1 do
+        table.insert(file_list,i,{template_id=list[i].template_id,video_state=list[i].video_state,video_url=list[i].video_url,create_time=list[i].create_time,file_id=list[i].id,info=list[i].generate_video_info,file_name=list[i].video_name,custom=list[i].custom})
+        -- table.insert(file_list,i,{create_time=list[i].create_time,file_id=list[i].id,info=list[i].generate_video_info,file_name=list[i].video_name})
+    end
+    if #list<=0  then
+        return M.response(fd,200,error_json)
+    end
+    return M.response(fd,200,cjson.encode({code=10000,msg = "搜索成功",data=file_list,total_count=total_count}))
+end
+M.response_db_generate_video = function(fd,isok)
+    if not isok then
+        return M.response(fd,200,cjson.encode({code=10001,msg = "生成视频失败"}))
+    end
+    return M.response(fd,200,cjson.encode({code=10000,msg = "生成视频成功"}))
+end
+M.getRandomIndex = function(array)
+    local count = #array
+    local index = math.random(1,count)
+    return index
+end
+
+M.getRandomArray = function(array)
+    local numberTable = {}
+    for i = 1, #array do
+        table.insert(numberTable,i)
+    end
+    -- local count = #array
+    function getRandom()
+        local index = math.random(1,#numberTable)
+        local random = numberTable[index]
+        table.remove(numberTable, index)
+        return random
+    end
+
+    local randomNumList = {}
+    for i = 1, #array do
+        local random = getRandom()
+        table.insert(randomNumList,random)
+    end
+    return randomNumList
+end
+
+return M

+ 48 - 0
service/agent/init.lua

@@ -0,0 +1,48 @@
+local skynet = require "skynet"
+local s = require "service"
+
+s.client = {}
+s.gate = nil
+
+s.resp.client = function(source, cmd, msg)
+    s.gate = source
+    if s.client[cmd] then
+		local ret_msg = s.client[cmd]( msg, source)
+		if ret_msg then
+			skynet.send(source, "lua", "send", s.id, ret_msg)
+		end
+    else
+        skynet.error("s.resp.client fail", cmd)
+    end
+end
+
+
+
+s.resp.kick = function(source)
+	s.leave_scene()
+	--在此处保存角色数据
+	skynet.sleep(200)
+end
+
+s.resp.exit = function(source)
+	skynet.exit()
+end
+
+s.resp.send = function(source, msg)
+	skynet.send(s.gate, "lua", "send", s.id, msg)
+end
+
+
+s.init = function( )
+	--playerid = s.id
+	--在此处加载角色数据
+	skynet.sleep(200)
+	s.data = {
+		coin = 100,
+		hp = 200,
+	}
+
+
+end
+
+s.start(...)

+ 811 - 0
service/agentmgr/init.lua

@@ -0,0 +1,811 @@
+local skynet = require "skynet"
+local s = require "service"
+local tools = require "tools"
+local cjson = require "cjson"
+--玩家列表
+local players = {}
+
+--玩家类
+function mgrplayer()
+    local m = {
+        playerid = nil,
+		node = nil,
+        agent = nil,
+		status = nil,
+		gate = nil,
+    }
+    return m
+end
+--登录
+s.resp.login = function(fd,msg_body)
+    msg_body = cjson.decode(msg_body)
+    if msg_body.account == nil then
+        return tools.response(fd,200,cjson.encode({code=1001,msg = "账号不能为空"}))
+    end
+
+    if msg_body.password == nil then
+        return tools.response(fd,200,cjson.encode({code=1002,msg = "密码不能为空"}))
+    end
+
+    local isok,user_data =  skynet.call("dbmgr","lua","on_recv","verify",msg_body)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=1003,msg = "账号密码错误!"}))
+    end
+    -- if msg_body.account~="123456" or msg_body.password~="abc" then
+       
+    -- end
+    local index = 0
+    if players[user_data.id] ~=nil then
+        index = players[user_data.id].index+1
+    end
+    local token = tools.tokenEncode(cjson.encode({user_id=user_data.id,index=index}))
+    local myTable = {code =10000, msg = "登录成功!", data = {user_id=user_data.id,user_name=user_data.name,group_id=user_data.group_id,permit_id=user_data.permit_id,token=token}}
+    local jsonStr = cjson.encode(myTable)
+    players[user_data.id] = {index = index}
+    return tools.response(fd,200,jsonStr)
+end
+
+s.resp.account_is_other_user_login = function(source,user_id,index)
+    if not players[user_id] then
+        players[user_id] = {index = index}
+        return false
+    end
+
+    if players[user_id].index~=index then
+        return true
+    end
+
+    return false
+end
+--注册
+s.resp.register = function(fd,msg_body)
+    msg_body = cjson.decode(msg_body)
+    local isok,user_data =  skynet.call("dbmgr","lua","on_recv","select_user_by_account",msg_body.account)
+    if isok then
+        return tools.response(fd,200,string.format("用户 %s 已存在",msg_body.account))
+    end
+    isok = skynet.call("dbmgr","lua","on_recv","add_new_user",msg_body)
+    if not isok then
+        return tools.response(fd,200,"创建失败!")
+    end
+    return tools.response(fd,200,cjson.encode({code=10000,msg = "创建成功!"}))
+end
+
+--用户新建文件夹
+s.resp.new_folder = function(fd,msg_body,user_data)
+    skynet.error("new_folder",msg_body,user_data)
+    msg_body = cjson.decode(msg_body)
+    if type(user_data) ~= "table" then
+        return  tools.response(fd, 200, "token error!")
+    end
+    local user_id = user_data.user_id
+    if not user_id then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = "缺少user_id"}))
+    end
+    msg_body["user_id"] = user_id
+    local isok ,key =  tools.checkData({"category_name","type","classification_id"},msg_body)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: '%s'.", key)}))
+    end
+
+    local is_public = 0
+    if msg_body.is_public ~=nil then
+        is_public = msg_body.is_public 
+    end
+    msg_body["is_public"]  = is_public
+    local isok = skynet.call("dbmgr","lua","on_recv","new_folder",{
+        user_id=user_id,
+        folder_name=msg_body.category_name,
+        classification_id = msg_body.classification_id,
+        folder_type=msg_body.type,
+        is_public=msg_body.is_public}
+    ,fd)
+
+end
+
+--获取资源文件夹列表
+s.resp.folder_list = function(fd,msg_body,user_data)
+    msg_body = cjson.decode(msg_body)
+    if type(user_data) ~= "table" then
+        return  tools.response(fd, 200, "token error!")
+    end
+    local user_id = user_data.user_id
+    if user_id==nil then
+        return tools.response(fd,100,"user_id==nil folder_list !")
+    end
+    msg_body["user_id"] = user_id
+    local isok ,key =  tools.checkData({"type","page","count","classification_id"},msg_body)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+    local is_public = 0
+    if msg_body.is_public ~=nil then
+        is_public = msg_body.is_public 
+    end
+    isok = skynet.call("dbmgr","lua","on_recv","folder_list",{user_id = user_id,
+        type=msg_body.type,
+        is_public=is_public,
+        page=msg_body.page,
+        count = msg_body.count,
+        classification_id = msg_body.classification_id}
+    ,fd)
+   
+end
+
+--获取文件夹内的所有资源
+s.resp.folder_res_list = function(fd,msg_body,user_data)
+    msg_body = cjson.decode(msg_body)
+    if type(user_data) ~= "table" then
+        return  tools.response(fd, 200, "token error!")
+    end
+    local user_id = user_data.user_id
+    if user_id==nil then
+        return tools.response(fd,100,"user_id==nil folder_res_list !")
+    end
+    msg_body["user_id"] = user_id
+    local isok ,key =  tools.checkData({"folder_id","page","count"},msg_body)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+    local is_public = 0
+    if msg_body.is_public ~=nil then
+        is_public = msg_body.is_public 
+    end
+    local duration = nil
+    if msg_body.duration ~=nil then
+        duration = msg_body.duration 
+    end
+    isok = skynet.call("dbmgr","lua","on_recv","folder_res_list",{
+        folder_id = msg_body.folder_id,
+        user_id = user_id,
+        is_public=is_public,
+        page=msg_body.page, 
+        count = msg_body.count,
+        duration = duration}
+    ,fd)
+end
+
+--重命名资源
+s.resp.reset_res_name = function(fd,msg_body,user_data)
+    msg_body = cjson.decode(msg_body)
+    if type(user_data) ~= "table" then
+        return  tools.response(fd, 200, "token error!")
+    end
+    local user_id = user_data.user_id
+    if user_id==nil then
+        return tools.response(fd,100,"user_id==nil reset_res_name !")
+    end
+    msg_body["user_id"] = user_id
+    local isok ,key =  tools.checkData({"folder_id","file_id","name"},msg_body)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+    local is_public = 0
+    if msg_body.is_public ~=nil then
+        is_public = msg_body.is_public 
+    end
+    isok  = skynet.call("dbmgr","lua","on_recv","reset_res_name",{
+        folder_id = msg_body.folder_id,
+        file_id = msg_body.file_id,
+        name = msg_body.name,
+        is_public=is_public,
+        user_id = user_id}
+    )
+
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=10001,msg = "--重命名资源失败"}))
+    end
+    return tools.response(fd,200,cjson.encode({code=10000,msg = "重命名资源成功"}))
+end
+
+--重命名文件夹
+s.resp.reset_folder_name = function(fd,msg_body,user_data)
+    msg_body = cjson.decode(msg_body)
+    if type(user_data) ~= "table" then
+        return  tools.response(fd, 200, "token error!")
+    end
+    local user_id = user_data.user_id
+    if user_id==nil then
+        return tools.response(fd,100,"user_id==nil reset_folder_name !")
+    end
+    msg_body["user_id"] = user_id
+    local isok ,key =  tools.checkData({"folder_id","name"},msg_body)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+    local is_public = 0
+    if msg_body.is_public ~=nil then
+        is_public = msg_body.is_public 
+    end
+    isok  = skynet.call("dbmgr","lua","on_recv","reset_folder_name",{
+        folder_id = msg_body.folder_id,
+        name = msg_body.name,
+        is_public=is_public,
+        user_id = user_id}
+    )
+
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=10001,msg = "--重命名资源失败"}))
+    end
+    return tools.response(fd,200,cjson.encode({code=10000,msg = "重命名资源成功"}))
+end
+
+--搜索
+s.resp.search_res = function(fd,msg_body,user_data)
+    msg_body = cjson.decode(msg_body)
+    if type(user_data) ~= "table" then
+        return  tools.response(fd, 200, "token error!")
+    end
+    local user_id = user_data.user_id
+    if user_id==nil then
+        return tools.response(fd,100,"user_id==nil search_res !")
+    end
+    msg_body["user_id"] = user_id
+    local isok ,key =  tools.checkData({"search_content","type","is_public","page","count","classification_id"},msg_body)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+    local is_public = 0
+    if msg_body.is_public ~=nil then
+        is_public = msg_body.is_public 
+    end
+    isok = skynet.call("dbmgr","lua","on_recv","search_res",{
+        type = msg_body.type,
+        search_content = msg_body.search_content,
+        is_public=is_public,
+        page = msg_body.page,
+        count = msg_body.count,
+        classification_id = msg_body.classification_id,
+        user_id = user_id}
+    ,fd)
+end
+
+--删除资源
+s.resp.delete_res = function(fd,msg_body,user_data)
+    msg_body = cjson.decode(msg_body)
+    if type(user_data) ~= "table" then
+        return  tools.response(fd, 200, "token error!")
+    end
+    local user_id = user_data.user_id
+    if user_id==nil then
+        return tools.response(fd,200,"user_id==nil delete_res !")
+    end
+    msg_body["user_id"] = user_id
+    local isok ,key =  tools.checkData({"file_id_list","is_public"},msg_body)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+
+    local is_public = 0
+    if msg_body.is_public ~=nil then
+        is_public = msg_body.is_public 
+    end
+
+    isok  = skynet.call("dbmgr","lua","on_recv","delete_res",{
+        file_id_list = msg_body.file_id_list,
+        is_public=is_public,
+        user_id = user_id}
+    )
+
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=10000,msg = "删除失败!",data={}}))
+    end
+    return tools.response(fd,200,cjson.encode({code=10000,msg = "删除成功!",data={}}))
+end
+
+--删除文件夹
+s.resp.delete_folder = function(fd,msg_body,user_data)
+    msg_body = cjson.decode(msg_body)
+    if type(user_data) ~= "table" then
+        return  tools.response(fd, 200, "token error!")
+    end
+    local user_id = user_data.user_id
+    if user_id==nil then
+        return tools.response(fd,200,"user_id==nil delete_folder !")
+    end
+    msg_body["user_id"] = user_id
+    local isok ,key =  tools.checkData({"folder_id_list","is_public"},msg_body)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+
+    local is_public = 0
+    if msg_body.is_public ~=nil then
+        is_public = msg_body.is_public 
+    end
+
+    isok  = skynet.call("dbmgr","lua","on_recv","delete_folder",{
+        folder_id_list = msg_body.folder_id_list,
+        is_public=is_public,
+        user_id = user_id}
+    )
+
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=10000,msg = "删除失败!",data={}}))
+    end
+    return tools.response(fd,200,cjson.encode({code=10000,msg = "删除成功!",data={}}))
+end
+
+--获取指定类型所有文件
+s.resp.get_file_list_by_type = function(fd,msg_body,user_data)
+    msg_body = cjson.decode(msg_body)
+    if type(user_data) ~= "table" then
+        return  tools.response(fd, 200, "token error!")
+    end
+    local user_id = user_data.user_id
+    if user_id==nil then
+        return tools.response(fd,200,"user_id==nil get_file_list_by_type !")
+    end
+    msg_body["user_id"] = user_id
+    local isok ,key =  tools.checkData({"type","page","count"},msg_body)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+    local duration = nil
+    if msg_body.duration ~=nil then
+        duration = msg_body.duration 
+    end
+    isok = skynet.call("dbmgr","lua","on_recv","get_file_list_by_type",{
+        type = msg_body.type,
+        count = msg_body.count,
+        page = msg_body.page,
+        user_id = user_id,
+        duration = duration}
+    ,fd)
+end
+
+
+--新建模板
+s.resp.create_template = function(fd,msg_body,user_data)
+    msg_body = cjson.decode(msg_body)
+    if type(user_data) ~= "table" then
+        return  tools.response(fd, 200, "token error!")
+    end
+    local user_id = user_data.user_id
+    if user_id==nil then
+        return tools.response(fd,200,"user_id==nil create_template !")
+    end
+    msg_body["user_id"] = user_id
+    local isok ,key =  tools.checkData({"project_name","book_name","ratio","video_stype","subtitles","subtitles_audio","video_nums","video_crop_time"},msg_body)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+    local error_info = ""
+    isok,error_info = skynet.call("dbmgr","lua","on_recv","check_template_isRight", msg_body)
+
+    if not isok then
+        return tools.response(fd,200,error_info)
+    end
+    -- isok  = skynet.call("dbmgr","lua","on_recv","checkNumsByType",{
+    --     duration = 0,
+    --     type = 1,
+    --     limit = 1,
+    --     user_id = user_id}
+    -- )
+
+    -- if not isok then
+    --     return tools.response(fd,200,cjson.encode({code=10001,msg = "新建模板失败,片头资源不足!"}))
+    -- end
+
+    -- isok  = skynet.call("dbmgr","lua","on_recv","checkNumsByType",{
+    --     duration = 0,
+    --     type = 3,
+    --     limit = 1,
+    --     user_id = user_id}
+    -- )
+
+    -- if not isok then
+    --     return tools.response(fd,200,cjson.encode({code=10001,msg = "新建模板失败,片尾资源不足"}))
+    -- end
+
+
+    -- local subtitles_audio_duration = 0
+
+    -- if  msg_body.template_info ~=nil and msg_body.template_info~="" then
+    --    local  template_info = cjson.decode(msg_body.template_info)
+    --    if  template_info.subtitles_audio_duration~=nil then
+    --      subtitles_audio_duration = tonumber(template_info.subtitles_audio_duration)
+    --    end
+    -- end
+    
+    -- local duration =  msg_body.video_crop_time + 5
+
+    -- local limit = math.floor(subtitles_audio_duration/duration)
+    -- isok  = skynet.call("dbmgr","lua","on_recv","checkNumsByType",{
+    --     duration = duration,
+    --     type = 2,
+    --     limit =limit ,
+    --     user_id = user_id}
+    -- )
+
+    -- if not isok then
+    --     return tools.response(fd,200,cjson.encode({code=10001,msg = "正片资源不足"}))
+    -- end
+
+
+    -- isok  = skynet.call("dbmgr","lua","on_recv","checkNumsByType",{
+    --     duration = 0,
+    --     type = 4,
+    --     limit = 1,
+    --     user_id = user_id}
+    -- )
+
+    -- if not isok then
+    --     return tools.response(fd,200,cjson.encode({code=10001,msg = "BGM音效资源不足!"}))
+    -- end
+
+
+    isok = skynet.call("dbmgr","lua","on_recv","create_template",msg_body,fd)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=10001,msg = "新建模板失败"}))
+    end
+    return tools.response(fd,200,cjson.encode({code=10000,msg = "新建模板成功"}))
+end
+
+-- 获取模板列表
+s.resp.get_template_list = function(fd,msg_body,user_data)
+    msg_body = cjson.decode(msg_body)
+    if type(user_data) ~= "table" then
+        return  tools.response(fd, 200, "token error!")
+    end
+    local user_id = user_data.user_id
+    if user_id==nil then
+        return tools.response(fd,200,"user_id==nil get_template_list !")
+    end
+    msg_body["user_id"] = user_id
+    local isok ,key =  tools.checkData({"video_stype","page","count"},msg_body)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+    isok = skynet.call("dbmgr","lua","on_recv","get_template_list",msg_body,fd)
+end
+
+--删除模板
+s.resp.delete_template = function(fd,msg_body,user_data)
+    msg_body = cjson.decode(msg_body)
+    if type(user_data) ~= "table" then
+        return  tools.response(fd, 200, "token error!")
+    end
+    local user_id = user_data.user_id
+    if user_id==nil then
+        return tools.response(fd,200,"user_id==nil get_template_list !")
+    end
+    msg_body["user_id"] = user_id
+    local isok ,key =  tools.checkData({"template_id_list"},msg_body)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+    isok = skynet.call("dbmgr","lua","on_recv","delete_template",msg_body,fd)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=10001,msg = "删除模板失败"}))
+    end
+    return tools.response(fd,200,cjson.encode({code=10000,msg = "删除模板成功"}))
+end
+--保存/修改模板
+s.resp.save_template = function(fd,msg_body,user_data)
+    msg_body = cjson.decode(msg_body)
+    if type(user_data) ~= "table" then
+        return  tools.response(fd, 200, "token error!")
+    end
+    local user_id = user_data.user_id
+    if user_id==nil then
+        return tools.response(fd,200,"user_id==nil save_template !")
+    end
+    msg_body["user_id"] = user_id
+
+    local isok ,key =  tools.checkData({"template_id","project_name","book_name","ratio","video_stype","subtitles","subtitles_audio","video_nums","video_crop_time","template_info"},msg_body)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+    isok = skynet.call("dbmgr","lua","on_recv","save_template",msg_body,fd)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=10001,msg = "修改模板失败"}))
+    end
+    return tools.response(fd,200,cjson.encode({code=10000,msg = "修改模板成功"}))
+end
+
+--模板搜索
+s.resp.search_template = function(fd,msg_body,user_data)
+    msg_body = cjson.decode(msg_body)
+    if type(user_data) ~= "table" then
+        return  tools.response(fd, 200, "token error!")
+    end
+    local user_id = user_data.user_id
+    if user_id==nil then
+        return tools.response(fd,200,"user_id==nil search_template !")
+    end
+    msg_body["user_id"] = user_id
+
+    local isok ,key =  tools.checkData({"video_stype","search_content","page","count"},msg_body)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+    isok = skynet.call("dbmgr","lua","on_recv","search_template",msg_body,fd)
+end
+
+--根据模板ID获取模板信息
+s.resp.get_template_info_by_id = function(fd,msg_body,user_data)
+    msg_body = cjson.decode(msg_body)
+    if type(user_data) ~= "table" then
+        return  tools.response(fd, 200, "token error!")
+    end
+    local user_id = user_data.user_id
+    if user_id==nil then
+        return tools.response(fd,200,"user_id==nil get_template_info_by_id !")
+    end
+    msg_body["user_id"] = user_id
+
+    local isok ,key =  tools.checkData({"template_id"},msg_body)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+    isok = skynet.call("dbmgr","lua","on_recv","get_template_info_by_id",msg_body,fd)
+end
+
+
+--生成视频
+s.resp.generate_video = function(fd,msg_body,user_data)
+    msg_body = cjson.decode(msg_body)
+    if type(user_data) ~= "table" then
+        return  tools.response(fd, 200, "token error!")
+    end
+    local user_id = user_data.user_id
+    if user_id==nil then
+        return tools.response(fd,200,"user_id==nil generate_video !")
+    end
+    msg_body["user_id"] = user_id
+    local isok ,key =  tools.checkData({"template_id"},msg_body)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+    isok = skynet.call("dbmgr","lua","on_recv","generate_video",msg_body,fd)
+end
+
+--获取生成视频文件夹列表
+s.resp.get_generate_video_folder_list = function(fd,msg_body,user_data)
+    msg_body = cjson.decode(msg_body)
+    if type(user_data) ~= "table" then
+        return  tools.response(fd, 200, "token error!")
+    end
+    local user_id = user_data.user_id
+    if user_id==nil then
+        return tools.response(fd,100,"user_id==nil get_generate_video_folder_list !")
+    end
+    msg_body["user_id"] = user_id
+    local isok ,key =  tools.checkData({"page","count","video_stype"},msg_body)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+    local is_public = 0
+    if msg_body.is_public ~=nil then
+        is_public = msg_body.is_public 
+    end
+    isok = skynet.call("dbmgr","lua","on_recv","get_generate_video_folder_list",{user_id = user_id,
+        page=msg_body.page,
+        count = msg_body.count,
+        video_stype=msg_body.video_stype}
+    ,fd)
+end
+
+--获取文件夹内的生成视频
+s.resp.get_video_list_by_folder_id = function(fd,msg_body,user_data)
+    msg_body = cjson.decode(msg_body)
+    if type(user_data) ~= "table" then
+        return  tools.response(fd, 200, "token error!")
+    end
+    local user_id = user_data.user_id
+    if user_id==nil then
+        return tools.response(fd,100,"user_id==nil get_video_list_by_folder_id !")
+    end
+    msg_body["user_id"] = user_id
+    local isok ,key =  tools.checkData({"folder_id","page","count"},msg_body)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+    local is_public = 0
+    if msg_body.is_public ~=nil then
+        is_public = msg_body.is_public 
+    end
+    local duration = nil
+    if msg_body.duration ~=nil then
+        duration = msg_body.duration 
+    end
+    isok = skynet.call("dbmgr","lua","on_recv","get_video_list_by_folder_id",{
+        folder_id = msg_body.folder_id,
+        user_id = user_id,
+        page=msg_body.page, 
+        count = msg_body.count}
+    ,fd)
+end
+
+--删除生成视频文件夹
+s.resp.delete_generate_video_folder = function(fd,msg_body,user_data)
+    msg_body = cjson.decode(msg_body)
+    if type(user_data) ~= "table" then
+        return  tools.response(fd, 200, "token error!")
+    end
+    local user_id = user_data.user_id
+    if user_id==nil then
+        return tools.response(fd,200,"user_id==nil delete_generate_video_folder !")
+    end
+    msg_body["user_id"] = user_id
+    local isok ,key =  tools.checkData({"folder_id_list"},msg_body)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+
+    isok  = skynet.call("dbmgr","lua","on_recv","delete_generate_video_folder",{
+        folder_id_list = msg_body.folder_id_list,
+        user_id = user_id}
+    )
+
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=10000,msg = "删除失败!",data={}}))
+    end
+    return tools.response(fd,200,cjson.encode({code=10000,msg = "删除成功!",data={}}))
+end
+
+--删除生成视频
+s.resp.delete_generate_video = function(fd,msg_body,user_data)
+    msg_body = cjson.decode(msg_body)
+    if type(user_data) ~= "table" then
+        return  tools.response(fd, 200, "token error!")
+    end
+    local user_id = user_data.user_id
+    if user_id==nil then
+        return tools.response(fd,200,"user_id==nil delete_generate_video !")
+    end
+    msg_body["user_id"] = user_id
+    local isok ,key =  tools.checkData({"generate_video_id_list"},msg_body)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+
+    local is_public = 0
+    if msg_body.is_public ~=nil then
+        is_public = msg_body.is_public 
+    end
+
+    isok  = skynet.call("dbmgr","lua","on_recv","delete_generate_video",{
+        file_id_list = msg_body.generate_video_id_list,
+        user_id = user_id}
+    )
+
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=10000,msg = "删除失败!"}))
+    end
+    return tools.response(fd,200,cjson.encode({code=10000,msg = "删除成功!"}))
+end
+
+--重命名生成视频文件夹的名字
+s.resp.reset_generate_video_folder_name = function(fd,msg_body,user_data)
+    msg_body = cjson.decode(msg_body)
+    if type(user_data) ~= "table" then
+        return  tools.response(fd, 200, "token error!")
+    end
+    local user_id = user_data.user_id
+    if user_id==nil then
+        return tools.response(fd,100,"user_id==nil reset_generate_video_folder_name !")
+    end
+    msg_body["user_id"] = user_id
+    local isok ,key =  tools.checkData({"folder_id","file_id"},msg_body)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+
+    isok  = skynet.call("dbmgr","lua","on_recv","reset_generate_video_folder_name",{
+        folder_id = msg_body.folder_id,
+        file_id = msg_body.file_id,
+        user_id = user_id}
+    )
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=10001,msg = "重命名生成视频文件夹的名字失败"}))
+    end
+    return tools.response(fd,200,cjson.encode({code=10000,msg = "重命名生成视频文件夹的名字成功"}))
+end
+
+--生成视频搜索
+s.resp.search_generate_video_file = function(fd,msg_body,user_data)
+    msg_body = cjson.decode(msg_body)
+    if type(user_data) ~= "table" then
+        return  tools.response(fd, 200, "token error!")
+    end
+    local user_id = user_data.user_id
+    if user_id==nil then
+        return tools.response(fd,100,"user_id==nil reset_generate_video_folder_name !")
+    end
+    msg_body["user_id"] = user_id
+    local isok ,key =  tools.checkData({"page","count","video_stype","search_content"},msg_body)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+    isok  = skynet.call("dbmgr","lua","on_recv","search_generate_video_file",{
+        search_content = msg_body.search_content,
+        page = msg_body.page,
+        count = msg_body.count,
+        video_stype = msg_body.video_stype},fd
+    )
+end
+--检测指定类型文件是否够数量
+s.resp.checkNumsByType = function(fd,msg_body,user_data)
+    msg_body = cjson.decode(msg_body)
+    if type(user_data) ~= "table" then
+        return  tools.response(fd, 200, "token error!")
+    end
+    local user_id = user_data.user_id
+    if user_id==nil then
+        return tools.response(fd,100,"user_id==nil checkNumsByType !")
+    end
+    msg_body["user_id"] = user_id
+    local isok ,key =  tools.checkData({"type","limit"},msg_body)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+    isok  = skynet.call("dbmgr","lua","on_recv","checkNumsByType",{
+        duration = msg_body.duration,
+        type = msg_body.type,
+        limit = msg_body.limit,
+        user_id = user_id}
+    )
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=10001,msg = "条件不足"}))
+    end
+    return tools.response(fd,200,cjson.encode({code=10000,msg = "条件成立"}))
+end
+
+
+--修改密码
+s.resp.reset_password = function(fd,msg_body,user_data)
+    msg_body = cjson.decode(msg_body)
+    if type(user_data) ~= "table" then
+        return  tools.response(fd, 200, "token error!")
+    end
+    local user_id = user_data.user_id
+    if user_id==nil then
+        return tools.response(fd,100,"user_id==nil reset_password !")
+    end
+    msg_body["user_id"] = user_id
+    local isok ,key =  tools.checkData({"new_pw","sure_pw"},msg_body)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+
+    if msg_body.new_pw~=msg_body.sure_pw then
+        return tools.response(fd,200,cjson.encode({code=9002,msg ="两次密码不一致!"}))
+    end
+
+    isok  = skynet.call("dbmgr","lua","on_recv","reset_password",{
+        new_pw = msg_body.new_pw,
+        sure_pw = msg_body.sure_pw,
+        user_id = user_id}
+    )
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=10001,msg = "修改密码失败!"}))
+    end
+    return tools.response(fd,200,cjson.encode({code=10000,msg = "修改密码成功!"}))
+end
+--踢掉
+s.resp.kick = function(fd,msg_body,user_data)
+    
+end
+
+
+
+s.resp.on_recv = function (source, fd, msg_id, msg_body,user_data)
+    skynet.error("接收一条客户端消息 ",msg_id,user_data)
+    local func = string.gsub(msg_id, '/', '')
+    if func ~= "login" then
+       if not  s.resp.account_is_other_user_login(source,user_data.user_id,user_data.index) then
+       
+       else
+            skynet.error("用户被挤掉",user_data.user_id)
+            return tools.response(fd,200,cjson.encode({code=999,msg = "您的账号被其他用户登录!"}))
+       end
+    end
+    if s.resp[func] ~=nil then
+        return s.resp[func](fd,msg_body,user_data)
+    end
+    return tools.response(fd,200,string.format("接口 %s 不存在",func))
+end
+
+s.start(...)

+ 12 - 0
service/backmgr/back_response.lua

@@ -0,0 +1,12 @@
+local skynet = require "skynet"
+local cjson = require "cjson"
+local crypt = require "client.crypt"
+local tools = require "tools"
+local M = {
+
+}
+
+M.response = function()
+    
+end
+return M

+ 304 - 0
service/backmgr/init.lua

@@ -0,0 +1,304 @@
+local skynet = require "skynet"
+local s = require "service"
+local tools = require "tools"
+local cjson = require "cjson"
+local mysql = require "skynet.db.mysql"
+local runconfig = require("run_config")
+local back_response = require "back_response"
+local db = nil
+
+--数据库
+
+--数据库end
+
+
+--接口
+
+s.resp.admin_login = function(msg_body,fd)
+    local isOk,key = tools.checkData({"account","password"},msg_body)
+    if not isOk then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: '%s'.", key)}))
+    end
+    skynet.error("msg_body")
+    if msg_body.account == "zhuoyueweizhong2024" and msg_body.password == "zywz123" then
+        return tools.response(fd,200,cjson.encode({code=10000,msg = "成功!",data={user_name="卓越微众"}}))
+    else
+        return tools.response(fd,200,cjson.encode({code=10001,msg = "登陆失败,密码错误!"}))
+    end
+    tools.dump(msg_body)
+end
+
+--添加用户
+s.resp.add_user = function(msg_body,fd)
+    local isOk,key = tools.checkData({"account","password","user_name","group_id","permit_id"},msg_body)
+    if not isOk then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: '%s'.", key)}))
+    end
+    local user_data = nil
+    isOk,user_data =  skynet.call("dbmgr","lua","on_recv","select_user_by_account",msg_body.account)
+    if isOk then
+        return tools.response(fd,200,string.format("用户 %s 已存在",msg_body.account))
+    end
+    isOk = skynet.call("dbmgr","lua","on_recv","add_new_user",msg_body)
+    if not isOk then
+        return tools.response(fd,200,"创建失败!")
+    end
+    return tools.response(fd,200,cjson.encode({code=10000,msg = "创建成功!"}))
+end
+
+--修改用户
+s.resp.modify_user = function(msg_body,fd)
+    local isOk,key = tools.checkData({"user_id","modify_password","modify_permissions_id","modify_group_id","is_ban","user_name"},msg_body)
+    if not isOk then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: '%s'.", key)}))
+    end
+    function action(isOk)
+        if isOk then
+            return tools.response(fd,200,cjson.encode({code=10000,msg = "修改用户成功!"}))
+        end
+        return tools.response(fd,200,cjson.encode({code=10001,msg = "修改用户失败!"}))
+    end
+    local sql = string.format("UPDATE users SET password ='%s' ,group_id = %d ,permit_id = %d , is_ban = %d  , name = '%s' WHERE id = %d ",msg_body.modify_password,msg_body.modify_group_id,msg_body.modify_permissions_id,msg_body.is_ban,msg_body.user_name,msg_body.user_id)
+    db:query(sql)
+    skynet.error(sql)
+    action(true)
+end
+
+--获取用户列表
+s.resp.get_user_list = function(msg_body,fd)
+    local isOk,key = tools.checkData({"page","count"},msg_body)
+    if not isOk then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: '%s'.", key)}))
+    end
+
+    function action(isOk,list)
+        local error_json = '{"code": 10000,   "msg": "获取用户列表失败",  "data": [] }'
+        if isOk then
+            local _list = {}
+            local total_count = 0 
+            list ,total_count = tools.getPageData(msg_body.page,msg_body.count,list)
+            if #list<=0  then
+                return tools.response(fd,200,error_json)
+            end
+            return tools.response(fd,200,cjson.encode({code=10000,msg = "获取用户列表成功",data=list}))
+        end
+        return tools.response(fd,200,error_json)
+    end
+    local sql = string.format("select * from users")
+    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.add_permissions = function(msg_body,fd)
+    local isOk,key = tools.checkData({"permissions_name","permissions_describe","permissions_json"},msg_body)
+    if not isOk then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: '%s'.", key)}))
+    end
+
+    function action(isOk)
+        if isOk then
+            return tools.response(fd,200,cjson.encode({code=10000,msg = "添加权限成功!"}))
+        end
+        return tools.response(fd,200,cjson.encode({code=10001,msg = "添加权限失败!"}))
+    end
+    local permissions_json = msg_body.permissions_json
+    local sql = string.format("INSERT INTO permissions_list_tab (permissions_name, permissions_describe, info) VALUES ('%s','%s','%s')",msg_body.permissions_name,msg_body.permissions_describe,permissions_json)
+    local res = db:query(sql)
+    skynet.error(sql)
+    action(true)
+end
+
+--修改权限
+s.resp.modify_permissions = function(msg_body,fd)
+    local isOk,key = tools.checkData({"permissions_id","modify_permissions_name","modify_permissions_describe","modify_permissions_json"},msg_body)
+    if not isOk then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: '%s'.", key)}))
+    end
+    function action(isOk)
+        if isOk then
+            return tools.response(fd,200,cjson.encode({code=10000,msg = "修改权限权限成功!"}))
+        end
+        return tools.response(fd,200,cjson.encode({code=10001,msg = "修改权限权限失败!"}))
+    end
+    local permissions_json = msg_body.modify_permissions_json
+    -- skynet.error("json",msg_body.modify_permissions_json)
+    local sql = string.format("UPDATE permissions_list_tab SET permissions_name ='%s' ,permissions_describe ='%s' , info ='%s'  WHERE id = %d ",msg_body.modify_permissions_name,msg_body.modify_permissions_describe,permissions_json,msg_body.permissions_id)
+    db:query(sql)
+    skynet.error(sql)
+    action(true)
+end
+
+--获取权限列表
+s.resp.get_permissions_list = function(msg_body,fd)
+
+    local isOk,key = tools.checkData({"page","count"},msg_body)
+    if not isOk then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: '%s'.", key)}))
+    end
+
+    function action(isOk,list)
+        local error_json = '{"code": 10000,   "msg": "获取权限列表失败",  "data": [] }'
+        if isOk then
+            local _list = {}
+            local total_count = 0 
+            list ,total_count = tools.getPageData(msg_body.page,msg_body.count,list)
+            if #list<=0  then
+                return tools.response(fd,200,error_json)
+            end
+            return tools.response(fd,200,cjson.encode({code=10000,msg = "获取权限列表成功",data=list,total_count=total_count}))
+        end
+        return tools.response(fd,200,error_json)
+    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.add_group = function(msg_body,fd)
+    local isOk,key = tools.checkData({"group_name","group_describe","info"},msg_body)
+    if not isOk then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: '%s'.", key)}))
+    end
+
+    function action(isOk)
+        if isOk then
+            return tools.response(fd,200,cjson.encode({code=10000,msg = "添加部门成功!"}))
+        end
+        return tools.response(fd,200,cjson.encode({code=10001,msg = "添加部门失败!"}))
+    end
+    local info = "{}"
+    local sql = string.format("INSERT INTO group_list_tab (group_name, group_describe, info) VALUES ('%s','%s','%s')",msg_body.group_name,msg_body.group_describe,info)
+    local res = db:query(sql)
+    skynet.error(sql)
+    action(true)
+end
+
+--修改部门
+s.resp.modify_group = function(msg_body,fd)
+    local isOk,key = tools.checkData({"group_id","modify_name","modify_describe","info"},msg_body)
+    if not isOk then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: '%s'.", key)}))
+    end
+    function action(isOk)
+        if isOk then
+            return tools.response(fd,200,cjson.encode({code=10000,msg = "修改权限权限成功!"}))
+        end
+        return tools.response(fd,200,cjson.encode({code=10001,msg = "修改权限权限失败!"}))
+    end
+    local info = "{}"
+    local sql = string.format("UPDATE group_list_tab SET group_name ='%s' ,group_describe ='%s' , info ='%s'  WHERE id = %d ",msg_body.modify_name,msg_body.modify_describe,info,msg_body.group_id)
+    db:query(sql)
+    action(true)
+end
+
+--获取部门列表
+s.resp.get_group_list = function(msg_body,fd)
+    local isOk,key = tools.checkData({"page","count"},msg_body)
+    if not isOk then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: '%s'.", key)}))
+    end
+
+    function action(isOk,list)
+        local error_json = '{"code": 10000,   "msg": "获取部门列表失败",  "data": [] }'
+        if isOk then
+            local _list = {}
+            local total_count = 0 
+            list ,total_count = tools.getPageData(msg_body.page,msg_body.count,list)
+            if #list<=0  then
+                return tools.response(fd,200,error_json)
+            end
+            return tools.response(fd,200,cjson.encode({code=10000,msg = "获取部门列表成功",data=list}))
+        end
+        return tools.response(fd,200,error_json)
+    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.modify_classification = function(msg_body,fd)
+    local isOk,key = tools.checkData({"info"},msg_body)
+    if not isOk then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: '%s'.", key)}))
+    end
+    function action(isOk)
+        if isOk then
+            return tools.response(fd,200,cjson.encode({code=10000,msg = "修改权限权限成功!"}))
+        end
+        return tools.response(fd,200,cjson.encode({code=10001,msg = "修改权限权限失败!"}))
+    end
+    local info = msg_body.info
+    local sql = string.format("UPDATE classification_list_tab SET info ='%s' WHERE self_id = 1 ",info)
+    -- skynet.error("sql",sql)
+    db:query(sql)
+    action(true)
+end
+--接口end
+s.resp.on_recv = function (source, fd, msg_id, msg_body)
+    skynet.error("接收一后台消息 ",msg_id)
+    -- tools.dump(msg_body)
+    local func = string.gsub(msg_id, '/back/', '')
+    if s.resp[func] ~=nil then
+        msg_body = cjson.decode(msg_body)
+        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") 
+        skynet.error(" 初始化后台服务成功!")       
+    end
+end
+s.start(...)

+ 293 - 0
service/config_mgr/init.lua

@@ -0,0 +1,293 @@
+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(...)

+ 1426 - 0
service/dbmgr/init.lua

@@ -0,0 +1,1426 @@
+local skynet = require "skynet"
+local s = require "service"
+local mysql = require "skynet.db.mysql"
+local runconfig = require("run_config")
+local db = nil
+local cjson = require "cjson"
+local tools = require "tools"
+
+s.resp.parse_template_info = function(info,template_info)
+    --片头
+    local head_video = {}
+    local type = 1     --	类型 1=片头视频,2=视频,3=片尾视频,4=bgm音频,5=片尾音频,6=图片
+    local video_crop_time = info.video_crop_time
+    local ratio = info.ratio
+    local user_id = info.user_id
+    -- skynet.error("(info.template_info",info.template_info)
+    -- if template_info.piantou_video_data.is_random then --说明选择的是随机
+    --     local folder_list = template_info.piantou_video_data.random_folder_list
+    --     if folder_list ==nil or #folder_list ==0 then
+    --         skynet.error("开始随机生成全部片头")
+    --         --说明选择的全部随机
+    --         local isOk,list = s.resp.get_random_res_by_type(user_id,1,ratio,0)
+    --         if not isOk then
+    --             skynet.error("缺少片头资源!")
+    --         else
+    --             if #list>=1 then
+    --                 skynet.error("获取全部随机的一个指定片头")
+    --                 table.insert(head_video,1,{video_id =list[1].id,path =cjson.decode( list[tools.getRandomIndex(list)].file_info).path,duration=list[1].duration })
+    --                 tools.dump(head_video)
+    --             end
+    --         end 
+    --     else -- 说明选择了指定文件夹随机
+    --         local isOk,list = s.resp.get_random_res_by_folder_list(1,ratio,folder_list,0,user_id)
+    --         if not isOk then
+    --             skynet.error("缺少片头资源!")
+    --         else
+    --             if #list>=1 then
+    --                 table.insert(head_video,1,list[tools.getRandomIndex(list)])
+    --             end
+    --         end 
+    --     end
+    -- else 
+    --     if template_info.piantou_video_data.is_specified then --说明是指定了文件
+    --         local isok,item = s.resp.get_res_file_by_id(template_info.piantou_video_data.specified_res_list[1].file_id)
+    --         if isok then
+    --             table.insert(head_video,1,item)
+    --         end
+    --     else
+    --         skynet.error("参数错误!没有指定随机也没指定固定文件")
+    --     end
+    -- end
+
+    if  template_info.piantou_video_data.random_folder_resource_data~=nil then
+        local data = template_info.piantou_video_data.random_folder_resource_data
+        table.insert(head_video,1,{video_id =data.info.id,path =data.info.path,duration=data.info.duration,info=data })
+        -- table.insert(head_video,1,data)
+    end
+
+    if #head_video <= 0 then
+        skynet.error("片头是空的")
+    end
+
+    --内容
+    local content_video = {}
+    local json_info = cjson.decode(info.template_info)
+    -- skynet.error("json_info.subtitles_audio_duration",json_info.subtitles_audio_duration)
+    -- skynet.error("head_video[1]",head_video[1].duration)
+    -- tools.dump(json_info.subtitles_audio_duration)   
+    -- skynet.error("head_video[1]",head_video[1].info)
+    -- tools.dump(head_video[1].info)
+    local need_num = math.floor((json_info.subtitles_audio_duration  - head_video[1].duration) / (video_crop_time)) +1
+    if template_info.content_video_data.is_random then --说明选择的是随机
+        local folder_list = template_info.content_video_data.random_folder_list
+        if folder_list ==nil or #folder_list ==0 then
+            --说明选择的全部随机
+            local isOk,list = s.resp.get_random_res_by_type(user_id,2,ratio,(video_crop_time+5))
+            if not isOk then
+               return skynet.error("缺少内容资源!")
+            else
+                skynet.error("need_num",need_num)
+                if need_num>#list then
+                     skynet.error("缺少内容资源!")
+                end
+                local random_array = tools.getRandomArray(list)
+                -- skynet.error("random_array")
+                -- tools.dump(random_array)
+                for i = 1, need_num, 1 do
+                    local random_index = random_array[i]
+                    table.insert(content_video,i,{video_id =list[random_index].id,path =cjson.decode( list[random_index].file_info).path,duration=list[random_index].duration,info = list[random_index].file_info })
+                    -- table.insert(content_video,i,list[random_index].file_info)
+                end
+            end 
+        else -- 说明选择了指定文件夹随机
+            local isOk,list = s.resp.get_random_res_by_folder_list(2,ratio,folder_list,(video_crop_time+5),user_id)
+            if not isOk then
+                return skynet.error("缺少内容资源!")
+             else
+                 if need_num>#list then
+                      skynet.error("缺少内容资源!")
+                 end
+                 local random_array = tools.getRandomArray(list)
+                 for i = 1, need_num, 1 do
+                    local random_index = random_array[i]
+                    table.insert(content_video,i,{video_id =list[random_index].id,path =cjson.decode( list[random_index].file_info).path,duration=list[random_index].duration ,info = list[random_index].file_info})
+                    -- table.insert(content_video,i,list[random_index].file_info)
+                end
+             end 
+        end
+    else 
+        if template_info.content_video_data.is_specified then --说明是指定了文件
+            local specified_res_list = template_info.content_video_data.specified_res_list
+            if #specified_res_list<need_num  then
+                skynet.error("指定文件缺少",need_num)
+            else
+                for i = 1, #specified_res_list, 1 do
+                    local isok,item = s.resp.get_res_file_by_id(specified_res_list[1].file_id)
+                    if isok then
+                        -- table.insert(content_video,i, item.file_info)
+                        table.insert(head_video,i,{video_id =item.id,path =cjson.decode( item.file_info).path,duration=item.duration,info =  item.file_info})
+                    end
+                end
+            end
+        else
+            skynet.error("参数错误!没有指定随机也没指定固定文件")
+        end
+    end
+
+    --片尾
+    local end_video = {}
+    -- if template_info.pianwei_video_data.is_random then --说明选择的是随机
+    --     local folder_list = template_info.pianwei_video_data.random_folder_list
+    --     if folder_list ==nil or #folder_list ==0 then
+    --         --说明选择的全部随机
+    --         local isOk,list = s.resp.get_random_res_by_type(user_id,3,ratio,0)
+    --         if not isOk then
+    --            return skynet.error("缺少片尾资源!")
+    --         else
+    --             if #list>=1 then
+    --                 table.insert(end_video,1,{video_id =list[1].id,path =cjson.decode( list[tools.getRandomIndex(list)].file_info).path,duration=list[1].duration })
+    --             end
+    --         end 
+    --     else -- 说明选择了指定文件夹随机
+    --         local isOk,list = s.resp.get_random_res_by_folder_list(3,ratio,folder_list,0,user_id)
+    --         if not isOk then
+    --            return skynet.error("缺少片尾资源!")
+    --         else
+    --             if #list>=1 then
+    --                 table.insert(end_video,1,{video_id =list[1].id,path =cjson.decode( list[tools.getRandomIndex(list)].file_info).path,duration=list[1].duration })
+    --             end
+    --         end 
+    --     end
+    -- else 
+    --     if template_info.pianwei_video_data.is_specified then --说明是指定了文件
+    --         local isok,item = s.resp.get_res_file_by_id(template_info.pianwei_video_data.specified_res_list[1].file_id)
+    --         if isok then
+    --             table.insert(end_video,1,item)
+    --         end
+    --     else
+    --         skynet.error("参数错误!没有指定随机也没指定固定文件")
+    --     end
+    -- end
+    if  template_info.pianwei_video_data.random_folder_resource_data~=nil then
+        local data = template_info.pianwei_video_data.random_folder_resource_data
+        table.insert(end_video,1,{video_id =data.info.id,path =data.info.path,duration=data.info.duration,info = data })
+        -- table.insert(end_video,1,data)
+    end
+    if #end_video<=0 then
+        skynet.error("添加片尾资源失败")
+    end
+
+    --BGM音效
+    local bgm_audio = {}
+    -- if template_info.bgm_audio_data.is_random then --说明选择的是随机
+    --     local folder_list = template_info.bgm_audio_data.random_folder_list
+    --     if template_info.bgm_audio_data.random_folder_list ==nil or #template_info.bgm_audio_data.random_folder_list ==0 then
+    --         --说明选择的全部随机
+    --         local isOk,list = s.resp.get_random_res_by_type(user_id,4,ratio,0)
+    --         if not isOk then
+    --             skynet.error("缺少BGM音效资源!")
+    --         else
+    --             if #list>=1 then
+    --                 table.insert(bgm_audio,1,{video_id =list[1].id,path =cjson.decode( list[tools.getRandomIndex(list)].file_info).path,duration=list[1].duration })
+    --             end
+    --         end 
+    --     else -- 说明选择了指定文件夹随机
+    --         local isOk,list = s.resp.get_random_res_by_folder_list(4,ratio,folder_list,0,user_id)
+    --         if not isOk then
+    --             skynet.error("缺少BGM音效资源!")
+    --         else
+    --             if #list>=1 then
+    --                 table.insert(bgm_audio,1,{video_id =list[1].id,path =cjson.decode( list[tools.getRandomIndex(list)].file_info).path,duration=list[1].duration })
+    --             end
+    --         end 
+    --     end
+    -- else 
+    --     if template_info.bgm_audio_data.is_specified then --说明是指定了文件
+    --         local isok,item = s.resp.get_res_file_by_id(template_info.bgm_audio_data.specified_res_list[1].file_id)
+    --         if isok then
+    --             table.insert(bgm_audio,1,item)
+    --         end
+    --     else
+    --         skynet.error("参数错误!没有指定随机也没指定固定文件")
+    --     end
+    -- end
+    if  template_info.bgm_audio_data.random_folder_resource_data~=nil then
+        local data = template_info.bgm_audio_data.random_folder_resource_data
+        table.insert(bgm_audio,1,{video_id =data.info.id,path =data.info.path,duration=data.info.duration,info = data })
+        -- table.insert(bgm_audio,1,data)
+    end
+    return head_video,content_video,end_video,bgm_audio
+end
+
+s.resp.getUserById = function(id)
+    
+end
+
+s.resp.updateUserInfoById = function(id)
+    
+end
+
+s.resp.createUser = function()
+    
+end
+
+s.resp.deleteUserById = function(id)
+    
+end
+
+s.resp.verify = function(msg_body)
+    local isok = false
+    local user_data = nil
+    isok,user_data = s.resp.select_user_by_account(msg_body.account)
+    if not isok or user_data==nil then
+        return isok,user_data
+    end
+    isok = false
+    if msg_body.password==user_data.password then
+ 
+        isok = true
+        -- user_data = {user_id=1,user_name="小丑"}
+    end
+    return isok,user_data
+end
+
+s.resp.select_user_by_account = function(account) 
+    local sql = string.format("select * from users where account = '%s'",account)
+    skynet.error("sql",sql)
+    local res = db:query(sql)
+      -- 判断是否找到数据
+    if res and #res > 0 then
+        local tab = tools.getDbResData(res)
+        skynet.error("Found data:",tab)
+        return true,tab
+    else
+        skynet.error("No data found.")
+        return false,nil
+    end
+
+    -- tools.dump(res)
+
+end
+
+s.resp.select_user_by_user_id = function(user_id) 
+    
+end
+
+s.resp.add_new_user = function(msg_body)
+    -- skynet.error("msg_body",msg_body.group_type)
+   local sql = string.format("INSERT INTO users (name,account, password,permit_id,group_id) VALUES ('%s', '%s','%s',%d,%d)",msg_body.user_name,msg_body.account,msg_body.password,msg_body.permit_id,msg_body.group_id)
+   local res = db:query(sql)
+   return true
+end
+--- 新建文件夹
+s.resp.new_folder = function(msg_body,fd)
+    skynet.fork(function(_fd)
+        local sql = string.format("INSERT INTO folder_list_tab (user_id,folder_name, folder_type,is_public,classification_id) VALUES (%d, '%s',%d,%d,%d)",msg_body.user_id,msg_body.folder_name,msg_body.folder_type,msg_body.is_public,msg_body.classification_id)
+        -- skynet.error(sql)
+        local res = db:query(sql)
+        tools.response_db_new_folder(_fd,true)
+    end,fd)
+    return true 
+end
+--获取资源文件夹列表
+s.resp.folder_list = function(msg_body,fd)
+    skynet.fork(function(_fd)
+        local sql = string.format("select * from folder_list_tab where user_id = %d AND folder_type = %d AND classification_id = %d",msg_body.user_id,msg_body.type,msg_body.classification_id)
+        local res = db:query(sql)
+        -- skynet.error('folder_list',sql)
+        -- 判断是否找到数据
+        if res and #res > 0 then
+            local tab =  {}
+            if #res == 1 then
+                tab[1] = tools.getDbResData(res)
+            else
+                tab = tools.getDbResData(res)
+            end
+            
+            skynet.error("Found data:")
+            -- tools.dump(tab)
+            -- return true,tab
+            tools.response_db_folder_list(_fd,msg_body,true,tab)
+        else
+            skynet.error("No data found.")
+            tools.response_db_folder_list(_fd,msg_body,false,nil)
+            -- return false,nil
+        end
+    end,fd)
+    return true 
+end
+
+--获取文件夹列表每个文件夹的文件数量
+s.resp.folder_res_list_nums = function(folder_list,fd,total_count)
+    skynet.fork(function(_fd)
+        local temp ={}
+        for i = 1, #folder_list, 1 do
+            local msg_body = folder_list[i]
+            -- tools.dump(msg_body)
+            local sql = string.format("select * from res_list_tab where user_id = %d AND folder_id = %d AND is_public = %d AND is_delete = 0",msg_body.user_id,msg_body.id,msg_body.is_public)
+            local res = db:query(sql)
+            local count = 0
+            if res and #res > 0 then
+                count = #res
+                skynet.error("Found data:")
+                -- tools.dump(tab)
+                -- return true,tab
+            else
+                skynet.error("No data found.",msg_body.id)
+            end
+            temp[msg_body.id] = count
+            -- table.insert(temp,msg_body.id,count)
+        end
+        tools.response_db_folder_list_nums(_fd,folder_list,temp,total_count)
+    end,fd)
+end
+--获取指定文件夹内的资源列表
+s.resp.folder_res_list = function(msg_body,fd,call_back)
+    skynet.fork(function(_fd) 
+        local sql_duration = ""
+        if msg_body.duration~=nil then
+            sql_duration = string.format("AND duration >= %d",msg_body.duration)
+        end
+        local sql = string.format("select * from res_list_tab where user_id = %d AND folder_id = %d AND is_public = %d  AND is_delete = 0"..sql_duration,msg_body.user_id,msg_body.folder_id,msg_body.is_public)
+        local res = db:query(sql)
+        skynet.error('folder_res_list',sql)
+        -- 判断是否找到数据
+        if res and #res > 0 then
+            local tab =  {}
+            if #res == 1 then
+                tab[1] = tools.getDbResData(res)
+            else
+                tab = tools.getDbResData(res)
+            end
+            
+            skynet.error("Found data:")
+            if not call_back and _fd~=nil then
+                tools.response_db_folder_res_list(_fd,msg_body,true,tab)
+            else
+                if call_back ~=nil then
+                    call_back(tab)
+                end
+            end
+           
+            -- tools.dump(tab)
+            -- return true,tab
+        else
+            skynet.error("No data found.",call_back)
+            if  call_back == nil  and _fd~=nil then
+                tools.response_db_folder_res_list(_fd,msg_body,false,nil)
+            else
+                if call_back ~=nil then
+                    call_back({})
+                end
+            end
+            
+            -- return false,nil
+        end
+    end,fd)
+    return true
+end
+s.resp.on_recv = function (source, msg_id, msg_body,fd,...)
+    if db==nil then
+        return false,nil
+    end
+    if s.resp[msg_id]==nil then
+        return false,nil
+    end
+    return s.resp[msg_id](msg_body,fd,...)
+end
+
+--添加资源数据到表里
+s.resp.add_res_file = function(msg_body)
+    skynet.fork(function()
+        local temp = '{"width": 100, "height": 100, "duration": 123}'
+        temp = cjson.encode(msg_body)
+        local duration = 0
+        if msg_body.duration~=nil then
+            duration = tonumber(msg_body.duration)
+        end
+        local sql = string.format("INSERT INTO res_list_tab (user_id, folder_id, file_type, file_name, is_public,file_info,duration,classification_id) VALUES (%d, %d, %d, '%s',%d,'%s',%f,%d)",msg_body.user_id,msg_body.folder_id,msg_body.stype,msg_body.file_name,msg_body.is_public,temp,duration,msg_body.classification_id)
+        local res = db:query(sql)
+    end)
+    return true
+end
+
+--更改文件夹名
+s.resp.reset_folder_name = function(msg_body)
+    local isOk = s.resp.get_res_folder_by_id(msg_body.folder_id)
+    if not isOk then
+        return false
+    end
+    local sql = string.format("UPDATE folder_list_tab SET folder_name ='%s' WHERE id = %d  AND is_public = %d",msg_body.name,msg_body.folder_id,msg_body.is_public)
+    db:query(sql)
+    return true
+end
+
+--更改资源文件名
+s.resp.reset_res_name = function(msg_body)
+    local isOk = s.resp.get_res_file_by_id(msg_body.file_id)
+    if not isOk then
+        return false
+    end
+    local sql = string.format("UPDATE res_list_tab SET file_name ='%s' WHERE id = %d AND folder_id = %d AND is_public = %d  AND is_delete = 0",msg_body.name,msg_body.file_id,msg_body.folder_id,msg_body.is_public)
+    db:query(sql)
+    return true
+end
+
+--根据id获取资源 
+s.resp.get_res_file_by_id = function(file_id)
+    local sql = string.format("select * from res_list_tab where id = %d  AND is_delete = 0",file_id)
+    -- skynet.error("sql",sql)
+    local res = db:query(sql)
+      -- 判断是否找到数据
+    if res and #res > 0 then
+        local tab = tools.getDbResData(res)
+        skynet.error("Found data:",tab)
+        return true,tab
+    else
+        skynet.error("No data found.")
+        return false,nil
+    end
+end
+
+--根据id获取文件夹 
+s.resp.get_res_folder_by_id = function(folder_id)
+    local sql = string.format("select * from folder_list_tab where id = %d ",folder_id)
+    -- skynet.error("sql",sql)
+    local res = db:query(sql)
+      -- 判断是否找到数据
+    if res and #res > 0 then
+        local tab = tools.getDbResData(res)
+        skynet.error("Found data:",tab)
+        return true,tab
+    else
+        skynet.error("No data found.")
+        return false,nil
+    end
+end
+
+--搜索资源 
+s.resp.search_res = function(msg_body,fd)
+    skynet.fork(function(_fd)
+        local sql = string.format("SELECT * FROM res_list_tab WHERE file_type = %d AND file_name LIKE '%%%s%%'  AND is_delete = 0 AND classification_id = %d",msg_body.type ,msg_body.search_content,msg_body.classification_id)
+        skynet.error("sql",sql)
+        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
+            
+            skynet.error("Found data:")
+            -- tools.dump(tab)
+            -- return true,tab
+            tools.response_db_search_res(_fd,msg_body,true,tab)
+        else
+            skynet.error("No data found.")
+            -- return false,nil
+            tools.response_db_search_res(_fd,msg_body,false,nil)
+        end
+    end,fd)
+    return true
+end
+--根据所有文件id查到所有文件的url并删除
+local fork_get_file_list_url_and_delete = function(deleteString,call_back)
+    local sql = string.format("SELECT * FROM res_list_tab WHERE id IN (%s)", deleteString)
+    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
+        
+        skynet.error("Found data:fork_get_file_list_url_and_delete")
+        local url_list = {}
+        local count = 1
+        for i = 1, #tab, 1 do
+            if tab[i].ref_id==0 then
+                local file_info =  cjson.decode(tab[i].file_info)
+                table.insert(url_list,count,file_info.path)
+                count = count + 1
+            end
+        end
+        skynet.send("tools_work","lua","delete_file",url_list)
+        -- tools.dump(url_list)
+        -- return true,tab
+    else
+        skynet.error("No data found.")
+        -- return false,nil
+    end
+
+    if call_back~=nil then
+        call_back()
+    end
+   
+end
+--执行删除文件操作
+local fork_delete_file = function(msg_body)
+    -- tools.dump(msg_body)
+    local listToDelete = {}
+    for i = 1, #msg_body.file_id_list, 1 do
+        table.insert(listToDelete,i,msg_body.file_id_list[i])
+    end
+    local deleteString = table.concat(listToDelete, ',')
+
+    local sql = string.format("UPDATE res_list_tab SET is_delete = %d WHERE id IN (%s)",1,deleteString)
+    db:query(sql)
+
+    skynet.fork(fork_get_file_list_url_and_delete,deleteString,function()
+        local delete_sql = string.format("DELETE FROM res_list_tab WHERE id IN (%s) AND is_public = %d AND user_id = %d", deleteString,msg_body.is_public,msg_body.user_id)
+        db:query(delete_sql)
+    end)
+end
+
+--执行删除文件夹操作
+local fork_delete_folder =  function(msg)
+    for i = 1, #msg.folder_id_list, 1 do
+        local  isok = s.resp.folder_res_list({
+            folder_id = msg.folder_id_list[i],
+            user_id = msg.user_id,
+            is_public=msg.is_public},nil,function(list)
+                -- skynet.error("执行删除文件夹操作",#list)
+                if #list>0 then
+                    local temp = {}
+                    for i = 1, #list, 1 do
+                        table.insert(temp,i,list[i].id)
+                    end
+                    skynet.fork(fork_delete_file,{file_id_list=temp,user_id=msg.user_id,is_public=msg.is_public})
+                end
+            end)
+    end
+end
+
+--删除资源文件
+s.resp.delete_res = function(msg_body)
+    skynet.fork(fork_delete_file,msg_body)
+    return true
+end
+--删除文件夹
+s.resp.delete_folder =function(msg_body)
+    local listToDelete = {}
+    for i = 1, #msg_body.folder_id_list, 1 do
+        table.insert(listToDelete,i,msg_body.folder_id_list[i])
+    end
+    local deleteString = table.concat(listToDelete, ',')
+    local sql = string.format("DELETE FROM folder_list_tab WHERE id IN (%s) AND is_public = %d AND user_id = %d", deleteString,msg_body.is_public,msg_body.user_id)
+    db:query(sql)
+    skynet.fork(fork_delete_folder,msg_body)
+    return true
+end
+--新建模板
+s.resp.create_template = function(msg_body,fd)
+    local template_info = "{}"
+    if msg_body.template_info~=nil then
+        template_info = msg_body.template_info
+    end
+    local sql = string.format("INSERT INTO template_list_tab (user_id,project_name, book_name,ratio,video_stype,subtitles,subtitles_audio,video_nums,video_crop_time,template_info) VALUES (%d, '%s','%s',%d,%d,'%s','%s',%d,%d,'%s')",msg_body.user_id,msg_body.project_name,msg_body.book_name,msg_body.ratio,msg_body.video_stype,msg_body.subtitles,msg_body.subtitles_audio,msg_body.video_nums,msg_body.video_crop_time,template_info)
+    local res = db:query(sql)
+    -- skynet.error("sql",sql)
+    return true
+end
+--获取模板列表
+s.resp.get_template_list = function(msg_body,fd)
+    skynet.fork(function(_fd)
+        local sql = string.format("select * from template_list_tab where user_id = %d AND video_stype = %d",msg_body.user_id,msg_body.video_stype)
+        skynet.error("sql",sql)
+        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
+            skynet.error("Found data:",tab)
+            -- return true,tab
+            tools.response_db_get_template_list(_fd,msg_body,true,tab)
+        else
+            skynet.error("No data found.")
+            -- return false,nil
+            tools.response_db_get_template_list(_fd,msg_body,false,nil)
+        end
+    end,fd)
+    return true
+end
+--删除模板
+s.resp.delete_template = function(msg_body)
+    local listToDelete = {}
+    for i = 1, #msg_body.template_id_list, 1 do
+        table.insert(listToDelete,i,msg_body.template_id_list[i])
+    end
+    local deleteString = table.concat(listToDelete, ',')
+    local sql = string.format("DELETE FROM template_list_tab WHERE id IN (%s) AND user_id = %d", deleteString,msg_body.user_id)
+    db:query(sql)
+    skynet.error(sql)
+    return true
+end
+--保存/修改模板
+s.resp.save_template = function(msg_body,fd)
+    local template_info = "{}"
+    if msg_body.template_info~="" and msg_body.template_info~=nil then
+        template_info = cjson.decode(msg_body.template_info)
+        if template_info.creat_video_list~=nil and template_info.creat_video_list~="" then
+            if #template_info.creat_video_list >0 then
+                for i = 1,  #template_info.creat_video_list, 1 do
+                    if template_info.creat_video_list[i]~=nil then
+                        if template_info.creat_video_list[i].title_html~=nil then
+                            template_info.creat_video_list[i].title_html = tools.base64encode(template_info.creat_video_list[i].title_html)
+                        end
+                    end
+                end
+            end
+        end
+  
+        template_info = cjson.encode(template_info)
+    end
+
+    local sql = string.format("UPDATE template_list_tab SET project_name = '%s' , book_name = '%s' ,ratio = %d, video_stype = %d, subtitles = '%s', subtitles_audio = '%s' ,video_nums = %d, video_crop_time = %d, template_info = '%s'  WHERE id = %d ",msg_body.project_name,msg_body.book_name,msg_body.ratio,msg_body.video_stype,msg_body.subtitles,msg_body.subtitles_audio,msg_body.video_nums,msg_body.video_crop_time,template_info,msg_body.template_id)
+    -- skynet.error("sql",sql)
+    db:query(sql)
+    return true
+end
+--搜索模板
+s.resp.search_template = function(msg_body,fd)
+    skynet.fork(function(_fd)
+        local sql = string.format("SELECT * FROM template_list_tab WHERE user_id = %d AND video_stype = %d AND book_name LIKE '%%%s%%'",msg_body.user_id ,msg_body.video_stype,msg_body.search_content)
+        -- local sql = string.format("select * from template_list_tab where user_id = %d AND video_stype = %d",msg_body.user_id,msg_body.video_stype)
+        skynet.error("sql",sql)
+        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
+            skynet.error("Found data:",tab)
+            -- return true,tab
+            tools.response_db_search_template(_fd,msg_body,true,tab)
+        else
+            skynet.error("No data found.")
+            -- return false,nil
+            tools.response_db_search_template(_fd,msg_body,false,nil)
+        end
+    end,fd)
+    return true
+end
+--根据模板ID获取模板信息
+s.resp.get_template_info_by_id = function(msg_body,fd,call_back) 
+    skynet.fork(function(_fd)
+        local sql = string.format("SELECT * FROM template_list_tab WHERE user_id = %d AND id = %d",msg_body.user_id ,msg_body.template_id)
+        -- local sql = string.format("select * from template_list_tab where user_id = %d AND video_stype = %d",msg_body.user_id,msg_body.video_stype)
+        skynet.error("sql",sql)
+        local res = db:query(sql)
+          -- 判断是否找到数据
+        if res and #res > 0 then
+            local tab = tools.getDbResData(res)
+            skynet.error("Found data:",tab)
+            -- return true,tab
+            if call_back~=nil and fd ==nil then
+                call_back(tab)
+            else
+                tools.response_db_get_template_info_by_id(_fd,msg_body,true,tab)
+            end
+   
+        else
+            skynet.error("No data found.")
+            -- return false,nil
+            if call_back~=nil and fd ==nil then
+                call_back(nil)
+            else
+                tools.response_db_search_template(_fd,msg_body,false,nil)
+            end
+        end
+    end,fd)
+    return true
+end
+--获取指定类型所有文件
+s.resp.get_file_list_by_type = function(msg_body,fd)
+    skynet.fork(function(_fd,_msg_body)
+        local sql_duration = ""
+        if msg_body.duration~=nil then
+            sql_duration = string.format(" AND duration >= %f",msg_body.duration)
+        end
+        local sql = string.format("SELECT * FROM res_list_tab WHERE file_type = %d AND user_id = %d AND is_delete = 0"..sql_duration,msg_body.type,msg_body.user_id)
+        local res = db:query(sql)
+        -- skynet.error(sql)
+        if res and #res > 0 then
+            local tab =  {}
+            if #res == 1 then
+                tab[1] = tools.getDbResData(res)
+            else
+                tab = tools.getDbResData(res)
+            end
+            tools.response_db_get_file_list_by_type(_fd,_msg_body,true,tab)
+            -- return true,tab
+        else
+            skynet.error("No data found.")
+            -- return false,nil
+            tools.response_db_get_file_list_by_type(_fd,_msg_body,false,nil)
+        end
+    end,fd,msg_body)
+end
+
+--随机一个类型,获取相应数量的资源列表
+s.resp.get_random_res_by_type = function(user_id,file_type,classification_id,duration)
+    local sql = string.format("SELECT *FROM res_list_tab WHERE file_type = %d  AND is_delete = 0 AND classification_id = %d AND duration>= %f AND user_id = %d", file_type,classification_id,duration,user_id)
+    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
+        -- local test = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
+        -- tools.shuffle(tab)
+        -- tools.dump(test)
+        -- tools.dump(tab)
+        return true,tab
+    else
+        skynet.error("No data found.")
+        return false,nil
+    end
+end
+
+--获取一个类型,指定在文件夹列表里随机
+s.resp.get_random_res_by_folder_list = function(file_type,classification_id,folder_list,duration,user_id)
+    local listToSelect = {}
+    for i = 1, #folder_list, 1 do
+        table.insert(listToSelect,i,folder_list[i].folder_id)
+    end
+    local selectString = table.concat(listToSelect, ',')
+    skynet.error("file_type",file_type)
+    skynet.error("classification_id",classification_id)
+    skynet.error("folder_list")
+    tools.dump(folder_list)
+    skynet.error("user_id",user_id)
+    local sql = string.format("SELECT* FROM res_list_tab WHERE file_type = %d  AND is_delete = 0 AND classification_id = %d AND duration>= %f AND user_id = %d AND folder_id in(%s)", file_type,classification_id,duration,user_id,selectString)
+    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
+        -- tools.dump(tab)
+        return true,tab
+    else
+        skynet.error("No data found.")
+        return false,nil
+    end
+end
+
+--生成视频数据库
+s.resp.generate_video = function(msg_body,fd)
+    s.resp.get_template_info_by_id(msg_body,nil,function(tab)
+        -- tools.dump(tab)
+        if tab ~=nil then
+            local isOk,error_info = s.resp.check_template_isRight(tab)
+            if  not isOk then
+                
+                return  tools.response(fd,200,error_info)
+            end
+            -- tools.dump(tab)
+            local user_id = msg_body.user_id
+            local template_id = msg_body.template_id
+            local file_name = tab.book_name
+            local video_stype = tab.video_stype
+            --先查找是否有这个名的文件夹
+            local sql = string.format("SELECT * FROM generate_video_folder_list_tab WHERE user_id = %d  AND book_name = '%s' AND video_stype = %d ",user_id,file_name,video_stype)
+            local res = db:query(sql)
+            local info = tools.getDbResData(res)
+            local write_video_db = function(folder_id)
+                skynet.error("开始生成",folder_id)
+                local template_info = cjson.decode(tab.template_info)
+                local gen_num = #template_info.creat_video_list
+                local custom = {}
+                if template_info.custom~=nil and template_info.custom~="" then
+                    custom = template_info.custom
+                end
+                -- skynet.error("custom")
+                -- tools.dump(custom)
+                for i = 1, gen_num, 1 do  -- 模拟数据每次生成5条 
+                    local item_info = template_info.creat_video_list[i]
+                    local head_video,content_video,end_video,bgm_audio = s.resp.parse_template_info(tab,item_info)
+                    -- tools.dump(head_video)
+                    -- tools.dump(content_video)
+                    -- tools.dump(end_video)
+                    -- tools.dump(bgm_audio)
+                    local is_corner_mark = item_info.is_corner_mark
+                    local is_video_bottom_text = item_info.is_video_bottom_text
+                    local hot_tag_type = 0
+                    local item_custom = {}
+                    
+                    if item_info.custom~=nil and item_info.custom~="" then
+                        item_custom = item_info.custom
+                    end
+                    
+
+                    if is_corner_mark then
+                        hot_tag_type = 1
+                    end
+
+                    local fictitious_tag_type = 0
+                    if is_video_bottom_text then
+                        fictitious_tag_type = 1
+                    end
+                    local gen_info = {user_id=0,id=0,project_name=tab.project_name,
+                    book_name=tab.book_name,
+                    ratio=tab.ratio,
+                    video_stype=tab.video_stype,
+                    crop_time=tab.video_crop_time,
+                    marketing_title_info={marketing_title_top_h = 0,stroke_h=0,marketing_title=tools.base64decode(item_info.title_html)},
+                    video_list = content_video,
+                    subtitles = {stype=0,subtitle_font="",subtitles_path=template_info.subtitles_path},
+                    subtitles_audio={path = template_info.subtitles_audio_path,duration=template_info.subtitles_audio_duration },
+                    video_last_frame =end_video[1],
+                    video_first_frame = head_video[1],
+                    bgm_list = bgm_audio[1],
+                    hot_tag = {type=hot_tag_type,path=""}, --上边
+                    fictitious_tag = {type=fictitious_tag_type,path=""}, --下边
+                    custom = custom,
+                    video_custom = item_custom,
+                    }
+                   
+                    local video_name =  gen_info.book_name.."__视频"..i
+                    local book_name =  gen_info.book_name
+                    local ratio = gen_info.ratio
+                    local video_stype = gen_info.video_stype
+                    local video_url = ""
+                    local generate_video_info = {}
+                    generate_video_info =item_info 
+                    generate_video_info.book_name = tab.book_name
+                    generate_video_info.project_name = tab.project_name
+                    generate_video_info.ratio = tab.ratio
+                    generate_video_info.video_stype = tab.video_stype
+                    generate_video_info = cjson.encode(generate_video_info)
+                    local video_state = 0
+                    sql = string.format("INSERT INTO generate_video_list_tab (user_id,template_id, folder_id,video_name,book_name,ratio,video_stype,video_url,video_state,generate_video_info) VALUES (%d,%d,%d,'%s','%s',%d,%d,'%s',%d,'%s')",user_id,
+                    template_id,
+                    folder_id,
+                    video_name,
+                    book_name,
+                    ratio,
+                    video_stype,
+                    video_url,video_state,generate_video_info)
+                    -- skynet.error("123sss")
+                    -- tools.dump(gen_info)
+                    db:query(sql)
+                    -- skynet.error(sql)
+                    sql = string.format("SELECT * FROM generate_video_list_tab WHERE user_id = %d and folder_id = %d and is_use = 0  LIMIT 1",user_id,folder_id)
+                    res = db:query(sql)
+                    if res and #res > 0 then
+                        local tab =  {}
+                        if #res > 0 then
+                            tab = tools.getDbResData(res)
+                            gen_info.id = tab.id
+                            gen_info.user_id = user_id
+                            sql = string.format("UPDATE generate_video_list_tab SET is_use = %d WHERE id =%d",1,gen_info.id)
+                            db:query(sql)
+                            skynet.send("tools_work","lua","generate_video",gen_info)
+                        end
+                        -- return true,tab
+                    else
+                        skynet.error("No data found.")
+                    end
+      
+                end
+
+                --获取5个未使用的生成视频文件
+                tools.response_db_generate_video(fd,true)
+            end
+            if res and #res > 0 then       --存在这个文件夹,直接写入到这个文件夹
+                local folder_id = info.id
+                write_video_db(folder_id)
+            else -- 没有这个文件夹则创建一个
+                sql = string.format("INSERT INTO generate_video_folder_list_tab (user_id,book_name, generate_video_info,video_stype) VALUES (%d, '%s','%s' ,%d)",user_id,file_name,"{}",video_stype)
+                db:query(sql)
+                --查找新建的文件夹id
+                sql = string.format("SELECT * FROM generate_video_folder_list_tab WHERE user_id = %d  AND book_name = '%s' AND video_stype = %d ",user_id,file_name,video_stype)
+                res = db:query(sql)
+
+                info = tools.getDbResData(res)
+                local folder_id = info.id
+                write_video_db(folder_id)
+            end
+            
+        end
+    end)
+    return true
+end
+
+--获取生成视频文件夹列表
+s.resp.get_generate_video_folder_list = function(msg_body,fd)
+    skynet.fork(function(_fd,_msg_body)
+        local sql = string.format("select * from generate_video_folder_list_tab where user_id = %d AND video_stype = %d",_msg_body.user_id,_msg_body.video_stype)
+        local res = db:query(sql)
+        -- skynet.error('folder_list',sql)
+        -- 判断是否找到数据
+        if res and #res > 0 then
+            local tab =  {}
+            if #res == 1 then
+                tab[1] = tools.getDbResData(res)
+            else
+                tab = tools.getDbResData(res)
+            end
+            
+            skynet.error("Found data:")
+            -- tools.dump(tab)
+            -- return true,tab
+            tools.response_db_generate_video_folder_list(_fd,msg_body,true,tab)
+        else
+            skynet.error("No data found.")
+            tools.response_db_folder_list(_fd,msg_body,false,nil)
+            -- return false,nil
+        end
+    end,fd,msg_body)
+    return true
+end
+
+--获取文件夹内的生成视频
+s.resp.get_video_list_by_folder_id = function(msg_body,fd,call_back)
+    skynet.fork(function(_fd) 
+        local sql = string.format("select * from generate_video_list_tab where user_id = %d AND folder_id = %d  AND is_delete = 0",msg_body.user_id,msg_body.folder_id)
+        local res = db:query(sql)
+        -- skynet.error('folder_res_list',sql)
+        -- 判断是否找到数据
+        if res and #res > 0 then
+            local tab =  {}
+            if #res == 1 then
+                tab[1] = tools.getDbResData(res)
+            else
+                tab = tools.getDbResData(res)
+            end
+            
+            skynet.error("Found data:")
+            if not call_back and _fd~=nil then
+                tools.response_db_get_video_list_by_folder_id(_fd,msg_body,true,tab)
+            else
+                if call_back ~=nil then
+                    call_back(tab)
+                end
+            end
+           
+            -- tools.dump(tab)
+            -- return true,tab
+        else
+            skynet.error("No data found.",call_back)
+            if  call_back == nil  and _fd~=nil then
+                tools.response_db_get_video_list_by_folder_id(_fd,msg_body,false,nil)
+            else
+                if call_back ~=nil then
+                    call_back({})
+                end
+            end
+            
+            -- return false,nil
+        end
+    end,fd)
+    return true
+end
+
+--根据所有生成视频文件id查到所有文件的url并删除
+local fork_get_gen_video_file_list_url_and_delete = function(delete_list,call_back)
+    local url_list = {}
+    for i = 1, #delete_list, 1 do
+       table.insert(url_list,i, delete_list[i].path)
+    end
+    skynet.send("tools_work","lua","delete_file",url_list)
+    if call_back~=nil then
+        call_back()
+    end
+   
+end
+--执行删除生成视频文件操作
+local fork_delete_gen_video_file = function(msg_body)
+    -- tools.dump(msg_body)
+    local listToDelete = {}
+    for i = 1, #msg_body.file_list, 1 do
+        table.insert(listToDelete,i,msg_body.file_list[i].id)
+    end
+    local deleteString = table.concat(listToDelete, ',')
+
+    local sql = string.format("UPDATE generate_video_list_tab SET is_delete = %d WHERE id IN (%s)",1,deleteString)
+    db:query(sql)
+    skynet.fork(fork_get_gen_video_file_list_url_and_delete,msg_body.file_list,function()
+        local delete_sql = string.format("DELETE FROM generate_video_list_tab WHERE id IN (%s) AND user_id = %d", deleteString,msg_body.user_id)
+        db:query(delete_sql)
+        skynet.error(delete_sql)
+    end)
+end
+
+--执行删除生成视频文件夹操作
+local fork_delete_gen_video_folder =  function(msg)
+    for i = 1, #msg.folder_id_list, 1 do
+        local  isok = s.resp.get_video_list_by_folder_id({
+            folder_id = msg.folder_id_list[i],
+            user_id = msg.user_id},nil,function(list)
+                skynet.error("执行删除生成视频文件夹操作",#list)
+                if #list>0 then
+                    local temp = {}
+                    for i = 1, #list, 1 do
+                        table.insert(temp,i,list[i])
+                    end
+                    skynet.fork(fork_delete_gen_video_file,{file_list=temp,user_id=msg.user_id})
+                end
+            end)
+            local delete_sql = string.format("DELETE FROM generate_video_folder_list_tab WHERE id = %d", msg.folder_id_list[i])
+            db:query(delete_sql)
+    end
+end
+
+--删除生成视频文件夹
+s.resp.delete_generate_video_folder = function(msg_body,fd)
+    skynet.fork(fork_delete_gen_video_folder,msg_body,fd)
+    return true
+end
+
+--删除生成视频
+s.resp.delete_generate_video = function(msg_body,fd)
+    local temp = {}
+    msg_body.file_list = {}
+    local listToDelete = {}
+    for i = 1, #msg_body.file_id_list, 1 do
+        table.insert(listToDelete,i,msg_body.file_id_list[i])
+    end
+    local deleteString = table.concat(listToDelete, ',')
+    local sql = string.format("select * from generate_video_list_tab WHERE id IN (%s) AND is_delete = 0",deleteString)
+    local res = db:query(sql)
+    skynet.error(sql)
+    if res and #res > 0 then
+        local tab =  {}
+        if #res == 1 then
+            tab[1] = tools.getDbResData(res)
+        else
+            tab = tools.getDbResData(res)
+        end
+        for i = 1, #tab, 1 do
+            table.insert(msg_body.file_list,i,tab[i])
+        end
+        skynet.fork(fork_delete_gen_video_file,msg_body,fd)
+        skynet.error("Found data:")
+
+    else
+        skynet.error("No data found.")
+    end
+
+    return true
+end
+
+--重命名生成视频文件夹的名字
+s.resp.reset_generate_video_folder_name = function(msg_body,fd)
+    local sql = string.format("UPDATE generate_video_list_tab SET video_name ='%s' WHERE id = %d ",msg_body.name,msg_body.folder_id)
+    db:query(sql)
+    return true
+end
+
+--生成视频搜索
+s.resp.search_generate_video_file = function(msg_body,fd)
+    skynet.fork(function(_fd)
+        -- tools.dump(msg_body)
+        local sql = string.format("SELECT * FROM generate_video_list_tab WHERE   video_name LIKE '%%%s%%'  AND is_delete = 0 AND video_stype = %d" ,msg_body.search_content,msg_body.video_stype)
+        -- skynet.error("sql",sql)
+        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
+            
+            skynet.error("Found data:")
+            -- tools.dump(tab)
+            -- return true,tab
+            tools.response_db_search_generate_video_file(_fd,msg_body,true,tab)
+        else
+            skynet.error("No data found.")
+            -- return false,nil
+            tools.response_db_search_generate_video_file(_fd,msg_body,false,nil)
+        end
+    end,fd)
+    return true
+end
+
+
+--获取生成视频文件夹列表每个文件夹的文件数量
+s.resp.folder_gen_video_list_nums = function(folder_list,fd,total_count)
+    skynet.fork(function(_fd)
+        local temp ={}
+        for i = 1, #folder_list, 1 do
+            local msg_body = folder_list[i]
+            -- tools.dump(msg_body)
+            local sql = string.format("select * from generate_video_list_tab where user_id = %d AND folder_id = %d  AND is_delete = 0",msg_body.user_id,msg_body.id)
+            local res = db:query(sql)
+            local count = 0
+            if res and #res > 0 then
+                count = #res
+                skynet.error("Found data:")
+                -- tools.dump(tab)
+                -- return true,tab
+            else
+                skynet.error("No data found.",msg_body.id)
+            end
+            temp[msg_body.id] = count
+            -- table.insert(temp,msg_body.id,count)
+        end
+        tools.response_db_folder_generate_video_list_nums(_fd,folder_list,temp,total_count)
+    end,fd)
+end
+
+--更新生成视频的状态
+s.resp.update_gen_video_file_status = function(msg_body)
+    local custom = "{}"
+    if msg_body.custom~=nil and msg_body.custom~="" then
+        custom = msg_body.custom
+    end
+    local sql = string.format("UPDATE generate_video_list_tab SET video_url = '%s', path = '%s' , custom = '%s', video_state = %d WHERE id = %d and user_id = %d",msg_body.surl,msg_body.path,custom,msg_body.state,msg_body.id,msg_body.user_id)
+    db:query(sql)
+    skynet.error(sql)
+    return true
+end
+
+--检测指定类型文件是否够数量
+s.resp.checkNumsByType = function(msg_body)
+    local duration = 0
+    if msg_body.duration~= nil then
+        duration = msg_body.duration
+    end
+    local limit = msg_body.limit
+    local type = msg_body.type
+    local sql = string.format("select *from res_list_tab where duration >= %f AND file_type= %d AND user_id = %d LIMIT %d",duration,type,msg_body.user_id,limit)
+    -- skynet.error("sql",sql)
+    local res = db:query(sql)
+    if res and #res > 0 then
+        if #res >= tonumber(limit) then
+            return true
+        end
+        return false
+    else
+        return false
+    end
+end
+
+--修改密码
+s.resp.reset_password = function(msg_body)
+    local sql = string.format("UPDATE users SET password = '%s' WHERE id = %d ",msg_body.new_pw,msg_body.user_id)
+    db:query(sql)
+    return true
+end
+
+--检测是否有此文件
+s.resp.check_have_file = function(msg_body)
+    local sql = string.format("select * from res_list_tab where ref_id = %d  AND is_delete = 0 AND user_id = %d LIMIT 1",msg_body.file_id,msg_body.user_id)
+    -- skynet.error("sql",sql)
+    local res = db:query(sql)
+      -- 判断是否找到数据
+    if res and #res > 0 then
+        local tab = tools.getDbResData(res)
+        skynet.error("Found data:",tab)
+        return true,tab
+    else
+        skynet.error("No data found.")
+        return false,nil
+    end
+end
+
+--检测是否有此文件夹
+s.resp.check_have_folder = function(msg_body)
+    local sql = string.format("select * from folder_list_tab where ref_id = %d AND user_id = %d LIMIT 1",msg_body.folder_id,msg_body.user_id)
+    -- skynet.error("sql",sql)
+    local res = db:query(sql)
+      -- 判断是否找到数据
+    if res and #res > 0 then
+        local tab = tools.getDbResData(res)
+        skynet.error("Found data:",tab)
+        return true,tab
+    else
+        skynet.error("No data found.")
+        return false,nil
+    end
+end
+
+--检查模板是否正常
+s.resp.check_template_isRight = function(info)
+ 
+    local isok  = s.resp.checkNumsByType({
+    duration = 0,
+    type = 1,
+    limit = 1,
+    user_id = info.user_id})
+
+    if not isok then
+        return false,cjson.encode({code=10001,msg = "新建模板失败,片头资源不足!"})
+    end
+
+    isok  = s.resp.checkNumsByType({
+        duration = 0,
+        type = 3,
+        limit = 1,
+        user_id = info.user_id}
+    )
+
+    if not isok then
+        return false,cjson.encode({code=10001,msg = "新建模板失败,片尾资源不足"})
+    end
+
+
+    local subtitles_audio_duration = 0
+
+    if  info.template_info ~=nil and info.template_info~="" then
+       local  template_info = cjson.decode(info.template_info)
+       if  template_info.subtitles_audio_duration~=nil then
+         subtitles_audio_duration = tonumber(template_info.subtitles_audio_duration)
+       end
+    end
+    
+    local duration =  info.video_crop_time + 5
+
+    local limit = math.floor(subtitles_audio_duration/duration)
+    skynet.error("limit",limit)
+    skynet.error("subtitles_audio_duration",subtitles_audio_duration)
+    skynet.error("duration",duration)
+    isok  = s.resp.checkNumsByType({
+        duration = duration,
+        type = 2,
+        limit =limit+1 ,
+        user_id = info.user_id}
+    )
+
+    if not isok then
+        return false,cjson.encode({code=10001,msg = "正片资源不足"})
+    end
+
+
+    isok  = s.resp.checkNumsByType({
+        duration = 0,
+        type = 4,
+        limit = 1,
+        user_id = info.user_id}
+    )
+
+    if not isok then
+        return false,cjson.encode({code=10001,msg = "BGM音效资源不足!"})
+    end
+
+    return true,nil
+end
+
+--接收到删除引用的文件列表信息
+s.resp.recv_ref_file_list_del_info = function(msg_body)
+    skynet.error("接收到删除引用的文件列表信息")
+    local listToDelete = {}
+    for i = 1, #msg_body.file_id_list, 1 do
+        table.insert(listToDelete,i,msg_body.file_id_list[i])
+    end
+    local deleteString = table.concat(listToDelete, ',')
+
+    -- local sql = string.format("UPDATE res_list_tab SET is_delete = %d WHERE ref_id IN (%s)",1,deleteString)
+    -- db:query(sql)
+    local delete_sql = string.format("DELETE FROM res_list_tab WHERE ref_id IN (%s)", deleteString)
+    db:query(delete_sql)
+    skynet.error(delete_sql)
+    return true
+end
+
+--检测引用的文件夹是否有自己上传的文件
+s.resp.check_ref_folder_have_self_file = function(msg_body)
+    local check_user_folder = function(info) --检测用户的文件夹
+        local user_id = info.user_id
+        local isHave = false
+        local folder_id = info.id
+        local sql = string.format("select * from res_list_tab where  folder_id = %d  AND is_delete = 0 AND user_id = %d ",folder_id,user_id)
+        local res = db:query(sql)
+        local delete_tab = {}
+        -- 判断是否找到数据
+        if res and #res > 0 then
+            local tab =  {}
+            if #res == 1 then
+                tab[1] = tools.getDbResData(res)
+            else
+                tab = tools.getDbResData(res)
+            end
+            local count = 1
+            for i = 1, #tab, 1 do
+                if tab[i].ref_id==0 then
+                    isHave = true
+                else
+                    table.insert(delete_tab,count,tab[i])
+                    count = count+1
+                end
+            end
+            return isHave,delete_tab,info
+        else
+            return isHave,delete_tab,info
+        end
+    end
+
+    local sql = ""
+    local folder_id = msg_body.folder_id
+    --获取当前引用的文件夹
+    sql = string.format("select * from folder_list_tab where  ref_id = %d ",folder_id)
+    local res = db:query(sql)
+    local tab_list = {}
+    if res and #res > 0 then
+        local tab =  {}
+        if #res == 1 then
+            tab[1] = tools.getDbResData(res)
+        else
+            tab = tools.getDbResData(res)
+        end
+        for i = 1, #tab, 1 do
+            local isHave,delete_tab,info = check_user_folder(tab[i])
+            table.insert(tab_list,i,{isHave = isHave,delete_tab=delete_tab,info=info})
+        end
+        return tab_list
+    else
+        return tab_list
+    end
+
+
+   
+end
+
+--接收到删除引用的文件夹列表信息
+s.resp.recv_ref_folder_list_del_info = function(msg_body)
+    local delete_file_list = function(delete_tab)
+        local listToDelete = {}
+        for i = 1, #delete_tab, 1 do
+            table.insert(listToDelete,i,delete_tab[i].ref_id)
+        end
+        s.resp.recv_ref_file_list_del_info({file_id_list=listToDelete})
+    end
+    skynet.error("接收到删除引用的文件夹列表信息")
+    tools.dump(msg_body)
+    for i = 1, #msg_body.folder_id_list, 1 do
+        local folder_id = msg_body.folder_id_list[i]
+        local  list =  s.resp.check_ref_folder_have_self_file({folder_id=folder_id})
+        for i = 1, #list, 1 do
+            tools.dump(list[i])
+            delete_file_list(list[i].delete_tab)
+            local isHave = list[i].isHave
+            local folder_info = list[i].info
+            if isHave then --有自定义的文件不删除这个文件夹,但是要将其引用设置为0
+                skynet.error("有自定义的文件不删除这个文件夹,但是要将其引用设置为0")
+                local sql = string.format("UPDATE folder_list_tab SET ref_id = %d WHERE id = %d AND user_id = %d",0,folder_info.id,folder_info.user_id)
+                db:query(sql)        
+                skynet.error(sql)
+            else --没有自己上传的文件夹,将其文件夹删除
+                skynet.error("没有自己上传的文件夹,将其文件夹删除")
+                local sql = string.format("DELETE FROM folder_list_tab WHERE id  = %d AND user_id = %d ",folder_info.id,folder_info.user_id)
+                db:query(sql)
+                skynet.error(sql)
+            end
+        end
+    end
+    return true
+end
+
+--接收到修改引用的文件信息
+s.resp.recv_ref_file_modify_info = function(msg_body)
+    local file_id = msg_body.file_id
+    local name = msg_body.name
+    local sql = string.format("UPDATE res_list_tab SET folder_name ='%s' WHERE ref_id = %d",name,file_id)
+    db:query(sql)
+    return true
+end
+
+--接收到修改引用的文件夹信息
+s.resp.recv_ref_folder_modify_info = function(msg_body)
+    local folder_id = msg_body.folder_id
+    local name = msg_body.name
+    local sql = string.format("UPDATE folder_list_tab SET folder_name ='%s' WHERE ref_id = %d",name,folder_id)
+    db:query(sql)
+    return true
+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("success to connect to mysql server")    
+    end
+    --设置utf8字符集
+    local res = db:query("set charset utf8");
+end
+
+
+s.start(...)

+ 22 - 0
service/doc/back_sql.sql

@@ -0,0 +1,22 @@
+create table permissions_list_tab (  
+	id int not null auto_increment COMMENT '唯一id',
+	permissions_name  varchar(1024) not null COMMENT '权限名字',
+	permissions_describe  varchar(1024) not null COMMENT '权限描述',	
+	create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+	info JSON COMMENT '详情',
+	primary key (id));
+
+create table group_list_tab (  
+	id int not null auto_increment COMMENT '唯一id',
+	group_name  varchar(1024) not null COMMENT '部门名字',
+	group_describe  varchar(1024) not null COMMENT '部门描述',	
+	create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+	info JSON COMMENT '详情',
+	primary key (id));
+
+	create table classification_list_tab (  
+	id int not null auto_increment COMMENT '唯一id',
+	create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+	info JSON  COMMENT  '详情',
+	self_id int not NULL,
+	primary key (id));

+ 152 - 0
service/doc/mysql_use.sql

@@ -0,0 +1,152 @@
+create database video_tools_user_db; --创建数据库
+	-- build_video_list_tab_id int DEFAULT -1 COMMENT '用户生成视频列表的表id',
+	-- head_video_list_tab_id int DEFAULT -1 COMMENT '用户上传片头视频列表的表id',
+	-- end_video_list_tab_id int DEFAULT -1 COMMENT '用户上传片片尾频列表的表id',
+	-- audio_bg_list_tab_id int DEFAULT -1 COMMENT '用户上传音频背景列表的表id',
+	-- audio_text_list_tab_id int DEFAULT -1 COMMENT '用户上传音频文字列表的表id',
+	-- img_list_tab_id int DEFAULT -1 COMMENT '用户上传图片列表的表id',
+--创建用户表
+create table users (  
+	id int not null auto_increment COMMENT '唯一id',
+	name varchar(30) not null COMMENT '用户昵称',
+	account varchar(30) not null COMMENT '账号',
+	password varchar(30) not null COMMENT '密码',
+    is_ban int DEFAULT 0 COMMENT '账号是否被禁用',
+	user_info JSON,
+	create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+	group_id int not NULL COMMENT '部门ID',
+	permit_id int not NULL COMMENT '权限ID',
+	primary key (id));
+
+DROP TABLE users; --删除用户表
+
+INSERT INTO users (name,account, password,user_permit_level,group_type) VALUES ('小强', '13599887766','123',1,1);  --插入一条数据
+
+SELECT * FROM users;  --查询用户表的所有内容
+
+
+
+	--用户生成的视频表
+	create table generate_video_list_tab (  
+	id int not null auto_increment COMMENT '唯一id',
+	user_id int not null COMMENT '用户id',
+	template_id int not null COMMENT '模板id',
+	folder_id int not null COMMENT '文件夹id',
+	video_name varchar(30) not null COMMENT '视频名称',
+	book_name varchar(30) not null COMMENT '小说名称',
+	ratio int not null COMMENT '视频比例 1=9:16 2=4:3',
+	video_stype int not null COMMENT '视频类型 1 解压 2 滚屏',
+	video_url  varchar(1024) not null COMMENT '展示使用的视频地址',
+	path varchar(1024) DEFAULT "" COMMENT '删除使用的path地址',
+	is_delete int DEFAULT 0 COMMENT '0=没有被删除,1=等待被删除',
+	is_use int DEFAULT 0 COMMENT '0=未使用,1=已使用',
+	create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+	generate_video_info JSON COMMENT '生成详情',
+	video_state int  DEFAULT 0 COMMENT '0=等待生成,1=成功,2=失败',
+	custom JSON COMMENT '扩展信息',
+	primary key (id));
+
+	--用户生成的视频文件夹表
+	create table generate_video_folder_list_tab (  
+	id int not null auto_increment COMMENT '唯一id',
+	user_id int not null COMMENT '用户id',
+	book_name varchar(30) not null COMMENT '小说名称/文件夹名字',
+	is_delete int DEFAULT 0 COMMENT '0=没有被删除,1=等待被删除',
+	create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+	generate_video_info JSON COMMENT '生成详情',
+	video_stype int not null COMMENT '视频类型 1 解压 2 滚屏',
+	primary key (id));
+
+
+	--文件夹 表
+	create table folder_list_tab (  
+	id int not null auto_increment COMMENT '唯一id',
+	user_id int not null COMMENT '用户id',
+	folder_name varchar(30) not null COMMENT '文件夹名称',
+	folder_type int not null COMMENT '文件夹类型',
+	is_public int DEFAULT 0 COMMENT '是否公共资源',
+	classification_id int DEFAULT 0 COMMENT '分类id',
+	create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+	ref_id int DEFAULT 0 COMMENT '引用的id',
+	primary key (id));
+	INSERT INTO folder_list_tab (user_id,folder_name, folder_type,is_public) VALUES (1, '恐怖',1,0);  --插入一条数据
+
+	--资源文件 表
+	create table res_list_tab (  
+	id int not null auto_increment COMMENT '唯一id',
+	user_id int not null COMMENT '用户id',
+	folder_id int not null COMMENT '文件夹ID',
+	file_type int not null COMMENT '文件类型',
+	file_name varchar(30) not null COMMENT '文件名字',	
+	file_info JSON COMMENT '文件详情',
+	is_public int DEFAULT 0 COMMENT '是否公共资源',
+	duration  float DEFAULT 0 COMMENT '时长 单位秒,保留2位小数',
+	create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+	is_delete int DEFAULT 0 COMMENT '0=没有被删除,1=等待被删除',
+	ref_id int DEFAULT 0 COMMENT '引用的资源id',
+	classification_id int DEFAULT 0 COMMENT '分类id',
+	primary key (id));
+
+
+
+
+	--模板 表
+	create table template_list_tab (  
+	id int not null auto_increment COMMENT '唯一id',
+	user_id int not null COMMENT '用户id',
+	project_name  varchar(30) not null COMMENT '项目名',
+	book_name  varchar(30) not null COMMENT '小说名称',
+	ratio int not null COMMENT '视频比例 1=9:16 2=4:3',	
+	video_stype int not null COMMENT '视频类型 1 解压 2 滚屏',	
+	subtitles  varchar(1024) not null COMMENT '字幕地址',	
+	subtitles_audio  varchar(1024) not null COMMENT '字幕音频地址',	
+	video_nums int not null COMMENT '视频条数',	
+	video_crop_time int not null COMMENT '正片截取,每个视频截取多少秒',	
+	create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+	template_info JSON COMMENT '模板详情',
+	primary key (id));
+
+
+	--公共文件夹 表
+	create table public_folder_list_tab (  
+	id int not null auto_increment COMMENT '唯一id',
+	user_id int not null COMMENT '用户id',
+	folder_name varchar(30) not null COMMENT '文件夹名称',
+	folder_type int not null COMMENT '文件夹类型',
+	create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+	ref_id int DEFAULT 0 COMMENT '引用的资源id',
+	upload_user_id int DEFAULT 0 COMMENT '上传的用户id',
+	classification_id int DEFAULT 0 COMMENT '分类id',
+	primary key (id));
+	INSERT INTO folder_list_tab (user_id,folder_name, folder_type,is_public) VALUES (1, '恐怖',1,0);  --插入一条数据
+
+	--公共资源文件 表
+	create table public_res_list_tab (  
+	id int not null auto_increment COMMENT '唯一id',
+	user_id int not null COMMENT '用户id',
+	folder_id int not null COMMENT '文件夹ID',
+	file_type int not null COMMENT '文件类型',
+	file_name varchar(30) not null COMMENT '文件名字',	
+	file_info JSON COMMENT '文件详情',
+	duration  float DEFAULT 0 COMMENT '时长 单位秒,保留2位小数',
+	create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+	is_delete int DEFAULT 0 COMMENT '0=没有被删除,1=等待被删除',
+	ref_id int DEFAULT 0 COMMENT '引用的资源id',
+	upload_user_id int DEFAULT 0 COMMENT '上传的用户id',
+	classification_id int DEFAULT 0 COMMENT '分类id',
+	primary key (id));
+
+
+	--配置
+	create table video_tools_config_tab (
+		id int not null auto_increment COMMENT '唯一id',
+		config_info JSON COMMENT '资源类型配置',
+		permissions_info JSON COMMENT '权限配置',
+		group_info JSON COMMENT '组配置',
+		other_info JSON COMMENT '其他配置',
+		primary key (id));
+
+
+	INSERT INTO res_list_tab (user_id, folder_id, file_type, file_name, file_info) VALUES (2, 1, 2, "absd.mp4", '{"width": 100, "height": 100, "duration": 123}'); --插入一条数据
+	select * from res_list_tab where user_id = %d AND folder_id = %d AND is_public = %d
+	TRUNCATE TABLE  users; --清理users表

+ 70 - 0
service/http_work/init.lua

@@ -0,0 +1,70 @@
+local skynet = require "skynet"
+-- local httpc = require "http.httpc"
+-- local httpurl = require "http.url"
+-- local dns = require "skynet.dns"
+-- local httpd = require "http.httpd"
+-- local sockethelper = require "http.sockethelper"
+local socket = require "skynet.socket"
+local cjson = require "cjson"
+local tools = require "tools"
+local dispatch = function(session, address,id, addr,...)
+    socket.start(id)
+    local req = tools.read_request(id)
+    -- skynet.error('id,',id)
+    -- skynet.error('addr,',addr)
+    -- skynet.error('url,',req.url)
+    -- skynet.error('header,',)
+
+    -- skynet.error('body,',req.body)
+    -- local color,text = "red", "hello"
+    -- skynet.error("req.url",req.url)
+    if  string.find(req.url, "/config/") then
+        skynet.send("config_mgr","lua","on_recv",id,req.url,req.body)
+        return
+    end
+
+    if  string.find(req.url, "back/") then
+        skynet.send("backmgr","lua","on_recv",id,req.url,req.body)
+        return
+    end
+    if req.url == nil or #req.url==0 or req.code~=200 or #req.body==0 then
+        skynet.error(req.url)
+        return  tools.response(id, req.code, "error!")
+    end
+
+    if string.find(req.url, "tools/") then
+        skynet.send("tools_work","lua","on_recv",id,req.url,req.body)
+    elseif string.find(req.url, "public")  then
+        local token = req.header.token
+        local user_data = nil
+        skynet.error(" header.token", req.header.token)
+        if  token~=nil and #token>1 then
+            local user_data = tools.tokenDecode(token)
+            user_data =  cjson.decode(user_data)
+            skynet.error("user_data",user_data)
+            skynet.send("public_mgr","lua","on_recv",id,req.url,req.body,user_data)
+        else
+            skynet.send("public_mgr","lua","on_recv",id,req.url,req.body,nil)
+        end
+    else
+        -- local header = cjson.encode(req.header)
+        local token = req.header.token
+        local user_data = nil
+        skynet.error(" header.token", req.header.token)
+        if  token~=nil and #token>1 then
+            local user_data = tools.tokenDecode(token)
+            user_data =  cjson.decode(user_data)
+            skynet.error("user_data",user_data)
+            skynet.send("agentmgr","lua","on_recv",id,req.url,req.body,user_data)
+        else
+            skynet.send("agentmgr","lua","on_recv",id,req.url,req.body,nil)
+        end
+
+    end
+
+ 
+
+end
+skynet.start(function()
+    skynet.dispatch("lua", dispatch)
+end)

+ 93 - 1
service/main.lua

@@ -1 +1,93 @@
-local test = '123'
+local skynet = require "skynet"
+
+local httpc = require "http.httpc"
+local httpurl = require "http.url"
+local dns = require "skynet.dns"
+local runconfig = require "run_config"
+local socket = require "skynet.socket"
+local httpd = require "http.httpd"
+local sockethelper = require "http.sockethelper"
+local cjson = require "cjson"
+local skynet_manager = require "skynet.manager"
+local function http_test(protocol)
+	--httpc.dns()	-- set dns server
+	httpc.timeout = 100	-- set timeout 1 second
+	print("GET baidu.com")
+	protocol = protocol or "http"
+	local respheader = {}
+	local host = string.format("%s://baidu.com", protocol)
+	print("geting... ".. host)
+	local status, body = httpc.get(host, "/", respheader)
+	print("[header] =====>")
+	for k,v in pairs(respheader) do
+		print(k,v)
+	end
+	print("[body] =====>", status)
+	print(body)
+
+	local respheader = {}
+	local ip = dns.resolve "baidu.com"
+	print(string.format("GET %s (baidu.com)", ip))
+	local status, body = httpc.get(host, "/", respheader, { host = "baidu.com" })
+	print(status)
+end
+
+local function response(id, ...)
+    local ok, err = httpd.write_response(sockethelper.writefunc(id), ...)
+    if not ok then
+        -- if err == sockethelper.socket_error , that means socket closed.
+        skynet.error(string.format("fd = %d, %s", id, err))
+    end
+end
+
+function json_test()
+    local myTable = {name = "John", age = 30, city = "New York"}
+    local jsonStr = cjson.encode(myTable)
+    print(jsonStr)
+    jsonStr = '{"name":"John","age":30,"city":"New York"}'
+    local decodedTable = cjson.decode(jsonStr)
+    print(decodedTable.name)
+    print(decodedTable.age)
+    print(decodedTable.city)
+
+end
+
+skynet.start(function()
+
+	local srv = skynet.newservice("agentmgr", "agentmgr", 0)
+	skynet.name("agentmgr", srv)
+
+
+	local db_srv = skynet.newservice("dbmgr", "dbmgr", 0)
+	skynet.name("dbmgr", db_srv)
+
+	local tools_srv = skynet.newservice("tools_work", "tools_work", 0)
+	skynet.name("tools_work", tools_srv)
+
+	local public_srv = skynet.newservice("public_mgr", "public_mgr", 0)
+	skynet.name("public_mgr", public_srv)
+
+	local conifg_srv = skynet.newservice("config_mgr", "config_mgr", 0)
+	skynet.name("config_mgr", conifg_srv)
+
+	local back_srv = skynet.newservice("backmgr", "backmgr", 0)
+	skynet.name("backmgr", back_srv)
+
+	local http_works = {}
+	local protocol = "http" 
+	for i= 1, 30 do --开启30个服务用来接收消息
+		http_works[i] = skynet.newservice("http_work", "http_work", protocol)
+	end
+	local balance = 1
+	local id = socket.listen("0.0.0.0",runconfig.testHttpProt )
+	-- json_test()
+	skynet.error(string.format("Listen web port 8001 protocol:%s", protocol))
+	socket.start(id , function(id, addr)
+		-- skynet.error(string.format("%s connected, pass it to http_works :%08x", addr, http_works[balance]))
+		skynet.send(http_works[balance], "lua", id,addr)
+		balance = balance + 1
+		if balance > #http_works then
+			balance = 1
+		end
+	end)
+end)

+ 998 - 0
service/public_mgr/init.lua

@@ -0,0 +1,998 @@
+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
+
+--通知 start
+
+local response_db_new_folder = function(fd,is_ok)
+    if not is_ok then
+        return tools.response(fd,200,cjson.encode({code=10001,msg = "新建文件夹失败!"}))
+    end
+    return tools.response(fd,200,cjson.encode({code=10000,msg = "新建文件夹成功!"}))
+end
+
+--回应db获取资源文件夹列表
+local response_db_folder_list = function(fd,msg_body,isok,tab)
+    if not isok then
+        return tools.response(fd,200, '{"code": 10000,   "msg": "获取资源文件夹列表失败!",  "data": [] }')
+    end
+    local total_count = 0 
+    local list = tab
+    list,total_count = tools.getPageData(msg_body.page,msg_body.count,list) 
+    if #list <= 0 or list == nil then
+        return tools.response(fd,200,'{"code": 10000,   "msg": "获取资源文件夹列表失败!",  "data": [] }')
+        -- return M.response(fd,200,cjson.encode({code=10000,msg = "获取资源文件夹列表成功!",data=folder_list,total_count=total_count}))
+    end
+    s.resp.folder_res_list_nums(list,fd,total_count)
+end
+
+
+--回应db获取指定文件夹内的资源列表
+local response_db_folder_res_list = function(fd,msg_body,isok,tab)
+    if not isok then
+        return tools.response(fd,200,'{"code": 10000,   "msg": "获取文件夹资源失败",  "data": [] }')
+    end
+    local list = tab
+    local folder_list = {}
+    local total_count = 0 
+    -- M.dump(list)
+    -- skynet.error("list",list)
+    -- skynet.error("msg_body",msg_body)
+    -- M.dump(msg_body)
+    list,total_count = tools.getPageData(msg_body.page,msg_body.count,list)
+    for i = 1, #list, 1 do
+        -- skynet.error("create_time")
+        -- M.dump(list[i])
+        table.insert(folder_list,i,{create_time=list[i].create_time,file_id=list[i].id,info=list[i].file_info,file_name=list[i].file_name})
+    end
+    if #list<=0  then
+        return tools.response(fd,200,'{"code": 10000,   "msg": "获取文件夹资源失败",  "data": [] }')
+    end
+    return tools.response(fd,200,cjson.encode({code=10000,msg = "获取文件夹资源成功!",data=folder_list,total_count=total_count}))
+end
+
+local response_db_search_res = function(fd,msg_body,isok,tab)
+    local error_json = '{"code": 10000,   "msg": "搜索失败",  "data": [] }'
+    if not isok then
+        return tools.response(fd,200,error_json)
+    end
+    local list = tab
+    local file_list = {}
+    local total_count = 0 
+    -- M.dump(list)
+    -- skynet.error("list",list)
+    -- skynet.error("msg_body",msg_body)
+    -- tools.dump(msg_body)
+    list ,total_count = tools.getPageData(msg_body.page,msg_body.count,list)
+    for i = 1, #list, 1 do
+        table.insert(file_list,i,{create_time=list[i].create_time,file_id=list[i].id,info=list[i].file_info,file_name=list[i].file_name})
+    end
+    if #list<=0  then
+        return M.response(fd,200,error_json)
+    end
+    return tools.response(fd,200,cjson.encode({code=10000,msg = "搜索成功",data=file_list,total_count=total_count}))
+end
+
+
+local response_db_folder_list_nums  = function(fd,list,count_list,total_count)
+    local folder_list = {}
+    for i = 1, #list, 1 do
+        folder_list[i] = {file_nums=count_list[list[i].id],folder_name=list[i].folder_name,folder_id=list[i].id}
+    end
+    return tools.response(fd,200,cjson.encode({code=10000,msg = "获取资源文件夹列表成功!",data=folder_list,total_count=total_count}))
+end
+
+local response_db_tools_tools_create_folder = function(fd,isok,tab)
+    if not isok then
+        return tools.response(fd,200,cjson.encode({code=2,msg = "失败"}))
+    end
+    return tools.response(fd,200,cjson.encode({code=1,msg = "创建公共文件夹成功!",folder_id=tab[#tab].id}))
+end
+--通知 end
+
+local checkMsg = function(msg_body,user_data,orgin_body)
+    local key = nil
+    local user_id = nil
+    if type(user_data) ~= "table" then
+        return  false,100,key,user_id
+    end
+    user_id = user_data.user_id
+    if user_id==nil then
+        return  false,101,key,user_id
+    end
+    msg_body["user_id"] = user_id
+    local isok ,key =  tools.checkData(orgin_body,msg_body)
+    if not isok then
+        return false,102,key,user_id
+    end
+    return true,200,key,user_id
+end
+
+local response_error = function( isOk,err_code,key,fd,func_name)
+    if err_code == 100 then
+        tools.response(fd, 200, "token error!")
+    elseif err_code == 101 then
+        tools.response(fd,200,"user_id==nil "..func_name)
+    elseif err_code == 102 then
+        tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+end
+--@@@@@@@@@@@@@@@@@@@@@@@@@@数据库 start
+
+--- 新建文件夹
+s.resp.db_public_new_folder = function(msg_body,fd)
+    skynet.fork(function(_fd)
+        local sql = string.format("INSERT INTO public_folder_list_tab (user_id,folder_name, folder_type,upload_user_id,classification_id) VALUES (%d, '%s',%d,%d,%d)",-1,msg_body.folder_name,msg_body.folder_type,msg_body.user_id,msg_body.classification_id)
+        local res = db:query(sql)
+        response_db_new_folder(_fd,true)
+    end,fd)
+    return true 
+end
+
+--获取文件夹列表每个文件夹的文件数量
+s.resp.folder_res_list_nums = function(folder_list,fd,total_count)
+    skynet.fork(function(_fd)
+        local temp ={}
+        for i = 1, #folder_list, 1 do
+            local msg_body = folder_list[i]
+            -- tools.dump(msg_body)
+            local sql = string.format("select * from public_res_list_tab where user_id = %d AND folder_id = %d  AND is_delete = 0",-1,msg_body.id)
+            local res = db:query(sql)
+            local count = 0
+            if res and #res > 0 then
+                count = #res
+                skynet.error("Found data:")
+                -- tools.dump(tab)
+                -- return true,tab
+            else
+                skynet.error("No data found.",msg_body.id)
+            end
+            temp[msg_body.id] = count
+            -- table.insert(temp,msg_body.id,count)
+        end
+        response_db_folder_list_nums(_fd,folder_list,temp,total_count)
+    end,fd)
+end
+--- 获取资源文件夹列表
+s.resp.db_public_folder_list = function(msg_body,fd)
+    skynet.fork(function(_fd)
+        local sql = string.format("select * from public_folder_list_tab where user_id = %d AND folder_type = %d AND classification_id = %d",-1,msg_body.type,msg_body.classification_id)
+        local res = db:query(sql)
+        skynet.error('db_public_folder_list',sql)
+        -- 判断是否找到数据
+        if res and #res > 0 then
+            local tab =  {}
+            if #res == 1 then
+                tab[1] = tools.getDbResData(res)
+            else
+                tab = tools.getDbResData(res)
+            end
+            
+            skynet.error("Found data:")
+            -- tools.dump(tab)
+            -- return true,tab
+            response_db_folder_list(_fd,msg_body,true,tab)
+        else
+            skynet.error("No data found.")
+            response_db_folder_list(_fd,msg_body,false,nil)
+            -- return false,nil
+        end
+    end,fd)
+    return true 
+end
+
+--- 获取文件夹内所有资源
+s.resp.db_public_folder_res_list = function(msg_body,fd,call_back)
+    skynet.fork(function(_fd) 
+        local sql_duration = ""
+        if msg_body.duration~=nil then
+            sql_duration = string.format("AND duration >= %d",msg_body.duration)
+        end
+        local sql = string.format("select * from public_res_list_tab where user_id = %d AND folder_id = %d  AND is_delete = 0"..sql_duration,-1,msg_body.folder_id)
+        local res = db:query(sql)
+        skynet.error('db_public_folder_res_list',sql)
+        -- 判断是否找到数据
+        if res and #res > 0 then
+            local tab =  {}
+            if #res == 1 then
+                tab[1] = tools.getDbResData(res)
+            else
+                tab = tools.getDbResData(res)
+            end
+            
+            skynet.error("Found data:")
+            if not call_back and _fd~=nil then
+                response_db_folder_res_list(_fd,msg_body,true,tab)
+            else
+                if call_back ~=nil then
+                    call_back(tab)
+                end
+            end
+           
+            -- tools.dump(tab)
+            -- return true,tab
+        else
+            skynet.error("No data found.",call_back)
+            if  call_back == nil  and _fd~=nil then
+                response_db_folder_res_list(_fd,msg_body,false,nil)
+            else
+                if call_back ~=nil then
+                    call_back({})
+                end
+            end
+            
+            -- return false,nil
+        end
+    end,fd)
+    return true
+end
+
+--- 重命名资源
+s.resp.db_public_reset_res_name = function(msg_body,fd)
+    local isOk = s.resp.get_res_file_by_id(msg_body.file_id)
+    if not isOk then
+        return false
+    end
+    local sql = string.format("UPDATE public_res_list_tab SET file_name ='%s' WHERE id = %d AND folder_id = %d   AND is_delete = 0",msg_body.name,msg_body.file_id,msg_body.folder_id)
+    db:query(sql)
+    return true
+end
+
+--- 重命名文件夹
+s.resp.db_public_reset_folder_name = function(msg_body,fd)
+    local isOk = s.resp.get_res_folder_by_id(msg_body.folder_id)
+    if not isOk then
+        return false
+    end
+    local sql = string.format("UPDATE public_folder_list_tab SET folder_name ='%s' WHERE id = %d  ",msg_body.name,msg_body.folder_id)
+    db:query(sql)
+    return true
+end
+
+--根据所有文件id查到所有文件的url并删除
+local fork_get_file_list_url_and_delete = function(deleteString,call_back)
+    local sql = string.format("SELECT file_info FROM public_res_list_tab WHERE id IN (%s)", deleteString)
+    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
+        
+        skynet.error("Found data:fork_get_file_list_url_and_delete")
+        local url_list = {}
+        for i = 1, #tab, 1 do
+           local file_info =  cjson.decode(tab[i].file_info)
+           table.insert(url_list,i,file_info.path)
+        end
+        skynet.send("tools_work","lua","delete_file",url_list)
+        tools.dump(url_list)
+        -- return true,tab
+    else
+        skynet.error("No data found.")
+        -- return false,nil
+    end
+
+    if call_back~=nil then
+        call_back()
+    end
+   
+end
+--执行删除文件操作
+local fork_delete_file = function(msg_body)
+    -- tools.dump(msg_body)
+    local listToDelete = {}
+    for i = 1, #msg_body.file_id_list, 1 do
+        table.insert(listToDelete,i,msg_body.file_id_list[i])
+    end
+    local deleteString = table.concat(listToDelete, ',')
+
+    local sql = string.format("UPDATE public_res_list_tab SET is_delete = %d WHERE id IN (%s)",1,deleteString)
+    db:query(sql)
+
+    skynet.fork(fork_get_file_list_url_and_delete,deleteString,function()
+        local delete_sql = string.format("DELETE FROM public_res_list_tab WHERE id IN (%s)  AND user_id = %d", deleteString,-1)
+        db:query(delete_sql)
+    end)
+end
+
+--执行删除文件夹操作
+local fork_delete_folder =  function(msg)
+    for i = 1, #msg.folder_id_list, 1 do
+        local  isok = s.resp.folder_res_list({
+            folder_id = msg.folder_id_list[i],
+            user_id = -1},nil,nil,function(list)
+                skynet.error("执行删除文件夹操作",#list)
+                if #list>0 then
+                    local temp = {}
+                    for i = 1, #list, 1 do
+                        table.insert(temp,i,list[i].id)
+                    end
+                    skynet.fork(fork_delete_file,{file_id_list=temp,user_id=msg.user_id})
+                end
+            end)
+    end
+end
+
+--- 文件夹删除
+s.resp.db_public_delete_folder = function(msg_body,fd)
+    local listToDelete = {}
+    for i = 1, #msg_body.folder_id_list, 1 do
+        table.insert(listToDelete,i,msg_body.folder_id_list[i])
+    end
+    local deleteString = table.concat(listToDelete, ',')
+    local sql = string.format("DELETE FROM public_folder_list_tab WHERE id IN (%s) AND user_id = %d", deleteString,-1)
+    db:query(sql)
+    skynet.fork(fork_delete_folder,msg_body)
+    return true
+end
+
+--- 搜索文件
+s.resp.db_public_search_res = function(msg_body,fd)
+    skynet.fork(function(_fd)
+        local sql = string.format("SELECT * FROM public_res_list_tab WHERE file_type = %d AND file_name LIKE '%%%s%%'  AND is_delete = 0 AND classification_id = %d",msg_body.type ,msg_body.search_content,msg_body.classification_id)
+        skynet.error("sql",sql)
+        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
+            
+            skynet.error("Found data:")
+            -- tools.dump(tab)
+            -- return true,tab
+           response_db_search_res(_fd,msg_body,true,tab)
+        else
+            skynet.error("No data found.")
+            -- return false,nil
+            response_db_search_res(_fd,msg_body,false,nil)
+        end
+    end,fd)
+    return true
+end
+
+--- 删除文件
+s.resp.db_public_delete_res = function(msg_body,fd)
+    skynet.fork(fork_delete_file,msg_body)
+    return true
+end
+
+--根据id获取文件夹 
+s.resp.get_res_folder_by_id = function(folder_id)
+    local sql = string.format("select * from public_folder_list_tab where id = %d ",folder_id)
+    skynet.error("sql",sql)
+    local res = db:query(sql)
+      -- 判断是否找到数据
+    if res and #res > 0 then
+        local tab = tools.getDbResData(res)
+        skynet.error("Found data:",tab)
+        return true,tab
+    else
+        skynet.error("No data found.")
+        return false,nil
+    end
+end
+
+--根据id获取资源 
+s.resp.get_res_file_by_id = function(file_id)
+    local sql = string.format("select * from public_res_list_tab where id = %d  AND is_delete = 0",file_id)
+    skynet.error("sql",sql)
+    local res = db:query(sql)
+      -- 判断是否找到数据
+    if res and #res > 0 then
+        local tab = tools.getDbResData(res)
+        skynet.error("Found data:",tab)
+        return true,tab
+    else
+        skynet.error("No data found.")
+        return false,nil
+    end
+end
+
+s.resp.tools_create_folder = function(source,fd,msg_body)
+    skynet.fork(function(_fd)
+        local sql = string.format("INSERT INTO public_folder_list_tab (user_id,folder_name, folder_type,upload_user_id,classification_id) VALUES (%d, '%s',%d,%d,%d)",-1,msg_body.folder_name,msg_body.stype,msg_body.user_id,msg_body.classification_id)
+        local res = db:query(sql)
+        skynet.sleep(10)
+        sql = string.format("select *from public_folder_list_tab where user_id = %d AND folder_name = '%s' AND folder_type = %d AND upload_user_id = %d AND classification_id = %d ",-1,msg_body.folder_name,msg_body.stype,msg_body.user_id,msg_body.classification_id)
+        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
+            response_db_tools_tools_create_folder(_fd,true,tab)
+        else
+            response_db_tools_tools_create_folder(_fd,false,nil)
+            skynet.error("No data found.")
+        end
+    end,fd)
+    return true 
+end
+s.resp.tools_add_public_res_info = function(source,fd,msg_body)
+    skynet.fork(function()
+        local temp = '{"width": 100, "height": 100, "duration": 123}'
+        temp = cjson.encode(msg_body)
+        local duration = 0
+        if msg_body.duration~=nil then
+            duration = tonumber(msg_body.duration)
+        end
+        local sql = string.format("INSERT INTO public_res_list_tab (user_id, folder_id, file_type, file_name,file_info,duration,classification_id,upload_user_id) VALUES (%d, %d, %d, '%s','%s',%f,%d,%d)",-1,msg_body.folder_id,msg_body.stype,msg_body.file_name,temp,duration,msg_body.classification_id,msg_body.user_id)
+        skynet.error("add_res_file",sql)
+        local res = db:query(sql)
+    end)
+    return true
+end
+
+s.resp.db_add_public_res_info = function(msg_body,fd)
+    skynet.fork(function()
+        local temp = '{"width": 100, "height": 100, "duration": 123}'
+        temp = cjson.encode(msg_body)
+        local duration = 0
+        if msg_body.duration~=nil then
+            duration = tonumber(msg_body.duration)
+        end
+        local sql = string.format("INSERT INTO public_res_list_tab (user_id, folder_id, file_type, file_name,file_info,duration,classification_id,upload_user_id) VALUES (%d, %d, %d, '%s','%s',%f,%d)",-1,msg_body.folder_id,msg_body.stype,msg_body.file_name,temp,duration,msg_body.classification_id,msg_body.user_id)
+        -- skynet.error("add_res_file",sql)
+        local res = db:query(sql)
+    end)
+    return true
+end
+
+local get_res_list_for_folder = function(user_id,folder_id,call_back)
+    local sql = string.format("select * from public_res_list_tab where user_id = %d AND folder_id = %d  AND is_delete = 0",-1,folder_id)
+    local res = db:query(sql)
+    skynet.error('folder_res_list',sql)
+    -- 判断是否找到数据
+    if res and #res > 0 then
+        local tab =  {}
+        if #res == 1 then
+            tab[1] = tools.getDbResData(res)
+        else
+            tab = tools.getDbResData(res)
+        end
+        
+        skynet.error("Found data:")
+        if call_back ~=nil then
+            call_back(tab)
+        end
+
+    else
+        if call_back ~=nil then
+            call_back(nil)
+        end
+       
+    end
+end
+s.resp.db_public_add_folder_list_to_private = function(msg_body,fd,call_back)
+    local count = 0
+    local check_all_finish = true
+    for i = 1, #msg_body.folder_id_list, 1 do
+        local public_folder_id = msg_body.folder_id_list[i]
+        local isOk =  s.resp.db_public_add_folder_to_private({
+            public_folder_id = public_folder_id,
+            user_id = msg_body.user_id},fd,function(isFinish)
+                count = count+1;
+                if isFinish == false then
+                    check_all_finish = false
+                end
+                if count>=#msg_body.folder_id_list then
+                    call_back(check_all_finish)
+                end
+        end)
+    end
+
+end
+s.resp.db_public_add_folder_to_private = function(msg_body,fd,call_back)
+    skynet.fork(function()
+        --获取公共文件夹
+        local isOk,public_folder_info = s.resp.get_res_folder_by_id(msg_body.public_folder_id)
+        if not isOk then
+            call_back(false)
+        end
+
+        --检测用户是否有此公共文件夹
+        local self_folder_info = nil
+        isOk,self_folder_info = skynet.call("dbmgr","lua","on_recv","check_have_folder",{
+            folder_id = public_folder_info.id,
+            user_id = msg_body.user_id}
+        )
+
+        if not isOk then
+            --如果没有创建用户私人文件夹
+            local sql = string.format("INSERT INTO folder_list_tab (user_id,folder_name, folder_type,classification_id,ref_id) VALUES (%d, '%s',%d,%d,%d)",msg_body.user_id,public_folder_info.folder_name,public_folder_info.folder_type,public_folder_info.classification_id,public_folder_info.id)
+            local res = db:query(sql)
+            --获取刚刚创建的私人文件夹
+            sql = string.format("select *from folder_list_tab where user_id = %d AND folder_name = '%s' AND folder_type = %d AND  classification_id = %d limit 1",msg_body.user_id,public_folder_info.folder_name,public_folder_info.folder_type,public_folder_info.classification_id)
+            res = db:query(sql)
+
+            skynet.error(sql)
+            if res and #res > 0 then
+                local tab =  {}
+                tab = tools.getDbResData(res)
+                local user_id = tab.user_id
+                local private_folder_id = tab.id
+                local public_folder_id = msg_body.public_folder_id
+
+                skynet.error("刚刚创建的文件夹",private_folder_id)
+                --获取公共文件夹下的所有文件
+                skynet.fork(get_res_list_for_folder,user_id,public_folder_id,function(list)
+                    --将所有文件也拷贝到私人
+                    skynet.error("获取公共文件夹下的所有文件")
+                    -- tools.dump(list)
+                    if list ~=nil then
+                        for i = 1, #list, 1 do
+                            local temp = {}
+                            temp = list[i].file_info
+                            sql = string.format("INSERT INTO res_list_tab (user_id, folder_id, file_type, file_name, file_info, duration, classification_id, ref_id) VALUES (%d, %d, %d, '%s','%s',%f,%d,%d)",user_id,private_folder_id,list[i].file_type,list[i].file_name,temp,list[i].duration,list[i].classification_id,list[i].id)
+                            db:query(sql)
+                        end
+                    end
+                    call_back(true)
+                end)
+            else
+                call_back(false)
+                skynet.error("No data found.")
+            end
+        else --如果用户已存此文件夹在
+            skynet.fork(get_res_list_for_folder,msg_body.user_id, public_folder_info.id,function(list)
+                --将所有文件也拷贝到私人
+                -- skynet.error("将所有文件也拷贝到私人")
+                -- tools.dump(list)
+                if list ~=nil then
+                    for i = 1, #list, 1 do
+                        local file_id = list[i].id
+                        local self_file_info = nil
+                        isOk,self_file_info = skynet.call("dbmgr","lua","on_recv","check_have_file",{
+                            file_id = file_id,
+                            folder_id = public_folder_info.id,
+                            user_id = msg_body.user_id}
+                        )
+                        if not isOk then --如果用户没有此文件 
+                            local temp = {}
+                            temp = list[i].file_info
+                            local sql = string.format("INSERT INTO res_list_tab (user_id, folder_id, file_type, file_name, file_info, duration, classification_id, ref_id) VALUES (%d, %d, %d, '%s','%s',%f,%d,%d)",self_folder_info.user_id,self_folder_info.id,list[i].file_type,list[i].file_name,temp,list[i].duration,list[i].classification_id,list[i].id)
+                            db:query(sql)
+                        end
+                    end
+                end
+                call_back(true)
+            end)
+        
+        end
+      
+    end)
+    return true
+end
+
+s.resp.db_public_add_file_list_to_private = function(msg_body,fd,call_back)
+    local count = 0
+    local check_all_finish = true
+    for i = 1, #msg_body.file_id_list, 1 do
+        local public_file_id = msg_body.file_id_list[i]
+        local isOk =  s.resp.db_public_add_file_to_private({
+            file_id = public_file_id,
+            user_id = msg_body.user_id},fd,function(isFinish)
+                count = count+1;
+                if isFinish == false then
+                    check_all_finish = false
+                end
+                skynet.error("count",count)
+                skynet.error("file_id_list",#msg_body.file_id_list)
+                if count>=#msg_body.file_id_list then
+                    call_back(check_all_finish)
+                end
+        end)
+    end
+    return true
+
+end
+
+s.resp.db_public_add_file_to_private = function(msg_body,fd,call_back)
+    local isOk,public_file_info = s.resp.get_res_file_by_id(msg_body.file_id)
+    if not isOk then
+        return false
+    end
+
+    local self_file_info = nil
+    local file_id = public_file_info.id
+    isOk,self_file_info = skynet.call("dbmgr","lua","on_recv","check_have_file",{
+        file_id = file_id,
+        user_id = msg_body.user_id}
+    )
+
+
+
+    --检测是否有此文件夹
+         --如果没有创建用户私人文件夹
+        --  local sql = string.format("INSERT INTO folder_list_tab (user_id,folder_name, folder_type,classification_id,ref_id) VALUES (%d, '%s',%d,%d,%d)",msg_body.user_id,public_folder_info.folder_name,public_folder_info.folder_type,public_folder_info.classification_id,public_folder_info.id)
+        --  local res = db:query(sql)
+        --  --获取刚刚创建的私人文件夹
+        --  sql = string.format("select *from folder_list_tab where user_id = %d AND folder_name = '%s' AND folder_type = %d AND  classification_id = %d limit 1",msg_body.user_id,public_folder_info.folder_name,public_folder_info.folder_type,public_folder_info.classification_id)
+        --  res = db:query(sql)
+    if  not isOk then
+        --检测用户是否有此公共文件夹
+        local self_folder_info = nil
+        isOk,self_folder_info = skynet.call("dbmgr","lua","on_recv","check_have_folder",{
+            folder_id = public_file_info.folder_id,
+            user_id = msg_body.user_id}
+        )
+        if not isOk then
+
+            local isOk,public_folder_info = s.resp.get_res_folder_by_id(public_file_info.folder_id)
+            if not isOk then
+                call_back(false)
+            end
+            --如果没有创建用户私人文件夹
+            local sql = string.format("INSERT INTO folder_list_tab (user_id,folder_name, folder_type,classification_id,ref_id) VALUES (%d, '%s',%d,%d,%d)",msg_body.user_id,public_folder_info.folder_name,public_folder_info.folder_type,public_folder_info.classification_id,public_folder_info.id)
+            local res = db:query(sql)
+            --获取刚刚创建的私人文件夹
+            sql = string.format("select *from folder_list_tab where user_id = %d AND folder_name = '%s' AND folder_type = %d AND  classification_id = %d limit 1",msg_body.user_id,public_folder_info.folder_name,public_folder_info.folder_type,public_folder_info.classification_id)
+            res = db:query(sql)
+
+            if res and #res > 0 then
+                local tab =  {}
+                tab = tools.getDbResData(res)
+                local private_folder_id = tab.id
+                skynet.error("添加一个文件到用户")
+                local temp = {}
+                temp = public_file_info.file_info
+                local sql = string.format("INSERT INTO res_list_tab (user_id, folder_id, file_type, file_name,file_info,duration,classification_id,ref_id) VALUES (%d, %d, %d, '%s','%s',%f,%d,%d)",msg_body.user_id,private_folder_id,public_file_info.file_type,public_file_info.file_name,temp,public_file_info.duration,public_file_info.classification_id,public_file_info.id)
+                skynet.error(sql)
+                db:query(sql)
+            end
+        
+        else
+            local private_folder_id  = self_folder_info.id
+            local temp = {}
+            temp = public_file_info.file_info
+            local sql = string.format("INSERT INTO res_list_tab (user_id, folder_id, file_type, file_name,file_info,duration,classification_id,ref_id) VALUES (%d, %d, %d, '%s','%s',%f,%d,%d)",msg_body.user_id,private_folder_id,public_file_info.file_type,public_file_info.file_name,temp,public_file_info.duration,public_file_info.classification_id,public_file_info.id)
+            skynet.error("用户已有此文件夹,直接添加")
+            db:query(sql)
+        end
+
+    end
+    call_back(true)
+    return true
+end
+--@@@@@@@@@@@@@@@@@@@@@@@@@@数据库 end
+
+
+
+-----------------------------------------
+-----------------------------------------
+-----------------------------------------
+-----------------------------------------
+-----------------------------------------
+-----------------------------------------
+-----------------------------------------
+-----------------------------------------
+-----------------------------------------
+-----------------------------------------
+-----------------------------------------
+
+
+--==========================逻辑 start
+
+--- 搜索文件
+s.resp.search_res = function(msg_body,fd,user_data)
+    local isOk,err_code,key,user_id = checkMsg(msg_body,user_data,
+    {"search_content",
+    "type",
+    "page",
+    "count",
+    "classification_id"})
+    if isOk then
+        s.resp.db_public_search_res({
+            type = msg_body.type,
+            search_content = msg_body.search_content,
+            page = msg_body.page,
+            count = msg_body.count,
+            classification_id = msg_body.classification_id,
+            user_id = user_id},fd)
+    else
+        response_error(isOk,err_code,key,fd,"search_res")
+    end
+end
+
+--- 文件夹删除
+s.resp.delete_folder = function(msg_body,fd,user_data)
+    local isOk,err_code,key,user_id = checkMsg(msg_body,user_data,
+    {"folder_id_list"})
+    skynet.error("公共文件夹删除")
+    if isOk then
+        isOk =  s.resp.db_public_delete_folder({
+            folder_id_list = msg_body.folder_id_list,
+            user_id = user_id},fd)
+        if not isOk then
+            return tools.response(fd,200,cjson.encode({code=10000,msg = "删除失败!",data={}}))
+        end
+        isOk = skynet.call("dbmgr","lua","on_recv","recv_ref_folder_list_del_info",{folder_id_list= msg_body.folder_id_list})
+        return tools.response(fd,200,cjson.encode({code=10000,msg = "删除成功!",data={}}))
+    else
+        skynet.error("err_code:",err_code)
+        response_error(isOk,err_code,key,fd,"delete_folder")
+    end
+end
+
+--- 删除文件
+s.resp.delete_res = function(msg_body,fd,user_data)
+    local isOk,err_code,key,user_id = checkMsg(msg_body,user_data,
+    {"file_id_list"})
+    if isOk then
+        isOk =  s.resp.db_public_delete_res({
+            file_id_list = msg_body.file_id_list,
+            user_id = user_id},fd)
+        if not isOk then
+            return tools.response(fd,200,cjson.encode({code=10000,msg = "删除失败!",data={}}))
+        end
+        isOk = skynet.call("dbmgr","lua","on_recv","recv_ref_file_list_del_info",{file_id_list= msg_body.file_id_list})
+        return tools.response(fd,200,cjson.encode({code=10000,msg = "删除成功!",data={}}))
+   
+    else
+        response_error(isOk,err_code,key,fd,"delete_res")
+    end
+end
+
+--- 新建文件夹
+s.resp.new_folder = function(msg_body,fd,user_data)
+    local isOk,err_code,key,user_id = checkMsg(msg_body,user_data,
+    {"category_name","type","classification_id"})
+    if isOk then
+        isOk =  s.resp.db_public_new_folder({
+            user_id=user_id,
+            folder_name=msg_body.category_name,
+            folder_type=msg_body.type,
+            classification_id=msg_body.classification_id},fd)
+        return
+    else
+        response_error(isOk,err_code,key,fd,"new_folder")
+    end
+end
+
+--- 获取资源文件夹列表
+s.resp.folder_list = function(msg_body,fd,user_data)
+    local isOk,err_code,key,user_id = checkMsg(msg_body,user_data,
+    {"type","page","count","classification_id"})
+    if isOk then
+        isOk =  s.resp.db_public_folder_list({user_id = user_id,
+        type=msg_body.type,
+        page=msg_body.page,
+        count = msg_body.count,
+        classification_id = msg_body.classification_id },fd)
+        return
+    else
+        response_error(isOk,err_code,key,fd,"folder_list")
+    end
+end
+
+--- 获取文件夹内所有资源
+s.resp.folder_res_list = function(msg_body,fd,user_data,call_back)
+    if call_back~=nil then
+        local duration = nil
+        if msg_body.duration ~=nil then
+            duration = msg_body.duration 
+        end
+        s.resp.db_public_folder_res_list({
+            folder_id = msg_body.folder_id,
+            user_id = msg_body.user_id,
+            page=msg_body.page, 
+            count = msg_body.count,
+            classification_id = msg_body.classification_id,
+            duration = duration},fd,call_back)
+        return
+    end
+    local isOk,err_code,key,user_id = checkMsg(msg_body,user_data,
+    {"folder_id","page","count"})
+    if isOk then
+        local duration = nil
+        if msg_body.duration ~=nil then
+            duration = msg_body.duration 
+        end
+        isOk =  s.resp.db_public_folder_res_list({
+            folder_id = msg_body.folder_id,
+            user_id = user_id,
+            page=msg_body.page, 
+            count = msg_body.count,
+            classification_id = msg_body.classification_id,
+            duration = duration},fd)
+        return
+    else
+        response_error(isOk,err_code,key,fd,"folder_res_list")
+    end
+end
+
+--- 重命名资源
+s.resp.reset_res_name = function(msg_body,fd,user_data)
+    local isOk,err_code,key,user_id = checkMsg(msg_body,user_data,
+    {"file_id","name","file_id"})
+    if isOk then
+        isOk =  s.resp.db_public_reset_res_name({
+            folder_id = msg_body.folder_id,
+            file_id = msg_body.file_id,
+            name = msg_body.name,
+            user_id = user_id},fd)
+        if not isOk then
+            return tools.response(fd,200,cjson.encode({code=10001,msg = "--重命名资源失败"}))
+        end
+        isOk = skynet.call("dbmgr","lua","on_recv","recv_ref_file_modify_info",{file_id= msg_body.file_id,name=msg_body.name})
+        return tools.response(fd,200,cjson.encode({code=10000,msg = "重命名资源成功"}))
+    else
+        response_error(isOk,err_code,key,fd,"reset_res_name")
+    end
+end
+
+--- 重命名文件夹
+s.resp.reset_folder_name = function(msg_body,fd,user_data)
+    local isOk,err_code,key,user_id = checkMsg(msg_body,user_data,
+    {"folder_id","name"})
+    if isOk then
+        isOk =  s.resp.db_public_reset_folder_name({
+            folder_id = msg_body.folder_id,
+            name = msg_body.name,
+            user_id = user_id},fd)
+        if not isOk then
+            return tools.response(fd,200,cjson.encode({code=10001,msg = "--重命名文件夹失败"}))
+        end
+        isOk = skynet.call("dbmgr","lua","on_recv","recv_ref_folder_modify_info",{folder_id= msg_body.folder_id,name=msg_body.name})
+        return tools.response(fd,200,cjson.encode({code=10000,msg = "重命名文件夹成功"}))
+    else
+        response_error(isOk,err_code,key,fd,"reset_folder_name")
+    end
+end
+
+s.resp.add_public_res_info = function(msg_body,fd,user_data)
+    local isOk,err_code,key,user_id = checkMsg(msg_body,user_data,
+    {"classification_id","stype","folder_id", "height", "width","duration", "user_id", "ratio", "category_name","file_name","size","surl","path"})
+    if isOk then
+        isOk =  s.resp.db_add_public_res_info(msg_body,fd)
+        if not isOk then
+            return tools.response(fd,200,cjson.encode({code=10001,msg = "--添加文件失败"}))
+        end
+        return tools.response(fd,200,cjson.encode({code=10000,msg = "添加文件成功"}))
+    else
+        response_error(isOk,err_code,key,fd,"add_public_res_info")
+    end
+end
+--添加公共文件列表到个人
+s.resp.add_file_list_to_private = function(msg_body,fd,user_data)
+    local isOk,err_code,key,user_id = checkMsg(msg_body,user_data,
+    {"file_id_list"})
+    if isOk then
+        isOk =  s.resp.db_public_add_file_list_to_private({
+            file_id_list = msg_body.file_id_list,
+            user_id = user_id},fd,function(isFinish)
+                if isFinish == true then
+                    return tools.response(fd,200,cjson.encode({code=10000,msg = "--添加公共文件到个人成功!"}))
+                else
+                    return tools.response(fd,200,cjson.encode({code=10001,msg = "--添加公共文件到个人失败!"}))
+                end
+            end)
+        return
+    else
+        response_error(isOk,err_code,key,fd,"add_file_to_private")
+    end
+end
+
+--添加公共文件到个人
+s.resp.add_file_to_private = function(msg_body,fd,user_data)
+    local isOk,err_code,key,user_id = checkMsg(msg_body,user_data,
+    {"file_id"})
+    if isOk then
+        isOk =  s.resp.db_public_add_file_to_private({
+            file_id = msg_body.file_id,
+            user_id = user_id},fd)
+        if isOk == true then
+            return tools.response(fd,200,cjson.encode({code=10001,msg = "--添加公共文件到个人失败!"}))
+        else
+            return tools.response(fd,200,cjson.encode({code=10000,msg = "--添加公共文件到个人成功!"}))
+        end
+    else
+        response_error(isOk,err_code,key,fd,"add_file_to_private")
+    end
+end
+
+--添加公共文件夹列表到个人
+s.resp.add_folder_list_to_private = function(msg_body,fd,user_data)
+    local isOk,err_code,key,user_id = checkMsg(msg_body,user_data,
+    {"folder_id_list"})
+    if isOk then
+        isOk =  s.resp.db_public_add_folder_list_to_private({
+            folder_id_list = msg_body.folder_id_list,
+            user_id = user_id},fd,function(isFinish)
+                if isFinish then
+                    return tools.response(fd,200,cjson.encode({code=10000,msg = "--添加公共文件夹到个人成功!"}))
+                else
+                    return tools.response(fd,200,cjson.encode({code=10001,msg = "--添加公共文件夹到个人失败!"}))
+                end
+            end)
+            return
+    else
+        response_error(isOk,err_code,key,fd,"add_folder_to_private")
+    end
+end
+--添加公共文件夹到个人
+s.resp.add_folder_to_private = function(msg_body,fd,user_data)
+    local isOk,err_code,key,user_id = checkMsg(msg_body,user_data,
+    {"folder_id"})
+    if isOk then
+        isOk =  s.resp.db_public_add_folder_to_private({
+            public_folder_id = msg_body.folder_id,
+            user_id = user_id},fd,function(isFinish)
+                if isFinish == true then
+                    return tools.response(fd,200,cjson.encode({code=10001,msg = "--添加公共文件夹到个人成功!"}))
+                else
+                    return tools.response(fd,200,cjson.encode({code=10001,msg = "--添加公共文件夹到个人失败!"}))
+                end
+            end)
+            return
+    else
+        response_error(isOk,err_code,key,fd,"add_folder_to_private")
+    end
+end
+
+--==========================逻辑 end
+
+
+
+-----------------------------------------
+-----------------------------------------
+-----------------------------------------
+-----------------------------------------
+-----------------------------------------
+-----------------------------------------
+-----------------------------------------
+-----------------------------------------
+-----------------------------------------
+-----------------------------------------
+-----------------------------------------
+
+
+
+s.resp.on_recv = function (source, fd, msg_id, msg_body,user_data)
+    skynet.error("接收一条客户端public消息 ",msg_id,user_data)
+    tools.dump(msg_body)
+    local func = string.gsub(msg_id, '/public/', '')
+    local isKick = skynet.call("agentmgr","lua","account_is_other_user_login",user_data.user_id,user_data.index) 
+    if not isKick then
+       
+    else
+         skynet.error("用户被挤掉",user_data.user_id)
+         return tools.response(fd,200,cjson.encode({code=9999,msg = "您的账号被其他用户登录!"}))
+    end
+    if s.resp[func] ~=nil then
+        msg_body = cjson.decode(msg_body)
+        return s.resp[func](msg_body,fd,user_data)
+    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") 
+        skynet.error(" 初始化公共服务成功!")       
+    end
+end
+s.start(...)

+ 134 - 0
service/tools_work/init.lua

@@ -0,0 +1,134 @@
+local skynet = require "skynet"
+local s = require "service"
+local tools = require "tools"
+local cjson = require "cjson"
+local httpc = require "http.httpc"
+local runconfig = require "run_config"
+s.resp.upload_video_sync = function(fd,msg_body)
+    -- skynet.error("msg_body",msg_body)
+    msg_body = cjson.decode(msg_body)
+    local isOk,key = tools.checkToolsSyncVideo(msg_body)
+    if not isOk then
+        local str = string.format("缺少字段: %s.", key)
+        return tools.response(fd,200,cjson.encode({code=9001,msg = str}))
+    end
+    isOk = skynet.call("dbmgr","lua","on_recv","add_res_file",msg_body)
+    if not isOk then
+        return tools.response(fd,200,cjson.encode({code=10001,msg = "失败"}))
+    else
+        return tools.response(fd,200,cjson.encode({code=10000,msg = "成功!"}))
+    end
+end
+
+s.resp.upload_audio_sync = function(fd,msg_body)
+    skynet.error("msg_body",msg_body)
+    msg_body = cjson.decode(msg_body)
+    local isOk,key = tools.checkData({"folder_id","stype","surl","path","file_name","classification_id"},msg_body)
+    if not isOk then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+    isOk = skynet.call("dbmgr","lua","on_recv","add_res_file",msg_body)
+    if not isOk then
+        return tools.response(fd,200,cjson.encode({code=10001,msg = "失败"}))
+    else
+        return tools.response(fd,200,cjson.encode({code=10000,msg = "成功!"}))
+    end
+end
+
+s.resp.upload_img_sync = function(fd,msg_body)
+    skynet.error("msg_body",msg_body)
+    msg_body = cjson.decode(msg_body)
+    local isOk,key = tools.checkData({"folder_id","stype","is_public","surl","path","file_name","classification_id"},msg_body)
+    if not isOk then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+    isOk = skynet.call("dbmgr","lua","on_recv","add_res_file",msg_body)
+    if not isOk then
+        return tools.response(fd,200,cjson.encode({code=10001,msg = "失败"}))
+    else
+        return tools.response(fd,200,cjson.encode({code=10000,msg = "成功!"}))
+    end
+end
+
+s.resp.generate_video_sync = function(fd,msg_body)
+    skynet.error("generate_video_sync",msg_body)
+    msg_body = cjson.decode(msg_body)
+    local isOk,key = tools.checkData({"id","state","path","user_id","surl","custom"},msg_body)
+    if not isOk then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+    isOk = skynet.call("dbmgr","lua","on_recv","update_gen_video_file_status",msg_body)
+    if not isOk then
+        return tools.response(fd,200,cjson.encode({code=2,msg = "失败"}))
+    else
+        return tools.response(fd,200,cjson.encode({code=1,msg = "成功!"}))
+    end
+end
+
+s.resp.upload_public_res_info = function(fd,msg_body)
+    msg_body = cjson.decode(msg_body)
+    local isOk,key = tools.checkToolsSyncVideo(msg_body)
+    if not isOk then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+    isOk = skynet.call("public_mgr","lua","tools_add_public_res_info",fd,msg_body)
+    if not isOk then
+        return tools.response(fd,200,cjson.encode({code=2,msg = "失败"}))
+    else
+        local code = 10000
+        if msg_body.user_id ~= nil then
+            if msg_body.user_id==-1 then
+                code = 1
+            end
+        end
+        return tools.response(fd,200,cjson.encode({code=code,msg = "成功!"}))
+    end
+end
+
+s.resp.tools_create_folder = function(fd,msg_body)
+    msg_body = cjson.decode(msg_body)
+    local isOk,key = tools.checkData({"classification_id","stype", "folder_name","user_id"},msg_body)
+    if not isOk then
+        return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
+    end
+    isOk = skynet.call("public_mgr","lua","tools_create_folder",fd,msg_body)
+end
+
+s.resp.on_recv = function (source, fd, msg_id, msg_body)
+    skynet.error("接收一条工具消息 ",msg_id)
+    local func = string.gsub(msg_id, "/tools/", "")
+    if s.resp[func] ~=nil then
+        return s.resp[func](fd,msg_body)
+    end
+    return tools.response(fd,200,string.format("接口 %s 不存在",func))
+end
+
+s.resp.delete_file = function(source,file_paths)
+    httpc.dns() -- set dns server
+    httpc.timeout = 100 -- set timeout 1 second
+    local func = '/file/deletes'
+    local respheader = {}
+    -- skynet.error("file_paths",file_paths)
+    -- tools.dump(file_paths)
+    local status, body = httpc.post(runconfig.tools_api,func,{file_paths=cjson.encode(file_paths)})
+    if status == 200 then
+        skynet.error("删除成功!")
+    else
+        skynet.error("删除失败!")
+    end
+end
+s.resp.generate_video = function(source,msg_body)
+    httpc.dns() -- set dns server
+    httpc.timeout = 100 -- set timeout 1 second
+    local func = '/video/generate'
+    local respheader = {}
+    -- skynet.error("file_paths",msg_body)
+    -- tools.dump(msg_body)
+    local status, body = httpc.post(runconfig.tools_api,func,{sdata=cjson.encode(msg_body)})
+    if status == 200 then
+        skynet.error("生成成功!")
+    else
+        skynet.error("生成失败!",status)
+    end
+end
+s.start(...)