Commit 231ca77d by 王昆

gsb

parent bdbcc176
......@@ -31,5 +31,30 @@ class UserroleDao extends Dao {
user_id: user_id
}) || [];
}
async mapByUserIds(userIds) {
let result = {};
let sql = [];
sql.push("SELECT");
sql.push("user_id, role_id");
sql.push("FROM uc_user_role");
sql.push("WHERE user_id IN (:userIds)");
sql.push("GROUP BY user_id, role_id");
let list = await this.customQuery(sql.join(" "), {userIds: userIds});
if (!list || list.length == 0) {
return {};
}
for (let item of list) {
let roleIds = result[item.user_id];
if (!roleIds) {
roleIds = [];
}
roleIds.push(item.role_id);
result[item.user_id] = roleIds;
}
return result;
}
}
module.exports = UserroleDao;
\ No newline at end of file
......@@ -101,25 +101,40 @@ class AuthService extends ServiceBase {
}
async menuByRoleIds(params) {
params.menuType = 1;
var all = await this.byRoleIds(params);
let all = await this.byRoleIds(params);
if(!all || all.length == 0) {
return [];
}
var pmap = {};
for (var item of all) {
var list = pmap[item.pid];
if (!list) {
list = [];
let pmenus = [];
let pmenuMap = {};
for (let item of all) {
if (item.pid === 0) {
pmenus.push(item);
pmenuMap[item.id] = item;
}
list.push(item);
pmap[item.pid] = list;
}
for(var item of all) {
item.childs = pmap[item.id] || [];
for (let item of all) {
let pid = item.pid;
if (pid === 0) {
continue;
}
if(pmap.length == 0) {
return system.getResultSuccess({});
let pmenu = pmenuMap[pid];
if (!pmenu) {
continue;
}
return system.getResultSuccess(pmap[0][0]);
let childs = pmenu.childs;
if (!childs) {
childs = [];
}
childs.push(item);
pmenu.childs = childs;
}
return pmenus;
}
async authByRoleIds(params) {
......
......@@ -259,6 +259,7 @@ class UserService extends ServiceBase {
user.realName = info.realName;
user.roles = await this.userroleDao.listByUserId(id, "user_id, role_id");
await this.setRoleIds([user]);
this.handleDate(user, ["created_at"], null, -8);
return system.getResultSuccess(user);
}
......@@ -293,9 +294,10 @@ class UserService extends ServiceBase {
params.startRow = (currentPage - 1) * pageSize;
result.rows = await this.dao.listByCondition(params) || [];
if (result.rows) {
for (var item of result.rows) {
for (let item of result.rows) {
this.handleDate(item, ["created_at"], null, -8);
}
await this.setRoleIds(result.rows);
}
return system.getResultSuccess(result);
}
......@@ -342,6 +344,22 @@ class UserService extends ServiceBase {
let rs = await this.dao.findUsers(params);
return system.getResultSuccess(rs);
}
async setRoleIds(rows) {
if (!rows || rows.length == 0) {
return;
}
let userIds = [];
for (let row of rows) {
userIds.push(row.id);
}
let roleIdMap = await this.userroleDao.mapByUserIds(userIds);
for (let row of rows) {
row.roleIds = roleIdMap[row.id] || [];
}
}
}
module.exports = UserService;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment