com.quhaodian.user.data.dao.impl.UserInfoDaoImpl Maven / Gradle / Ivy
package com.quhaodian.user.data.dao.impl;
import com.quhaodian.data.core.CriteriaDaoImpl;
import com.quhaodian.user.data.dao.UserInfoDao;
import com.quhaodian.user.data.dao.UserRoleDao;
import com.quhaodian.user.data.entity.UserInfo;
import com.quhaodian.user.data.entity.UserRole;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
/**
* Created by imake on 2017年07月20日16:35:48.
*/
@Repository
public class UserInfoDaoImpl extends CriteriaDaoImpl implements UserInfoDao {
@Autowired
UserRoleDao roleDao;
@Override
public UserInfo findById(Long id) {
if (id == null) {
return null;
}
return get(id);
}
@Override
public UserInfo save(UserInfo bean) {
getSession().save(bean);
return bean;
}
@Override
public UserInfo deleteById(Long id) {
UserInfo entity = super.get(id);
if (entity != null) {
getSession().delete(entity);
}
return entity;
}
@Override
public UserInfo addRole(Long id, Long roleid) {
UserInfo entity = findById(id);
if (entity != null) {
UserRole role = roleDao.findById(roleid);
if (role != null) {
entity.getRoles().add(role);
}
}
return entity;
}
@Override
public UserInfo addRoles(Long id, Long... role) {
UserInfo entity = findById(id);
if (entity != null) {
for (Long item : role) {
UserRole temp = roleDao.findById(item);
if (role != null) {
entity.getRoles().add(temp);
}
}
}
return entity;
}
@Override
public UserInfo addRole(Long id, String roleName) {
UserInfo entity = findById(id);
if (entity != null) {
UserRole temp = roleDao.findByName(roleName);
if (temp != null) {
entity.getRoles().add(temp);
}
}
return entity;
}
@Override
protected Class getEntityClass() {
return UserInfo.class;
}
@Autowired
public void setSuperSessionFactory(SessionFactory sessionFactory) {
super.setSessionFactory(sessionFactory);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy