Search in sources :

Example 11 with Department

use of org.mx.comps.rbac.dal.entity.Department in project main by JohnPeng739.

the class TestDepartment method testEditDepartment.

public static void testEditDepartment(GeneralDictAccessor service, DepartmentManageService departService) {
    DepartmentManageService.DepartInfo departInfo = DepartmentManageService.DepartInfo.valueOf("depart3", "depart3", "description");
    Department depart3 = departService.saveDepartment(departInfo);
    assertEquals(3, service.count(Department.class));
    assertNotNull(depart3);
    assertNotNull(depart3.getId());
    depart3Id = depart3.getId();
    departInfo = DepartmentManageService.DepartInfo.valueOf("depart3", "new name", "description", depart3.getId(), "", Arrays.asList(), false);
    depart3 = departService.saveDepartment(departInfo);
    assertEquals(2, service.count(Department.class));
    assertEquals(3, service.count(Department.class, false));
    assertNotNull(depart3);
    depart3 = service.getById(depart3Id, Department.class);
    assertNotNull(depart3);
    assertEquals("new name", depart3.getName());
    assertFalse(depart3.isValid());
    departInfo = DepartmentManageService.DepartInfo.valueOf("depart3", "depart3", "description", depart3.getId(), "", Arrays.asList(), true);
    departService.saveDepartment(departInfo);
    assertEquals(3, service.count(Department.class));
    assertEquals(3, service.count(Department.class, false));
}
Also used : Department(org.mx.comps.rbac.dal.entity.Department) DepartmentManageService(org.mx.comps.rbac.service.DepartmentManageService)

Example 12 with Department

use of org.mx.comps.rbac.dal.entity.Department in project main by JohnPeng739.

the class DepartmentManageServiceCommonImpl method saveDepartment.

/**
 * {@inheritDoc}
 *
 * @see DepartmentManageService#saveDepartment(DepartInfo)
 */
@Override
public Department saveDepartment(DepartInfo departInfo) {
    if (departInfo == null) {
        throw new UserInterfaceSystemErrorException(UserInterfaceSystemErrorException.SystemErrors.SYSTEM_ILLEGAL_PARAM);
    }
    String id = departInfo.getId();
    Department department;
    if (!StringUtils.isBlank(id)) {
        department = accessor.getById(id, Department.class);
        if (department == null) {
            throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.DEPARTMENT_NOT_FOUND);
        }
    } else {
        department = EntityFactory.createEntity(Department.class);
    }
    department.setCode(departInfo.getCode());
    department.setName(departInfo.getName());
    department.setDesc(departInfo.getDesc());
    if (StringUtils.isBlank(departInfo.getManagerId())) {
        department.setManager(null);
    } else {
        User manager = accessor.getById(departInfo.getManagerId(), User.class);
        if (manager == null) {
            throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.USER_NOT_FOUND);
        }
        department.setManager(manager);
    }
    if (department.getEmployees() != null && !department.getEmployees().isEmpty()) {
        department.getEmployees().clear();
    }
    if (departInfo.getEmployeeIds() != null) {
        for (String employeeId : departInfo.getEmployeeIds()) {
            User employee = accessor.getById(employeeId, User.class);
            if (employee == null) {
                throw new UserInterfaceRbacErrorException(UserInterfaceRbacErrorException.RbacErrors.USER_NOT_FOUND);
            }
            department.getEmployees().add(employee);
        }
    }
    department.setValid(departInfo.isValid());
    department = this.save(department);
    if (operateLogService != null) {
        operateLogService.writeLog(String.format("保存部门[code=%s, name=%s]信息成功。", departInfo.getCode(), departInfo.getName()));
    }
    return department;
}
Also used : Department(org.mx.comps.rbac.dal.entity.Department) UserInterfaceRbacErrorException(org.mx.comps.rbac.error.UserInterfaceRbacErrorException) User(org.mx.comps.rbac.dal.entity.User) UserInterfaceSystemErrorException(org.mx.error.UserInterfaceSystemErrorException)

Example 13 with Department

use of org.mx.comps.rbac.dal.entity.Department in project main by JohnPeng739.

the class DepartmentVO method transform.

public static List<DepartmentVO> transform(Collection<Department> departments) {
    List<DepartmentVO> departmentVOS = new ArrayList<>();
    if (departments != null && !departments.isEmpty()) {
        for (Department department : departments) {
            DepartmentVO departmentVO = DepartmentVO.transform(department, false);
            departmentVOS.add(departmentVO);
        }
    }
    return departmentVOS;
}
Also used : Department(org.mx.comps.rbac.dal.entity.Department)

Aggregations

Department (org.mx.comps.rbac.dal.entity.Department)13 UserInterfaceSystemErrorException (org.mx.error.UserInterfaceSystemErrorException)6 User (org.mx.comps.rbac.dal.entity.User)4 DepartmentVO (org.mx.comps.rbac.rest.vo.DepartmentVO)4 DepartmentManageService (org.mx.comps.rbac.service.DepartmentManageService)4 UserInterfaceException (org.mx.error.UserInterfaceException)4 PaginationDataVO (org.mx.service.rest.vo.PaginationDataVO)4 AuthenticateAround (org.mx.comps.jwt.AuthenticateAround)3 UserInterfaceRbacErrorException (org.mx.comps.rbac.error.UserInterfaceRbacErrorException)3 DataVO (org.mx.service.rest.vo.DataVO)3 Test (org.junit.Test)2 UserManageService (org.mx.comps.rbac.service.UserManageService)2 GeneralDictAccessor (org.mx.dal.service.GeneralDictAccessor)2 ParseException (java.text.ParseException)1 Date (java.util.Date)1 Pagination (org.mx.dal.Pagination)1