@Override public DepartmentModel saveDepartment( DepartmentModel clientDepartment, String parentDepartmentId, String headSchoolDepartmentId, String masterUserIds, String leaderUserIds) { if (StringUtils.isEmpty(clientDepartment.getId())) { if (StringUtils.isNotEmpty(masterUserIds)) { String[] masterIds = masterUserIds.split(";"); for (String id : masterIds) { UserModel user = userDAO.get(id); if (user != null && !clientDepartment.getMasterStaffs().contains(user)) clientDepartment.getMasterStaffs().add(user); } } if (StringUtils.isNotEmpty(leaderUserIds)) { String[] leaderIds = leaderUserIds.split(";"); for (String id : leaderIds) { UserModel user = userDAO.get(id); if (user != null && !clientDepartment.getLeaderStaffs().contains(user)) clientDepartment.getLeaderStaffs().add(user); } } if (StringUtils.isEmpty(parentDepartmentId)) { if (StringUtils.isNotEmpty(headSchoolDepartmentId)) { clientDepartment .getHeadSchoolLeaderDepartments() .add(departmentDAO.get(headSchoolDepartmentId)); } departmentDAO.saveOrUpdate(clientDepartment); return clientDepartment; } else { DepartmentModel parent = departmentDAO.get(parentDepartmentId); if (parent == null) return null; else { // 以下代码 2012.4.5 ysc 解决增加报错问题 departmentDAO.saveOrUpdate(clientDepartment); // 以上代码 2012.4.5 ysc 解决增加报错问题 parent.getChildDepartments().add(clientDepartment); if (StringUtils.isNotEmpty(headSchoolDepartmentId)) { clientDepartment .getHeadSchoolLeaderDepartments() .add(departmentDAO.get(headSchoolDepartmentId)); } departmentDAO.saveOrUpdate(parent); return clientDepartment; } } } else { DepartmentModel dbDepartment = departmentDAO.get(clientDepartment.getId()); dbDepartment.setName(clientDepartment.getName()); dbDepartment.setDetail(clientDepartment.getDetail()); dbDepartment.setLevel(clientDepartment.getLevel()); dbDepartment.setPhone(clientDepartment.getPhone()); dbDepartment.setCreationDate(clientDepartment.getCreationDate()); dbDepartment.setSequence(clientDepartment.getSequence()); dbDepartment.setSchoolId(clientDepartment.getSchoolId()); dbDepartment.setHrFlag(clientDepartment.getHrFlag()); dbDepartment.setLearnManageFlag(clientDepartment.getLearnManageFlag()); dbDepartment.setTechFlag(clientDepartment.getTechFlag()); dbDepartment.setConsultFlag(clientDepartment.getConsultFlag()); dbDepartment.setConsultantFlag(clientDepartment.getConsultantFlag()); if (StringUtils.isNotEmpty(headSchoolDepartmentId)) { dbDepartment.getHeadSchoolLeaderDepartments().clear(); dbDepartment .getHeadSchoolLeaderDepartments() .add(departmentDAO.get(headSchoolDepartmentId)); } dbDepartment.getMasterStaffs().clear(); if (StringUtils.isNotEmpty(masterUserIds)) { String[] masterIds = masterUserIds.split(";"); for (String id : masterIds) { UserModel user = userDAO.get(id); if (user != null && !dbDepartment.getMasterStaffs().contains(user)) dbDepartment.getMasterStaffs().add(user); } } dbDepartment.getLeaderStaffs().clear(); if (StringUtils.isNotEmpty(leaderUserIds)) { String[] leaderIds = leaderUserIds.split(";"); for (String id : leaderIds) { UserModel user = userDAO.get(id); if (user != null && !dbDepartment.getLeaderStaffs().contains(user)) dbDepartment.getLeaderStaffs().add(user); } } departmentDAO.saveOrUpdate(dbDepartment); return dbDepartment; } }
@Override public DepartmentModel getDepartment(String id) throws ServiceException { // TODO Auto-generated method stub return departmentDAO.get(id); }