package com.tuoheng.admin.service.dept.query;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tuoheng.admin.entity.Dept;
import com.tuoheng.admin.enums.MarkEnum;
import com.tuoheng.admin.mapper.DeptMapper;
import com.tuoheng.admin.utils.CurrentUserUtil;
import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.SecurityUserUtils;
import com.tuoheng.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author ChengWang
 * @Date 2023/3/8
 */
@Service
@Slf4j
public class QueryListByTenantIdService {

    @Autowired
    private DeptMapper deptMapper;


    /**
     * 根据租户id获取部门列表
     * @return
     */
    public JsonResult getListByTenantId() {
        //获取当前登录用户租户id
        String tenantId = CurrentUserUtil.getTenantId();
        if(null == tenantId){
            return JsonResult.error("当前租户不存在");
        }
        //根据当前租户查询部门列表
        List<Dept> deptList = deptMapper.selectList(Wrappers.<Dept>lambdaQuery()
                .eq(Dept::getTenantId, tenantId)
                .eq(Dept::getMark, MarkEnum.VALID.getCode()));

        return JsonResult.success(deptList);

    }
}
