Search in sources :

Example 1 with UserRole

use of com.github.liuweijw.business.admin.domain.UserRole in project fw-cloud-framework by liuweijw.

the class UserServiceImpl method updateUserAndRole.

@Override
@Transactional
public boolean updateUserAndRole(UserForm userForm) {
    if (null == userForm.getUserId() || userForm.getUserId() <= 0)
        return Boolean.FALSE;
    User user = userRepository.findUserByUserId(userForm.getUserId());
    if (null == user)
        return false;
    user.setStatu(userForm.getStatu());
    user.setUpdateTime(new Date());
    user.setUserId(userForm.getUserId());
    user.setUsername(userForm.getUsername());
    userRepository.save(user);
    QUserRole qUserRole = QUserRole.userRole;
    this.queryFactory.delete(qUserRole).where(qUserRole.userId.eq(userForm.getUserId())).execute();
    UserRole uRole = new UserRole();
    uRole.setRoleId(userForm.getRoleId());
    uRole.setUserId(userForm.getUserId());
    this.userRoleRepository.saveAndFlush(uRole);
    return true;
}
Also used : User(com.github.liuweijw.business.admin.domain.User) QUser(com.github.liuweijw.business.admin.domain.QUser) AuthUser(com.github.liuweijw.core.beans.system.AuthUser) QUserRole(com.github.liuweijw.business.admin.domain.QUserRole) UserRole(com.github.liuweijw.business.admin.domain.UserRole) QUserRole(com.github.liuweijw.business.admin.domain.QUserRole) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with UserRole

use of com.github.liuweijw.business.admin.domain.UserRole in project fw-cloud-framework by liuweijw.

the class UserServiceImpl method addUserAndRole.

@Override
@Transactional
public boolean addUserAndRole(User user, Integer roleId) {
    User dbUser = this.userRepository.saveAndFlush(user);
    UserRole uRole = new UserRole();
    uRole.setRoleId(roleId);
    uRole.setUserId(dbUser.getUserId());
    this.userRoleRepository.saveAndFlush(uRole);
    return true;
}
Also used : User(com.github.liuweijw.business.admin.domain.User) QUser(com.github.liuweijw.business.admin.domain.QUser) AuthUser(com.github.liuweijw.core.beans.system.AuthUser) QUserRole(com.github.liuweijw.business.admin.domain.QUserRole) UserRole(com.github.liuweijw.business.admin.domain.UserRole) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with UserRole

use of com.github.liuweijw.business.admin.domain.UserRole in project fw-cloud-framework by liuweijw.

the class UserServiceImpl method updateUserAndRoleDept.

@Override
@Transactional
@CacheEvict(allEntries = true)
public boolean updateUserAndRoleDept(UserForm userForm) {
    if (null == userForm.getUserId() || userForm.getUserId() <= 0)
        return Boolean.FALSE;
    User user = userRepository.findUserByUserId(userForm.getUserId());
    if (null == user)
        return false;
    user.setStatu(userForm.getStatu());
    user.setUpdateTime(new Date());
    user.setUserId(userForm.getUserId());
    user.setDeptId(userForm.getDeptId());
    user.setUsername(userForm.getUsername());
    user.setMobile(userForm.getMobile());
    userRepository.save(user);
    QUserRole qUserRole = QUserRole.userRole;
    this.queryFactory.delete(qUserRole).where(qUserRole.userId.eq(userForm.getUserId())).execute();
    UserRole uRole = new UserRole();
    uRole.setRoleId(userForm.getRoleId());
    uRole.setUserId(userForm.getUserId());
    this.userRoleRepository.saveAndFlush(uRole);
    return true;
}
Also used : User(com.github.liuweijw.business.admin.domain.User) AuthUser(com.github.liuweijw.system.api.model.AuthUser) QUser(com.github.liuweijw.business.admin.domain.QUser) QUserRole(com.github.liuweijw.business.admin.domain.QUserRole) UserRole(com.github.liuweijw.business.admin.domain.UserRole) QUserRole(com.github.liuweijw.business.admin.domain.QUserRole) Date(java.util.Date) CacheEvict(org.springframework.cache.annotation.CacheEvict) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with UserRole

use of com.github.liuweijw.business.admin.domain.UserRole in project fw-cloud-framework by liuweijw.

the class UserServiceImpl method addUserAndRoleDept.

@Override
@Transactional
@CacheEvict(allEntries = true)
public boolean addUserAndRoleDept(UserForm userForm) {
    User user = new User();
    user.setCreateTime(new Date());
    user.setStatu(0);
    user.setDeptId(userForm.getDeptId());
    user.setPassword(new BCryptPasswordEncoder().encode(userForm.getPassword().trim()));
    user.setUpdateTime(new Date());
    user.setUsername(userForm.getUsername().trim());
    user.setMobile(userForm.getMobile());
    User dbUser = this.userRepository.saveAndFlush(user);
    UserRole uRole = new UserRole();
    uRole.setRoleId(userForm.getRoleId());
    uRole.setUserId(dbUser.getUserId());
    this.userRoleRepository.saveAndFlush(uRole);
    return true;
}
Also used : User(com.github.liuweijw.business.admin.domain.User) AuthUser(com.github.liuweijw.system.api.model.AuthUser) QUser(com.github.liuweijw.business.admin.domain.QUser) QUserRole(com.github.liuweijw.business.admin.domain.QUserRole) UserRole(com.github.liuweijw.business.admin.domain.UserRole) Date(java.util.Date) BCryptPasswordEncoder(org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder) CacheEvict(org.springframework.cache.annotation.CacheEvict) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

QUser (com.github.liuweijw.business.admin.domain.QUser)4 QUserRole (com.github.liuweijw.business.admin.domain.QUserRole)4 User (com.github.liuweijw.business.admin.domain.User)4 UserRole (com.github.liuweijw.business.admin.domain.UserRole)4 Transactional (org.springframework.transaction.annotation.Transactional)4 Date (java.util.Date)3 AuthUser (com.github.liuweijw.core.beans.system.AuthUser)2 AuthUser (com.github.liuweijw.system.api.model.AuthUser)2 CacheEvict (org.springframework.cache.annotation.CacheEvict)2 BCryptPasswordEncoder (org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder)1