Search in sources :

Example 1 with DeptRelationDo

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

the class DeptServiceImpl method saveOrUpdate.

/**
 * 添加信息部门
 *
 * @param deptDto 部门
 */
@Override
@Transactional(rollbackFor = Exception.class)
public void saveOrUpdate(DeptDto deptDto) {
    boolean add = ObjectUtil.isEmpty(deptDto.getId());
    super.saveOrUpdate(deptDto);
    if (add) {
        deptRelationService.saveDeptRelation(deptDto);
    } else {
        // 更新部门关系
        DeptRelationDo relation = new DeptRelationDo();
        relation.setAncestor(deptDto.getParentId());
        relation.setDescendant(deptDto.getId());
        deptRelationService.updateDeptRelation(relation);
    }
    SysCacheUtil.delDeptCaches(deptDto.getId());
}
Also used : DeptRelationDo(com.albedo.java.modules.sys.domain.DeptRelationDo) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with DeptRelationDo

use of com.albedo.java.modules.sys.domain.DeptRelationDo 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)

Aggregations

DeptRelationDo (com.albedo.java.modules.sys.domain.DeptRelationDo)2 Transactional (org.springframework.transaction.annotation.Transactional)2 CollUtil (com.albedo.java.common.core.util.CollUtil)1 DeptDto (com.albedo.java.modules.sys.domain.dto.DeptDto)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 Service (org.springframework.stereotype.Service)1