AuthPlatform/src/service/system/application.lua

100 lines
2.7 KiB
Lua
Raw Normal View History

---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by .
--- DateTime: 2025/9/27 16:02
--- 业务逻辑 对应用数据表进行数据表业务处理
local validator = require("util.validator")
local helpers = require("util.helpers")
local application = require("model.application")
local _M = {}
-- 查询数据表中的所有应用信息
function _M.getAllApplication()
return application:all()
end
--根据应用id获取应用信息
function _M.getApplication(id)
return application.find(id)
end
--根据组织id获取应用信息
function _M.getOrganizationApplication(id)
--todo
return application.find(id)
end
--根据用户id获取应用信息
function _M.getUserApplication(id)
--todo
return application.find(id)
end
--增加应用信息到数据表
function _M.addApplication(jsonData)
--验证数据的正确性,错误时返回
local success, result = validator.checkJson(jsonData)
if success == false then
return 0x000001, result
end
--解析json中的键和数据值
local name = ""
for key, value in pairs(result) do
if key == "name" then name = value end
end
--根据应用进行验证是否存在
local code, res = application:where("name", "=", name):get()
if code ~= 0 then
return 0x000001, res
end
local num = 0
for _, row in ipairs(res) do
for key, value in pairs(row) do
num = num + 1
end
end
--应用存在时返回应用已经存在
if num <= 0 then
return 0x01000C, nil
end
--键值为id产生uuid数据值增加到json中
result.id = helpers.getUuid()
local ret = helpers.convert_json(result)
-- 创建一个应用
return application:create('{'..ret..'}')
end
--删除应用信息到数据表
function _M.deleteApplication(id)
return application:delete(id)
end
--更新应用信息到数据表
function _M.updateApplication(id, jsonData)
--根据应用id进行验证应用是否存在
local code, res = application:find(id)
if code ~= 0 then
return 0x000001, res
end
local num = 0
for _, row in ipairs(res) do
for key, value in pairs(row) do
num = num + 1
end
end
--应用不存在返回错误
if num <= 0 then
return 0x01000C, nil
end
--验证数据的正确性,错误时返回
local success, result = validator.checkJson(jsonData)
if success == false then
return 0x000001, result
end
--对数据内容进行更新
return application:where('id', '=', id):update(jsonData)
end
return _M