Commit c466c8de by 孙亚楠

dd

parent 38f3bd3d
......@@ -106,10 +106,10 @@ class ActionAPI extends APIBase {
opResult = await this.roleSve.apiUpdRole(action_body);
break;
case "delRole":
opResult = await this.roleSve.delRole(action_body);
opResult = await this.roleSve.apiDelRole(action_body);
break;
case "listRole":
opResult = await this.roleSve.listRole(action_body);
opResult = await this.roleSve.apiListRole(action_body);
break;
// 用户
......
......@@ -4,5 +4,16 @@ class RoleDao extends Dao {
constructor() {
super(Dao.getModelName(RoleDao));
}
async findUserByRoleId(params){
let sql = [];
sql.push(`SELECT c.ucid,c.ucname,c.uctype,c.saas_id,c.isEnabled,c.created_at,c.updated_at,c.deleted_at
FROM uc_role a INNER JOIN uc_user_role b ON a.id = b.role_id INNER JOIN uc_user c ON b.user_id = c.id
WHERE 1=1 and ( c.deleted_at is null or c.deleted_at > NOW() ) `);
if(params.id){
sql.push("AND a.id = :id");
}
return await this.customQuery(sql.join(" "), params);
}
}
module.exports = RoleDao;
\ No newline at end of file
......@@ -221,6 +221,18 @@ class OrgService extends ServiceBase {
}
}
async queryById(params){
if(!params.id){
return system.getResult(-1, `参数错误 ID不能为空`);
}
try {
let _org = await this.findOne({id:this.trim(params.id)});
return system.getResult(_org);
} catch (error) {
return system.getResult(-1,`系统错误 错误信息 ${error}`);
}
}
/**
* 根据ID查询该组织机构下的所有用户
*/
......
const system = require("../../../system");
const ServiceBase = require("../../sve.base")
const settings = require("../../../../config/settings")
class RoleService extends ServiceBase {
constructor() {
super("role", ServiceBase.getDaoName(RoleService));
......@@ -29,26 +28,52 @@ class RoleService extends ServiceBase {
return system.getResult(null, `系统错误 错误信息 ${error}`);
}
}
/**
* role 删除
* @param {*} params
*/
async apiDelRole(params) {
try {
return await this.delRole(params);
} catch (error) {
return system.getResult(null, `系统错误 错误信息 ${error}`);
}
}
/**
* role 查询列表
* @param {*} params
*/
async apiListRole(params) {
try {
return await this.listRole(params);
} catch (error) {
return system.getResult(null, `系统错误 错误信息 ${error}`);
}
}
/***************************************************************** */
/***************************************************************** */
/**
* 添加
* @param {T} params
*/
async addRole (params){
async addRole(params) {
params.code = this.trim(params.code);
params.name = this.trim(params.name);
params.saas_id = Number(params.saas_id || 0);
params.name = this.trim(params.name);
params.saas_id = Number(params.saas_id || 0);
try {
let res = await this.create(params);
console.log(`saas 信息插入 : ${JSON.stringify(res)}`);
return system.getResult(res);
} catch (error) {
return system.getResult(-1,`系统错误 错误信息 ${error}`);
return system.getResult(-1, `系统错误 错误信息 ${error}`);
}
}
......@@ -56,27 +81,84 @@ class RoleService extends ServiceBase {
* 更新
* @param {T} params
*/
async updateRole (params){
if(params.id){
params.id = Number(this.trim(params.id));
async updateRole(params) {
if (params.id) {
params.id = Number(this.trim(params.id));
}
let _role = await this.findById({id:params.id});
if(!_role){
return system.getResult(-1,`参数错误 角色不存在`);
let _role = await this.findById(this.trim(params.id));
if (!_role) {
return system.getResult(-1, `参数错误 角色不存在`);
}
if(params.code){
if (params.code) {
_role.code = this.trim(params.code);
}
params.code = this.trim(params.code);
params.name = this.trim(params.name);
if (params.name) {
_role.name = this.trim(params.name);
}
if (params.saas_id) {
_role.name = Number(params.saas_id);
}
try {
let res = await this.update(params);
let res = await _role.save();
console.log(`saas 信息插入 : ${JSON.stringify(res)}`);
return system.getResult(res);
} catch (error) {
return system.getResult(-1,`系统错误 错误信息 ${error}`);
return system.getResult(-1, `系统错误 错误信息 ${error}`);
}
}
/**
* 删除角色
* @param {*} params
*/
async delRole(params) {
try {
//检查是否存在此记录
if (!params.id) {
return system.getResult(-1, `参数错误 ID不能为空`);
}
params.id = this.trim(params.id);
let _role = await this.findById(params.id);
if (!_role) {
return system.getResult(-1, `角色不存在`);
}
//检查该角色是否有用户使用
let users = await this.dao.findUserByRoleId(params);
if (!users || users.length != 0) {
return system.getResult(-1, `角色不能删除`);
}
//删除并删除对应表
let res = await _role.destroy();
return system.getResult(res);
} catch (error) {
return system.getResult(-1, `系统错误 错误信息${error}`);
}
}
/**
* 查询列表
* @param {*} params
*/
async listRole(params) {
let where = {};
let pageIndex = params.pageIndex || 1;
let pageSize = params.pageSize || 10;
if (params.code) {
where.code = this.trim(params.code);
}
if (params.name) {
where.name = this.trim(params.name);
}
if (params.hasOwnProperty("saas_id")) {
where.saas_id = Number(params.saas_id);
}
try {
let roleList = await this.getPageList(pageIndex, pageSize, where);
return system.getResult(roleList);
} catch (error) {
return system.getResult(-1, `系统错误 错误信息 ${error}`);
}
}
}
module.exports = RoleService;
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