Commit 3d6790b2 authored by ml's avatar ml

逻辑调整

parent 35310c78
......@@ -217,7 +217,7 @@ export const delRole = async (req: any, aclRoleVO: AclRoleVO) => {
/**
* 修改角色权限
* 修改角色权限-接口逻辑合并到保存角色接口中-此接口目前无用
* @param req
* @param infoVO
*/
......@@ -226,8 +226,8 @@ export const changeRoleAuth = async (req: any, aclAuthVO: AclAuthVO) => {
let cmd = req.path;
try {
ApiAssert.notNull(ErrorCode.PARAM_MISS, aclAuthVO.id);
let res = await aclRoleAuthService.changeRoleAuth(aclAuthVO.id, aclAuthVO.authIds, req.cookies.session_id);
return Res3Utils.result(res);
//let res = await aclRoleAuthService.changeRoleAuth(aclAuthVO.id, aclAuthVO.authIds, req.cookies.session_id);
//return Res3Utils.result(res);
}
catch (e) {
logger.error(`${func_name} error:${e}`);
......
......@@ -130,6 +130,7 @@ async function preCheck(aclUserInfoVO: AclUserInfoVO) {
ApiAssert.notNull(ErrorCode.PARAM_MISS, aclUserInfoVO.position_id);
ApiAssert.notNull(ErrorCode.PARAM_MISS, aclUserInfoVO.role_ids);
ApiAssert.notNull(ErrorCode.PARAM_MISS, aclUserInfoVO.totp_encrypt);
ApiAssert.notNull(ErrorCode.PARAM_MISS, aclUserInfoVO.pwd);
if (aclUserInfoVO.pwd && (aclUserInfoVO.pwd.length < 8 || aclUserInfoVO.pwd.length > 30)) {
throw ErrorCode.PWD_ILLEGAL;
}
......@@ -142,6 +143,7 @@ async function updatePreCheck(aclUserInfoVO: AclUserInfoVO) {
ApiAssert.notNull(ErrorCode.PARAM_MISS, aclUserInfoVO.position_id);
ApiAssert.notNull(ErrorCode.PARAM_MISS, aclUserInfoVO.role_ids);
ApiAssert.notNull(ErrorCode.PARAM_MISS, aclUserInfoVO.totp_encrypt);
ApiAssert.notNull(ErrorCode.PARAM_MISS, aclUserInfoVO.pwd);
if (aclUserInfoVO.pwd && (aclUserInfoVO.pwd.length < 8 || aclUserInfoVO.pwd.length > 30)) {
throw ErrorCode.PWD_ILLEGAL;
}
......
......@@ -55,7 +55,9 @@ export interface AclRoleVO {
updatedAt?: Date | any;
roleIds?: any
roleIds?: any;
authIds?: any;
}
export interface AclRolePageVO extends AclRoleVO {
......@@ -155,6 +157,7 @@ export const saveAuth = async (aclAuthVO: AclAuthVO, session_id: any) => {
url: aclAuthVO.url,
type: aclAuthVO.type,
idx_number: aclAuthVO.idx_number,
opt_type: aclAuthVO.opt_type ? aclAuthVO.opt_type : 4,
remark: aclAuthVO.remark
}, {
where: { id: aclAuthVO.id }
......@@ -162,6 +165,9 @@ export const saveAuth = async (aclAuthVO: AclAuthVO, session_id: any) => {
}
else {
await _checkUrl(aclAuthVO.url);
if (!aclAuthVO.opt_type){
aclAuthVO.opt_type = 4;
}
aclAuth.prototype.create(aclAuthVO);
}
addOptLog(null, 0, '新增/修改权限', "", JSON.stringify(aclAuthVO), '权限管理', session_id);
......@@ -255,29 +261,56 @@ export const getRoleByUser = async (userId: number | any) => {
};
export const saveRole = async (aclRoleVO: AclRoleVO) => {
if (aclRoleVO.id) {
let roleId = Number(aclRoleVO.id);
let authIds = aclRoleVO.authIds;
let tx;
try {
tx = await madAdminOrmDB.transaction();
if (roleId) {
let role = await aclRole.prototype.find({
where: {
id: roleId,
},
raw: true
});
if (!role) {
throw ErrorCode.ROLE_NOT_EXIST
}
await aclRole.prototype.update({
name: aclRoleVO.name,
remark: aclRoleVO.remark
}, {
where: {
id: aclRoleVO.id,
id: roleId,
creator: aclRoleVO.creator
}
},
transaction: tx
})
}
else {
// 创建
await aclRole.prototype.create({
let insertInfo = await aclRole.prototype.create({
name: aclRoleVO.name,
remark: aclRoleVO.remark,
creator: aclRoleVO.creator,
type: aclRoleVO.type ? aclRoleVO.type : 0,
})
}, {
transaction: tx
});
roleId = insertInfo.id
}
await changeRoleAuth(roleId, authIds, tx);
await tx.commit();
}
catch (e) {
if (tx) {
await tx.rollback();
}
logger.error('saveRole.error:' + e);
throw e;
}
addOptLog(aclRoleVO.creator, 0, '保存角色', "", JSON.stringify(aclRoleVO), '后台角色管理');
addOptLog(aclRoleVO.creator, 0, '保存角色和权限', "", `role_id:${roleId},authIds:${authIds}`, '后台角色管理');
return "ok";
};
......@@ -339,30 +372,21 @@ export const delRole = async (id: number | any, currentUserId: number) => {
};
export const changeRoleAuth = async (id: number | any, authIds: any, session_id: any) => {
const changeRoleAuth = async (id: number | any, authIds: any, tx: any) => {
let sp = authIds.split(",");
let role = await aclRole.prototype.find({
where: {
id: id,
},
raw: true
});
if (!role) {
throw ErrorCode.ROLE_NOT_EXIST
}
let authIDArr: any[] = [];
for (let i of sp) {
if (!isNaN(i)) {
authIDArr.push(i)
}
}
if (!authIDArr.length) {
// 没有指定权限的,直接删除角色对应的所有权限。
await aclRoleAuth.prototype.destroy({
where: {
role_id: id
}
},
transaction: tx
})
}
else {
......@@ -401,9 +425,6 @@ export const changeRoleAuth = async (id: number | any, authIds: any, session_id:
addData.push(item)
}
}
let tx;
try {
tx = await madAdminOrmDB.transaction()
if (deleteIDArr.length) {
await aclRoleAuth.prototype.destroy({
where: {
......@@ -414,27 +435,13 @@ export const changeRoleAuth = async (id: number | any, authIds: any, session_id:
})
}
if (addData.length) {
await aclRoleAuth.prototype.bulkCreate(addData, {
transaction: tx
})
}
await tx.commit();
tx = null;
}
catch (e) {
if (tx) {
await tx.rollback();
}
throw e
}
}
addOptLog(null, 0, '修改角色权限', "", `role_id:${id},authIds:${authIds}`, '后台角色管理', session_id);
return "ok"
};
......
......@@ -418,21 +418,18 @@ async function buildReturnData(pageData: any, fill_user_info: boolean, fill_coin
//初始化
let wallet_account_balance = new BigNumber(String(walletAssetMap[item.user_id].balance_usdt)).add(new BigNumber(String(walletAssetMap[item.user_id].holds_usdt)));
let trade_account_balance = new BigNumber(String(tradeAssetMap[item.user_id].balance_usdt)).add(new BigNumber(String(tradeAssetMap[item.user_id].holds_usdt)));
let assets_total = wallet_account_balance.add(trade_account_balance);
let oneRealName = realNameMap[item.user_id];
let one = {
user_id: user_id,
real_name: item.real_name ? item.real_name : "",
email: item.email ? item.email : "",
register_date: item.createdAt ? item.createdAt : "",
spot_trade_total: 0,//TODO:现货交易总量
contract_trade_total: 0,//TODO:永续合约交易总量
spot_balance: 0,//TODO:现货余额
contract_balance: 0,//TODO:永续合约余额
assets_total: 0,//TODO: 总资产
spot_order: 0,//TODO: 现货订单数量
contract_order: 0,//TODO: 永续合约订单数量
assets_total: assets_total,//总资产
wallet_account_balance: wallet_account_balance,//钱包账户余额
trade_account_balance: trade_account_balance,//TODO: 交易账户余额
trade_account_balance: trade_account_balance,//交易账户余额
kyc_status: oneRealName ? oneRealName.status : 0,//0未提交,1审核中,2审核不通过,3审核通过
kyc_type: oneRealName ? oneRealName.type : 0,//1身份证,2护照,3驾驶证
kyc_identity: item.kyc_identity ? item.kyc_identity : "",
......
......@@ -95,6 +95,8 @@ export const getInfoDetailByUserId = async (user_id: number | any) => {
user_status: dbUserInfo.user_status,
account: dbUserInfo.account,
pwd: dbUserInfo.pwd,
pwd_salt: dbUserInfo.pwd_salt,
pwd_status: dbUserInfo.pwd_status,
roleSet: roleSet,
authSet: authSet,
hasTotp: dbUserInfo && dbUserInfo.totp_encrypt ? 1 : 0,
......
......@@ -70,7 +70,7 @@ const postFunc = {
'acl/role/getAll': aclRoleAuthCtrl.getAllRole,
'acl/role/save': aclRoleAuthCtrl.saveRole,
'acl/role/del': aclRoleAuthCtrl.delRole,
'acl/changeRoleAuth': aclRoleAuthCtrl.changeRoleAuth,
//'acl/changeRoleAuth': aclRoleAuthCtrl.changeRoleAuth,
'acl/auth/list': aclRoleAuthCtrl.authList,
'acl/auth/tree': aclRoleAuthCtrl.getAuthTree,
'acl/auth/getByUser': aclRoleAuthCtrl.getAuthByUser,
......
......@@ -43,7 +43,7 @@ let cmdWhiteList = {
'acl/role/getAll': 1,
'acl/role/save': 1,
'acl/role/del': 1,
'acl/changeRoleAuth': 1,
//'acl/changeRoleAuth': 1,
'acl/auth/list': 1,
'acl/auth/tree': 1,
'acl/auth/getByUser': 1,
......
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