Commit bef7fc52 by Suvalue

分配角色相关修改

parent ce8b3652
...@@ -20,5 +20,5 @@ public interface SysUserRoleRsMapper { ...@@ -20,5 +20,5 @@ public interface SysUserRoleRsMapper {
int deleteByUser(@Param("userId") Long userId); 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,7 +29,7 @@ public class SysRoleServiceImpl implements SysRoleService { ...@@ -29,7 +29,7 @@ public class SysRoleServiceImpl implements SysRoleService {
@Override @Override
public boolean addRole(Long userId, RoleReq.AddRoleReq role) { public boolean addRole(Long userId, RoleReq.AddRoleReq role) {
if(role!=null){ if (role != null) {
SysRole sysRole = new SysRole(); SysRole sysRole = new SysRole();
sysRole.setCreateDate(new Date()); sysRole.setCreateDate(new Date());
sysRole.setCreateUserid(userId); sysRole.setCreateUserid(userId);
...@@ -44,9 +44,9 @@ public class SysRoleServiceImpl implements SysRoleService { ...@@ -44,9 +44,9 @@ public class SysRoleServiceImpl implements SysRoleService {
@Override @Override
public boolean deleteRole(RoleReq.DeleteRoleReq role) { public boolean deleteRole(RoleReq.DeleteRoleReq role) {
if(role!=null){ if (role != null) {
SysRole sysRole = sysRoleMapper.selectByPrimaryKey(role.getRoleId()); SysRole sysRole = sysRoleMapper.selectByPrimaryKey(role.getRoleId());
if(sysRole!=null){ if (sysRole != null) {
sysRole.setState((short) StateType.OFF.getValue()); sysRole.setState((short) StateType.OFF.getValue());
sysRoleMapper.updateByPrimaryKey(sysRole); sysRoleMapper.updateByPrimaryKey(sysRole);
return true; return true;
...@@ -57,9 +57,9 @@ public class SysRoleServiceImpl implements SysRoleService { ...@@ -57,9 +57,9 @@ public class SysRoleServiceImpl implements SysRoleService {
@Override @Override
public boolean updateRole(RoleReq.UpdateRoleReq role) { public boolean updateRole(RoleReq.UpdateRoleReq role) {
if(role!=null) { if (role != null) {
SysRole sysRole = sysRoleMapper.selectByPrimaryKey(role.getRoleId()); SysRole sysRole = sysRoleMapper.selectByPrimaryKey(role.getRoleId());
if(sysRole!=null){ if (sysRole != null) {
sysRole.setRoleCode(role.getRoleCode()); sysRole.setRoleCode(role.getRoleCode());
sysRole.setRoleName(role.getRoleName()); sysRole.setRoleName(role.getRoleName());
sysRoleMapper.updateByPrimaryKey(sysRole); sysRoleMapper.updateByPrimaryKey(sysRole);
...@@ -72,9 +72,9 @@ public class SysRoleServiceImpl implements SysRoleService { ...@@ -72,9 +72,9 @@ public class SysRoleServiceImpl implements SysRoleService {
@Override @Override
public List<SysRole> getAll(RoleReq.GetRoleReq role) { public List<SysRole> getAll(RoleReq.GetRoleReq role) {
List<SysRole> list = sysRoleMapper.selectAll(); List<SysRole> list = sysRoleMapper.selectAll();
if(role.getRoleName()!=null){ if (role.getRoleName() != null) {
list = list.stream().filter( 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()); .collect(Collectors.toList());
} }
return list; return list;
...@@ -88,23 +88,25 @@ public class SysRoleServiceImpl implements SysRoleService { ...@@ -88,23 +88,25 @@ public class SysRoleServiceImpl implements SysRoleService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public boolean saveUserRole(Long userId,RoleReq.SavaUserRoleReq role){ public boolean saveUserRole(Long userId, RoleReq.SavaUserRoleReq role) {
int result=0; int result = 0;
if(role!=null&&role.getRoleId()!=null&&role.getUserId()!=null){ if (role != null && role.getRoleId() != null && role.getUserId() != null) {
SysUserRoleRs info = sysUserRoleRsMapper.selectByUser(role.getUserId()); //先删除用户关联数据
if(info!=null){ sysUserRoleRsMapper.deleteByUser(role.getUserId());
info.setState((short)StateType.ON.getValue()); SysUserRoleRs info = sysUserRoleRsMapper.selectByUser(role.getUserId(), role.getRoleId());
if (info != null) {
info.setState((short) StateType.ON.getValue());
result = sysUserRoleRsMapper.updateByPrimaryKey(info); result = sysUserRoleRsMapper.updateByPrimaryKey(info);
}else{ } else {
info = new SysUserRoleRs(); info = new SysUserRoleRs();
info.setCreateDate(new Date()); info.setCreateDate(new Date());
info.setCreateUserid(userId); info.setCreateUserid(userId);
info.setState((short)StateType.ON.getValue()); info.setState((short) StateType.ON.getValue());
info.setUserId(role.getUserId()); info.setUserId(role.getUserId());
info.setRoleId(role.getRoleId()); info.setRoleId(role.getRoleId());
result=sysUserRoleRsMapper.insert(info); result = sysUserRoleRsMapper.insert(info);
} }
} }
return result>0; return result > 0;
} }
} }
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
<select id="selectByUser" resultMap="BaseResultMap"> <select id="selectByUser" resultMap="BaseResultMap">
select ID, CREATE_DATE, CREATE_USERID, "STATE", USER_ID, ROLE_ID select ID, CREATE_DATE, CREATE_USERID, "STATE", USER_ID, ROLE_ID
from SYS_USER_ROLE_RS 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> </select>
</mapper> </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