1.x
tanghc 6 years ago
parent 043db3e726
commit 74683e1fb1
  1. 79
      sop-admin/sop-admin-server/sop.sql
  2. 79
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/isv/IsvApi.java
  3. 6
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/isv/param/IsvInfoForm.java
  4. 2
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/isv/result/IsvVO.java
  5. 16
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/api/isv/result/RoleVO.java
  6. 40
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/entity/PermIsvRole.java
  7. 40
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/entity/PermRole.java
  8. 40
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/entity/PermRolePermission.java
  9. 1
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/mapper/IsvInfoMapper.java
  10. 12
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/mapper/PermIsvRoleMapper.java
  11. 12
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/mapper/PermRoleMapper.java
  12. 12
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/mapper/PermRolePermissionMapper.java
  13. 34
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/service/PermService.java

@ -0,0 +1,79 @@
/*
Navicat Premium Data Transfer
Source Server : mysql-localhost
Source Server Type : MySQL
Source Server Version : 50724
Source Host : localhost:3306
Source Schema : sop
Target Server Type : MySQL
Target Server Version : 50724
File Encoding : 65001
Date: 27/03/2019 20:16:41
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for isv_info
-- ----------------------------
DROP TABLE IF EXISTS `isv_info`;
CREATE TABLE `isv_info` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`app_key` varchar(100) NOT NULL COMMENT 'appKey',
`secret` varchar(200) NOT NULL COMMENT 'secret',
`pub_key` text COMMENT '公钥',
`pri_key` text COMMENT '私钥',
`status` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '0启用,1禁用',
`gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_app_key` (`app_key`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COMMENT='isv信息表';
-- ----------------------------
-- Table structure for perm_isv_role
-- ----------------------------
DROP TABLE IF EXISTS `perm_isv_role`;
CREATE TABLE `perm_isv_role` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`isv_info_id` bigint(20) NOT NULL COMMENT 'isv_info.id',
`role_code` varchar(50) NOT NULL COMMENT '角色code',
`gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_user_role` (`isv_info_id`,`role_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='isv角色';
-- ----------------------------
-- Table structure for perm_role
-- ----------------------------
DROP TABLE IF EXISTS `perm_role`;
CREATE TABLE `perm_role` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`role_code` varchar(50) NOT NULL COMMENT '角色代码',
`description` varchar(50) NOT NULL COMMENT '角色描述',
`gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_code` (`role_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='角色表';
-- ----------------------------
-- Table structure for perm_role_permission
-- ----------------------------
DROP TABLE IF EXISTS `perm_role_permission`;
CREATE TABLE `perm_role_permission` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`role_code` varchar(50) NOT NULL COMMENT '角色表code',
`route_id` bigint(20) NOT NULL COMMENT 'api_id',
`gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_role_perm` (`role_code`,`route_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='角色权限表';
SET FOREIGN_KEY_CHECKS = 1;

@ -11,23 +11,29 @@ import com.gitee.fastmybatis.core.PageInfo;
import com.gitee.fastmybatis.core.query.Query; import com.gitee.fastmybatis.core.query.Query;
import com.gitee.fastmybatis.core.support.PageEasyui; import com.gitee.fastmybatis.core.support.PageEasyui;
import com.gitee.fastmybatis.core.util.MapperUtil; import com.gitee.fastmybatis.core.util.MapperUtil;
import com.gitee.sop.adminserver.api.isv.param.IsvInfoForm;
import com.gitee.sop.adminserver.api.isv.param.IsvInfoFormAdd; import com.gitee.sop.adminserver.api.isv.param.IsvInfoFormAdd;
import com.gitee.sop.adminserver.api.isv.param.IsvInfoFormUpdate; import com.gitee.sop.adminserver.api.isv.param.IsvInfoFormUpdate;
import com.gitee.sop.adminserver.api.isv.param.IsvPageParam; import com.gitee.sop.adminserver.api.isv.param.IsvPageParam;
import com.gitee.sop.adminserver.api.isv.result.AppKeySecretVo; import com.gitee.sop.adminserver.api.isv.result.AppKeySecretVo;
import com.gitee.sop.adminserver.api.isv.result.IsvVO; import com.gitee.sop.adminserver.api.isv.result.IsvVO;
import com.gitee.sop.adminserver.api.isv.result.PubPriVo; import com.gitee.sop.adminserver.api.isv.result.PubPriVo;
import com.gitee.sop.adminserver.api.isv.result.RoleVO;
import com.gitee.sop.adminserver.common.IdGen; import com.gitee.sop.adminserver.common.IdGen;
import com.gitee.sop.adminserver.entity.IsvInfo; import com.gitee.sop.adminserver.entity.IsvInfo;
import com.gitee.sop.adminserver.entity.PermIsvRole;
import com.gitee.sop.adminserver.entity.PermRole;
import com.gitee.sop.adminserver.mapper.IsvInfoMapper; import com.gitee.sop.adminserver.mapper.IsvInfoMapper;
import com.google.common.collect.Sets; import com.gitee.sop.adminserver.mapper.PermIsvRoleMapper;
import com.gitee.sop.adminserver.mapper.PermRoleMapper;
import com.gitee.sop.adminserver.service.PermService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* @author tanghc * @author tanghc
@ -39,6 +45,15 @@ public class IsvApi {
@Autowired @Autowired
IsvInfoMapper isvInfoMapper; IsvInfoMapper isvInfoMapper;
@Autowired
PermIsvRoleMapper permIsvRoleMapper;
@Autowired
PermRoleMapper permRoleMapper;
@Autowired
PermService permService;
@Api(name = "isv.info.page") @Api(name = "isv.info.page")
@ApiDocMethod(description = "接入方列表") @ApiDocMethod(description = "接入方列表")
PageEasyui pageIsv(IsvPageParam param) { PageEasyui pageIsv(IsvPageParam param) {
@ -46,14 +61,14 @@ public class IsvApi {
PageInfo<IsvInfo> pageInfo = MapperUtil.query(isvInfoMapper, query); PageInfo<IsvInfo> pageInfo = MapperUtil.query(isvInfoMapper, query);
List<IsvInfo> list = pageInfo.getList(); List<IsvInfo> list = pageInfo.getList();
List<IsvVO> retList = new ArrayList<>(list.size()); List<IsvVO> retList = list.stream()
.map(isvInfo -> {
for (IsvInfo permClient : list) {
IsvVO vo = new IsvVO(); IsvVO vo = new IsvVO();
CopyUtil.copyProperties(permClient, vo); CopyUtil.copyProperties(isvInfo, vo);
//vo.setRoleList(this.buildClientRole(permClient)); vo.setRoleList(this.buildIsvRole(isvInfo));
retList.add(vo); return vo;
} })
.collect(Collectors.toList());
PageEasyui<IsvVO> pageInfoRet = new PageEasyui<>(); PageEasyui<IsvVO> pageInfoRet = new PageEasyui<>();
pageInfoRet.setTotal(pageInfo.getTotal()); pageInfoRet.setTotal(pageInfo.getTotal());
@ -62,6 +77,28 @@ public class IsvApi {
return pageInfoRet; return pageInfoRet;
} }
/**
* 构建ISV拥有的角色
*
* @param permClient
* @return
*/
List<RoleVO> buildIsvRole(IsvInfo permClient) {
List<String> roleCodeList = permService.listClientRoleCode(permClient.getId());
if (CollectionUtils.isEmpty(roleCodeList)) {
return Collections.emptyList();
}
List<PermRole> list = permRoleMapper.list(new Query().in("role_code", roleCodeList));
return list.stream()
.map(permRole -> {
RoleVO vo = new RoleVO();
CopyUtil.copyProperties(permRole, vo);
return vo;
})
.collect(Collectors.toList());
}
@Api(name = "isv.info.add") @Api(name = "isv.info.add")
@ApiDocMethod(description = "添加isv") @ApiDocMethod(description = "添加isv")
void addIsv(IsvInfoFormAdd param) { void addIsv(IsvInfoFormAdd param) {
@ -69,7 +106,7 @@ public class IsvApi {
CopyUtil.copyPropertiesIgnoreNull(param, rec); CopyUtil.copyPropertiesIgnoreNull(param, rec);
isvInfoMapper.saveIgnoreNull(rec); isvInfoMapper.saveIgnoreNull(rec);
// this.saveClientRole(rec, param.getRoleCode()); this.saveClientRole(rec, param.getRoleCode());
// TODO:发送消息队列到zookeeper // TODO:发送消息队列到zookeeper
} }
@ -80,7 +117,7 @@ public class IsvApi {
CopyUtil.copyPropertiesIgnoreNull(param, rec); CopyUtil.copyPropertiesIgnoreNull(param, rec);
isvInfoMapper.updateIgnoreNull(rec); isvInfoMapper.updateIgnoreNull(rec);
// this.saveClientRole(rec, param.getRoleCode()); this.saveClientRole(rec, param.getRoleCode());
// syncService.syncAppSecretConfig(Sets.newHashSet(param.getApp())); // syncService.syncAppSecretConfig(Sets.newHashSet(param.getApp()));
// TODO:发送消息队列到zookeeper // TODO:发送消息队列到zookeeper
@ -106,4 +143,22 @@ public class IsvApi {
vo.setSecret(secret); vo.setSecret(secret);
return vo; return vo;
} }
void saveClientRole(IsvInfo isvInfo, List<String> roleCodeList) {
Query query = new Query();
long isvInfoId = isvInfo.getId();
query.eq("isv_info_id", isvInfoId);
permIsvRoleMapper.deleteByQuery(query);
List<PermIsvRole> tobeSaveList = roleCodeList.stream()
.map(roleCode -> {
PermIsvRole rec = new PermIsvRole();
rec.setIsvInfoId(isvInfoId);
rec.setRoleCode(roleCode);
return rec;
})
.collect(Collectors.toList());
permIsvRoleMapper.saveBatch(tobeSaveList);
}
} }

@ -5,6 +5,8 @@ import lombok.Data;
import org.hibernate.validator.constraints.Length; import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import java.util.List;
/** /**
* @author tanghc * @author tanghc
@ -31,6 +33,6 @@ public class IsvInfoForm {
@ApiDocField(description = "状态:0:启用,1:禁用") @ApiDocField(description = "状态:0:启用,1:禁用")
private Byte status = 0; private Byte status = 0;
// @NotEmpty(message = "角色不能为空") @NotEmpty(message = "角色不能为空")
// private List<String> roleCode; private List<String> roleCode;
} }

@ -33,4 +33,6 @@ public class IsvVO {
/** 数据库字段:gmt_modified */ /** 数据库字段:gmt_modified */
private Date gmtModified; private Date gmtModified;
private List<RoleVO> roleList;
} }

@ -0,0 +1,16 @@
package com.gitee.sop.adminserver.api.isv.result;
import lombok.Data;
import java.util.Date;
/**
* @author thc
*/
@Data
public class RoleVO {
private Long id;
private String roleCode;
private String description;
private Date gmtCreate;
}

@ -0,0 +1,40 @@
package com.gitee.sop.adminserver.entity;
import lombok.Data;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* 表名perm_isv_role
* 备注isv角色
*
* @author tanghc
*/
@Table(name = "perm_isv_role")
@Data
public class PermIsvRole {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
/** 数据库字段:id */
private Long id;
/** isv_info.id, 数据库字段:isv_info_id */
private Long isvInfoId;
/** 角色code, 数据库字段:role_code */
private String roleCode;
/** 数据库字段:gmt_create */
private Date gmtCreate;
/** 数据库字段:gmt_modified */
private Date gmtModified;
}

@ -0,0 +1,40 @@
package com.gitee.sop.adminserver.entity;
import lombok.Data;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* 表名perm_role
* 备注角色表
*
* @author tanghc
*/
@Table(name = "perm_role")
@Data
public class PermRole {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
/** 数据库字段:id */
private Long id;
/** 角色代码, 数据库字段:role_code */
private String roleCode;
/** 角色描述, 数据库字段:description */
private String description;
/** 数据库字段:gmt_create */
private Date gmtCreate;
/** 数据库字段:gmt_modified */
private Date gmtModified;
}

@ -0,0 +1,40 @@
package com.gitee.sop.adminserver.entity;
import lombok.Data;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* 表名perm_role_permission
* 备注角色权限表
*
* @author tanghc
*/
@Table(name = "perm_role_permission")
@Data
public class PermRolePermission {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
/** 数据库字段:id */
private Long id;
/** 角色表code, 数据库字段:role_code */
private String roleCode;
/** api_id, 数据库字段:route_id */
private Long routeId;
/** 数据库字段:gmt_create */
private Date gmtCreate;
/** 数据库字段:gmt_modified */
private Date gmtModified;
}

@ -4,6 +4,7 @@ import com.gitee.fastmybatis.core.mapper.CrudMapper;
import com.gitee.sop.adminserver.entity.IsvInfo; import com.gitee.sop.adminserver.entity.IsvInfo;
/** /**
* @author tanghc * @author tanghc
*/ */

@ -0,0 +1,12 @@
package com.gitee.sop.adminserver.mapper;
import com.gitee.fastmybatis.core.mapper.CrudMapper;
import com.gitee.sop.adminserver.entity.PermIsvRole;
/**
* @author tanghc
*/
public interface PermIsvRoleMapper extends CrudMapper<PermIsvRole, Long> {
}

@ -0,0 +1,12 @@
package com.gitee.sop.adminserver.mapper;
import com.gitee.fastmybatis.core.mapper.CrudMapper;
import com.gitee.sop.adminserver.entity.PermRole;
/**
* @author tanghc
*/
public interface PermRoleMapper extends CrudMapper<PermRole, Long> {
}

@ -0,0 +1,12 @@
package com.gitee.sop.adminserver.mapper;
import com.gitee.fastmybatis.core.mapper.CrudMapper;
import com.gitee.sop.adminserver.entity.PermRolePermission;
/**
* @author tanghc
*/
public interface PermRolePermissionMapper extends CrudMapper<PermRolePermission, Long> {
}

@ -0,0 +1,34 @@
package com.gitee.sop.adminserver.service;
import com.gitee.sop.adminserver.entity.PermIsvRole;
import com.gitee.sop.adminserver.mapper.PermIsvRoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* @author thc
*/
@Service
public class PermService {
@Autowired
PermIsvRoleMapper permClientRoleMapper;
/**
* 获取客户端角色码列表
*
* @param clientId
* @return
*/
public List<String> listClientRoleCode(Long clientId) {
List<PermIsvRole> list = permClientRoleMapper.listByColumn("client_id", clientId);
List<String> retList = new ArrayList<>(list.size());
for (PermIsvRole permClientRole : list) {
retList.add(permClientRole.getRoleCode());
}
return retList;
}
}
Loading…
Cancel
Save