示例#1
0
 @Override
 @Transactional(readOnly = false)
 public void connectUserRole(String userId, String roleId) {
   UserRole record = new UserRole();
   record.setId(new Date().getTime() + "");
   record.setUserId(userId);
   record.setTbRoleId(roleId);
   userRoleMapper.insert(record);
 }
示例#2
0
 @Override
 @Transactional(readOnly = false)
 public void updateUserRole(String userId, String oldRoleId, String newRoleId) {
   UserRoleCriteria userRoleCriteria = new UserRoleCriteria();
   userRoleCriteria.createCriteria().andUserIdEqualTo(userId).andTbRoleIdEqualTo(oldRoleId);
   List<UserRole> userRoles = userRoleMapper.selectByExample(userRoleCriteria);
   if (null != userRoles && userRoles.size() > 0) { // 更新
     UserRole userRole = userRoles.get(0);
     if (null != newRoleId) {
       userRole.setTbRoleId(newRoleId);
       userRoleMapper.updateByPrimaryKey(userRole);
     } else {
       userRoleMapper.deleteByPrimaryKey(userRole.getId());
     }
   } else { // 新增
     if ((null == oldRoleId || "".equals(oldRoleId)) && null != newRoleId) {
       UserRole userRole = new UserRole();
       userRole.setId(new Date().getTime() + "");
       userRole.setUserId(userId);
       userRole.setTbRoleId(newRoleId);
       userRoleMapper.insert(userRole);
     }
   }
 }