package cn.wisenergy.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.wisenergy.common.utils.exception.BASE_RESP_CODE_ENUM;
import cn.wisenergy.common.utils.exception.BaseCustomException;
import cn.wisenergy.mapper.WorkDeptMapper;
import cn.wisenergy.model.app.WorkDept;
import cn.wisenergy.service.WorkDeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author chenqi
 * @since 2021-01-19
 */
@Service
@Slf4j
public class WorkDeptServiceImpl implements WorkDeptService {

    @Autowired
    private WorkDeptMapper workDeptMapper;

    @Override
    public WorkDept getById(Integer id) {
        log.info("WorkDeptServiceImpl[]getById[]input.param.id" + id);
        if (null == id) {
            throw new BaseCustomException(BASE_RESP_CODE_ENUM.INPUT_PARAM_IS_NULL);
        }
        WorkDept workDept = workDeptMapper.selectById(id);
        if (null == workDept) {
            throw new BaseCustomException(BASE_RESP_CODE_ENUM.DEPT_IS_NULL);
        }
        return workDept;

    }

    @Override
    public List<WorkDept> getDeptInfo(Integer deptId) {
        log.info("WorkDeptServiceImpl[]getAllDeptInfo" + deptId);
        //获取部门信息
        Map<String, Object> map = new HashMap<>();
        map.put("id", deptId);
        List<WorkDept> workDepts = workDeptMapper.getDeptByCondition(map);
        if (CollectionUtil.isEmpty(workDepts)) {
            throw new BaseCustomException(BASE_RESP_CODE_ENUM.DEPT_NOT_FOUND);
        }
        return workDepts;
    }
}
