package com.sunyard.ssp.modules.user.serviceimpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sunyard.ssp.common.constant.CommonConstant;
import com.sunyard.ssp.modules.user.entity.ScDepartmentHeader;
import com.sunyard.ssp.modules.user.mapper.ScDepartmentHeaderMapper;
import com.sunyard.ssp.modules.user.service.IScDepartmentHeaderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author tsz
 * @since 2020-03-12
 */
@Slf4j
@Service
@Transactional
public class ScDepartmentHeaderServiceImpl extends ServiceImpl<ScDepartmentHeaderMapper, ScDepartmentHeader> implements IScDepartmentHeaderService {

    @Autowired
    IScDepartmentHeaderService departmentHeaderService;
    @Override
    public Integer getHeaderTypeByUserId(Long userId) {
        List<ScDepartmentHeader> departmentHeaders = departmentHeaderService.list(new QueryWrapper<ScDepartmentHeader>().lambda()
                .eq(ScDepartmentHeader::getUserId,userId));
        if(CollectionUtils.isNotEmpty(departmentHeaders)){
            return departmentHeaders.get(0).getType();
        }
        return CommonConstant.HEADER_TYPE_NONE;
    }
}
