系统权限控制切面工程实现

pull/1/head
陈沅 2 years ago
parent 1dece8a55a
commit b60ba37fd6

@ -0,0 +1,28 @@
package com.sztzjy.forex.trading_trading.annotation;
import com.sztzjy.forex.trading_trading.annotation.aspect.PermissionType;
import java.lang.annotation.*;
/**
*
*
* @author
*
* 2023630
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Permission {
/**
* MANAGER
* {o1,02}
*
* @return string
*/
String[] codes() default {PermissionType.TERMINAL_MANAGEMENT};
}

@ -0,0 +1,86 @@
package com.sztzjy.forex.trading_trading.annotation.aspect;
import com.sztzjy.forex.trading_trading.annotation.Permission;
import com.sztzjy.forex.trading_trading.config.security.JwtUser;
import com.sztzjy.forex.trading_trading.config.security.TokenProvider;
import com.sztzjy.forex.trading_trading.service.RoleAuthorityService;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.core.Ordered;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
import java.util.List;
/**
*
*
* @author
*/
@Aspect
@Component
public class PermissionAspect implements Ordered{
@Resource
private HttpServletRequest request;
@Resource
private RoleAuthorityService roleAuthorityService;
@Pointcut("@annotation(com.sztzjy.forex.trading_trading.annotation.Permission)")
public void authPointcut() {
}
@Around("authPointcut()")
public Object around(ProceedingJoinPoint point) throws Throwable {
Object result = point.proceed();
return result;
}
@Before("authPointcut()")
public void before(JoinPoint joinPoint) {
JwtUser onlineUser = TokenProvider.getJWTUser(request);
if (onlineUser == null) {
throw new AccessDeniedException("当前用户未登录");
}
// 获取注解参数
MethodSignature sign = (MethodSignature) joinPoint.getSignature();
Method method = sign.getMethod();
Permission permission = method.getAnnotation(Permission.class);
//限制权限类型
String[] codes = permission.codes();
if(onlineUser.getRoleId()==0){
throw new AccessDeniedException("权限不足");
}
//角色绑定的权限列表
List<String> codeList = roleAuthorityService.getAuthorityByRoleId(onlineUser.getRoleId());
boolean hasPermission = false;
for (String code : codes){
if(codeList.contains(code)){
hasPermission=true;
break;
}
}
if(!hasPermission){
throw new AccessDeniedException("权限不足");
}
}
@After("authPointcut()")
public void after() {
//log.info("======>>> 后置通知:执行结束");
}
@Override
public int getOrder() {
return Ordered.HIGHEST_PRECEDENCE + 1;
}
}

@ -0,0 +1,26 @@
package com.sztzjy.forex.trading_trading.annotation.aspect;
/**
*
* author:
*/
public class PermissionType {
public final static String DATA_STATISTICS = "DATA_STATISTICS";
public final static String QUOTATION_TRADING = "QUOTATION_TRADING";
public final static String TERMINAL_MANAGEMENT = "TERMINAL_MANAGEMENT";
public final static String TRADING = "TRADING";
public final static String TRAINING_MANAGEMENT = "TRAINING_MANAGEMENT";
public final static String TRAINING_MANAGEMENT_ADD = "TRAINING_MANAGEMENT_ADD";
public final static String TRAINING_MANAGEMENT_DEL = "TRAINING_MANAGEMENT_DEL";
public final static String TRAINING_MANAGEMENT_EDIT = "TRAINING_MANAGEMENT_EDIT";
public final static String TRAINING_MANAGEMENT_SEARCH = "TRAINING_MANAGEMENT_SEARCH";
public final static String TRAINING_PLAN_MANAGEMENT = "TRAINING_PLAN_MANAGEMENT";
public final static String TRAINING_PLAN_MANAGEMENT_ADD = "TRAINING_PLAN_MANAGEMENT_ADD";
public final static String TRAINING_PLAN_MANAGEMENT_DEL = "TRAINING_PLAN_MANAGEMENT_DEL";
public final static String TRAINING_PLAN_MANAGEMENT_EDIT = "TRAINING_PLAN_MANAGEMENT_EDIT";
public final static String TRAINING_PLAN_MANAGEMENT_SEARCH = "TRAINING_PLAN_MANAGEMENT_SEARCH";
}

@ -6,6 +6,7 @@ import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import java.util.Collection;
import java.util.List;
/**
* jwt
@ -20,6 +21,13 @@ public class JwtUser implements UserDetails {
private int roleId;
private int schoolId;
private int classId;
private String schoolName;
private String className;
private int majorId;
private String majorName;
private String collegeId;
private String collegeName;
private List<String> authorityCodes;
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {

@ -31,6 +31,8 @@ public class LoginResult {
private int classId;
@ApiModelProperty("用户所在学校id")
private int schoolId;
@ApiModelProperty("用户权限")
private List<String> authorityCodes;
/**
*
@ -47,6 +49,7 @@ public class LoginResult {
result.setAccessToken(accessToken);
result.setClassId(jwtUser.getClassId());
result.setSchoolId(jwtUser.getSchoolId());
result.setAuthorityCodes(jwtUser.getAuthorityCodes());
return result;
}
}

@ -1,11 +1,18 @@
package com.sztzjy.forex.trading_trading.config.security;
import com.sztzjy.forex.trading_trading.config.Constant;
import com.sztzjy.forex.trading_trading.config.exception.UnAuthorizedException;
import com.sztzjy.forex.trading_trading.mappers.RoleAuthorityMapper;
import com.sztzjy.forex.trading_trading.service.RoleAuthorityService;
import io.jsonwebtoken.*;
import io.jsonwebtoken.security.Keys;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.crypto.spec.SecretKeySpec;
import javax.servlet.http.HttpServletRequest;
import java.nio.charset.StandardCharsets;
import java.security.Key;
import java.security.MessageDigest;
@ -21,6 +28,7 @@ public class TokenProvider {
private final static long EXP_TIME = 1000 * 60 * 60 * 2;
private final static String SECRET_ZHIYUN = "zy_wh_mnjy_fp76ckwuczzmb67w0a8x0";
/**
* jwtToken
*
@ -46,7 +54,7 @@ public class TokenProvider {
jwtUser.setRoleId(Integer.valueOf(claims.get("roleId").toString()));
jwtUser.setClassId(Integer.valueOf(claims.get("classId").toString()));
jwtUser.setSchoolId(Integer.valueOf(claims.get("schoolId").toString()));
jwtUser.setUsername(claims.get("name").toString());
jwtUser.setUsername(claims.get("username").toString());
return jwtUser;
} catch (Exception e) {
return null;
@ -63,6 +71,7 @@ public class TokenProvider {
.claim("classId", jwtUser.getClassId())
.claim("schoolId", jwtUser.getSchoolId())
.claim("username", jwtUser.getUsername())
.claim("authorityCodes",jwtUser.getAuthorityCodes())
.setIssuedAt(new Date(System.currentTimeMillis()))
.setExpiration(expiration)
.signWith(key, SignatureAlgorithm.HS512)
@ -119,4 +128,21 @@ public class TokenProvider {
return keyBuilder.toString();
}
/**
*
* @param request request
* @return JwtUser
*/
public static JwtUser getJWTUser(HttpServletRequest request) {
if (!(request.getUserPrincipal() instanceof UsernamePasswordAuthenticationToken)) {
throw new UnAuthorizedException("身份认证失败");
}
String jwtToken = request.getHeader(Constant.AUTHORIZATION);
if (StringUtils.hasText(jwtToken)) {
return getJWTUser(jwtToken);
}
throw new UnAuthorizedException("身份认证失败");
}
}

@ -3,6 +3,8 @@ package com.sztzjy.forex.trading_trading.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.sztzjy.forex.trading_trading.annotation.Permission;
import com.sztzjy.forex.trading_trading.annotation.aspect.PermissionType;
import com.sztzjy.forex.trading_trading.config.security.JwtUser;
import com.sztzjy.forex.trading_trading.config.security.TokenProvider;
import com.sztzjy.forex.trading_trading.dto.TrainingBO;
@ -32,6 +34,7 @@ public class TrainingController {
HttpServletRequest request;
@Permission(codes = PermissionType.TRAINING_MANAGEMENT_ADD)
@ApiOperation("教师端----新增一条实训记录")
@PostMapping("create")
public ResultEntity create(@RequestBody TrainingBO bo) {
@ -40,14 +43,16 @@ public class TrainingController {
return new ResultEntity(HttpStatus.OK);
}
@Permission(codes = PermissionType.TRAINING_MANAGEMENT_DEL)
@ApiOperation("教师端----删除一条实训记录")
@PostMapping("deleteById")
public ResultEntity deleteById(@ApiParam("实训记录id") @RequestParam Integer trainingId) {
trainingService.delete(trainingId);
return new ResultEntity(HttpStatus.OK);
}
@Permission(codes = PermissionType.TRAINING_MANAGEMENT_EDIT)
@ApiOperation("教师端----修改一条实训记录")
@PostMapping("update")
public ResultEntity update(@ApiParam("实训记录id") @RequestParam Integer trainingId,
@ -59,6 +64,7 @@ public class TrainingController {
}
@Permission(codes = PermissionType.TRAINING_MANAGEMENT_SEARCH)
@ApiOperation("教师端----根据实训记录id查询实训记录")
@GetMapping("training/{id}")
public ResultEntity<Training> get(@ApiParam("实训记录id")
@ -68,6 +74,7 @@ public class TrainingController {
}
@Permission(codes = PermissionType.TRAINING_MANAGEMENT_SEARCH)
@ApiOperation("教师端----根据条件分页获取实训记录数据")
@GetMapping("findByConditions")
public ResultEntity<PageInfo<Training>> findByConditions(@ApiParam("页码") Integer index,
@ -76,10 +83,11 @@ public class TrainingController {
return new ResultEntity<PageInfo<Training>>(HttpStatus.OK, trainingService.pagedListTraining(index, size));
}
@Permission(codes = PermissionType.TRAINING_MANAGEMENT_SEARCH)
@ApiOperation("获取实训下拉框列表")
@GetMapping("findTrainingNameList")
public ResultEntity<List<Map<String,Object>>> findTrainingNameList() {
public ResultEntity<List<Map<String, Object>>> findTrainingNameList() {
JwtUser currentUser = TokenProvider.getJWTUser(request);
return new ResultEntity<List<Map<String,Object>>>(HttpStatus.OK, trainingService.findTrainingNameList(currentUser));
return new ResultEntity<List<Map<String, Object>>>(HttpStatus.OK, trainingService.findTrainingNameList(currentUser));
}
}

@ -6,6 +6,7 @@ import com.sztzjy.forex.trading_trading.annotation.OperateLog;
import com.sztzjy.forex.trading_trading.config.security.JwtUser;
import com.sztzjy.forex.trading_trading.config.security.LoginResult;
import com.sztzjy.forex.trading_trading.config.security.TokenProvider;
import com.sztzjy.forex.trading_trading.service.RoleAuthorityService;
import com.sztzjy.forex.trading_trading.util.ResultEntity;
import com.sztzjy.forex.trading_trading.util.RsaUtil;
import com.sztzjy.forex.trading_trading.util.TzApi;
@ -13,6 +14,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
@ -33,6 +35,9 @@ import javax.annotation.Resource;
@RequiredArgsConstructor
public class UserController {
@Autowired
private RoleAuthorityService roleAuthorityService;
@AnonymousAccess
@OperateLog(description = "用户登录")
@ApiOperation(value = "用户登录", httpMethod = "POST")
@ -49,6 +54,7 @@ public class UserController {
String md5Pwd =RsaUtil.calculateMD5(password);
String hashPwd = RsaUtil.formatHash(md5Pwd);
JwtUser jwtUser = TzApi.foreignExchangeTradingLogin(username, hashPwd);
jwtUser.setAuthorityCodes(roleAuthorityService.getAuthorityByRoleId(jwtUser.getRoleId()));
Authentication authentication = new UsernamePasswordAuthenticationToken(jwtUser, null, jwtUser.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(authentication);
String token = TokenProvider.createToken(jwtUser);

@ -0,0 +1,102 @@
package com.sztzjy.forex.trading_trading.entity;
public class RoleAuthority {
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column sys_role_authority.id
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
private String id;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column sys_role_authority.role_id
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
private Integer roleId;
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column sys_role_authority.authority_id
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
private String authorityId;
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column sys_role_authority.id
*
* @return the value of sys_role_authority.id
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
public String getId() {
return id;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column sys_role_authority.id
*
* @param id the value for sys_role_authority.id
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
public void setId(String id) {
this.id = id == null ? null : id.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column sys_role_authority.role_id
*
* @return the value of sys_role_authority.role_id
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
public Integer getRoleId() {
return roleId;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column sys_role_authority.role_id
*
* @param roleId the value for sys_role_authority.role_id
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
public void setRoleId(Integer roleId) {
this.roleId = roleId;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column sys_role_authority.authority_id
*
* @return the value of sys_role_authority.authority_id
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
public String getAuthorityId() {
return authorityId;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column sys_role_authority.authority_id
*
* @param authorityId the value for sys_role_authority.authority_id
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
public void setAuthorityId(String authorityId) {
this.authorityId = authorityId == null ? null : authorityId.trim();
}
}

@ -0,0 +1,501 @@
package com.sztzjy.forex.trading_trading.entity;
import java.util.ArrayList;
import java.util.List;
public class RoleAuthorityExample {
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
protected String orderByClause;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
protected boolean distinct;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
protected List<Criteria> oredCriteria;
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
public RoleAuthorityExample() {
oredCriteria = new ArrayList<>();
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
public String getOrderByClause() {
return orderByClause;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
public boolean isDistinct() {
return distinct;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
public List<Criteria> getOredCriteria() {
return oredCriteria;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
public void or(Criteria criteria) {
oredCriteria.add(criteria);
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
public Criteria or() {
Criteria criteria = createCriteriaInternal();
oredCriteria.add(criteria);
return criteria;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
public Criteria createCriteria() {
Criteria criteria = createCriteriaInternal();
if (oredCriteria.size() == 0) {
oredCriteria.add(criteria);
}
return criteria;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
protected Criteria createCriteriaInternal() {
Criteria criteria = new Criteria();
return criteria;
}
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
public void clear() {
oredCriteria.clear();
orderByClause = null;
distinct = false;
}
/**
* This class was generated by MyBatis Generator.
* This class corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;
protected GeneratedCriteria() {
super();
criteria = new ArrayList<>();
}
public boolean isValid() {
return criteria.size() > 0;
}
public List<Criterion> getAllCriteria() {
return criteria;
}
public List<Criterion> getCriteria() {
return criteria;
}
protected void addCriterion(String condition) {
if (condition == null) {
throw new RuntimeException("Value for condition cannot be null");
}
criteria.add(new Criterion(condition));
}
protected void addCriterion(String condition, Object value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value));
}
protected void addCriterion(String condition, Object value1, Object value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value1, value2));
}
public Criteria andIdIsNull() {
addCriterion("id is null");
return (Criteria) this;
}
public Criteria andIdIsNotNull() {
addCriterion("id is not null");
return (Criteria) this;
}
public Criteria andIdEqualTo(String value) {
addCriterion("id =", value, "id");
return (Criteria) this;
}
public Criteria andIdNotEqualTo(String value) {
addCriterion("id <>", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThan(String value) {
addCriterion("id >", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThanOrEqualTo(String value) {
addCriterion("id >=", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThan(String value) {
addCriterion("id <", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThanOrEqualTo(String value) {
addCriterion("id <=", value, "id");
return (Criteria) this;
}
public Criteria andIdLike(String value) {
addCriterion("id like", value, "id");
return (Criteria) this;
}
public Criteria andIdNotLike(String value) {
addCriterion("id not like", value, "id");
return (Criteria) this;
}
public Criteria andIdIn(List<String> values) {
addCriterion("id in", values, "id");
return (Criteria) this;
}
public Criteria andIdNotIn(List<String> values) {
addCriterion("id not in", values, "id");
return (Criteria) this;
}
public Criteria andIdBetween(String value1, String value2) {
addCriterion("id between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andIdNotBetween(String value1, String value2) {
addCriterion("id not between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andRoleIdIsNull() {
addCriterion("role_id is null");
return (Criteria) this;
}
public Criteria andRoleIdIsNotNull() {
addCriterion("role_id is not null");
return (Criteria) this;
}
public Criteria andRoleIdEqualTo(Integer value) {
addCriterion("role_id =", value, "roleId");
return (Criteria) this;
}
public Criteria andRoleIdNotEqualTo(Integer value) {
addCriterion("role_id <>", value, "roleId");
return (Criteria) this;
}
public Criteria andRoleIdGreaterThan(Integer value) {
addCriterion("role_id >", value, "roleId");
return (Criteria) this;
}
public Criteria andRoleIdGreaterThanOrEqualTo(Integer value) {
addCriterion("role_id >=", value, "roleId");
return (Criteria) this;
}
public Criteria andRoleIdLessThan(Integer value) {
addCriterion("role_id <", value, "roleId");
return (Criteria) this;
}
public Criteria andRoleIdLessThanOrEqualTo(Integer value) {
addCriterion("role_id <=", value, "roleId");
return (Criteria) this;
}
public Criteria andRoleIdIn(List<Integer> values) {
addCriterion("role_id in", values, "roleId");
return (Criteria) this;
}
public Criteria andRoleIdNotIn(List<Integer> values) {
addCriterion("role_id not in", values, "roleId");
return (Criteria) this;
}
public Criteria andRoleIdBetween(Integer value1, Integer value2) {
addCriterion("role_id between", value1, value2, "roleId");
return (Criteria) this;
}
public Criteria andRoleIdNotBetween(Integer value1, Integer value2) {
addCriterion("role_id not between", value1, value2, "roleId");
return (Criteria) this;
}
public Criteria andAuthorityIdIsNull() {
addCriterion("authority_id is null");
return (Criteria) this;
}
public Criteria andAuthorityIdIsNotNull() {
addCriterion("authority_id is not null");
return (Criteria) this;
}
public Criteria andAuthorityIdEqualTo(String value) {
addCriterion("authority_id =", value, "authorityId");
return (Criteria) this;
}
public Criteria andAuthorityIdNotEqualTo(String value) {
addCriterion("authority_id <>", value, "authorityId");
return (Criteria) this;
}
public Criteria andAuthorityIdGreaterThan(String value) {
addCriterion("authority_id >", value, "authorityId");
return (Criteria) this;
}
public Criteria andAuthorityIdGreaterThanOrEqualTo(String value) {
addCriterion("authority_id >=", value, "authorityId");
return (Criteria) this;
}
public Criteria andAuthorityIdLessThan(String value) {
addCriterion("authority_id <", value, "authorityId");
return (Criteria) this;
}
public Criteria andAuthorityIdLessThanOrEqualTo(String value) {
addCriterion("authority_id <=", value, "authorityId");
return (Criteria) this;
}
public Criteria andAuthorityIdLike(String value) {
addCriterion("authority_id like", value, "authorityId");
return (Criteria) this;
}
public Criteria andAuthorityIdNotLike(String value) {
addCriterion("authority_id not like", value, "authorityId");
return (Criteria) this;
}
public Criteria andAuthorityIdIn(List<String> values) {
addCriterion("authority_id in", values, "authorityId");
return (Criteria) this;
}
public Criteria andAuthorityIdNotIn(List<String> values) {
addCriterion("authority_id not in", values, "authorityId");
return (Criteria) this;
}
public Criteria andAuthorityIdBetween(String value1, String value2) {
addCriterion("authority_id between", value1, value2, "authorityId");
return (Criteria) this;
}
public Criteria andAuthorityIdNotBetween(String value1, String value2) {
addCriterion("authority_id not between", value1, value2, "authorityId");
return (Criteria) this;
}
}
/**
* This class was generated by MyBatis Generator.
* This class corresponds to the database table sys_role_authority
*
* @mbg.generated do_not_delete_during_merge Fri Jun 30 00:09:22 CST 2023
*/
public static class Criteria extends GeneratedCriteria {
protected Criteria() {
super();
}
}
/**
* This class was generated by MyBatis Generator.
* This class corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
public static class Criterion {
private String condition;
private Object value;
private Object secondValue;
private boolean noValue;
private boolean singleValue;
private boolean betweenValue;
private boolean listValue;
private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) {
super();
this.condition = condition;
this.typeHandler = null;
this.noValue = true;
}
protected Criterion(String condition, Object value, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.typeHandler = typeHandler;
if (value instanceof List<?>) {
this.listValue = true;
} else {
this.singleValue = true;
}
}
protected Criterion(String condition, Object value) {
this(condition, value, null);
}
protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.secondValue = secondValue;
this.typeHandler = typeHandler;
this.betweenValue = true;
}
protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
}
}

@ -0,0 +1,104 @@
package com.sztzjy.forex.trading_trading.mappers;
import com.sztzjy.forex.trading_trading.entity.RoleAuthority;
import com.sztzjy.forex.trading_trading.entity.RoleAuthorityExample;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
@Mapper
public interface RoleAuthorityMapper {
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
long countByExample(RoleAuthorityExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
int deleteByExample(RoleAuthorityExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
int deleteByPrimaryKey(String id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
int insert(RoleAuthority record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
int insertSelective(RoleAuthority record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
List<RoleAuthority> selectByExample(RoleAuthorityExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
RoleAuthority selectByPrimaryKey(String id);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
int updateByExampleSelective(@Param("record") RoleAuthority record, @Param("example") RoleAuthorityExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
int updateByExample(@Param("record") RoleAuthority record, @Param("example") RoleAuthorityExample example);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
int updateByPrimaryKeySelective(RoleAuthority record);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table sys_role_authority
*
* @mbg.generated Fri Jun 30 00:09:22 CST 2023
*/
int updateByPrimaryKey(RoleAuthority record);
@Select("select authority_id from sys_role_authority where role_id = #{roleId}")
List<String> getAuthorityCode(@Param("roleId") Integer roleId);
}

@ -0,0 +1,22 @@
package com.sztzjy.forex.trading_trading.service;
import com.sztzjy.forex.trading_trading.mappers.RoleAuthorityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class RoleAuthorityService {
@Autowired
RoleAuthorityMapper roleAuthorityMapper;
public List<String> getAuthorityByRoleId(Integer roleId) {
return roleAuthorityMapper.getAuthorityCode(roleId);
}
}

@ -0,0 +1,256 @@
<?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.sztzjy.forex.trading_trading.mappers.RoleAuthorityMapper">
<resultMap id="BaseResultMap" type="com.sztzjy.forex.trading_trading.entity.RoleAuthority">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri Jun 30 00:09:22 CST 2023.
-->
<id column="id" jdbcType="VARCHAR" property="id" />
<result column="role_id" jdbcType="INTEGER" property="roleId" />
<result column="authority_id" jdbcType="VARCHAR" property="authorityId" />
</resultMap>
<sql id="Example_Where_Clause">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri Jun 30 00:09:22 CST 2023.
-->
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri Jun 30 00:09:22 CST 2023.
-->
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri Jun 30 00:09:22 CST 2023.
-->
id, role_id, authority_id
</sql>
<select id="selectByExample" parameterType="com.sztzjy.forex.trading_trading.entity.RoleAuthorityExample" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri Jun 30 00:09:22 CST 2023.
-->
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from sys_role_authority
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri Jun 30 00:09:22 CST 2023.
-->
select
<include refid="Base_Column_List" />
from sys_role_authority
where id = #{id,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri Jun 30 00:09:22 CST 2023.
-->
delete from sys_role_authority
where id = #{id,jdbcType=VARCHAR}
</delete>
<delete id="deleteByExample" parameterType="com.sztzjy.forex.trading_trading.entity.RoleAuthorityExample">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri Jun 30 00:09:22 CST 2023.
-->
delete from sys_role_authority
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.sztzjy.forex.trading_trading.entity.RoleAuthority">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri Jun 30 00:09:22 CST 2023.
-->
insert into sys_role_authority (id, role_id, authority_id
)
values (#{id,jdbcType=VARCHAR}, #{roleId,jdbcType=INTEGER}, #{authorityId,jdbcType=VARCHAR}
)
</insert>
<insert id="insertSelective" parameterType="com.sztzjy.forex.trading_trading.entity.RoleAuthority">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri Jun 30 00:09:22 CST 2023.
-->
insert into sys_role_authority
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="roleId != null">
role_id,
</if>
<if test="authorityId != null">
authority_id,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=VARCHAR},
</if>
<if test="roleId != null">
#{roleId,jdbcType=INTEGER},
</if>
<if test="authorityId != null">
#{authorityId,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.sztzjy.forex.trading_trading.entity.RoleAuthorityExample" resultType="java.lang.Long">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri Jun 30 00:09:22 CST 2023.
-->
select count(*) from sys_role_authority
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri Jun 30 00:09:22 CST 2023.
-->
update sys_role_authority
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=VARCHAR},
</if>
<if test="record.roleId != null">
role_id = #{record.roleId,jdbcType=INTEGER},
</if>
<if test="record.authorityId != null">
authority_id = #{record.authorityId,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri Jun 30 00:09:22 CST 2023.
-->
update sys_role_authority
set id = #{record.id,jdbcType=VARCHAR},
role_id = #{record.roleId,jdbcType=INTEGER},
authority_id = #{record.authorityId,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.sztzjy.forex.trading_trading.entity.RoleAuthority">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri Jun 30 00:09:22 CST 2023.
-->
update sys_role_authority
<set>
<if test="roleId != null">
role_id = #{roleId,jdbcType=INTEGER},
</if>
<if test="authorityId != null">
authority_id = #{authorityId,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="com.sztzjy.forex.trading_trading.entity.RoleAuthority">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri Jun 30 00:09:22 CST 2023.
-->
update sys_role_authority
set role_id = #{roleId,jdbcType=INTEGER},
authority_id = #{authorityId,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>
Loading…
Cancel
Save