AuthPlatform/src/dao/position.lua

92 lines
2.3 KiB
Lua
Raw Normal View History

---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by admin.
--- DateTime: 2025/11/04 15:14
--- 数据表模型文件
local helpers = require("share.helpers")
--引用使用的库文件
local model = require("share.model")
--创建一个数据表相关的模型
local positionModel = model:new('sys_post')
local _M = {}
--判断岗位是否存在
local function isExistPosition(id)
--根据岗位id进行验证岗位是否存在
local code, res = positionModel: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.getSystemPositions(pageNum, pageSize)
return positionModel:paginate(pageNum, pageSize)
end
--根据岗位id获取岗位信息
function _M.getSystemPosition(id)
return positionModel.find(id)
end
--增加岗位信息到数据表
function _M.addSystemPosition(jsonData)
--解析json中的键和数据值
local post_id = jsonData['post_id']
--根据岗位id进行验证岗位是否存在
local code, res = positionModel:where("post_id", "=", post_id):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 positionModel:create(jsonData)
end
--删除岗位信息到数据表
function _M.deleteSystemPosition(id)
--根据岗位id进行验证岗位是否存在
local ok = isExistPosition(id)
--岗位不存在则返回
if ok == false then
return 0x000001,nil
end
return positionModel:delete(id)
end
--更新岗位信息到数据表
function _M.updateSystemPosition(id, jsonData)
--根据岗位id进行验证岗位是否存在
local ok = isExistPosition(id)
--岗位不存在则返回
if ok == false then
return 0x000001,nil
end
jsonData.update_time = ngx.time()
--对数据内容进行更新
return positionModel:where('post_id', '=', id):update(jsonData)
end
return _M