Search in sources :

Example 1 with SysDept

use of com.pig4cloud.pig.admin.api.entity.SysDept 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)

Example 2 with SysDept

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

the class SysDeptServiceImpl method saveDept.

/**
 * 添加信息部门
 * @param dept 部门
 * @return
 */
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean saveDept(SysDept dept) {
    SysDept sysDept = new SysDept();
    BeanUtils.copyProperties(dept, sysDept);
    this.save(sysDept);
    sysDeptRelationService.saveDeptRelation(sysDept);
    return Boolean.TRUE;
}
Also used : SysDept(com.pig4cloud.pig.admin.api.entity.SysDept) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with SysDept

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

the class DeptController method user.

/**
 * 根据部门名查询部门信息
 * @param deptname 部门名
 * @return
 */
@GetMapping("/details/{deptname}")
public R<SysDept> user(@PathVariable String deptname) {
    SysDept condition = new SysDept();
    condition.setName(deptname);
    return R.ok(sysDeptService.getOne(new QueryWrapper<>(condition)));
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) SysDept(com.pig4cloud.pig.admin.api.entity.SysDept)

Aggregations

SysDept (com.pig4cloud.pig.admin.api.entity.SysDept)3 Transactional (org.springframework.transaction.annotation.Transactional)2 CollUtil (cn.hutool.core.collection.CollUtil)1 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 Wrappers (com.baomidou.mybatisplus.core.toolkit.Wrappers)1 ServiceImpl (com.baomidou.mybatisplus.extension.service.impl.ServiceImpl)1 SysDeptRelation (com.pig4cloud.pig.admin.api.entity.SysDeptRelation)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