<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.qs.mp.admin.mapper.TicketBoxGoodsMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.qs.mp.admin.domain.TicketBoxGoods">
        <id column="id" property="id" />
        <result column="box_id" property="boxId" />
        <result column="title" property="title" />
        <result column="pic_url" property="picUrl" />
        <result column="ref_id" property="refId" />
        <result column="is_deleted" property="isDeleted" />
        <result column="created_time" property="createdTime" />
        <result column="updated_time" property="updatedTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, box_id, title, pic_url, ref_id, is_deleted, created_time, updated_time
    </sql>

    <select id="listByQueryWrapper" resultType="com.qs.mp.admin.domain.vo.TicketBoxGoodsVO">
        select if(t2.title is not null, t2.title, t1.title)       as title,
               if(t2.pic_url is not null, t2.pic_url, t1.pic_url) as pic_url,
               if(t2.value is not null, t2.value, t1.value)       as value,
               if(t2.cost is not null, t2.cost, 0)                as cost,
               t1.*
        from mp_ticket_box_goods t1
        left join mp_goods t2 on t1.ref_id = t2.goods_id
            ${ew.customSqlSegment}
    </select>
</mapper>