Search in sources :

Example 1 with SysDeptRelation

use of com.pig4cloud.pig.admin.api.entity.SysDeptRelation in project pig by pig-mesh.

the class SysDeptServiceImpl method updateDeptById.

/**
 * 更新部门
 * @param sysDept 部门信息
 * @return 成功、失败
 */
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean updateDeptById(SysDept sysDept) {
    // 更新部门状态
    this.updateById(sysDept);
    // 更新部门关系
    SysDeptRelation relation = new SysDeptRelation();
    relation.setAncestor(sysDept.getParentId());
    relation.setDescendant(sysDept.getDeptId());
    sysDeptRelationService.updateDeptRelation(relation);
    return Boolean.TRUE;
}
Also used : SysDeptRelation(com.pig4cloud.pig.admin.api.entity.SysDeptRelation) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with SysDeptRelation

use of com.pig4cloud.pig.admin.api.entity.SysDeptRelation in project pig by pig-mesh.

the class SysDeptRelationServiceImpl method saveDeptRelation.

/**
 * 维护部门关系
 * @param sysDept 部门
 */
@Override
@Transactional(rollbackFor = Exception.class)
public void saveDeptRelation(SysDept sysDept) {
    // 增加部门关系表
    List<SysDeptRelation> relationList = sysDeptRelationMapper.selectList(Wrappers.<SysDeptRelation>query().lambda().eq(SysDeptRelation::getDescendant, sysDept.getParentId())).stream().map(relation -> {
        relation.setDescendant(sysDept.getDeptId());
        return relation;
    }).collect(Collectors.toList());
    if (CollUtil.isNotEmpty(relationList)) {
        this.saveBatch(relationList);
    }
    // 自己也要维护到关系表中
    SysDeptRelation own = new SysDeptRelation();
    own.setDescendant(sysDept.getDeptId());
    own.setAncestor(sysDept.getDeptId());
    sysDeptRelationMapper.insert(own);
}
Also used : ServiceImpl(com.baomidou.mybatisplus.extension.service.impl.ServiceImpl) SysDept(com.pig4cloud.pig.admin.api.entity.SysDept) Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) CollUtil(cn.hutool.core.collection.CollUtil) SysDeptRelationMapper(com.pig4cloud.pig.admin.mapper.SysDeptRelationMapper) SysDeptRelationService(com.pig4cloud.pig.admin.service.SysDeptRelationService) List(java.util.List) SysDeptRelation(com.pig4cloud.pig.admin.api.entity.SysDeptRelation) Service(org.springframework.stereotype.Service) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Collectors(java.util.stream.Collectors) Transactional(org.springframework.transaction.annotation.Transactional) SysDeptRelation(com.pig4cloud.pig.admin.api.entity.SysDeptRelation) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

SysDeptRelation (com.pig4cloud.pig.admin.api.entity.SysDeptRelation)2 Transactional (org.springframework.transaction.annotation.Transactional)2 CollUtil (cn.hutool.core.collection.CollUtil)1 Wrappers (com.baomidou.mybatisplus.core.toolkit.Wrappers)1 ServiceImpl (com.baomidou.mybatisplus.extension.service.impl.ServiceImpl)1 SysDept (com.pig4cloud.pig.admin.api.entity.SysDept)1 SysDeptRelationMapper (com.pig4cloud.pig.admin.mapper.SysDeptRelationMapper)1 SysDeptRelationService (com.pig4cloud.pig.admin.service.SysDeptRelationService)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Service (org.springframework.stereotype.Service)1