Commit 4e8ca5d1 by 王昆

gsb

parent cc7b6390
...@@ -76,14 +76,14 @@ class ActionAPI extends APIBase { ...@@ -76,14 +76,14 @@ class ActionAPI extends APIBase {
case "findById": case "findById":
opResult = await this.orgSve.apiFindById(action_body); opResult = await this.orgSve.apiFindById(action_body);
break; break;
case "byPid": case "orgByPid":
opResult = await this.orgSve.apiByPid(action_body); opResult = await this.orgSve.apiByPid(action_body);
break; break;
case "orgTree": case "orgTree":
opResult = await this.orgSve.apiTree(); opResult = await this.orgSve.apiTree();
break; break;
// 菜单权限 // 菜单权限
case "addAuth": case "addAuth":
opResult = this.authSve.add(action_body); opResult = this.authSve.add(action_body);
break; break;
...@@ -96,7 +96,7 @@ class ActionAPI extends APIBase { ...@@ -96,7 +96,7 @@ class ActionAPI extends APIBase {
case "authInfo": case "authInfo":
opResult = this.authSve.info(action_body); opResult = this.authSve.info(action_body);
break; break;
case "byPid": case "authByPid":
opResult = this.authSve.byPid(action_body); opResult = this.authSve.byPid(action_body);
break; break;
case "delAuth": case "delAuth":
...@@ -118,31 +118,37 @@ class ActionAPI extends APIBase { ...@@ -118,31 +118,37 @@ class ActionAPI extends APIBase {
opResult = await this.roleSve.apiListRole(action_body); opResult = await this.roleSve.apiListRole(action_body);
break; break;
case "roleQueryById": case "roleQueryById":
opResult = await this.roleSve.apiQueryById(action_body); opResult = await this.roleSve.apiQueryById(action_body);
break; break;
// 用户 // 用户
case "addUser": case "addUser":
action_body.org = await this.orgSve.findById(Number(action_body.org_id)); if (action_body.uctype === 1) {
if (!action_body.org) { action_body.org = await this.orgSve.findById(Number(action_body.org_id));
opResult = system.getResult(null, `组织机构不存在`); if (!action_body.org) {
} else { return system.getResult(null, `组织机构不存在`);
opResult = this.userSve.add(action_body); }
} }
opResult = this.userSve.add(action_body);
break; break;
case "updUser": case "updUser":
action_body.org = await this.orgSve.findById(Number(action_body.org_id)); if (action_body.uctype === 1) {
if (!action_body.org) { action_body.org = await this.orgSve.findById(Number(action_body.org_id));
opResult = system.getResult(null, `当前SAAS不能删除`); if (!action_body.org) {
} else { return system.getResult(null, `组织机构不存在`);
opResult = this.userSve.upd(action_body); }
} }
opResult = this.userSve.upd(action_body);
break; break;
case "userInfo": case "userInfo":
opResult = this.userSve.info(action_body); opResult = this.userSve.info(action_body);
break; break;
case "enabled":
opResult = this.userSve.enabled(action_body);
break;
case "delUser": case "delUser":
opResult = this.userSve.delUser(action_body);
break; break;
case "listUser": case "userPage":
opResult = this.userSve.pageByCondition(action_body); opResult = this.userSve.pageByCondition(action_body);
break; break;
} }
......
...@@ -5,8 +5,19 @@ class AuthDao extends Dao { ...@@ -5,8 +5,19 @@ class AuthDao extends Dao {
super(Dao.getModelName(AuthDao)); super(Dao.getModelName(AuthDao));
} }
async all() { async all(saas_id, attrs) {
return this.customQuery("SELECT * FROM uc_auth WHERE deleted_at IS NULL"); attrs = attrs || "*";
var sql = [];
sql.push("SELECT");
sql.push(attrs);
sql.push("FROM uc_auth");
sql.push("WHERE deleted_at IS NULL");
var params = {};
if(saas_id) {
sql.push("AND saas_id = :saas_id");
params.saas_id = saas_id;
}
return this.customQuery(sql.join(" "), params);
} }
} }
module.exports = AuthDao; module.exports = AuthDao;
\ No newline at end of file
...@@ -38,7 +38,7 @@ class UserDao extends Dao { ...@@ -38,7 +38,7 @@ class UserDao extends Dao {
sql.push("count(1) as num"); sql.push("count(1) as num");
sql.push("FROM uc_user t1"); sql.push("FROM uc_user t1");
sql.push("INNER JOIN uc_user_info t2 ON t1.id = t2.id"); sql.push("INNER JOIN uc_user_info t2 ON t1.id = t2.id");
sql.push("WHERE 1 = 1"); sql.push("WHERE t1.deleted_at IS NULL");
var list = await this.customQuery(sql.join(" "), params); var list = await this.customQuery(sql.join(" "), params);
if (!list || list.length == 0) { if (!list || list.length == 0) {
...@@ -58,7 +58,7 @@ class UserDao extends Dao { ...@@ -58,7 +58,7 @@ class UserDao extends Dao {
sql.push("t2.mobile, t2.realName"); sql.push("t2.mobile, t2.realName");
sql.push("FROM uc_user t1"); sql.push("FROM uc_user t1");
sql.push("INNER JOIN uc_user_info t2 ON t1.id = t2.id"); sql.push("INNER JOIN uc_user_info t2 ON t1.id = t2.id");
sql.push("WHERE 1 = 1"); sql.push("WHERE t1.deleted_at IS NULL");
this.setCondition(sql, params); this.setCondition(sql, params);
...@@ -67,7 +67,7 @@ class UserDao extends Dao { ...@@ -67,7 +67,7 @@ class UserDao extends Dao {
return await this.customQuery(sql.join(" "), params); return await this.customQuery(sql.join(" "), params);
} }
setCondition(params, sql) { setCondition(sql, params) {
if (!params || !sql) { if (!params || !sql) {
return; return;
} }
...@@ -98,6 +98,10 @@ class UserDao extends Dao { ...@@ -98,6 +98,10 @@ class UserDao extends Dao {
if(params.createEnd) { if(params.createEnd) {
sql.push("AND t1.created_at <= :createEnd"); sql.push("AND t1.created_at <= :createEnd");
} }
if(params.isEnabled === 0 || params.isEnabled === 1) {
sql.push("AND t1.isEnabled = :isEnabled");
}
} }
} }
module.exports = UserDao; module.exports = UserDao;
\ No newline at end of file
...@@ -12,8 +12,9 @@ class UserroleDao extends Dao { ...@@ -12,8 +12,9 @@ class UserroleDao extends Dao {
}, t) || []; }, t) || [];
} }
async listByUserId(user_id, t) { async listByUserId(user_id, attrs, t) {
var sql = "SELECT * FROM uc_user_role WHERE user_id = :user_id"; attrs = attrs || "*";
var sql = "SELECT " + attrs + " FROM uc_user_role WHERE user_id = :user_id";
return await this.customQuery(sql, { return await this.customQuery(sql, {
user_id: user_id user_id: user_id
}, t) || []; }, t) || [];
......
...@@ -4,7 +4,7 @@ const uiconfig = system.getUiConfig2(settings.appKey); ...@@ -4,7 +4,7 @@ const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => { module.exports = (db, DataTypes) => {
return db.define("userrole", { return db.define("userrole", {
user_id: DataTypes.INTEGER, user_id: DataTypes.INTEGER,
org_id: DataTypes.INTEGER, role_id: DataTypes.INTEGER,
}, { }, {
paranoid: true, //假的删除 paranoid: true, //假的删除
underscored: true, underscored: true,
......
...@@ -12,7 +12,7 @@ class AuthService extends ServiceBase { ...@@ -12,7 +12,7 @@ class AuthService extends ServiceBase {
var pid = Number(obj.pid || 0); var pid = Number(obj.pid || 0);
if (!saas_id) { if (!saas_id) {
return system.getResult(null, "请指定saas_id"); return system.getResult(null, "saas_id不存在");
} }
if (pid === 0) { if (pid === 0) {
...@@ -47,7 +47,7 @@ class AuthService extends ServiceBase { ...@@ -47,7 +47,7 @@ class AuthService extends ServiceBase {
} }
var auth = await this.findById(id); var auth = await this.findById(id);
if (!saas_id) { if (!saas_id) {
return system.getResult(null, "请指定saas_id"); return system.getResult(null, "saas_id不存在");
} }
if (saas_id != auth.saas_id) { if (saas_id != auth.saas_id) {
...@@ -68,11 +68,11 @@ class AuthService extends ServiceBase { ...@@ -68,11 +68,11 @@ class AuthService extends ServiceBase {
var list = await this.dao.findAll({ var list = await this.dao.findAll({
pid: obj.pid || 0, pid: obj.pid || 0,
}); });
return list; return system.getResultSuccess(list);
} }
async tree() { async tree(params) {
var all = await this.dao.all(); var all = await this.dao.all(params.saas_id, "id, pid, menuType, name, icon, path");
var pmap = {}; var pmap = {};
for (var item of all) { for (var item of all) {
...@@ -87,8 +87,7 @@ class AuthService extends ServiceBase { ...@@ -87,8 +87,7 @@ class AuthService extends ServiceBase {
for(var item of all) { for(var item of all) {
item.childs = pmap[item.id] || []; item.childs = pmap[item.id] || [];
} }
return system.getResultSuccess(pmap[0][0]);
return system.getResultSuccess(pmap[0]);
} }
async info(obj) { async info(obj) {
......
...@@ -110,13 +110,25 @@ class OrgService extends ServiceBase { ...@@ -110,13 +110,25 @@ class OrgService extends ServiceBase {
try { try {
var pid = Number(params.pid || 0); var pid = Number(params.pid || 0);
params.orgname = this.trim(params.orgname); params.orgname = this.trim(params.orgname);
params.saas_id = Number(params.saas_id || 0);
if(!params.saas_id){return system.getResult(-1,`saas_id不存在`)}
if(!params.orgname){return system.getResult(-1,`参数错误 组织名称不能为空`)} if(!params.orgname){return system.getResult(-1,`参数错误 组织名称不能为空`)}
let _orgByName = await this.findOne({orgname:params.orgname}); let _orgByName = await this.findOne({orgname:params.orgname, saas_id: params.saas_id});
if(_orgByName){ if(_orgByName){
return system.getResult(-1,`参数错误 组织名称已经存在`); return system.getResult(-1,`参数错误 组织名称已经存在`);
} }
let path = ""; let path = "";
if(pid===0){ if(pid === 0){
// 验证是否存在其他权限
var exist = await this.findCount({
where: {
saas_id: saas_id
}
});
if (exist) {
return system.getResult(null, "菜单根目录已经存在");
}
path = `/${params.orgname}`; path = `/${params.orgname}`;
}else{ }else{
let _org = await this.findOne({id:pid}); let _org = await this.findOne({id:pid});
......
...@@ -39,7 +39,7 @@ class UserService extends ServiceBase { ...@@ -39,7 +39,7 @@ class UserService extends ServiceBase {
async add(obj) { async add(obj) {
var roles = obj.roles || []; var roles = obj.roles || [];
var org = obj.org; var org = obj.org || {};
var saas_id = Number(obj.saas_id || 0); var saas_id = Number(obj.saas_id || 0);
var ucid = this.trim(obj.ucid); var ucid = this.trim(obj.ucid);
var ucname = this.trim(obj.ucname); var ucname = this.trim(obj.ucname);
...@@ -50,7 +50,7 @@ class UserService extends ServiceBase { ...@@ -50,7 +50,7 @@ class UserService extends ServiceBase {
var isMain = obj.isMain || 0; var isMain = obj.isMain || 0;
if (!saas_id) { if (!saas_id) {
return system.getResult(null, "请指定saas_id"); return system.getResult(null, "saas_id不存在");
} }
var exist = await this.findOne({ var exist = await this.findOne({
...@@ -66,13 +66,13 @@ class UserService extends ServiceBase { ...@@ -66,13 +66,13 @@ class UserService extends ServiceBase {
ucname: ucname, ucname: ucname,
password: await this.getEncryptStr(password), password: await this.getEncryptStr(password),
uctype: uctype, uctype: uctype,
org_id: org.id, org_id: org.id || 0,
isMain: isMain, isMain: isMain,
orgpath: "", orgpath: "",
isEnabled: 1, isEnabled: 1,
} }
var orgpath = org.path; var orgpath = org.path || "";
var info = { var info = {
mobile: mobile, mobile: mobile,
...@@ -94,14 +94,14 @@ class UserService extends ServiceBase { ...@@ -94,14 +94,14 @@ class UserService extends ServiceBase {
await self.userroleDao.bulkCreate(roles, t); await self.userroleDao.bulkCreate(roles, t);
} }
if (!isMain) { if (user.uctype === 1) {
orgpath = orgpath + "/" + user.id; orgpath = isMain ? orgpath : orgpath + "/" + user.id;
await self.dao.update({
id: user.id,
orgpath: orgpath
}, t);
} }
user.orgpath = orgpath; user.orgpath = orgpath;
await self.dao.update({
id: user.id,
orgpath: orgpath
}, t);
return user; return user;
}); });
...@@ -111,7 +111,7 @@ class UserService extends ServiceBase { ...@@ -111,7 +111,7 @@ class UserService extends ServiceBase {
async upd(obj) { async upd(obj) {
var id = obj.id; var id = obj.id;
var roles = obj.roles || []; var roles = obj.roles || [];
var org = obj.org; var org = obj.org || {};
var uctype = this.trim(obj.uctype); var uctype = this.trim(obj.uctype);
var mobile = this.trim(obj.mobile); var mobile = this.trim(obj.mobile);
var realName = this.trim(obj.realName); var realName = this.trim(obj.realName);
...@@ -119,11 +119,13 @@ class UserService extends ServiceBase { ...@@ -119,11 +119,13 @@ class UserService extends ServiceBase {
var user = { var user = {
id: id, id: id,
org_id: org.id, org_id: org.id || "",
orgpath: isMain ? org.path : org.path + "/" + id, orgpath: "",
isMain: obj.isMain || 0, isMain: obj.isMain || 0,
} }
if(user.uctype === 1) {
user.orgpath = isMain ? org.path : org.path + "/" + id;
}
var info = { var info = {
id: id, id: id,
mobile: mobile, mobile: mobile,
...@@ -159,11 +161,21 @@ class UserService extends ServiceBase { ...@@ -159,11 +161,21 @@ class UserService extends ServiceBase {
user.mobile = info.mobile; user.mobile = info.mobile;
user.realName = info.realName; user.realName = info.realName;
user.roles = await this.userroleDao.listByUserId(id); user.roles = await this.userroleDao.listByUserId(id, "user_id, role_id");
this.handleDate(user, ["created_at"], null, -8); this.handleDate(user, ["created_at"], null, -8);
return system.getResultSuccess(user); return system.getResultSuccess(user);
} }
async enabled(params) {
var user = await this.dao.findById(params.id);
if (!user) {
return system.getResult(null, "用户不存在");
}
user.isEnabled = Number(params.enabled || 0) == 0 ? false : true;
await user.save();
return system.getResultSuccess();
}
async pageByCondition(params) { async pageByCondition(params) {
var result = { var result = {
count: 0, count: 0,
...@@ -180,17 +192,24 @@ class UserService extends ServiceBase { ...@@ -180,17 +192,24 @@ class UserService extends ServiceBase {
result.count = total; result.count = total;
params.startRow = (currentPage - 1) * pageSize; params.startRow = (currentPage - 1) * pageSize;
result.rows = await this.dao.listByCondition(params) || []; result.rows = await this.dao.listByCondition(params) || [];
if(result.rows) {
for(var item of result.rows) {
this.handleDate(item, ["created_at"], null, -8);
}
}
return system.getResultSuccess(result); return system.getResultSuccess(result);
} }
async delUser(params) { async delUser(params) {
await this.delete({ var user = await this.findById(params.id);
id: params.id if(!user) {
}); return system.getResultSuccess();
}
if(user.saas_id != params.saas_id) {
return system.getResult(null, "权限不足");
}
await this.delete({id: params.id});
return system.getResultSuccess(); return system.getResultSuccess();
} }
} }
module.exports = UserService; 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