package com.ruoyi.web.stock.service.impl;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.stock.mapper.RoleOrgMapper;
import com.ruoyi.web.stock.service.IRoleOrgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 角色租户解析服务实现。
 */
@Service
public class RoleOrgServiceImpl implements IRoleOrgService {

    @Autowired
    private RoleOrgMapper roleOrgMapper;

    @Override
    public String resolveOrgId(Long userId, Long deptId) {
        if (userId != null) {
            String orgId = roleOrgMapper.selectOrgIdByUserId(userId);
            if (StringUtils.isNotEmpty(orgId)) {
                return orgId;
            }
        }
        return deptId == null ? "-1" : String.valueOf(deptId);
    }
}
