package com.storlead.user.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.storlead.framework.common.constant.CommonConstant;
import com.storlead.framework.mybatis.service.impl.MyBaseServiceImpl;
import com.storlead.user.mapper.TenantEnterpriseMapper;
import com.storlead.user.pojo.entity.TenantEnterpriseEntity;
import com.storlead.user.service.ITenantEnterpriseService;
import org.springframework.stereotype.Service;

@Service
public class TenantEnterpriseServiceImpl extends MyBaseServiceImpl<TenantEnterpriseMapper, TenantEnterpriseEntity>
        implements ITenantEnterpriseService {

    @Override
    public TenantEnterpriseEntity getByTenantId(Long tenantId) {
        if (tenantId == null) {
            return null;
        }
        return getOne(Wrappers.<TenantEnterpriseEntity>lambdaQuery()
                .eq(TenantEnterpriseEntity::getTenantId, tenantId)
                .eq(TenantEnterpriseEntity::getIsDelete, CommonConstant.DEL_FLAG_0)
                .last("LIMIT 1"));
    }

    @Override
    public TenantEnterpriseEntity getByEnterpriseCode(String enterpriseCode) {
        if (StrUtil.isBlank(enterpriseCode)) {
            return null;
        }
        return getOne(Wrappers.<TenantEnterpriseEntity>lambdaQuery()
                .eq(TenantEnterpriseEntity::getEnterpriseCode, StrUtil.trim(enterpriseCode))
                .eq(TenantEnterpriseEntity::getIsDelete, CommonConstant.DEL_FLAG_0)
                .last("LIMIT 1"));
    }
}
