Search in sources :

Example 1 with DeptDto

use of com.albedo.java.modules.sys.domain.dto.DeptDto in project albedo by somowhere.

the class DeptDoResourceIntTest method updateDept.

@Test
@Transactional(rollbackFor = Exception.class)
public void updateDept() throws Exception {
    // Initialize the database
    deptService.saveOrUpdate(dept);
    int databaseSizeBeforeUpdate = deptService.list().size();
    // Update the dept
    DeptDo updatedDeptDo = deptService.getById(dept.getId());
    DeptDto managedDeptVM = new DeptDto();
    managedDeptVM.setName(UPDATED_NAME);
    managedDeptVM.setSort(UPDATED_SORT);
    managedDeptVM.setParentId(UPDATED_PARENT_ID);
    managedDeptVM.setDescription(UPDATED_DESCRIPTION);
    managedDeptVM.setId(updatedDeptDo.getId());
    restDeptMockMvc.perform(post(DEFAULT_API_URL).contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(managedDeptVM))).andExpect(status().isOk()).andExpect(jsonPath("$.code").value(CommonConstants.SUCCESS));
    // Validate the Dept in the database
    List<DeptDo> deptDoList = deptService.list();
    assertThat(deptDoList).hasSize(databaseSizeBeforeUpdate);
    DeptDo testDeptDo = deptService.getById(updatedDeptDo.getId());
    assertThat(testDeptDo.getName()).isEqualTo(UPDATED_NAME);
    assertThat(testDeptDo.getSort()).isEqualTo(UPDATED_SORT);
    assertThat(testDeptDo.getParentId()).isEqualTo(UPDATED_PARENT_ID);
    // assertThat(testDept.getParentIds()).contains(UPDATED_PARENT_ID);
    assertThat(testDeptDo.isLeaf()).isEqualTo(true);
    assertThat(testDeptDo.getDescription()).isEqualTo(UPDATED_DESCRIPTION);
    assertThat(testDeptDo.getDelFlag()).isEqualTo(DeptDo.FLAG_NORMAL);
}
Also used : DeptDto(com.albedo.java.modules.sys.domain.dto.DeptDto) DeptDo(com.albedo.java.modules.sys.domain.DeptDo) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with DeptDto

use of com.albedo.java.modules.sys.domain.dto.DeptDto in project albedo by somowhere.

the class DeptRelationServiceImpl method saveDeptRelation.

/**
 * 维护部门关系
 *
 * @param deptDto 部门
 */
@Override
@Transactional(rollbackFor = Exception.class)
public void saveDeptRelation(DeptDto deptDto) {
    // 增加部门关系表
    DeptRelationDo condition = new DeptRelationDo();
    condition.setDescendant(deptDto.getParentId());
    List<DeptRelationDo> relationList = deptRelationRepository.selectList(Wrappers.<DeptRelationDo>query().lambda().eq(DeptRelationDo::getDescendant, deptDto.getParentId())).stream().map(relation -> {
        relation.setDescendant(deptDto.getId());
        return relation;
    }).collect(Collectors.toList());
    if (CollUtil.isNotEmpty(relationList)) {
        this.saveBatch(relationList);
    }
    // 自己也要维护到关系表中
    DeptRelationDo own = new DeptRelationDo();
    own.setDescendant(deptDto.getId());
    own.setAncestor(deptDto.getId());
    deptRelationRepository.insert(own);
}
Also used : Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) DeptRelationRepository(com.albedo.java.modules.sys.repository.DeptRelationRepository) List(java.util.List) DeptRelationDo(com.albedo.java.modules.sys.domain.DeptRelationDo) CollUtil(com.albedo.java.common.core.util.CollUtil) Service(org.springframework.stereotype.Service) AllArgsConstructor(lombok.AllArgsConstructor) BaseServiceImpl(com.albedo.java.plugins.database.mybatis.service.impl.BaseServiceImpl) Collectors(java.util.stream.Collectors) DeptDto(com.albedo.java.modules.sys.domain.dto.DeptDto) DeptRelationService(com.albedo.java.modules.sys.service.DeptRelationService) Transactional(org.springframework.transaction.annotation.Transactional) DeptRelationDo(com.albedo.java.modules.sys.domain.DeptRelationDo) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with DeptDto

use of com.albedo.java.modules.sys.domain.dto.DeptDto in project albedo by somowhere.

the class DeptDoResourceIntTest method createEntity.

/**
 * Create a Dept.
 * <p>
 * This is a static method, as tests for other entities might also need it, if they
 * test an domain which has a required relationship to the Dept domain.
 */
public DeptDto createEntity() {
    DeptDto dept = new DeptDto();
    dept.setName(DEFAULT_NAME);
    dept.setSort(DEFAULT_SORT);
    dept.setDescription(DEFAULT_DESCRIPTION);
    return dept;
}
Also used : DeptDto(com.albedo.java.modules.sys.domain.dto.DeptDto)

Aggregations

DeptDto (com.albedo.java.modules.sys.domain.dto.DeptDto)3 Transactional (org.springframework.transaction.annotation.Transactional)2 CollUtil (com.albedo.java.common.core.util.CollUtil)1 DeptDo (com.albedo.java.modules.sys.domain.DeptDo)1 DeptRelationDo (com.albedo.java.modules.sys.domain.DeptRelationDo)1 DeptRelationRepository (com.albedo.java.modules.sys.repository.DeptRelationRepository)1 DeptRelationService (com.albedo.java.modules.sys.service.DeptRelationService)1 BaseServiceImpl (com.albedo.java.plugins.database.mybatis.service.impl.BaseServiceImpl)1 Wrappers (com.baomidou.mybatisplus.core.toolkit.Wrappers)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 AllArgsConstructor (lombok.AllArgsConstructor)1 Test (org.junit.jupiter.api.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 Service (org.springframework.stereotype.Service)1