fengjin
2022-12-05 4b92c6f30a86ad0f804614b2659c1dda368b8fdd
flower_city/src/main/java/com/dg/core/service/impl/OrganizationChartImpl.java
@@ -6,6 +6,7 @@
import com.dg.core.db.gen.entity.OrganizationChartEntity;
import com.dg.core.db.gen.mapper.OrganizationChartMapper;
import com.dg.core.service.IOrganizationChartService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@@ -17,19 +18,32 @@
{
    @Override
    public List<OrganizationChartEntity> selectConfigList(String parentId,String grade)
    public List<OrganizationChartEntity> selectConfigList(String parentId,String grade,List<String> ids)
    {
        List<OrganizationChartEntity> ocList=baseMapper.selectConfigList("","1");
        List<OrganizationChartEntity> ocList=baseMapper.selectConfigList(parentId,"1",ids);
        if(ocList==null || ocList.size()<1)
        {
            List<String> id=new ArrayList<>();
            id.add(parentId);
            ocList=baseMapper.selectConfigList(null,null,id);
        }
        for (OrganizationChartEntity entity:ocList)
        {
            entity.setChild(baseMapper.selectConfigList(entity.getId()+"",""));
            entity.setChild(baseMapper.selectConfigList(entity.getId()+"","",null));
            if (entity.getChild()!=null)
            {
                entity.setChild(this.selectConfigList(entity.getId().toString()));
            }
        }
        return ocList;
    }
    @Override
    public List<OrganizationChartEntity> selectConfigList(List<String> ids) {
        List<OrganizationChartEntity> ocList=baseMapper.selectConfigList(null,null,ids);
        return ocList;
    }
@@ -57,9 +71,9 @@
    public List<OrganizationChartEntity> selectConfigList(String parentsId) {
        List<OrganizationChartEntity> list =baseMapper.selectConfigList(parentsId,"");
        List<OrganizationChartEntity> list =baseMapper.selectConfigList(parentsId,"",null);
        for (OrganizationChartEntity sysStreet:list) {
            sysStreet.setChild(baseMapper.selectConfigList(sysStreet.getId().toString(),""));
            sysStreet.setChild(baseMapper.selectConfigList(sysStreet.getId().toString(),"",null));
            if (sysStreet.getChild()!=null)
            {
                sysStreet.setChild(this.selectConfigList(sysStreet.getId().toString()));
@@ -93,7 +107,7 @@
    @Override
    public List<OrganizationChartEntity> selectParentList(String parentId, String grade) {
        return baseMapper.selectConfigList(parentId,grade);
        return baseMapper.selectConfigList(parentId,grade,null);
    }
    /**
@@ -106,7 +120,7 @@
    public List<String> getIds(String id)
    {
        List<String> ids=new ArrayList<>();
        List<OrganizationChartEntity> lists = baseMapper.selectConfigList(id,"");
        List<OrganizationChartEntity> lists = baseMapper.selectConfigList(id,"",null);
        if(lists.size()<1)
        {
            lists.add(baseMapper.selectConfigById(id));
@@ -120,6 +134,85 @@
        return ids;
    }
    @Override
    public List<String> getDepartmentId(String id){
        String parentId = parentId(id);
        List<String> departmentIds=new ArrayList<>();
        departmentIds.add(parentId);
        List<OrganizationChartEntity> organizationChartEntities = baseMapper.selectList(new QueryWrapper<OrganizationChartEntity>().lambda().eq(OrganizationChartEntity::getParentId, parentId));
        for (OrganizationChartEntity organizationChart :organizationChartEntities){
            departmentIds.add(organizationChart.getId().toString());
            departmentIds=getDepartmentIds(organizationChart.getId().toString(),departmentIds);
        }
        return  departmentIds;
    }
    @Override
    public String getStairId(String id)
    {
        OrganizationChartEntity entity= baseMapper.selectConfigById(id);
        if(entity!=null && StringUtils.isEmpty(entity.getParentId()))
        {
            return entity.getId()+"";
        }
        else
        {
            return getParentId(entity.getParentId());
        }
    }
    /**
     * 根据id  获取一级部门id   递归
     * @param id
     * @return
     */
    public String getParentId(String id)
    {
        String ultimatelyId;
        OrganizationChartEntity entity= baseMapper.selectConfigById(id);
        if(entity==null)
        {
            return id;
        }
        if(!StringUtils.isEmpty(entity.getParentId()))
        {
            ultimatelyId= getParentId(entity.getParentId());
            return ultimatelyId;
        }
        else
        {
            ultimatelyId=entity.getId()+"";
            return ultimatelyId;
        }
    }
    public  String parentId(String id){
        String parentId=id;
        OrganizationChartEntity organizationChart = baseMapper.selectOne(new QueryWrapper<OrganizationChartEntity>().lambda().eq(OrganizationChartEntity::getId, id));
        if (organizationChart.getParentId().length()>0){
            parentId=parentId(organizationChart.getParentId());
        }
        return parentId;
    }
    public  List<String>  getDepartmentIds(String id,List<String> departmentIds){
        List<OrganizationChartEntity> organizationChartEntities = baseMapper.selectList(new QueryWrapper<OrganizationChartEntity>().lambda().eq(OrganizationChartEntity::getParentId, id));
        if (organizationChartEntities.size()==0){
            return  departmentIds;
        }
        else {
            for (OrganizationChartEntity organizationChart :organizationChartEntities){
                departmentIds.add(organizationChart.getId().toString());
                departmentIds=getDepartmentIds(organizationChart.getId().toString(),departmentIds);
            }
        }
        return departmentIds;
    }
    //递归取id