|
|
|
@ -1,22 +1,30 @@
|
|
|
|
|
package au.com.royalpay.payment.manage.management.sysconfig.core.impls;
|
|
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.manage.management.sysconfig.beans.FuncInfo;
|
|
|
|
|
import au.com.royalpay.payment.manage.management.sysconfig.beans.ModuleInfo;
|
|
|
|
|
import au.com.royalpay.payment.manage.management.sysconfig.beans.PartnerModuleInfo;
|
|
|
|
|
import au.com.royalpay.payment.manage.management.sysconfig.core.PartnerPermissionManager;
|
|
|
|
|
import au.com.royalpay.payment.manage.management.sysconfig.core.PermissionManager;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.*;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.ClientMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.PermissionClientModuleMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.PermissionPartnerFunctionMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.PermissionPartnerModuleMapper;
|
|
|
|
|
import au.com.royalpay.payment.manage.permission.manager.scanner.PermissionNode;
|
|
|
|
|
import au.com.royalpay.payment.manage.permission.manager.scanner.PermissionReader;
|
|
|
|
|
import au.com.royalpay.payment.manage.permission.manager.scanner.PermissionPartnerReader;
|
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
|
|
|
|
import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
|
|
|
|
import org.springframework.cache.annotation.CacheEvict;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.TreeMap;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Created by yangluo on 2018/07/05.
|
|
|
|
@ -24,46 +32,47 @@ import java.util.*;
|
|
|
|
|
@Service
|
|
|
|
|
public class PartnerPermissionManagerImpl implements PartnerPermissionManager {
|
|
|
|
|
@Resource
|
|
|
|
|
private PartnerPermissionFunctionMapper partnerPermissionFunctionMapper;
|
|
|
|
|
private PermissionPartnerFunctionMapper permissionPartnerFunctionMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private PartnerPermissionModuleMapper partnerPermissionModuleMapper;
|
|
|
|
|
private PermissionPartnerModuleMapper permissionPartnerModuleMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
private PermissionReader permissionReader;
|
|
|
|
|
private PermissionPartnerReader permissionPartnerReader;
|
|
|
|
|
@Resource
|
|
|
|
|
PermissionClientModuleMapper permissionClientModuleMapper;
|
|
|
|
|
private PermissionClientModuleMapper permissionClientModuleMapper;
|
|
|
|
|
@Resource
|
|
|
|
|
ClientMapper clientMapper;
|
|
|
|
|
private ClientMapper clientMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void synchronizeFunctions() {
|
|
|
|
|
List<JSONObject> functions = partnerPermissionFunctionMapper.listAll();
|
|
|
|
|
List<JSONObject> functions = permissionPartnerFunctionMapper.listAll();
|
|
|
|
|
Map<String, JSONObject> funcMapFromDB = new HashMap<>();
|
|
|
|
|
for (JSONObject func : functions) {
|
|
|
|
|
funcMapFromDB.put(func.getString("func_id"), func);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<PermissionNode> nodes = permissionReader.listFunctions();
|
|
|
|
|
List<PermissionNode> nodes = permissionPartnerReader.listFunctions();
|
|
|
|
|
for (PermissionNode node : nodes) {
|
|
|
|
|
String funcId = node.getFuncId();
|
|
|
|
|
if (funcMapFromDB.containsKey(funcId)) {
|
|
|
|
|
funcMapFromDB.remove(funcId);
|
|
|
|
|
JSONObject func = node.initFuncObject();
|
|
|
|
|
func.remove("role");
|
|
|
|
|
partnerPermissionFunctionMapper.update(func);
|
|
|
|
|
permissionPartnerFunctionMapper.update(func);
|
|
|
|
|
} else {
|
|
|
|
|
JSONObject func = node.initFuncObject();
|
|
|
|
|
partnerPermissionFunctionMapper.save(func);
|
|
|
|
|
permissionPartnerFunctionMapper.save(func);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (String funcId : funcMapFromDB.keySet()) {
|
|
|
|
|
partnerPermissionFunctionMapper.delete(funcId);
|
|
|
|
|
permissionPartnerFunctionMapper.delete(funcId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public JSONObject listFunctions() {
|
|
|
|
|
List<JSONObject> funcs = partnerPermissionFunctionMapper.listAll();
|
|
|
|
|
List<JSONObject> funcs = permissionPartnerFunctionMapper.listAll();
|
|
|
|
|
Map<String, List<JSONObject>> moduleMap = new TreeMap<>();
|
|
|
|
|
List<JSONObject> noModule = new ArrayList<>();
|
|
|
|
|
for (JSONObject func : funcs) {
|
|
|
|
@ -100,19 +109,19 @@ public class PartnerPermissionManagerImpl implements PartnerPermissionManager {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<JSONObject> listModules() {
|
|
|
|
|
return partnerPermissionModuleMapper.list();
|
|
|
|
|
return permissionPartnerModuleMapper.list();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void saveOrUpdateModule(String moduleName, PartnerModuleInfo module) {
|
|
|
|
|
JSONObject mod = partnerPermissionModuleMapper.find(moduleName);
|
|
|
|
|
JSONObject mod = permissionPartnerModuleMapper.find(moduleName);
|
|
|
|
|
if (mod == null) {
|
|
|
|
|
mod = new JSONObject();
|
|
|
|
|
mod.put("module_name", moduleName);
|
|
|
|
|
module.initObject(mod);
|
|
|
|
|
partnerPermissionModuleMapper.save(mod);
|
|
|
|
|
permissionPartnerModuleMapper.save(mod);
|
|
|
|
|
List<JSONObject> IdandMoniker = clientMapper.listClientsIdAndMoniker();
|
|
|
|
|
JSONObject nModuleId = partnerPermissionModuleMapper.listModuleId(moduleName);
|
|
|
|
|
JSONObject nModuleId = permissionPartnerModuleMapper.listModuleId(moduleName);
|
|
|
|
|
|
|
|
|
|
if (module.getInitialize()) {
|
|
|
|
|
for (JSONObject clientMod : IdandMoniker) {
|
|
|
|
@ -134,17 +143,17 @@ public class PartnerPermissionManagerImpl implements PartnerPermissionManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
module.initObject(mod);
|
|
|
|
|
partnerPermissionModuleMapper.update(mod);
|
|
|
|
|
permissionPartnerModuleMapper.update(mod);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void checkAndDeleteModule(String moduleName) {
|
|
|
|
|
List<JSONObject> funcs = partnerPermissionFunctionMapper.listByModule(moduleName);
|
|
|
|
|
List<JSONObject> funcs = permissionPartnerFunctionMapper.listByModule(moduleName);
|
|
|
|
|
if (funcs.isEmpty()) {
|
|
|
|
|
permissionClientModuleMapper.delete(moduleName);
|
|
|
|
|
partnerPermissionModuleMapper.delete(moduleName);
|
|
|
|
|
permissionPartnerModuleMapper.delete(moduleName);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
throw new BadRequestException("Module have functions. Move them first.");
|
|
|
|
@ -157,7 +166,7 @@ public class PartnerPermissionManagerImpl implements PartnerPermissionManager {
|
|
|
|
|
update.put("func_id", funcId);
|
|
|
|
|
update.put("name", funcInfo.getName());
|
|
|
|
|
update.put("remark", funcInfo.getRemark());
|
|
|
|
|
partnerPermissionFunctionMapper.update(update);
|
|
|
|
|
permissionPartnerFunctionMapper.update(update);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -166,21 +175,21 @@ public class PartnerPermissionManagerImpl implements PartnerPermissionManager {
|
|
|
|
|
if (moduleName == null) {
|
|
|
|
|
throw new BadRequestException("module name not provided");
|
|
|
|
|
}
|
|
|
|
|
JSONObject mod = partnerPermissionModuleMapper.find(moduleName);
|
|
|
|
|
JSONObject mod = permissionPartnerModuleMapper.find(moduleName);
|
|
|
|
|
if (mod == null) {
|
|
|
|
|
throw new BadRequestException("Module:" + moduleName + " not exists!");
|
|
|
|
|
}
|
|
|
|
|
JSONObject nModuleId = partnerPermissionModuleMapper.listModuleId(moduleName);
|
|
|
|
|
JSONObject nModuleId = permissionPartnerModuleMapper.listModuleId(moduleName);
|
|
|
|
|
JSONObject update = new JSONObject();
|
|
|
|
|
update.put("func_id", funcId);
|
|
|
|
|
update.put("module", moduleName);
|
|
|
|
|
update.put("module_id",nModuleId.getString("id"));
|
|
|
|
|
partnerPermissionFunctionMapper.update(update);
|
|
|
|
|
permissionPartnerFunctionMapper.update(update);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<String> listRoleFunctions(ManagerRole role) {
|
|
|
|
|
List<JSONObject> funcs = partnerPermissionFunctionMapper.listByRoleMask(role.getMask());
|
|
|
|
|
List<JSONObject> funcs = permissionPartnerFunctionMapper.listByRoleMask(role.getMask());
|
|
|
|
|
List<String> funcIds = new ArrayList<>();
|
|
|
|
|
for (JSONObject func : funcs) {
|
|
|
|
|
funcIds.add(func.getString("func_id"));
|
|
|
|
@ -192,13 +201,13 @@ public class PartnerPermissionManagerImpl implements PartnerPermissionManager {
|
|
|
|
|
@Transactional
|
|
|
|
|
@CacheEvict(value = ":login:managers:",allEntries = true)
|
|
|
|
|
public void authorizeRole(ManagerRole role, List<String> functions) {
|
|
|
|
|
partnerPermissionFunctionMapper.clearRolePermission(role.getInverseMask());
|
|
|
|
|
partnerPermissionFunctionMapper.authorizeRole(role.getMask(), functions);
|
|
|
|
|
permissionPartnerFunctionMapper.clearRolePermission(role.getInverseMask());
|
|
|
|
|
permissionPartnerFunctionMapper.authorizeRole(role.getMask(), functions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<JSONObject> listUserFunctions(int role) {
|
|
|
|
|
return partnerPermissionFunctionMapper.listByRoleMask(role);
|
|
|
|
|
return permissionPartnerFunctionMapper.listByRoleMask(role);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|