--- --- Generated by EmmyLua(https://github.com/EmmyLua) --- Created by admin. --- DateTime: 2025/10/25 16:36 --- 数据表模型文件 local helpers = require("share.helpers") --引用使用的库文件 local model = require("share.model") --创建一个数据表相关的模型 local roleModel = model:new('sys_role') local _M = {} --判断角色是否存在 local function isExistRole(id) --根据角色id进行验证角色是否存在 local code, res = roleModel:find(id) if code ~= 0 then return false end local num = 0 if res ~= nil then num = table.getn(res) end --角色不存在返回错误 if num <= 0 then return false end return true end -- 查询数据表中的所有角色信息 function _M.getSystemRoles(pageNum, pageSize) return roleModel:paginate(pageNum, pageSize) end --根据角色id获取角色信息 function _M.getSystemRole(id) return roleModel:find(id) end --增加角色信息到数据表 function _M.addSystemRole(jsonData) --解析json中的键和数据值 local roleName = jsonData['role_name'] --根据角色、手机号、邮箱进行验证角色是否存在 local code, res = roleModel:where("role_name", "=", roleName):get() if code ~= 0 then return 0x000001,res end local num = 0 if res ~= nil then num = table.getn(res) end --角色存在时返回角色已经存在 if num > 0 then return 0x01000C,nil end --键值为id产生uuid数据值,增加到json中 jsonData.id = helpers.getUuid() -- 创建一个角色 return roleModel:create(jsonData) end --删除角色信息到数据表 function _M:deleteSystemRole(id) --根据角色id进行验证角色是否存在 local ok = isExistRole(id) --角色不存在则返回 if ok == false then return 0x000001,nil end return roleModel:delete(id) end --更新角色信息到数据表 function _M:updateSystemRole(id, jsonData) --根据角色id进行验证角色是否存在 local ok = isExistRole(id) --角色不存在则返回 if ok == false then return 0x000001,nil end --对数据内容进行更新 return roleModel:where('id', '=', id):update(jsonData) end return _M