<?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.OGoodsMapper">

    <resultMap id="BaseResultMap" type="cn.qihangerp.model.entity.OGoods">
            <id property="id" column="id" jdbcType="BIGINT"/>
            <result property="shopId" column="shop_id" jdbcType="BIGINT"/>
            <result property="name" column="name" jdbcType="VARCHAR"/>
            <result property="image" column="image" jdbcType="VARCHAR"/>
            <result property="outerErpGoodsId" column="outer_erp_goods_id" jdbcType="VARCHAR"/>
            <result property="province" column="province" jdbcType="VARCHAR"/>
            <result property="city" column="city" jdbcType="VARCHAR"/>
            <result property="town" column="town" jdbcType="VARCHAR"/>
            <result property="goodsNum" column="goods_num" jdbcType="VARCHAR"/>
            <result property="unitName" column="unit_name" jdbcType="VARCHAR"/>
            <result property="categoryId" column="category_id" jdbcType="INTEGER"/>
            <result property="categoryCode" column="category_code" jdbcType="VARCHAR"/>
            <result property="brandCode" column="brand_code" jdbcType="VARCHAR"/>
            <result property="canonicalExt" column="canonical_ext" jdbcType="LONGVARCHAR"/>
            <result property="barCode" column="bar_code" jdbcType="VARCHAR"/>
            <result property="remark" column="remark" jdbcType="VARCHAR"/>
            <result property="status" column="status" jdbcType="TINYINT"/>
            <result property="length" column="length" jdbcType="FLOAT"/>
            <result property="height" column="height" jdbcType="FLOAT"/>
            <result property="width" column="width" jdbcType="FLOAT"/>
            <result property="width1" column="width1" jdbcType="FLOAT"/>
            <result property="width2" column="width2" jdbcType="FLOAT"/>
            <result property="width3" column="width3" jdbcType="FLOAT"/>
            <result property="weight" column="weight" jdbcType="FLOAT"/>
            <result property="disable" column="disable" jdbcType="TINYINT"/>
            <result property="period" column="period" jdbcType="VARCHAR"/>
            <result property="purPrice" column="pur_price" jdbcType="DECIMAL"/>
            <result property="wholePrice" column="whole_price" jdbcType="DECIMAL"/>
            <result property="retailPrice" column="retail_price" jdbcType="DECIMAL"/>
            <result property="unitCost" column="unit_cost" jdbcType="DECIMAL"/>
            <result property="supplierId" column="supplier_id" jdbcType="INTEGER"/>
            <result property="brandId" column="brand_id" jdbcType="INTEGER"/>
            <result property="attr1" column="attr1" jdbcType="VARCHAR"/>
            <result property="attr2" column="attr2" jdbcType="VARCHAR"/>
            <result property="attr3" column="attr3" jdbcType="VARCHAR"/>
            <result property="attr4" column="attr4" jdbcType="VARCHAR"/>
            <result property="attr5" column="attr5" jdbcType="VARCHAR"/>
            <result property="linkUrl" column="link_url" jdbcType="VARCHAR"/>
            <result property="lowQty" column="low_qty" jdbcType="INTEGER"/>
            <result property="highQty" column="high_qty" jdbcType="INTEGER"/>
            <result property="createBy" column="create_by" jdbcType="VARCHAR"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
            <result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
            <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
    </resultMap>
    <resultMap type="cn.qihangerp.model.vo.GoodsSpecListVo" id="GoodsSpecListVoResult">
        <result property="skuId"    column="sku_id"    />
        <result property="goodsName"    column="goods_name"    />
        <result property="skuName"    column="sku_name"    />
        <result property="outerErpSkuId"    column="outer_erp_sku_id"    />
        <result property="skuCode"    column="sku_code"    />
        <result property="colorValue"    column="color_value"    />
        <result property="colorImage"    column="color_image"    />
        <result property="sizeValue"    column="size_value"    />
        <result property="styleValue"    column="style_value"    />
        <result property="retailPrice"    column="retail_price"    />
        <result property="purPrice"    column="pur_price"    />
    </resultMap>

    <sql id="Base_Column_List">
        id,shop_id,name,image,province,city,town,
        outer_erp_goods_id,goods_num,unit_name,
        category_id,category_code,brand_code,canonical_ext,bar_code,remark,
        status,length,height,
        width,width1,width2,
        width3,weight,disable,
        period,pur_price,whole_price,
        retail_price,unit_cost,supplier_id,
        brand_id,attr1,attr2,
        attr3,attr4,attr5,
        link_url,low_qty,high_qty,
        create_by,create_time,update_by,
        update_time
    </sql>

    <select id="searchGoodsSpec" parameterType="String" resultMap="GoodsSpecListVoResult">
        SELECT g.`name`,spec.id as sku_id,spec.outer_erp_goods_id,spec.outer_erp_sku_id,spec.`sku_name`,
               spec.sku_code,spec.color_value,spec.color_image,spec.size_value,spec.style_value,
               spec.retail_price,spec.pur_price,spec.goods_name
        FROM `o_goods_sku` as spec
        LEFT JOIN o_goods as g on g.id = spec.goods_id
        <where>
            <if test="keyword != null  and keyword != ''">
                and
                (
                g.name like concat('%', #{keyword}, '%')
                or spec.sku_name like concat('%', #{keyword}, '%')
                or g.goods_num like concat(#{keyword}, '%')
                or spec.sku_code like concat(#{keyword}, '%')
                )
            </if>
        </where>
    </select>
</mapper>
