package com.ningdatech.carapi.user.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ningdatech.carapi.user.entity.NdUserInfoJoin;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author PoffyZhang
 * @since 2022-09-30
 */
public interface NdUserInfoJoinMapper extends BaseMapper<NdUserInfoJoin> {

    String QUERY_SQL = "SELECT u.*, c.name as company_name,c.region_id, " +
            " a.identifier as account,ur.role_id  FROM nd_user_info AS u " +
            " LEFT JOIN nd_company_info AS c ON u.company_id = c.id " +
            " LEFT JOIN nd_user_role AS ur ON u.id = ur.user_id " +
            " LEFT JOIN nd_user_auth AS a ON u.id = a.user_id ";
    String WRAPPER_SQL = "SELECT * from ( " + QUERY_SQL + " ) AS q ${ew.customSqlSegment}";

    @Select(WRAPPER_SQL)
    Page<NdUserInfoJoin> pageJoin(Page page, @Param("ew") LambdaQueryWrapper<NdUserInfoJoin> wrapper);

    @Select(WRAPPER_SQL)
    NdUserInfoJoin oneJoin(@Param("ew") LambdaQueryWrapper<NdUserInfoJoin> wrapper);
}
