提交 1f15d064 编写于 作者: jiangjiawei's avatar jiangjiawei

Merge branch 'dev-20200106-refactor' into 'master'

Dev 20200106 refactor

merge request

See merge request !2
......@@ -11,7 +11,7 @@
<groupId>com.pica.cloud.permission</groupId>
<artifactId>pica-cloud-permission-client</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<name>pica-cloud-permission-client</name>
<packaging>jar</packaging>
......@@ -28,15 +28,57 @@
<artifactId>pica-cloud-permission-common</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
<version>1.4.5.RELEASE</version>
</dependency>
<dependency>
<groupId>com.pica.cloud.foundation</groupId>
<artifactId>pica-cloud-entity</artifactId>
<version>1.2.0</version>
<version>1.2.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.22.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.3.22.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>8.5.37</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.pica.cloud.foundation</groupId>
<artifactId>pica-cloud-redis</artifactId>
<version>1.2.5-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
......
package com.pica.cloud.permission.permission.aop;
import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.foundation.redis.ICacheClient;
import com.pica.cloud.permission.permission.client.PermissionServiceClient;
import com.pica.cloud.permission.permission.common.annotation.Authentication;
import com.pica.cloud.permission.permission.common.constants.AuthTypeEnum;
import com.pica.cloud.permission.permission.common.constants.PermissionResultCode;
import com.pica.cloud.permission.permission.common.constants.ProductTypeEnum;
import com.pica.cloud.permission.permission.common.dto.AuthDto;
import com.pica.cloud.permission.permission.common.dto.AuthResultDto;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.*;
/**
* @author andong
* @create 2019/9/11
*/
@Aspect
@Component
public class AuthAspect {
private final String TOKEN_PREFIX = "token-";
private final String DOCTOR_TOKEN_PREFIX = "token-doctor-";
private final Map<Method, Authentication> methodAuthMap = new HashMap();
private final Map<Method, String> methodUrlMap = new HashMap();
private final Map<Method, Integer> methodIndexMap = new HashMap();
@Autowired
private ICacheClient cacheClient;
@Autowired
private PermissionServiceClient permissionServiceClient;
@Pointcut("@annotation(com.pica.cloud.permission.permission.common.annotation.Authentication)")
public void auth() {}
@Around("auth()")
public Object permissionAuth(ProceedingJoinPoint joinPoint) throws Throwable {
//获取鉴权注解配置信息
MethodSignature sign = (MethodSignature) joinPoint.getSignature();
Method method = sign.getMethod();
Authentication authentication = methodAuthMap.get(method);
if (authentication == null) {
authentication = method.getAnnotation(Authentication.class);
methodAuthMap.put(method, authentication);
}
//根据token获取userId
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
String token = request.getHeader("token");
//是否需要校验token
if ((token == null || "".equals(token.trim())) && !authentication.tokenRequired()) {
return joinPoint.proceed();
}
int userId = 0;
try {
if (authentication.productType() == ProductTypeEnum.DOCTOR.code()) { //获取云鹊医doctorId
String tokenValue = cacheClient.get(TOKEN_PREFIX + token);
userId = Integer.valueOf(tokenValue.replace(DOCTOR_TOKEN_PREFIX, ""));
}
//TODO
} catch (Exception ex) {
}
if (userId == 0) { //未登录
throw new PicaException(PicaResultCode.LOGIN_FAILE.code(), PicaResultCode.LOGIN_FAILE.message());
}
//判断鉴权类型
List<String> roleCodes = new ArrayList();
int authType = AuthTypeEnum.URL.code();
if (authentication.roleCodes().length > 0) {
authType = AuthTypeEnum.ROLE.code();
roleCodes = Arrays.asList(authentication.roleCodes());
}
//url鉴权,获取api
String api = null;
if (authType == AuthTypeEnum.URL.code()) {
api = methodUrlMap.get(method);
if (api == null) {
String requestMappingUrl = this.getRequestMappingUrl(joinPoint.getTarget(), method);
api = request.getMethod() + ":" + request.getContextPath() + requestMappingUrl;
methodUrlMap.put(method, api);
}
}
//访问权限中心进行鉴权
AuthDto authDto = new AuthDto(authentication.productType(), userId, authType, roleCodes, api, authentication.dataAuth(), null);
PicaResponse<AuthResultDto> result = permissionServiceClient.auth(authDto);
if (!PicaResultCode.SUCCESS.code().equals(result.getCode())) {
throw new PicaException(result.getCode(), result.getMessage());
}
AuthResultDto authResult = result.getData();
if (!authResult.isAccess()) { //无操作权限
throw new PicaException(PermissionResultCode.PERMISSION_DENY.code(), PermissionResultCode.PERMISSION_DENY.message());
}
//设置数据权限信息
if (authentication.dataAuth()) {
//获取方法签名上AuthResultDto类型参数的位置信息
Integer index = methodIndexMap.get(method);
if (index == null) {
index = -1;
Class[] types = method.getParameterTypes();
if (types != null && types.length > 0) {
for (int i = 0; i < types.length; i++) {
if (types[i] == AuthResultDto.class) {
index = i;
break;
}
}
}
methodIndexMap.put(method, index);
}
if (index >= 0) {
Object[] objs = joinPoint.getArgs();
objs[index] = authResult;
return joinPoint.proceed(objs);
}
}
return joinPoint.proceed();
}
//获取Controller+Method上配置的uri信息
private String getRequestMappingUrl(Object controller, Method method) {
RequestMapping classUrl = controller.getClass().getAnnotation(RequestMapping.class);
String url = "";
if (classUrl != null) {
url += classUrl.value()[0]; //Controller类上RequestMapping配置
}
//方法上RequestMapping配置
Annotation[] anns = method.getAnnotations();
for (Annotation ann : anns) {
if (ann.annotationType() == RequestMapping.class) {
url += ((RequestMapping) ann).value()[0];
break;
}
if (ann.annotationType() == GetMapping.class) {
url += ((GetMapping) ann).value()[0];
break;
}
if (ann.annotationType() == PostMapping.class) {
url += ((PostMapping) ann).value()[0];
break;
}
if (ann.annotationType() == PutMapping.class) {
url += ((PutMapping) ann).value()[0];
break;
}
if (ann.annotationType() == DeleteMapping.class) {
url += ((DeleteMapping) ann).value()[0];
break;
}
if (ann.annotationType() == PatchMapping.class) {
url += ((PatchMapping) ann).value()[0];
break;
}
}
return url;
}
}
package com.pica.cloud.permission.permission.client;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.permission.permission.common.dto.AuthDto;
import com.pica.cloud.permission.permission.common.dto.AuthResultDto;
import com.pica.cloud.permission.permission.common.dto.GrantDto;
import com.pica.cloud.permission.permission.common.dto.UserRoleDto;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.*;
/**
* @author andong
* @create 2019/9/9
*/
@FeignClient(name = "13501-pica-cloud-permission")
public interface PermissionServiceClient {
//授权
@PostMapping("/permission/permission/user-role")
PicaResponse grant(@RequestBody UserRoleDto userRoleDto);
//业务场景授权
@PostMapping("/permission/permission/grant")
PicaResponse grant(@RequestBody GrantDto grantDto);
//取消权限
@PutMapping("/permission/permission/user-role")
PicaResponse revoke(@RequestBody UserRoleDto userRoleDto);
//鉴权
@PostMapping("/permission/permission/auth")
PicaResponse<AuthResultDto> auth(@RequestBody AuthDto authDto);
//初始化用户-角色缓存信息
@GetMapping("/permission/permission/init/user")
PicaResponse initUserRole(@RequestParam("userId") int userId);
}
package com.pica.cloud.permission.permission.client;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.permission.permission.entity.PUserRole;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
/**
* Created on 2020/1/6 10:53
* author:crs
* Description:UseRoleClient
*/
@FeignClient(name = "13501-pica-cloud-permission")
public interface UseRoleClient {
/**
* 注册用户角色
*
* @param pUserRole
* @return
*/
@PostMapping("/permission/role/register")
PicaResponse postUserRole(@RequestBody PUserRole pUserRole);
}
package com.pica.cloud.permission.permission.common.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Authentication {
int productType() default 1;
String[] roleCodes() default {};
boolean dataAuth() default false;
boolean tokenRequired() default true;
}
package com.pica.cloud.permission.permission.common.constants;
/**
* @author andong
* @create 2019/9/5
*/
public enum AuthTypeEnum {
ROLE(1, "角色鉴权"), URL(2, "url鉴权");
private int code;
private String desc;
AuthTypeEnum(int code, String desc) {
this.code = code;
this.desc = desc;
}
public int code() {
return this.code;
}
public String desc() {
return this.desc;
}
}
package com.pica.cloud.permission.permission.common.constants;
/**
* @author andong
* @create 2019/9/4
*/
@SuppressWarnings("unused")
public enum GrantCodeEnum {
REGISTER, //注册
JOIN_HOSPITAL, //加入机构
QUIT_HOSPITAL, //退出(移除)机构
CERTIFY //认证通过
}
package com.pica.cloud.permission.permission.common.constants;
/**
* @author andong
* @create 2019/9/12
*/
public enum PermissionResultCode {
PERMISSION_DENY("217001", "无操作权限");
private String code;
private String message;
PermissionResultCode(String code, String message) {
this.code = code;
this.message = message;
}
public String code() {
return this.code;
}
public String message() {
return this.message;
}
}
package com.pica.cloud.permission.permission.common.constants;
/**
* @author andong
* @create 2019/9/4
*/
@SuppressWarnings("unused")
public enum ProductTypeEnum {
DOCTOR(1, "云鹊医"), HEALTH(2, "云鹊健康"), ADMIN(3, "admin");
private int code;
private String desc;
ProductTypeEnum(int code, String desc) {
this.code = code;
this.desc = desc;
}
public int code() {
return this.code;
}
public String desc() {
return this.desc;
}
}
package com.pica.cloud.permission.permission.common.constants;
/**
* @author andong
* @create 2019/9/6
*/
@SuppressWarnings("unused")
public enum ResourceTypeEnum {
//1系统 2页面 3菜单 4按钮 5接口 6文件
SYSTEM(1, "系统"), PAGE(2, "页面"), MENU(3, "菜单"),
BUTTON(4, "按钮"), API(5, "接口"), FILE(6, "文件");
private int code;
private String desc;
ResourceTypeEnum(int code, String desc) {
this.code = code;
this.desc = desc;
}
public int code() {
return this.code;
}
public String desc() {
return this.desc;
}
}
package com.pica.cloud.permission.permission.common.constants;
/**
* @author andong
* @create 2019/9/16
*/
public enum RoleCodeEnum {
GUEST("R001", "游客"), MEMBER("R002", "注册医生"), INVITER("R003", "邀请码用户"),
CERTIFY("R004", "认证用户"), HOSPITAL("R005", "注册有机构"), NON_HOSPITAL("R006", "认证无机构"),
MAIN_ADMIN("R010", "主管理员"), ADMIN("R011", "管理员"), VIRTUAL("R999", "虚拟账号");
private String code;
private String desc;
RoleCodeEnum(String code, String desc) {
this.code = code;
this.desc = desc;
}
public String code() {
return code;
}
public String desc() {
return desc;
}
}
package com.pica.cloud.permission.permission.common.dto;
import java.util.List;
/**
* @author andong
* @create 2019/9/5
*/
public class AuthDto {
private int productType;
private int userId;
private int authType;
private List<String> roleCodes;
private String url;
private boolean dataAuth;
private String sysCode;
public AuthDto() {}
public AuthDto(int productType, int userId, int authType, List<String> roleCodes, String url, boolean dataAuth, String sysCode) {
this.productType = productType;
this.userId = userId;
this.authType = authType;
this.roleCodes = roleCodes;
this.url = url;
this.dataAuth = dataAuth;
this.sysCode = sysCode;
}
public int getProductType() {
return productType;
}
public void setProductType(int productType) {
this.productType = productType;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public int getAuthType() {
return authType;
}
public void setAuthType(int authType) {
this.authType = authType;
}
public List<String> getRoleCodes() {
return roleCodes;
}
public void setRoleCodes(List<String> roleCodes) {
this.roleCodes = roleCodes;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public boolean isDataAuth() {
return dataAuth;
}
public void setDataAuth(boolean dataAuth) {
this.dataAuth = dataAuth;
}
public String getSysCode() {
return sysCode;
}
public void setSysCode(String sysCode) {
this.sysCode = sysCode;
}
@Override
public String toString() {
return "AuthDto{" +
"productType=" + productType +
", userId=" + userId +
", authType=" + authType +
", roleCodes=" + this.getRoleCodesStr() +
", url='" + url + '\'' +
", dataAuth=" + dataAuth +
", sysCode='" + sysCode + '\'' +
'}';
}
private String getRoleCodesStr() {
if (this.roleCodes == null || this.roleCodes.size() == 0) {
return "[]";
}
StringBuilder sb = new StringBuilder(50);
sb.append("[");
for (int i = 0; i < roleCodes.size(); i++) {
if (i > 0) {
sb.append(",");
}
sb.append(roleCodes.get(i));
}
sb.append("]");
return sb.toString();
}
}
package com.pica.cloud.permission.permission.common.dto;
import java.util.List;
/**
* @author andong
* @create 2019/9/5
*/
public class AuthResultDto {
private boolean access;
private List<DataPrivilegeDto> dataPrivileges;
public AuthResultDto() {}
public AuthResultDto(boolean access, List<DataPrivilegeDto> dataPrivileges) {
this.access = access;
this.dataPrivileges = dataPrivileges;
}
public boolean isAccess() {
return access;
}
public void setAccess(boolean access) {
this.access = access;
}
public List<DataPrivilegeDto> getDataPrivileges() {
return dataPrivileges;
}
public void setDataPrivileges(List<DataPrivilegeDto> dataPrivileges) {
this.dataPrivileges = dataPrivileges;
}
}
package com.pica.cloud.permission.permission.common.dto;
/**
* @author andong
* @create 2019/9/5
*/
public class DataPrivilegeDto {
private String config;
private String configExt;
public DataPrivilegeDto() {}
public DataPrivilegeDto(String config, String configExt) {
this.config = config;
this.configExt = configExt;
}
public String getConfig() {
return config;
}
public void setConfig(String config) {
this.config = config;
}
public String getConfigExt() {
return configExt;
}
public void setConfigExt(String configExt) {
this.configExt = configExt;
}
}
package com.pica.cloud.permission.permission.common.dto;
/**
* @author andong
* @create 2019/9/4
*/
public class GrantDto {
private int userId;
private String grantCode;
private int createdId;
private String sysCode;
public GrantDto() {}
public GrantDto(int userId, String grantCode, int createdId) {
this.userId = userId;
this.grantCode = grantCode;
this.createdId = createdId;
}
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getGrantCode() {
return grantCode;
}
public void setGrantCode(String grantCode) {
this.grantCode = grantCode;
}
public int getCreatedId() {
return createdId;
}
public void setCreatedId(int createdId) {
this.createdId = createdId;
}
public String getSysCode() {
return sysCode;
}
public void setSysCode(String sysCode) {
this.sysCode = sysCode;
}
@Override
public String toString() {
return "GrantDto{" +
"userId=" + userId +
", grantCode='" + grantCode + '\'' +
", createdId=" + createdId +
", sysCode='" + sysCode + '\'' +
'}';
}
}
package com.pica.cloud.permission.permission.common.dto;
/**
* @author andong
* @create 2019/9/3
*/
public class RoleResourceDto {
private Integer roleId;
private String roleCode;
private String roleName;
private Integer resourceId;
private String resourceCode;
private String resourceName;
private String url;
private Integer dataPrivilegeId;
private String description;
private String config;
private String configExt;
public Integer getRoleId() {
return roleId;
}
public void setRoleId(Integer roleId) {
this.roleId = roleId;
}
public String getRoleCode() {
return roleCode;
}
public void setRoleCode(String roleCode) {
this.roleCode = roleCode;
}
public String getRoleName() {
return roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
public Integer getResourceId() {
return resourceId;
}
public void setResourceId(Integer resourceId) {
this.resourceId = resourceId;
}
public String getResourceCode() {
return resourceCode;
}
public void setResourceCode(String resourceCode) {
this.resourceCode = resourceCode;
}
public String getResourceName() {
return resourceName;
}
public void setResourceName(String resourceName) {
this.resourceName = resourceName;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public Integer getDataPrivilegeId() {
return dataPrivilegeId;
}
public void setDataPrivilegeId(Integer dataPrivilegeId) {
this.dataPrivilegeId = dataPrivilegeId;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getConfig() {
return config;
}
public void setConfig(String config) {
this.config = config;
}
public String getConfigExt() {
return configExt;
}
public void setConfigExt(String configExt) {
this.configExt = configExt;
}
}
package com.pica.cloud.permission.permission.common.dto;
/**
* @author andong
* @create 2019/9/3
*/
public class UserRoleDto {
private Integer id;
private Integer productType;
private Integer userId;
private Integer roleId;
private String roleCode;
private Integer createdId;
private Integer modifiedId;
public UserRoleDto() {}
public UserRoleDto(Integer productType, Integer userId, String roleCode, Integer createdId, Integer modifiedId) {
this.productType = productType;
this.userId = userId;
this.roleCode = roleCode;
this.createdId = createdId;
this.modifiedId = modifiedId;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getProductType() {
return productType;
}
public void setProductType(Integer productType) {
this.productType = productType;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public Integer getRoleId() {
return roleId;
}
public void setRoleId(Integer roleId) {
this.roleId = roleId;
}
public String getRoleCode() {
return roleCode;
}
public void setRoleCode(String roleCode) {
this.roleCode = roleCode;
}
public Integer getCreatedId() {
return createdId;
}
public void setCreatedId(Integer createdId) {
this.createdId = createdId;
}
public Integer getModifiedId() {
return modifiedId;
}
public void setModifiedId(Integer modifiedId) {
this.modifiedId = modifiedId;
}
@Override
public String toString() {
return "UserRoleDto{" +
"id=" + id +
", productType=" + productType +
", userId=" + userId +
", roleId=" + roleId +
", roleCode='" + roleCode + '\'' +
", createdId=" + createdId +
", modifiedId=" + modifiedId +
'}';
}
}
package com.pica.cloud.permission.permission.entity;
import java.util.Date;
public class PUserRole {
private Integer id;
private Integer systemId;
private Integer userRoleId;
private Integer userId;
private Integer userType;
private String param1;
private String param2;
private String param3;
private String param4;
private String param5;
private Integer status;
private Integer deleteFlag;
private Integer creatId;
private Date creatTime;
private Integer modifyId;
private Date modifyTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getSystemId() {
return systemId;
}
public void setSystemId(Integer systemId) {
this.systemId = systemId;
}
public Integer getUserRoleId() {
return userRoleId;
}
public void setUserRoleId(Integer userRoleId) {
this.userRoleId = userRoleId;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public Integer getUserType() {
return userType;
}
public void setUserType(Integer userType) {
this.userType = userType;
}
public String getParam1() {
return param1;
}
public void setParam1(String param1) {
this.param1 = param1 == null ? null : param1.trim();
}
public String getParam2() {
return param2;
}
public void setParam2(String param2) {
this.param2 = param2 == null ? null : param2.trim();
}
public String getParam3() {
return param3;
}
public void setParam3(String param3) {
this.param3 = param3 == null ? null : param3.trim();
}
public String getParam4() {
return param4;
}
public void setParam4(String param4) {
this.param4 = param4 == null ? null : param4.trim();
}
public String getParam5() {
return param5;
}
public void setParam5(String param5) {
this.param5 = param5 == null ? null : param5.trim();
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Integer getDeleteFlag() {
return deleteFlag;
}
public void setDeleteFlag(Integer deleteFlag) {
this.deleteFlag = deleteFlag;
}
public Integer getCreatId() {
return creatId;
}
public void setCreatId(Integer creatId) {
this.creatId = creatId;
}
public Date getCreatTime() {
return creatTime;
}
public void setCreatTime(Date creatTime) {
this.creatTime = creatTime;
}
public Integer getModifyId() {
return modifyId;
}
public void setModifyId(Integer modifyId) {
this.modifyId = modifyId;
}
public Date getModifyTime() {
return modifyTime;
}
public void setModifyTime(Date modifyTime) {
this.modifyTime = modifyTime;
}
}
\ No newline at end of file
......@@ -85,9 +85,15 @@
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<dependency>
<!-- <dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>-->
<dependency>
<groupId>com.pica.cloud.permission</groupId>
<artifactId>pica-cloud-permission-common</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
......@@ -111,35 +117,6 @@
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>nexus</id>
<url>http://192.168.110.42:8082/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<url>http://192.168.110.42:8082/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
<build>
<finalName>pica-cloud-permission-server</finalName>
......@@ -155,23 +132,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.5</version>
<dependencies>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
<configurationFile>src/main/resources/mybatis-generator.xml</configurationFile>
</configuration>
</plugin>
</plugins>
</build>
</project>
......@@ -12,7 +12,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@SpringBootApplication(scanBasePackages = "com.pica.cloud", exclude = {XxlJobConfiguration.class})
@EnableDiscoveryClient
@EnableSwagger2
@EnableFeignClients
@EnableFeignClients(basePackages = "com.pica.cloud")
@MapperScan("com.pica.cloud.permission.permission.server.mapper")
@EnableTransactionManagement
public class App {
......
package com.pica.cloud.permission.permission.server.aop;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
/**
* @author andong
* @create 2019/9/17
*/
@Aspect
@Component
public class PicaLogAspect {
private static final Logger logger = LoggerFactory.getLogger(PicaLogAspect.class);
@Pointcut("execution(public * com.pica.cloud..*Controller.*(..))")
public void weblog() {}
@Around("weblog()")
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
String url = request.getRequestURL().toString();
String method = request.getMethod();
String queryString = request.getQueryString();
String requestBody = "";
if (!"GET".equalsIgnoreCase(method) && !"DELETE".equalsIgnoreCase(method)) {
Object[] args = joinPoint.getArgs();
if (args != null && args.length > 0) {
requestBody = args[0].toString();
}
}
long startTime = System.currentTimeMillis();
logger.info("request start, controller params==>, url: {}, method: {}, params: {}, body: {}", url, method, queryString, requestBody);
Object result = joinPoint.proceed();
logger.info("request spent time milliSeconds ==>" + (System.currentTimeMillis() - startTime));
return result;
}
}
package com.pica.cloud.permission.permission.server.constants;
/**
* @author andong
* @create 2019/9/2
*/
@SuppressWarnings("unused")
public class Constants {
//delete_flag
public static final int DELETE_FLAG_VALID = 1;
public static final int DELETE_FLAG_INVALID = 2;
//缓存KEY
public static final String KEY_DOCTOR_ROLE = "perm_doctor_role_"; //医生-角色
public static final String KEY_ROLE_URL = "perm_role_url_"; //角色-资源
public static final String KEY_ROLE_DATA = "perm_role_data_"; //角色-资源-数据权限
//缓存失效时间
public static final int EXPIRE_TIMES = 2592000; //30天
//数据分割符
public static final String DATA_SPLIT = ";;;";
}
package com.pica.cloud.permission.permission.server.controller;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.permission.permission.server.entity.DataPrivilege;
import com.pica.cloud.permission.permission.server.service.DataPrivilegeService;
import com.pica.cloud.permission.permission.server.validation.DataPrivilegeValidation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @author andong
* @create 2019/9/2
*/
@Api(description = "数据权限管理")
@RestController
@RequestMapping("/permission")
public class DataPrivilegeController {
@Autowired
private DataPrivilegeService dataPrivilegeService;
@ApiOperation("根据ID获取数据权限")
@GetMapping("/data-privilege/{id}")
public PicaResponse<DataPrivilege> getById(@PathVariable("id") int id) {
DataPrivilege dataPrivilege = dataPrivilegeService.getById(id);
return PicaResponse.toResponse(dataPrivilege);
}
@ApiOperation("根据资源ID获取数据权限")
@GetMapping("/data-privilege")
public PicaResponse<List<DataPrivilege>> getByResourceId(@RequestParam("resourceId") int resourceId) {
List<DataPrivilege> list = dataPrivilegeService.getByResourceId(resourceId);
return PicaResponse.toResponse(list);
}
@ApiOperation("添加数据权限")
@PostMapping("/data-privilege")
public PicaResponse addDataPrivilege(@RequestBody DataPrivilege dataPrivilege) {
DataPrivilegeValidation.addDataPrivilegeValidate(dataPrivilege);
dataPrivilegeService.addDataPrivilege(dataPrivilege);
return PicaResponse.toResponse();
}
@ApiOperation("修改数据权限")
@PutMapping("/data-privilege")
public PicaResponse updateDataPrivilege(@RequestBody DataPrivilege dataPrivilege) {
DataPrivilegeValidation.updateDataPrivilegeValidate(dataPrivilege);
dataPrivilegeService.updateDataPrivilege(dataPrivilege);
return PicaResponse.toResponse();
}
@ApiOperation("逻辑删除数据权限")
@DeleteMapping("/data-privilege")
public PicaResponse deleteDataPrivilege(@RequestParam("id") int id, @RequestParam("modifiedId") int modifiedId) {
dataPrivilegeService.deleteDataPrivilege(id, modifiedId);
return PicaResponse.toResponse();
}
}
package com.pica.cloud.permission.permission.server.controller;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.redis.ICacheClient;
import com.pica.cloud.permission.permission.common.dto.AuthDto;
import com.pica.cloud.permission.permission.common.dto.AuthResultDto;
import com.pica.cloud.permission.permission.common.dto.GrantDto;
import com.pica.cloud.permission.permission.server.service.PermissionCacheService;
import com.pica.cloud.permission.permission.server.service.PermissionService;
import com.pica.cloud.permission.permission.server.validation.PermissionValidation;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Set;
/**
* @author andong
......@@ -15,9 +24,64 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/permission")
public class PermissionController {
@Autowired
private PermissionService permissionService;
@Autowired
private PermissionCacheService permissionCacheService;
@Autowired
private ICacheClient cacheClient;
@GetMapping("/test")
public PicaResponse<String> test() {
return PicaResponse.toResponse("test");
public PicaResponse test() {
return PicaResponse.toResponse("OK");
}
@GetMapping("/cache")
public PicaResponse getCache(@RequestParam("key") String key) {
Set<String> set = cacheClient.smembers(key);
return PicaResponse.toResponse(set);
}
@PostMapping("/cache")
public PicaResponse saveCache(@RequestParam("key") String key, @RequestParam("value") String value) {
cacheClient.set(key, value);
return PicaResponse.toResponse();
}
@DeleteMapping("/cache")
public PicaResponse deleteCache(@RequestParam("key") String key) {
cacheClient.del(key);
return PicaResponse.toResponse();
}
@ApiOperation("授权")
@PostMapping("/grant")
public PicaResponse grant(@RequestBody GrantDto grantDto) {
PermissionValidation.grantValidate(grantDto);
permissionService.grant(grantDto);
return PicaResponse.toResponse();
}
@ApiOperation("鉴权")
@PostMapping("/auth")
public PicaResponse<AuthResultDto> auth(@RequestBody AuthDto authDto) {
PermissionValidation.authValidate(authDto);
AuthResultDto result = permissionService.auth(authDto);
return PicaResponse.toResponse(result);
}
@ApiOperation("初始化角色-资源缓存信息")
@GetMapping("/init/role-res")
public PicaResponse initAllRoleResource() {
permissionCacheService.initAllRoleResource();
return PicaResponse.toResponse();
}
@ApiOperation("初始化用户-角色缓存信息")
@GetMapping("/init/user")
public PicaResponse initUserRole(@RequestParam("userId") int userId) {
permissionCacheService.initUserRole(userId);
return PicaResponse.toResponse();
}
}
package com.pica.cloud.permission.permission.server.controller;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.permission.permission.server.entity.Resource;
import com.pica.cloud.permission.permission.server.service.ResourceService;
import com.pica.cloud.permission.permission.server.validation.ResourceValidation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @author andong
* @create 2019/8/30
*/
@Api(description = "资源管理")
@RestController
@RequestMapping("/permission")
public class ResourceController {
@Autowired
private ResourceService resourceService;
@ApiOperation("根据ID获取资源")
@GetMapping("/resource/{id}")
public PicaResponse<Resource> getById(@PathVariable("id") int id) {
Resource resource = resourceService.getById(id);
return PicaResponse.toResponse(resource);
}
@ApiOperation("根据条件获取资源")
@GetMapping("/resource")
public PicaResponse<List<Resource>> getResource(@RequestParam(value = "productType", required = false) Integer productType,
@RequestParam(value = "category", required = false) Integer category,
@RequestParam(value = "type", required = false) Integer type,
@RequestParam(value = "code", required = false) String code,
@RequestParam(value = "parentId", required = false) Integer parentId) {
ResourceValidation.queryResourceValidate(productType, category, type, code, parentId);
List<Resource> list = resourceService.getByCriteria(new Resource(productType, category, type, code, parentId));
return PicaResponse.toResponse(list);
}
@ApiOperation("添加资源")
@PostMapping("/resource")
public PicaResponse addResource(@RequestBody Resource resource) {
ResourceValidation.addResourceValidate(resource);
resourceService.addResource(resource);
return PicaResponse.toResponse();
}
@ApiOperation("修改资源")
@PutMapping("/resource")
public PicaResponse updateResource(@RequestBody Resource resource) {
ResourceValidation.updateResourceValidate(resource);
resourceService.updateResource(resource);
return PicaResponse.toResponse();
}
@ApiOperation("根据ID逻辑删除资源")
@DeleteMapping("/resource")
public PicaResponse deleteResource(@RequestParam("id") int id, @RequestParam("modifiedId") int modifiedId) {
resourceService.deleteResource(id, modifiedId);
return PicaResponse.toResponse();
}
}
package com.pica.cloud.permission.permission.server.controller;
import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.permission.permission.server.entity.Role;
import com.pica.cloud.permission.permission.server.service.RoleService;
import com.pica.cloud.permission.permission.server.validation.RoleValidation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
* @author andong
* @create 2019/9/2
*/
@Api(description = "角色管理")
@RestController
@RequestMapping("/permission")
public class RoleController {
@Autowired
private RoleService roleService;
@ApiOperation("根据ID获取角色")
@GetMapping("/role/{id}")
public PicaResponse<Role> getById(@PathVariable("id") int id) {
Role role = roleService.getById(id);
return PicaResponse.toResponse(role);
}
@ApiOperation("根据角色编码或产品线类型获取角色")
@GetMapping("/role")
public PicaResponse getByCode(@RequestParam(value = "code", required = false) String code,
@RequestParam(value = "productType", required = false) Integer productType) {
if (StringUtils.isNotBlank(code)) {
return PicaResponse.toResponse(roleService.getByCode(code));
}
if (productType != null) {
return PicaResponse.toResponse(roleService.getByProductType(productType));
}
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "缺少查询参数");
}
@ApiOperation("添加角色")
@PostMapping("/role")
public PicaResponse addRole(@RequestBody Role role) {
RoleValidation.addRoleValidate(role);
roleService.addRole(role);
return PicaResponse.toResponse();
}
@ApiOperation("修改角色")
@PutMapping("/role")
public PicaResponse updateRole(@RequestBody Role role) {
RoleValidation.updateRoleValidate(role);
roleService.updateRole(role);
return PicaResponse.toResponse();
}
@ApiOperation("逻辑删除角色")
@DeleteMapping("/role")
public PicaResponse deleteRole(@RequestParam("id") int id, @RequestParam("modifiedId") int modifiedId) {
roleService.deleteRole(id, modifiedId);
return PicaResponse.toResponse();
}
}
package com.pica.cloud.permission.permission.server.controller;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.permission.permission.common.dto.RoleResourceDto;
import com.pica.cloud.permission.permission.server.entity.RoleResource;
import com.pica.cloud.permission.permission.server.service.RoleResourceService;
import com.pica.cloud.permission.permission.server.validation.RoleResourceValidation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @author andong
* @create 2019/9/2
*/
@Api(description = "角色-资源管理")
@RestController
@RequestMapping("/permission")
public class RoleResourceController {
@Autowired
private RoleResourceService roleResourceService;
@ApiOperation("根据角色ID获取资源列表")
@GetMapping("/role-resource")
public PicaResponse<List<RoleResourceDto>> getByRoleId(@RequestParam("roleId") int roleId) {
List<RoleResourceDto> list = roleResourceService.getByRoleId(roleId);
return PicaResponse.toResponse(list);
}
@ApiOperation("添加角色资源关系")
@PostMapping("/role-resource")
public PicaResponse addRoleResource(@RequestBody RoleResource roleResource) {
RoleResourceValidation.addRoleResourceValidate(roleResource);
roleResourceService.addRoleResource(roleResource);
return PicaResponse.toResponse();
}
@ApiOperation("逻辑删除角色资源关系")
@DeleteMapping("/role-resource")
public PicaResponse deleteRoleResource(@RequestParam(value = "id", required = false) Integer id,
@RequestParam(value = "roleId", required = false) Integer roleId,
@RequestParam("modifiedId") int modifiedId) {
if (id != null) {
roleResourceService.deleteRoleResource(id, modifiedId);
}
if (roleId != null) {
roleResourceService.deleteAll(roleId, modifiedId);
}
return PicaResponse.toResponse();
}
}
package com.pica.cloud.permission.permission.server.controller;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.permission.permission.server.entity.PUserRole;
import com.pica.cloud.permission.permission.server.service.IUseRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Created on 2020/1/6 10:31
* author:crs
* Description:注册用户角色
*/
@RestController
@RequestMapping("/role")
public class UseRoleController {
@Autowired
private IUseRoleService iUseRoleService;
@PostMapping("/register")
public PicaResponse postUserRole(@RequestBody PUserRole pUserRole) {
iUseRoleService.postRegisterRole(pUserRole);
return PicaResponse.toResponse();
}
}
package com.pica.cloud.permission.permission.server.controller;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.permission.permission.common.dto.UserRoleDto;
import com.pica.cloud.permission.permission.server.service.UserRoleService;
import com.pica.cloud.permission.permission.server.validation.UserRoleValidation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @author andong
* @create 2019/9/3
*/
@Api(description = "用户-角色管理")
@RestController
@RequestMapping("/permission")
public class UserRoleController {
@Autowired
private UserRoleService userRoleService;
@ApiOperation("根据用户ID,产品线类型查询角色列表")
@GetMapping("/user-role")
public PicaResponse<List<UserRoleDto>> getByUserId(@RequestParam("userId") int userId, @RequestParam("productType") int productType) {
List<UserRoleDto> list = userRoleService.getByUserId(userId, productType);
return PicaResponse.toResponse(list);
}
@ApiOperation("添加用户角色关系")
@PostMapping("/user-role")
public PicaResponse addUserRole(@RequestBody UserRoleDto userRoleDto) {
UserRoleValidation.addUserRoleValidate(userRoleDto);
userRoleService.addUserRole(userRoleDto);
return PicaResponse.toResponse();
}
@ApiOperation("根据主键逻辑删除用户角色关系")
@DeleteMapping("/user-role")
public PicaResponse deleteById(@RequestParam("id") int id, @RequestParam("modifiedId") int modifiedId) {
userRoleService.deleteById(id, modifiedId);
return PicaResponse.toResponse();
}
@ApiOperation("逻辑删除用户角色关系")
@PutMapping("/user-role")
public PicaResponse deleteUserRole(@RequestBody UserRoleDto userRoleDto) {
UserRoleValidation.deleteUserRoleValidate(userRoleDto);
userRoleService.deleteUserRole(userRoleDto);
return PicaResponse.toResponse();
}
}
......@@ -102,4 +102,18 @@ public class DataPrivilege {
public void setModifiedTime(Date modifiedTime) {
this.modifiedTime = modifiedTime;
}
@Override
public String toString() {
return "DataPrivilege{" +
"id=" + id +
", resourceId=" + resourceId +
", description='" + description + '\'' +
", config='" + config + '\'' +
", configExt='" + configExt + '\'' +
", deleteFlag=" + deleteFlag +
", createdId=" + createdId +
", modifiedId=" + modifiedId +
'}';
}
}
\ No newline at end of file
package com.pica.cloud.permission.permission.server.entity;
import java.util.Date;
public class PUserRole {
private Integer id;
private Integer systemId;
private Integer userRoleId;
private Integer userId;
private Integer userType;
private String param1;
private String param2;
private String param3;
private String param4;
private String param5;
private Integer status;
private Integer deleteFlag;
private Integer creatId;
private Date creatTime;
private Integer modifyId;
private Date modifyTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getSystemId() {
return systemId;
}
public void setSystemId(Integer systemId) {
this.systemId = systemId;
}
public Integer getUserRoleId() {
return userRoleId;
}
public void setUserRoleId(Integer userRoleId) {
this.userRoleId = userRoleId;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public Integer getUserType() {
return userType;
}
public void setUserType(Integer userType) {
this.userType = userType;
}
public String getParam1() {
return param1;
}
public void setParam1(String param1) {
this.param1 = param1 == null ? null : param1.trim();
}
public String getParam2() {
return param2;
}
public void setParam2(String param2) {
this.param2 = param2 == null ? null : param2.trim();
}
public String getParam3() {
return param3;
}
public void setParam3(String param3) {
this.param3 = param3 == null ? null : param3.trim();
}
public String getParam4() {
return param4;
}
public void setParam4(String param4) {
this.param4 = param4 == null ? null : param4.trim();
}
public String getParam5() {
return param5;
}
public void setParam5(String param5) {
this.param5 = param5 == null ? null : param5.trim();
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Integer getDeleteFlag() {
return deleteFlag;
}
public void setDeleteFlag(Integer deleteFlag) {
this.deleteFlag = deleteFlag;
}
public Integer getCreatId() {
return creatId;
}
public void setCreatId(Integer creatId) {
this.creatId = creatId;
}
public Date getCreatTime() {
return creatTime;
}
public void setCreatTime(Date creatTime) {
this.creatTime = creatTime;
}
public Integer getModifyId() {
return modifyId;
}
public void setModifyId(Integer modifyId) {
this.modifyId = modifyId;
}
public Date getModifyTime() {
return modifyTime;
}
public void setModifyTime(Date modifyTime) {
this.modifyTime = modifyTime;
}
}
\ No newline at end of file
......@@ -31,6 +31,16 @@ public class Resource {
private Date modifiedTime;
public Resource() {}
public Resource(Integer productType, Integer category, Integer type, String code, Integer parentId) {
this.productType = productType;
this.category = category;
this.type = type;
this.code = code;
this.parentId = parentId;
}
public Integer getId() {
return id;
}
......@@ -142,4 +152,21 @@ public class Resource {
public void setModifiedTime(Date modifiedTime) {
this.modifiedTime = modifiedTime;
}
@Override
public String toString() {
return "Resource{" +
"id=" + id +
", productType=" + productType +
", category=" + category +
", type=" + type +
", code='" + code + '\'' +
", name='" + name + '\'' +
", url='" + url + '\'' +
", level=" + level +
", parentId=" + parentId +
", createdId=" + createdId +
", modifiedId=" + modifiedId +
'}';
}
}
\ No newline at end of file
......@@ -92,4 +92,16 @@ public class Role {
public void setModifiedTime(Date modifiedTime) {
this.modifiedTime = modifiedTime;
}
@Override
public String toString() {
return "Role{" +
"id=" + id +
", productType=" + productType +
", code='" + code + '\'' +
", name='" + name + '\'' +
", createdId=" + createdId +
", modifiedId=" + modifiedId +
'}';
}
}
\ No newline at end of file
......@@ -92,4 +92,16 @@ public class RoleResource {
public void setModifiedTime(Date modifiedTime) {
this.modifiedTime = modifiedTime;
}
@Override
public String toString() {
return "RoleResource{" +
"id=" + id +
", roleId=" + roleId +
", resourceId=" + resourceId +
", dataPrivilegeId=" + dataPrivilegeId +
", createdId=" + createdId +
", modifiedId=" + modifiedId +
'}';
}
}
\ No newline at end of file
//package com.pica.cloud.permission.permission.server.exception;
//
//
//import com.pica.cloud.foundation.entity.PicaResponse;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.web.bind.annotation.ExceptionHandler;
//import org.springframework.web.bind.annotation.RestControllerAdvice;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//@RestControllerAdvice
//public class GlobalExceptionHandler {
// public static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
//
// @ExceptionHandler(Exception.class)
// public PicaResponse defaultErrorHandler(HttpServletRequest request , HttpServletResponse response, Throwable e){
// logger.error(e.getMessage(), e);
// return PicaResponse.toResponse(null, "500005", "服务内部异常");
// }
//}
\ No newline at end of file
package com.pica.cloud.permission.permission.server.exception;
import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@RestControllerAdvice
public class GlobalExceptionHandler {
public static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
@ExceptionHandler(Exception.class)
public PicaResponse defaultErrorHandler(Throwable t){
if (t instanceof PicaException) {
PicaException ex = (PicaException) t;
return PicaResponse.toResponse(null, ex.getCode(), ex.getMsg());
}
logger.error(t.getMessage(), t);
return PicaResponse.toResponse(null, "500005", "服务内部异常");
}
}
\ No newline at end of file
......@@ -2,18 +2,17 @@ package com.pica.cloud.permission.permission.server.mapper;
import com.pica.cloud.permission.permission.server.entity.DataPrivilege;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface DataPrivilegeMapper {
int deleteByPrimaryKey(Integer id);
int insert(DataPrivilege record);
int insertSelective(DataPrivilege dataPrivilege);
int insertSelective(DataPrivilege record);
DataPrivilege selectByPrimaryKey(int id);
DataPrivilege selectByPrimaryKey(Integer id);
List<DataPrivilege> getByResourceId(int resourceId);
int updateByPrimaryKeySelective(DataPrivilege record);
int updateByPrimaryKeySelective(DataPrivilege dataPrivilege);
int updateByPrimaryKey(DataPrivilege record);
}
\ No newline at end of file
package com.pica.cloud.permission.permission.server.mapper;
import com.pica.cloud.permission.permission.server.entity.PUserRole;
public interface PUserRoleMapper {
int deleteByPrimaryKey(Integer id);
int insert(PUserRole record);
int insertSelective(PUserRole record);
PUserRole selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(PUserRole record);
int updateByPrimaryKey(PUserRole record);
}
\ No newline at end of file
......@@ -2,18 +2,17 @@ package com.pica.cloud.permission.permission.server.mapper;
import com.pica.cloud.permission.permission.server.entity.Resource;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface ResourceMapper {
int deleteByPrimaryKey(Integer id);
int insert(Resource record);
int insertSelective(Resource resource);
int insertSelective(Resource record);
Resource selectByPrimaryKey(int id);
Resource selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(Resource resource);
int updateByPrimaryKeySelective(Resource record);
List<Resource> selectByCriteria(Resource resource);
int updateByPrimaryKey(Resource record);
}
\ No newline at end of file
......@@ -2,18 +2,19 @@ package com.pica.cloud.permission.permission.server.mapper;
import com.pica.cloud.permission.permission.server.entity.Role;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface RoleMapper {
int deleteByPrimaryKey(Integer id);
int insert(Role record);
int insertSelective(Role role);
int insertSelective(Role record);
Role selectByPrimaryKey(int id);
Role selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(Role role);
int updateByPrimaryKeySelective(Role record);
Role getByCode(String code);
List<Role> getByProductType(int productType);
int updateByPrimaryKey(Role record);
}
\ No newline at end of file
package com.pica.cloud.permission.permission.server.mapper;
import com.pica.cloud.permission.permission.common.dto.RoleResourceDto;
import com.pica.cloud.permission.permission.server.entity.RoleResource;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface RoleResourceMapper {
int deleteByPrimaryKey(Integer id);
int insert(RoleResource record);
RoleResource selectByPrimaryKey(int id);
int insertSelective(RoleResource record);
int insertSelective(RoleResource roleResource);
RoleResource selectByPrimaryKey(Integer id);
List<RoleResourceDto> getByRoleId(int roleId);
int updateByPrimaryKeySelective(RoleResource record);
int updateByPrimaryKeySelective(RoleResource roleResource);
int deleteAll(@Param("roleId") int roleId, @Param("modifiedId") int modifiedId);
Integer checkResourceUsed(int resourceId);
Integer checkDataPrivilegeUsed(int dataPrivilegeId);
Integer checkExist(RoleResource roleResource);
Integer checkRoleResourceExist(RoleResource roleResource);
List<RoleResourceDto> getByResourceId(int resourceId);
List<RoleResourceDto> getList(@Param("productType") int productType, @Param("type") int type);
int updateByPrimaryKey(RoleResource record);
}
\ No newline at end of file
package com.pica.cloud.permission.permission.server.mapper;
import com.pica.cloud.permission.permission.common.dto.UserRoleDto;
import com.pica.cloud.permission.permission.server.entity.UserRole;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface UserRoleMapper {
int deleteByPrimaryKey(Integer id);
int insert(UserRole record);
UserRole selectByPrimaryKey(int id);
int insertSelective(UserRole record);
int insertSelective(UserRole userRole);
UserRole selectByPrimaryKey(Integer id);
List<UserRoleDto> getByUserId(@Param("userId") int userId, @Param("productType") int productType);
int updateByPrimaryKeySelective(UserRole record);
int updateByPrimaryKeySelective(UserRole userRole);
int deleteUserRole(UserRole userRole);
Integer checkRoleUsed(int roleId);
Integer checkExist(UserRole userRole);
int updateByPrimaryKey(UserRole record);
}
\ No newline at end of file
package com.pica.cloud.permission.permission.server.service;
import com.pica.cloud.permission.permission.server.entity.DataPrivilege;
import java.util.List;
/**
* @author andong
* @create 2019/9/2
*/
public interface DataPrivilegeService {
//添加数据权限
void addDataPrivilege(DataPrivilege dataPrivilege);
//根据ID查询数据权限
DataPrivilege getById(int id);
//根据资源ID查询数据权限
List<DataPrivilege> getByResourceId(int resourceId);
//修改数据权限
void updateDataPrivilege(DataPrivilege dataPrivilege);
//逻辑删除数据权限
void deleteDataPrivilege(int id, int modifiedId);
}
package com.pica.cloud.permission.permission.server.service;
import com.pica.cloud.permission.permission.server.entity.PUserRole;
/**
* Created on 2020/1/6 10:44
* author:crs
* Description:IUseRoleService
*/
public interface IUseRoleService {
/**
* 插入注册用户的角色
*
* @param pUserRole
*/
void postRegisterRole(PUserRole pUserRole);
}
package com.pica.cloud.permission.permission.server.service;
import com.pica.cloud.permission.permission.server.entity.*;
/**
* @author andong
* @create 2019/9/5
*/
public interface PermissionCacheService {
//添加角色-资源
void addRoleResource(RoleResource roleResource);
//删除角色-资源
void deleteRoleResource(RoleResource roleResource);
//删除角色下所有资源
void deleteAllRoleResource(Role role);
//添加用户-角色
void addUserRole(UserRole userRole);
//删除用户-角色
void deleteUserRole(UserRole userRole);
//修改资源
void updateResource(Resource oldRes, Resource newRes);
//修改数据资源
void updateDataPrivilege(DataPrivilege oldDataPrivilege, DataPrivilege newDataPrivilege);
//初始化角色-资源(云鹊医产品系)
void initAllRoleResource();
//初始化用户-角色(云鹊医用户)
void initUserRole(int userId);
}
package com.pica.cloud.permission.permission.server.service;
import com.pica.cloud.permission.permission.common.dto.AuthDto;
import com.pica.cloud.permission.permission.common.dto.AuthResultDto;
import com.pica.cloud.permission.permission.common.dto.GrantDto;
/**
* @author andong
* @create 2019/9/5
*/
public interface PermissionService {
//业务场景授权
void grant(GrantDto grantDto);
//鉴权
AuthResultDto auth(AuthDto authDto);
}
package com.pica.cloud.permission.permission.server.service;
import com.pica.cloud.permission.permission.server.entity.Resource;
import java.util.List;
/**
* @author andong
* @create 2019/8/30
*/
public interface ResourceService {
//添加资源
void addResource(Resource resource);
//根据ID查询资源
Resource getById(int id);
//修改资源
void updateResource(Resource resource);
//根据条件查询资源
List<Resource> getByCriteria(Resource resource);
//根据ID逻辑删除资源
void deleteResource(int id, int modifiedId);
}
package com.pica.cloud.permission.permission.server.service;
import com.pica.cloud.permission.permission.common.dto.RoleResourceDto;
import com.pica.cloud.permission.permission.server.entity.RoleResource;
import java.util.List;
/**
* @author andong
* @create 2019/9/2
*/
public interface RoleResourceService {
//添加角色资源关系
void addRoleResource(RoleResource roleResource);
//根据角色ID查询角色资源关系
List<RoleResourceDto> getByRoleId(int roleId);
//逻辑删除角色资源关系
void deleteRoleResource(int id, int modifiedId);
//逻辑删除角色下全部资源
void deleteAll(int roleId, int modifiedId);
}
package com.pica.cloud.permission.permission.server.service;
import com.pica.cloud.permission.permission.server.entity.Role;
import java.util.List;
/**
* @author andong
* @create 2019/9/2
*/
public interface RoleService {
//添加角色
void addRole(Role role);
//根据ID查询角色
Role getById(int id);
//根据角色编码查询角色
Role getByCode(String code);
//根据产品线类型查询角色列表
List<Role> getByProductType(int productType);
//修改角色
void updateRole(Role role);
//逻辑删除角色
void deleteRole(int id, int modifiedId);
}
package com.pica.cloud.permission.permission.server.service;
import com.pica.cloud.permission.permission.common.dto.UserRoleDto;
import java.util.List;
/**
* @author andong
* @create 2019/9/3
*/
public interface UserRoleService {
//添加用户角色关系
void addUserRole(UserRoleDto userRoleDto);
//根据用户ID,产品限类型查询角色列表
List<UserRoleDto> getByUserId(int userId, int productType);
//逻辑删除用户角色关系
void deleteById(int id, int modifiedId);
void deleteUserRole(UserRoleDto userRoleDto);
}
package com.pica.cloud.permission.permission.server.service.impl;
import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.permission.permission.server.constants.Constants;
import com.pica.cloud.permission.permission.server.entity.DataPrivilege;
import com.pica.cloud.permission.permission.server.mapper.DataPrivilegeMapper;
import com.pica.cloud.permission.permission.server.mapper.RoleResourceMapper;
import com.pica.cloud.permission.permission.server.service.DataPrivilegeService;
import com.pica.cloud.permission.permission.server.service.PermissionCacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
/**
* @author andong
* @create 2019/9/2
*/
@Service
public class DataPrivilegeServiceImpl implements DataPrivilegeService {
@Autowired
private PermissionCacheService permissionCacheService;
@Autowired
private DataPrivilegeMapper dataPrivilegeMapper;
@Autowired
private RoleResourceMapper roleResourceMapper;
@Override
@Transactional
public void addDataPrivilege(DataPrivilege dataPrivilege) {
dataPrivilege.setModifiedId(dataPrivilege.getCreatedId());
dataPrivilege.setCreatedTime(new Date());
dataPrivilege.setModifiedTime(dataPrivilege.getCreatedTime());
dataPrivilegeMapper.insertSelective(dataPrivilege);
}
@Override
public DataPrivilege getById(int id) {
return dataPrivilegeMapper.selectByPrimaryKey(id);
}
@Override
public List<DataPrivilege> getByResourceId(int resourceId) {
return dataPrivilegeMapper.getByResourceId(resourceId);
}
@Override
@Transactional
public void updateDataPrivilege(DataPrivilege dataPrivilege) {
DataPrivilege origin = dataPrivilegeMapper.selectByPrimaryKey(dataPrivilege.getId());
if (origin == null) {
throw new PicaException(PicaResultCode.DATA_EXCEPTION.code(), "数据权限不存在");
}
dataPrivilege.setResourceId(null); //不支持修改资源ID
dataPrivilege.setModifiedTime(new Date());
dataPrivilegeMapper.updateByPrimaryKeySelective(dataPrivilege);
permissionCacheService.updateDataPrivilege(origin, dataPrivilege); //更新缓存信息
}
@Override
@Transactional
public void deleteDataPrivilege(int id, int modifiedId) {
Integer pk = roleResourceMapper.checkDataPrivilegeUsed(id);
if (pk != null) {
throw new PicaException(PicaResultCode.DATA_EXCEPTION.code(), "数据权限已被使用,无法删除");
}
DataPrivilege dataPrivilege = new DataPrivilege();
dataPrivilege.setId(id);
dataPrivilege.setDeleteFlag(Constants.DELETE_FLAG_INVALID);
dataPrivilege.setModifiedId(modifiedId);
dataPrivilege.setModifiedTime(new Date());
dataPrivilegeMapper.updateByPrimaryKeySelective(dataPrivilege);
}
}
package com.pica.cloud.permission.permission.server.service.impl;
import com.pica.cloud.foundation.redis.ICacheClient;
import com.pica.cloud.permission.permission.common.constants.AuthTypeEnum;
import com.pica.cloud.permission.permission.common.constants.ProductTypeEnum;
import com.pica.cloud.permission.permission.common.dto.*;
import com.pica.cloud.permission.permission.server.constants.Constants;
import com.pica.cloud.permission.permission.server.service.PermissionCacheService;
import com.pica.cloud.permission.permission.server.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* @author andong
* @create 2019/9/5
*/
@Service
public class PermissionServiceImpl implements PermissionService {
@Autowired
private ICacheClient cacheClient;
@Autowired
private PermissionCacheService permissionCacheService;
@Override
public void grant(GrantDto grantDto) {
String grantCode = grantDto.getGrantCode();
switch (grantCode) {
case "REGISTER" :
break;
case "JOIN_HOSPITAL" :
break;
case "QUIT_HOSPITAL" :
break;
case "CERTIFY" :
break;
}
}
@Override
public AuthResultDto auth(AuthDto authDto) {
if (authDto.getAuthType() == AuthTypeEnum.ROLE.code()) { //判断用户是否具有角色
if (authDto.getProductType() == ProductTypeEnum.DOCTOR.code()) {
return this.doctorRoleAuth(authDto);
} else {
//TODO
}
} else if (authDto.getAuthType() == AuthTypeEnum.URL.code()) { //判断用户是否具有该url访问权限
if (authDto.getProductType() == ProductTypeEnum.DOCTOR.code()) {
return this.doctorUrlAuth(authDto);
} else {
//TODO
}
}
return new AuthResultDto(false, null);
}
//医生角色鉴权
private AuthResultDto doctorRoleAuth(AuthDto authDto) {
long count = cacheClient.scard(Constants.KEY_DOCTOR_ROLE + authDto.getUserId());
if (count == 0) {
permissionCacheService.initUserRole(authDto.getUserId());
}
for (String roleCode : authDto.getRoleCodes()) {
boolean access = cacheClient.sismember(Constants.KEY_DOCTOR_ROLE + authDto.getUserId(), roleCode);
if (access) {
return new AuthResultDto(true, null);
}
}
return new AuthResultDto(false, null);
}
//医生url鉴权
private AuthResultDto doctorUrlAuth(AuthDto authDto) {
long count = cacheClient.scard(Constants.KEY_DOCTOR_ROLE + authDto.getUserId());
if (count == 0) {
permissionCacheService.initUserRole(authDto.getUserId());
}
Set<String> roleCodes = cacheClient.smembers(Constants.KEY_DOCTOR_ROLE + authDto.getUserId());
if (CollectionUtils.isEmpty(roleCodes)) { //用户无任何角色
return new AuthResultDto(false, null);
}
if (!authDto.isDataAuth()) { //仅url鉴权
for (String roleCode : roleCodes) {
Set<String> urls = cacheClient.smembers(Constants.KEY_ROLE_URL + roleCode);
for (String url : urls) {
if (authDto.getUrl().equals(url)) {
return new AuthResultDto(true, null);
}
}
}
return new AuthResultDto(false, null); //用户无该url访问权限
} else { //url+数据权限鉴权
boolean access = false;
List<DataPrivilegeDto> list = new ArrayList();
for (String roleCode : roleCodes) {
Set<String> urls = cacheClient.smembers(Constants.KEY_ROLE_DATA + roleCode);
for (String urlData : urls) {
String[] datas = urlData.split(Constants.DATA_SPLIT);
if (authDto.getUrl().equals(datas[0])) {
access = true;
if (datas.length == 2) {
list.add(new DataPrivilegeDto(datas[1], ""));
}
if (datas.length == 3) {
list.add(new DataPrivilegeDto(datas[1], datas[2]));
}
}
}
}
return new AuthResultDto(access, list);
}
}
}
package com.pica.cloud.permission.permission.server.service.impl;
import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.permission.permission.server.constants.Constants;
import com.pica.cloud.permission.permission.server.entity.Resource;
import com.pica.cloud.permission.permission.server.mapper.ResourceMapper;
import com.pica.cloud.permission.permission.server.mapper.RoleResourceMapper;
import com.pica.cloud.permission.permission.server.service.PermissionCacheService;
import com.pica.cloud.permission.permission.server.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
/**
* @author andong
* @create 2019/8/30
*/
@Service
public class ResourceServiceImpl implements ResourceService {
@Autowired
private PermissionCacheService permissionCacheService;
@Autowired
private ResourceMapper resourceMapper;
@Autowired
private RoleResourceMapper roleResourceMapper;
@Override
@Transactional
public void addResource(Resource resource) {
resource.setModifiedId(resource.getCreatedId());
resource.setCreatedTime(new Date());
resource.setModifiedTime(resource.getCreatedTime());
resourceMapper.insertSelective(resource);
}
@Override
public Resource getById(int id) {
return resourceMapper.selectByPrimaryKey(id);
}
@Override
@Transactional
public void updateResource(Resource resource) {
Resource origin = resourceMapper.selectByPrimaryKey(resource.getId());
if (origin == null) {
throw new PicaException(PicaResultCode.DATA_EXCEPTION.code(), "资源不存在");
}
resource.setProductType(null); //不支持修改产品线类型
resource.setType(null); //不支持修改资源类型
resource.setModifiedTime(new Date());
resourceMapper.updateByPrimaryKeySelective(resource);
permissionCacheService.updateResource(origin, resource); //更新缓存信息
}
@Override
public List<Resource> getByCriteria(Resource resource) {
return resourceMapper.selectByCriteria(resource);
}
@Override
@Transactional
public void deleteResource(int id, int modifiedId) {
Integer pk = roleResourceMapper.checkResourceUsed(id);
if (pk != null) {
throw new PicaException(PicaResultCode.DATA_EXCEPTION.code(), "资源已被使用,无法删除");
}
Resource resource = new Resource();
resource.setId(id);
resource.setDeleteFlag(Constants.DELETE_FLAG_INVALID);
resource.setModifiedId(modifiedId);
resource.setModifiedTime(new Date());
resourceMapper.updateByPrimaryKeySelective(resource);
}
}
package com.pica.cloud.permission.permission.server.service.impl;
import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.permission.permission.common.dto.RoleResourceDto;
import com.pica.cloud.permission.permission.server.constants.Constants;
import com.pica.cloud.permission.permission.server.entity.DataPrivilege;
import com.pica.cloud.permission.permission.server.entity.Resource;
import com.pica.cloud.permission.permission.server.entity.Role;
import com.pica.cloud.permission.permission.server.entity.RoleResource;
import com.pica.cloud.permission.permission.server.mapper.DataPrivilegeMapper;
import com.pica.cloud.permission.permission.server.mapper.ResourceMapper;
import com.pica.cloud.permission.permission.server.mapper.RoleMapper;
import com.pica.cloud.permission.permission.server.mapper.RoleResourceMapper;
import com.pica.cloud.permission.permission.server.service.PermissionCacheService;
import com.pica.cloud.permission.permission.server.service.RoleResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
/**
* @author andong
* @create 2019/9/2
*/
@Service
public class RoleResourceServiceImpl implements RoleResourceService {
@Autowired
private PermissionCacheService permissionCacheService;
@Autowired
private RoleResourceMapper roleResourceMapper;
@Autowired
private RoleMapper roleMapper;
@Autowired
private ResourceMapper resourceMapper;
@Autowired
private DataPrivilegeMapper dataPrivilegeMapper;
@Override
@Transactional
public void addRoleResource(RoleResource roleResource) {
Role role = roleMapper.selectByPrimaryKey(roleResource.getRoleId());
if (role == null) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "角色ID不存在");
}
Resource resource = resourceMapper.selectByPrimaryKey(roleResource.getResourceId());
if (resource == null) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "资源ID不存在");
}
if (roleResource.getDataPrivilegeId() != null) {
DataPrivilege dataPrivilege = dataPrivilegeMapper.selectByPrimaryKey(roleResource.getDataPrivilegeId());
if (dataPrivilege == null) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "数据权限ID不存在");
}
if (dataPrivilege.getResourceId().intValue() != roleResource.getResourceId().intValue()) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "数据权限与资源不匹配");
}
}
if (role.getProductType().intValue() != resource.getProductType().intValue()) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "角色与资源产品线不匹配");
}
Integer pk = roleResourceMapper.checkExist(roleResource);
if (pk != null) {
return; //角色-资源关系已经存在,直接返回
}
roleResource.setModifiedId(roleResource.getCreatedId());
roleResource.setCreatedTime(new Date());
roleResource.setModifiedTime(roleResource.getCreatedTime());
roleResourceMapper.insertSelective(roleResource);
permissionCacheService.addRoleResource(roleResource); //更新缓存信息
}
@Override
public List<RoleResourceDto> getByRoleId(int roleId) {
return roleResourceMapper.getByRoleId(roleId);
}
@Override
@Transactional
public void deleteRoleResource(int id, int modifiedId) {
RoleResource origin = roleResourceMapper.selectByPrimaryKey(id);
RoleResource roleResource = new RoleResource();
roleResource.setId(id);
roleResource.setDeleteFlag(Constants.DELETE_FLAG_INVALID);
roleResource.setModifiedId(modifiedId);
roleResource.setModifiedTime(new Date());
roleResourceMapper.updateByPrimaryKeySelective(roleResource);
permissionCacheService.deleteRoleResource(origin); //更新缓存信息
}
@Override
@Transactional
public void deleteAll(int roleId, int modifiedId) {
Role role = roleMapper.selectByPrimaryKey(roleId);
roleResourceMapper.deleteAll(roleId, modifiedId);
permissionCacheService.deleteAllRoleResource(role); //更新缓存信息
}
}
package com.pica.cloud.permission.permission.server.service.impl;
import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.permission.permission.server.constants.Constants;
import com.pica.cloud.permission.permission.server.entity.Role;
import com.pica.cloud.permission.permission.server.mapper.RoleMapper;
import com.pica.cloud.permission.permission.server.mapper.RoleResourceMapper;
import com.pica.cloud.permission.permission.server.mapper.UserRoleMapper;
import com.pica.cloud.permission.permission.server.service.PermissionCacheService;
import com.pica.cloud.permission.permission.server.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
/**
* @author andong
* @create 2019/9/2
*/
@Service
public class RoleServiceImpl implements RoleService {
@Autowired
private PermissionCacheService permissionCacheService;
@Autowired
private RoleMapper roleMapper;
@Autowired
private UserRoleMapper userRoleMapper;
@Autowired
private RoleResourceMapper roleResourceMapper;
@Override
@Transactional
public void addRole(Role role) {
role.setModifiedId(role.getCreatedId());
role.setCreatedTime(new Date());
role.setModifiedTime(role.getCreatedTime());
roleMapper.insertSelective(role);
}
@Override
public Role getById(int id) {
return roleMapper.selectByPrimaryKey(id);
}
@Override
public Role getByCode(String code) {
return roleMapper.getByCode(code);
}
@Override
public List<Role> getByProductType(int productType) {
return roleMapper.getByProductType(productType);
}
@Override
@Transactional
public void updateRole(Role role) {
role.setProductType(null); //不支持修改产品线类型
role.setCode(null); //不支持修改角色编码
role.setModifiedTime(new Date());
roleMapper.updateByPrimaryKeySelective(role);
}
@Override
@Transactional
public void deleteRole(int id, int modifiedId) {
Integer pk = userRoleMapper.checkRoleUsed(id);
if (pk != null) {
throw new PicaException(PicaResultCode.DATA_EXCEPTION.code(), "角色已被使用,无法删除");
}
Role origin = roleMapper.selectByPrimaryKey(id);
Role role = new Role();
role.setId(id);
role.setDeleteFlag(Constants.DELETE_FLAG_INVALID);
role.setModifiedId(modifiedId);
role.setModifiedTime(new Date());
roleMapper.updateByPrimaryKeySelective(role);
roleResourceMapper.deleteAll(id, modifiedId); //删除角色后,清除角色-资源关系
permissionCacheService.deleteAllRoleResource(origin); //清除缓存信息
}
}
package com.pica.cloud.permission.permission.server.service.impl;
import com.pica.cloud.permission.permission.server.entity.PUserRole;
import com.pica.cloud.permission.permission.server.mapper.PUserRoleMapper;
import com.pica.cloud.permission.permission.server.service.IUseRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Created on 2020/1/6 10:45
* author:crs
* Description:UseRoleServiceImpl
*/
@Service
public class UseRoleServiceImpl implements IUseRoleService {
@Autowired
private PUserRoleMapper pUserRoleMapper;
@Override
public void postRegisterRole(PUserRole pUserRole) {
pUserRoleMapper.insertSelective(pUserRole);
}
}
package com.pica.cloud.permission.permission.server.service.impl;
import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.permission.permission.common.dto.UserRoleDto;
import com.pica.cloud.permission.permission.server.constants.Constants;
import com.pica.cloud.permission.permission.server.entity.Role;
import com.pica.cloud.permission.permission.server.entity.UserRole;
import com.pica.cloud.permission.permission.server.mapper.RoleMapper;
import com.pica.cloud.permission.permission.server.mapper.UserRoleMapper;
import com.pica.cloud.permission.permission.server.service.PermissionCacheService;
import com.pica.cloud.permission.permission.server.service.UserRoleService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
/**
* @author andong
* @create 2019/9/3
*/
@Service
public class UserRoleServiceImpl implements UserRoleService {
@Autowired
private PermissionCacheService permissionCacheService;
@Autowired
private UserRoleMapper userRoleMapper;
@Autowired
private RoleMapper roleMapper;
@Override
@Transactional
public void addUserRole(UserRoleDto userRoleDto) {
Role role;
if (userRoleDto.getRoleId() != null) {
role = roleMapper.selectByPrimaryKey(userRoleDto.getRoleId());
} else {
role = roleMapper.getByCode(userRoleDto.getRoleCode());
}
if (role == null) {
throw new PicaException(PicaResultCode.RESULE_DATA_NONE.code(), "角色不存在");
}
if (role.getProductType().intValue() != userRoleDto.getProductType().intValue()) {
throw new PicaException(PicaResultCode.PARAM_IS_INVALID.code(), "用户与角色产品线不匹配");
}
UserRole userRole = new UserRole();
BeanUtils.copyProperties(userRoleDto, userRole);
userRole.setRoleId(role.getId());
userRole.setModifiedId(userRole.getCreatedId());
userRole.setCreatedTime(new Date());
userRole.setModifiedTime(userRole.getCreatedTime());
Integer pk = userRoleMapper.checkExist(userRole);
if (pk != null) {
return; //用户-角色关系已经存在
}
userRoleMapper.insertSelective(userRole);
permissionCacheService.addUserRole(userRole); //更新缓存信息
}
@Override
public List<UserRoleDto> getByUserId(int userId, int productType) {
return userRoleMapper.getByUserId(userId, productType);
}
@Override
@Transactional
public void deleteById(int id, int modifiedId) {
UserRole origin = userRoleMapper.selectByPrimaryKey(id);
UserRole userRole = new UserRole();
userRole.setId(id);
userRole.setDeleteFlag(Constants.DELETE_FLAG_INVALID);
userRole.setModifiedId(modifiedId);
userRole.setModifiedTime(new Date());
userRoleMapper.updateByPrimaryKeySelective(userRole);
permissionCacheService.deleteUserRole(origin); //更新缓存信息
}
@Override
@Transactional
public void deleteUserRole(UserRoleDto userRoleDto) {
UserRole userRole = new UserRole();
BeanUtils.copyProperties(userRoleDto, userRole);
if (userRoleDto.getRoleId() == null) {
Role role = roleMapper.getByCode(userRoleDto.getRoleCode());
if (role == null) {
return;
}
userRole.setRoleId(role.getId());
}
userRoleMapper.deleteUserRole(userRole);
permissionCacheService.deleteUserRole(userRole); //更新缓存信息
}
}
package com.pica.cloud.permission.permission.server.validation;
import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.permission.permission.server.entity.DataPrivilege;
import org.apache.commons.lang.StringUtils;
/**
* @author andong
* @create 2019/9/2
*/
public class DataPrivilegeValidation {
public static void addDataPrivilegeValidate(DataPrivilege dataPrivilege) {
if (dataPrivilege.getResourceId() == null) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "资源ID为空");
}
if (StringUtils.isBlank(dataPrivilege.getDescription())) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "数据权限描述为空");
}
if (StringUtils.isBlank(dataPrivilege.getConfig())) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "数据权限配置为空");
}
if (dataPrivilege.getCreatedId() == null) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "操作人ID为空");
}
}
public static void updateDataPrivilegeValidate(DataPrivilege dataPrivilege) {
if (dataPrivilege.getId() == null) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "数据权限ID为空");
}
if (dataPrivilege.getDescription() != null && StringUtils.isBlank(dataPrivilege.getDescription())) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "数据权限描述为空");
}
if (dataPrivilege.getConfig() != null && StringUtils.isBlank(dataPrivilege.getConfig())) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "数据权限配置为空");
}
if (dataPrivilege.getModifiedId() == null) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "操作人ID为空");
}
if (dataPrivilege.getConfig() == null && dataPrivilege.getDescription() == null && dataPrivilege.getConfigExt() == null) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "缺少必要参数");
}
}
}
package com.pica.cloud.permission.permission.server.validation;
import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.permission.permission.common.constants.AuthTypeEnum;
import com.pica.cloud.permission.permission.common.constants.ProductTypeEnum;
import com.pica.cloud.permission.permission.common.dto.AuthDto;
import com.pica.cloud.permission.permission.common.dto.GrantDto;
import org.apache.commons.lang.StringUtils;
import org.springframework.util.CollectionUtils;
/**
* @author andong
* @create 2019/9/5
*/
public class PermissionValidation {
public static void grantValidate(GrantDto grantDto) {
if (grantDto.getUserId() <= 0) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "用户ID不正确");
}
if (StringUtils.isBlank(grantDto.getGrantCode())) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "授权场景编码为空");
}
if (grantDto.getCreatedId() <= 0) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "操作人ID为空");
}
}
public static void authValidate(AuthDto authDto) {
int productType = authDto.getProductType();
if (productType != ProductTypeEnum.DOCTOR.code() && productType != ProductTypeEnum.HEALTH.code()
&& productType != ProductTypeEnum.ADMIN.code()) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "产品线类型不正确");
}
if (authDto.getUserId() <= 0) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "用户ID不正确");
}
if (authDto.getAuthType() != AuthTypeEnum.ROLE.code() && authDto.getAuthType() != AuthTypeEnum.URL.code()) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "鉴权类型不正确");
}
if (authDto.getAuthType() == AuthTypeEnum.ROLE.code() && CollectionUtils.isEmpty(authDto.getRoleCodes())) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "角色编码为空");
}
if (authDto.getAuthType() == AuthTypeEnum.URL.code() && StringUtils.isBlank(authDto.getUrl())) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "资源url为空");
}
}
}
package com.pica.cloud.permission.permission.server.validation;
import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.permission.permission.common.constants.ProductTypeEnum;
import com.pica.cloud.permission.permission.common.constants.ResourceTypeEnum;
import com.pica.cloud.permission.permission.server.entity.Resource;
import org.apache.commons.lang.StringUtils;
/**
* @author andong
* @create 2019/8/30
*/
public class ResourceValidation {
//添加资源校验
public static void addResourceValidate(Resource resource) {
Integer productType = resource.getProductType();
if (productType == null || (productType.intValue() != ProductTypeEnum.DOCTOR.code()
&& productType.intValue() != ProductTypeEnum.HEALTH.code()
&& productType.intValue() != ProductTypeEnum.ADMIN.code())) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "产品线类型不正确");
}
if (resource.getCategory() == null || resource.getCategory().intValue() <= 0) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "系统分类不正确");
}
Integer type = resource.getType();
if (type == null || (type.intValue() != ResourceTypeEnum.SYSTEM.code()
&& type.intValue() != ResourceTypeEnum.PAGE.code()
&& type.intValue() != ResourceTypeEnum.MENU.code()
&& type.intValue() != ResourceTypeEnum.BUTTON.code()
&& type.intValue() != ResourceTypeEnum.API.code()
&& type.intValue() != ResourceTypeEnum.FILE.code())) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "资源类型不正确");
}
if (StringUtils.isBlank(resource.getCode())) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "资源编码为空");
}
if (StringUtils.isBlank(resource.getName())) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "资源名称为空");
}
if (resource.getCreatedId() == null) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "操作人ID为空");
}
if (resource.getType().intValue() == ResourceTypeEnum.API.code() && StringUtils.isBlank(resource.getUrl())) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "API资源url不能为空");
}
}
//修改资源校验
public static void updateResourceValidate(Resource resource) {
if (resource.getId() == null) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "资源ID为空");
}
if (resource.getModifiedId() == null) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "操作人ID为空");
}
if (resource.getCategory() == null && StringUtils.isBlank(resource.getCode())
&& StringUtils.isBlank(resource.getName()) && StringUtils.isBlank(resource.getUrl())
&& resource.getLevel() == null && resource.getParentId() == null) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "缺少必要参数");
}
}
//查询资源校验
public static void queryResourceValidate(Integer productType, Integer category, Integer type, String code, Integer parentId) {
if (productType == null && category == null && type == null && parentId == null && StringUtils.isBlank(code)) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "缺少查询参数");
}
}
}
package com.pica.cloud.permission.permission.server.validation;
import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.permission.permission.server.entity.RoleResource;
/**
* @author andong
* @create 2019/9/3
*/
public class RoleResourceValidation {
public static void addRoleResourceValidate(RoleResource roleResource) {
if (roleResource.getRoleId() == null) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "角色ID为空");
}
if (roleResource.getResourceId() == null) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "资源ID为空");
}
if (roleResource.getCreatedId() == null) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "操作人ID为空");
}
}
}
package com.pica.cloud.permission.permission.server.validation;
import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.permission.permission.common.constants.ProductTypeEnum;
import com.pica.cloud.permission.permission.server.entity.Role;
import org.apache.commons.lang.StringUtils;
/**
* @author andong
* @create 2019/9/2
*/
public class RoleValidation {
public static void addRoleValidate(Role role) {
Integer productType = role.getProductType();
if (productType == null || (productType.intValue() != ProductTypeEnum.DOCTOR.code()
&& productType.intValue() != ProductTypeEnum.HEALTH.code()
&& productType.intValue() != ProductTypeEnum.ADMIN.code())) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "产品线类型不正确");
}
if (StringUtils.isBlank(role.getCode())) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "角色编码为空");
}
if (StringUtils.isBlank(role.getName())) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "角色名称为空");
}
if (role.getCreatedId() == null) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "操作人ID为空");
}
}
public static void updateRoleValidate(Role role) {
if (role.getId() == null) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "角色ID为空");
}
if (role.getModifiedId() == null) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "操作人ID为空");
}
if (StringUtils.isBlank(role.getName())) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "角色名称为空");
}
}
}
package com.pica.cloud.permission.permission.server.validation;
import com.pica.cloud.foundation.entity.PicaException;
import com.pica.cloud.foundation.entity.PicaResultCode;
import com.pica.cloud.permission.permission.common.constants.ProductTypeEnum;
import com.pica.cloud.permission.permission.common.dto.UserRoleDto;
import org.apache.commons.lang.StringUtils;
/**
* @author andong
* @create 2019/9/3
*/
public class UserRoleValidation {
public static void addUserRoleValidate(UserRoleDto userRoleDto) {
Integer productType = userRoleDto.getProductType();
if (productType == null || (productType.intValue() != ProductTypeEnum.DOCTOR.code()
&& productType.intValue() != ProductTypeEnum.HEALTH.code()
&& productType.intValue() != ProductTypeEnum.ADMIN.code())) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "产品线类型不正确");
}
if (userRoleDto.getUserId() == null) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "用户ID为空");
}
if (userRoleDto.getRoleId() == null && StringUtils.isBlank(userRoleDto.getRoleCode())) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "角色ID或角色编码为空");
}
if (userRoleDto.getCreatedId() == null) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "操作人ID为空");
}
}
public static void deleteUserRoleValidate(UserRoleDto userRoleDto) {
Integer productType = userRoleDto.getProductType();
if (productType == null || (productType.intValue() != ProductTypeEnum.DOCTOR.code()
&& productType.intValue() != ProductTypeEnum.HEALTH.code()
&& productType.intValue() != ProductTypeEnum.ADMIN.code())) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "产品线类型不正确");
}
if (userRoleDto.getUserId() == null) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "用户ID为空");
}
if (userRoleDto.getRoleId() == null && StringUtils.isBlank(userRoleDto.getRoleCode())) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "角色ID或角色编码为空");
}
if (userRoleDto.getModifiedId() == null) {
throw new PicaException(PicaResultCode.PARAM_IS_BLANK.code(), "操作人ID为空");
}
}
}
......@@ -26,4 +26,7 @@ logging.path=c:/tomcat_log/${spring.application.name}
feign.hystrix.enabled=false
ribbon.ReadTimeout=120000
ribbon.ConnectTimeout=60000
#------------ Please don't change above configurations ------------
\ No newline at end of file
#------------ Please don't change above configurations ------------
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
\ No newline at end of file
......@@ -20,10 +20,13 @@ eureka.instance.prefer-ip-address=true
#logback setting
logging.level.ROOT=INFO
logging.path=/opt/tomcat_log/${spring.application.name}
logging.path=/opt/tomcat-log/${spring.application.name}
#feign settings
feign.hystrix.enabled=false
ribbon.ReadTimeout=120000
ribbon.ConnectTimeout=60000
#------------ Please don't change above configurations ------------
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
......@@ -20,10 +20,13 @@ eureka.instance.prefer-ip-address=true
#logback setting
logging.level.ROOT=INFO
logging.path=/opt/tomcat_log/${spring.application.name}
logging.path=/opt/tomcat-log/${spring.application.name}
#feign settings
feign.hystrix.enabled=false
ribbon.ReadTimeout=120000
ribbon.ConnectTimeout=60000
#------------ Please don't change above configurations ------------
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
......@@ -20,10 +20,13 @@ eureka.instance.prefer-ip-address=true
#logback setting
logging.level.ROOT=INFO
logging.path=/opt/tomcat_log/${spring.application.name}
logging.path=/opt/tomcat-log/${spring.application.name}
#feign settings
feign.hystrix.enabled=false
ribbon.ReadTimeout=120000
ribbon.ConnectTimeout=60000
#------------ Please don't change above configurations ------------
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
......@@ -20,10 +20,13 @@ eureka.instance.prefer-ip-address=true
#logback setting
logging.level.ROOT=INFO
logging.path=/opt/tomcat_log/${spring.application.name}
logging.path=/opt/tomcat-log/${spring.application.name}
#feign settings
feign.hystrix.enabled=false
ribbon.ReadTimeout=120000
ribbon.ConnectTimeout=60000
#------------ Please don't change above configurations ------------
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
<?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="com.pica.cloud.permission.permission.server.mapper.DataPrivilegeMapper">
<resultMap id="BaseResultMap" type="com.pica.cloud.permission.permission.server.entity.DataPrivilege">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="resource_id" jdbcType="INTEGER" property="resourceId" />
......@@ -13,36 +14,29 @@
<result column="modified_id" jdbcType="INTEGER" property="modifiedId" />
<result column="modified_time" jdbcType="TIMESTAMP" property="modifiedTime" />
</resultMap>
<sql id="Base_Column_List">
id, resource_id, description, config, config_ext, delete_flag, created_id, created_time,
modified_id, modified_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from perm_data_privilege
where id = #{id,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER} and delete_flag = 1
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from perm_data_privilege
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.pica.cloud.permission.permission.server.entity.DataPrivilege">
insert into perm_data_privilege (id, resource_id, description,
config, config_ext, delete_flag,
created_id, created_time, modified_id,
modified_time)
values (#{id,jdbcType=INTEGER}, #{resourceId,jdbcType=INTEGER}, #{description,jdbcType=VARCHAR},
#{config,jdbcType=VARCHAR}, #{configExt,jdbcType=VARCHAR}, #{deleteFlag,jdbcType=INTEGER},
#{createdId,jdbcType=INTEGER}, #{createdTime,jdbcType=TIMESTAMP}, #{modifiedId,jdbcType=INTEGER},
#{modifiedTime,jdbcType=TIMESTAMP})
</insert>
<select id="getByResourceId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from perm_data_privilege
where resource_id = #{resourceId,jdbcType=INTEGER} and delete_flag = 1
</select>
<insert id="insertSelective" parameterType="com.pica.cloud.permission.permission.server.entity.DataPrivilege">
insert into perm_data_privilege
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="resourceId != null">
resource_id,
</if>
......@@ -72,9 +66,6 @@
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="resourceId != null">
#{resourceId,jdbcType=INTEGER},
</if>
......@@ -104,6 +95,7 @@
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.pica.cloud.permission.permission.server.entity.DataPrivilege">
update perm_data_privilege
<set>
......@@ -137,17 +129,5 @@
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.pica.cloud.permission.permission.server.entity.DataPrivilege">
update perm_data_privilege
set resource_id = #{resourceId,jdbcType=INTEGER},
description = #{description,jdbcType=VARCHAR},
config = #{config,jdbcType=VARCHAR},
config_ext = #{configExt,jdbcType=VARCHAR},
delete_flag = #{deleteFlag,jdbcType=INTEGER},
created_id = #{createdId,jdbcType=INTEGER},
created_time = #{createdTime,jdbcType=TIMESTAMP},
modified_id = #{modifiedId,jdbcType=INTEGER},
modified_time = #{modifiedTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
<?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="com.pica.cloud.permission.permission.server.mapper.PUserRoleMapper" >
<resultMap id="BaseResultMap" type="com.pica.cloud.permission.permission.server.entity.PUserRole" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="system_id" property="systemId" jdbcType="INTEGER" />
<result column="user_role_id" property="userRoleId" jdbcType="INTEGER" />
<result column="user_id" property="userId" jdbcType="INTEGER" />
<result column="user_type" property="userType" jdbcType="INTEGER" />
<result column="param_1" property="param1" jdbcType="VARCHAR" />
<result column="param_2" property="param2" jdbcType="VARCHAR" />
<result column="param_3" property="param3" jdbcType="VARCHAR" />
<result column="param_4" property="param4" jdbcType="VARCHAR" />
<result column="param_5" property="param5" jdbcType="VARCHAR" />
<result column="status" property="status" jdbcType="INTEGER" />
<result column="delete_flag" property="deleteFlag" jdbcType="INTEGER" />
<result column="creat_id" property="creatId" jdbcType="INTEGER" />
<result column="creat_time" property="creatTime" jdbcType="TIMESTAMP" />
<result column="modify_id" property="modifyId" jdbcType="INTEGER" />
<result column="modify_time" property="modifyTime" jdbcType="TIMESTAMP" />
</resultMap>
<sql id="Base_Column_List" >
id, system_id, user_role_id, user_id, user_type, param_1, param_2, param_3, param_4,
param_5, status, delete_flag, creat_id, creat_time, modify_id, modify_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from p_user_role_mapping
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from p_user_role_mapping
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.pica.cloud.permission.permission.server.entity.PUserRole" >
insert into p_user_role_mapping (id, system_id, user_role_id,
user_id, user_type, param_1,
param_2, param_3, param_4,
param_5, status, delete_flag,
creat_id, creat_time, modify_id,
modify_time)
values (#{id,jdbcType=INTEGER}, #{systemId,jdbcType=INTEGER}, #{userRoleId,jdbcType=INTEGER},
#{userId,jdbcType=INTEGER}, #{userType,jdbcType=INTEGER}, #{param1,jdbcType=VARCHAR},
#{param2,jdbcType=VARCHAR}, #{param3,jdbcType=VARCHAR}, #{param4,jdbcType=VARCHAR},
#{param5,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, #{deleteFlag,jdbcType=INTEGER},
#{creatId,jdbcType=INTEGER}, #{creatTime,jdbcType=TIMESTAMP}, #{modifyId,jdbcType=INTEGER},
#{modifyTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.pica.cloud.permission.permission.server.entity.PUserRole" >
insert into p_user_role_mapping
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="systemId != null" >
system_id,
</if>
<if test="userRoleId != null" >
user_role_id,
</if>
<if test="userId != null" >
user_id,
</if>
<if test="userType != null" >
user_type,
</if>
<if test="param1 != null" >
param_1,
</if>
<if test="param2 != null" >
param_2,
</if>
<if test="param3 != null" >
param_3,
</if>
<if test="param4 != null" >
param_4,
</if>
<if test="param5 != null" >
param_5,
</if>
<if test="status != null" >
status,
</if>
<if test="deleteFlag != null" >
delete_flag,
</if>
<if test="creatId != null" >
creat_id,
</if>
<if test="creatTime != null" >
creat_time,
</if>
<if test="modifyId != null" >
modify_id,
</if>
<if test="modifyTime != null" >
modify_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="systemId != null" >
#{systemId,jdbcType=INTEGER},
</if>
<if test="userRoleId != null" >
#{userRoleId,jdbcType=INTEGER},
</if>
<if test="userId != null" >
#{userId,jdbcType=INTEGER},
</if>
<if test="userType != null" >
#{userType,jdbcType=INTEGER},
</if>
<if test="param1 != null" >
#{param1,jdbcType=VARCHAR},
</if>
<if test="param2 != null" >
#{param2,jdbcType=VARCHAR},
</if>
<if test="param3 != null" >
#{param3,jdbcType=VARCHAR},
</if>
<if test="param4 != null" >
#{param4,jdbcType=VARCHAR},
</if>
<if test="param5 != null" >
#{param5,jdbcType=VARCHAR},
</if>
<if test="status != null" >
#{status,jdbcType=INTEGER},
</if>
<if test="deleteFlag != null" >
#{deleteFlag,jdbcType=INTEGER},
</if>
<if test="creatId != null" >
#{creatId,jdbcType=INTEGER},
</if>
<if test="creatTime != null" >
#{creatTime,jdbcType=TIMESTAMP},
</if>
<if test="modifyId != null" >
#{modifyId,jdbcType=INTEGER},
</if>
<if test="modifyTime != null" >
#{modifyTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.pica.cloud.permission.permission.server.entity.PUserRole" >
update p_user_role_mapping
<set >
<if test="systemId != null" >
system_id = #{systemId,jdbcType=INTEGER},
</if>
<if test="userRoleId != null" >
user_role_id = #{userRoleId,jdbcType=INTEGER},
</if>
<if test="userId != null" >
user_id = #{userId,jdbcType=INTEGER},
</if>
<if test="userType != null" >
user_type = #{userType,jdbcType=INTEGER},
</if>
<if test="param1 != null" >
param_1 = #{param1,jdbcType=VARCHAR},
</if>
<if test="param2 != null" >
param_2 = #{param2,jdbcType=VARCHAR},
</if>
<if test="param3 != null" >
param_3 = #{param3,jdbcType=VARCHAR},
</if>
<if test="param4 != null" >
param_4 = #{param4,jdbcType=VARCHAR},
</if>
<if test="param5 != null" >
param_5 = #{param5,jdbcType=VARCHAR},
</if>
<if test="status != null" >
status = #{status,jdbcType=INTEGER},
</if>
<if test="deleteFlag != null" >
delete_flag = #{deleteFlag,jdbcType=INTEGER},
</if>
<if test="creatId != null" >
creat_id = #{creatId,jdbcType=INTEGER},
</if>
<if test="creatTime != null" >
creat_time = #{creatTime,jdbcType=TIMESTAMP},
</if>
<if test="modifyId != null" >
modify_id = #{modifyId,jdbcType=INTEGER},
</if>
<if test="modifyTime != null" >
modify_time = #{modifyTime,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.pica.cloud.permission.permission.server.entity.PUserRole" >
update p_user_role_mapping
set system_id = #{systemId,jdbcType=INTEGER},
user_role_id = #{userRoleId,jdbcType=INTEGER},
user_id = #{userId,jdbcType=INTEGER},
user_type = #{userType,jdbcType=INTEGER},
param_1 = #{param1,jdbcType=VARCHAR},
param_2 = #{param2,jdbcType=VARCHAR},
param_3 = #{param3,jdbcType=VARCHAR},
param_4 = #{param4,jdbcType=VARCHAR},
param_5 = #{param5,jdbcType=VARCHAR},
status = #{status,jdbcType=INTEGER},
delete_flag = #{deleteFlag,jdbcType=INTEGER},
creat_id = #{creatId,jdbcType=INTEGER},
creat_time = #{creatTime,jdbcType=TIMESTAMP},
modify_id = #{modifyId,jdbcType=INTEGER},
modify_time = #{modifyTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
<?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="com.pica.cloud.permission.permission.server.mapper.ResourceMapper">
<resultMap id="BaseResultMap" type="com.pica.cloud.permission.permission.server.entity.Resource">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="product_type" jdbcType="INTEGER" property="productType" />
......@@ -17,38 +18,22 @@
<result column="modified_id" jdbcType="INTEGER" property="modifiedId" />
<result column="modified_time" jdbcType="TIMESTAMP" property="modifiedTime" />
</resultMap>
<sql id="Base_Column_List">
id, product_type, category, type, code, name, url, level, parent_id, delete_flag,
created_id, created_time, modified_id, modified_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from perm_resource
where id = #{id,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER} and delete_flag = 1
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from perm_resource
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.pica.cloud.permission.permission.server.entity.Resource">
insert into perm_resource (id, product_type, category,
type, code, name, url,
level, parent_id, delete_flag,
created_id, created_time, modified_id,
modified_time)
values (#{id,jdbcType=INTEGER}, #{productType,jdbcType=INTEGER}, #{category,jdbcType=INTEGER},
#{type,jdbcType=INTEGER}, #{code,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR},
#{level,jdbcType=INTEGER}, #{parentId,jdbcType=INTEGER}, #{deleteFlag,jdbcType=INTEGER},
#{createdId,jdbcType=INTEGER}, #{createdTime,jdbcType=TIMESTAMP}, #{modifiedId,jdbcType=INTEGER},
#{modifiedTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.pica.cloud.permission.permission.server.entity.Resource">
insert into perm_resource
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="productType != null">
product_type,
</if>
......@@ -90,9 +75,6 @@
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="productType != null">
#{productType,jdbcType=INTEGER},
</if>
......@@ -134,6 +116,7 @@
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.pica.cloud.permission.permission.server.entity.Resource">
update perm_resource
<set>
......@@ -179,21 +162,27 @@
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.pica.cloud.permission.permission.server.entity.Resource">
update perm_resource
set product_type = #{productType,jdbcType=INTEGER},
category = #{category,jdbcType=INTEGER},
type = #{type,jdbcType=INTEGER},
code = #{code,jdbcType=VARCHAR},
name = #{name,jdbcType=VARCHAR},
url = #{url,jdbcType=VARCHAR},
level = #{level,jdbcType=INTEGER},
parent_id = #{parentId,jdbcType=INTEGER},
delete_flag = #{deleteFlag,jdbcType=INTEGER},
created_id = #{createdId,jdbcType=INTEGER},
created_time = #{createdTime,jdbcType=TIMESTAMP},
modified_id = #{modifiedId,jdbcType=INTEGER},
modified_time = #{modifiedTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectByCriteria" resultMap="BaseResultMap" parameterType="com.pica.cloud.permission.permission.server.entity.Resource">
select
<include refid="Base_Column_List" />
from perm_resource
where delete_flag = 1
<if test="productType != null">
and product_type = #{productType,jdbcType=INTEGER}
</if>
<if test="category != null">
and category = #{category,jdbcType=INTEGER}
</if>
<if test="type != null">
and type = #{type,jdbcType=INTEGER}
</if>
<if test="code != null">
and code = #{code,jdbcType=VARCHAR}
</if>
<if test="parentId != null">
and parent_id = #{parentId,jdbcType=INTEGER}
</if>
</select>
</mapper>
\ No newline at end of file
<?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="com.pica.cloud.permission.permission.server.mapper.RoleMapper">
<resultMap id="BaseResultMap" type="com.pica.cloud.permission.permission.server.entity.Role">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="product_type" jdbcType="INTEGER" property="productType" />
......@@ -12,36 +13,36 @@
<result column="modified_id" jdbcType="INTEGER" property="modifiedId" />
<result column="modified_time" jdbcType="TIMESTAMP" property="modifiedTime" />
</resultMap>
<sql id="Base_Column_List">
id, product_type, code, name, delete_flag, created_id, created_time, modified_id,
modified_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from perm_role
where id = #{id,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER} and delete_flag = 1
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from perm_role
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.pica.cloud.permission.permission.server.entity.Role">
insert into perm_role (id, product_type, code,
name, delete_flag, created_id,
created_time, modified_id, modified_time
)
values (#{id,jdbcType=INTEGER}, #{productType,jdbcType=INTEGER}, #{code,jdbcType=VARCHAR},
#{name,jdbcType=VARCHAR}, #{deleteFlag,jdbcType=INTEGER}, #{createdId,jdbcType=INTEGER},
#{createdTime,jdbcType=TIMESTAMP}, #{modifiedId,jdbcType=INTEGER}, #{modifiedTime,jdbcType=TIMESTAMP}
)
</insert>
<select id="getByCode" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from perm_role
where code = #{code,jdbcType=VARCHAR} and delete_flag = 1
</select>
<select id="getByProductType" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from perm_role
where product_type = #{productType,jdbcType=INTEGER} and delete_flag = 1
</select>
<insert id="insertSelective" parameterType="com.pica.cloud.permission.permission.server.entity.Role">
insert into perm_role
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="productType != null">
product_type,
</if>
......@@ -68,9 +69,6 @@
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="productType != null">
#{productType,jdbcType=INTEGER},
</if>
......@@ -97,6 +95,7 @@
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.pica.cloud.permission.permission.server.entity.Role">
update perm_role
<set>
......@@ -127,16 +126,5 @@
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.pica.cloud.permission.permission.server.entity.Role">
update perm_role
set product_type = #{productType,jdbcType=INTEGER},
code = #{code,jdbcType=VARCHAR},
name = #{name,jdbcType=VARCHAR},
delete_flag = #{deleteFlag,jdbcType=INTEGER},
created_id = #{createdId,jdbcType=INTEGER},
created_time = #{createdTime,jdbcType=TIMESTAMP},
modified_id = #{modifiedId,jdbcType=INTEGER},
modified_time = #{modifiedTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
<?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="com.pica.cloud.permission.permission.server.mapper.RoleResourceMapper">
<resultMap id="BaseResultMap" type="com.pica.cloud.permission.permission.server.entity.RoleResource">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="role_id" jdbcType="INTEGER" property="roleId" />
......@@ -12,36 +13,33 @@
<result column="modified_id" jdbcType="INTEGER" property="modifiedId" />
<result column="modified_time" jdbcType="TIMESTAMP" property="modifiedTime" />
</resultMap>
<sql id="Base_Column_List">
id, role_id, resource_id, data_privilege_id, delete_flag, created_id, created_time,
modified_id, modified_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
select
<include refid="Base_Column_List" />
from perm_role_resource
where id = #{id,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER} and delete_flag = 1
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from perm_role_resource
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.pica.cloud.permission.permission.server.entity.RoleResource">
insert into perm_role_resource (id, role_id, resource_id,
data_privilege_id, delete_flag, created_id,
created_time, modified_id, modified_time
)
values (#{id,jdbcType=INTEGER}, #{roleId,jdbcType=INTEGER}, #{resourceId,jdbcType=INTEGER},
#{dataPrivilegeId,jdbcType=INTEGER}, #{deleteFlag,jdbcType=INTEGER}, #{createdId,jdbcType=INTEGER},
#{createdTime,jdbcType=TIMESTAMP}, #{modifiedId,jdbcType=INTEGER}, #{modifiedTime,jdbcType=TIMESTAMP}
)
</insert>
<select id="getByRoleId" resultType="com.pica.cloud.permission.permission.common.dto.RoleResourceDto" parameterType="java.lang.Integer">
select rr.role_id as roleId, r.code as roleCode, r.name as roleName,
re.id as resourceId, re.code as resourceCode, re.name as resourceName, re.url,
dp.id as dataPrivilegeId, dp.description, dp.config, dp.config_ext as configExt
from perm_role_resource rr
join perm_role r on rr.role_id = r.id and r.delete_flag = 1
join perm_resource re on rr.resource_id = re.id and re.delete_flag = 1
left join perm_data_privilege dp on rr.data_privilege_id = dp.id and dp.delete_flag = 1
where rr.role_id = #{roleId} and rr.delete_flag = 1
</select>
<insert id="insertSelective" parameterType="com.pica.cloud.permission.permission.server.entity.RoleResource">
insert into perm_role_resource
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="roleId != null">
role_id,
</if>
......@@ -68,9 +66,6 @@
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="roleId != null">
#{roleId,jdbcType=INTEGER},
</if>
......@@ -97,6 +92,7 @@
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.pica.cloud.permission.permission.server.entity.RoleResource">
update perm_role_resource
<set>
......@@ -127,16 +123,62 @@
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.pica.cloud.permission.permission.server.entity.RoleResource">
update perm_role_resource
set role_id = #{roleId,jdbcType=INTEGER},
resource_id = #{resourceId,jdbcType=INTEGER},
data_privilege_id = #{dataPrivilegeId,jdbcType=INTEGER},
delete_flag = #{deleteFlag,jdbcType=INTEGER},
created_id = #{createdId,jdbcType=INTEGER},
created_time = #{createdTime,jdbcType=TIMESTAMP},
modified_id = #{modifiedId,jdbcType=INTEGER},
modified_time = #{modifiedTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
<update id="deleteAll">
update perm_role_resource set delete_flag = 2, modified_id = #{modifiedId}, modified_time = now()
where role_id = #{roleId}
</update>
<select id="checkResourceUsed" resultType="java.lang.Integer" parameterType="java.lang.Integer">
select id
from perm_role_resource
where resource_id = #{resourceId} and delete_flag = 1
limit 1
</select>
<select id="checkDataPrivilegeUsed" resultType="java.lang.Integer" parameterType="java.lang.Integer">
select id
from perm_role_resource
where data_privilege_id = #{dataPrivilegeId} and delete_flag = 1
limit 1
</select>
<select id="checkExist" resultType="java.lang.Integer" parameterType="com.pica.cloud.permission.permission.server.entity.RoleResource">
select id
from perm_role_resource
where role_id = #{roleId} and resource_id = #{resourceId}
<if test="dataPrivilegeId != null">
and data_privilege_id = #{dataPrivilegeId}
</if>
<if test="dataPrivilegeId == null">
and data_privilege_id = 0
</if>
and delete_flag = 1
limit 1
</select>
<select id="checkRoleResourceExist" resultType="java.lang.Integer" parameterType="com.pica.cloud.permission.permission.server.entity.RoleResource">
select id
from perm_role_resource
where role_id = #{roleId} and resource_id = #{resourceId} and delete_flag = 1
limit 1
</select>
<select id="getByResourceId" resultType="com.pica.cloud.permission.permission.common.dto.RoleResourceDto" parameterType="java.lang.Integer">
select r.id as roleId, r.code as roleCode, rr.data_privilege_id as dataPrivilegeId
from perm_role_resource rr join perm_role r on rr.role_id = r.id and r.delete_flag = 1
where rr.resource_id = #{resourceId} and rr.delete_flag = 1
</select>
<select id="getList" resultType="com.pica.cloud.permission.permission.common.dto.RoleResourceDto">
select rr.role_id as roleId, r.code as roleCode, r.name as roleName,
re.id as resourceId, re.code as resourceCode, re.name as resourceName, re.url,
dp.id as dataPrivilegeId, dp.description, dp.config, dp.config_ext as configExt
from perm_role_resource rr
join perm_role r on rr.role_id = r.id and r.delete_flag = 1
join perm_resource re on rr.resource_id = re.id and re.delete_flag = 1
left join perm_data_privilege dp on rr.data_privilege_id = dp.id and dp.delete_flag = 1
where rr.delete_flag = 1 and re.product_type = #{productType} and re.type = #{type}
</select>
</mapper>
\ No newline at end of file
<?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="com.pica.cloud.permission.permission.server.mapper.UserRoleMapper">
<resultMap id="BaseResultMap" type="com.pica.cloud.permission.permission.server.entity.UserRole">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="product_type" jdbcType="INTEGER" property="productType" />
......@@ -12,36 +13,31 @@
<result column="modified_id" jdbcType="INTEGER" property="modifiedId" />
<result column="modified_time" jdbcType="TIMESTAMP" property="modifiedTime" />
</resultMap>
<sql id="Base_Column_List">
id, product_type, user_id, role_id, delete_flag, created_id, created_time, modified_id,
modified_time
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
select
<include refid="Base_Column_List" />
from perm_user_role
where id = #{id,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER} and delete_flag = 1
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from perm_user_role
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.pica.cloud.permission.permission.server.entity.UserRole">
insert into perm_user_role (id, product_type, user_id,
role_id, delete_flag, created_id,
created_time, modified_id, modified_time
)
values (#{id,jdbcType=INTEGER}, #{productType,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER},
#{roleId,jdbcType=INTEGER}, #{deleteFlag,jdbcType=INTEGER}, #{createdId,jdbcType=INTEGER},
#{createdTime,jdbcType=TIMESTAMP}, #{modifiedId,jdbcType=INTEGER}, #{modifiedTime,jdbcType=TIMESTAMP}
)
</insert>
<select id="getByUserId" resultType="com.pica.cloud.permission.permission.common.dto.UserRoleDto">
select ur.id, ur.product_type as productType, ur.user_id as userId, ur.role_id as roleId,
r.code as roleCode, r.name as roleName
from perm_user_role ur
join perm_role r on ur.role_id = r.id
where ur.user_id = #{userId} and ur.product_type = #{productType}
and ur.delete_flag = 1 and r.delete_flag = 1
</select>
<insert id="insertSelective" parameterType="com.pica.cloud.permission.permission.server.entity.UserRole">
insert into perm_user_role
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="productType != null">
product_type,
</if>
......@@ -68,9 +64,6 @@
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=INTEGER},
</if>
<if test="productType != null">
#{productType,jdbcType=INTEGER},
</if>
......@@ -97,6 +90,7 @@
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.pica.cloud.permission.permission.server.entity.UserRole">
update perm_user_role
<set>
......@@ -127,16 +121,25 @@
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.pica.cloud.permission.permission.server.entity.UserRole">
<update id="deleteUserRole" parameterType="com.pica.cloud.permission.permission.server.entity.UserRole">
update perm_user_role
set product_type = #{productType,jdbcType=INTEGER},
user_id = #{userId,jdbcType=INTEGER},
role_id = #{roleId,jdbcType=INTEGER},
delete_flag = #{deleteFlag,jdbcType=INTEGER},
created_id = #{createdId,jdbcType=INTEGER},
created_time = #{createdTime,jdbcType=TIMESTAMP},
modified_id = #{modifiedId,jdbcType=INTEGER},
modified_time = #{modifiedTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
set delete_flag = 2, modified_time = now(), modified_id = #{modifiedId}
where product_type = #{productType} and user_id = #{userId} and role_id = #{roleId}
</update>
<select id="checkRoleUsed" resultType="java.lang.Integer" parameterType="java.lang.Integer">
select id
from perm_user_role
where role_id = #{roleId} and delete_flag = 1
limit 1
</select>
<select id="checkExist" resultType="java.lang.Integer" parameterType="com.pica.cloud.permission.permission.server.entity.UserRole">
select id
from perm_user_role
where product_type = #{productType} and user_id = #{userId} and role_id = #{roleId} and delete_flag = 1
limit 1
</select>
</mapper>
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册