package com.ghy.system.service.impl;

import com.ghy.common.core.domain.entity.SysDept;
import com.ghy.common.exception.ServiceException;
import com.ghy.common.utils.StringUtils;
import com.ghy.system.domain.SysDeptConfig;
import com.ghy.system.mapper.SysDeptConfigMapper;
import com.ghy.system.mapper.SysDeptMapper;
import com.ghy.system.service.ISysDeptConfigService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author clunt
 * 部门配置impl
 */
@Service
public class SysDeptConfigServiceImpl implements ISysDeptConfigService {

    @Resource
    private SysDeptConfigMapper sysDeptConfigMapper;

    @Resource
    private SysDeptMapper sysDeptMapper;

    @Override
    public SysDeptConfig selectByDeptId(Long deptId) {

        SysDept dept = sysDeptMapper.selectDeptById(deptId);
        if(StringUtils.isNotNull(dept) && StringUtils.isNotEmpty(dept.getAncestors())){
            Long targetDeptId  = Long.parseLong(dept.getAncestors().split(",")[1]);
            return sysDeptConfigMapper.selectByDeptId(targetDeptId);
        }else {
            throw new ServiceException("该用户的部门ID数据有误!");
        }

    }
}
