Commit bef7fc52 by Suvalue

分配角色相关修改

parent ce8b3652
......@@ -20,5 +20,5 @@ public interface SysUserRoleRsMapper {
int deleteByUser(@Param("userId") Long userId);
SysUserRoleRs selectByUser(@Param("userId") Long userId);
SysUserRoleRs selectByUser(@Param("userId") Long userId,@Param("roleId") Long roleId);
}
\ No newline at end of file
......@@ -29,8 +29,8 @@ public class SysRoleServiceImpl implements SysRoleService {
@Override
public boolean addRole(Long userId, RoleReq.AddRoleReq role) {
if(role!=null){
SysRole sysRole = new SysRole();
if (role != null) {
SysRole sysRole = new SysRole();
sysRole.setCreateDate(new Date());
sysRole.setCreateUserid(userId);
sysRole.setState((short) StateType.ON.getValue());
......@@ -44,9 +44,9 @@ public class SysRoleServiceImpl implements SysRoleService {
@Override
public boolean deleteRole(RoleReq.DeleteRoleReq role) {
if(role!=null){
if (role != null) {
SysRole sysRole = sysRoleMapper.selectByPrimaryKey(role.getRoleId());
if(sysRole!=null){
if (sysRole != null) {
sysRole.setState((short) StateType.OFF.getValue());
sysRoleMapper.updateByPrimaryKey(sysRole);
return true;
......@@ -57,9 +57,9 @@ public class SysRoleServiceImpl implements SysRoleService {
@Override
public boolean updateRole(RoleReq.UpdateRoleReq role) {
if(role!=null) {
if (role != null) {
SysRole sysRole = sysRoleMapper.selectByPrimaryKey(role.getRoleId());
if(sysRole!=null){
if (sysRole != null) {
sysRole.setRoleCode(role.getRoleCode());
sysRole.setRoleName(role.getRoleName());
sysRoleMapper.updateByPrimaryKey(sysRole);
......@@ -72,9 +72,9 @@ public class SysRoleServiceImpl implements SysRoleService {
@Override
public List<SysRole> getAll(RoleReq.GetRoleReq role) {
List<SysRole> list = sysRoleMapper.selectAll();
if(role.getRoleName()!=null){
if (role.getRoleName() != null) {
list = list.stream().filter(
o->(o.getRoleName()!=null && o.getRoleName().toLowerCase().contains(role.getRoleName().toLowerCase())))
o -> (o.getRoleName() != null && o.getRoleName().toLowerCase().contains(role.getRoleName().toLowerCase())))
.collect(Collectors.toList());
}
return list;
......@@ -88,23 +88,25 @@ public class SysRoleServiceImpl implements SysRoleService {
@Override
@Transactional(rollbackFor = Exception.class)
public boolean saveUserRole(Long userId,RoleReq.SavaUserRoleReq role){
int result=0;
if(role!=null&&role.getRoleId()!=null&&role.getUserId()!=null){
SysUserRoleRs info = sysUserRoleRsMapper.selectByUser(role.getUserId());
if(info!=null){
info.setState((short)StateType.ON.getValue());
public boolean saveUserRole(Long userId, RoleReq.SavaUserRoleReq role) {
int result = 0;
if (role != null && role.getRoleId() != null && role.getUserId() != null) {
//先删除用户关联数据
sysUserRoleRsMapper.deleteByUser(role.getUserId());
SysUserRoleRs info = sysUserRoleRsMapper.selectByUser(role.getUserId(), role.getRoleId());
if (info != null) {
info.setState((short) StateType.ON.getValue());
result = sysUserRoleRsMapper.updateByPrimaryKey(info);
}else{
} else {
info = new SysUserRoleRs();
info.setCreateDate(new Date());
info.setCreateUserid(userId);
info.setState((short)StateType.ON.getValue());
info.setState((short) StateType.ON.getValue());
info.setUserId(role.getUserId());
info.setRoleId(role.getRoleId());
result=sysUserRoleRsMapper.insert(info);
result = sysUserRoleRsMapper.insert(info);
}
}
return result>0;
return result > 0;
}
}
......@@ -49,6 +49,7 @@
<select id="selectByUser" resultMap="BaseResultMap">
select ID, CREATE_DATE, CREATE_USERID, "STATE", USER_ID, ROLE_ID
from SYS_USER_ROLE_RS
where "STATE"=1 and USER_ID = #{userId,jdbcType=DECIMAL}
where USER_ID = #{userId,jdbcType=DECIMAL}
and ROLE_ID = #{roleId,jdbcType=DECIMAL}
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment