📄 departmentserviceimpl.java
字号:
package sample.service.impl;
import java.util.List;
import java.util.Set;
import org.hibernate.Criteria;
import org.hibernate.Hibernate;
import org.hibernate.criterion.Restrictions;
import org.springframework.dao.DataAccessException;
import sample.BaseException;
import sample.dao.IBaseDao;
import sample.mappings.department.Department;
import sample.mappings.department.OrganizationType;
import sample.service.BaseServiceImpl;
import sample.service.DepartmentService;
import sample.service.MisUtils;
public class DepartmentServiceImpl extends BaseServiceImpl implements DepartmentService {
private IBaseDao baseDao;
public IBaseDao getBaseDao() {
return baseDao;
}
public void setBaseDao(IBaseDao baseDao) {
this.baseDao = baseDao;
}
public List getAllDepartment() {
return baseDao.loadAll(Department.class);
}
public Department getDepartmentById(String id) {
Department department = (Department)super.getByPk(baseDao,Department.class,id);
return department;
}
public void updateDepartment(Department department)throws BaseException{
try {
super.updateObject(baseDao,department);
} catch (DataAccessException e) {
throw new BaseException("更新失败");
}
}
public void deleteDepartment(Department department)throws BaseException{
try {
super.deleteObject(baseDao,department);
} catch (DataAccessException e) {
throw new BaseException("删除失败");
}
}
public List getTeamFromDepartment(String departmentId) {
return null;
}
public void deleteDepartmentById(String id) throws BaseException {
try {
Department department = (Department)super.getByPk(baseDao,Department.class,id);
super.deleteObject(baseDao,department);
} catch (DataAccessException e) {
throw new BaseException();
}
}
public void createDepartment(Department dept) throws BaseException {
String orgId = dept.getOrganizationTypeId();
try{
if(MisUtils.validateString(orgId)){
OrganizationType org = (OrganizationType)baseDao.getByPk(OrganizationType.class,orgId);
org.getDepartments().add(dept);
dept.setOrganizationType(org);
baseDao.create(dept);
}else{
baseDao.create(dept);
}
}catch(DataAccessException a){
throw new BaseException("创建部门错误");
}
}
public void createOrganizationrType(OrganizationType org) throws BaseException {
try{
baseDao.create(org);
}catch(DataAccessException e){
throw new BaseException();
}
}
public void deleteOrganizationrType(OrganizationType org) throws BaseException {
try{
baseDao.delete(org);
}catch(DataAccessException e){
throw new BaseException();
}
}
public void updateOrganizationrType(OrganizationType org) throws BaseException {
try{
baseDao.update(org);
}catch(DataAccessException e){
throw new BaseException();
}
}
public OrganizationType getOrganizationTypeById(String id) {
return (OrganizationType)baseDao.getByPk(OrganizationType.class,id);
}
public List getAllOrganizationType() {
return baseDao.loadAll(OrganizationType.class);
}
public Department getDepartmentByName(String name) {
return (Department)baseDao.loadByKey(Department.class,"name",name);
}
public OrganizationType getOrganizationTypeByName(String name) {
return (OrganizationType)baseDao.loadByKey(OrganizationType.class,"name",name);
}
public List getDepartmentsByOrgTypeId(String id) {
Criteria criteria = super.getCriteria(baseDao,Department.class);
criteria.createCriteria("organizationType").add(Restrictions.eq("id",id));
return criteria.list();
}
public List getDepartmentsByOrgType(OrganizationType org) {
Criteria criteria = super.getCriteria(baseDao,Department.class);
criteria.add(Restrictions.eq("organizationtype_id",org.getId()));
return criteria.list();
}
public Set getDepartmentByParentDepartmentId(String id) {
Department dept =(Department) super.getByPk(baseDao,Department.class,id);
Hibernate.initialize(dept.getDepartments());
return dept.getDepartments();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -