<?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="cn.qihangerp.mapper.TaoGoodsSkuMapper">

    <resultMap id="BaseResultMap" type="cn.qihangerp.model.entity.TaoGoodsSku">
            <id property="id" column="id" jdbcType="BIGINT"/>
            <result property="taoGoodsId" column="tao_goods_id" jdbcType="BIGINT"/>
            <result property="shopId" column="shop_id" jdbcType="BIGINT"/>
            <result property="numIid" column="num_iid" jdbcType="BIGINT"/>
            <result property="title" column="title" jdbcType="VARCHAR"/>
            <result property="picUrl" column="pic_url" jdbcType="VARCHAR"/>
            <result property="iid" column="iid" jdbcType="VARCHAR"/>
            <result property="skuId" column="sku_id" jdbcType="BIGINT"/>
            <result property="properties" column="properties" jdbcType="VARCHAR"/>
            <result property="propertiesName" column="properties_name" jdbcType="VARCHAR"/>
            <result property="quantity" column="quantity" jdbcType="BIGINT"/>
            <result property="spec" column="spec" jdbcType="VARCHAR"/>
            <result property="skuName" column="sku_name" jdbcType="VARCHAR"/>
            <result property="price" column="price" jdbcType="DOUBLE"/>
            <result property="outerId" column="outer_id" jdbcType="VARCHAR"/>
            <result property="created" column="created" jdbcType="TIMESTAMP"/>
            <result property="modified" column="modified" jdbcType="TIMESTAMP"/>
            <result property="status" column="status" jdbcType="VARCHAR"/>
            <result property="skuSpecId" column="sku_spec_id" jdbcType="VARCHAR"/>
            <result property="barcode" column="barcode" jdbcType="VARCHAR"/>
        <result property="erpGoodsId" column="erp_goods_id" jdbcType="BIGINT"/>
        <result property="erpGoodsSkuId" column="erp_goods_sku_id" jdbcType="BIGINT"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,tao_goods_id,num_iid,shop_id,
        iid,sku_id,properties,pic_url,title,
        properties_name,quantity,spec,sku_name,
        price,outer_id,created,
        modified,status,sku_spec_id,
        barcode,erp_goods_sku_id,erp_goods_id,
        create_time
    </sql>

    <select id="selectSkuPageList" resultType="cn.qihangerp.model.vo.TaoGoodsSkuListVo">
        SELECT sku.*,g.title,g.pic_url,ogs.outer_erp_sku_id,g.shop_id FROM oms_tao_goods_sku sku
        LEFT JOIN oms_tao_goods g on g.id = sku.tao_goods_id
        LEFT JOIN o_goods_sku ogs on ogs.id = sku.erp_goods_sku_id
        WHERE 1=1
        <if test="shopId != null and shopId != ''">
            AND g.shop_id = #{shopId}
        </if>
        <if test="numIid != null and numIid != ''">
            AND sku.num_iid = #{numIid}
        </if>
        <if test="skuId != null and skuId != ''">
            AND sku.sku_id = #{skuId}
        </if>
        <if test="outerId != null and outerId != ''">
            AND sku.outer_id = #{outerId}
        </if>
        <if test="hasLink != null and hasLink == 0">
            AND (sku.erp_goods_sku_id is NULL or sku.erp_goods_sku_id = 0)
        </if>
        <if test="hasLink != null and hasLink == 1">
            AND sku.erp_goods_sku_id is NOT NULL and sku.erp_goods_sku_id != 0
        </if>
    </select>
</mapper>
