AuthPlatform/src/dao/account.lua

93 lines
2.3 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
--- 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 accountModel = Model:new('sys_account')
local _M = {}
--判断账户是否存在
local function isExistAccount(id)
--根据账户id进行验证账户是否存在
local code, res = accountModel: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.getSystemAccounts(pageNum, pageSize)
return accountModel:paginate(pageNum, pageSize)
end
--根据账户id获取账户信息
function _M.getSystemAccount(id)
return accountModel:find(id)
end
--增加账户信息到数据表
function _M.addSystemAccount(jsonData)
--解析json中的键和数据值
local name = jsonData['name']
--根据账户进行验证账户是否存在
local code, res = accountModel:where("name", "=", name):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()
local ret = helpers.convert_json(jsonData)
-- 创建一个账户
return accountModel:create('{'..ret..'}')
end
--删除账户信息到数据表
function _M:deleteSystemAccount(id)
--根据账户id进行验证账户是否存在
local ok = isExistAccount(id)
--账户不存在则返回
if ok == false then
return 0x000001,nil
end
return accountModel:delete(id)
end
--更新账户信息到数据表
function _M:updateSystemAccount(id, jsonData)
--根据账户id进行验证账户是否存在
local ok = isExistAccount(id)
--账户不存在则返回
if ok == false then
return 0x000001,nil
end
--对数据内容进行更新
return accountModel:where('id', '=', id):update(jsonData)
end
return _M