fix:用户注册绑定角色权限

dev
wangxy 1 year ago
parent 5337945ac4
commit f7acbe966e

@ -0,0 +1,13 @@
package com.hyp.web.controller.apply;
/**
* packageName com.hyp.web.controller.apply
*
* @author wangxy
* @version JDK 8
* @className TestController
* @date 2024/4/10
* @description TODO
*/
public class TestController {
}

@ -131,4 +131,4 @@ xss:
# 排除链接(多个用逗号分隔)
excludes: /system/notice
# 匹配链接
urlPatterns: /system/*,/monitor/*,/tool/*
urlPatterns: /system/*,/monitor/*,/tool/*,/apply/*

@ -27,6 +27,11 @@ public class LoginBody
*/
private String uuid;
/**
* key
*/
private String roleKey;
public String getUsername()
{
return username;
@ -66,4 +71,12 @@ public class LoginBody
{
this.uuid = uuid;
}
public String getRoleKey() {
return roleKey;
}
public void setRoleKey(String roleKey) {
this.roleKey = roleKey;
}
}

@ -1,5 +1,9 @@
package com.hyp.framework.web.service;
import com.hyp.common.core.domain.entity.SysRole;
import com.hyp.system.domain.SysUserRole;
import com.hyp.system.mapper.SysUserRoleMapper;
import com.hyp.system.service.ISysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.hyp.common.constant.CacheConstants;
@ -18,6 +22,10 @@ import com.hyp.framework.manager.factory.AsyncFactory;
import com.hyp.system.service.ISysConfigService;
import com.hyp.system.service.ISysUserService;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
*
*
@ -35,6 +43,13 @@ public class SysRegisterService
@Autowired
private RedisCache redisCache;
@Autowired
private SysUserRoleMapper userRoleMapper;
@Autowired
private ISysRoleService roleService;
/**
*
*/
@ -78,6 +93,8 @@ public class SysRegisterService
sysUser.setNickName(username);
sysUser.setPassword(SecurityUtils.encryptPassword(password));
boolean regFlag = userService.registerUser(sysUser);
//注册绑定角色
roleBinding(sysUser,"yxxxj_xxl");
if (!regFlag)
{
msg = "注册失败,请联系系统管理人员";
@ -90,6 +107,28 @@ public class SysRegisterService
return msg;
}
/**
*
*
* @param sysUser
* @param roleKey
* @return void
*/
public void roleBinding(SysUser sysUser,String roleKey) {
//注册绑定角色
userRoleMapper.deleteUserRoleByUserId(sysUser.getUserId());
List<SysUserRole> list = new ArrayList<>();
SysUserRole ur = new SysUserRole();
ur.setUserId(sysUser.getUserId());
SysRole sysRole = roleService.selectRoleByKey(roleKey);
if(Objects.nonNull(sysRole)){
ur.setRoleId(sysRole.getRoleId());
}
list.add(ur);
userRoleMapper.batchUserRole(list);
}
/**
*
*

@ -104,4 +104,12 @@ public interface SysRoleMapper
* @return
*/
public int deleteRoleByIds(Long[] roleIds);
/**
* key
*
* @param roleKey Key
* @return
*/
public SysRole selectRoleByKey(String roleKey);
}

@ -170,4 +170,13 @@ public interface ISysRoleService
* @return
*/
public int insertAuthUsers(Long roleId, Long[] userIds);
/**
* key
*
* @param roleKey Key
* @return
*/
public SysRole selectRoleByKey(String roleKey);
}

@ -421,4 +421,17 @@ public class SysRoleServiceImpl implements ISysRoleService
}
return userRoleMapper.batchUserRole(list);
}
/**
* ID
*
* @param roleKey KEY
* @return
*/
@Override
public SysRole selectRoleByKey(String roleKey)
{
return roleMapper.selectRoleByKey(roleKey);
}
}

@ -92,8 +92,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectRoleVo"/>
where r.role_key=#{roleKey} and r.del_flag = '0' limit 1
</select>
<insert id="insertRole" parameterType="SysRole" useGeneratedKeys="true" keyProperty="roleId">
<insert id="insertRole" parameterType="SysRole" useGeneratedKeys="true" keyProperty="roleId">
insert into sys_role(
<if test="roleId != null and roleId != 0">role_id,</if>
<if test="roleName != null and roleName != ''">role_name,</if>
@ -148,5 +149,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{roleId}
</foreach>
</delete>
<select id="selectRoleByKey" parameterType="String" resultType="com.hyp.common.core.domain.entity.SysRole">
<include refid="selectRoleVo"/>
where r.role_key = #{roleKey}
</select>
</mapper>
Loading…
Cancel
Save