package cn.ysk.cashier.mybatis.mapper;

import cn.ysk.cashier.dto.TbShopShareRecordQueryCriteria;
import cn.ysk.cashier.vo.TbUserCouponVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.ysk.cashier.mybatis.entity.TbShopShareRecord;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * (TbShopShareRecord)表数据库访问层
 *
 * @author ww
 * @since 2024-11-08 09:17:37
 */
public interface TbShopShareRecordMapper extends BaseMapper<TbShopShareRecord> {

    @Select("<script> " +
            "SELECT" +
            " record.*," +
            " user1.nick_name AS invitedName," +
            " user2.nick_name AS beInvitedName," +
            " user1.head_img AS invitedHeadImg," +
            " user2.head_img AS beInvitedHeadImg " +
            "FROM" +
            " tb_shop_share_record record" +
            " LEFT JOIN tb_user_info user1 ON record.invited_id = user1.id " +
            "  <if test=\"param.search != null and param.search != '' \"> " +
            "      AND (user1.nick_name like concat('%', #{param.search}, '%') or user1.telephone like concat('%', #{param.search}, '%')) " +
            "  </if> " +
            " LEFT JOIN tb_user_info user2 ON record.be_invited_id = user2.id " +
            "  <if test=\"param.search != null and param.search != '' \"> " +
            "      AND (user2.nick_name like concat('%', #{param.search}, '%') or user2.telephone like concat('%', #{param.search}, '%')) " +
            "  </if> " +
            "WHERE" +
            "  share_id = #{param.shareId}" +
            "  <if test=\" param.status != null \"> " +
            "     and record.status = #{param.status} "+
            "  </if> " +
            "</script>")
    Page<TbShopShareRecord> selectAllByShare(@Param("param") TbShopShareRecordQueryCriteria param, Page page);
}

