修改接口相关数据和数据表名称,增加账号信息相关业务逻辑查询
This commit is contained in:
parent
2080f423b1
commit
c5a12dbf9d
|
|
@ -42,10 +42,10 @@ local routes = {
|
|||
},
|
||||
--账户相关路由接口
|
||||
{
|
||||
paths = { "/api/get-accounts" },
|
||||
metadata = { "metadata get-accounts" },
|
||||
paths = { "/api/get-account" },
|
||||
metadata = { "metadata get-account" },
|
||||
methods = { "GET" },
|
||||
handler = accountApi.get_allaccounts,
|
||||
handler = accountApi.get_allaccount,
|
||||
},
|
||||
{
|
||||
paths = { "/api/get-account/:id" },
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
local _M = {}
|
||||
|
||||
local dao = require("service.system.user")
|
||||
local dao = require("service.system.account")
|
||||
local resp = require("util.response")
|
||||
|
||||
--验证请求头是否正确
|
||||
|
|
@ -20,14 +20,14 @@ local function checkReqHeader()
|
|||
return true
|
||||
end
|
||||
|
||||
--获取所有用户信息
|
||||
function _M.get_allaccount(uuid)
|
||||
local code,ret = dao.getAllAccount(uuid)
|
||||
--获取所有账号信息
|
||||
function _M.get_allaccount()
|
||||
local code,ret = dao.getAllAccount()
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
||||
--根据用户id获取用户信息
|
||||
--根据账号id获取账号信息
|
||||
function _M.get_account(m)
|
||||
local id = m.id
|
||||
local code,ret = dao.getAccount(id)
|
||||
|
|
@ -35,7 +35,7 @@ function _M.get_account(m)
|
|||
resp:send(result)
|
||||
end
|
||||
|
||||
--根据用户id获取用户信息
|
||||
--根据账号id获取账号信息
|
||||
function _M.add_account()
|
||||
--获取请求头并进行校验
|
||||
if checkReqHeader() == false then
|
||||
|
|
@ -57,7 +57,7 @@ function _M.add_account()
|
|||
resp:send(result)
|
||||
end
|
||||
|
||||
--根据用户id删除用户信息
|
||||
--根据账号id删除账号信息
|
||||
function _M.delete_account(m)
|
||||
local id = m.id
|
||||
local code, ret = dao.deleteAccount(id)
|
||||
|
|
@ -65,10 +65,20 @@ function _M.delete_account(m)
|
|||
resp:send(result)
|
||||
end
|
||||
|
||||
--根据用户id删除用户信息
|
||||
--根据账号id删除账号信息
|
||||
function _M.update_account(m)
|
||||
local id = m.id
|
||||
local code, ret = dao.updateAccount(id)
|
||||
--读取请求体的数据
|
||||
ngx.req.read_body()
|
||||
--获取请求数据
|
||||
local body_data = ngx.req.get_body_data()
|
||||
--判断请求体数据是否为空
|
||||
if body_data == nil then
|
||||
local result = resp:json(0x000001)
|
||||
resp:send(result)
|
||||
return
|
||||
end
|
||||
local code, ret = dao.updateAccount(id, body_data)
|
||||
local result = resp:json(code, ret)
|
||||
resp:send(result)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -70,31 +70,29 @@ local function checkJson(jsonData)
|
|||
end
|
||||
|
||||
--通过查询条件判断数据库中的数据记录
|
||||
--根据用户、手机号、邮箱进行验证用户是否存在
|
||||
local function checkAccountExist(username, phone, email)
|
||||
local function checkAccountExist(where)
|
||||
--组装sql语句
|
||||
local where = string.format("where username='%s' or phone='%s' or email='%s'", username, phone, email)
|
||||
local sql = string.format("select count(*) as count from \"T_Users\" %s", where)
|
||||
local sql = string.format("select count(*) as count from \"tbl_account\" %s", where)
|
||||
print("check sql: "..sql)
|
||||
--获取数据库连接
|
||||
return execSQL(sql)
|
||||
end
|
||||
|
||||
-- 查询数据表中的所有账户根据用户的uuid
|
||||
function _M.getAllAccount(uuid)
|
||||
-- 查询数据表中的所有账号信息
|
||||
function _M.getAllAccount()
|
||||
--组装sql语句
|
||||
local sql = "select * from \"T_Users\""
|
||||
local sql = "select * from \"tbl_account\""
|
||||
return execSQL(sql)
|
||||
end
|
||||
|
||||
--根据用户id获取用户信息
|
||||
function _M.getAccount(uuid)
|
||||
--根据用户id获取账号信息
|
||||
function _M.getAccount(id)
|
||||
--组装sql语句
|
||||
local sql = "select * from \"T_Users\" where uuid='"..uuid.."'"
|
||||
local sql = "select * from \"tbl_account\" where id='"..id.."'"
|
||||
return execSQL(sql)
|
||||
end
|
||||
|
||||
--增加用户信息到数据表
|
||||
--增加账号信息到数据表
|
||||
function _M.addAccount(jsonData)
|
||||
--验证数据的正确性,错误时返回
|
||||
local success, result = checkJson(jsonData)
|
||||
|
|
@ -112,8 +110,9 @@ function _M.addAccount(jsonData)
|
|||
if key == "phone" then phone = value end
|
||||
if key == "email" then email = value end
|
||||
end
|
||||
--校验用户是否存在
|
||||
local ok, res = checkAccountExist(username, phone, email)
|
||||
--根据用户、手机号、邮箱进行验证用户是否存在
|
||||
local where = string.format("where username='%s' or phone='%s' or email='%s'", username, phone, email)
|
||||
local ok, res = checkAccountExist(where)
|
||||
if ok ~= 0 then
|
||||
return 0x000001,res
|
||||
end
|
||||
|
|
@ -128,17 +127,52 @@ function _M.addAccount(jsonData)
|
|||
return 0x010000,nil
|
||||
end
|
||||
--自己增加对应的uuid数据值
|
||||
local newKeys = keys.."uuid"
|
||||
local newKeys = keys.."id"
|
||||
local newValues = values.."'"..getUuid().."'"
|
||||
--组装sql语句
|
||||
local sql = string.format("insert into \"T_Users\"(%s)values(%s)", newKeys, newValues)
|
||||
local sql = string.format("insert into \"tbl_account\"(%s)values(%s)", newKeys, newValues)
|
||||
return execSQL(sql)
|
||||
end
|
||||
|
||||
--增加用户信息到数据表
|
||||
function _M.deleteAccount(uuid)
|
||||
--增加账号信息到数据表
|
||||
function _M.deleteAccount(id)
|
||||
--组装sql语句
|
||||
local sql = "delete from \"T_Users\" where uuid='"..uuid.."'"
|
||||
local sql = "delete from \"tbl_account\" where id='"..id.."'"
|
||||
return execSQL(sql)
|
||||
end
|
||||
|
||||
--更新账号信息到数据表
|
||||
function _M.updateAccount(id, jsonData)
|
||||
--根据用户id进行验证用户是否存在
|
||||
local where = string.format("where id='%s'", id)
|
||||
local ok, res = checkAccountExist(where)
|
||||
if ok ~= 0 then
|
||||
return 0x000001,res
|
||||
end
|
||||
local num = 0
|
||||
for _, row in ipairs(res) do
|
||||
for key, value in pairs(row) do
|
||||
num = value
|
||||
end
|
||||
end
|
||||
print("exec result:", num)
|
||||
if num <= 0 then
|
||||
return 0x01000C,nil
|
||||
end
|
||||
--验证数据的正确性,错误时返回
|
||||
local success, result = checkJson(jsonData)
|
||||
if success == false then
|
||||
return 0x000001,result
|
||||
end
|
||||
--解析json中的键和数据值
|
||||
local tmp = ""
|
||||
for key, value in pairs(result) do
|
||||
local val = (type(value) == "string") and "'"..value.."'" or value
|
||||
tmp = string.format("%s=%s,", key, val)
|
||||
end
|
||||
local vals = tmp:sub(1, #tmp - 1)
|
||||
--组装sql语句
|
||||
local sql = string.format("update \"tbl_account\" set %s where id='%s'", vals, id)
|
||||
return execSQL(sql)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ end
|
|||
--通过查询条件判断数据库中的数据记录
|
||||
local function checkUserExist(where)
|
||||
--组装sql语句
|
||||
local sql = string.format("select count(*) as count from \"tbl_users\" %s", where)
|
||||
local sql = string.format("select count(*) as count from \"tbl_user\" %s", where)
|
||||
print("check sql: "..sql)
|
||||
--获取数据库连接
|
||||
return execSQL(sql)
|
||||
|
|
@ -81,14 +81,14 @@ end
|
|||
-- 查询数据表中的所有用户信息
|
||||
function _M.getAllUser()
|
||||
--组装sql语句
|
||||
local sql = "select * from \"tbl_users\""
|
||||
local sql = "select * from \"tbl_user\""
|
||||
return execSQL(sql)
|
||||
end
|
||||
|
||||
--根据用户id获取用户信息
|
||||
function _M.getUser(id)
|
||||
--组装sql语句
|
||||
local sql = "select * from \"tbl_users\" where id='"..id.."'"
|
||||
local sql = "select * from \"tbl_user\" where id='"..id.."'"
|
||||
return execSQL(sql)
|
||||
end
|
||||
|
||||
|
|
@ -130,19 +130,19 @@ function _M.addUser(jsonData)
|
|||
local newKeys = keys.."id"
|
||||
local newValues = values.."'"..getUuid().."'"
|
||||
--组装sql语句
|
||||
local sql = string.format("insert into \"tbl_users\"(%s)values(%s)", newKeys, newValues)
|
||||
local sql = string.format("insert into \"tbl_user\"(%s)values(%s)", newKeys, newValues)
|
||||
return execSQL(sql)
|
||||
end
|
||||
|
||||
--增加用户信息到数据表
|
||||
function _M.delete_user(id)
|
||||
function _M.deleteUser(id)
|
||||
--组装sql语句
|
||||
local sql = "delete from \"tbl_users\" where id='"..id.."'"
|
||||
local sql = "delete from \"tbl_user\" where id='"..id.."'"
|
||||
return execSQL(sql)
|
||||
end
|
||||
|
||||
--更新用户信息到数据表
|
||||
function _M.update_user(id, jsonData)
|
||||
function _M.updateUser(id, jsonData)
|
||||
--根据用户id进行验证用户是否存在
|
||||
local where = string.format("where id='%s'", id)
|
||||
local ok, res = checkUserExist(where)
|
||||
|
|
@ -172,7 +172,7 @@ function _M.update_user(id, jsonData)
|
|||
end
|
||||
local vals = tmp:sub(1, #tmp - 1)
|
||||
--组装sql语句
|
||||
local sql = string.format("update \"tbl_users\" set %s where id='%s'", vals, id)
|
||||
local sql = string.format("update \"tbl_user\" set %s where id='%s'", vals, id)
|
||||
return execSQL(sql)
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user