master
wangning 6 years ago
parent fdab9c1d4c
commit 2b3671a8af

@ -31,16 +31,4 @@ public interface PermissionManager {
List<JSONObject> listUserFunctions(int role);
//partner start
void synchronizePartnerFunctions();
JSONObject listPartnerFunctions();
JSONObject getPartnerFuncById(String funcId);
}

@ -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);
}
}

@ -5,10 +5,7 @@ import au.com.royalpay.payment.manage.management.sysconfig.beans.ModuleInfo;
import au.com.royalpay.payment.manage.management.sysconfig.core.PermissionManager;
import au.com.royalpay.payment.manage.mappers.system.PermissionFunctionMapper;
import au.com.royalpay.payment.manage.mappers.system.PermissionModuleMapper;
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.PermissionPartnerReader;
import au.com.royalpay.payment.manage.permission.manager.scanner.PermissionReader;
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
@ -38,16 +35,6 @@ public class PermissionManagerImpl implements PermissionManager {
private PermissionModuleMapper permissionModuleMapper;
@Resource
private PermissionReader permissionReader;
@Resource
private PermissionPartnerFunctionMapper permissionPartnerFunctionMapper;
@Resource
private PermissionPartnerModuleMapper permissionPartnerModuleMapper;
@Resource
private PermissionPartnerReader permissionPartnerReader;
@Override
public void synchronizeFunctions() {
List<JSONObject> functions = permissionFunctionMapper.listAll();
@ -75,74 +62,6 @@ public class PermissionManagerImpl implements PermissionManager {
}
}
@Override
public void synchronizePartnerFunctions() {
List<JSONObject> functions = permissionFunctionMapper.listAll();
Map<String, JSONObject> funcMapFromDB = new HashMap<>();
for (JSONObject func : functions) {
funcMapFromDB.put(func.getString("func_id"), func);
}
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");
permissionPartnerFunctionMapper.update(func);
} else {
JSONObject func = node.initFuncObject();
permissionPartnerFunctionMapper.save(func);
}
}
for (String funcId : funcMapFromDB.keySet()) {
permissionPartnerFunctionMapper.delete(funcId);
}
}
@Override
public JSONObject listPartnerFunctions() {
List<JSONObject> funcs = permissionPartnerFunctionMapper.listAll();
Map<String, List<JSONObject>> moduleMap = new TreeMap<>();
List<JSONObject> noModule = new ArrayList<>();
for (JSONObject func : funcs) {
String module = func.getString("module");
if (module == null) {
noModule.add(func);
continue;
}
List<JSONObject> funcsInModule = moduleMap.get(module);
if (funcsInModule == null) {
funcsInModule = new ArrayList<>();
moduleMap.put(module, funcsInModule);
}
funcsInModule.add(func);
}
JSONObject report = new JSONObject();
report.put("no_module", noModule);
List<JSONObject> modules = new ArrayList<>();
for (String module : moduleMap.keySet()) {
JSONObject mod = new JSONObject();
mod.put("module_name", module);
List<JSONObject> funcList = moduleMap.get(module);
mod.put("remark", funcList.get(0).getString("mod_remark"));
mod.put("js_module", funcList.get(0).getString("js_module"));
mod.put("js_path", funcList.get(0).getString("js_path"));
mod.put("funcs", funcList);
modules.add(mod);
}
report.put("modules", modules);
return report;
}
@Override
@CacheEvict(value = ":System:permissionCheck:",allEntries = true)
public JSONObject getPartnerFuncById(String funcId) {
return permissionPartnerFunctionMapper.find(funcId);
}
@Override
public JSONObject listFunctions() {
List<JSONObject> funcs = permissionFunctionMapper.listAll();

@ -93,18 +93,4 @@ public class SysPermissionConfigController {
}
throw new BadRequestException("Invalid role mask:" + roleMask);
}
@RequestMapping(value = "/partner/synchronize", method = RequestMethod.POST)
public void synchronizePartnerFunctions() {
permissionManager.synchronizePartnerFunctions();
}
@RequestMapping(value = "/partner/functions", method = RequestMethod.GET)
public JSONObject listPartnerFunctions() {
return permissionManager.listPartnerFunctions();
}
}

@ -3,21 +3,27 @@ package au.com.royalpay.payment.manage.management.sysconfig.web;
import au.com.royalpay.payment.manage.management.sysconfig.beans.FuncInfo;
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.permission.manager.ManagerMapping;
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.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import javax.annotation.Resource;
/**
* Created by yangluo on 2018/07/05.
*/
@RestController
@ManagerMapping(role = ManagerRole.ADMIN, value = "/sys/partnerPermission")
public class SysPartnerPermission {
@RequestMapping( value = "/sys/partnerPermission")
public class SysPermissionPartnerConfigController {
@Resource
private PartnerPermissionManager patnerPermissionManager;

@ -1,39 +0,0 @@
package au.com.royalpay.payment.manage.mappers.system;
import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper;
import cn.yixblog.support.mybatis.autosql.annotations.AutoSql;
import cn.yixblog.support.mybatis.autosql.annotations.SqlType;
import com.alibaba.fastjson.JSONObject;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* Created by yixian on 2017-02-28.
*/
@AutoMapper(tablename = "sys_permission_partner_functions", pkName = "func_id")
public interface PartnerPermissionFunctionMapper {
@AutoSql(type = SqlType.INSERT)
void save(JSONObject func);
@AutoSql(type = SqlType.UPDATE)
void update(JSONObject func);
List<JSONObject> listByRoleMask(@Param("mask") int mask);
List<JSONObject> listAll();
@AutoSql(type = SqlType.SELECT)
List<JSONObject> listByModule(@Param("module") String moduleName);
@AutoSql(type = SqlType.DELETE)
void delete(@Param("func_id") String funcId);
void clearRolePermission(@Param("mask") int mask);
void authorizeRole(@Param("mask") int mask, @Param("func_ids") List<String> functions);
@AutoSql(type = SqlType.SELECT)
JSONObject find(@Param("func_id") String funcId);
}

@ -1,32 +0,0 @@
package au.com.royalpay.payment.manage.mappers.system;
import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper;
import cn.yixblog.support.mybatis.autosql.annotations.AutoSql;
import cn.yixblog.support.mybatis.autosql.annotations.SqlType;
import com.alibaba.fastjson.JSONObject;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* Created by yixian on 2017-02-28.
*/
@AutoMapper(tablename = "sys_permission_partner_modules", pkName = "module_name")
public interface PartnerPermissionModuleMapper {
void save(JSONObject module);
JSONObject listModuleId(@Param("module_name") String moduleName);
@AutoSql(type = SqlType.UPDATE)
void update(JSONObject module);
@AutoSql(type = SqlType.DELETE)
void delete(@Param("module_name") String moduleName);
@AutoSql(type = SqlType.SELECT)
List<JSONObject> list();
@AutoSql(type = SqlType.SELECT)
JSONObject find(@Param("module_name") String moduleName);
}

@ -29,4 +29,7 @@ public interface PermissionPartnerModuleMapper {
@AutoSql(type = SqlType.SELECT)
JSONObject find(@Param("module_name") String moduleName);
@AutoSql(type = SqlType.SELECT)
JSONObject listModuleId(@Param("module_name") String moduleName);
}

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="au.com.royalpay.payment.manage.mappers.system.PartnerPermissionModuleMapper">
<mapper namespace="au.com.royalpay.payment.manage.mappers.system.PermissionPartnerModuleMapper">
<select id="listModuleId" resultType="com.alibaba.fastjson.JSONObject" >
<!-- <select id="listModuleId" resultType="com.alibaba.fastjson.JSONObject" >
select id from sys_permission_partner_modules where module_name=#{module_name}
</select>
@ -14,7 +14,7 @@
<insert id="save">
insert into sys_permission_partner_modules(module_name,js_module,js_path,remark) value (#{module_name},#{js_module},#{js_path},#{remark})
</insert>
</insert>-->
</mapper>
Loading…
Cancel
Save