package cn.wisenergy.service.impl;

import cn.wisenergy.common.utils.exception.BASE_RESP_CODE_ENUM;
import cn.wisenergy.common.utils.exception.BaseCustomException;
import cn.wisenergy.mapper.WorkCentreMapper;
import cn.wisenergy.model.app.WorkCentre;
import cn.wisenergy.service.WorkCentreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Authotr:陈奇
 * @QQ1799796883
 */

@Service
@Slf4j
public class WorkCentreServiceImpl implements WorkCentreService {

    @Autowired
    private WorkCentreMapper workCentreMapper;
    @Override
    public WorkCentre getCentreById(Integer id) {
        log.info("WorkCentreServiceImpl[]getCentreById[]input.param.id:{}" + id);
        if (null == id) {
            throw new BaseCustomException(BASE_RESP_CODE_ENUM.INPUT_PARAM_IS_NULL);
        }
        WorkCentre workCentre = workCentreMapper.selectById(id);

        if (null != workCentre) {
            return workCentre;
        }
        return null;
    }

    @Override
    public Boolean updateManagerIdIsNullById(Integer id) {
        log.info("WorkCentreServiceImpl[]updateManagerIdIsNullById[]input.param.id" + id);
        if (null == id) {
            throw new BaseCustomException(BASE_RESP_CODE_ENUM.INPUT_PARAM_IS_NULL);
        }
        int i = workCentreMapper.updateManagerIdIsNullById(id);
        return i>0;
    }

    @Override
    public Boolean updateById(WorkCentre workCentre) {
        log.info("WorkCentreServiceImpl[]updateById[]input.param.workCentre" + workCentre);
        if (null == workCentre || null == workCentre.getId()) {
            throw new BaseCustomException(BASE_RESP_CODE_ENUM.INPUT_PARAM_IS_NULL);
        }
        int updateRow = workCentreMapper.updateById(workCentre);
        return updateRow>0;
    }
}
