package com.cyksj.mapper.corp;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cyksj.model.entity.CorpUser;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;


/**
 * @author chan
 * @date 2022/3/15 上午9:49
 */
public interface CorpUserMapper extends BaseMapper<CorpUser> {
	@Select("select cu.id,cu.user_id,cu.unionid from (select corp_user_id from corp_user_auth where external_userid = #{corpUserId} limit 1) cua inner join corp_user cu on cu.id = cua.corp_user_id and cu.unionid != '' limit 1")
	CorpUser setCorpUserUserId(String corpUserId);

	@Select("select u.id from (select corp_user_id from corp_user_auth where wx_corp_id = #{wxCorpId} and external_userid = #{corpUserId} limit 1) ca inner join corp_user cu on cu.id = ca.corp_user_id and cu.unionid != ''" +
			" inner join user u on u.uionid = cu.unionid")
	Long selectUserIdByCropUserId(@Param("wxCorpId") Long wxCorpId, @Param("corpUserId") String corpUserId);

	@Select("select external_userid from (select id from corp_user where unionid = #{unionid} limit 1 ) cu inner join corp_user_auth ca on ca.corp_user_id = cu.id limit 1")
	String selectUserExternalUserId(String unionid);
}
