904118851 11 сар өмнө
parent
commit
51928c84e0

+ 16 - 0
lualib/tools.lua

@@ -426,6 +426,22 @@ M.response_db_get_folder_info = function(fd,msg_body,isok,tab)
       end
       return M.response(fd,200,cjson.encode({code=10000,msg = "获取成功!",data=tab}))
 end
+
+M.response_db_get_file_info_by_id = function(fd,msg_body,isok,tab)
+    local error_json = '{"code": 10001,   "msg": "获取失败" }'
+    if not isok or #tab<=0 then
+      return M.response(fd,200,error_json)
+    end
+    return M.response(fd,200,cjson.encode({code=10000,msg = "获取成功!",data=tab}))
+end
+
+M.response_db_get_not_have_file_list_by_list = function(fd,msg_body,isok,tab)
+    local error_json = '{"code": 10000,   "msg": "没有被删除的文件","data": [] }'
+    if not isok or #tab<=0 then
+      return M.response(fd,200,error_json)
+    end
+    return M.response(fd,200,cjson.encode({code=10000,msg = "获取被删除的文件!",data=tab}))
+end
 M.getRandomIndex = function(array)
     local count = #array
     local index = math.random(1,count)

+ 44 - 0
service/agentmgr/init.lua

@@ -997,6 +997,50 @@ s.resp.get_folder_info = function(fd,msg_body,user_data)
     )
 end
 
+
+--根据文件ID获取文件信息
+s.resp.get_file_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
+    -- tools.dump(msg_body)
+    if user_id==nil then
+        return tools.response(fd,100,"user_id==nil get_file_info_by_id !")
+    end
+    msg_body["user_id"] = user_id
+    local isok ,key =  tools.checkData({"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","get_file_info_by_id",{
+        file_id = msg_body.file_id,
+        user_id = user_id},fd
+    )
+end
+
+--获取文件列表中已删除的文件
+s.resp.get_not_have_file_list_by_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
+    -- tools.dump(msg_body)
+    if user_id==nil then
+        return tools.response(fd,100,"user_id==nil get_not_have_file_list_by_list !")
+    end
+    msg_body["user_id"] = user_id
+    local isok ,key =  tools.checkData({"file_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","get_not_have_file_list_by_list",{
+        file_id_list = msg_body.file_id_list,
+        user_id = user_id},fd
+    )
+end
 --踢掉
 s.resp.kick = function(fd,msg_body,user_data)
     

+ 36 - 2
service/dbmgr/init.lua

@@ -488,9 +488,42 @@ s.resp.reset_res_name = function(msg_body)
     return true
 end
 
+s.resp.get_file_info_by_id = function(msg_body,fd)
+    skynet.fork(function()
+       local isOk,file_info = s.resp.get_res_file_by_id(msg_body.file_id,msg_body.user_id)
+       if isOk then
+            tools.response_db_get_file_info_by_id(fd,msg_body,true,file_info)
+       else
+            tools.response_db_get_file_info_by_id(fd,msg_body,false,nil)
+       end
+    end)
+    return true
+end
+
+s.resp.get_not_have_file_list_by_list = function(msg_body,fd)
+    skynet.fork(function()
+        local temp = {}
+        local count = 1
+        for i = 1, #msg_body.file_id_list, 1 do
+            local file_id = msg_body.file_id_list[i]
+            local isOk,file_info = s.resp.get_res_file_by_id(file_id,msg_body.user_id)
+            if not isOk then
+                table.insert(temp,count,file_id)
+                count = count +1
+            end
+        end
+        tools.response_db_get_not_have_file_list_by_list(fd,msg_body,true,temp)
+    end)
+    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)
+s.resp.get_res_file_by_id = function(file_id,user_id)
+    local select_user_id_sql = ""
+    if user_id~=nil then
+        select_user_id_sql = " AND user_id = " ..user_id
+    end
+    local sql = string.format("select * from res_list_tab where id = %d  AND is_delete = 0"..select_user_id_sql,file_id)
     -- skynet.error("sql",sql)
     local res = db:query(sql)
       -- 判断是否找到数据
@@ -504,6 +537,7 @@ s.resp.get_res_file_by_id = function(file_id)
     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)