package com.yihu.jw.base.service.org;

import com.yihu.jw.base.dao.org.BaseOrgUserDao;
import com.yihu.jw.entity.base.org.BaseOrgUserDO;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 
 * 机构与机构管理员关联信息服务service
 * 
 * @version 
 * <pre>
 * Author	Version		Date		Changes
 * litaohong    1.0  2018年10月20日 Created
 *
 * </pre>
 * @since 1.
 */
@Service
public class BaseOrgUserService extends BaseJpaService<BaseOrgUserDO, BaseOrgUserDao> {

    @Autowired
    private BaseOrgUserDao baseOrgUserDao;

    public List<BaseOrgUserDO> findAllByOrgCode(String orgCode){
        List<BaseOrgUserDO> result = new ArrayList<>();
        return StringUtils.isEmpty(orgCode) ? result : baseOrgUserDao.findAllByOrgCode(orgCode);
    }


    public List<BaseOrgUserDO> findAllByUserId(String userId) {
        List<BaseOrgUserDO> result = new ArrayList<>();
        return StringUtils.isEmpty(userId) ? result : baseOrgUserDao.findAllByUserId(userId);
    }


    /**
     * 根据用户标识获取用户关联的机构Id列表
     *
     * @param userId
     * @return
     */
    public Set<Object> findIdListByUserId(String userId) {
        Set<Object> result = new HashSet<>();
        if (StringUtils.isEmpty(userId)) {
            return result;
        }
        return baseOrgUserDao.findIdListByUserId(userId);
    }

    /**
     * 根据用户标识获取用户关联的机构code列表
     *
     * @param userId
     * @return
     */
    public Set<String> findorgCodeListByUserId(String userId) {
        Set<String> result = new HashSet<>();
        if (StringUtils.isEmpty(userId)) {
            return result;
        }
        return baseOrgUserDao.findorgCodeListByUserId(userId);
    }

}
